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

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

Issue 159202: add mole info to toolstrip definition and enable moles (Closed)
Patch Set: ready for review Created 11 years, 5 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
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_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
11 #include "chrome/browser/browser_list.h" 11 #include "chrome/browser/browser_list.h"
12 #include "chrome/browser/debugger/devtools_manager.h" 12 #include "chrome/browser/debugger/devtools_manager.h"
13 #include "chrome/browser/extensions/extension_message_service.h" 13 #include "chrome/browser/extensions/extension_message_service.h"
14 #include "chrome/browser/profile.h" 14 #include "chrome/browser/profile.h"
15 #include "chrome/browser/renderer_host/render_view_host.h" 15 #include "chrome/browser/renderer_host/render_view_host.h"
16 #include "chrome/browser/renderer_host/render_process_host.h" 16 #include "chrome/browser/renderer_host/render_process_host.h"
17 #include "chrome/browser/renderer_host/render_widget_host.h" 17 #include "chrome/browser/renderer_host/render_widget_host.h"
18 #include "chrome/browser/renderer_host/render_widget_host_view.h" 18 #include "chrome/browser/renderer_host/render_widget_host_view.h"
19 #include "chrome/browser/renderer_host/site_instance.h" 19 #include "chrome/browser/renderer_host/site_instance.h"
20 #include "chrome/browser/tab_contents/infobar_delegate.h" 20 #include "chrome/browser/tab_contents/infobar_delegate.h"
21 #include "chrome/browser/tab_contents/tab_contents.h" 21 #include "chrome/browser/tab_contents/tab_contents.h"
22 #include "chrome/browser/tab_contents/tab_contents_view.h" 22 #include "chrome/browser/tab_contents/tab_contents_view.h"
23 #include "chrome/common/bindings_policy.h" 23 #include "chrome/common/bindings_policy.h"
24 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
25 #include "chrome/common/notification_service.h" 25 #include "chrome/common/notification_service.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "chrome/common/pref_service.h" 27 #include "chrome/common/pref_service.h"
28 #include "chrome/common/render_messages.h"
28 29
29 #include "grit/browser_resources.h" 30 #include "grit/browser_resources.h"
30 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
31 #include "grit/theme_resources.h" 32 #include "grit/theme_resources.h"
32 33
33 #include "webkit/glue/context_menu.h" 34 #include "webkit/glue/context_menu.h"
34 35
35 namespace { 36 namespace {
36 37
37 class CrashedExtensionInfobarDelegate : public ConfirmInfoBarDelegate { 38 class CrashedExtensionInfobarDelegate : public ConfirmInfoBarDelegate {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 render_view_host_->set_view(host_view); 133 render_view_host_->set_view(host_view);
133 render_view_host_->CreateRenderView(); 134 render_view_host_->CreateRenderView();
134 render_view_host_->NavigateToURL(url_); 135 render_view_host_->NavigateToURL(url_);
135 DCHECK(IsRenderViewLive()); 136 DCHECK(IsRenderViewLive());
136 NotificationService::current()->Notify( 137 NotificationService::current()->Notify(
137 NotificationType::EXTENSION_PROCESS_CREATED, 138 NotificationType::EXTENSION_PROCESS_CREATED,
138 Source<Profile>(profile_), 139 Source<Profile>(profile_),
139 Details<ExtensionHost>(this)); 140 Details<ExtensionHost>(this));
140 } 141 }
141 142
143 void ExtensionHost::NavigateToURL(const GURL& url) {
144 url_ = url;
145 render_view_host_->NavigateToURL(url_);
146 }
147
142 void ExtensionHost::RecoverCrashedExtension() { 148 void ExtensionHost::RecoverCrashedExtension() {
143 DCHECK(!IsRenderViewLive()); 149 DCHECK(!IsRenderViewLive());
144 #if defined(TOOLKIT_VIEWS) 150 #if defined(TOOLKIT_VIEWS)
145 if (view_.get()) { 151 if (view_.get()) {
146 // The view should call us back to CreateRenderView, which is the place 152 // The view should call us back to CreateRenderView, which is the place
147 // where we create the render process and fire notification. 153 // where we create the render process and fire notification.
148 view_->RecoverCrashedExtension(); 154 view_->RecoverCrashedExtension();
149 } else { 155 } else {
150 CreateRenderView(NULL); 156 CreateRenderView(NULL);
151 } 157 }
(...skipping 18 matching lines...) Expand all
170 current_tab->AddInfoBar( 176 current_tab->AddInfoBar(
171 new CrashedExtensionInfobarDelegate(current_tab, this)); 177 new CrashedExtensionInfobarDelegate(current_tab, this));
172 } 178 }
173 } 179 }
174 NotificationService::current()->Notify( 180 NotificationService::current()->Notify(
175 NotificationType::EXTENSION_PROCESS_CRASHED, 181 NotificationType::EXTENSION_PROCESS_CRASHED,
176 Source<Profile>(profile_), 182 Source<Profile>(profile_),
177 Details<ExtensionHost>(this)); 183 Details<ExtensionHost>(this));
178 } 184 }
179 185
186 void ExtensionHost::DidNavigate(RenderViewHost* render_view_host,
187 const ViewHostMsg_FrameNavigate_Params& params) {
188 // We only care when the outer frame changes.
189 switch (params.transition) {
190 case PageTransition::AUTO_SUBFRAME:
191 case PageTransition::MANUAL_SUBFRAME:
192 return;
193 }
194
195 extension_function_dispatcher_.reset(
196 new ExtensionFunctionDispatcher(render_view_host_, this, url_));
Matt Perry 2009/07/24 23:11:11 I think we need to use params.url here, or this wo
197 }
198
180 void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { 199 void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) {
181 // TODO(aa): This is toolstrip-specific and should probably not be here. 200 #if defined(TOOLKIT_VIEWS)
182 // ExtensionToolstrip in bookmark_bar_view.cc? 201 ExtensionView* view = view_.get();
183 static const StringPiece toolstrip_css( 202 if (view) {
184 ResourceBundle::GetSharedInstance().GetRawDataResource( 203 // TODO(erikkay) this injection should really happen in the renderer.
185 IDR_EXTENSIONS_TOOLSTRIP_CSS)); 204 // When the Jerry's view type change lands, investigate moving this there.
186 render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string()); 205
206 // As a toolstrip, inject our toolstrip CSS to make it easier for toolstrips
207 // to blend in with the chrome UI.
208 if (view->is_toolstrip()) {
209 static const StringPiece toolstrip_css(
210 ResourceBundle::GetSharedInstance().GetRawDataResource(
211 IDR_EXTENSIONS_TOOLSTRIP_CSS));
212 render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string());
213 } else {
214 // No CSS injecting currently, but call SetDidInsertCSS to tell the view
215 // that it's OK to display.
216 view->SetDidInsertCSS(true);
217 }
218 }
219 #endif
187 220
188 did_stop_loading_ = true; 221 did_stop_loading_ = true;
189 } 222 }
190 223
191 void ExtensionHost::RunJavaScriptMessage(const std::wstring& message, 224 void ExtensionHost::RunJavaScriptMessage(const std::wstring& message,
192 const std::wstring& default_prompt, 225 const std::wstring& default_prompt,
193 const GURL& frame_url, 226 const GURL& frame_url,
194 const int flags, 227 const int flags,
195 IPC::Message* reply_msg, 228 IPC::Message* reply_msg,
196 bool* did_suppress_message) { 229 bool* did_suppress_message) {
(...skipping 18 matching lines...) Expand all
215 } 248 }
216 249
217 void ExtensionHost::DidInsertCSS() { 250 void ExtensionHost::DidInsertCSS() {
218 #if defined(TOOLKIT_VIEWS) 251 #if defined(TOOLKIT_VIEWS)
219 if (view_.get()) 252 if (view_.get())
220 view_->SetDidInsertCSS(true); 253 view_->SetDidInsertCSS(true);
221 #endif 254 #endif
222 } 255 }
223 256
224 RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() { 257 RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() {
225 // TODO(erikkay) this is unfortunate. The interface declares that this method
226 // must be const (no good reason for it as far as I can tell) which means you
227 // can't return self without doing this const_cast. Either we need to change
228 // the interface, or we need to split out the view delegate into another
229 // object (which is how TabContents works).
230 return this; 258 return this;
231 } 259 }
232 260
233 void ExtensionHost::CreateNewWindow(int route_id, 261 void ExtensionHost::CreateNewWindow(int route_id,
234 base::WaitableEvent* modal_dialog_event) { 262 base::WaitableEvent* modal_dialog_event) {
235 delegate_view_helper_.CreateNewWindow( 263 delegate_view_helper_.CreateNewWindow(
236 route_id, modal_dialog_event, render_view_host()->process()->profile(), 264 route_id, modal_dialog_event, render_view_host()->process()->profile(),
237 site_instance()); 265 site_instance());
238 } 266 }
239 267
240 void ExtensionHost::CreateNewWidget(int route_id, bool activatable) { 268 void ExtensionHost::CreateNewWidget(int route_id, bool activatable) {
241 delegate_view_helper_.CreateNewWidget(route_id, activatable, 269 delegate_view_helper_.CreateNewWidget(route_id, activatable,
242 site_instance()->GetProcess()); 270 site_instance()->GetProcess());
243 } 271 }
244 272
245 void ExtensionHost::ShowCreatedWindow(int route_id, 273 void ExtensionHost::ShowCreatedWindow(int route_id,
246 WindowOpenDisposition disposition, 274 WindowOpenDisposition disposition,
247 const gfx::Rect& initial_pos, 275 const gfx::Rect& initial_pos,
248 bool user_gesture, 276 bool user_gesture,
249 const GURL& creator_url) { 277 const GURL& creator_url) {
250 TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id); 278 TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
251 if (contents) { 279 if (contents) {
252 Browser* browser = GetBrowser(); 280 Browser* browser = GetBrowser();
253 DCHECK(browser); 281 DCHECK(browser);
254 if (!browser) 282 if (!browser)
255 return; 283 return;
256 // TODO(erikkay) is it safe to pass in NULL as source?
257 browser->AddTabContents(contents, disposition, initial_pos, 284 browser->AddTabContents(contents, disposition, initial_pos,
258 user_gesture); 285 user_gesture);
259 } 286 }
260 } 287 }
261 288
262 void ExtensionHost::ShowCreatedWidget(int route_id, 289 void ExtensionHost::ShowCreatedWidget(int route_id,
263 const gfx::Rect& initial_pos) { 290 const gfx::Rect& initial_pos) {
264 RenderWidgetHostView* widget_host_view = 291 RenderWidgetHostView* widget_host_view =
265 delegate_view_helper_.GetCreatedWidget(route_id); 292 delegate_view_helper_.GetCreatedWidget(route_id);
266 Browser *browser = GetBrowser(); 293 Browser *browser = GetBrowser();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, 344 // NOTE(rafaelw): This can return NULL in some circumstances. In particular,
318 // a toolstrip or background_page onload chrome.tabs api call can make it 345 // a toolstrip or background_page onload chrome.tabs api call can make it
319 // into here before the browser is sufficiently initialized to return here. 346 // into here before the browser is sufficiently initialized to return here.
320 // A similar situation may arise during shutdown. 347 // A similar situation may arise during shutdown.
321 // TODO(rafaelw): Delay creation of background_page until the browser 348 // TODO(rafaelw): Delay creation of background_page until the browser
322 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 349 // is available. http://code.google.com/p/chromium/issues/detail?id=13284
323 return browser; 350 return browser;
324 } 351 }
325 352
326 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { 353 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) {
327 extension_function_dispatcher_.reset(
328 new ExtensionFunctionDispatcher(render_view_host_, this, url_));
329 } 354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698