~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/WebKit/UIProcess/Inspector/gtk/RemoteWebInspectorProxyGtk.cpp

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "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>
 
38
 
 
39
namespace WebKit {
 
40
using namespace WebCore;
 
41
 
 
42
void RemoteWebInspectorProxy::updateWindowTitle(const CString& targetName)
 
43
{
 
44
    if (!m_window)
 
45
        return;
 
46
    webkitInspectorWindowSetSubtitle(WEBKIT_INSPECTOR_WINDOW(m_window), !targetName.isNull() ? targetName.data() : nullptr);
 
47
}
 
48
 
 
49
static void remoteInspectorViewDestroyed(RemoteWebInspectorProxy* inspectorProxy)
 
50
{
 
51
    inspectorProxy->closeFromCrash();
 
52
}
 
53
 
 
54
WebPageProxy* RemoteWebInspectorProxy::platformCreateFrontendPageAndWindow()
 
55
{
 
56
    ASSERT(!m_webView);
 
57
 
 
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);
 
63
#endif
 
64
    auto pageGroup = WebPageGroup::create(inspectorPageGroupIdentifierForPage(nullptr));
 
65
 
 
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));
 
73
 
 
74
    m_window = webkitInspectorWindowNew();
 
75
    gtk_container_add(GTK_CONTAINER(m_window), m_webView);
 
76
    gtk_widget_show(m_webView);
 
77
 
 
78
    g_object_add_weak_pointer(G_OBJECT(m_window), reinterpret_cast<void**>(&m_window));
 
79
    gtk_window_present(GTK_WINDOW(m_window));
 
80
 
 
81
    return webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_webView));
 
82
}
 
83
 
 
84
void RemoteWebInspectorProxy::platformCloseFrontendPageAndWindow()
 
85
{
 
86
    if (m_webView) {
 
87
        if (auto* webPage = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_webView)))
 
88
            webPage->close();
 
89
    }
 
90
    if (m_window)
 
91
        gtk_widget_destroy(m_window);
 
92
}
 
93
 
 
94
void RemoteWebInspectorProxy::platformResetState()
 
95
{
 
96
}
 
97
 
 
98
void RemoteWebInspectorProxy::platformBringToFront()
 
99
{
 
100
    if (m_window)
 
101
        gtk_window_present(GTK_WINDOW(m_window));
 
102
}
 
103
 
 
104
static void remoteFileReplaceContentsCallback(GObject* sourceObject, GAsyncResult* result, gpointer userData)
 
105
{
 
106
    GFile* file = G_FILE(sourceObject);
 
107
    if (!g_file_replace_contents_finish(file, result, nullptr, nullptr))
 
108
        return;
 
109
 
 
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());
 
113
}
 
114
 
 
115
void RemoteWebInspectorProxy::platformSave(const String& suggestedURL, const String& content, bool base64Encoded, bool forceSaveDialog)
 
116
{
 
117
    UNUSED_PARAM(forceSaveDialog);
 
118
 
 
119
    GRefPtr<GtkFileChooserNative> dialog = adoptGRef(gtk_file_chooser_native_new("Save File",
 
120
        GTK_WINDOW(m_window), GTK_FILE_CHOOSER_ACTION_SAVE, "Save", "Cancel"));
 
121
 
 
122
    GtkFileChooser* chooser = GTK_FILE_CHOOSER(dialog.get());
 
123
    gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
 
124
 
 
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
 
127
    // unfortunately.
 
128
    URL url(URL(), suggestedURL);
 
129
    // Strip leading / character.
 
130
    gtk_file_chooser_set_current_name(chooser, url.path().substring(1).utf8().data());
 
131
 
 
132
    if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())) != GTK_RESPONSE_ACCEPT)
 
133
        return;
 
134
 
 
135
    Vector<char> dataVector;
 
136
    CString dataString;
 
137
    if (base64Encoded) {
 
138
        if (!base64Decode(content, dataVector, Base64ValidatePadding))
 
139
            return;
 
140
        dataVector.shrinkToFit();
 
141
    } else
 
142
        dataString = content.utf8();
 
143
 
 
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);
 
150
}
 
151
 
 
152
void RemoteWebInspectorProxy::platformAppend(const String&, const String&)
 
153
{
 
154
}
 
155
 
 
156
void RemoteWebInspectorProxy::platformSetSheetRect(const FloatRect&)
 
157
{
 
158
}
 
159
 
 
160
void RemoteWebInspectorProxy::platformStartWindowDrag()
 
161
{
 
162
}
 
163
 
 
164
void RemoteWebInspectorProxy::platformOpenInNewTab(const String&)
 
165
{
 
166
}
 
167
 
 
168
void RemoteWebInspectorProxy::platformShowCertificate(const CertificateInfo&)
 
169
{
 
170
}
 
171
 
 
172
} // namespace WebKit
 
173
 
 
174
#endif // ENABLE(REMOTE_INSPECTOR)