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

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

Issue 8587001: Have ExtensionHost use TabContents instead of RenderViewHost. Try #3. (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 RenderProcessHost; 32 class RenderProcessHost;
32 class RenderWidgetHostView; 33 class RenderWidgetHostView;
33 class TabContents; 34 class TabContents;
34 struct ViewHostMsg_RunFileChooser_Params; 35 struct ViewHostMsg_RunFileChooser_Params;
35 struct WebPreferences; 36 struct WebPreferences;
36 37
37 // This class is the browser component of an extension component's RenderView. 38 // This class is the browser component of an extension component's RenderView.
38 // It handles setting up the renderer process, if needed, with special 39 // It handles setting up the renderer process, if needed, with special
39 // privileges available to extensions. It may have a view to be shown in the 40 // privileges available to extensions. It may have a view to be shown in the
40 // browser UI, or it may be hidden. 41 // browser UI, or it may be hidden.
41 class ExtensionHost : public RenderViewHostDelegate, 42 class ExtensionHost : public TabContentsDelegate,
42 public RenderViewHostDelegate::View, 43 public TabContentsObserver,
43 public ExtensionFunctionDispatcher::Delegate, 44 public ExtensionFunctionDispatcher::Delegate,
44 public content::NotificationObserver, 45 public content::NotificationObserver {
45 public content::JavaScriptDialogDelegate {
46 public: 46 public:
47 class ProcessCreationQueue; 47 class ProcessCreationQueue;
48 48
49 // Enable DOM automation in created render view hosts.
50 static void EnableDOMAutomation() { enable_dom_automation_ = true; }
51
52 ExtensionHost(const Extension* extension, SiteInstance* site_instance, 49 ExtensionHost(const Extension* extension, SiteInstance* site_instance,
53 const GURL& url, content::ViewType host_type); 50 const GURL& url, content::ViewType host_type);
54 virtual ~ExtensionHost(); 51 virtual ~ExtensionHost();
55 52
56 #if defined(TOOLKIT_VIEWS) 53 #if defined(TOOLKIT_VIEWS)
57 void set_view(ExtensionView* view) { view_.reset(view); } 54 void set_view(ExtensionView* view) { view_.reset(view); }
58 const ExtensionView* view() const { return view_.get(); } 55 const ExtensionView* view() const { return view_.get(); }
59 ExtensionView* view() { return view_.get(); } 56 ExtensionView* view() { return view_.get(); }
60 #elif defined(OS_MACOSX) 57 #elif defined(OS_MACOSX)
61 const ExtensionViewMac* view() const { return view_.get(); } 58 const ExtensionViewMac* view() const { return view_.get(); }
62 ExtensionViewMac* view() { return view_.get(); } 59 ExtensionViewMac* view() { return view_.get(); }
63 #elif defined(TOOLKIT_GTK) 60 #elif defined(TOOLKIT_GTK)
64 const ExtensionViewGtk* view() const { return view_.get(); } 61 const ExtensionViewGtk* view() const { return view_.get(); }
65 ExtensionViewGtk* view() { return view_.get(); } 62 ExtensionViewGtk* view() { return view_.get(); }
66 #endif 63 #endif
67 64
68 // Create an ExtensionView and tie it to this host and |browser|. Note NULL 65 // Create an ExtensionView and tie it to this host and |browser|. Note NULL
69 // is a valid argument for |browser|. Extension views may be bound to 66 // is a valid argument for |browser|. Extension views may be bound to
70 // tab-contents hosted in ExternalTabContainer objects, which do not 67 // tab-contents hosted in ExternalTabContainer objects, which do not
71 // instantiate Browser objects. 68 // instantiate Browser objects.
72 void CreateView(Browser* browser); 69 void CreateView(Browser* browser);
73 70
74 const Extension* extension() const { return extension_; } 71 const Extension* extension() const { return extension_; }
75 const std::string& extension_id() const { return extension_id_; } 72 const std::string& extension_id() const { return extension_id_; }
76 RenderViewHost* render_view_host() const { return render_view_host_; } 73 TabContents* host_contents() const { return host_contents_.get(); }
74 RenderViewHost* render_view_host() const;
77 RenderProcessHost* render_process_host() const; 75 RenderProcessHost* render_process_host() const;
78 SiteInstance* site_instance() const;
79 bool did_stop_loading() const { return did_stop_loading_; } 76 bool did_stop_loading() const { return did_stop_loading_; }
80 bool document_element_available() const { 77 bool document_element_available() const {
81 return document_element_available_; 78 return document_element_available_;
82 } 79 }
83 80
84 Profile* profile() const { return profile_; } 81 Profile* profile() const { return profile_; }
85 82
86 content::ViewType extension_host_type() const { 83 content::ViewType extension_host_type() const { return extension_host_type_; }
87 return extension_host_type_; 84 const GURL& GetURL() const;
88 }
89 85
90 // ExtensionFunctionDispatcher::Delegate 86 // ExtensionFunctionDispatcher::Delegate
91 virtual TabContents* GetAssociatedTabContents() const OVERRIDE; 87 virtual TabContents* GetAssociatedTabContents() const OVERRIDE;
92 void set_associated_tab_contents(TabContents* associated_tab_contents) { 88 void set_associated_tab_contents(TabContents* associated_tab_contents) {
93 associated_tab_contents_ = associated_tab_contents; 89 associated_tab_contents_ = associated_tab_contents;
94 } 90 }
95 91
96 // Returns true if the render view is initialized and didn't crash. 92 // Returns true if the render view is initialized and didn't crash.
97 bool IsRenderViewLive() const; 93 bool IsRenderViewLive() const;
98 94
99 // Prepares to initializes our RenderViewHost by creating its RenderView and 95 // Prepares to initializes our RenderViewHost by creating its RenderView and
100 // navigating to this host's url. Uses host_view for the RenderViewHost's view 96 // navigating to this host's url. Uses host_view for the RenderViewHost's view
101 // (can be NULL). This happens delayed to avoid locking the UI. 97 // (can be NULL). This happens delayed to avoid locking the UI.
102 void CreateRenderViewSoon(RenderWidgetHostView* host_view); 98 void CreateRenderViewSoon();
103
104 // Sets |url_| and navigates |render_view_host_|.
105 void NavigateToURL(const GURL& url);
106 99
107 // Insert a default style sheet for Extension Infobars. 100 // Insert a default style sheet for Extension Infobars.
108 void InsertInfobarCSS(); 101 void InsertInfobarCSS();
109 102
110 // Tell the renderer not to draw scrollbars on windows smaller than 103 // Tell the renderer not to draw scrollbars on windows smaller than
111 // |size_limit| in both width and height. 104 // |size_limit| in both width and height.
112 void DisableScrollbarsForSmallWindows(const gfx::Size& size_limit); 105 void DisableScrollbarsForSmallWindows(const gfx::Size& size_limit);
113 106
114 // RenderViewHostDelegate implementation. 107 // TabContentsObserver
115 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 108 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
116 virtual const GURL& GetURL() const OVERRIDE;
117 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; 109 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
118 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE; 110 virtual void RenderViewReady() OVERRIDE;
119 virtual content::ViewType GetRenderViewType() const OVERRIDE; 111 virtual void RenderViewGone(base::TerminationStatus status) 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 CloseContents(TabContents* contents) OVERRIDE;
158 virtual void CreateNewWindow(
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 130
186 // content::NotificationObserver 131 // content::NotificationObserver
187 virtual void Observe(int type, 132 virtual void Observe(int type,
188 const content::NotificationSource& source, 133 const content::NotificationSource& source,
189 const content::NotificationDetails& details) OVERRIDE; 134 const content::NotificationDetails& details) OVERRIDE;
190 135
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: 136 protected:
198 // This should only be used by unit tests. 137 // This should only be used by unit tests.
199 ExtensionHost(const Extension* extension, content::ViewType host_type); 138 ExtensionHost(const Extension* extension, content::ViewType host_type);
200 139
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: 140 private:
216 friend class ProcessCreationQueue; 141 friend class ProcessCreationQueue;
217 142
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. 143 // Actually create the RenderView for this host. See CreateRenderViewSoon.
223 void CreateRenderViewNow(); 144 void CreateRenderViewNow();
224 145
146 // Navigates to the initial page.
147 void LoadInitialURL();
148
225 // Const version of below function. 149 // Const version of below function.
226 const Browser* GetBrowser() const; 150 const Browser* GetBrowser() const;
227 151
228 // ExtensionFunctionDispatcher::Delegate 152 // ExtensionFunctionDispatcher::Delegate
229 virtual Browser* GetBrowser() OVERRIDE; 153 virtual Browser* GetBrowser() OVERRIDE;
230 virtual gfx::NativeView GetNativeViewOfHost() OVERRIDE; 154 virtual gfx::NativeView GetNativeViewOfHost() OVERRIDE;
231 155
232 // Message handlers. 156 // Message handlers.
233 void OnRequest(const ExtensionHostMsg_Request_Params& params); 157 void OnRequest(const ExtensionHostMsg_Request_Params& params);
234 158
(...skipping 18 matching lines...) Expand all
253 // Optional view that shows the rendered content in the UI. 177 // Optional view that shows the rendered content in the UI.
254 #if defined(TOOLKIT_VIEWS) 178 #if defined(TOOLKIT_VIEWS)
255 scoped_ptr<ExtensionView> view_; 179 scoped_ptr<ExtensionView> view_;
256 #elif defined(OS_MACOSX) 180 #elif defined(OS_MACOSX)
257 scoped_ptr<ExtensionViewMac> view_; 181 scoped_ptr<ExtensionViewMac> view_;
258 #elif defined(TOOLKIT_GTK) 182 #elif defined(TOOLKIT_GTK)
259 scoped_ptr<ExtensionViewGtk> view_; 183 scoped_ptr<ExtensionViewGtk> view_;
260 #endif 184 #endif
261 185
262 // The host for our HTML content. 186 // The host for our HTML content.
263 RenderViewHost* render_view_host_; 187 scoped_ptr<TabContents> host_contents_;
264
265 // Common implementations of some RenderViewHostDelegate::View methods.
266 RenderViewHostDelegateViewHelper delegate_view_helper_;
267 188
268 // Whether the RenderWidget has reported that it has stopped loading. 189 // Whether the RenderWidget has reported that it has stopped loading.
269 bool did_stop_loading_; 190 bool did_stop_loading_;
270 191
271 // True if the main frame has finished parsing. 192 // True if the main frame has finished parsing.
272 bool document_element_available_; 193 bool document_element_available_;
273 194
274 // The URL being hosted. 195 // The original URL of the page being hosted.
275 GURL url_; 196 GURL initial_url_;
276 197
277 content::NotificationRegistrar registrar_; 198 content::NotificationRegistrar registrar_;
278 199
279 ExtensionFunctionDispatcher extension_function_dispatcher_; 200 ExtensionFunctionDispatcher extension_function_dispatcher_;
280 201
281 // Only EXTENSION_INFOBAR, EXTENSION_POPUP, and EXTENSION_BACKGROUND_PAGE 202 // Only EXTENSION_INFOBAR, EXTENSION_POPUP, and EXTENSION_BACKGROUND_PAGE
282 // are used here, others are not hosted by ExtensionHost. 203 // are used here, others are not hosted by ExtensionHost.
283 content::ViewType extension_host_type_; 204 content::ViewType extension_host_type_;
284 205
285 // The relevant TabContents associated with this ExtensionHost, if any. 206 // The relevant TabContents associated with this ExtensionHost, if any.
286 TabContents* associated_tab_contents_; 207 TabContents* associated_tab_contents_;
287 208
288 // Used to measure how long it's been since the host was created. 209 // Used to measure how long it's been since the host was created.
289 PerfTimer since_created_; 210 PerfTimer since_created_;
290 211
291 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); 212 DISALLOW_COPY_AND_ASSIGN(ExtensionHost);
292 }; 213 };
293 214
294 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ 215 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698