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

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: cleanup 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 void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE; 111 virtual void RenderViewReady() OVERRIDE;
120 virtual content::ViewType GetRenderViewType() const OVERRIDE; 112 virtual void RenderViewGone() OVERRIDE;
121 virtual void RenderViewGone(RenderViewHost* render_view_host, 113 virtual void DocumentAvailableInMainFrame() OVERRIDE;
122 base::TerminationStatus status,
123 int error_code) OVERRIDE;
124 virtual void DidNavigate(
125 RenderViewHost* render_view_host,
126 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
127 virtual void DidStopLoading() OVERRIDE; 114 virtual void DidStopLoading() OVERRIDE;
128 virtual void DocumentAvailableInMainFrame( 115
129 RenderViewHost* render_view_host) OVERRIDE; 116 // TabContentsDelegate
130 virtual void DocumentOnLoadCompletedInMainFrame(
131 RenderViewHost* render_view_host,
132 int32 page_id) OVERRIDE;
133 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
134 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
135 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
136 const string16& message,
137 const string16& default_prompt,
138 const GURL& frame_url,
139 const int flags,
140 IPC::Message* reply_msg,
141 bool* did_suppress_message) OVERRIDE;
142 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
143 virtual content::RendererPreferences GetRendererPrefs(
144 content::BrowserContext* browser_context) const OVERRIDE;
145 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 117 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
146 bool* is_keyboard_shortcut) OVERRIDE; 118 bool* is_keyboard_shortcut) OVERRIDE;
147 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) 119 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event)
148 OVERRIDE; 120 OVERRIDE;
149 virtual void HandleMouseMove() OVERRIDE; 121 virtual void UpdatePreferredSize(TabContents* source,
150 virtual void HandleMouseDown() OVERRIDE; 122 const gfx::Size& pref_size) OVERRIDE;
151 virtual void HandleMouseLeave() OVERRIDE; 123 virtual content::JavaScriptDialogCreator* GetJavaScriptDialogCreator()
152 virtual void HandleMouseUp() OVERRIDE; 124 OVERRIDE;
153 virtual void HandleMouseActivate() OVERRIDE; 125 virtual void AddNewContents(TabContents* source,
154 virtual void RunFileChooser(RenderViewHost* render_view_host, 126 TabContents* new_contents,
155 const ViewHostMsg_RunFileChooser_Params& params); 127 WindowOpenDisposition disposition,
156 virtual void UpdatePreferredSize(const gfx::Size& new_size); 128 const gfx::Rect& initial_pos,
157 129 bool user_gesture) OVERRIDE;
158 // RenderViewHostDelegate::View 130 virtual void TabContentsFocused(TabContents* contents) OVERRIDE;
159 virtual void CreateNewWindow( 131 virtual void CloseContents(TabContents* contents) OVERRIDE;
160 int route_id,
161 const ViewHostMsg_CreateWindow_Params& params) OVERRIDE;
162 virtual void CreateNewWidget(int route_id,
163 WebKit::WebPopupType popup_type) OVERRIDE;
164 virtual void CreateNewFullscreenWidget(int route_id) OVERRIDE;
165 virtual void ShowCreatedWindow(int route_id,
166 WindowOpenDisposition disposition,
167 const gfx::Rect& initial_pos,
168 bool user_gesture) OVERRIDE;
169 virtual void ShowCreatedWidget(int route_id,
170 const gfx::Rect& initial_pos) OVERRIDE;
171 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE;
172 virtual void ShowContextMenu(const ContextMenuParams& params) OVERRIDE;
173 virtual void ShowPopupMenu(const gfx::Rect& bounds,
174 int item_height,
175 double item_font_size,
176 int selected_item,
177 const std::vector<WebMenuItem>& items,
178 bool right_aligned) OVERRIDE;
179 virtual void StartDragging(const WebDropData& drop_data,
180 WebKit::WebDragOperationsMask allowed_operations,
181 const SkBitmap& image,
182 const gfx::Point& image_offset) OVERRIDE;
183 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE;
184 virtual void GotFocus() OVERRIDE;
185 virtual void TakeFocus(bool reverse) OVERRIDE;
186 132
187 // content::NotificationObserver 133 // content::NotificationObserver
188 virtual void Observe(int type, 134 virtual void Observe(int type,
189 const content::NotificationSource& source, 135 const content::NotificationSource& source,
190 const content::NotificationDetails& details) OVERRIDE; 136 const content::NotificationDetails& details) OVERRIDE;
191 137
192 // Overridden from content::JavaScriptDialogDelegate:
193 virtual void OnDialogClosed(IPC::Message* reply_msg,
194 bool success,
195 const string16& user_input) OVERRIDE;
196 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE;
197
198 protected: 138 protected:
199 // This should only be used by unit tests. 139 // This should only be used by unit tests.
200 ExtensionHost(const Extension* extension, content::ViewType host_type); 140 ExtensionHost(const Extension* extension, content::ViewType host_type);
201 141
202 // Internal functions used to support the CreateNewWidget() method. If a
203 // platform requires plugging into widget creation at a lower level, then a
204 // subclass might want to override these functions, but otherwise they should
205 // be fine just implementing RenderWidgetHostView::InitAsPopup().
206 //
207 // The Create function returns the newly created widget so it can be
208 // associated with the given route. When the widget needs to be shown later,
209 // we'll look it up again and pass the object to the Show functions rather
210 // than the route ID.
211 virtual RenderWidgetHostView* CreateNewWidgetInternal(
212 int route_id,
213 WebKit::WebPopupType popup_type);
214 virtual void ShowCreatedWidgetInternal(RenderWidgetHostView* widget_host_view,
215 const gfx::Rect& initial_pos);
216 private: 142 private:
217 friend class ProcessCreationQueue; 143 friend class ProcessCreationQueue;
218 144
219 // Whether to allow DOM automation for created RenderViewHosts. This is used
220 // for testing.
221 static bool enable_dom_automation_;
222
223 // Actually create the RenderView for this host. See CreateRenderViewSoon. 145 // Actually create the RenderView for this host. See CreateRenderViewSoon.
224 void CreateRenderViewNow(); 146 void CreateRenderViewNow();
225 147
148 // Navigates to the initial page.
149 void LoadInitialURL();
150
226 // Const version of below function. 151 // Const version of below function.
227 const Browser* GetBrowser() const; 152 const Browser* GetBrowser() const;
228 153
229 // ExtensionFunctionDispatcher::Delegate 154 // ExtensionFunctionDispatcher::Delegate
230 virtual Browser* GetBrowser() OVERRIDE; 155 virtual Browser* GetBrowser() OVERRIDE;
231 virtual gfx::NativeView GetNativeViewOfHost() OVERRIDE; 156 virtual gfx::NativeView GetNativeViewOfHost() OVERRIDE;
232 157
233 // Message handlers. 158 // Message handlers.
234 void OnRequest(const ExtensionHostMsg_Request_Params& params); 159 void OnRequest(const ExtensionHostMsg_Request_Params& params);
235 160
(...skipping 18 matching lines...) Expand all
254 // Optional view that shows the rendered content in the UI. 179 // Optional view that shows the rendered content in the UI.
255 #if defined(TOOLKIT_VIEWS) 180 #if defined(TOOLKIT_VIEWS)
256 scoped_ptr<ExtensionView> view_; 181 scoped_ptr<ExtensionView> view_;
257 #elif defined(OS_MACOSX) 182 #elif defined(OS_MACOSX)
258 scoped_ptr<ExtensionViewMac> view_; 183 scoped_ptr<ExtensionViewMac> view_;
259 #elif defined(TOOLKIT_GTK) 184 #elif defined(TOOLKIT_GTK)
260 scoped_ptr<ExtensionViewGtk> view_; 185 scoped_ptr<ExtensionViewGtk> view_;
261 #endif 186 #endif
262 187
263 // The host for our HTML content. 188 // The host for our HTML content.
264 RenderViewHost* render_view_host_; 189 scoped_ptr<TabContents> host_contents_;
265
266 // Common implementations of some RenderViewHostDelegate::View methods.
267 RenderViewHostDelegateViewHelper delegate_view_helper_;
268 190
269 // Whether the RenderWidget has reported that it has stopped loading. 191 // Whether the RenderWidget has reported that it has stopped loading.
270 bool did_stop_loading_; 192 bool did_stop_loading_;
271 193
272 // True if the main frame has finished parsing. 194 // True if the main frame has finished parsing.
273 bool document_element_available_; 195 bool document_element_available_;
274 196
275 // The URL being hosted. 197 // The original URL of the page being hosted.
276 GURL url_; 198 GURL initial_url_;
277 199
278 content::NotificationRegistrar registrar_; 200 content::NotificationRegistrar registrar_;
279 201
280 ExtensionFunctionDispatcher extension_function_dispatcher_; 202 ExtensionFunctionDispatcher extension_function_dispatcher_;
281 203
282 // Only EXTENSION_INFOBAR, EXTENSION_POPUP, and EXTENSION_BACKGROUND_PAGE 204 // Only EXTENSION_INFOBAR, EXTENSION_POPUP, and EXTENSION_BACKGROUND_PAGE
283 // are used here, others are not hosted by ExtensionHost. 205 // are used here, others are not hosted by ExtensionHost.
284 content::ViewType extension_host_type_; 206 content::ViewType extension_host_type_;
285 207
286 // The relevant TabContents associated with this ExtensionHost, if any. 208 // The relevant TabContents associated with this ExtensionHost, if any.
287 TabContents* associated_tab_contents_; 209 TabContents* associated_tab_contents_;
288 210
289 // Used to measure how long it's been since the host was created. 211 // Used to measure how long it's been since the host was created.
290 PerfTimer since_created_; 212 PerfTimer since_created_;
291 213
292 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); 214 DISALLOW_COPY_AND_ASSIGN(ExtensionHost);
293 }; 215 };
294 216
295 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ 217 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698