diff options
Diffstat (limited to 'Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp | 188 |
1 files changed, 157 insertions, 31 deletions
diff --git a/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp index 231bc4ffb..b46d114a4 100644 --- a/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp +++ b/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp @@ -29,16 +29,16 @@ #include "config.h" #include "WebInspectorProxy.h" -#if ENABLE(INSPECTOR) - #include "WebKitWebViewBasePrivate.h" +#include "WebPageGroup.h" +#include "WebProcessPool.h" #include "WebProcessProxy.h" #include <WebCore/FileSystem.h> #include <WebCore/GtkUtilities.h> #include <WebCore/NotImplemented.h> #include <glib/gi18n-lib.h> #include <gtk/gtk.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> #include <wtf/text/WTFString.h> @@ -53,6 +53,11 @@ static void inspectorViewDestroyed(GtkWidget*, gpointer userData) inspectorProxy->close(); } +static unsigned long long exceededDatabaseQuota(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKStringRef, WKStringRef, unsigned long long, unsigned long long, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage, const void*) +{ + return std::max<unsigned long long>(expectedUsage, currentDatabaseUsage * 1.25); +} + void WebInspectorProxy::initializeInspectorClientGtk(const WKInspectorClientGtkBase* inspectorClient) { m_client.initialize(inspectorClient); @@ -60,11 +65,81 @@ void WebInspectorProxy::initializeInspectorClientGtk(const WKInspectorClientGtkB WebPageProxy* WebInspectorProxy::platformCreateInspectorPage() { - ASSERT(m_page); + ASSERT(inspectedPage()); ASSERT(!m_inspectorView); - m_inspectorView = GTK_WIDGET(webkitWebViewBaseCreate(&page()->process().context(), inspectorPageGroup(), m_page)); + + RefPtr<WebPreferences> preferences = WebPreferences::create(String(), "WebKit2.", "WebKit2."); +#if ENABLE(DEVELOPER_MODE) + // Allow developers to inspect the Web Inspector in debug builds without changing settings. + preferences->setDeveloperExtrasEnabled(true); + preferences->setLogsPageMessagesToSystemConsoleEnabled(true); +#endif + preferences->setJavaScriptRuntimeFlags({ + }); + RefPtr<WebPageGroup> pageGroup = WebPageGroup::create(inspectorPageGroupIdentifierForPage(inspectedPage()), false, false); + + auto pageConfiguration = API::PageConfiguration::create(); + pageConfiguration->setProcessPool(&inspectorProcessPool(inspectionLevel())); + pageConfiguration->setPreferences(preferences.get()); + pageConfiguration->setPageGroup(pageGroup.get()); + m_inspectorView = GTK_WIDGET(webkitWebViewBaseCreate(*pageConfiguration.ptr())); g_object_add_weak_pointer(G_OBJECT(m_inspectorView), reinterpret_cast<void**>(&m_inspectorView)); - return webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_inspectorView)); + + WKPageUIClientV2 uiClient = { + { 2, this }, + nullptr, // createNewPage_deprecatedForUseWithV0 + nullptr, // showPage + nullptr, // closePage + nullptr, // takeFocus + nullptr, // focus + nullptr, // unfocus + nullptr, // runJavaScriptAlert + nullptr, // runJavaScriptConfirm + nullptr, // runJavaScriptPrompt + nullptr, // setStatusText + nullptr, // mouseDidMoveOverElement_deprecatedForUseWithV0 + nullptr, // missingPluginButtonClicked_deprecatedForUseWithV0 + nullptr, // didNotHandleKeyEvent + nullptr, // didNotHandleWheelEvent + nullptr, // areToolbarsVisible + nullptr, // setToolbarsVisible + nullptr, // isMenuBarVisible + nullptr, // setMenuBarVisible + nullptr, // isStatusBarVisible + nullptr, // setStatusBarVisible + nullptr, // isResizable + nullptr, // setResizable + nullptr, // getWindowFrame, + nullptr, // setWindowFrame, + nullptr, // runBeforeUnloadConfirmPanel + nullptr, // didDraw + nullptr, // pageDidScroll + exceededDatabaseQuota, + nullptr, // runOpenPanel, + nullptr, // decidePolicyForGeolocationPermissionRequest + nullptr, // headerHeight + nullptr, // footerHeight + nullptr, // drawHeader + nullptr, // drawFooter + nullptr, // printFrame + nullptr, // runModal + nullptr, // unused + nullptr, // saveDataToFileInDownloadsFolder + nullptr, // shouldInterruptJavaScript + nullptr, // createPage + nullptr, // mouseDidMoveOverElement + nullptr, // decidePolicyForNotificationPermissionRequest + nullptr, // unavailablePluginButtonClicked_deprecatedForUseWithV1 + nullptr, // showColorPicker + nullptr, // hideColorPicker + nullptr, // unavailablePluginButtonClicked + }; + + WebPageProxy* inspectorPage = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_inspectorView)); + ASSERT(inspectorPage); + WKPageSetPageUIClient(toAPI(inspectorPage), &uiClient.base); + + return inspectorPage; } void WebInspectorProxy::createInspectorWindow() @@ -75,11 +150,18 @@ void WebInspectorProxy::createInspectorWindow() ASSERT(!m_inspectorWindow); m_inspectorWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); - GtkWidget* inspectedViewParent = gtk_widget_get_toplevel(m_page->viewWidget()); + GtkWidget* inspectedViewParent = gtk_widget_get_toplevel(inspectedPage()->viewWidget()); if (WebCore::widgetIsOnscreenToplevelWindow(inspectedViewParent)) gtk_window_set_transient_for(GTK_WINDOW(m_inspectorWindow), GTK_WINDOW(inspectedViewParent)); - gtk_window_set_title(GTK_WINDOW(m_inspectorWindow), _("Web Inspector")); +#if GTK_CHECK_VERSION(3, 10, 0) + m_headerBar = gtk_header_bar_new(); + gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(m_headerBar), TRUE); + gtk_window_set_titlebar(GTK_WINDOW(m_inspectorWindow), m_headerBar); + gtk_widget_show(m_headerBar); +#endif + + updateInspectorWindowTitle(); gtk_window_set_default_size(GTK_WINDOW(m_inspectorWindow), initialWindowWidth, initialWindowHeight); gtk_container_add(GTK_CONTAINER(m_inspectorWindow), m_inspectorView); @@ -89,6 +171,23 @@ void WebInspectorProxy::createInspectorWindow() gtk_window_present(GTK_WINDOW(m_inspectorWindow)); } +void WebInspectorProxy::updateInspectorWindowTitle() const +{ + ASSERT(m_inspectorWindow); + if (m_inspectedURLString.isEmpty()) { + gtk_window_set_title(GTK_WINDOW(m_inspectorWindow), _("Web Inspector")); + return; + } + +#if GTK_CHECK_VERSION(3, 10, 0) + gtk_header_bar_set_title(GTK_HEADER_BAR(m_headerBar), _("Web Inspector")); + gtk_header_bar_set_subtitle(GTK_HEADER_BAR(m_headerBar), m_inspectedURLString.utf8().data()); +#else + GUniquePtr<gchar> title(g_strdup_printf("%s - %s", _("Web Inspector"), m_inspectedURLString.utf8().data())); + gtk_window_set_title(GTK_WINDOW(m_inspectorWindow), title.get()); +#endif +} + void WebInspectorProxy::platformOpen() { ASSERT(!m_inspectorWindow); @@ -115,6 +214,14 @@ void WebInspectorProxy::platformDidClose() m_inspectorView = 0; } +void WebInspectorProxy::platformDidCloseForCrash() +{ +} + +void WebInspectorProxy::platformInvalidate() +{ +} + void WebInspectorProxy::platformHide() { notImplemented(); @@ -130,6 +237,11 @@ void WebInspectorProxy::platformBringToFront() gtk_window_present(GTK_WINDOW(parent)); } +void WebInspectorProxy::platformBringInspectedPageToFront() +{ + notImplemented(); +} + bool WebInspectorProxy::platformIsFront() { GtkWidget* parent = gtk_widget_get_toplevel(m_inspectorView); @@ -140,32 +252,36 @@ bool WebInspectorProxy::platformIsFront() void WebInspectorProxy::platformInspectedURLChanged(const String& url) { + m_inspectedURLString = url; m_client.inspectedURLChanged(this, url); - if (!m_inspectorWindow) - return; - GUniquePtr<gchar> title(g_strdup_printf("%s - %s", _("Web Inspector"), url.utf8().data())); - gtk_window_set_title(GTK_WINDOW(m_inspectorWindow), title.get()); + if (m_inspectorWindow) + updateInspectorWindowTitle(); } -String WebInspectorProxy::inspectorPageURL() const +String WebInspectorProxy::inspectorPageURL() { return String("resource:///org/webkitgtk/inspector/UserInterface/Main.html"); } -String WebInspectorProxy::inspectorBaseURL() const +String WebInspectorProxy::inspectorTestPageURL() +{ + return String("resource:///org/webkitgtk/inspector/UserInterface/Test.html"); +} + +String WebInspectorProxy::inspectorBaseURL() { return String("resource:///org/webkitgtk/inspector/UserInterface/"); } unsigned WebInspectorProxy::platformInspectedWindowHeight() { - return gtk_widget_get_allocated_height(m_page->viewWidget()); + return gtk_widget_get_allocated_height(inspectedPage()->viewWidget()); } unsigned WebInspectorProxy::platformInspectedWindowWidth() { - return gtk_widget_get_allocated_width(m_page->viewWidget()); + return gtk_widget_get_allocated_width(inspectedPage()->viewWidget()); } void WebInspectorProxy::platformAttach() @@ -177,9 +293,12 @@ void WebInspectorProxy::platformAttach() m_inspectorWindow = 0; } - // Set a default attached size based on InspectorFrontendClientLocal. + // Set a default sizes based on InspectorFrontendClientLocal. static const unsigned defaultAttachedSize = 300; - if (m_attachmentSide == AttachmentSideBottom) { + static const unsigned minimumAttachedWidth = 750; + static const unsigned minimumAttachedHeight = 250; + + if (m_attachmentSide == AttachmentSide::Bottom) { unsigned maximumAttachedHeight = platformInspectedWindowHeight() * 3 / 4; platformSetAttachedWindowHeight(std::max(minimumAttachedHeight, std::min(defaultAttachedSize, maximumAttachedHeight))); } else { @@ -190,24 +309,33 @@ void WebInspectorProxy::platformAttach() if (m_client.attach(this)) return; - webkitWebViewBaseAddWebInspector(WEBKIT_WEB_VIEW_BASE(m_page->viewWidget()), m_inspectorView, m_attachmentSide); + webkitWebViewBaseAddWebInspector(WEBKIT_WEB_VIEW_BASE(inspectedPage()->viewWidget()), m_inspectorView, m_attachmentSide); gtk_widget_show(m_inspectorView); } void WebInspectorProxy::platformDetach() { - if (!m_page->isValid()) + if (!inspectedPage()->isValid()) return; GRefPtr<GtkWidget> inspectorView = m_inspectorView; if (!m_client.detach(this)) { - GtkWidget* parent = gtk_widget_get_parent(m_inspectorView); - ASSERT(parent); - gtk_container_remove(GTK_CONTAINER(parent), m_inspectorView); + // Detach is called when m_isAttached is true, but it could called before + // the inspector is opened if the inspector is shown/closed quickly. So, + // we might not have a parent yet. + if (GtkWidget* parent = gtk_widget_get_parent(m_inspectorView)) + gtk_container_remove(GTK_CONTAINER(parent), m_inspectorView); } - if (!m_isVisible) + // Return early if we are not visible. This means the inspector was closed while attached + // and we should not create and show the inspector window. + if (!m_isVisible) { + // The inspector view will be destroyed, but we don't need to notify the web process to close the + // inspector in this case, since it's already closed. + g_signal_handlers_disconnect_by_func(m_inspectorView, reinterpret_cast<void*>(inspectorViewDestroyed), this); + m_inspectorView = nullptr; return; + } createInspectorWindow(); } @@ -218,7 +346,7 @@ void WebInspectorProxy::platformSetAttachedWindowHeight(unsigned height) return; m_client.didChangeAttachedHeight(this, height); - webkitWebViewBaseSetInspectorViewSize(WEBKIT_WEB_VIEW_BASE(m_page->viewWidget()), height); + webkitWebViewBaseSetInspectorViewSize(WEBKIT_WEB_VIEW_BASE(inspectedPage()->viewWidget()), height); } void WebInspectorProxy::platformSetAttachedWindowWidth(unsigned width) @@ -227,10 +355,10 @@ void WebInspectorProxy::platformSetAttachedWindowWidth(unsigned width) return; m_client.didChangeAttachedWidth(this, width); - webkitWebViewBaseSetInspectorViewSize(WEBKIT_WEB_VIEW_BASE(m_page->viewWidget()), width); + webkitWebViewBaseSetInspectorViewSize(WEBKIT_WEB_VIEW_BASE(inspectedPage()->viewWidget()), width); } -void WebInspectorProxy::platformSetToolbarHeight(unsigned) +void WebInspectorProxy::platformStartWindowDrag() { notImplemented(); } @@ -245,11 +373,9 @@ void WebInspectorProxy::platformAppend(const String&, const String&) notImplemented(); } -void WebInspectorProxy::platformAttachAvailabilityChanged(bool) +void WebInspectorProxy::platformAttachAvailabilityChanged(bool available) { - notImplemented(); + m_client.didChangeAttachAvailability(this, available); } } // namespace WebKit - -#endif // ENABLE(INSPECTOR) |