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_HOST_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_HOST_H_ |
6 #define EXTENSIONS_BROWSER_EXTENSION_HOST_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_HOST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/timer/elapsed_timer.h" | 15 #include "base/timer/elapsed_timer.h" |
16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/browser/web_contents_delegate.h" | 18 #include "content/public/browser/web_contents_delegate.h" |
19 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 20 #include "extensions/browser/deferred_start_render_host.h" |
20 #include "extensions/browser/extension_function_dispatcher.h" | 21 #include "extensions/browser/extension_function_dispatcher.h" |
21 #include "extensions/common/stack_frame.h" | 22 #include "extensions/common/stack_frame.h" |
22 #include "extensions/common/view_type.h" | 23 #include "extensions/common/view_type.h" |
23 | 24 |
24 class PrefsTabHelper; | 25 class PrefsTabHelper; |
25 | 26 |
26 namespace content { | 27 namespace content { |
27 class BrowserContext; | 28 class BrowserContext; |
28 class RenderProcessHost; | 29 class RenderProcessHost; |
29 class RenderWidgetHostView; | 30 class RenderWidgetHostView; |
30 class SiteInstance; | 31 class SiteInstance; |
31 } | 32 } |
32 | 33 |
33 namespace extensions { | 34 namespace extensions { |
34 class Extension; | 35 class Extension; |
35 class ExtensionHostDelegate; | 36 class ExtensionHostDelegate; |
36 class ExtensionHostObserver; | 37 class ExtensionHostObserver; |
37 class ExtensionHostQueue; | 38 class ExtensionHostQueue; |
38 class WindowController; | 39 class WindowController; |
39 | 40 |
40 // This class is the browser component of an extension component's RenderView. | 41 // This class is the browser component of an extension component's RenderView. |
41 // It handles setting up the renderer process, if needed, with special | 42 // It handles setting up the renderer process, if needed, with special |
42 // privileges available to extensions. It may have a view to be shown in the | 43 // privileges available to extensions. It may have a view to be shown in the |
43 // browser UI, or it may be hidden. | 44 // browser UI, or it may be hidden. |
44 // | 45 // |
45 // If you are adding code that only affects visible extension views (and not | 46 // If you are adding code that only affects visible extension views (and not |
46 // invisible background pages) you should add it to ExtensionViewHost. | 47 // invisible background pages) you should add it to ExtensionViewHost. |
47 class ExtensionHost : public content::WebContentsDelegate, | 48 class ExtensionHost : public DeferredStartRenderHost, |
| 49 public content::WebContentsDelegate, |
48 public content::WebContentsObserver, | 50 public content::WebContentsObserver, |
49 public ExtensionFunctionDispatcher::Delegate, | 51 public ExtensionFunctionDispatcher::Delegate, |
50 public content::NotificationObserver { | 52 public content::NotificationObserver { |
51 public: | 53 public: |
52 ExtensionHost(const Extension* extension, | 54 ExtensionHost(const Extension* extension, |
53 content::SiteInstance* site_instance, | 55 content::SiteInstance* site_instance, |
54 const GURL& url, ViewType host_type); | 56 const GURL& url, ViewType host_type); |
55 ~ExtensionHost() override; | 57 ~ExtensionHost() override; |
56 | 58 |
57 const Extension* extension() const { return extension_; } | 59 const Extension* extension() const { return extension_; } |
(...skipping 12 matching lines...) Expand all Loading... |
70 const GURL& GetURL() const; | 72 const GURL& GetURL() const; |
71 | 73 |
72 // Returns true if the render view is initialized and didn't crash. | 74 // Returns true if the render view is initialized and didn't crash. |
73 bool IsRenderViewLive() const; | 75 bool IsRenderViewLive() const; |
74 | 76 |
75 // Prepares to initializes our RenderViewHost by creating its RenderView and | 77 // Prepares to initializes our RenderViewHost by creating its RenderView and |
76 // navigating to this host's url. Uses host_view for the RenderViewHost's view | 78 // navigating to this host's url. Uses host_view for the RenderViewHost's view |
77 // (can be NULL). This happens delayed to avoid locking the UI. | 79 // (can be NULL). This happens delayed to avoid locking the UI. |
78 void CreateRenderViewSoon(); | 80 void CreateRenderViewSoon(); |
79 | 81 |
80 // DO NOT CALL THIS. Always use CreateRenderViewSoon(). | |
81 // (Unless you're implementing an ExtensionHostQueue). | |
82 void CreateRenderViewNow(); | |
83 | |
84 // Closes this host (results in [possibly asynchronous] deletion). | 82 // Closes this host (results in [possibly asynchronous] deletion). |
85 void Close(); | 83 void Close(); |
86 | 84 |
87 // Typical observer interface. | 85 // Typical observer interface. |
88 void AddObserver(ExtensionHostObserver* observer); | 86 void AddObserver(ExtensionHostObserver* observer); |
89 void RemoveObserver(ExtensionHostObserver* observer); | 87 void RemoveObserver(ExtensionHostObserver* observer); |
90 | 88 |
91 // Called when an IPC message is dispatched to the RenderView associated with | 89 // Called when an IPC message is dispatched to the RenderView associated with |
92 // this ExtensionHost. | 90 // this ExtensionHost. |
93 void OnMessageDispatched(const std::string& event_name, int message_id); | 91 void OnMessageDispatched(const std::string& event_name, int message_id); |
94 | 92 |
95 // Called by the ProcessManager when a network request is started by the | 93 // Called by the ProcessManager when a network request is started by the |
96 // extension corresponding to this ExtensionHost. | 94 // extension corresponding to this ExtensionHost. |
97 void OnNetworkRequestStarted(uint64 request_id); | 95 void OnNetworkRequestStarted(uint64 request_id); |
98 | 96 |
99 // Called by the ProcessManager when a previously started network request is | 97 // Called by the ProcessManager when a previously started network request is |
100 // finished. | 98 // finished. |
101 void OnNetworkRequestDone(uint64 request_id); | 99 void OnNetworkRequestDone(uint64 request_id); |
102 | 100 |
103 // content::WebContentsObserver | 101 // content::WebContentsObserver: |
104 bool OnMessageReceived(const IPC::Message& message) override; | 102 bool OnMessageReceived(const IPC::Message& message) override; |
105 void RenderViewCreated(content::RenderViewHost* render_view_host) override; | 103 void RenderViewCreated(content::RenderViewHost* render_view_host) override; |
106 void RenderViewDeleted(content::RenderViewHost* render_view_host) override; | 104 void RenderViewDeleted(content::RenderViewHost* render_view_host) override; |
107 void RenderViewReady() override; | 105 void RenderViewReady() override; |
108 void RenderProcessGone(base::TerminationStatus status) override; | 106 void RenderProcessGone(base::TerminationStatus status) override; |
109 void DocumentAvailableInMainFrame() override; | 107 void DocumentAvailableInMainFrame() override; |
110 void DidStopLoading(content::RenderViewHost* render_view_host) override; | 108 void DidStopLoading(content::RenderViewHost* render_view_host) override; |
111 | 109 |
112 // content::WebContentsDelegate | 110 // content::WebContentsDelegate: |
113 content::JavaScriptDialogManager* GetJavaScriptDialogManager( | 111 content::JavaScriptDialogManager* GetJavaScriptDialogManager( |
114 content::WebContents* source) override; | 112 content::WebContents* source) override; |
115 void AddNewContents(content::WebContents* source, | 113 void AddNewContents(content::WebContents* source, |
116 content::WebContents* new_contents, | 114 content::WebContents* new_contents, |
117 WindowOpenDisposition disposition, | 115 WindowOpenDisposition disposition, |
118 const gfx::Rect& initial_rect, | 116 const gfx::Rect& initial_rect, |
119 bool user_gesture, | 117 bool user_gesture, |
120 bool* was_blocked) override; | 118 bool* was_blocked) override; |
121 void CloseContents(content::WebContents* contents) override; | 119 void CloseContents(content::WebContents* contents) override; |
122 void RequestMediaAccessPermission( | 120 void RequestMediaAccessPermission( |
123 content::WebContents* web_contents, | 121 content::WebContents* web_contents, |
124 const content::MediaStreamRequest& request, | 122 const content::MediaStreamRequest& request, |
125 const content::MediaResponseCallback& callback) override; | 123 const content::MediaResponseCallback& callback) override; |
126 bool CheckMediaAccessPermission(content::WebContents* web_contents, | 124 bool CheckMediaAccessPermission(content::WebContents* web_contents, |
127 const GURL& security_origin, | 125 const GURL& security_origin, |
128 content::MediaStreamType type) override; | 126 content::MediaStreamType type) override; |
129 bool IsNeverVisible(content::WebContents* web_contents) override; | 127 bool IsNeverVisible(content::WebContents* web_contents) override; |
130 | 128 |
131 // content::NotificationObserver | 129 // content::NotificationObserver: |
132 void Observe(int type, | 130 void Observe(int type, |
133 const content::NotificationSource& source, | 131 const content::NotificationSource& source, |
134 const content::NotificationDetails& details) override; | 132 const content::NotificationDetails& details) override; |
135 | 133 |
136 protected: | 134 protected: |
137 content::NotificationRegistrar* registrar() { return ®istrar_; } | 135 content::NotificationRegistrar* registrar() { return ®istrar_; } |
138 | 136 |
139 // Called after the extension page finishes loading but before the | 137 // Called after the extension page finishes loading but before the |
140 // EXTENSION_HOST_DID_STOP_LOADING notification is sent. | 138 // EXTENSION_HOST_DID_STOP_LOADING notification is sent. |
141 virtual void OnDidStopLoading(); | 139 virtual void OnDidStopLoading(); |
142 | 140 |
143 // Navigates to the initial page. | 141 // Navigates to the initial page. |
144 virtual void LoadInitialURL(); | 142 virtual void LoadInitialURL(); |
145 | 143 |
146 // Returns true if we're hosting a background page. | 144 // Returns true if we're hosting a background page. |
147 virtual bool IsBackgroundPage() const; | 145 virtual bool IsBackgroundPage() const; |
148 | 146 |
149 private: | 147 private: |
| 148 // DeferredStartRenderHost: |
| 149 void CreateRenderViewNow() override; |
| 150 |
150 // Message handlers. | 151 // Message handlers. |
151 void OnRequest(const ExtensionHostMsg_Request_Params& params); | 152 void OnRequest(const ExtensionHostMsg_Request_Params& params); |
152 void OnEventAck(int message_id); | 153 void OnEventAck(int message_id); |
153 void OnIncrementLazyKeepaliveCount(); | 154 void OnIncrementLazyKeepaliveCount(); |
154 void OnDecrementLazyKeepaliveCount(); | 155 void OnDecrementLazyKeepaliveCount(); |
155 | 156 |
156 // Delegate for functionality that cannot exist in the extensions module. | 157 // Delegate for functionality that cannot exist in the extensions module. |
157 scoped_ptr<ExtensionHostDelegate> delegate_; | 158 scoped_ptr<ExtensionHostDelegate> delegate_; |
158 | 159 |
159 // The extension that we're hosting in this view. | 160 // The extension that we're hosting in this view. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 scoped_ptr<base::ElapsedTimer> load_start_; | 197 scoped_ptr<base::ElapsedTimer> load_start_; |
197 | 198 |
198 ObserverList<ExtensionHostObserver> observer_list_; | 199 ObserverList<ExtensionHostObserver> observer_list_; |
199 | 200 |
200 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); | 201 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); |
201 }; | 202 }; |
202 | 203 |
203 } // namespace extensions | 204 } // namespace extensions |
204 | 205 |
205 #endif // EXTENSIONS_BROWSER_EXTENSION_HOST_H_ | 206 #endif // EXTENSIONS_BROWSER_EXTENSION_HOST_H_ |
OLD | NEW |