- Revision
- 253678
- Author
- ph...@webkit.org
- Date
- 2019-12-18 04:48:43 -0800 (Wed, 18 Dec 2019)
Log Message
[GTK][WebInspector] Support for saving remote data
https://bugs.webkit.org/show_bug.cgi?id=204618
Reviewed by Carlos Garcia Campos.
Similarly to what landed already in r251069, the Remote
WebInspector GTK client can now save data coming from the
inspector server.
* UIProcess/gtk/RemoteWebInspectorProxyGtk.cpp:
(WebKit::RemoteWebInspectorProxy::platformSave):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (253677 => 253678)
--- trunk/Source/WebKit/ChangeLog 2019-12-18 12:07:00 UTC (rev 253677)
+++ trunk/Source/WebKit/ChangeLog 2019-12-18 12:48:43 UTC (rev 253678)
@@ -1,3 +1,17 @@
+2019-12-18 Philippe Normand <pnorm...@igalia.com>
+
+ [GTK][WebInspector] Support for saving remote data
+ https://bugs.webkit.org/show_bug.cgi?id=204618
+
+ Reviewed by Carlos Garcia Campos.
+
+ Similarly to what landed already in r251069, the Remote
+ WebInspector GTK client can now save data coming from the
+ inspector server.
+
+ * UIProcess/gtk/RemoteWebInspectorProxyGtk.cpp:
+ (WebKit::RemoteWebInspectorProxy::platformSave):
+
2019-12-17 Joonghun Park <jh718.p...@samsung.com>
Unreviewed. Remove the build warning below since r253452.
Modified: trunk/Source/WebKit/UIProcess/gtk/RemoteWebInspectorProxyGtk.cpp (253677 => 253678)
--- trunk/Source/WebKit/UIProcess/gtk/RemoteWebInspectorProxyGtk.cpp 2019-12-18 12:07:00 UTC (rev 253677)
+++ trunk/Source/WebKit/UIProcess/gtk/RemoteWebInspectorProxyGtk.cpp 2019-12-18 12:48:43 UTC (rev 253678)
@@ -28,11 +28,13 @@
#if ENABLE(REMOTE_INSPECTOR)
+#include "RemoteWebInspectorUIMessages.h"
#include "WebInspectorProxy.h"
#include "WebKitInspectorWindow.h"
#include "WebKitWebViewBasePrivate.h"
#include "WebPageGroup.h"
#include <WebCore/CertificateInfo.h>
+#include <wtf/text/Base64.h>
namespace WebKit {
using namespace WebCore;
@@ -99,10 +101,54 @@
gtk_window_present(GTK_WINDOW(m_window));
}
-void RemoteWebInspectorProxy::platformSave(const String&, const String&, bool, bool)
+static void remoteFileReplaceContentsCallback(GObject* sourceObject, GAsyncResult* result, gpointer userData)
{
+ GFile* file = G_FILE(sourceObject);
+ if (!g_file_replace_contents_finish(file, result, nullptr, nullptr))
+ return;
+
+ auto* page = static_cast<WebPageProxy*>(userData);
+ GUniquePtr<char> path(g_file_get_path(file));
+ page->process().send(Messages::RemoteWebInspectorUI::DidSave(path.get()), page->webPageID());
}
+void RemoteWebInspectorProxy::platformSave(const String& suggestedURL, const String& content, bool base64Encoded, bool forceSaveDialog)
+{
+ UNUSED_PARAM(forceSaveDialog);
+
+ GRefPtr<GtkFileChooserNative> dialog = adoptGRef(gtk_file_chooser_native_new("Save File",
+ GTK_WINDOW(m_window), GTK_FILE_CHOOSER_ACTION_SAVE, "Save", "Cancel"));
+
+ GtkFileChooser* chooser = GTK_FILE_CHOOSER(dialog.get());
+ gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
+
+ // Some inspector views (Audits for instance) use a custom URI scheme, such
+ // as web-inspector. So we can't rely on the URL being a valid file:/// URL
+ // unfortunately.
+ URL url(URL(), suggestedURL);
+ // Strip leading / character.
+ gtk_file_chooser_set_current_name(chooser, url.path().substring(1).utf8().data());
+
+ if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())) != GTK_RESPONSE_ACCEPT)
+ return;
+
+ Vector<char> dataVector;
+ CString dataString;
+ if (base64Encoded) {
+ if (!base64Decode(content, dataVector, Base64ValidatePadding))
+ return;
+ dataVector.shrinkToFit();
+ } else
+ dataString = content.utf8();
+
+ const char* data = "" ? dataString.data() : dataVector.data();
+ size_t dataLength = !dataString.isNull() ? dataString.length() : dataVector.size();
+ GRefPtr<GFile> file = adoptGRef(gtk_file_chooser_get_file(chooser));
+ GUniquePtr<char> path(g_file_get_path(file.get()));
+ g_file_replace_contents_async(file.get(), data, dataLength, nullptr, false,
+ G_FILE_CREATE_REPLACE_DESTINATION, nullptr, remoteFileReplaceContentsCallback, m_inspectorPage);
+}
+
void RemoteWebInspectorProxy::platformAppend(const String&, const String&)
{
}
Modified: trunk/Source/WebKit/UIProcess/gtk/WebInspectorProxyGtk.cpp (253677 => 253678)
--- trunk/Source/WebKit/UIProcess/gtk/WebInspectorProxyGtk.cpp 2019-12-18 12:07:00 UTC (rev 253677)
+++ trunk/Source/WebKit/UIProcess/gtk/WebInspectorProxyGtk.cpp 2019-12-18 12:48:43 UTC (rev 253678)
@@ -460,8 +460,19 @@
notImplemented();
}
-void WebInspectorProxy::platformSave(const String& filename, const String& content, bool base64Encoded, bool forceSaveDialog)
+static void fileReplaceContentsCallback(GObject* sourceObject, GAsyncResult* result, gpointer userData)
{
+ GFile* file = G_FILE(sourceObject);
+ if (!g_file_replace_contents_finish(file, result, nullptr, nullptr))
+ return;
+
+ auto* page = static_cast<WebPageProxy*>(userData);
+ GUniquePtr<char> path(g_file_get_path(file));
+ page->process().send(Messages::WebInspectorUI::DidSave(path.get()), page->webPageID());
+}
+
+void WebInspectorProxy::platformSave(const String& suggestedURL, const String& content, bool base64Encoded, bool forceSaveDialog)
+{
UNUSED_PARAM(forceSaveDialog);
GtkWidget* parent = gtk_widget_get_toplevel(m_inspectorView);
@@ -473,8 +484,14 @@
GtkFileChooser* chooser = GTK_FILE_CHOOSER(dialog.get());
gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
- gtk_file_chooser_set_current_name(chooser, filename.utf8().data());
+ // Some inspector views (Audits for instance) use a custom URI scheme, such
+ // as web-inspector. So we can't rely on the URL being a valid file:/// URL
+ // unfortunately.
+ URL url(URL(), suggestedURL);
+ // Strip leading / character.
+ gtk_file_chooser_set_current_name(chooser, url.path().substring(1).utf8().data());
+
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())) != GTK_RESPONSE_ACCEPT)
return;
@@ -491,8 +508,8 @@
size_t dataLength = !dataString.isNull() ? dataString.length() : dataVector.size();
GRefPtr<GFile> file = adoptGRef(gtk_file_chooser_get_file(chooser));
GUniquePtr<char> path(g_file_get_path(file.get()));
- if (g_file_set_contents(path.get(), data, dataLength, nullptr))
- m_inspectorPage->send(Messages::WebInspectorUI::DidSave(path.get()));
+ g_file_replace_contents_async(file.get(), data, dataLength, nullptr, false,
+ G_FILE_CREATE_REPLACE_DESTINATION, nullptr, fileReplaceContentsCallback, m_inspectorPage);
}
void WebInspectorProxy::platformAppend(const String&, const String&)