1 | /* |
2 | * Copyright (C) 2017 Igalia S.L. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "RemoteWebInspectorProxy.h" |
28 | |
29 | #if ENABLE(REMOTE_INSPECTOR) |
30 | |
31 | #include "WebInspectorProxy.h" |
32 | #include "WebKitInspectorWindow.h" |
33 | #include "WebKitWebViewBasePrivate.h" |
34 | #include "WebPageGroup.h" |
35 | #include <WebCore/CertificateInfo.h> |
36 | |
37 | namespace WebKit { |
38 | using namespace WebCore; |
39 | |
40 | void RemoteWebInspectorProxy::updateWindowTitle(const CString& targetName) |
41 | { |
42 | if (!m_window) |
43 | return; |
44 | webkitInspectorWindowSetSubtitle(WEBKIT_INSPECTOR_WINDOW(m_window), !targetName.isNull() ? targetName.data() : nullptr); |
45 | } |
46 | |
47 | static void inspectorViewDestroyed(RemoteWebInspectorProxy* inspectorProxy) |
48 | { |
49 | inspectorProxy->closeFromCrash(); |
50 | } |
51 | |
52 | WebPageProxy* RemoteWebInspectorProxy::platformCreateFrontendPageAndWindow() |
53 | { |
54 | ASSERT(!m_webView); |
55 | |
56 | auto preferences = WebPreferences::create(String(), "WebKit2." , "WebKit2." ); |
57 | #if ENABLE(DEVELOPER_MODE) |
58 | // Allow developers to inspect the Web Inspector in debug builds without changing settings. |
59 | preferences->setDeveloperExtrasEnabled(true); |
60 | preferences->setLogsPageMessagesToSystemConsoleEnabled(true); |
61 | #endif |
62 | auto pageGroup = WebPageGroup::create(inspectorPageGroupIdentifierForPage(nullptr)); |
63 | |
64 | auto pageConfiguration = API::PageConfiguration::create(); |
65 | pageConfiguration->setProcessPool(&inspectorProcessPool(inspectorLevelForPage(nullptr))); |
66 | pageConfiguration->setPreferences(preferences.ptr()); |
67 | pageConfiguration->setPageGroup(pageGroup.ptr()); |
68 | m_webView = GTK_WIDGET(webkitWebViewBaseCreate(*pageConfiguration.ptr())); |
69 | g_signal_connect_swapped(m_webView, "destroy" , G_CALLBACK(inspectorViewDestroyed), this); |
70 | g_object_add_weak_pointer(G_OBJECT(m_webView), reinterpret_cast<void**>(&m_webView)); |
71 | |
72 | m_window = webkitInspectorWindowNew(nullptr); |
73 | gtk_container_add(GTK_CONTAINER(m_window), m_webView); |
74 | gtk_widget_show(m_webView); |
75 | |
76 | g_object_add_weak_pointer(G_OBJECT(m_window), reinterpret_cast<void**>(&m_window)); |
77 | gtk_window_present(GTK_WINDOW(m_window)); |
78 | |
79 | return webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_webView)); |
80 | } |
81 | |
82 | void RemoteWebInspectorProxy::platformCloseFrontendPageAndWindow() |
83 | { |
84 | if (m_webView) { |
85 | if (auto* webPage = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_webView))) |
86 | webPage->close(); |
87 | } |
88 | if (m_window) |
89 | gtk_widget_destroy(m_window); |
90 | } |
91 | |
92 | void RemoteWebInspectorProxy::platformBringToFront() |
93 | { |
94 | if (m_window) |
95 | gtk_window_present(GTK_WINDOW(m_window)); |
96 | } |
97 | |
98 | void RemoteWebInspectorProxy::platformSave(const String&, const String&, bool, bool) |
99 | { |
100 | } |
101 | |
102 | void RemoteWebInspectorProxy::platformAppend(const String&, const String&) |
103 | { |
104 | } |
105 | |
106 | void RemoteWebInspectorProxy::platformSetSheetRect(const FloatRect&) |
107 | { |
108 | } |
109 | |
110 | void RemoteWebInspectorProxy::platformStartWindowDrag() |
111 | { |
112 | } |
113 | |
114 | void RemoteWebInspectorProxy::platformOpenInNewTab(const String&) |
115 | { |
116 | } |
117 | |
118 | void RemoteWebInspectorProxy::platformShowCertificate(const CertificateInfo&) |
119 | { |
120 | } |
121 | |
122 | } // namespace WebKit |
123 | |
124 | #endif // ENABLE(REMOTE_INSPECTOR) |
125 | |