| 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 "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 "components/browsing_data/storage_partition_http_cache_data_remover.h" | 10 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "content/public/common/media_stream_request.h" | 33 #include "content/public/common/media_stream_request.h" |
| 34 #include "content/public/common/page_zoom.h" | 34 #include "content/public/common/page_zoom.h" |
| 35 #include "content/public/common/result_codes.h" | 35 #include "content/public/common/result_codes.h" |
| 36 #include "content/public/common/stop_find_action.h" | 36 #include "content/public/common/stop_find_action.h" |
| 37 #include "content/public/common/url_constants.h" | 37 #include "content/public/common/url_constants.h" |
| 38 #include "extensions/browser/api/declarative/rules_registry_service.h" | 38 #include "extensions/browser/api/declarative/rules_registry_service.h" |
| 39 #include "extensions/browser/api/extensions_api_client.h" | 39 #include "extensions/browser/api/extensions_api_client.h" |
| 40 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h" | 40 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h" |
| 41 #include "extensions/browser/api/web_request/web_request_api.h" | 41 #include "extensions/browser/api/web_request/web_request_api.h" |
| 42 #include "extensions/browser/extension_system.h" | 42 #include "extensions/browser/extension_system.h" |
| 43 #include "extensions/browser/extensions_browser_client.h" |
| 43 #include "extensions/browser/guest_view/web_view/web_view_constants.h" | 44 #include "extensions/browser/guest_view/web_view/web_view_constants.h" |
| 44 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager
.h" | 45 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager
.h" |
| 45 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" | 46 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 46 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" | 47 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" |
| 47 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 48 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
| 48 #include "extensions/common/constants.h" | 49 #include "extensions/common/constants.h" |
| 49 #include "extensions/common/extension_messages.h" | 50 #include "extensions/common/extension_messages.h" |
| 50 #include "extensions/strings/grit/extensions_strings.h" | 51 #include "extensions/strings/grit/extensions_strings.h" |
| 51 #include "ipc/ipc_message_macros.h" | 52 #include "ipc/ipc_message_macros.h" |
| 52 #include "net/base/escape.h" | 53 #include "net/base/escape.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 FROM_HERE, | 227 FROM_HERE, |
| 227 base::Bind( | 228 base::Bind( |
| 228 &RemoveWebViewEventListenersOnIOThread, | 229 &RemoveWebViewEventListenersOnIOThread, |
| 229 browser_context, | 230 browser_context, |
| 230 embedder_process_id, | 231 embedder_process_id, |
| 231 view_instance_id)); | 232 view_instance_id)); |
| 232 | 233 |
| 233 // Clean up content scripts for the WebView. | 234 // Clean up content scripts for the WebView. |
| 234 auto csm = WebViewContentScriptManager::Get(browser_context); | 235 auto csm = WebViewContentScriptManager::Get(browser_context); |
| 235 csm->RemoveAllContentScriptsForWebView(embedder_process_id, view_instance_id); | 236 csm->RemoveAllContentScriptsForWebView(embedder_process_id, view_instance_id); |
| 237 |
| 238 // Allow an extensions browser client to potentially perform more cleanup. |
| 239 ExtensionsBrowserClient::Get()->CleanUpWebView(embedder_process_id, |
| 240 view_instance_id); |
| 236 } | 241 } |
| 237 | 242 |
| 238 // static | 243 // static |
| 239 GuestViewBase* WebViewGuest::Create(content::WebContents* owner_web_contents) { | 244 GuestViewBase* WebViewGuest::Create(content::WebContents* owner_web_contents) { |
| 240 return new WebViewGuest(owner_web_contents); | 245 return new WebViewGuest(owner_web_contents); |
| 241 } | 246 } |
| 242 | 247 |
| 243 // static | 248 // static |
| 244 bool WebViewGuest::GetGuestPartitionConfigForSite( | 249 bool WebViewGuest::GetGuestPartitionConfigForSite( |
| 245 const GURL& site, | 250 const GURL& site, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 return it->second; | 285 return it->second; |
| 281 | 286 |
| 282 auto rph = content::RenderProcessHost::FromID(embedder_process_id); | 287 auto rph = content::RenderProcessHost::FromID(embedder_process_id); |
| 283 int rules_registry_id = | 288 int rules_registry_id = |
| 284 RulesRegistryService::Get(rph->GetBrowserContext())-> | 289 RulesRegistryService::Get(rph->GetBrowserContext())-> |
| 285 GetNextRulesRegistryID(); | 290 GetNextRulesRegistryID(); |
| 286 web_view_key_to_id_map.Get()[key] = rules_registry_id; | 291 web_view_key_to_id_map.Get()[key] = rules_registry_id; |
| 287 return rules_registry_id; | 292 return rules_registry_id; |
| 288 } | 293 } |
| 289 | 294 |
| 290 // static | |
| 291 int WebViewGuest::GetViewInstanceId(WebContents* contents) { | |
| 292 auto guest = FromWebContents(contents); | |
| 293 if (!guest) | |
| 294 return guest_view::kInstanceIDNone; | |
| 295 | |
| 296 return guest->view_instance_id(); | |
| 297 } | |
| 298 | |
| 299 bool WebViewGuest::CanRunInDetachedState() const { | 295 bool WebViewGuest::CanRunInDetachedState() const { |
| 300 return true; | 296 return true; |
| 301 } | 297 } |
| 302 | 298 |
| 303 void WebViewGuest::CreateWebContents( | 299 void WebViewGuest::CreateWebContents( |
| 304 const base::DictionaryValue& create_params, | 300 const base::DictionaryValue& create_params, |
| 305 const WebContentsCreatedCallback& callback) { | 301 const WebContentsCreatedCallback& callback) { |
| 306 content::RenderProcessHost* owner_render_process_host = | 302 content::RenderProcessHost* owner_render_process_host = |
| 307 owner_web_contents()->GetRenderProcessHost(); | 303 owner_web_contents()->GetRenderProcessHost(); |
| 308 std::string storage_partition_id; | 304 std::string storage_partition_id; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 422 |
| 427 const char* WebViewGuest::GetAPINamespace() const { | 423 const char* WebViewGuest::GetAPINamespace() const { |
| 428 return webview::kAPINamespace; | 424 return webview::kAPINamespace; |
| 429 } | 425 } |
| 430 | 426 |
| 431 int WebViewGuest::GetTaskPrefix() const { | 427 int WebViewGuest::GetTaskPrefix() const { |
| 432 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; | 428 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; |
| 433 } | 429 } |
| 434 | 430 |
| 435 void WebViewGuest::GuestDestroyed() { | 431 void WebViewGuest::GuestDestroyed() { |
| 436 // Clean up custom context menu items for this guest. | |
| 437 if (web_view_guest_delegate_) | |
| 438 web_view_guest_delegate_->OnGuestDestroyed(); | |
| 439 RemoveWebViewStateFromIOThread(web_contents()); | 432 RemoveWebViewStateFromIOThread(web_contents()); |
| 440 } | 433 } |
| 441 | 434 |
| 442 void WebViewGuest::GuestReady() { | 435 void WebViewGuest::GuestReady() { |
| 443 // The guest RenderView should always live in an isolated guest process. | 436 // The guest RenderView should always live in an isolated guest process. |
| 444 CHECK(web_contents()->GetRenderProcessHost()->IsForGuestsOnly()); | 437 CHECK(web_contents()->GetRenderProcessHost()->IsForGuestsOnly()); |
| 445 Send(new ExtensionMsg_SetFrameName(web_contents()->GetRoutingID(), name_)); | 438 Send(new ExtensionMsg_SetFrameName(web_contents()->GetRoutingID(), name_)); |
| 446 | 439 |
| 447 // We don't want to accidentally set the opacity of an interstitial page. | 440 // We don't want to accidentally set the opacity of an interstitial page. |
| 448 // WebContents::GetRenderWidgetHostView will return the RWHV of an | 441 // WebContents::GetRenderWidgetHostView will return the RWHV of an |
| (...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1449 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1457 DispatchEventToView( | 1450 DispatchEventToView( |
| 1458 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); | 1451 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); |
| 1459 } | 1452 } |
| 1460 // Since we changed fullscreen state, sending a Resize message ensures that | 1453 // Since we changed fullscreen state, sending a Resize message ensures that |
| 1461 // renderer/ sees the change. | 1454 // renderer/ sees the change. |
| 1462 web_contents()->GetRenderViewHost()->WasResized(); | 1455 web_contents()->GetRenderViewHost()->WasResized(); |
| 1463 } | 1456 } |
| 1464 | 1457 |
| 1465 } // namespace extensions | 1458 } // namespace extensions |
| OLD | NEW |