Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/extensions/extension_host.h

Issue 8498022: Have ExtensionHost use TabContents instead of RenderViewHost. Try #2. The first (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/perftimer.h" 13 #include "base/perftimer.h"
14 #include "chrome/browser/extensions/extension_function_dispatcher.h" 14 #include "chrome/browser/extensions/extension_function_dispatcher.h"
15 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
16 #include "content/browser/javascript_dialogs.h" 15 #include "content/browser/javascript_dialogs.h"
17 #include "content/browser/renderer_host/render_view_host_delegate.h" 16 #include "content/browser/tab_contents/tab_contents_delegate.h"
17 #include "content/browser/tab_contents/tab_contents_observer.h"
18 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/common/view_types.h"
20 21
21 #if defined(TOOLKIT_VIEWS) 22 #if defined(TOOLKIT_VIEWS)
22 #include "chrome/browser/ui/views/extensions/extension_view.h" 23 #include "chrome/browser/ui/views/extensions/extension_view.h"
23 #elif defined(OS_MACOSX) 24 #elif defined(OS_MACOSX)
24 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" 25 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h"
25 #elif defined(TOOLKIT_GTK) 26 #elif defined(TOOLKIT_GTK)
26 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" 27 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h"
27 #endif 28 #endif
28 29
29 class Browser; 30 class Browser;
30 class Extension; 31 class Extension;
31 class FileSelectHelper; 32 class FileSelectHelper;
32 class RenderProcessHost; 33 class RenderProcessHost;
33 class RenderWidgetHostView; 34 class RenderWidgetHostView;
34 class TabContents; 35 class TabContents;
35 struct ViewHostMsg_RunFileChooser_Params; 36 struct ViewHostMsg_RunFileChooser_Params;
36 struct WebPreferences; 37 struct WebPreferences;
37 38
38 // This class is the browser component of an extension component's RenderView. 39 // This class is the browser component of an extension component's RenderView.
39 // It handles setting up the renderer process, if needed, with special 40 // It handles setting up the renderer process, if needed, with special
40 // privileges available to extensions. It may have a view to be shown in the 41 // privileges available to extensions. It may have a view to be shown in the
41 // browser UI, or it may be hidden. 42 // browser UI, or it may be hidden.
42 class ExtensionHost : public RenderViewHostDelegate, 43 class ExtensionHost : public TabContentsDelegate,
43 public RenderViewHostDelegate::View, 44 public TabContentsObserver,
44 public ExtensionFunctionDispatcher::Delegate, 45 public ExtensionFunctionDispatcher::Delegate,
45 public content::NotificationObserver, 46 public content::NotificationObserver {
46 public content::JavaScriptDialogDelegate {
47 public: 47 public:
48 class ProcessCreationQueue; 48 class ProcessCreationQueue;
49 49
50 // Enable DOM automation in created render view hosts.
51 static void EnableDOMAutomation() { enable_dom_automation_ = true; }
52
53 ExtensionHost(const Extension* extension, SiteInstance* site_instance, 50 ExtensionHost(const Extension* extension, SiteInstance* site_instance,
54 const GURL& url, content::ViewType host_type); 51 const GURL& url, content::ViewType host_type);
55 virtual ~ExtensionHost(); 52 virtual ~ExtensionHost();
56 53
57 #if defined(TOOLKIT_VIEWS) 54 #if defined(TOOLKIT_VIEWS)
58 void set_view(ExtensionView* view) { view_.reset(view); } 55 void set_view(ExtensionView* view) { view_.reset(view); }
59 const ExtensionView* view() const { return view_.get(); } 56 const ExtensionView* view() const { return view_.get(); }
60 ExtensionView* view() { return view_.get(); } 57 ExtensionView* view() { return view_.get(); }
61 #elif defined(OS_MACOSX) 58 #elif defined(OS_MACOSX)
62 const ExtensionViewMac* view() const { return view_.get(); } 59 const ExtensionViewMac* view() const { return view_.get(); }
63 ExtensionViewMac* view() { return view_.get(); } 60 ExtensionViewMac* view() { return view_.get(); }
64 #elif defined(TOOLKIT_GTK) 61 #elif defined(TOOLKIT_GTK)
65 const ExtensionViewGtk* view() const { return view_.get(); } 62 const ExtensionViewGtk* view() const { return view_.get(); }
66 ExtensionViewGtk* view() { return view_.get(); } 63 ExtensionViewGtk* view() { return view_.get(); }
67 #endif 64 #endif
68 65
69 // Create an ExtensionView and tie it to this host and |browser|. Note NULL 66 // Create an ExtensionView and tie it to this host and |browser|. Note NULL
70 // is a valid argument for |browser|. Extension views may be bound to 67 // is a valid argument for |browser|. Extension views may be bound to
71 // tab-contents hosted in ExternalTabContainer objects, which do not 68 // tab-contents hosted in ExternalTabContainer objects, which do not
72 // instantiate Browser objects. 69 // instantiate Browser objects.
73 void CreateView(Browser* browser); 70 void CreateView(Browser* browser);
74 71
75 const Extension* extension() const { return extension_; } 72 const Extension* extension() const { return extension_; }
76 const std::string& extension_id() const { return extension_id_; } 73 const std::string& extension_id() const { return extension_id_; }
77 RenderViewHost* render_view_host() const { return render_view_host_; } 74 TabContents* host_contents() const { return host_contents_.get(); }
75 RenderViewHost* render_view_host() const;
78 RenderProcessHost* render_process_host() const; 76 RenderProcessHost* render_process_host() const;
79 SiteInstance* site_instance() const;
80 bool did_stop_loading() const { return did_stop_loading_; } 77 bool did_stop_loading() const { return did_stop_loading_; }
81 bool document_element_available() const { 78 bool document_element_available() const {
82 return document_element_available_; 79 return document_element_available_;
83 } 80 }
84 81
85 Profile* profile() const { return profile_; } 82 Profile* profile() const { return profile_; }
86 83
87 content::ViewType extension_host_type() const { 84 content::ViewType extension_host_type() const { return extension_host_type_; }
88 return extension_host_type_; 85 const GURL& GetURL() const;
89 }
90 86
91 // ExtensionFunctionDispatcher::Delegate 87 // ExtensionFunctionDispatcher::Delegate
92 virtual TabContents* GetAssociatedTabContents() const OVERRIDE; 88 virtual TabContents* GetAssociatedTabContents() const OVERRIDE;
93 void set_associated_tab_contents(TabContents* associated_tab_contents) { 89 void set_associated_tab_contents(TabContents* associated_tab_contents) {
94 associated_tab_contents_ = associated_tab_contents; 90 associated_tab_contents_ = associated_tab_contents;
95 } 91 }
96 92
97 // Returns true if the render view is initialized and didn't crash. 93 // Returns true if the render view is initialized and didn't crash.
98 bool IsRenderViewLive() const; 94 bool IsRenderViewLive() const;
99 95
100 // Prepares to initializes our RenderViewHost by creating its RenderView and 96 // Prepares to initializes our RenderViewHost by creating its RenderView and
101 // navigating to this host's url. Uses host_view for the RenderViewHost's view 97 // navigating to this host's url. Uses host_view for the RenderViewHost's view
102 // (can be NULL). This happens delayed to avoid locking the UI. 98 // (can be NULL). This happens delayed to avoid locking the UI.
103 void CreateRenderViewSoon(RenderWidgetHostView* host_view); 99 void CreateRenderViewSoon();
104
105 // Sets |url_| and navigates |render_view_host_|.
106 void NavigateToURL(const GURL& url);
107 100
108 // Insert a default style sheet for Extension Infobars. 101 // Insert a default style sheet for Extension Infobars.
109 void InsertInfobarCSS(); 102 void InsertInfobarCSS();
110 103
111 // Tell the renderer not to draw scrollbars on windows smaller than 104 // Tell the renderer not to draw scrollbars on windows smaller than
112 // |size_limit| in both width and height. 105 // |size_limit| in both width and height.
113 void DisableScrollbarsForSmallWindows(const gfx::Size& size_limit); 106 void DisableScrollbarsForSmallWindows(const gfx::Size& size_limit);
114 107
115 // RenderViewHostDelegate implementation. 108 // TabContentsObserver
116 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 109 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
117 virtual const GURL& GetURL() const OVERRIDE;
118 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; 110 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
119 virtual content::ViewType GetRenderViewType() const OVERRIDE; 111 virtual void RenderViewGone() OVERRIDE;
120 virtual void RenderViewGone(RenderViewHost* render_view_host, 112 virtual void DocumentAvailableInMainFrame() OVERRIDE;
121 base::TerminationStatus status,
122 int error_code) OVERRIDE;
123 virtual void DidNavigate(
124 RenderViewHost* render_view_host,
125 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
126 virtual void DidStopLoading() OVERRIDE; 113 virtual void DidStopLoading() OVERRIDE;
127 virtual void DocumentAvailableInMainFrame( 114
128 RenderViewHost* render_view_host) OVERRIDE; 115 // TabContentsDelegate
129 virtual void DocumentOnLoadCompletedInMainFrame(
130 RenderViewHost* render_view_host,
131 int32 page_id) OVERRIDE;
132 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
133 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
134 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
135 const string16& message,
136 const string16& default_prompt,
137 const GURL& frame_url,
138 const int flags,
139 IPC::Message* reply_msg,
140 bool* did_suppress_message) OVERRIDE;
141 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
142 virtual content::RendererPreferences GetRendererPrefs(
143 content::BrowserContext* browser_context) const OVERRIDE;
144 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 116 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
145 bool* is_keyboard_shortcut) OVERRIDE; 117 bool* is_keyboard_shortcut) OVERRIDE;
146 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) 118 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event)
147 OVERRIDE; 119 OVERRIDE;
148 virtual void HandleMouseMove() OVERRIDE; 120 virtual void UpdatePreferredSize(TabContents* source,
149 virtual void HandleMouseDown() OVERRIDE; 121 const gfx::Size& pref_size) OVERRIDE;
150 virtual void HandleMouseLeave() OVERRIDE; 122 virtual content::JavaScriptDialogCreator* GetJavaScriptDialogCreator()
151 virtual void HandleMouseUp() OVERRIDE; 123 OVERRIDE;
152 virtual void HandleMouseActivate() OVERRIDE; 124 virtual void AddNewContents(TabContents* source,
153 virtual void RunFileChooser(RenderViewHost* render_view_host, 125 TabContents* new_contents,
154 const ViewHostMsg_RunFileChooser_Params& params); 126 WindowOpenDisposition disposition,
155 virtual void UpdatePreferredSize(const gfx::Size& new_size); 127 const gfx::Rect& initial_pos,
156 128 bool user_gesture) OVERRIDE;
157 // RenderViewHostDelegate::View 129 virtual void TabContentsFocused(TabContents* contents) OVERRIDE;
158 virtual void CreateNewWindow( 130 virtual void CloseContents(TabContents* contents) OVERRIDE;
159 int route_id,
160 const ViewHostMsg_CreateWindow_Params& params) OVERRIDE;
161 virtual void CreateNewWidget(int route_id,
162 WebKit::WebPopupType popup_type) OVERRIDE;
163 virtual void CreateNewFullscreenWidget(int route_id) OVERRIDE;
164 virtual void ShowCreatedWindow(int route_id,
165 WindowOpenDisposition disposition,
166 const gfx::Rect& initial_pos,
167 bool user_gesture) OVERRIDE;
168 virtual void ShowCreatedWidget(int route_id,
169 const gfx::Rect& initial_pos) OVERRIDE;
170 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE;
171 virtual void ShowContextMenu(const ContextMenuParams& params) OVERRIDE;
172 virtual void ShowPopupMenu(const gfx::Rect& bounds,
173 int item_height,
174 double item_font_size,
175 int selected_item,
176 const std::vector<WebMenuItem>& items,
177 bool right_aligned) OVERRIDE;
178 virtual void StartDragging(const WebDropData& drop_data,
179 WebKit::WebDragOperationsMask allowed_operations,
180 const SkBitmap& image,
181 const gfx::Point& image_offset) OVERRIDE;
182 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE;
183 virtual void GotFocus() OVERRIDE;
184 virtual void TakeFocus(bool reverse) OVERRIDE;
185 131
186 // content::NotificationObserver 132 // content::NotificationObserver
187 virtual void Observe(int type, 133 virtual void Observe(int type,
188 const content::NotificationSource& source, 134 const content::NotificationSource& source,
189 const content::NotificationDetails& details) OVERRIDE; 135 const content::NotificationDetails& details) OVERRIDE;
190 136
191 // Overridden from content::JavaScriptDialogDelegate:
192 virtual void OnDialogClosed(IPC::Message* reply_msg,
193 bool success,
194 const string16& user_input) OVERRIDE;
195 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE;
196
197 protected: 137 protected:
198 // This should only be used by unit tests. 138 // This should only be used by unit tests.
199 ExtensionHost(const Extension* extension, content::ViewType host_type); 139 ExtensionHost(const Extension* extension, content::ViewType host_type);
200 140
201 // Internal functions used to support the CreateNewWidget() method. If a
202 // platform requires plugging into widget creation at a lower level, then a
203 // subclass might want to override these functions, but otherwise they should
204 // be fine just implementing RenderWidgetHostView::InitAsPopup().
205 //
206 // The Create function returns the newly created widget so it can be
207 // associated with the given route. When the widget needs to be shown later,
208 // we'll look it up again and pass the object to the Show functions rather
209 // than the route ID.
210 virtual RenderWidgetHostView* CreateNewWidgetInternal(
211 int route_id,
212 WebKit::WebPopupType popup_type);
213 virtual void ShowCreatedWidgetInternal(RenderWidgetHostView* widget_host_view,
214 const gfx::Rect& initial_pos);
215 private: 141 private:
216 friend class ProcessCreationQueue; 142 friend class ProcessCreationQueue;
217 143
218 // Whether to allow DOM automation for created RenderViewHosts. This is used
219 // for testing.
220 static bool enable_dom_automation_;
221
222 // Actually create the RenderView for this host. See CreateRenderViewSoon. 144 // Actually create the RenderView for this host. See CreateRenderViewSoon.
223 void CreateRenderViewNow(); 145 void CreateRenderViewNow();
224 146
147 // Navigates to the initial page.
148 void LoadInitialURL();
149
225 // Const version of below function. 150 // Const version of below function.
226 const Browser* GetBrowser() const; 151 const Browser* GetBrowser() const;
227 152
228 // ExtensionFunctionDispatcher::Delegate 153 // ExtensionFunctionDispatcher::Delegate
229 virtual Browser* GetBrowser() OVERRIDE; 154 virtual Browser* GetBrowser() OVERRIDE;
230 virtual gfx::NativeView GetNativeViewOfHost() OVERRIDE; 155 virtual gfx::NativeView GetNativeViewOfHost() OVERRIDE;
231 156
232 // Message handlers. 157 // Message handlers.
233 void OnRequest(const ExtensionHostMsg_Request_Params& params); 158 void OnRequest(const ExtensionHostMsg_Request_Params& params);
234 159
(...skipping 18 matching lines...) Expand all
253 // Optional view that shows the rendered content in the UI. 178 // Optional view that shows the rendered content in the UI.
254 #if defined(TOOLKIT_VIEWS) 179 #if defined(TOOLKIT_VIEWS)
255 scoped_ptr<ExtensionView> view_; 180 scoped_ptr<ExtensionView> view_;
256 #elif defined(OS_MACOSX) 181 #elif defined(OS_MACOSX)
257 scoped_ptr<ExtensionViewMac> view_; 182 scoped_ptr<ExtensionViewMac> view_;
258 #elif defined(TOOLKIT_GTK) 183 #elif defined(TOOLKIT_GTK)
259 scoped_ptr<ExtensionViewGtk> view_; 184 scoped_ptr<ExtensionViewGtk> view_;
260 #endif 185 #endif
261 186
262 // The host for our HTML content. 187 // The host for our HTML content.
263 RenderViewHost* render_view_host_; 188 scoped_ptr<TabContents> host_contents_;
264
265 // Common implementations of some RenderViewHostDelegate::View methods.
266 RenderViewHostDelegateViewHelper delegate_view_helper_;
267 189
268 // Whether the RenderWidget has reported that it has stopped loading. 190 // Whether the RenderWidget has reported that it has stopped loading.
269 bool did_stop_loading_; 191 bool did_stop_loading_;
270 192
271 // True if the main frame has finished parsing. 193 // True if the main frame has finished parsing.
272 bool document_element_available_; 194 bool document_element_available_;
273 195
274 // The URL being hosted. 196 // The original URL of the page being hosted.
275 GURL url_; 197 GURL initial_url_;
276 198
277 content::NotificationRegistrar registrar_; 199 content::NotificationRegistrar registrar_;
278 200
279 ExtensionFunctionDispatcher extension_function_dispatcher_; 201 ExtensionFunctionDispatcher extension_function_dispatcher_;
280 202
281 // Only EXTENSION_INFOBAR, EXTENSION_POPUP, and EXTENSION_BACKGROUND_PAGE 203 // Only EXTENSION_INFOBAR, EXTENSION_POPUP, and EXTENSION_BACKGROUND_PAGE
282 // are used here, others are not hosted by ExtensionHost. 204 // are used here, others are not hosted by ExtensionHost.
283 content::ViewType extension_host_type_; 205 content::ViewType extension_host_type_;
284 206
285 // The relevant TabContents associated with this ExtensionHost, if any. 207 // The relevant TabContents associated with this ExtensionHost, if any.
286 TabContents* associated_tab_contents_; 208 TabContents* associated_tab_contents_;
287 209
288 // Used to measure how long it's been since the host was created. 210 // Used to measure how long it's been since the host was created.
289 PerfTimer since_created_; 211 PerfTimer since_created_;
290 212
291 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); 213 DISALLOW_COPY_AND_ASSIGN(ExtensionHost);
292 }; 214 };
293 215
294 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ 216 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698