| 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> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/ui/views/extensions/extension_view.h" | 24 #include "chrome/browser/ui/views/extensions/extension_view.h" |
| 25 #elif defined(OS_MACOSX) | 25 #elif defined(OS_MACOSX) |
| 26 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 26 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
| 27 #elif defined(TOOLKIT_GTK) | 27 #elif defined(TOOLKIT_GTK) |
| 28 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" | 28 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" |
| 29 #elif defined(OS_ANDROID) | 29 #elif defined(OS_ANDROID) |
| 30 #include "chrome/browser/ui/android/extensions/extension_view_android.h" | 30 #include "chrome/browser/ui/android/extensions/extension_view_android.h" |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 class Browser; | 33 class Browser; |
| 34 class Extension; | |
| 35 class ExtensionWindowController; | 34 class ExtensionWindowController; |
| 36 class PrefsTabHelper; | 35 class PrefsTabHelper; |
| 37 | 36 |
| 38 namespace content { | 37 namespace content { |
| 39 class RenderProcessHost; | 38 class RenderProcessHost; |
| 40 class RenderWidgetHostView; | 39 class RenderWidgetHostView; |
| 41 class SiteInstance; | 40 class SiteInstance; |
| 42 } | 41 } |
| 43 | 42 |
| 43 namespace extensions { |
| 44 class Extension; |
| 45 } |
| 46 |
| 44 // This class is the browser component of an extension component's RenderView. | 47 // This class is the browser component of an extension component's RenderView. |
| 45 // It handles setting up the renderer process, if needed, with special | 48 // It handles setting up the renderer process, if needed, with special |
| 46 // privileges available to extensions. It may have a view to be shown in the | 49 // privileges available to extensions. It may have a view to be shown in the |
| 47 // browser UI, or it may be hidden. | 50 // browser UI, or it may be hidden. |
| 48 class ExtensionHost : public content::WebContentsDelegate, | 51 class ExtensionHost : public content::WebContentsDelegate, |
| 49 public content::WebContentsObserver, | 52 public content::WebContentsObserver, |
| 50 public ExtensionFunctionDispatcher::Delegate, | 53 public ExtensionFunctionDispatcher::Delegate, |
| 51 public content::NotificationObserver { | 54 public content::NotificationObserver { |
| 52 public: | 55 public: |
| 53 class ProcessCreationQueue; | 56 class ProcessCreationQueue; |
| 54 | 57 |
| 55 #if defined(TOOLKIT_VIEWS) | 58 #if defined(TOOLKIT_VIEWS) |
| 56 typedef ExtensionView PlatformExtensionView; | 59 typedef ExtensionView PlatformExtensionView; |
| 57 #elif defined(OS_MACOSX) | 60 #elif defined(OS_MACOSX) |
| 58 typedef ExtensionViewMac PlatformExtensionView; | 61 typedef ExtensionViewMac PlatformExtensionView; |
| 59 #elif defined(TOOLKIT_GTK) | 62 #elif defined(TOOLKIT_GTK) |
| 60 typedef ExtensionViewGtk PlatformExtensionView; | 63 typedef ExtensionViewGtk PlatformExtensionView; |
| 61 #elif defined(OS_ANDROID) | 64 #elif defined(OS_ANDROID) |
| 62 // Android does not support extensions. | 65 // Android does not support extensions. |
| 63 typedef ExtensionViewAndroid PlatformExtensionView; | 66 typedef ExtensionViewAndroid PlatformExtensionView; |
| 64 #endif | 67 #endif |
| 65 | 68 |
| 66 ExtensionHost(const Extension* extension, | 69 ExtensionHost(const extensions::Extension* extension, |
| 67 content::SiteInstance* site_instance, | 70 content::SiteInstance* site_instance, |
| 68 const GURL& url, content::ViewType host_type); | 71 const GURL& url, content::ViewType host_type); |
| 69 virtual ~ExtensionHost(); | 72 virtual ~ExtensionHost(); |
| 70 | 73 |
| 71 #if defined(TOOLKIT_VIEWS) | 74 #if defined(TOOLKIT_VIEWS) |
| 72 void set_view(PlatformExtensionView* view) { view_.reset(view); } | 75 void set_view(PlatformExtensionView* view) { view_.reset(view); } |
| 73 #endif | 76 #endif |
| 74 | 77 |
| 75 const PlatformExtensionView* view() const { | 78 const PlatformExtensionView* view() const { |
| 76 #if defined(OS_ANDROID) | 79 #if defined(OS_ANDROID) |
| 77 NOTREACHED(); | 80 NOTREACHED(); |
| 78 #endif | 81 #endif |
| 79 return view_.get(); | 82 return view_.get(); |
| 80 } | 83 } |
| 81 | 84 |
| 82 PlatformExtensionView* view() { | 85 PlatformExtensionView* view() { |
| 83 #if defined(OS_ANDROID) | 86 #if defined(OS_ANDROID) |
| 84 NOTREACHED(); | 87 NOTREACHED(); |
| 85 #endif | 88 #endif |
| 86 return view_.get(); | 89 return view_.get(); |
| 87 } | 90 } |
| 88 | 91 |
| 89 // Create an ExtensionView and tie it to this host and |browser|. Note NULL | 92 // Create an ExtensionView and tie it to this host and |browser|. Note NULL |
| 90 // is a valid argument for |browser|. Extension views may be bound to | 93 // is a valid argument for |browser|. Extension views may be bound to |
| 91 // tab-contents hosted in ExternalTabContainer objects, which do not | 94 // tab-contents hosted in ExternalTabContainer objects, which do not |
| 92 // instantiate Browser objects. | 95 // instantiate Browser objects. |
| 93 void CreateView(Browser* browser); | 96 void CreateView(Browser* browser); |
| 94 | 97 |
| 95 const Extension* extension() const { return extension_; } | 98 const extensions::Extension* extension() const { return extension_; } |
| 96 const std::string& extension_id() const { return extension_id_; } | 99 const std::string& extension_id() const { return extension_id_; } |
| 97 content::WebContents* host_contents() const { return host_contents_.get(); } | 100 content::WebContents* host_contents() const { return host_contents_.get(); } |
| 98 content::RenderViewHost* render_view_host() const; | 101 content::RenderViewHost* render_view_host() const; |
| 99 content::RenderProcessHost* render_process_host() const; | 102 content::RenderProcessHost* render_process_host() const; |
| 100 bool did_stop_loading() const { return did_stop_loading_; } | 103 bool did_stop_loading() const { return did_stop_loading_; } |
| 101 bool document_element_available() const { | 104 bool document_element_available() const { |
| 102 return document_element_available_; | 105 return document_element_available_; |
| 103 } | 106 } |
| 104 | 107 |
| 105 Profile* profile() const { return profile_; } | 108 Profile* profile() const { return profile_; } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // Handles keyboard events that were not handled by HandleKeyboardEvent(). | 193 // Handles keyboard events that were not handled by HandleKeyboardEvent(). |
| 191 // Platform specific implementation may override this method to handle the | 194 // Platform specific implementation may override this method to handle the |
| 192 // event in platform specific way. | 195 // event in platform specific way. |
| 193 virtual void UnhandledKeyboardEvent(const NativeWebKeyboardEvent& event) {} | 196 virtual void UnhandledKeyboardEvent(const NativeWebKeyboardEvent& event) {} |
| 194 | 197 |
| 195 // Returns true if we're hosting a background page. | 198 // Returns true if we're hosting a background page. |
| 196 // This isn't valid until CreateRenderView is called. | 199 // This isn't valid until CreateRenderView is called. |
| 197 bool is_background_page() const { return !view(); } | 200 bool is_background_page() const { return !view(); } |
| 198 | 201 |
| 199 // The extension that we're hosting in this view. | 202 // The extension that we're hosting in this view. |
| 200 const Extension* extension_; | 203 const extensions::Extension* extension_; |
| 201 | 204 |
| 202 // Id of extension that we're hosting in this view. | 205 // Id of extension that we're hosting in this view. |
| 203 const std::string extension_id_; | 206 const std::string extension_id_; |
| 204 | 207 |
| 205 // The profile that this host is tied to. | 208 // The profile that this host is tied to. |
| 206 Profile* profile_; | 209 Profile* profile_; |
| 207 | 210 |
| 208 // Optional view that shows the rendered content in the UI. | 211 // Optional view that shows the rendered content in the UI. |
| 209 scoped_ptr<PlatformExtensionView> view_; | 212 scoped_ptr<PlatformExtensionView> view_; |
| 210 | 213 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // The relevant WebContents associated with this ExtensionHost, if any. | 246 // The relevant WebContents associated with this ExtensionHost, if any. |
| 244 content::WebContents* associated_web_contents_; | 247 content::WebContents* associated_web_contents_; |
| 245 | 248 |
| 246 // Used to measure how long it's been since the host was created. | 249 // Used to measure how long it's been since the host was created. |
| 247 PerfTimer since_created_; | 250 PerfTimer since_created_; |
| 248 | 251 |
| 249 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); | 252 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); |
| 250 }; | 253 }; |
| 251 | 254 |
| 252 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ | 255 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ |
| OLD | NEW |