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

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

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

Powered by Google App Engine
This is Rietveld 408576698