| 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 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/user_metrics.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "components/guest_view/browser/guest_view_event.h" | 17 #include "components/guest_view/browser/guest_view_event.h" |
| 17 #include "components/guest_view/browser/guest_view_manager.h" | 18 #include "components/guest_view/browser/guest_view_manager.h" |
| 18 #include "components/guest_view/common/guest_view_constants.h" | 19 #include "components/guest_view/common/guest_view_constants.h" |
| 19 #include "components/web_cache/browser/web_cache_manager.h" | 20 #include "components/web_cache/browser/web_cache_manager.h" |
| 20 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/child_process_security_policy.h" | 23 #include "content/public/browser/child_process_security_policy.h" |
| 23 #include "content/public/browser/native_web_keyboard_event.h" | 24 #include "content/public/browser/native_web_keyboard_event.h" |
| 24 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
| 25 #include "content/public/browser/navigation_handle.h" | 26 #include "content/public/browser/navigation_handle.h" |
| 26 #include "content/public/browser/notification_details.h" | 27 #include "content/public/browser/notification_details.h" |
| 27 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
| 29 #include "content/public/browser/notification_types.h" | 30 #include "content/public/browser/notification_types.h" |
| 30 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
| 31 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 32 #include "content/public/browser/render_widget_host.h" | 33 #include "content/public/browser/render_widget_host.h" |
| 33 #include "content/public/browser/render_widget_host_view.h" | 34 #include "content/public/browser/render_widget_host_view.h" |
| 34 #include "content/public/browser/resource_request_details.h" | 35 #include "content/public/browser/resource_request_details.h" |
| 35 #include "content/public/browser/site_instance.h" | 36 #include "content/public/browser/site_instance.h" |
| 36 #include "content/public/browser/storage_partition.h" | 37 #include "content/public/browser/storage_partition.h" |
| 37 #include "content/public/browser/user_metrics.h" | |
| 38 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
| 39 #include "content/public/browser/web_contents_delegate.h" | 39 #include "content/public/browser/web_contents_delegate.h" |
| 40 #include "content/public/common/browser_side_navigation_policy.h" | 40 #include "content/public/common/browser_side_navigation_policy.h" |
| 41 #include "content/public/common/media_stream_request.h" | 41 #include "content/public/common/media_stream_request.h" |
| 42 #include "content/public/common/page_zoom.h" | 42 #include "content/public/common/page_zoom.h" |
| 43 #include "content/public/common/result_codes.h" | 43 #include "content/public/common/result_codes.h" |
| 44 #include "content/public/common/stop_find_action.h" | 44 #include "content/public/common/stop_find_action.h" |
| 45 #include "content/public/common/url_constants.h" | 45 #include "content/public/common/url_constants.h" |
| 46 #include "extensions/browser/api/declarative/rules_registry_service.h" | 46 #include "extensions/browser/api/declarative/rules_registry_service.h" |
| 47 #include "extensions/browser/api/extensions_api_client.h" | 47 #include "extensions/browser/api/extensions_api_client.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 RenderProcessHost* owner_render_process_host = | 328 RenderProcessHost* owner_render_process_host = |
| 329 owner_web_contents()->GetRenderProcessHost(); | 329 owner_web_contents()->GetRenderProcessHost(); |
| 330 std::string storage_partition_id; | 330 std::string storage_partition_id; |
| 331 bool persist_storage = false; | 331 bool persist_storage = false; |
| 332 ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); | 332 ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); |
| 333 // Validate that the partition id coming from the renderer is valid UTF-8, | 333 // Validate that the partition id coming from the renderer is valid UTF-8, |
| 334 // since we depend on this in other parts of the code, such as FilePath | 334 // since we depend on this in other parts of the code, such as FilePath |
| 335 // creation. If the validation fails, treat it as a bad message and kill the | 335 // creation. If the validation fails, treat it as a bad message and kill the |
| 336 // renderer process. | 336 // renderer process. |
| 337 if (!base::IsStringUTF8(storage_partition_id)) { | 337 if (!base::IsStringUTF8(storage_partition_id)) { |
| 338 content::RecordAction( | 338 base::RecordAction(base::UserMetricsAction("BadMessageTerminate_BPGM")); |
| 339 base::UserMetricsAction("BadMessageTerminate_BPGM")); | |
| 340 owner_render_process_host->Shutdown(content::RESULT_CODE_KILLED_BAD_MESSAGE, | 339 owner_render_process_host->Shutdown(content::RESULT_CODE_KILLED_BAD_MESSAGE, |
| 341 false); | 340 false); |
| 342 callback.Run(nullptr); | 341 callback.Run(nullptr); |
| 343 return; | 342 return; |
| 344 } | 343 } |
| 345 std::string url_encoded_partition = net::EscapeQueryParamValue( | 344 std::string url_encoded_partition = net::EscapeQueryParamValue( |
| 346 storage_partition_id, false); | 345 storage_partition_id, false); |
| 347 std::string partition_domain = GetOwnerSiteURL().host(); | 346 std::string partition_domain = GetOwnerSiteURL().host(); |
| 348 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", | 347 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", |
| 349 content::kGuestScheme, | 348 content::kGuestScheme, |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 // TODO(fsamuel): Don't check for repost because we don't want to show | 753 // TODO(fsamuel): Don't check for repost because we don't want to show |
| 755 // Chromium's repost warning. We might want to implement a separate API | 754 // Chromium's repost warning. We might want to implement a separate API |
| 756 // for registering a callback if a repost is about to happen. | 755 // for registering a callback if a repost is about to happen. |
| 757 web_contents()->GetController().Reload(content::ReloadType::NORMAL, false); | 756 web_contents()->GetController().Reload(content::ReloadType::NORMAL, false); |
| 758 } | 757 } |
| 759 | 758 |
| 760 void WebViewGuest::SetUserAgentOverride( | 759 void WebViewGuest::SetUserAgentOverride( |
| 761 const std::string& user_agent_override) { | 760 const std::string& user_agent_override) { |
| 762 is_overriding_user_agent_ = !user_agent_override.empty(); | 761 is_overriding_user_agent_ = !user_agent_override.empty(); |
| 763 if (is_overriding_user_agent_) { | 762 if (is_overriding_user_agent_) { |
| 764 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA")); | 763 base::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA")); |
| 765 } | 764 } |
| 766 web_contents()->SetUserAgentOverride(user_agent_override); | 765 web_contents()->SetUserAgentOverride(user_agent_override); |
| 767 } | 766 } |
| 768 | 767 |
| 769 void WebViewGuest::Stop() { | 768 void WebViewGuest::Stop() { |
| 770 web_contents()->Stop(); | 769 web_contents()->Stop(); |
| 771 } | 770 } |
| 772 | 771 |
| 773 void WebViewGuest::Terminate() { | 772 void WebViewGuest::Terminate() { |
| 774 content::RecordAction(UserMetricsAction("WebView.Guest.Terminate")); | 773 base::RecordAction(UserMetricsAction("WebView.Guest.Terminate")); |
| 775 base::ProcessHandle process_handle = | 774 base::ProcessHandle process_handle = |
| 776 web_contents()->GetRenderProcessHost()->GetHandle(); | 775 web_contents()->GetRenderProcessHost()->GetHandle(); |
| 777 if (process_handle) | 776 if (process_handle) |
| 778 web_contents()->GetRenderProcessHost()->Shutdown( | 777 web_contents()->GetRenderProcessHost()->Shutdown( |
| 779 content::RESULT_CODE_KILLED, false); | 778 content::RESULT_CODE_KILLED, false); |
| 780 } | 779 } |
| 781 | 780 |
| 782 bool WebViewGuest::ClearData(base::Time remove_since, | 781 bool WebViewGuest::ClearData(base::Time remove_since, |
| 783 uint32_t removal_mask, | 782 uint32_t removal_mask, |
| 784 const base::Closure& callback) { | 783 const base::Closure& callback) { |
| 785 content::RecordAction(UserMetricsAction("WebView.Guest.ClearData")); | 784 base::RecordAction(UserMetricsAction("WebView.Guest.ClearData")); |
| 786 content::StoragePartition* partition = | 785 content::StoragePartition* partition = |
| 787 content::BrowserContext::GetStoragePartition( | 786 content::BrowserContext::GetStoragePartition( |
| 788 web_contents()->GetBrowserContext(), | 787 web_contents()->GetBrowserContext(), |
| 789 web_contents()->GetSiteInstance()); | 788 web_contents()->GetSiteInstance()); |
| 790 | 789 |
| 791 if (!partition) | 790 if (!partition) |
| 792 return false; | 791 return false; |
| 793 | 792 |
| 794 if (removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_CACHE) { | 793 if (removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_CACHE) { |
| 795 // First clear http cache data and then clear the rest in | 794 // First clear http cache data and then clear the rest in |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1555 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1554 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1556 DispatchEventToView(base::MakeUnique<GuestViewEvent>( | 1555 DispatchEventToView(base::MakeUnique<GuestViewEvent>( |
| 1557 webview::kEventExitFullscreen, std::move(args))); | 1556 webview::kEventExitFullscreen, std::move(args))); |
| 1558 } | 1557 } |
| 1559 // Since we changed fullscreen state, sending a Resize message ensures that | 1558 // Since we changed fullscreen state, sending a Resize message ensures that |
| 1560 // renderer/ sees the change. | 1559 // renderer/ sees the change. |
| 1561 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); | 1560 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); |
| 1562 } | 1561 } |
| 1563 | 1562 |
| 1564 } // namespace extensions | 1563 } // namespace extensions |
| OLD | NEW |