| 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // It handles setting up the renderer process, if needed, with special | 47 // It handles setting up the renderer process, if needed, with special |
| 48 // privileges available to extensions. It may have a view to be shown in the | 48 // privileges available to extensions. It may have a view to be shown in the |
| 49 // browser UI, or it may be hidden. | 49 // browser UI, or it may be hidden. |
| 50 class ExtensionHost : public content::WebContentsDelegate, | 50 class ExtensionHost : public content::WebContentsDelegate, |
| 51 public content::WebContentsObserver, | 51 public content::WebContentsObserver, |
| 52 public ExtensionFunctionDispatcher::Delegate, | 52 public ExtensionFunctionDispatcher::Delegate, |
| 53 public content::NotificationObserver { | 53 public content::NotificationObserver { |
| 54 public: | 54 public: |
| 55 class ProcessCreationQueue; | 55 class ProcessCreationQueue; |
| 56 | 56 |
| 57 #if defined(TOOLKIT_VIEWS) | |
| 58 typedef ExtensionViewViews PlatformExtensionView; | |
| 59 #elif defined(OS_MACOSX) | |
| 60 typedef ExtensionViewMac PlatformExtensionView; | |
| 61 #elif defined(TOOLKIT_GTK) | |
| 62 typedef ExtensionViewGtk PlatformExtensionView; | |
| 63 #elif defined(OS_ANDROID) | |
| 64 // Android does not support extensions. | |
| 65 typedef ExtensionViewAndroid PlatformExtensionView; | |
| 66 #endif | |
| 67 | |
| 68 ExtensionHost(const Extension* extension, | 57 ExtensionHost(const Extension* extension, |
| 69 content::SiteInstance* site_instance, | 58 content::SiteInstance* site_instance, |
| 70 const GURL& url, chrome::ViewType host_type); | 59 const GURL& url, |
| 60 chrome::ViewType host_type); |
| 71 virtual ~ExtensionHost(); | 61 virtual ~ExtensionHost(); |
| 72 | 62 |
| 73 #if defined(TOOLKIT_VIEWS) | 63 void set_extension_view(ExtensionView* view) { extension_view_.reset(view); } |
| 74 void set_view(PlatformExtensionView* view) { view_.reset(view); } | |
| 75 #endif | |
| 76 | 64 |
| 77 const PlatformExtensionView* view() const { | 65 const ExtensionView* extension_view() const { return extension_view_.get(); } |
| 78 #if defined(OS_ANDROID) | 66 ExtensionView* extension_view() { return extension_view_.get(); } |
| 79 NOTREACHED(); | |
| 80 #endif | |
| 81 return view_.get(); | |
| 82 } | |
| 83 | |
| 84 PlatformExtensionView* view() { | |
| 85 #if defined(OS_ANDROID) | |
| 86 NOTREACHED(); | |
| 87 #endif | |
| 88 return view_.get(); | |
| 89 } | |
| 90 | 67 |
| 91 // Create an ExtensionView and tie it to this host and |browser|. Note NULL | 68 // Create an ExtensionView and tie it to this host and |browser|. Note NULL |
| 92 // is a valid argument for |browser|. Extension views may be bound to | 69 // is a valid argument for |browser|. Extension views may be bound to |
| 93 // tab-contents hosted in ExternalTabContainer objects, which do not | 70 // tab-contents hosted in ExternalTabContainer objects, which do not |
| 94 // instantiate Browser objects. | 71 // instantiate Browser objects. |
| 95 void CreateView(Browser* browser); | 72 void CreateView(Browser* browser); |
| 96 | 73 |
| 97 const Extension* extension() const { return extension_; } | 74 const Extension* extension() const { return extension_; } |
| 98 const std::string& extension_id() const { return extension_id_; } | 75 const std::string& extension_id() const { return extension_id_; } |
| 99 content::WebContents* host_contents() const { return host_contents_.get(); } | 76 content::WebContents* host_contents() const { return host_contents_.get(); } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 178 |
| 202 // Handles keyboard events that were not handled by HandleKeyboardEvent(). | 179 // Handles keyboard events that were not handled by HandleKeyboardEvent(). |
| 203 // Platform specific implementation may override this method to handle the | 180 // Platform specific implementation may override this method to handle the |
| 204 // event in platform specific way. | 181 // event in platform specific way. |
| 205 virtual void UnhandledKeyboardEvent( | 182 virtual void UnhandledKeyboardEvent( |
| 206 content::WebContents* source, | 183 content::WebContents* source, |
| 207 const content::NativeWebKeyboardEvent& event); | 184 const content::NativeWebKeyboardEvent& event); |
| 208 | 185 |
| 209 // Returns true if we're hosting a background page. | 186 // Returns true if we're hosting a background page. |
| 210 // This isn't valid until CreateRenderView is called. | 187 // This isn't valid until CreateRenderView is called. |
| 211 bool is_background_page() const { return !view(); } | 188 bool is_background_page() const { return !extension_view(); } |
| 212 | 189 |
| 213 // The extension that we're hosting in this view. | 190 // The extension that we're hosting in this view. |
| 214 const Extension* extension_; | 191 const Extension* extension_; |
| 215 | 192 |
| 216 // Id of extension that we're hosting in this view. | 193 // Id of extension that we're hosting in this view. |
| 217 const std::string extension_id_; | 194 const std::string extension_id_; |
| 218 | 195 |
| 219 // The profile that this host is tied to. | 196 // The profile that this host is tied to. |
| 220 Profile* profile_; | 197 Profile* profile_; |
| 221 | 198 |
| 222 // Optional view that shows the rendered content in the UI. | 199 // Optional view that shows the rendered content in the UI. |
| 223 scoped_ptr<PlatformExtensionView> view_; | 200 scoped_ptr<ExtensionView> extension_view_; |
| 224 | 201 |
| 225 // Used to create dialog boxes. | 202 // Used to create dialog boxes. |
| 226 // It must outlive host_contents_ as host_contents_ will access it | 203 // It must outlive host_contents_ as host_contents_ will access it |
| 227 // during destruction. | 204 // during destruction. |
| 228 scoped_ptr<content::JavaScriptDialogCreator> dialog_creator_; | 205 scoped_ptr<content::JavaScriptDialogCreator> dialog_creator_; |
| 229 | 206 |
| 230 // The host for our HTML content. | 207 // The host for our HTML content. |
| 231 scoped_ptr<content::WebContents> host_contents_; | 208 scoped_ptr<content::WebContents> host_contents_; |
| 232 | 209 |
| 233 // Helpers that take care of extra functionality for our host contents. | 210 // Helpers that take care of extra functionality for our host contents. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 259 | 236 |
| 260 // Used to measure how long it's been since the host was created. | 237 // Used to measure how long it's been since the host was created. |
| 261 PerfTimer since_created_; | 238 PerfTimer since_created_; |
| 262 | 239 |
| 263 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); | 240 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); |
| 264 }; | 241 }; |
| 265 | 242 |
| 266 } // namespace extensions | 243 } // namespace extensions |
| 267 | 244 |
| 268 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ | 245 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ |
| OLD | NEW |