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

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

Issue 10119003: Pull shell window stuff out of ExtensionHost and put in ShellWindow (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: More stuff Created 8 years, 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <list> 7 #include <list>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 view_->Init(); 170 view_->Init();
171 #elif defined(TOOLKIT_GTK) 171 #elif defined(TOOLKIT_GTK)
172 view_.reset(new ExtensionViewGtk(this, browser)); 172 view_.reset(new ExtensionViewGtk(this, browser));
173 view_->Init(); 173 view_->Init();
174 #else 174 #else
175 // TODO(port) 175 // TODO(port)
176 NOTREACHED(); 176 NOTREACHED();
177 #endif 177 #endif
178 } 178 }
179 179
180 void ExtensionHost::CreateViewWithoutBrowser() {
181 CreateView(NULL);
182 }
183
184 WebContents* ExtensionHost::GetAssociatedWebContents() const { 180 WebContents* ExtensionHost::GetAssociatedWebContents() const {
185 return associated_web_contents_; 181 return associated_web_contents_;
186 } 182 }
187 183
188 void ExtensionHost::SetAssociatedWebContents( 184 void ExtensionHost::SetAssociatedWebContents(
189 content::WebContents* web_contents) { 185 content::WebContents* web_contents) {
190 associated_web_contents_ = web_contents; 186 associated_web_contents_ = web_contents;
191 if (web_contents) { 187 if (web_contents) {
192 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 188 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
193 content::Source<WebContents>(associated_web_contents_)); 189 content::Source<WebContents>(associated_web_contents_));
194 } 190 }
195 } 191 }
196 192
197
198 content::RenderProcessHost* ExtensionHost::render_process_host() const { 193 content::RenderProcessHost* ExtensionHost::render_process_host() const {
199 return render_view_host()->GetProcess(); 194 return render_view_host()->GetProcess();
200 } 195 }
201 196
202 RenderViewHost* ExtensionHost::render_view_host() const { 197 RenderViewHost* ExtensionHost::render_view_host() const {
203 // TODO(mpcomplete): This can be NULL. How do we handle that? 198 // TODO(mpcomplete): This can be NULL. How do we handle that?
204 return render_view_host_; 199 return render_view_host_;
205 } 200 }
206 201
207 bool ExtensionHost::IsRenderViewLive() const { 202 bool ExtensionHost::IsRenderViewLive() const {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 281 }
287 break; 282 break;
288 default: 283 default:
289 NOTREACHED() << "Unexpected notification sent."; 284 NOTREACHED() << "Unexpected notification sent.";
290 break; 285 break;
291 } 286 }
292 } 287 }
293 288
294 void ExtensionHost::ResizeDueToAutoResize(WebContents* source, 289 void ExtensionHost::ResizeDueToAutoResize(WebContents* source,
295 const gfx::Size& new_size) { 290 const gfx::Size& new_size) {
296 if (view_.get()) 291 if (view())
297 view_->ResizeDueToAutoResize(new_size); 292 view()->ResizeDueToAutoResize(new_size);
298 } 293 }
299 294
300 void ExtensionHost::RenderViewGone(base::TerminationStatus status) { 295 void ExtensionHost::RenderViewGone(base::TerminationStatus status) {
301 // During browser shutdown, we may use sudden termination on an extension 296 // During browser shutdown, we may use sudden termination on an extension
302 // process, so it is expected to lose our connection to the render view. 297 // process, so it is expected to lose our connection to the render view.
303 // Do nothing. 298 // Do nothing.
304 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) 299 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID)
305 return; 300 return;
306 301
307 // In certain cases, multiple ExtensionHost objects may have pointed to 302 // In certain cases, multiple ExtensionHost objects may have pointed to
(...skipping 23 matching lines...) Expand all
331 326
332 render_view_host()->InsertCSS(string16(), css.as_string()); 327 render_view_host()->InsertCSS(string16(), css.as_string());
333 } 328 }
334 329
335 void ExtensionHost::DidStopLoading() { 330 void ExtensionHost::DidStopLoading() {
336 bool notify = !did_stop_loading_; 331 bool notify = !did_stop_loading_;
337 did_stop_loading_ = true; 332 did_stop_loading_ = true;
338 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || 333 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP ||
339 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || 334 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG ||
340 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR || 335 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR ||
341 extension_host_type_ == chrome::VIEW_TYPE_APP_SHELL ||
342 extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 336 extension_host_type_ == chrome::VIEW_TYPE_PANEL) {
343 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) 337 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)
344 if (view_.get()) 338 if (view())
345 view_->DidStopLoading(); 339 view()->DidStopLoading();
346 #endif 340 #endif
347 } 341 }
348 if (notify) { 342 if (notify) {
349 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 343 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
350 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime", 344 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime",
351 since_created_.Elapsed()); 345 since_created_.Elapsed());
352 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG) { 346 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG) {
353 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime", 347 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime",
354 since_created_.Elapsed()); 348 since_created_.Elapsed());
355 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) { 349 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) {
356 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime", 350 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime",
357 since_created_.Elapsed()); 351 since_created_.Elapsed());
358 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { 352 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) {
359 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime", 353 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime",
360 since_created_.Elapsed()); 354 since_created_.Elapsed());
361 } else if (extension_host_type_ == chrome::VIEW_TYPE_APP_SHELL) {
362 UMA_HISTOGRAM_TIMES("Extensions.ShellLoadTime", since_created_.Elapsed());
363 } else if (extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 355 } else if (extension_host_type_ == chrome::VIEW_TYPE_PANEL) {
364 UMA_HISTOGRAM_TIMES("Extensions.PanelLoadTime", since_created_.Elapsed()); 356 UMA_HISTOGRAM_TIMES("Extensions.PanelLoadTime", since_created_.Elapsed());
365 } 357 }
366 358
367 // Send the notification last, because it might result in this being 359 // Send the notification last, because it might result in this being
368 // deleted. 360 // deleted.
369 content::NotificationService::current()->Notify( 361 content::NotificationService::current()->Notify(
370 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, 362 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
371 content::Source<Profile>(profile_), 363 content::Source<Profile>(profile_),
372 content::Details<ExtensionHost>(this)); 364 content::Details<ExtensionHost>(this));
(...skipping 26 matching lines...) Expand all
399 content::Source<Profile>(profile_), 391 content::Source<Profile>(profile_),
400 content::Details<ExtensionHost>(this)); 392 content::Details<ExtensionHost>(this));
401 } 393 }
402 394
403 void ExtensionHost::CloseContents(WebContents* contents) { 395 void ExtensionHost::CloseContents(WebContents* contents) {
404 // TODO(mpcomplete): is this check really necessary? 396 // TODO(mpcomplete): is this check really necessary?
405 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || 397 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP ||
406 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || 398 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG ||
407 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE || 399 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE ||
408 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR || 400 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR ||
409 extension_host_type_ == chrome::VIEW_TYPE_APP_SHELL ||
410 extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 401 extension_host_type_ == chrome::VIEW_TYPE_PANEL) {
411 Close(); 402 Close();
412 } 403 }
413 } 404 }
414 405
415 bool ExtensionHost::ShouldSuppressDialogs() {
416 return extension_->is_platform_app();
417 }
418
419 void ExtensionHost::WillRunJavaScriptDialog() { 406 void ExtensionHost::WillRunJavaScriptDialog() {
420 ExtensionProcessManager* pm = 407 ExtensionProcessManager* pm =
421 ExtensionSystem::Get(profile_)->process_manager(); 408 ExtensionSystem::Get(profile_)->process_manager();
422 if (pm) 409 if (pm)
423 pm->IncrementLazyKeepaliveCount(extension()); 410 pm->IncrementLazyKeepaliveCount(extension());
424 } 411 }
425 412
426 void ExtensionHost::DidCloseJavaScriptDialog() { 413 void ExtensionHost::DidCloseJavaScriptDialog() {
427 ExtensionProcessManager* pm = 414 ExtensionProcessManager* pm =
428 ExtensionSystem::Get(profile_)->process_manager(); 415 ExtensionSystem::Get(profile_)->process_manager();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 return handled; 469 return handled;
483 } 470 }
484 471
485 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { 472 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) {
486 extension_function_dispatcher_.Dispatch(params, render_view_host()); 473 extension_function_dispatcher_.Dispatch(params, render_view_host());
487 } 474 }
488 475
489 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { 476 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) {
490 render_view_host_ = render_view_host; 477 render_view_host_ = render_view_host;
491 478
492 if (view_.get()) 479 if (view())
493 view_->RenderViewCreated(); 480 view()->RenderViewCreated();
494 481
495 // If the host is bound to a browser, then extract its window id. 482 // If the host is bound to a browser, then extract its window id.
496 // Extensions hosted in ExternalTabContainer objects may not have 483 // Extensions hosted in ExternalTabContainer objects may not have
497 // an associated browser. 484 // an associated browser.
498 const Browser* browser = GetBrowser(); 485 const Browser* browser = GetBrowser();
499 if (browser) { 486 if (browser) {
500 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId( 487 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId(
501 render_view_host->GetRoutingID(), 488 render_view_host->GetRoutingID(),
502 ExtensionTabUtil::GetWindowId(browser))); 489 ExtensionTabUtil::GetWindowId(browser)));
503 } 490 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 params.user_gesture = user_gesture; 559 params.user_gesture = user_gesture;
573 browser::Navigate(&params); 560 browser::Navigate(&params);
574 } 561 }
575 562
576 void ExtensionHost::RenderViewReady() { 563 void ExtensionHost::RenderViewReady() {
577 content::NotificationService::current()->Notify( 564 content::NotificationService::current()->Notify(
578 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, 565 chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
579 content::Source<Profile>(profile_), 566 content::Source<Profile>(profile_),
580 content::Details<ExtensionHost>(this)); 567 content::Details<ExtensionHost>(this));
581 } 568 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698