Changeset 253678 in webkit
- Timestamp:
- Dec 18, 2019 4:48:43 AM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r253672 r253678 1 2019-12-18 Philippe Normand <pnormand@igalia.com> 2 3 [GTK][WebInspector] Support for saving remote data 4 https://bugs.webkit.org/show_bug.cgi?id=204618 5 6 Reviewed by Carlos Garcia Campos. 7 8 Similarly to what landed already in r251069, the Remote 9 WebInspector GTK client can now save data coming from the 10 inspector server. 11 12 * UIProcess/gtk/RemoteWebInspectorProxyGtk.cpp: 13 (WebKit::RemoteWebInspectorProxy::platformSave): 14 1 15 2019-12-17 Joonghun Park <jh718.park@samsung.com> 2 16 -
trunk/Source/WebKit/UIProcess/gtk/RemoteWebInspectorProxyGtk.cpp
r247852 r253678 29 29 #if ENABLE(REMOTE_INSPECTOR) 30 30 31 #include "RemoteWebInspectorUIMessages.h" 31 32 #include "WebInspectorProxy.h" 32 33 #include "WebKitInspectorWindow.h" … … 34 35 #include "WebPageGroup.h" 35 36 #include <WebCore/CertificateInfo.h> 37 #include <wtf/text/Base64.h> 36 38 37 39 namespace WebKit { … … 100 102 } 101 103 102 void RemoteWebInspectorProxy::platformSave(const String&, const String&, bool, bool)104 static void remoteFileReplaceContentsCallback(GObject* sourceObject, GAsyncResult* result, gpointer userData) 103 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); 104 150 } 105 151 -
trunk/Source/WebKit/UIProcess/gtk/WebInspectorProxyGtk.cpp
r253346 r253678 461 461 } 462 462 463 void WebInspectorProxy::platformSave(const String& filename, const String& content, bool base64Encoded, bool forceSaveDialog) 463 static void fileReplaceContentsCallback(GObject* sourceObject, GAsyncResult* result, gpointer userData) 464 { 465 GFile* file = G_FILE(sourceObject); 466 if (!g_file_replace_contents_finish(file, result, nullptr, nullptr)) 467 return; 468 469 auto* page = static_cast<WebPageProxy*>(userData); 470 GUniquePtr<char> path(g_file_get_path(file)); 471 page->process().send(Messages::WebInspectorUI::DidSave(path.get()), page->webPageID()); 472 } 473 474 void WebInspectorProxy::platformSave(const String& suggestedURL, const String& content, bool base64Encoded, bool forceSaveDialog) 464 475 { 465 476 UNUSED_PARAM(forceSaveDialog); … … 474 485 GtkFileChooser* chooser = GTK_FILE_CHOOSER(dialog.get()); 475 486 gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE); 476 gtk_file_chooser_set_current_name(chooser, filename.utf8().data()); 487 488 // Some inspector views (Audits for instance) use a custom URI scheme, such 489 // as web-inspector. So we can't rely on the URL being a valid file:/// URL 490 // unfortunately. 491 URL url(URL(), suggestedURL); 492 // Strip leading / character. 493 gtk_file_chooser_set_current_name(chooser, url.path().substring(1).utf8().data()); 477 494 478 495 if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())) != GTK_RESPONSE_ACCEPT) … … 492 509 GRefPtr<GFile> file = adoptGRef(gtk_file_chooser_get_file(chooser)); 493 510 GUniquePtr<char> path(g_file_get_path(file.get())); 494 if (g_file_set_contents(path.get(), data, dataLength, nullptr))495 m_inspectorPage->send(Messages::WebInspectorUI::DidSave(path.get()));511 g_file_replace_contents_async(file.get(), data, dataLength, nullptr, false, 512 G_FILE_CREATE_REPLACE_DESTINATION, nullptr, fileReplaceContentsCallback, m_inspectorPage); 496 513 } 497 514
Note: See TracChangeset
for help on using the changeset viewer.