| 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 #ifndef EXTENSIONS_BROWSER_EXTENSION_WEB_CONTENTS_OBSERVER_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_WEB_CONTENTS_OBSERVER_H_ |
| 6 #define EXTENSIONS_BROWSER_EXTENSION_WEB_CONTENTS_OBSERVER_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_WEB_CONTENTS_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 class Extension; | 22 class Extension; |
| 23 | 23 |
| 24 // A web contents observer used for renderer and extension processes. Grants the | 24 // A web contents observer used for renderer and extension processes. Grants the |
| 25 // renderer access to certain URL scheme patterns for extensions and notifies | 25 // renderer access to certain URL scheme patterns for extensions and notifies |
| 26 // the renderer that the extension was loaded. | 26 // the renderer that the extension was loaded. |
| 27 // | 27 // |
| 28 // Extension system embedders must create an instance for every extension | 28 // Extension system embedders must create an instance for every extension |
| 29 // WebContents. It must be a subclass so that creating an instance via | 29 // WebContents. It must be a subclass so that creating an instance via |
| 30 // content::WebContentsUserData::CreateForWebContents() provides an object of | 30 // content::WebContentsUserData::CreateForWebContents() provides an object of |
| 31 // the correct type. For an example, see ChromeExtensionWebContentsObserver. | 31 // the correct type. For an example, see ChromeExtensionWebContentsObserver. |
| 32 // |
| 33 // This class is responsible for maintaining the registrations of extension |
| 34 // frames with the ProcessManager. Only frames in an extension process are |
| 35 // registered. If out-of-process frames are enabled, every frame hosts a |
| 36 // chrome-extension: page. Otherwise non-extension frames may erroneously be |
| 37 // registered, but only briefly until they are correctly classified. This is |
| 38 // achieved using the following notifications: |
| 39 // 1. RenderFrameCreated - registers all new frames in extension processes. |
| 40 // 2. DidCommitProvisionalLoadForFrame - unregisters non-extension frames. |
| 41 // 3. DidNavigateAnyFrame - registers extension frames if they had been |
| 42 // unregistered. |
| 43 // |
| 44 // Without OOPIF, non-extension frames created by the Chrome extension are also |
| 45 // registered at RenderFrameCreated. When the non-extension page is committed, |
| 46 // we detect that the unexpected URL and unregister the frame. |
| 47 // With OOPIF only the first notification is sufficient in most cases, except |
| 48 // for sandboxed frames with a unique origin. |
| 32 class ExtensionWebContentsObserver | 49 class ExtensionWebContentsObserver |
| 33 : public content::WebContentsObserver, | 50 : public content::WebContentsObserver, |
| 34 public ExtensionFunctionDispatcher::Delegate { | 51 public ExtensionFunctionDispatcher::Delegate { |
| 35 public: | 52 public: |
| 36 // Returns the ExtensionWebContentsObserver for the given |web_contents|. | 53 // Returns the ExtensionWebContentsObserver for the given |web_contents|. |
| 37 static ExtensionWebContentsObserver* GetForWebContents( | 54 static ExtensionWebContentsObserver* GetForWebContents( |
| 38 content::WebContents* web_contents); | 55 content::WebContents* web_contents); |
| 39 | 56 |
| 40 ExtensionFunctionDispatcher* dispatcher() { return &dispatcher_; } | 57 ExtensionFunctionDispatcher* dispatcher() { return &dispatcher_; } |
| 41 | 58 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 53 // ExtensionFunctionDispatcher::Delegate overrides. | 70 // ExtensionFunctionDispatcher::Delegate overrides. |
| 54 content::WebContents* GetAssociatedWebContents() const override; | 71 content::WebContents* GetAssociatedWebContents() const override; |
| 55 | 72 |
| 56 // content::WebContentsObserver overrides. | 73 // content::WebContentsObserver overrides. |
| 57 | 74 |
| 58 // A subclass should invoke this method to finish extension process setup. | 75 // A subclass should invoke this method to finish extension process setup. |
| 59 void RenderViewCreated(content::RenderViewHost* render_view_host) override; | 76 void RenderViewCreated(content::RenderViewHost* render_view_host) override; |
| 60 | 77 |
| 61 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; | 78 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
| 62 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 79 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
| 80 void DidCommitProvisionalLoadForFrame( |
| 81 content::RenderFrameHost* render_frame_host, |
| 82 const GURL& url, |
| 83 ui::PageTransition transition_type) override; |
| 84 void DidNavigateAnyFrame(content::RenderFrameHost* render_frame_host, |
| 85 const content::LoadCommittedDetails& details, |
| 86 const content::FrameNavigateParams& params) override; |
| 63 | 87 |
| 64 // Subclasses should call this first before doing their own message handling. | 88 // Subclasses should call this first before doing their own message handling. |
| 65 bool OnMessageReceived(const IPC::Message& message, | 89 bool OnMessageReceived(const IPC::Message& message, |
| 66 content::RenderFrameHost* render_frame_host) override; | 90 content::RenderFrameHost* render_frame_host) override; |
| 67 | 91 |
| 68 // Per the documentation in WebContentsObserver, these two methods are invoked | 92 // Per the documentation in WebContentsObserver, these two methods are invoked |
| 69 // when a Pepper plugin instance is attached/detached in the page DOM. | 93 // when a Pepper plugin instance is attached/detached in the page DOM. |
| 70 void PepperInstanceCreated() override; | 94 void PepperInstanceCreated() override; |
| 71 void PepperInstanceDeleted() override; | 95 void PepperInstanceDeleted() override; |
| 72 | 96 |
| 73 // Returns the extension id associated with the given |render_frame_host|, or | 97 // Returns the extension id associated with the given |render_frame_host|, or |
| 74 // the empty string if there is none. | 98 // the empty string if there is none. |
| 75 std::string GetExtensionIdFromFrame( | 99 std::string GetExtensionIdFromFrame( |
| 76 content::RenderFrameHost* render_frame_host) const; | 100 content::RenderFrameHost* render_frame_host) const; |
| 77 | 101 |
| 78 // Returns the extension associated with the given |render_frame_host|, or | 102 // Returns the extension associated with the given |render_frame_host|, or |
| 79 // null if there is none. | 103 // null if there is none. |
| 104 // If |verify_url| is false, only the SiteInstance is taken into account. |
| 105 // If |verify_url| is true, the frame's last committed URL is also used to |
| 106 // improve the classification of the frame. |
| 80 const Extension* GetExtensionFromFrame( | 107 const Extension* GetExtensionFromFrame( |
| 81 content::RenderFrameHost* render_frame_host) const; | 108 content::RenderFrameHost* render_frame_host, |
| 109 bool verify_url) const; |
| 82 | 110 |
| 83 // TODO(devlin): Remove these once callers are updated to use the FromFrame | 111 // TODO(devlin): Remove these once callers are updated to use the FromFrame |
| 84 // equivalents. | 112 // equivalents. |
| 85 // Returns the extension or app associated with a render view host. Returns | 113 // Returns the extension or app associated with a render view host. Returns |
| 86 // NULL if the render view host is not for a valid extension. | 114 // NULL if the render view host is not for a valid extension. |
| 87 const Extension* GetExtension(content::RenderViewHost* render_view_host); | 115 const Extension* GetExtension(content::RenderViewHost* render_view_host); |
| 88 // Returns the extension or app ID associated with a render view host. Returns | 116 // Returns the extension or app ID associated with a render view host. Returns |
| 89 // the empty string if the render view host is not for a valid extension. | 117 // the empty string if the render view host is not for a valid extension. |
| 90 static std::string GetExtensionId(content::RenderViewHost* render_view_host); | 118 static std::string GetExtensionId(content::RenderViewHost* render_view_host); |
| 91 | 119 |
| 92 private: | 120 private: |
| 93 void OnRequest(content::RenderFrameHost* render_frame_host, | 121 void OnRequest(content::RenderFrameHost* render_frame_host, |
| 94 const ExtensionHostMsg_Request_Params& params); | 122 const ExtensionHostMsg_Request_Params& params); |
| 95 | 123 |
| 96 // A helper function for initializing render frames at the creation of the | 124 // A helper function for initializing render frames at the creation of the |
| 97 // observer. | 125 // observer. |
| 98 void InitializeFrameHelper(content::RenderFrameHost* render_frame_host); | 126 void InitializeFrameHelper(content::RenderFrameHost* render_frame_host); |
| 99 | 127 |
| 100 // The BrowserContext associated with the WebContents being observed. | 128 // The BrowserContext associated with the WebContents being observed. |
| 101 content::BrowserContext* browser_context_; | 129 content::BrowserContext* browser_context_; |
| 102 | 130 |
| 103 ExtensionFunctionDispatcher dispatcher_; | 131 ExtensionFunctionDispatcher dispatcher_; |
| 104 | 132 |
| 105 DISALLOW_COPY_AND_ASSIGN(ExtensionWebContentsObserver); | 133 DISALLOW_COPY_AND_ASSIGN(ExtensionWebContentsObserver); |
| 106 }; | 134 }; |
| 107 | 135 |
| 108 } // namespace extensions | 136 } // namespace extensions |
| 109 | 137 |
| 110 #endif // EXTENSIONS_BROWSER_EXTENSION_WEB_CONTENTS_OBSERVER_H_ | 138 #endif // EXTENSIONS_BROWSER_EXTENSION_WEB_CONTENTS_OBSERVER_H_ |
| OLD | NEW |