| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 | 9 |
| 10 #include "base/perftimer.h" | 10 #include "base/perftimer.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 12 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 13 #include "chrome/browser/extensions/extension_popup_host.h" |
| 13 #include "chrome/browser/jsmessage_box_client.h" | 14 #include "chrome/browser/jsmessage_box_client.h" |
| 14 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 15 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 15 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" | 16 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" |
| 16 #if defined(TOOLKIT_VIEWS) | 17 #if defined(TOOLKIT_VIEWS) |
| 17 #include "chrome/browser/views/browser_bubble.h" | |
| 18 #include "chrome/browser/views/extensions/extension_view.h" | 18 #include "chrome/browser/views/extensions/extension_view.h" |
| 19 #elif defined(OS_LINUX) | 19 #elif defined(OS_LINUX) |
| 20 #include "chrome/browser/gtk/extension_view_gtk.h" | 20 #include "chrome/browser/gtk/extension_view_gtk.h" |
| 21 #elif defined(OS_MACOSX) | 21 #elif defined(OS_MACOSX) |
| 22 #include "chrome/browser/cocoa/extension_view_mac.h" | 22 #include "chrome/browser/cocoa/extension_view_mac.h" |
| 23 #endif | 23 #endif |
| 24 #include "chrome/common/notification_registrar.h" | 24 #include "chrome/common/notification_registrar.h" |
| 25 | 25 |
| 26 | 26 |
| 27 class Browser; | 27 class Browser; |
| 28 class Extension; | 28 class Extension; |
| 29 #if defined(TOOLKIT_VIEWS) | |
| 30 class ExtensionPopup; | |
| 31 #endif | |
| 32 class ExtensionProcessManager; | 29 class ExtensionProcessManager; |
| 33 class RenderProcessHost; | 30 class RenderProcessHost; |
| 34 class RenderWidgetHost; | 31 class RenderWidgetHost; |
| 35 class RenderWidgetHostView; | 32 class RenderWidgetHostView; |
| 36 class TabContents; | 33 class TabContents; |
| 37 struct WebPreferences; | 34 struct WebPreferences; |
| 38 | 35 |
| 39 // This class is the browser component of an extension component's RenderView. | 36 // This class is the browser component of an extension component's RenderView. |
| 40 // It handles setting up the renderer process, if needed, with special | 37 // It handles setting up the renderer process, if needed, with special |
| 41 // privileges available to extensions. It may have a view to be shown in the | 38 // privileges available to extensions. It may have a view to be shown in the |
| 42 // in the browser UI, or it may be hidden. | 39 // in the browser UI, or it may be hidden. |
| 43 class ExtensionHost : // NOLINT | 40 class ExtensionHost : public ExtensionPopupHost::PopupDelegate, |
| 44 #if defined(TOOLKIT_VIEWS) | |
| 45 public BrowserBubble::Delegate, | |
| 46 #endif | |
| 47 public RenderViewHostDelegate, | 41 public RenderViewHostDelegate, |
| 48 public RenderViewHostDelegate::View, | 42 public RenderViewHostDelegate::View, |
| 49 public ExtensionFunctionDispatcher::Delegate, | 43 public ExtensionFunctionDispatcher::Delegate, |
| 50 public NotificationObserver, | 44 public NotificationObserver, |
| 51 public JavaScriptMessageBoxClient { | 45 public JavaScriptMessageBoxClient { |
| 52 public: | 46 public: |
| 53 class ProcessCreationQueue; | 47 class ProcessCreationQueue; |
| 54 | 48 |
| 55 // Enable DOM automation in created render view hosts. | 49 // Enable DOM automation in created render view hosts. |
| 56 static void EnableDOMAutomation() { enable_dom_automation_ = true; } | 50 static void EnableDOMAutomation() { enable_dom_automation_ = true; } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 77 Extension* extension() { return extension_; } | 71 Extension* extension() { return extension_; } |
| 78 RenderViewHost* render_view_host() const { return render_view_host_; } | 72 RenderViewHost* render_view_host() const { return render_view_host_; } |
| 79 RenderProcessHost* render_process_host() const; | 73 RenderProcessHost* render_process_host() const; |
| 80 SiteInstance* site_instance() const; | 74 SiteInstance* site_instance() const; |
| 81 bool did_stop_loading() const { return did_stop_loading_; } | 75 bool did_stop_loading() const { return did_stop_loading_; } |
| 82 bool document_element_available() const { | 76 bool document_element_available() const { |
| 83 return document_element_available_; | 77 return document_element_available_; |
| 84 } | 78 } |
| 85 Profile* profile() const { return profile_; } | 79 Profile* profile() const { return profile_; } |
| 86 | 80 |
| 87 #if defined(TOOLKIT_VIEWS) | |
| 88 ExtensionPopup* child_popup() const { return child_popup_; } | |
| 89 void set_child_popup(ExtensionPopup* popup) { child_popup_ = popup; } | |
| 90 #endif | |
| 91 | |
| 92 // Dismiss the hosted pop-up, if one is present. | |
| 93 void DismissPopup(); | |
| 94 | |
| 95 // Sets the the ViewType of this host (e.g. mole, toolstrip). | 81 // Sets the the ViewType of this host (e.g. mole, toolstrip). |
| 96 void SetRenderViewType(ViewType::Type type); | 82 void SetRenderViewType(ViewType::Type type); |
| 97 | 83 |
| 98 // Returns true if the render view is initialized and didn't crash. | 84 // Returns true if the render view is initialized and didn't crash. |
| 99 bool IsRenderViewLive() const; | 85 bool IsRenderViewLive() const; |
| 100 | 86 |
| 101 // Prepares to initializes our RenderViewHost by creating its RenderView and | 87 // Prepares to initializes our RenderViewHost by creating its RenderView and |
| 102 // navigating to this host's url. Uses host_view for the RenderViewHost's view | 88 // navigating to this host's url. Uses host_view for the RenderViewHost's view |
| 103 // (can be NULL). This happens delayed to avoid locking the UI. | 89 // (can be NULL). This happens delayed to avoid locking the UI. |
| 104 void CreateRenderViewSoon(RenderWidgetHostView* host_view); | 90 void CreateRenderViewSoon(RenderWidgetHostView* host_view); |
| 105 | 91 |
| 106 // Sets |url_| and navigates |render_view_host_|. | 92 // Sets |url_| and navigates |render_view_host_|. |
| 107 void NavigateToURL(const GURL& url); | 93 void NavigateToURL(const GURL& url); |
| 108 | 94 |
| 109 // Insert the theme CSS for a toolstrip/mole. | 95 // Insert the theme CSS for a toolstrip/mole. |
| 110 void InsertThemeCSS(); | 96 void InsertThemeCSS(); |
| 111 | 97 |
| 112 #if defined(TOOLKIT_VIEWS) | |
| 113 // BrowserBubble::Delegate implementation. | |
| 114 // Called when the Browser Window that this bubble is attached to moves. | |
| 115 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); | |
| 116 | |
| 117 // Called with the Browser Window that this bubble is attached to is | |
| 118 // about to close. | |
| 119 virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); | |
| 120 | |
| 121 // Called when the bubble became active / got focus. | |
| 122 virtual void BubbleGotFocus(BrowserBubble* bubble); | |
| 123 | |
| 124 // Called when the bubble became inactive / lost focus. | |
| 125 virtual void BubbleLostFocus(BrowserBubble* bubble); | |
| 126 #endif // defined(TOOLKIT_VIEWS) | |
| 127 | |
| 128 // RenderViewHostDelegate implementation. | 98 // RenderViewHostDelegate implementation. |
| 129 virtual RenderViewHostDelegate::View* GetViewDelegate(); | 99 virtual RenderViewHostDelegate::View* GetViewDelegate(); |
| 130 virtual const GURL& GetURL() const { return url_; } | 100 virtual const GURL& GetURL() const { return url_; } |
| 131 virtual void RenderViewCreated(RenderViewHost* render_view_host); | 101 virtual void RenderViewCreated(RenderViewHost* render_view_host); |
| 132 virtual ViewType::Type GetRenderViewType() const; | 102 virtual ViewType::Type GetRenderViewType() const; |
| 133 virtual int GetBrowserWindowID() const; | 103 virtual int GetBrowserWindowID() const; |
| 134 virtual void RenderViewGone(RenderViewHost* render_view_host); | 104 virtual void RenderViewGone(RenderViewHost* render_view_host); |
| 135 virtual void DidNavigate(RenderViewHost* render_view_host, | 105 virtual void DidNavigate(RenderViewHost* render_view_host, |
| 136 const ViewHostMsg_FrameNavigate_Params& params); | 106 const ViewHostMsg_FrameNavigate_Params& params); |
| 137 virtual void DidStopLoading(); | 107 virtual void DidStopLoading(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // Actually create the RenderView for this host. See CreateRenderViewSoon. | 167 // Actually create the RenderView for this host. See CreateRenderViewSoon. |
| 198 void CreateRenderViewNow(); | 168 void CreateRenderViewNow(); |
| 199 | 169 |
| 200 // ExtensionFunctionDispatcher::Delegate | 170 // ExtensionFunctionDispatcher::Delegate |
| 201 // If this ExtensionHost has a view, this returns the Browser that view is a | 171 // If this ExtensionHost has a view, this returns the Browser that view is a |
| 202 // part of. If this is a global background page, we use the active Browser | 172 // part of. If this is a global background page, we use the active Browser |
| 203 // instead. | 173 // instead. |
| 204 virtual Browser* GetBrowser(); | 174 virtual Browser* GetBrowser(); |
| 205 virtual ExtensionHost* GetExtensionHost() { return this; } | 175 virtual ExtensionHost* GetExtensionHost() { return this; } |
| 206 | 176 |
| 177 // ExtensionPopupHost::Delegate |
| 178 virtual RenderViewHost* GetRenderViewHost() { return render_view_host(); } |
| 179 |
| 207 // Returns true if we're hosting a background page. | 180 // Returns true if we're hosting a background page. |
| 208 // This isn't valid until CreateRenderView is called. | 181 // This isn't valid until CreateRenderView is called. |
| 209 bool is_background_page() const { return !view(); } | 182 bool is_background_page() const { return !view(); } |
| 210 | 183 |
| 211 // The extension that we're hosting in this view. | 184 // The extension that we're hosting in this view. |
| 212 Extension* extension_; | 185 Extension* extension_; |
| 213 | 186 |
| 214 // The profile that this host is tied to. | 187 // The profile that this host is tied to. |
| 215 Profile* profile_; | 188 Profile* profile_; |
| 216 | 189 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 231 | 204 |
| 232 // Whether the RenderWidget has reported that it has stopped loading. | 205 // Whether the RenderWidget has reported that it has stopped loading. |
| 233 bool did_stop_loading_; | 206 bool did_stop_loading_; |
| 234 | 207 |
| 235 // True if the main frame has finished parsing. | 208 // True if the main frame has finished parsing. |
| 236 bool document_element_available_; | 209 bool document_element_available_; |
| 237 | 210 |
| 238 // The URL being hosted. | 211 // The URL being hosted. |
| 239 GURL url_; | 212 GURL url_; |
| 240 | 213 |
| 241 #if defined(TOOLKIT_VIEWS) | |
| 242 // A popup view that is anchored to and owned by this ExtensionHost. However, | |
| 243 // the popup contains its own separate ExtensionHost | |
| 244 ExtensionPopup* child_popup_; | |
| 245 #endif | |
| 246 | |
| 247 NotificationRegistrar registrar_; | 214 NotificationRegistrar registrar_; |
| 248 | 215 |
| 249 scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; | 216 scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; |
| 250 | 217 |
| 251 // Only EXTENSION_TOOLSTRIP, EXTENSION_POPUP, and EXTENSION_BACKGROUND_PAGE | 218 // Only EXTENSION_TOOLSTRIP, EXTENSION_POPUP, and EXTENSION_BACKGROUND_PAGE |
| 252 // are used here, others are not hosted by ExtensionHost. | 219 // are used here, others are not hosted by ExtensionHost. |
| 253 ViewType::Type extension_host_type_; | 220 ViewType::Type extension_host_type_; |
| 254 | 221 |
| 255 // Used to measure how long it's been since the host was created. | 222 // Used to measure how long it's been since the host was created. |
| 256 PerfTimer since_created_; | 223 PerfTimer since_created_; |
| 257 | 224 |
| 258 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); | 225 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); |
| 259 }; | 226 }; |
| 260 | 227 |
| 261 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ | 228 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ |
| OLD | NEW |