| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" | 55 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 56 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" | 56 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" |
| 57 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 57 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
| 58 #include "extensions/common/constants.h" | 58 #include "extensions/common/constants.h" |
| 59 #include "extensions/common/extension_messages.h" | 59 #include "extensions/common/extension_messages.h" |
| 60 #include "extensions/common/manifest_constants.h" | 60 #include "extensions/common/manifest_constants.h" |
| 61 #include "extensions/strings/grit/extensions_strings.h" | 61 #include "extensions/strings/grit/extensions_strings.h" |
| 62 #include "ipc/ipc_message_macros.h" | 62 #include "ipc/ipc_message_macros.h" |
| 63 #include "net/base/escape.h" | 63 #include "net/base/escape.h" |
| 64 #include "net/base/net_errors.h" | 64 #include "net/base/net_errors.h" |
| 65 #include "net/cookies/canonical_cookie.h" |
| 65 #include "ui/base/models/simple_menu_model.h" | 66 #include "ui/base/models/simple_menu_model.h" |
| 66 #include "ui/events/keycodes/keyboard_codes.h" | 67 #include "ui/events/keycodes/keyboard_codes.h" |
| 67 #include "url/url_constants.h" | 68 #include "url/url_constants.h" |
| 68 | 69 |
| 69 using base::UserMetricsAction; | 70 using base::UserMetricsAction; |
| 70 using content::GlobalRequestID; | 71 using content::GlobalRequestID; |
| 71 using content::RenderFrameHost; | 72 using content::RenderFrameHost; |
| 72 using content::RenderProcessHost; | 73 using content::RenderProcessHost; |
| 73 using content::StoragePartition; | 74 using content::StoragePartition; |
| 74 using content::WebContents; | 75 using content::WebContents; |
| 75 using guest_view::GuestViewBase; | 76 using guest_view::GuestViewBase; |
| 76 using guest_view::GuestViewEvent; | 77 using guest_view::GuestViewEvent; |
| 77 using guest_view::GuestViewManager; | 78 using guest_view::GuestViewManager; |
| 78 using zoom::ZoomController; | 79 using zoom::ZoomController; |
| 79 | 80 |
| 80 namespace extensions { | 81 namespace extensions { |
| 81 | 82 |
| 82 namespace { | 83 namespace { |
| 83 | 84 |
| 84 // Returns storage partition removal mask from web_view clearData mask. Note | 85 // Returns storage partition removal mask from web_view clearData mask. Note |
| 85 // that storage partition mask is a subset of webview's data removal mask. | 86 // that storage partition mask is a subset of webview's data removal mask. |
| 86 uint32_t GetStoragePartitionRemovalMask(uint32_t web_view_removal_mask) { | 87 uint32_t GetStoragePartitionRemovalMask(uint32_t web_view_removal_mask) { |
| 87 uint32_t mask = 0; | 88 uint32_t mask = 0; |
| 88 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_APPCACHE) | 89 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_APPCACHE) |
| 89 mask |= StoragePartition::REMOVE_DATA_MASK_APPCACHE; | 90 mask |= StoragePartition::REMOVE_DATA_MASK_APPCACHE; |
| 90 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_COOKIES) | 91 if (web_view_removal_mask & |
| 92 (webview::WEB_VIEW_REMOVE_DATA_MASK_COOKIES | |
| 93 webview::WEB_VIEW_REMOVE_DATA_MASK_SESSION_COOKIES | |
| 94 webview::WEB_VIEW_REMOVE_DATA_MASK_PERSISTENT_COOKIES)) { |
| 91 mask |= StoragePartition::REMOVE_DATA_MASK_COOKIES; | 95 mask |= StoragePartition::REMOVE_DATA_MASK_COOKIES; |
| 96 } |
| 92 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_FILE_SYSTEMS) | 97 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_FILE_SYSTEMS) |
| 93 mask |= StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS; | 98 mask |= StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS; |
| 94 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_INDEXEDDB) | 99 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_INDEXEDDB) |
| 95 mask |= StoragePartition::REMOVE_DATA_MASK_INDEXEDDB; | 100 mask |= StoragePartition::REMOVE_DATA_MASK_INDEXEDDB; |
| 96 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_LOCAL_STORAGE) | 101 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_LOCAL_STORAGE) |
| 97 mask |= StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE; | 102 mask |= StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE; |
| 98 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_WEBSQL) | 103 if (web_view_removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_WEBSQL) |
| 99 mask |= StoragePartition::REMOVE_DATA_MASK_WEBSQL; | 104 mask |= StoragePartition::REMOVE_DATA_MASK_WEBSQL; |
| 100 | 105 |
| 101 return mask; | 106 return mask; |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 | 423 |
| 419 void WebViewGuest::ClearDataInternal(base::Time remove_since, | 424 void WebViewGuest::ClearDataInternal(base::Time remove_since, |
| 420 uint32_t removal_mask, | 425 uint32_t removal_mask, |
| 421 const base::Closure& callback) { | 426 const base::Closure& callback) { |
| 422 uint32_t storage_partition_removal_mask = | 427 uint32_t storage_partition_removal_mask = |
| 423 GetStoragePartitionRemovalMask(removal_mask); | 428 GetStoragePartitionRemovalMask(removal_mask); |
| 424 if (!storage_partition_removal_mask) { | 429 if (!storage_partition_removal_mask) { |
| 425 callback.Run(); | 430 callback.Run(); |
| 426 return; | 431 return; |
| 427 } | 432 } |
| 433 |
| 434 content::StoragePartition::CookieMatcherFunction cookie_matcher; |
| 435 |
| 436 bool remove_session_cookies = |
| 437 !!(removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_SESSION_COOKIES); |
| 438 bool remove_persistent_cookies = |
| 439 !!(removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_PERSISTENT_COOKIES); |
| 440 bool remove_all_cookies = |
| 441 (!!(removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_COOKIES)) || |
| 442 (remove_session_cookies && remove_persistent_cookies); |
| 443 |
| 444 // Leaving the cookie_matcher unset will cause all cookies to be purged. |
| 445 if (!remove_all_cookies) { |
| 446 if (remove_session_cookies) { |
| 447 cookie_matcher = |
| 448 base::Bind([](const net::CanonicalCookie& cookie) -> bool { |
| 449 return !cookie.IsPersistent(); |
| 450 }); |
| 451 } else if (remove_persistent_cookies) { |
| 452 cookie_matcher = |
| 453 base::Bind([](const net::CanonicalCookie& cookie) -> bool { |
| 454 return cookie.IsPersistent(); |
| 455 }); |
| 456 } |
| 457 } |
| 458 |
| 428 content::StoragePartition* partition = | 459 content::StoragePartition* partition = |
| 429 content::BrowserContext::GetStoragePartition( | 460 content::BrowserContext::GetStoragePartition( |
| 430 web_contents()->GetBrowserContext(), | 461 web_contents()->GetBrowserContext(), |
| 431 web_contents()->GetSiteInstance()); | 462 web_contents()->GetSiteInstance()); |
| 432 partition->ClearData( | 463 partition->ClearData( |
| 433 storage_partition_removal_mask, | 464 storage_partition_removal_mask, |
| 434 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, GURL(), | 465 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 435 content::StoragePartition::OriginMatcherFunction(), remove_since, | 466 content::StoragePartition::OriginMatcherFunction(), cookie_matcher, |
| 436 base::Time::Now(), callback); | 467 remove_since, base::Time::Now(), callback); |
| 437 } | 468 } |
| 438 | 469 |
| 439 void WebViewGuest::GuestViewDidStopLoading() { | 470 void WebViewGuest::GuestViewDidStopLoading() { |
| 440 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 471 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 441 DispatchEventToView(base::MakeUnique<GuestViewEvent>(webview::kEventLoadStop, | 472 DispatchEventToView(base::MakeUnique<GuestViewEvent>(webview::kEventLoadStop, |
| 442 std::move(args))); | 473 std::move(args))); |
| 443 } | 474 } |
| 444 | 475 |
| 445 void WebViewGuest::EmbedderFullscreenToggled(bool entered_fullscreen) { | 476 void WebViewGuest::EmbedderFullscreenToggled(bool entered_fullscreen) { |
| 446 is_embedder_fullscreen_ = entered_fullscreen; | 477 is_embedder_fullscreen_ = entered_fullscreen; |
| (...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1559 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1529 DispatchEventToView(base::MakeUnique<GuestViewEvent>( | 1560 DispatchEventToView(base::MakeUnique<GuestViewEvent>( |
| 1530 webview::kEventExitFullscreen, std::move(args))); | 1561 webview::kEventExitFullscreen, std::move(args))); |
| 1531 } | 1562 } |
| 1532 // Since we changed fullscreen state, sending a Resize message ensures that | 1563 // Since we changed fullscreen state, sending a Resize message ensures that |
| 1533 // renderer/ sees the change. | 1564 // renderer/ sees the change. |
| 1534 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); | 1565 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); |
| 1535 } | 1566 } |
| 1536 | 1567 |
| 1537 } // namespace extensions | 1568 } // namespace extensions |
| OLD | NEW |