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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 FROM_HERE, | 228 FROM_HERE, |
228 base::Bind( | 229 base::Bind( |
229 &RemoveWebViewEventListenersOnIOThread, | 230 &RemoveWebViewEventListenersOnIOThread, |
230 browser_context, | 231 browser_context, |
231 embedder_process_id, | 232 embedder_process_id, |
232 view_instance_id)); | 233 view_instance_id)); |
233 | 234 |
234 // Clean up content scripts for the WebView. | 235 // Clean up content scripts for the WebView. |
235 auto csm = WebViewContentScriptManager::Get(browser_context); | 236 auto csm = WebViewContentScriptManager::Get(browser_context); |
236 csm->RemoveAllContentScriptsForWebView(embedder_process_id, view_instance_id); | 237 csm->RemoveAllContentScriptsForWebView(embedder_process_id, view_instance_id); |
| 238 |
| 239 // Allow an extensions browser client to potentially perform more cleanup. |
| 240 ExtensionsBrowserClient::Get()->CleanUpWebView(embedder_process_id, |
| 241 view_instance_id); |
237 } | 242 } |
238 | 243 |
239 // static | 244 // static |
240 GuestViewBase* WebViewGuest::Create(content::WebContents* owner_web_contents) { | 245 GuestViewBase* WebViewGuest::Create(content::WebContents* owner_web_contents) { |
241 return new WebViewGuest(owner_web_contents); | 246 return new WebViewGuest(owner_web_contents); |
242 } | 247 } |
243 | 248 |
244 // static | 249 // static |
245 bool WebViewGuest::GetGuestPartitionConfigForSite( | 250 bool WebViewGuest::GetGuestPartitionConfigForSite( |
246 const GURL& site, | 251 const GURL& site, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 return it->second; | 286 return it->second; |
282 | 287 |
283 auto rph = content::RenderProcessHost::FromID(embedder_process_id); | 288 auto rph = content::RenderProcessHost::FromID(embedder_process_id); |
284 int rules_registry_id = | 289 int rules_registry_id = |
285 RulesRegistryService::Get(rph->GetBrowserContext())-> | 290 RulesRegistryService::Get(rph->GetBrowserContext())-> |
286 GetNextRulesRegistryID(); | 291 GetNextRulesRegistryID(); |
287 web_view_key_to_id_map.Get()[key] = rules_registry_id; | 292 web_view_key_to_id_map.Get()[key] = rules_registry_id; |
288 return rules_registry_id; | 293 return rules_registry_id; |
289 } | 294 } |
290 | 295 |
291 // static | |
292 int WebViewGuest::GetViewInstanceId(WebContents* contents) { | |
293 auto guest = FromWebContents(contents); | |
294 if (!guest) | |
295 return guest_view::kInstanceIDNone; | |
296 | |
297 return guest->view_instance_id(); | |
298 } | |
299 | |
300 bool WebViewGuest::CanRunInDetachedState() const { | 296 bool WebViewGuest::CanRunInDetachedState() const { |
301 return true; | 297 return true; |
302 } | 298 } |
303 | 299 |
304 void WebViewGuest::CreateWebContents( | 300 void WebViewGuest::CreateWebContents( |
305 const base::DictionaryValue& create_params, | 301 const base::DictionaryValue& create_params, |
306 const WebContentsCreatedCallback& callback) { | 302 const WebContentsCreatedCallback& callback) { |
307 content::RenderProcessHost* owner_render_process_host = | 303 content::RenderProcessHost* owner_render_process_host = |
308 owner_web_contents()->GetRenderProcessHost(); | 304 owner_web_contents()->GetRenderProcessHost(); |
309 std::string storage_partition_id; | 305 std::string storage_partition_id; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 423 |
428 const char* WebViewGuest::GetAPINamespace() const { | 424 const char* WebViewGuest::GetAPINamespace() const { |
429 return webview::kAPINamespace; | 425 return webview::kAPINamespace; |
430 } | 426 } |
431 | 427 |
432 int WebViewGuest::GetTaskPrefix() const { | 428 int WebViewGuest::GetTaskPrefix() const { |
433 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; | 429 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; |
434 } | 430 } |
435 | 431 |
436 void WebViewGuest::GuestDestroyed() { | 432 void WebViewGuest::GuestDestroyed() { |
437 // Clean up custom context menu items for this guest. | |
438 if (web_view_guest_delegate_) | |
439 web_view_guest_delegate_->OnGuestDestroyed(); | |
440 RemoveWebViewStateFromIOThread(web_contents()); | 433 RemoveWebViewStateFromIOThread(web_contents()); |
441 } | 434 } |
442 | 435 |
443 void WebViewGuest::GuestReady() { | 436 void WebViewGuest::GuestReady() { |
444 // The guest RenderView should always live in an isolated guest process. | 437 // The guest RenderView should always live in an isolated guest process. |
445 CHECK(web_contents()->GetRenderProcessHost()->IsForGuestsOnly()); | 438 CHECK(web_contents()->GetRenderProcessHost()->IsForGuestsOnly()); |
446 Send(new ExtensionMsg_SetFrameName(web_contents()->GetRoutingID(), name_)); | 439 Send(new ExtensionMsg_SetFrameName(web_contents()->GetRoutingID(), name_)); |
447 | 440 |
448 // We don't want to accidentally set the opacity of an interstitial page. | 441 // We don't want to accidentally set the opacity of an interstitial page. |
449 // WebContents::GetRenderWidgetHostView will return the RWHV of an | 442 // WebContents::GetRenderWidgetHostView will return the RWHV of an |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1450 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1458 DispatchEventToView( | 1451 DispatchEventToView( |
1459 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); | 1452 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); |
1460 } | 1453 } |
1461 // Since we changed fullscreen state, sending a Resize message ensures that | 1454 // Since we changed fullscreen state, sending a Resize message ensures that |
1462 // renderer/ sees the change. | 1455 // renderer/ sees the change. |
1463 web_contents()->GetRenderViewHost()->WasResized(); | 1456 web_contents()->GetRenderViewHost()->WasResized(); |
1464 } | 1457 } |
1465 | 1458 |
1466 } // namespace extensions | 1459 } // namespace extensions |
OLD | NEW |