Changeset 173456 in webkit
- Timestamp:
- Sep 10, 2014 1:37:17 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r173455 r173456 1 2014-09-10 Michael Catanzaro <mcatanzaro@igalia.com> 2 3 [GTK] allow overwriting destination of download 4 https://bugs.webkit.org/show_bug.cgi?id=136372 5 6 Reviewed by Carlos Garcia Campos. 7 8 * UIProcess/API/gtk/WebKitDownload.cpp: 9 (webkitDownloadGetProperty): Added 10 (webkit_download_class_init): Install webkitDownloadGetProperty 11 (webkitDownloadDecideDestinationWithSuggestedFilename): Add 12 allowOverwrite parameter and set it appropriately 13 (webkit_download_get_allow_overwrite): Added 14 (webkit_download_set_allow_overwrite): Added 15 * UIProcess/API/gtk/WebKitDownload.h: New API 16 * UIProcess/API/gtk/WebKitDownloadClient.cpp: 17 (decideDestinationWithSuggestedFilename): Pass allowOverwrite to 18 webkitDownloadDecideDestinationWithSuggestedFilename 19 * UIProcess/API/gtk/WebKitDownloadPrivate.h: Add allowOverwrite 20 parameter to webkitDownloadDecideDestinationWithSuggestedFilename 21 * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: New API 22 1 23 2014-09-10 Rohit Kumar <kumar.rohit@samsung.com> 2 24 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp
r164438 r173456 1 1 /* 2 * Copyright (C) 2012 Igalia S.L.2 * Copyright (C) 2012, 2014 Igalia S.L. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 64 64 PROP_DESTINATION, 65 65 PROP_RESPONSE, 66 PROP_ESTIMATED_PROGRESS 66 PROP_ESTIMATED_PROGRESS, 67 PROP_ALLOW_OVERWRITE 67 68 }; 68 69 … … 85 86 gdouble lastProgress; 86 87 gdouble lastElapsed; 88 bool allowOverwrite; 87 89 }; 88 90 … … 90 92 91 93 WEBKIT_DEFINE_TYPE(WebKitDownload, webkit_download, G_TYPE_OBJECT) 94 95 static void webkitDownloadSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec) 96 { 97 WebKitDownload* download = WEBKIT_DOWNLOAD(object); 98 99 switch (propId) { 100 case PROP_ALLOW_OVERWRITE: 101 webkit_download_set_allow_overwrite(download, g_value_get_boolean(value)); 102 break; 103 default: 104 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); 105 } 106 } 92 107 93 108 static void webkitDownloadGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec) … … 104 119 case PROP_ESTIMATED_PROGRESS: 105 120 g_value_set_double(value, webkit_download_get_estimated_progress(download)); 121 break; 122 case PROP_ALLOW_OVERWRITE: 123 g_value_set_boolean(value, webkit_download_get_allow_overwrite(download)); 106 124 break; 107 125 default: … … 131 149 { 132 150 GObjectClass* objectClass = G_OBJECT_CLASS(downloadClass); 151 objectClass->set_property = webkitDownloadSetProperty; 133 152 objectClass->get_property = webkitDownloadGetProperty; 134 153 … … 178 197 0.0, 1.0, 1.0, 179 198 WEBKIT_PARAM_READABLE)); 199 200 /** 201 * WebKitDownload:allow-overwrite: 202 * 203 * Whether or not the download is allowed to overwrite an existing file on 204 * disk. If this property is %FALSE and the destination already exists, 205 * the download will fail. 206 * 207 * Since: 2.6 208 */ 209 g_object_class_install_property( 210 objectClass, 211 PROP_ALLOW_OVERWRITE, 212 g_param_spec_boolean( 213 "allow-overwrite", 214 _("Allow Overwrite"), 215 _("Whether the destination may be overwritten"), 216 FALSE, 217 WEBKIT_PARAM_READWRITE)); 180 218 181 219 /** … … 371 409 } 372 410 373 CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload* download, const CString& suggestedFilename )411 CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload* download, const CString& suggestedFilename, bool& allowOverwrite) 374 412 { 375 413 if (download->priv->isCancelled) … … 377 415 gboolean returnValue; 378 416 g_signal_emit(download, signals[DECIDE_DESTINATION], 0, suggestedFilename.data(), &returnValue); 417 allowOverwrite = download->priv->allowOverwrite; 379 418 return download->priv->destinationURI; 380 419 } … … 569 608 return download->priv->webView; 570 609 } 610 611 /** 612 * webkit_download_get_allow_overwrite: 613 * @download: a #WebKitDownload 614 * 615 * Returns the current value of the #WebKitDownload:allow-overwrite property, 616 * which determines whether the download will overwrite an existing file on 617 * disk, or if it will fail if the destination already exists. 618 * 619 * Returns: the current value of the #WebKitDownload:allow-overwrite property 620 * 621 * Since: 2.6 622 */ 623 gboolean webkit_download_get_allow_overwrite(WebKitDownload* download) 624 { 625 g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), FALSE); 626 627 return download->priv->allowOverwrite; 628 } 629 630 /** 631 * webkit_download_set_allow_overwrite: 632 * @download: a #WebKitDownload 633 * @allowed: the new value for the #WebKitDownload:allow-overwrite property 634 * 635 * Sets the #WebKitDownload:allow-overwrite property, which determines whether 636 * the download may overwrite an existing file on disk, or if it will fail if 637 * the destination already exists. 638 * 639 * Since: 2.6 640 */ 641 void webkit_download_set_allow_overwrite(WebKitDownload* download, gboolean allowed) 642 { 643 g_return_if_fail(WEBKIT_IS_DOWNLOAD(download)); 644 645 if (allowed == download->priv->allowOverwrite) 646 return; 647 648 download->priv->allowOverwrite = allowed; 649 g_object_notify(G_OBJECT(download), "allow-overwrite"); 650 } -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h
r150130 r173456 93 93 webkit_download_get_web_view (WebKitDownload *download); 94 94 95 WEBKIT_API gboolean 96 webkit_download_get_allow_overwrite (WebKitDownload *download); 97 98 WEBKIT_API void 99 webkit_download_set_allow_overwrite (WebKitDownload *download, 100 gboolean allowed); 101 95 102 G_END_DECLS 96 103 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp
r168961 r173456 55 55 } 56 56 57 static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef wkDownload, WKStringRef filename, bool* /* allowOverwrite */, const void* /* clientInfo */)57 static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef wkDownload, WKStringRef filename, bool* allowOverwrite, const void* /* clientInfo */) 58 58 { 59 59 GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); 60 CString destinationURI = webkitDownloadDecideDestinationWithSuggestedFilename(download.get(), 61 toImpl(filename)->string().utf8()); 60 CString destinationURI = webkitDownloadDecideDestinationWithSuggestedFilename(download.get(), toImpl(filename)->string().utf8(), *allowOverwrite); 62 61 return WKStringCreateWithUTF8CString(destinationURI.data()); 63 62 } -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h
r145244 r173456 36 36 void webkitDownloadCancelled(WebKitDownload*); 37 37 void webkitDownloadFinished(WebKitDownload*); 38 CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload*, const CString& suggestedFilename );38 CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload*, const CString& suggestedFilename, bool& allowOverwrite); 39 39 void webkitDownloadDestinationCreated(WebKitDownload*, const CString& destinationURI); 40 40 -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
r173060 r173456 523 523 webkit_download_get_received_data_length 524 524 webkit_download_get_web_view 525 webkit_download_get_allow_overwrite 526 webkit_download_set_allow_overwrite 525 527 526 528 <SUBSECTION Standard> -
trunk/Tools/ChangeLog
r173452 r173456 1 2014-09-10 Michael Catanzaro <mcatanzaro@igalia.com> 2 3 [GTK] allow overwriting destination of download 4 https://bugs.webkit.org/show_bug.cgi?id=136372 5 6 Reviewed by Carlos Garcia Campos. 7 8 * TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp: 9 (downloadLocalFileSuccessfully): Split from testDownloadLocalFile 10 (testDownloadLocalFile): Split off downloadLocalFileSuccessfully 11 (createFileAtDestination): Added 12 (testDownloadOverwriteDestinationAllowed): Added 13 (testDownloadOverwriteDestinationDisallowed): Added 14 (testDownloadLocalFileError): Use new DownloadErrorTest::ExpectedError 15 (testDownloadRemoteFileError): Use new DownloadErrorTest::ExpectedError 16 (beforeAll): New tests 17 1 18 2014-08-05 David Farler <dfarler@apple.com> 2 19 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp
r167008 r173456 1 1 /* 2 * Copyright (C) 2012 Igalia S.L.2 * Copyright (C) 2012, 2014 Igalia S.L. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 57 57 g_assert(webkit_download_get_destination(download)); 58 58 g_assert_cmpstr(webkit_download_get_destination(download), ==, destination); 59 GRefPtr<GFile> file = adoptGRef(g_file_new_for_uri(destination)); 60 g_assert(g_file_query_exists(file.get(), nullptr)); 59 61 test->createdDestination(download, destination); 60 62 } … … 73 75 { 74 76 g_assert(error); 77 78 const char* destinationURI = webkit_download_get_destination(download); 79 if (destinationURI) { 80 GUniquePtr<char> tempFileURI(g_strconcat(destinationURI, ".wkdownload", nullptr)); 81 GRefPtr<GFile> tempFile = adoptGRef(g_file_new_for_uri(tempFileURI.get())); 82 g_assert(!g_file_query_exists(tempFile.get(), nullptr)); 83 } 84 75 85 test->failed(download, error); 76 86 } … … 99 109 , m_mainLoop(g_main_loop_new(0, TRUE)) 100 110 , m_downloadSize(0) 111 , m_allowOverwrite(false) 101 112 { 102 113 g_signal_connect(m_webContext, "download-started", G_CALLBACK(downloadStartedCallback), this); … … 111 122 virtual void started(WebKitDownload* download) 112 123 { 124 m_downloadSize = 0; 125 m_downloadEvents.clear(); 113 126 m_downloadEvents.append(Started); 114 127 } … … 154 167 WebKitDownload* download = webkit_web_context_download_uri(m_webContext, requestURI.data()); 155 168 assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download)); 169 170 g_assert(!webkit_download_get_allow_overwrite(download)); 171 webkit_download_set_allow_overwrite(download, m_allowOverwrite); 172 g_assert(webkit_download_get_allow_overwrite(download) == m_allowOverwrite); 156 173 157 174 WebKitURIRequest* request = webkit_download_get_request(download); … … 179 196 Vector<DownloadEvent> m_downloadEvents; 180 197 guint64 m_downloadSize; 198 bool m_allowOverwrite; 181 199 }; 182 200 183 static void testDownloadLocalFile(DownloadTest* test, gconstpointer)184 { 185 GUniquePtr<char> sourcePath(g_build_filename(Test::getResourcesDir().data(), "test.pdf", nullptr));201 static GRefPtr<WebKitDownload> downloadLocalFileSuccessfully(DownloadTest* test, const char* filename) 202 { 203 GUniquePtr<char> sourcePath(g_build_filename(Test::getResourcesDir().data(), filename, nullptr)); 186 204 GRefPtr<GFile> source = adoptGRef(g_file_new_for_path(sourcePath.get())); 187 205 GRefPtr<GFileInfo> sourceInfo = adoptGRef(g_file_query_info(source.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE, static_cast<GFileQueryInfoFlags>(0), 0, 0)); … … 205 223 g_assert(webkit_download_get_destination(download.get())); 206 224 g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), ==, 1); 207 test->checkDestinationAndDeleteFile(download.get(), "test.pdf"); 225 226 return download; 227 } 228 229 static void testDownloadLocalFile(DownloadTest* test, gconstpointer) 230 { 231 static const char* filename = "test.pdf"; 232 GRefPtr<WebKitDownload> download = downloadLocalFileSuccessfully(test, filename); 233 test->checkDestinationAndDeleteFile(download.get(), filename); 234 } 235 236 static void createFileAtDestination(const char* filename) 237 { 238 GUniquePtr<char> path(g_build_filename(kTempDirectory, filename, nullptr)); 239 GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path.get())); 240 GUniqueOutPtr<GError> error; 241 g_file_create(file.get(), G_FILE_CREATE_NONE, nullptr, &error.outPtr()); 242 g_assert(!error); 243 g_assert(g_file_query_exists(file.get(), nullptr)); 244 } 245 246 static void testDownloadOverwriteDestinationAllowed(DownloadTest* test, gconstpointer) 247 { 248 static const char* filename = "test.pdf"; 249 createFileAtDestination(filename); 250 251 test->m_allowOverwrite = true; 252 GRefPtr<WebKitDownload> download = downloadLocalFileSuccessfully(test, filename); 253 test->checkDestinationAndDeleteFile(download.get(), filename); 208 254 } 209 255 … … 212 258 MAKE_GLIB_TEST_FIXTURE(DownloadErrorTest); 213 259 260 enum ExpectedError { 261 NetworkError, 262 DownloadCancelled, 263 InvalidDestination, 264 DestinationExists 265 }; 266 214 267 DownloadErrorTest() 215 : m_expectedError( WEBKIT_DOWNLOAD_ERROR_NETWORK)268 : m_expectedError(NetworkError) 216 269 { 217 270 } … … 224 277 void createdDestination(WebKitDownload* download, const char* destination) 225 278 { 226 if (m_expectedError == WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER)279 if (m_expectedError == DownloadCancelled) 227 280 webkit_download_cancel(download); 228 281 else … … 232 285 void failed(WebKitDownload* download, GError* error) 233 286 { 234 g_assert(g_error_matches(error, WEBKIT_DOWNLOAD_ERROR, m_expectedError));287 g_assert(g_error_matches(error, WEBKIT_DOWNLOAD_ERROR, expectedErrorToWebKitDownloadError(m_expectedError))); 235 288 DownloadTest::failed(download, error); 236 289 } … … 238 291 void decideDestination(WebKitDownload* download, const gchar* suggestedFilename) 239 292 { 240 if (m_expectedError != WEBKIT_DOWNLOAD_ERROR_DESTINATION) {293 if (m_expectedError != InvalidDestination) { 241 294 DownloadTest::decideDestination(download, suggestedFilename); 242 295 return; … … 245 298 } 246 299 247 WebKitDownloadError m_expectedError; 300 static WebKitDownloadError expectedErrorToWebKitDownloadError(ExpectedError expected) 301 { 302 switch (expected) { 303 case NetworkError: 304 return WEBKIT_DOWNLOAD_ERROR_NETWORK; 305 case DownloadCancelled: 306 return WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER; 307 case InvalidDestination: 308 return WEBKIT_DOWNLOAD_ERROR_DESTINATION; 309 case DestinationExists: 310 return WEBKIT_DOWNLOAD_ERROR_DESTINATION; 311 default: 312 g_assert_not_reached(); 313 } 314 } 315 316 ExpectedError m_expectedError; 248 317 }; 249 318 319 static void testDownloadOverwriteDestinationDisallowed(DownloadErrorTest* test, gconstpointer) 320 { 321 static const char* filename = "test.pdf"; 322 createFileAtDestination(filename); 323 324 test->m_expectedError = DownloadErrorTest::DestinationExists; 325 GUniquePtr<char> sourcePath(g_build_filename(Test::getResourcesDir().data(), filename, nullptr)); 326 GRefPtr<GFile> source = adoptGRef(g_file_new_for_path(sourcePath.get())); 327 GUniquePtr<char> sourceURI(g_file_get_uri(source.get())); 328 GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(sourceURI.get())); 329 g_assert(!webkit_download_get_web_view(download.get())); 330 331 Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents; 332 g_assert_cmpint(events.size(), ==, 4); 333 g_assert_cmpint(events[0], ==, DownloadTest::Started); 334 g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse); 335 g_assert_cmpint(events[2], ==, DownloadTest::Failed); 336 g_assert_cmpint(events[3], ==, DownloadTest::Finished); 337 g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), ==, 0); 338 339 test->checkDestinationAndDeleteFile(download.get(), filename); 340 } 341 250 342 static void testDownloadLocalFileError(DownloadErrorTest* test, gconstpointer) 251 343 { 252 test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_NETWORK;344 test->m_expectedError = DownloadErrorTest::NetworkError; 253 345 GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes("file:///foo/bar")); 254 346 g_assert(!webkit_download_get_web_view(download.get())); … … 262 354 g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), <, 1); 263 355 264 test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_DESTINATION;356 test->m_expectedError = DownloadErrorTest::InvalidDestination; 265 357 GUniquePtr<char> path(g_build_filename(Test::getResourcesDir().data(), "test.pdf", nullptr)); 266 358 GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path.get())); … … 278 370 test->checkDestinationAndDeleteFile(download.get(), "bar"); 279 371 280 test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER;372 test->m_expectedError = DownloadErrorTest::DownloadCancelled; 281 373 download = adoptGRef(test->downloadURIAndWaitUntilFinishes(uri.get())); 282 374 g_assert(!webkit_download_get_web_view(download.get())); … … 370 462 static void testDownloadRemoteFileError(DownloadErrorTest* test, gconstpointer) 371 463 { 372 test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_NETWORK;464 test->m_expectedError = DownloadErrorTest::NetworkError; 373 465 GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/foo"))); 374 466 g_assert(!webkit_download_get_web_view(download.get())); … … 385 477 g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), <, 1); 386 478 387 test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_DESTINATION;479 test->m_expectedError = DownloadErrorTest::InvalidDestination; 388 480 download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/test.pdf"))); 389 481 g_assert(!webkit_download_get_web_view(download.get())); … … 398 490 test->checkDestinationAndDeleteFile(download.get(), "bar"); 399 491 400 test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER;492 test->m_expectedError = DownloadErrorTest::DownloadCancelled; 401 493 download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/cancel-after-destination"))); 402 494 g_assert(!webkit_download_get_web_view(download.get())); … … 534 626 535 627 DownloadTest::add("Downloads", "local-file", testDownloadLocalFile); 628 DownloadTest::add("Downloads", "overwrite-destination-allowed", testDownloadOverwriteDestinationAllowed); 629 DownloadErrorTest::add("Downloads", "overwrite-destination-disallowed", testDownloadOverwriteDestinationDisallowed); 536 630 DownloadErrorTest::add("Downloads", "local-file-error", testDownloadLocalFileError); 537 631 DownloadTest::add("Downloads", "remote-file", testDownloadRemoteFile);
Note: See TracChangeset
for help on using the changeset viewer.