| 1 | /* |
| 2 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 | * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 24 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #include "config.h" |
| 28 | #include "WebPageProxy.h" |
| 29 | |
| 30 | #include "PageClientImpl.h" |
| 31 | #include "WebKitWebViewBasePrivate.h" |
| 32 | #include "WebPageMessages.h" |
| 33 | #include "WebPasteboardProxy.h" |
| 34 | #include "WebProcessProxy.h" |
| 35 | #include "WebsiteDataStore.h" |
| 36 | #include <WebCore/NotImplemented.h> |
| 37 | #include <WebCore/PlatformDisplay.h> |
| 38 | #include <WebCore/UserAgent.h> |
| 39 | #include <gtk/gtkx.h> |
| 40 | #include <wtf/NeverDestroyed.h> |
| 41 | |
| 42 | namespace WebKit { |
| 43 | |
| 44 | void WebPageProxy::platformInitialize() |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | GtkWidget* WebPageProxy::viewWidget() |
| 49 | { |
| 50 | return static_cast<PageClientImpl&>(pageClient()).viewWidget(); |
| 51 | } |
| 52 | |
| 53 | String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent) |
| 54 | { |
| 55 | return WebCore::standardUserAgent(applicationNameForUserAgent); |
| 56 | } |
| 57 | |
| 58 | void WebPageProxy::bindAccessibilityTree(const String& plugID) |
| 59 | { |
| 60 | auto* accessible = gtk_widget_get_accessible(viewWidget()); |
| 61 | atk_socket_embed(ATK_SOCKET(accessible), const_cast<char*>(plugID.utf8().data())); |
| 62 | atk_object_notify_state_change(accessible, ATK_STATE_TRANSIENT, FALSE); |
| 63 | } |
| 64 | |
| 65 | void WebPageProxy::saveRecentSearches(const String&, const Vector<WebCore::RecentSearch>&) |
| 66 | { |
| 67 | notImplemented(); |
| 68 | } |
| 69 | |
| 70 | void WebPageProxy::loadRecentSearches(const String&, CompletionHandler<void(Vector<WebCore::RecentSearch>&&)>&& completionHandler) |
| 71 | { |
| 72 | notImplemented(); |
| 73 | completionHandler({ }); |
| 74 | } |
| 75 | |
| 76 | void WebsiteDataStore::platformRemoveRecentSearches(WallTime oldestTimeToRemove) |
| 77 | { |
| 78 | UNUSED_PARAM(oldestTimeToRemove); |
| 79 | notImplemented(); |
| 80 | } |
| 81 | |
| 82 | void WebPageProxy::updateEditorState(const EditorState& editorState) |
| 83 | { |
| 84 | m_editorState = editorState; |
| 85 | |
| 86 | if (editorState.shouldIgnoreSelectionChanges) |
| 87 | return; |
| 88 | if (m_editorState.selectionIsRange) |
| 89 | WebPasteboardProxy::singleton().setPrimarySelectionOwner(focusedFrame()); |
| 90 | pageClient().selectionDidChange(); |
| 91 | } |
| 92 | |
| 93 | #if PLATFORM(X11) |
| 94 | typedef HashMap<uint64_t, GtkWidget* > PluginWindowMap; |
| 95 | static PluginWindowMap& pluginWindowMap() |
| 96 | { |
| 97 | static NeverDestroyed<PluginWindowMap> map; |
| 98 | return map; |
| 99 | } |
| 100 | |
| 101 | static gboolean pluginContainerPlugRemoved(GtkSocket* socket) |
| 102 | { |
| 103 | uint64_t windowID = static_cast<uint64_t>(gtk_socket_get_id(socket)); |
| 104 | pluginWindowMap().remove(windowID); |
| 105 | return FALSE; |
| 106 | } |
| 107 | |
| 108 | void WebPageProxy::createPluginContainer(CompletionHandler<void(uint64_t)>&& completionHandler) |
| 109 | { |
| 110 | RELEASE_ASSERT(WebCore::PlatformDisplay::sharedDisplay().type() == WebCore::PlatformDisplay::Type::X11); |
| 111 | GtkWidget* socket = gtk_socket_new(); |
| 112 | g_signal_connect(socket, "plug-removed" , G_CALLBACK(pluginContainerPlugRemoved), 0); |
| 113 | gtk_container_add(GTK_CONTAINER(viewWidget()), socket); |
| 114 | |
| 115 | uint64_t windowID = static_cast<uint64_t>(gtk_socket_get_id(GTK_SOCKET(socket))); |
| 116 | pluginWindowMap().set(windowID, socket); |
| 117 | completionHandler(windowID); |
| 118 | } |
| 119 | |
| 120 | void WebPageProxy::windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID) |
| 121 | { |
| 122 | GtkWidget* plugin = pluginWindowMap().get(windowID); |
| 123 | if (!plugin) |
| 124 | return; |
| 125 | |
| 126 | if (gtk_widget_get_realized(plugin)) { |
| 127 | GdkRectangle clip = clipRect; |
| 128 | cairo_region_t* clipRegion = cairo_region_create_rectangle(&clip); |
| 129 | gdk_window_shape_combine_region(gtk_widget_get_window(plugin), clipRegion, 0, 0); |
| 130 | cairo_region_destroy(clipRegion); |
| 131 | } |
| 132 | |
| 133 | webkitWebViewBaseChildMoveResize(WEBKIT_WEB_VIEW_BASE(viewWidget()), plugin, frameRect); |
| 134 | } |
| 135 | |
| 136 | void WebPageProxy::windowedPluginVisibilityDidChange(bool isVisible, uint64_t windowID) |
| 137 | { |
| 138 | GtkWidget* plugin = pluginWindowMap().get(windowID); |
| 139 | if (!plugin) |
| 140 | return; |
| 141 | |
| 142 | if (isVisible) |
| 143 | gtk_widget_show(plugin); |
| 144 | else |
| 145 | gtk_widget_hide(plugin); |
| 146 | } |
| 147 | #endif // PLATFORM(X11) |
| 148 | |
| 149 | void WebPageProxy::setInputMethodState(bool enabled) |
| 150 | { |
| 151 | webkitWebViewBaseSetInputMethodState(WEBKIT_WEB_VIEW_BASE(viewWidget()), enabled); |
| 152 | } |
| 153 | |
| 154 | #if HAVE(GTK_GESTURES) |
| 155 | void WebPageProxy::getCenterForZoomGesture(const WebCore::IntPoint& centerInViewCoordinates, WebCore::IntPoint& center) |
| 156 | { |
| 157 | process().sendSync(Messages::WebPage::GetCenterForZoomGesture(centerInViewCoordinates), Messages::WebPage::GetCenterForZoomGesture::Reply(center), m_pageID); |
| 158 | } |
| 159 | #endif |
| 160 | |
| 161 | bool WebPageProxy::makeGLContextCurrent() |
| 162 | { |
| 163 | return webkitWebViewBaseMakeGLContextCurrent(WEBKIT_WEB_VIEW_BASE(viewWidget())); |
| 164 | } |
| 165 | |
| 166 | void WebPageProxy::showEmojiPicker(const WebCore::IntRect& caretRect, CompletionHandler<void(String)>&& completionHandler) |
| 167 | { |
| 168 | webkitWebViewBaseShowEmojiChooser(WEBKIT_WEB_VIEW_BASE(viewWidget()), caretRect, WTFMove(completionHandler)); |
| 169 | } |
| 170 | |
| 171 | } // namespace WebKit |
| 172 | |