| 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/extension_web_contents_observer.h" | 5 #include "extensions/browser/extension_web_contents_observer.h" |
| 6 | 6 |
| 7 #include "content/public/browser/child_process_security_policy.h" | 7 #include "content/public/browser/child_process_security_policy.h" |
| 8 #include "content/public/browser/navigation_details.h" | 8 #include "content/public/browser/navigation_details.h" |
| 9 #include "content/public/browser/render_frame_host.h" | 9 #include "content/public/browser/render_frame_host.h" |
| 10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
| 11 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/browser/site_instance.h" | 12 #include "content/public/browser/site_instance.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/common/url_constants.h" | 14 #include "content/public/common/url_constants.h" |
| 15 #include "extensions/browser/extension_api_frame_id_map.h" |
| 15 #include "extensions/browser/extension_prefs.h" | 16 #include "extensions/browser/extension_prefs.h" |
| 16 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
| 17 #include "extensions/browser/extensions_browser_client.h" | 18 #include "extensions/browser/extensions_browser_client.h" |
| 18 #include "extensions/browser/mojo/service_registration.h" | 19 #include "extensions/browser/mojo/service_registration.h" |
| 19 #include "extensions/browser/process_manager.h" | 20 #include "extensions/browser/process_manager.h" |
| 20 #include "extensions/browser/view_type_utils.h" | 21 #include "extensions/browser/view_type_utils.h" |
| 21 #include "extensions/common/constants.h" | 22 #include "extensions/common/constants.h" |
| 22 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
| 23 #include "extensions/common/extension_messages.h" | 24 #include "extensions/common/extension_messages.h" |
| 24 #include "extensions/common/view_type.h" | 25 #include "extensions/common/view_type.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // refactoring this isn't trivial to do, and this way is simpler. | 104 // refactoring this isn't trivial to do, and this way is simpler. |
| 104 // | 105 // |
| 105 // Plus, we can delete the concept of activating an extension once site | 106 // Plus, we can delete the concept of activating an extension once site |
| 106 // isolation is turned on. | 107 // isolation is turned on. |
| 107 render_view_host->Send(new ExtensionMsg_ActivateExtension(extension->id())); | 108 render_view_host->Send(new ExtensionMsg_ActivateExtension(extension->id())); |
| 108 } | 109 } |
| 109 | 110 |
| 110 void ExtensionWebContentsObserver::RenderFrameCreated( | 111 void ExtensionWebContentsObserver::RenderFrameCreated( |
| 111 content::RenderFrameHost* render_frame_host) { | 112 content::RenderFrameHost* render_frame_host) { |
| 112 InitializeRenderFrame(render_frame_host); | 113 InitializeRenderFrame(render_frame_host); |
| 114 |
| 115 // Optimization: Look up the extension API frame ID to force the mapping to be |
| 116 // cached. This minimizes the number of IO->UI->IO thread hops when the ID is |
| 117 // looked up again on the IO thread for the webRequest API. |
| 118 ExtensionApiFrameIdMap::Get()->CacheFrameId(render_frame_host); |
| 113 } | 119 } |
| 114 | 120 |
| 115 void ExtensionWebContentsObserver::RenderFrameDeleted( | 121 void ExtensionWebContentsObserver::RenderFrameDeleted( |
| 116 content::RenderFrameHost* render_frame_host) { | 122 content::RenderFrameHost* render_frame_host) { |
| 117 ProcessManager::Get(browser_context_) | 123 ProcessManager::Get(browser_context_) |
| 118 ->UnregisterRenderFrameHost(render_frame_host); | 124 ->UnregisterRenderFrameHost(render_frame_host); |
| 125 ExtensionApiFrameIdMap::Get()->RemoveFrameId(render_frame_host); |
| 119 } | 126 } |
| 120 | 127 |
| 121 void ExtensionWebContentsObserver::DidCommitProvisionalLoadForFrame( | 128 void ExtensionWebContentsObserver::DidCommitProvisionalLoadForFrame( |
| 122 content::RenderFrameHost* render_frame_host, | 129 content::RenderFrameHost* render_frame_host, |
| 123 const GURL& url, | 130 const GURL& url, |
| 124 ui::PageTransition transition_type) { | 131 ui::PageTransition transition_type) { |
| 125 ProcessManager* pm = ProcessManager::Get(browser_context_); | 132 ProcessManager* pm = ProcessManager::Get(browser_context_); |
| 126 | 133 |
| 127 if (pm->IsRenderFrameHostRegistered(render_frame_host)) { | 134 if (pm->IsRenderFrameHostRegistered(render_frame_host)) { |
| 128 const Extension* frame_extension = | 135 const Extension* frame_extension = |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 // Since this is called for all existing RenderFrameHosts during the | 279 // Since this is called for all existing RenderFrameHosts during the |
| 273 // ExtensionWebContentsObserver's creation, it's possible that not all hosts | 280 // ExtensionWebContentsObserver's creation, it's possible that not all hosts |
| 274 // are ready. | 281 // are ready. |
| 275 // We only initialize the frame if the renderer counterpart is live; otherwise | 282 // We only initialize the frame if the renderer counterpart is live; otherwise |
| 276 // we wait for the RenderFrameCreated notification. | 283 // we wait for the RenderFrameCreated notification. |
| 277 if (render_frame_host->IsRenderFrameLive()) | 284 if (render_frame_host->IsRenderFrameLive()) |
| 278 InitializeRenderFrame(render_frame_host); | 285 InitializeRenderFrame(render_frame_host); |
| 279 } | 286 } |
| 280 | 287 |
| 281 } // namespace extensions | 288 } // namespace extensions |
| OLD | NEW |