Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: extensions/browser/guest_view/web_view/web_view_guest.cc

Issue 1021073002: <webview> Implement clear http cache API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile error on mac/android: std::set initializer list makes them unhappy Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 5 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "extensions/strings/grit/extensions_strings.h" 46 #include "extensions/strings/grit/extensions_strings.h"
47 #include "ipc/ipc_message_macros.h" 47 #include "ipc/ipc_message_macros.h"
48 #include "net/base/escape.h" 48 #include "net/base/escape.h"
49 #include "net/base/net_errors.h" 49 #include "net/base/net_errors.h"
50 #include "ui/base/models/simple_menu_model.h" 50 #include "ui/base/models/simple_menu_model.h"
51 #include "url/url_constants.h" 51 #include "url/url_constants.h"
52 52
53 using base::UserMetricsAction; 53 using base::UserMetricsAction;
54 using content::RenderFrameHost; 54 using content::RenderFrameHost;
55 using content::ResourceType; 55 using content::ResourceType;
56 using content::StoragePartition;
56 using content::WebContents; 57 using content::WebContents;
57 58
58 namespace extensions { 59 namespace extensions {
59 60
60 namespace { 61 namespace {
61 62
63 // Returns storage partition removal mask from web_view clearData mask. Note
64 // that storage partition mask is a subset of webview's data removal mask.
65 uint32 GetStoragePartitionRemovalMask(uint32 web_view_removal_mask) {
66 uint32 mask = 0;
67 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_APPCACHE)
68 mask |= StoragePartition::REMOVE_DATA_MASK_APPCACHE;
69 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_COOKIES)
70 mask |= StoragePartition::REMOVE_DATA_MASK_COOKIES;
71 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_FILE_SYSTEMS)
72 mask |= StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS;
73 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_INDEXEDDB)
74 mask |= StoragePartition::REMOVE_DATA_MASK_INDEXEDDB;
75 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_LOCAL_STORAGE)
76 mask |= StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE;
77 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_WEBSQL)
78 mask |= StoragePartition::REMOVE_DATA_MASK_WEBSQL;
79
80 return mask;
81 }
82
62 std::string WindowOpenDispositionToString( 83 std::string WindowOpenDispositionToString(
63 WindowOpenDisposition window_open_disposition) { 84 WindowOpenDisposition window_open_disposition) {
64 switch (window_open_disposition) { 85 switch (window_open_disposition) {
65 case IGNORE_ACTION: 86 case IGNORE_ACTION:
66 return "ignore"; 87 return "ignore";
67 case SAVE_TO_DISK: 88 case SAVE_TO_DISK:
68 return "save_to_disk"; 89 return "save_to_disk";
69 case CURRENT_TAB: 90 case CURRENT_TAB:
70 return "current_tab"; 91 return "current_tab";
71 case NEW_BACKGROUND_TAB: 92 case NEW_BACKGROUND_TAB:
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 329
309 ApplyAttributes(create_params); 330 ApplyAttributes(create_params);
310 } 331 }
311 332
312 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { 333 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) {
313 if (web_view_guest_delegate_) 334 if (web_view_guest_delegate_)
314 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); 335 web_view_guest_delegate_->OnAttachWebViewHelpers(contents);
315 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); 336 web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
316 } 337 }
317 338
339 void WebViewGuest::ClearDataInternal(base::Time remove_since,
340 uint32 removal_mask,
341 const base::Closure& callback) {
342 uint32 storage_partition_removal_mask =
343 GetStoragePartitionRemovalMask(removal_mask);
344 if (!storage_partition_removal_mask) {
345 callback.Run();
346 return;
347 }
348 content::StoragePartition* partition =
349 content::BrowserContext::GetStoragePartition(
350 web_contents()->GetBrowserContext(),
351 web_contents()->GetSiteInstance());
352 partition->ClearData(
353 storage_partition_removal_mask,
354 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, GURL(),
355 content::StoragePartition::OriginMatcherFunction(), remove_since,
356 base::Time::Now(), callback);
357 }
358
318 void WebViewGuest::GuestViewDidStopLoading() { 359 void WebViewGuest::GuestViewDidStopLoading() {
319 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 360 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
320 DispatchEventToView( 361 DispatchEventToView(
321 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); 362 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
322 } 363 }
323 364
324 void WebViewGuest::EmbedderFullscreenToggled(bool entered_fullscreen) { 365 void WebViewGuest::EmbedderFullscreenToggled(bool entered_fullscreen) {
325 is_embedder_fullscreen_ = entered_fullscreen; 366 is_embedder_fullscreen_ = entered_fullscreen;
326 // If the embedder has got out of fullscreen, we get out of fullscreen 367 // If the embedder has got out of fullscreen, we get out of fullscreen
327 // mode as well. 368 // mode as well.
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 650
610 void WebViewGuest::Terminate() { 651 void WebViewGuest::Terminate() {
611 content::RecordAction(UserMetricsAction("WebView.Guest.Terminate")); 652 content::RecordAction(UserMetricsAction("WebView.Guest.Terminate"));
612 base::ProcessHandle process_handle = 653 base::ProcessHandle process_handle =
613 web_contents()->GetRenderProcessHost()->GetHandle(); 654 web_contents()->GetRenderProcessHost()->GetHandle();
614 if (process_handle) 655 if (process_handle)
615 web_contents()->GetRenderProcessHost()->Shutdown( 656 web_contents()->GetRenderProcessHost()->Shutdown(
616 content::RESULT_CODE_KILLED, false); 657 content::RESULT_CODE_KILLED, false);
617 } 658 }
618 659
619 bool WebViewGuest::ClearData(const base::Time remove_since, 660 bool WebViewGuest::ClearData(base::Time remove_since,
620 uint32 removal_mask, 661 uint32 removal_mask,
621 const base::Closure& callback) { 662 const base::Closure& callback) {
622 content::RecordAction(UserMetricsAction("WebView.Guest.ClearData")); 663 content::RecordAction(UserMetricsAction("WebView.Guest.ClearData"));
623 content::StoragePartition* partition = 664 content::StoragePartition* partition =
624 content::BrowserContext::GetStoragePartition( 665 content::BrowserContext::GetStoragePartition(
625 web_contents()->GetBrowserContext(), 666 web_contents()->GetBrowserContext(),
626 web_contents()->GetSiteInstance()); 667 web_contents()->GetSiteInstance());
627 668
628 if (!partition) 669 if (!partition)
629 return false; 670 return false;
630 671
631 partition->ClearData( 672 if (removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_CACHE) {
632 removal_mask, 673 if (web_view_guest_delegate_) {
633 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, 674 // First clear http cache data and then clear the rest in
634 GURL(), 675 // |ClearDataInternal|.
635 content::StoragePartition::OriginMatcherFunction(), 676 web_view_guest_delegate_->ClearCache(
636 remove_since, 677 remove_since, base::Bind(&WebViewGuest::ClearDataInternal,
637 base::Time::Now(), 678 weak_ptr_factory_.GetWeakPtr(), remove_since,
638 callback); 679 removal_mask, callback));
680 return true;
681 }
682 }
683
684 ClearDataInternal(remove_since, removal_mask, callback);
639 return true; 685 return true;
640 } 686 }
641 687
642 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) 688 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents)
643 : GuestView<WebViewGuest>(owner_web_contents), 689 : GuestView<WebViewGuest>(owner_web_contents),
644 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), 690 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID),
645 find_helper_(this), 691 find_helper_(this),
646 is_overriding_user_agent_(false), 692 is_overriding_user_agent_(false),
647 guest_opaque_(true), 693 guest_opaque_(true),
648 javascript_dialog_helper_(this), 694 javascript_dialog_helper_(this),
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 1377 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1332 DispatchEventToView( 1378 DispatchEventToView(
1333 new GuestViewBase::Event(webview::kEventExitFullscreen, args.Pass())); 1379 new GuestViewBase::Event(webview::kEventExitFullscreen, args.Pass()));
1334 } 1380 }
1335 // Since we changed fullscreen state, sending a Resize message ensures that 1381 // Since we changed fullscreen state, sending a Resize message ensures that
1336 // renderer/ sees the change. 1382 // renderer/ sees the change.
1337 web_contents()->GetRenderViewHost()->WasResized(); 1383 web_contents()->GetRenderViewHost()->WasResized();
1338 } 1384 }
1339 1385
1340 } // namespace extensions 1386 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698