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

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

Issue 1169223002: [Extensions] Clean up the handling of ExtensionHostMsg_Request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 5 years, 6 months 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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "content/public/browser/web_contents_observer.h" 12 #include "content/public/browser/web_contents_observer.h"
13 #include "extensions/browser/extension_function_dispatcher.h"
13 14
14 namespace content { 15 namespace content {
15 class BrowserContext; 16 class BrowserContext;
16 class RenderViewHost; 17 class RenderViewHost;
17 class WebContents; 18 class WebContents;
18 } 19 }
19 20
20 namespace extensions { 21 namespace extensions {
21 class Extension; 22 class Extension;
22 23
23 // 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
24 // renderer access to certain URL scheme patterns for extensions and notifies 25 // renderer access to certain URL scheme patterns for extensions and notifies
25 // the renderer that the extension was loaded. 26 // the renderer that the extension was loaded.
26 // 27 //
27 // Extension system embedders must create an instance for every extension 28 // Extension system embedders must create an instance for every extension
28 // 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
29 // content::WebContentsUserData::CreateForWebContents() provides an object of 30 // content::WebContentsUserData::CreateForWebContents() provides an object of
30 // the correct type. For an example, see ChromeExtensionWebContentsObserver. 31 // the correct type. For an example, see ChromeExtensionWebContentsObserver.
31 class ExtensionWebContentsObserver : public content::WebContentsObserver { 32 class ExtensionWebContentsObserver
33 : public content::WebContentsObserver,
34 public ExtensionFunctionDispatcher::Delegate {
35 public:
36 // Returns the ExtensionWebContentsObserver for the given |web_contents|.
37 static ExtensionWebContentsObserver* GetForWebContents(
38 content::WebContents* web_contents);
39
40 ExtensionFunctionDispatcher* dispatcher() { return &dispatcher_; }
41
32 protected: 42 protected:
33 explicit ExtensionWebContentsObserver(content::WebContents* web_contents); 43 explicit ExtensionWebContentsObserver(content::WebContents* web_contents);
34 ~ExtensionWebContentsObserver() override; 44 ~ExtensionWebContentsObserver() override;
35 45
36 content::BrowserContext* browser_context() { return browser_context_; } 46 content::BrowserContext* browser_context() { return browser_context_; }
37 47
48 // ExtensionFunctionDispatcher::Delegate overrides.
49 content::WebContents* GetAssociatedWebContents() const override;
50
38 // content::WebContentsObserver overrides. 51 // content::WebContentsObserver overrides.
39 52
40 // A subclass should invoke this method to finish extension process setup. 53 // A subclass should invoke this method to finish extension process setup.
41 void RenderViewCreated(content::RenderViewHost* render_view_host) override; 54 void RenderViewCreated(content::RenderViewHost* render_view_host) override;
42 55
43 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; 56 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
44 57
58 // Subclasses should call this first before doing their own message handling.
59 bool OnMessageReceived(const IPC::Message& message) override;
60
45 // Per the documentation in WebContentsObserver, these two methods are 61 // Per the documentation in WebContentsObserver, these two methods are
46 // appropriate to track the set of current RenderFrameHosts. 62 // appropriate to track the set of current RenderFrameHosts.
47 // NOTE: FrameDeleted() != RenderFrameDeleted(). 63 // NOTE: FrameDeleted() != RenderFrameDeleted().
48 void FrameDeleted(content::RenderFrameHost* render_frame_host) override; 64 void FrameDeleted(content::RenderFrameHost* render_frame_host) override;
49 void RenderFrameHostChanged(content::RenderFrameHost* old_host, 65 void RenderFrameHostChanged(content::RenderFrameHost* old_host,
50 content::RenderFrameHost* new_host) override; 66 content::RenderFrameHost* new_host) override;
51 67
52 // Per the documentation in WebContentsObserver, these two methods are invoked 68 // Per the documentation in WebContentsObserver, these two methods are invoked
53 // when a Pepper plugin instance is attached/detached in the page DOM. 69 // when a Pepper plugin instance is attached/detached in the page DOM.
54 void PepperInstanceCreated() override; 70 void PepperInstanceCreated() override;
55 void PepperInstanceDeleted() override; 71 void PepperInstanceDeleted() override;
56 72
57 // Returns the extension or app associated with a render view host. Returns 73 // Returns the extension or app associated with a render view host. Returns
58 // NULL if the render view host is not for a valid extension. 74 // NULL if the render view host is not for a valid extension.
59 const Extension* GetExtension(content::RenderViewHost* render_view_host); 75 const Extension* GetExtension(content::RenderViewHost* render_view_host);
60 76
61 // Updates ViewType for RenderViewHost based on GetViewType(web_contents()). 77 // Updates ViewType for RenderViewHost based on GetViewType(web_contents()).
62 void NotifyRenderViewType(content::RenderViewHost* render_view_host); 78 void NotifyRenderViewType(content::RenderViewHost* render_view_host);
63 79
64 // Returns the extension or app ID associated with a render view host. Returns 80 // Returns the extension or app ID associated with a render view host. Returns
65 // the empty string if the render view host is not for a valid extension. 81 // the empty string if the render view host is not for a valid extension.
66 static std::string GetExtensionId(content::RenderViewHost* render_view_host); 82 static std::string GetExtensionId(content::RenderViewHost* render_view_host);
67 83
68 private: 84 private:
85 void OnRequest(const ExtensionHostMsg_Request_Params& params);
86
69 // The BrowserContext associated with the WebContents being observed. 87 // The BrowserContext associated with the WebContents being observed.
70 content::BrowserContext* browser_context_; 88 content::BrowserContext* browser_context_;
71 89
90 ExtensionFunctionDispatcher dispatcher_;
91
72 DISALLOW_COPY_AND_ASSIGN(ExtensionWebContentsObserver); 92 DISALLOW_COPY_AND_ASSIGN(ExtensionWebContentsObserver);
73 }; 93 };
74 94
75 } // namespace extensions 95 } // namespace extensions
76 96
77 #endif // EXTENSIONS_BROWSER_EXTENSION_WEB_CONTENTS_OBSERVER_H_ 97 #endif // EXTENSIONS_BROWSER_EXTENSION_WEB_CONTENTS_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698