Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: extensions/browser/extension_web_contents_observer.h

Issue 1413853005: Track all extension frames in ProcessManager, inspect extensionoptions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits, treat hosted apps as extensions, no test flakiness Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // With OOPIF only the first notification is necessary.
45 // Without OOPIF, non-extension frames created by the Chrome extension are also
46 // registered at RenderFrameCreated. When the non-extension page is committed,
47 // we detect that the unexpected URL and unregister the frame.
32 class ExtensionWebContentsObserver 48 class ExtensionWebContentsObserver
33 : public content::WebContentsObserver, 49 : public content::WebContentsObserver,
34 public ExtensionFunctionDispatcher::Delegate { 50 public ExtensionFunctionDispatcher::Delegate {
35 public: 51 public:
36 // Returns the ExtensionWebContentsObserver for the given |web_contents|. 52 // Returns the ExtensionWebContentsObserver for the given |web_contents|.
37 static ExtensionWebContentsObserver* GetForWebContents( 53 static ExtensionWebContentsObserver* GetForWebContents(
38 content::WebContents* web_contents); 54 content::WebContents* web_contents);
39 55
40 ExtensionFunctionDispatcher* dispatcher() { return &dispatcher_; } 56 ExtensionFunctionDispatcher* dispatcher() { return &dispatcher_; }
41 57
(...skipping 11 matching lines...) Expand all
53 // ExtensionFunctionDispatcher::Delegate overrides. 69 // ExtensionFunctionDispatcher::Delegate overrides.
54 content::WebContents* GetAssociatedWebContents() const override; 70 content::WebContents* GetAssociatedWebContents() const override;
55 71
56 // content::WebContentsObserver overrides. 72 // content::WebContentsObserver overrides.
57 73
58 // A subclass should invoke this method to finish extension process setup. 74 // A subclass should invoke this method to finish extension process setup.
59 void RenderViewCreated(content::RenderViewHost* render_view_host) override; 75 void RenderViewCreated(content::RenderViewHost* render_view_host) override;
60 76
61 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; 77 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
62 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; 78 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
79 void DidCommitProvisionalLoadForFrame(
80 content::RenderFrameHost* render_frame_host,
81 const GURL& url,
82 ui::PageTransition transition_type) override;
83 void DidNavigateAnyFrame(content::RenderFrameHost* render_frame_host,
84 const content::LoadCommittedDetails& details,
85 const content::FrameNavigateParams& params) override;
63 86
64 // Subclasses should call this first before doing their own message handling. 87 // Subclasses should call this first before doing their own message handling.
65 bool OnMessageReceived(const IPC::Message& message, 88 bool OnMessageReceived(const IPC::Message& message,
66 content::RenderFrameHost* render_frame_host) override; 89 content::RenderFrameHost* render_frame_host) override;
67 90
68 // Per the documentation in WebContentsObserver, these two methods are invoked 91 // Per the documentation in WebContentsObserver, these two methods are invoked
69 // when a Pepper plugin instance is attached/detached in the page DOM. 92 // when a Pepper plugin instance is attached/detached in the page DOM.
70 void PepperInstanceCreated() override; 93 void PepperInstanceCreated() override;
71 void PepperInstanceDeleted() override; 94 void PepperInstanceDeleted() override;
72 95
73 // Returns the extension id associated with the given |render_frame_host|, or 96 // Returns the extension id associated with the given |render_frame_host|, or
74 // the empty string if there is none. 97 // the empty string if there is none.
75 std::string GetExtensionIdFromFrame( 98 std::string GetExtensionIdFromFrame(
76 content::RenderFrameHost* render_frame_host) const; 99 content::RenderFrameHost* render_frame_host) const;
77 100
78 // Returns the extension associated with the given |render_frame_host|, or 101 // Returns the extension associated with the given |render_frame_host|, or
79 // null if there is none. 102 // null if there is none.
103 // If |verify_url| is false, only the SiteInstance is taken into account.
104 // If |verify_url| is true, the frame's last committed URL is also used to
105 // improve the classification of the frame.
Devlin 2015/12/01 00:58:20 It sounds like there's a missing line here: // TOD
robwu 2015/12/01 17:19:57 Until the last patchset, I also thought that verif
80 const Extension* GetExtensionFromFrame( 106 const Extension* GetExtensionFromFrame(
81 content::RenderFrameHost* render_frame_host) const; 107 content::RenderFrameHost* render_frame_host,
108 bool verify_url) const;
82 109
83 // TODO(devlin): Remove these once callers are updated to use the FromFrame 110 // TODO(devlin): Remove these once callers are updated to use the FromFrame
84 // equivalents. 111 // equivalents.
85 // Returns the extension or app associated with a render view host. Returns 112 // 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. 113 // NULL if the render view host is not for a valid extension.
87 const Extension* GetExtension(content::RenderViewHost* render_view_host); 114 const Extension* GetExtension(content::RenderViewHost* render_view_host);
88 // Returns the extension or app ID associated with a render view host. Returns 115 // 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. 116 // the empty string if the render view host is not for a valid extension.
90 static std::string GetExtensionId(content::RenderViewHost* render_view_host); 117 static std::string GetExtensionId(content::RenderViewHost* render_view_host);
91 118
92 private: 119 private:
93 void OnRequest(content::RenderFrameHost* render_frame_host, 120 void OnRequest(content::RenderFrameHost* render_frame_host,
94 const ExtensionHostMsg_Request_Params& params); 121 const ExtensionHostMsg_Request_Params& params);
95 122
96 // A helper function for initializing render frames at the creation of the 123 // A helper function for initializing render frames at the creation of the
97 // observer. 124 // observer.
98 void InitializeFrameHelper(content::RenderFrameHost* render_frame_host); 125 void InitializeFrameHelper(content::RenderFrameHost* render_frame_host);
99 126
100 // The BrowserContext associated with the WebContents being observed. 127 // The BrowserContext associated with the WebContents being observed.
101 content::BrowserContext* browser_context_; 128 content::BrowserContext* browser_context_;
102 129
103 ExtensionFunctionDispatcher dispatcher_; 130 ExtensionFunctionDispatcher dispatcher_;
104 131
105 DISALLOW_COPY_AND_ASSIGN(ExtensionWebContentsObserver); 132 DISALLOW_COPY_AND_ASSIGN(ExtensionWebContentsObserver);
106 }; 133 };
107 134
108 } // namespace extensions 135 } // namespace extensions
109 136
110 #endif // EXTENSIONS_BROWSER_EXTENSION_WEB_CONTENTS_OBSERVER_H_ 137 #endif // EXTENSIONS_BROWSER_EXTENSION_WEB_CONTENTS_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698