2
* Copyright (C) 2017 Igalia S.L.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
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.
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.
27
#include "RemoteWebInspectorProxy.h"
29
#if ENABLE(REMOTE_INSPECTOR)
31
#include "RemoteWebInspectorUIMessages.h"
32
#include "WebInspectorProxy.h"
33
#include "WebKitInspectorWindow.h"
34
#include "WebKitWebViewBasePrivate.h"
35
#include "WebPageGroup.h"
36
#include <WebCore/CertificateInfo.h>
37
#include <wtf/text/Base64.h>
40
using namespace WebCore;
42
void RemoteWebInspectorProxy::updateWindowTitle(const CString& targetName)
46
webkitInspectorWindowSetSubtitle(WEBKIT_INSPECTOR_WINDOW(m_window), !targetName.isNull() ? targetName.data() : nullptr);
49
static void remoteInspectorViewDestroyed(RemoteWebInspectorProxy* inspectorProxy)
51
inspectorProxy->closeFromCrash();
54
WebPageProxy* RemoteWebInspectorProxy::platformCreateFrontendPageAndWindow()
58
auto preferences = WebPreferences::create(String(), "WebKit2.", "WebKit2.");
59
#if ENABLE(DEVELOPER_MODE)
60
// Allow developers to inspect the Web Inspector in debug builds without changing settings.
61
preferences->setDeveloperExtrasEnabled(true);
62
preferences->setLogsPageMessagesToSystemConsoleEnabled(true);
64
auto pageGroup = WebPageGroup::create(inspectorPageGroupIdentifierForPage(nullptr));
66
auto pageConfiguration = API::PageConfiguration::create();
67
pageConfiguration->setProcessPool(&inspectorProcessPool(inspectorLevelForPage(nullptr)));
68
pageConfiguration->setPreferences(preferences.ptr());
69
pageConfiguration->setPageGroup(pageGroup.ptr());
70
m_webView = GTK_WIDGET(webkitWebViewBaseCreate(*pageConfiguration.ptr()));
71
g_signal_connect_swapped(m_webView, "destroy", G_CALLBACK(remoteInspectorViewDestroyed), this);
72
g_object_add_weak_pointer(G_OBJECT(m_webView), reinterpret_cast<void**>(&m_webView));
74
m_window = webkitInspectorWindowNew();
75
gtk_container_add(GTK_CONTAINER(m_window), m_webView);
76
gtk_widget_show(m_webView);
78
g_object_add_weak_pointer(G_OBJECT(m_window), reinterpret_cast<void**>(&m_window));
79
gtk_window_present(GTK_WINDOW(m_window));
81
return webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_webView));
84
void RemoteWebInspectorProxy::platformCloseFrontendPageAndWindow()
87
if (auto* webPage = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_webView)))
91
gtk_widget_destroy(m_window);
94
void RemoteWebInspectorProxy::platformResetState()
98
void RemoteWebInspectorProxy::platformBringToFront()
101
gtk_window_present(GTK_WINDOW(m_window));
104
static void remoteFileReplaceContentsCallback(GObject* sourceObject, GAsyncResult* result, gpointer userData)
106
GFile* file = G_FILE(sourceObject);
107
if (!g_file_replace_contents_finish(file, result, nullptr, nullptr))
110
auto* page = static_cast<WebPageProxy*>(userData);
111
GUniquePtr<char> path(g_file_get_path(file));
112
page->process().send(Messages::RemoteWebInspectorUI::DidSave(path.get()), page->webPageID());
115
void RemoteWebInspectorProxy::platformSave(const String& suggestedURL, const String& content, bool base64Encoded, bool forceSaveDialog)
117
UNUSED_PARAM(forceSaveDialog);
119
GRefPtr<GtkFileChooserNative> dialog = adoptGRef(gtk_file_chooser_native_new("Save File",
120
GTK_WINDOW(m_window), GTK_FILE_CHOOSER_ACTION_SAVE, "Save", "Cancel"));
122
GtkFileChooser* chooser = GTK_FILE_CHOOSER(dialog.get());
123
gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
125
// Some inspector views (Audits for instance) use a custom URI scheme, such
126
// as web-inspector. So we can't rely on the URL being a valid file:/// URL
128
URL url(URL(), suggestedURL);
129
// Strip leading / character.
130
gtk_file_chooser_set_current_name(chooser, url.path().substring(1).utf8().data());
132
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())) != GTK_RESPONSE_ACCEPT)
135
Vector<char> dataVector;
138
if (!base64Decode(content, dataVector, Base64ValidatePadding))
140
dataVector.shrinkToFit();
142
dataString = content.utf8();
144
const char* data = !dataString.isNull() ? dataString.data() : dataVector.data();
145
size_t dataLength = !dataString.isNull() ? dataString.length() : dataVector.size();
146
GRefPtr<GFile> file = adoptGRef(gtk_file_chooser_get_file(chooser));
147
GUniquePtr<char> path(g_file_get_path(file.get()));
148
g_file_replace_contents_async(file.get(), data, dataLength, nullptr, false,
149
G_FILE_CREATE_REPLACE_DESTINATION, nullptr, remoteFileReplaceContentsCallback, m_inspectorPage);
152
void RemoteWebInspectorProxy::platformAppend(const String&, const String&)
156
void RemoteWebInspectorProxy::platformSetSheetRect(const FloatRect&)
160
void RemoteWebInspectorProxy::platformStartWindowDrag()
164
void RemoteWebInspectorProxy::platformOpenInNewTab(const String&)
168
void RemoteWebInspectorProxy::platformShowCertificate(const CertificateInfo&)
172
} // namespace WebKit
174
#endif // ENABLE(REMOTE_INSPECTOR)