OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
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/perftimer.h" | 14 #include "base/perftimer.h" |
| 15 #include "chrome/browser/extensions/base_extension_host.h" |
15 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 16 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
16 #include "content/public/browser/javascript_dialogs.h" | 17 #include "content/public/browser/javascript_dialogs.h" |
17 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
19 #include "content/public/browser/web_contents_delegate.h" | 20 #include "content/public/browser/web_contents_delegate.h" |
20 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
21 #include "content/public/common/view_type.h" | 22 #include "content/public/common/view_type.h" |
22 | 23 |
23 #if defined(TOOLKIT_VIEWS) | |
24 #include "chrome/browser/ui/views/extensions/extension_view.h" | |
25 #elif defined(OS_MACOSX) | |
26 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | |
27 #elif defined(TOOLKIT_GTK) | |
28 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" | |
29 #elif defined(OS_ANDROID) | |
30 #include "chrome/browser/ui/android/extensions/extension_view_android.h" | |
31 #endif | |
32 | |
33 class Browser; | 24 class Browser; |
34 class Extension; | 25 class Extension; |
35 class PrefsTabHelper; | 26 class PrefsTabHelper; |
36 | 27 |
37 namespace content { | 28 namespace content { |
38 class RenderProcessHost; | 29 class RenderProcessHost; |
39 class RenderWidgetHostView; | 30 class RenderWidgetHostView; |
40 class SiteInstance; | 31 class SiteInstance; |
41 } | 32 } |
42 | 33 |
43 // This class is the browser component of an extension component's RenderView. | 34 // This class is the browser component of an extension component's RenderView. |
44 // It handles setting up the renderer process, if needed, with special | 35 // It handles setting up the renderer process, if needed, with special |
45 // privileges available to extensions. It may have a view to be shown in the | 36 // privileges available to extensions. It may have a view to be shown in the |
46 // browser UI, or it may be hidden. | 37 // browser UI, or it may be hidden. |
47 class ExtensionHost : public content::WebContentsDelegate, | 38 class ExtensionHost : public BaseExtensionHost, |
| 39 public content::WebContentsDelegate, |
48 public content::WebContentsObserver, | 40 public content::WebContentsObserver, |
49 public ExtensionFunctionDispatcher::Delegate, | 41 public ExtensionFunctionDispatcher::Delegate, |
50 public content::NotificationObserver { | 42 public content::NotificationObserver { |
51 public: | 43 public: |
52 class ProcessCreationQueue; | 44 class ProcessCreationQueue; |
53 | 45 |
54 #if defined(TOOLKIT_VIEWS) | |
55 typedef ExtensionView PlatformExtensionView; | |
56 #elif defined(OS_MACOSX) | |
57 typedef ExtensionViewMac PlatformExtensionView; | |
58 #elif defined(TOOLKIT_GTK) | |
59 typedef ExtensionViewGtk PlatformExtensionView; | |
60 #elif defined(OS_ANDROID) | |
61 // Android does not support extensions. | |
62 typedef ExtensionViewAndroid PlatformExtensionView; | |
63 #endif | |
64 | |
65 ExtensionHost(const Extension* extension, | 46 ExtensionHost(const Extension* extension, |
66 content::SiteInstance* site_instance, | 47 content::SiteInstance* site_instance, |
67 const GURL& url, content::ViewType host_type); | 48 const GURL& url, content::ViewType host_type); |
68 virtual ~ExtensionHost(); | 49 virtual ~ExtensionHost(); |
69 | 50 |
70 #if defined(TOOLKIT_VIEWS) | |
71 void set_view(PlatformExtensionView* view) { view_.reset(view); } | |
72 #endif | |
73 | |
74 const PlatformExtensionView* view() const { | |
75 #if defined(OS_ANDROID) | |
76 NOTREACHED(); | |
77 #endif | |
78 return view_.get(); | |
79 } | |
80 | |
81 PlatformExtensionView* view() { | |
82 #if defined(OS_ANDROID) | |
83 NOTREACHED(); | |
84 #endif | |
85 return view_.get(); | |
86 } | |
87 | |
88 // Create an ExtensionView and tie it to this host and |browser|. Note NULL | |
89 // is a valid argument for |browser|. Extension views may be bound to | |
90 // tab-contents hosted in ExternalTabContainer objects, which do not | |
91 // instantiate Browser objects. | |
92 void CreateView(Browser* browser); | |
93 | |
94 // Helper variant of the above for cases where no Browser is present. | |
95 void CreateViewWithoutBrowser(); | |
96 | |
97 const Extension* extension() const { return extension_; } | 51 const Extension* extension() const { return extension_; } |
98 const std::string& extension_id() const { return extension_id_; } | 52 const std::string& extension_id() const { return extension_id_; } |
99 content::WebContents* host_contents() const { return host_contents_.get(); } | 53 virtual content::WebContents* host_contents() const OVERRIDE; |
100 content::RenderViewHost* render_view_host() const; | 54 virtual content::RenderViewHost* render_view_host() const OVERRIDE; |
101 content::RenderProcessHost* render_process_host() const; | 55 virtual content::RenderProcessHost* render_process_host() const OVERRIDE; |
102 bool did_stop_loading() const { return did_stop_loading_; } | 56 bool did_stop_loading() const { return did_stop_loading_; } |
103 bool document_element_available() const { | 57 bool document_element_available() const { |
104 return document_element_available_; | 58 return document_element_available_; |
105 } | 59 } |
106 | 60 |
107 Profile* profile() const { return profile_; } | 61 Profile* profile() const { return profile_; } |
108 | 62 |
109 content::ViewType extension_host_type() const { return extension_host_type_; } | 63 virtual content::ViewType extension_host_type() const OVERRIDE; |
110 const GURL& GetURL() const; | 64 const GURL& GetURL() const; |
111 | 65 |
112 // ExtensionFunctionDispatcher::Delegate | 66 // ExtensionFunctionDispatcher::Delegate |
113 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; | 67 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; |
114 void SetAssociatedWebContents(content::WebContents* web_contents); | 68 void SetAssociatedWebContents(content::WebContents* web_contents); |
115 | 69 |
116 // Returns true if the render view is initialized and didn't crash. | 70 // Returns true if the render view is initialized and didn't crash. |
117 bool IsRenderViewLive() const; | 71 bool IsRenderViewLive() const; |
118 | 72 |
119 // Prepares to initializes our RenderViewHost by creating its RenderView and | 73 // Prepares to initializes our RenderViewHost by creating its RenderView and |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 OVERRIDE; | 109 OVERRIDE; |
156 virtual void RunFileChooser( | 110 virtual void RunFileChooser( |
157 content::WebContents* tab, | 111 content::WebContents* tab, |
158 const content::FileChooserParams& params) OVERRIDE; | 112 const content::FileChooserParams& params) OVERRIDE; |
159 virtual void AddNewContents(content::WebContents* source, | 113 virtual void AddNewContents(content::WebContents* source, |
160 content::WebContents* new_contents, | 114 content::WebContents* new_contents, |
161 WindowOpenDisposition disposition, | 115 WindowOpenDisposition disposition, |
162 const gfx::Rect& initial_pos, | 116 const gfx::Rect& initial_pos, |
163 bool user_gesture) OVERRIDE; | 117 bool user_gesture) OVERRIDE; |
164 virtual void CloseContents(content::WebContents* contents) OVERRIDE; | 118 virtual void CloseContents(content::WebContents* contents) OVERRIDE; |
165 virtual bool ShouldSuppressDialogs() OVERRIDE; | |
166 | 119 |
167 // content::NotificationObserver | 120 // content::NotificationObserver |
168 virtual void Observe(int type, | 121 virtual void Observe(int type, |
169 const content::NotificationSource& source, | 122 const content::NotificationSource& source, |
170 const content::NotificationDetails& details) OVERRIDE; | 123 const content::NotificationDetails& details) OVERRIDE; |
171 | 124 |
172 private: | 125 private: |
173 friend class ProcessCreationQueue; | 126 friend class ProcessCreationQueue; |
174 | 127 |
175 // Actually create the RenderView for this host. See CreateRenderViewSoon. | 128 // Actually create the RenderView for this host. See CreateRenderViewSoon. |
(...skipping 25 matching lines...) Expand all Loading... |
201 | 154 |
202 // The extension that we're hosting in this view. | 155 // The extension that we're hosting in this view. |
203 const Extension* extension_; | 156 const Extension* extension_; |
204 | 157 |
205 // Id of extension that we're hosting in this view. | 158 // Id of extension that we're hosting in this view. |
206 const std::string extension_id_; | 159 const std::string extension_id_; |
207 | 160 |
208 // The profile that this host is tied to. | 161 // The profile that this host is tied to. |
209 Profile* profile_; | 162 Profile* profile_; |
210 | 163 |
211 // Optional view that shows the rendered content in the UI. | |
212 scoped_ptr<PlatformExtensionView> view_; | |
213 | |
214 // Used to create dialog boxes. | 164 // Used to create dialog boxes. |
215 // It must outlive host_contents_ as host_contents_ will access it | 165 // It must outlive host_contents_ as host_contents_ will access it |
216 // during destruction. | 166 // during destruction. |
217 scoped_ptr<content::JavaScriptDialogCreator> dialog_creator_; | 167 scoped_ptr<content::JavaScriptDialogCreator> dialog_creator_; |
218 | 168 |
219 // The host for our HTML content. | 169 // The host for our HTML content. |
220 scoped_ptr<content::WebContents> host_contents_; | 170 scoped_ptr<content::WebContents> host_contents_; |
221 | 171 |
222 // Helpers that take care of extra functionality for our host contents. | 172 // Helpers that take care of extra functionality for our host contents. |
223 scoped_ptr<PrefsTabHelper> prefs_tab_helper_; | 173 scoped_ptr<PrefsTabHelper> prefs_tab_helper_; |
(...skipping 22 matching lines...) Expand all Loading... |
246 // The relevant WebContents associated with this ExtensionHost, if any. | 196 // The relevant WebContents associated with this ExtensionHost, if any. |
247 content::WebContents* associated_web_contents_; | 197 content::WebContents* associated_web_contents_; |
248 | 198 |
249 // Used to measure how long it's been since the host was created. | 199 // Used to measure how long it's been since the host was created. |
250 PerfTimer since_created_; | 200 PerfTimer since_created_; |
251 | 201 |
252 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); | 202 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); |
253 }; | 203 }; |
254 | 204 |
255 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ | 205 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ |
OLD | NEW |