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.cc

Issue 92043: Refactor ExtensionView to support a UI-less extension instance.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months 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
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/extensions/extension_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/extensions/extension_view.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include "base/command_line.h"
8 #include "chrome/browser/browser.h" 7 #include "chrome/browser/browser.h"
9 #include "chrome/browser/character_encoding.h" 8 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/extensions/extension.h" 9 #include "chrome/browser/extensions/extension.h"
11 #include "chrome/browser/extensions/extension_message_service.h" 10 #include "chrome/browser/extensions/extension_message_service.h"
12 #include "chrome/browser/jsmessage_box_handler.h" 11 #include "chrome/browser/extensions/extension_view.h"
13 #include "chrome/browser/profile.h" 12 #include "chrome/browser/profile.h"
14 #include "chrome/browser/renderer_host/render_view_host.h" 13 #include "chrome/browser/renderer_host/render_view_host.h"
15 #include "chrome/browser/renderer_host/render_process_host.h" 14 #include "chrome/browser/renderer_host/render_process_host.h"
16 #include "chrome/browser/renderer_host/render_widget_host.h" 15 #include "chrome/browser/renderer_host/render_widget_host.h"
17 #include "chrome/browser/renderer_host/render_widget_host_view.h" 16 #include "chrome/browser/renderer_host/render_widget_host_view.h"
18 #include "chrome/browser/tab_contents/site_instance.h" 17 #include "chrome/browser/tab_contents/site_instance.h"
19 #include "chrome/browser/tab_contents/web_contents.h" 18 #include "chrome/browser/tab_contents/web_contents.h"
20 #include "chrome/browser/tab_contents/tab_contents_view.h" 19 #include "chrome/browser/tab_contents/tab_contents_view.h"
21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
23 #include "chrome/common/pref_service.h" 21 #include "chrome/common/pref_service.h"
24 #include "chrome/common/resource_bundle.h" 22 #include "chrome/common/resource_bundle.h"
25 23
26 #include "grit/browser_resources.h" 24 #include "grit/browser_resources.h"
27 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
28 26
29 #include "webkit/glue/context_menu.h" 27 #include "webkit/glue/context_menu.h"
30 28
31 ExtensionView::ExtensionView(Extension* extension, 29 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance)
32 const GURL& url, 30 : extension_(extension), view_(NULL), did_stop_loading_(false) {
33 SiteInstance* instance, 31 render_view_host_ = new RenderViewHost(
34 Browser* browser) 32 site_instance, this, MSG_ROUTING_NONE, NULL);
35 : HWNDHtmlView(url, this, false, instance), 33 render_view_host_->AllowExtensionBindings();
36 extension_(extension),
37 browser_(browser) {
38 // Set the width initially to 0, so that the WebCore::Document can
39 // correctly compute the minPrefWidth which is returned in
40 // DidContentsChangeSize()
41 set_preferred_size(gfx::Size(0, 100));
42 SetVisible(false);
43 } 34 }
44 35
45 void ExtensionView::DidStopLoading(RenderViewHost* render_view_host, 36 ExtensionHost::~ExtensionHost() {
46 int32 page_id) { 37 render_view_host_->Shutdown(); // deletes render_view_host
47 SetVisible(true);
48 render_view_host->WasResized();
49 } 38 }
50 39
51 void ExtensionView::DidContentsPreferredWidthChange(const int pref_width) { 40 SiteInstance* ExtensionHost::site_instance() const {
52 if (pref_width > 0) { 41 return render_view_host_->site_instance();
53 // SchedulePaint first because new_width may be smaller and we want
54 // the Parent to paint the vacated space.
55 SchedulePaint();
56 set_preferred_size(gfx::Size(pref_width, 100));
57 SizeToPreferredSize();
58
59 // TODO(rafaelw): This assumes that the extension view is a child of an
60 // ExtensionToolstrip, which is a child of the BookmarkBarView. There should
61 // be a way to do this where the ExtensionView doesn't have to know it's
62 // containment hierarchy.
63 if (GetParent() != NULL && GetParent()->GetParent() != NULL) {
64 GetParent()->GetParent()->Layout();
65 }
66
67 SchedulePaint();
68 render_view_host()->WasResized();
69 }
70 } 42 }
71 43
72 void ExtensionView::CreatingRenderer() { 44 void ExtensionHost::CreateRenderView(const GURL& url,
73 render_view_host()->AllowExtensionBindings(); 45 RenderWidgetHostView* host_view) {
46 render_view_host_->set_view(host_view);
47 render_view_host_->CreateRenderView();
48 render_view_host_->NavigateToURL(url);
74 } 49 }
75 50
76 void ExtensionView::RenderViewCreated(RenderViewHost* rvh) { 51 void ExtensionHost::DidContentsPreferredWidthChange(const int pref_width) {
52 if (view_)
53 view_->DidContentsPreferredWidthChange(pref_width);
54 }
55
56 void ExtensionHost::RenderViewCreated(RenderViewHost* rvh) {
77 URLRequestContext* context = rvh->process()->profile()->GetRequestContext(); 57 URLRequestContext* context = rvh->process()->profile()->GetRequestContext();
78 ExtensionMessageService::GetInstance(context)->RegisterExtension( 58 ExtensionMessageService::GetInstance(context)->RegisterExtension(
79 extension_->id(), render_view_host()->process()->pid()); 59 extension_->id(), rvh->process()->pid());
80 } 60 }
81 61
82 WebPreferences ExtensionView::GetWebkitPrefs() { 62 WebPreferences ExtensionHost::GetWebkitPrefs() {
83 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs(); 63 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs();
84 bool isDomUI = true; 64 const bool kIsDomUI = true;
85 return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, isDomUI); 65 return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, kIsDomUI);
86 } 66 }
87 67
88 void ExtensionView::RunJavaScriptMessage( 68 void ExtensionHost::RunJavaScriptMessage(
89 const std::wstring& message, 69 const std::wstring& message,
90 const std::wstring& default_prompt, 70 const std::wstring& default_prompt,
91 const GURL& frame_url, 71 const GURL& frame_url,
92 const int flags, 72 const int flags,
93 IPC::Message* reply_msg, 73 IPC::Message* reply_msg,
94 bool* did_suppress_message) { 74 bool* did_suppress_message) {
95 // Automatically cancel the javascript alert (otherwise the renderer hangs 75 // Automatically cancel the javascript alert (otherwise the renderer hangs
96 // indefinitely). 76 // indefinitely).
97 *did_suppress_message = true; 77 *did_suppress_message = true;
98 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, L""); 78 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, L"");
99 } 79 }
100 80
101 void ExtensionView::DidStartLoading(RenderViewHost* render_view_host, 81 void ExtensionHost::DidStartLoading(RenderViewHost* render_view_host) {
102 int32 page_id) {
103 static const StringPiece toolstrip_css( 82 static const StringPiece toolstrip_css(
104 ResourceBundle::GetSharedInstance().GetRawDataResource( 83 ResourceBundle::GetSharedInstance().GetRawDataResource(
105 IDR_EXTENSIONS_TOOLSTRIP_CSS)); 84 IDR_EXTENSIONS_TOOLSTRIP_CSS));
106 render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string()); 85 render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string());
107 } 86 }
108 87
109 RenderViewHostDelegate::View* ExtensionView::GetViewDelegate() const { 88 void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) {
89 render_view_host->WasResized();
90 did_stop_loading_ = true;
91 if (view_)
92 view_->ShowIfCompletelyLoaded();
93 }
94
95 ExtensionFunctionDispatcher* ExtensionHost::
96 CreateExtensionFunctionDispatcher(RenderViewHost *render_view_host,
97 const std::string& extension_id) {
98 return new ExtensionFunctionDispatcher(render_view_host, GetBrowser(),
99 extension_id);
100 }
101
102 RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() const {
110 // TODO(erikkay) this is unfortunate. The interface declares that this method 103 // TODO(erikkay) this is unfortunate. The interface declares that this method
111 // must be const (no good reason for it as far as I can tell) which means you 104 // must be const (no good reason for it as far as I can tell) which means you
112 // can't return self without doing this const_cast. Either we need to change 105 // can't return self without doing this const_cast. Either we need to change
113 // the interface, or we need to split out the view delegate into another 106 // the interface, or we need to split out the view delegate into another
114 // object (which is how WebContents works). 107 // object (which is how WebContents works).
115 return const_cast<ExtensionView*>(this); 108 return const_cast<ExtensionHost*>(this);
116 } 109 }
117 110
118 void ExtensionView::CreateNewWindow(int route_id, 111 void ExtensionHost::CreateNewWindow(int route_id,
119 base::WaitableEvent* modal_dialog_event) { 112 base::WaitableEvent* modal_dialog_event) {
120 delegate_view_helper_.CreateNewWindow(route_id, modal_dialog_event, 113 delegate_view_helper_.CreateNewWindow(
121 browser_->profile(), site_instance()); 114 route_id, modal_dialog_event, render_view_host()->process()->profile(),
115 site_instance());
122 } 116 }
123 117
124 void ExtensionView::CreateNewWidget(int route_id, bool activatable) { 118 void ExtensionHost::CreateNewWidget(int route_id, bool activatable) {
125 delegate_view_helper_.CreateNewWidget(route_id, activatable, 119 delegate_view_helper_.CreateNewWidget(route_id, activatable,
126 site_instance()->GetProcess()); 120 site_instance()->GetProcess());
127 } 121 }
128 122
129 void ExtensionView::ShowCreatedWindow(int route_id, 123 void ExtensionHost::ShowCreatedWindow(int route_id,
130 WindowOpenDisposition disposition, 124 WindowOpenDisposition disposition,
131 const gfx::Rect& initial_pos, 125 const gfx::Rect& initial_pos,
132 bool user_gesture) { 126 bool user_gesture) {
133 WebContents* contents = delegate_view_helper_.GetCreatedWindow(route_id); 127 WebContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
134 if (contents) { 128 if (contents) {
135 // TODO(erikkay) is it safe to pass in NULL as source? 129 // TODO(erikkay) is it safe to pass in NULL as source?
136 browser_->AddNewContents(NULL, contents, disposition, initial_pos, 130 GetBrowser()->AddTabContents(contents, disposition, initial_pos,
137 user_gesture); 131 user_gesture);
138 } 132 }
139 } 133 }
140 134
141 void ExtensionView::ShowCreatedWidget(int route_id, 135 void ExtensionHost::ShowCreatedWidget(int route_id,
142 const gfx::Rect& initial_pos) { 136 const gfx::Rect& initial_pos) {
143 RenderWidgetHostView* widget_host_view = 137 RenderWidgetHostView* widget_host_view =
144 delegate_view_helper_.GetCreatedWidget(route_id); 138 delegate_view_helper_.GetCreatedWidget(route_id);
145 browser_->RenderWidgetShowing(); 139 GetBrowser()->BrowserRenderWidgetShowing();
146 // TODO(erikkay): These two lines could be refactored with TabContentsView. 140 // TODO(erikkay): These two lines could be refactored with TabContentsView.
147 widget_host_view->InitAsPopup(render_view_host()->view(), 141 widget_host_view->InitAsPopup(render_view_host()->view(), initial_pos);
148 initial_pos);
149 widget_host_view->GetRenderWidgetHost()->Init(); 142 widget_host_view->GetRenderWidgetHost()->Init();
150 } 143 }
151 144
152 void ExtensionView::ShowContextMenu(const ContextMenuParams& params) { 145 void ExtensionHost::ShowContextMenu(const ContextMenuParams& params) {
153 // TODO(erikkay) - This is a temporary hack. Show a menu here instead. 146 // TODO(erikkay) - This is a temporary hack. Show a menu here instead.
154 render_view_host()->InspectElementAt(params.x, params.y); 147 render_view_host()->InspectElementAt(params.x, params.y);
155 } 148 }
156 149
157 void ExtensionView::StartDragging(const WebDropData& drop_data) { 150 void ExtensionHost::StartDragging(const WebDropData& drop_data) {
158 } 151 }
159 152
160 void ExtensionView::UpdateDragCursor(bool is_drop_target) { 153 void ExtensionHost::UpdateDragCursor(bool is_drop_target) {
161 } 154 }
162 155
163 void ExtensionView::TakeFocus(bool reverse) { 156 void ExtensionHost::TakeFocus(bool reverse) {
164 } 157 }
165 158
166 void ExtensionView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { 159 void ExtensionHost::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
167 } 160 }
168 161
162 Browser* ExtensionHost::GetBrowser() {
163 if (view_)
164 return view_->browser();
165 Browser* browser = BrowserList::FindBrowserWithProfile(
166 render_view_host()->process()->profile());
167 // TODO(mpcomplete): what this verifies doesn't actually happen yet.
168 CHECK(browser) << "ExtensionHost running in Profile with no Browser active."
169 " It should have been deleted.";
170 return browser;
171 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/extensions/extension_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698