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

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: Updated Created 8 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
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 view_->Init(); 171 view_->Init();
172 #elif defined(TOOLKIT_GTK) 172 #elif defined(TOOLKIT_GTK)
173 view_.reset(new ExtensionViewGtk(this, browser)); 173 view_.reset(new ExtensionViewGtk(this, browser));
174 view_->Init(); 174 view_->Init();
175 #else 175 #else
176 // TODO(port) 176 // TODO(port)
177 NOTREACHED(); 177 NOTREACHED();
178 #endif 178 #endif
179 } 179 }
180 180
181 void ExtensionHost::CreateViewWithoutBrowser() {
182 CreateView(NULL);
183 }
184
185 WebContents* ExtensionHost::GetAssociatedWebContents() const { 181 WebContents* ExtensionHost::GetAssociatedWebContents() const {
186 return associated_web_contents_; 182 return associated_web_contents_;
187 } 183 }
188 184
189 void ExtensionHost::SetAssociatedWebContents( 185 void ExtensionHost::SetAssociatedWebContents(
190 content::WebContents* web_contents) { 186 content::WebContents* web_contents) {
191 associated_web_contents_ = web_contents; 187 associated_web_contents_ = web_contents;
192 if (web_contents) { 188 if (web_contents) {
193 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 189 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
194 content::Source<WebContents>(associated_web_contents_)); 190 content::Source<WebContents>(associated_web_contents_));
195 } 191 }
196 } 192 }
197 193
198
199 content::RenderProcessHost* ExtensionHost::render_process_host() const { 194 content::RenderProcessHost* ExtensionHost::render_process_host() const {
200 return render_view_host()->GetProcess(); 195 return render_view_host()->GetProcess();
201 } 196 }
202 197
203 RenderViewHost* ExtensionHost::render_view_host() const { 198 RenderViewHost* ExtensionHost::render_view_host() const {
204 // TODO(mpcomplete): This can be NULL. How do we handle that? 199 // TODO(mpcomplete): This can be NULL. How do we handle that?
205 return render_view_host_; 200 return render_view_host_;
206 } 201 }
207 202
208 bool ExtensionHost::IsRenderViewLive() const { 203 bool ExtensionHost::IsRenderViewLive() const {
209 return render_view_host()->IsRenderViewLive(); 204 return render_view_host()->IsRenderViewLive();
210 } 205 }
211 206
212 void ExtensionHost::CreateRenderViewSoon() { 207 void ExtensionHost::CreateRenderViewSoon() {
213 if ((render_process_host() && render_process_host()->HasConnection()) || 208 if ((render_process_host() && render_process_host()->HasConnection())) {
214 extension_->is_platform_app()) {
215 // If the process is already started, go ahead and initialize the RenderView 209 // If the process is already started, go ahead and initialize the RenderView
216 // synchronously. The process creation is the real meaty part that we want 210 // synchronously. The process creation is the real meaty part that we want
217 // to defer. 211 // to defer.
218 // We also skip the ratelimiting in the platform app case. This is a hack
219 // (see crbug.com/124350 for details).
220 CreateRenderViewNow(); 212 CreateRenderViewNow();
221 } else { 213 } else {
222 ProcessCreationQueue::GetInstance()->CreateSoon(this); 214 ProcessCreationQueue::GetInstance()->CreateSoon(this);
223 } 215 }
224 } 216 }
225 217
226 void ExtensionHost::CreateRenderViewNow() { 218 void ExtensionHost::CreateRenderViewNow() {
227 LoadInitialURL(); 219 LoadInitialURL();
228 if (is_background_page()) { 220 if (is_background_page()) {
229 DCHECK(IsRenderViewLive()); 221 DCHECK(IsRenderViewLive());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 282 }
291 break; 283 break;
292 default: 284 default:
293 NOTREACHED() << "Unexpected notification sent."; 285 NOTREACHED() << "Unexpected notification sent.";
294 break; 286 break;
295 } 287 }
296 } 288 }
297 289
298 void ExtensionHost::ResizeDueToAutoResize(WebContents* source, 290 void ExtensionHost::ResizeDueToAutoResize(WebContents* source,
299 const gfx::Size& new_size) { 291 const gfx::Size& new_size) {
300 if (view_.get()) 292 if (view())
301 view_->ResizeDueToAutoResize(new_size); 293 view()->ResizeDueToAutoResize(new_size);
302 } 294 }
303 295
304 void ExtensionHost::RenderViewGone(base::TerminationStatus status) { 296 void ExtensionHost::RenderViewGone(base::TerminationStatus status) {
305 // During browser shutdown, we may use sudden termination on an extension 297 // During browser shutdown, we may use sudden termination on an extension
306 // process, so it is expected to lose our connection to the render view. 298 // process, so it is expected to lose our connection to the render view.
307 // Do nothing. 299 // Do nothing.
308 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) 300 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID)
309 return; 301 return;
310 302
311 // In certain cases, multiple ExtensionHost objects may have pointed to 303 // In certain cases, multiple ExtensionHost objects may have pointed to
(...skipping 23 matching lines...) Expand all
335 327
336 render_view_host()->InsertCSS(string16(), css.as_string()); 328 render_view_host()->InsertCSS(string16(), css.as_string());
337 } 329 }
338 330
339 void ExtensionHost::DidStopLoading() { 331 void ExtensionHost::DidStopLoading() {
340 bool notify = !did_stop_loading_; 332 bool notify = !did_stop_loading_;
341 did_stop_loading_ = true; 333 did_stop_loading_ = true;
342 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || 334 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP ||
343 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || 335 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG ||
344 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR || 336 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR ||
345 extension_host_type_ == chrome::VIEW_TYPE_APP_SHELL ||
346 extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 337 extension_host_type_ == chrome::VIEW_TYPE_PANEL) {
347 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) 338 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)
348 if (view_.get()) 339 if (view())
349 view_->DidStopLoading(); 340 view()->DidStopLoading();
350 #endif 341 #endif
351 } 342 }
352 if (notify) { 343 if (notify) {
353 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 344 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
354 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime", 345 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime",
355 since_created_.Elapsed()); 346 since_created_.Elapsed());
356 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG) { 347 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG) {
357 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime", 348 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime",
358 since_created_.Elapsed()); 349 since_created_.Elapsed());
359 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) { 350 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) {
360 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime", 351 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime",
361 since_created_.Elapsed()); 352 since_created_.Elapsed());
362 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { 353 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) {
363 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime", 354 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime",
364 since_created_.Elapsed()); 355 since_created_.Elapsed());
365 } else if (extension_host_type_ == chrome::VIEW_TYPE_APP_SHELL) {
366 UMA_HISTOGRAM_TIMES("Extensions.ShellLoadTime", since_created_.Elapsed());
367 } else if (extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 356 } else if (extension_host_type_ == chrome::VIEW_TYPE_PANEL) {
368 UMA_HISTOGRAM_TIMES("Extensions.PanelLoadTime", since_created_.Elapsed()); 357 UMA_HISTOGRAM_TIMES("Extensions.PanelLoadTime", since_created_.Elapsed());
369 } 358 }
370 359
371 // Send the notification last, because it might result in this being 360 // Send the notification last, because it might result in this being
372 // deleted. 361 // deleted.
373 content::NotificationService::current()->Notify( 362 content::NotificationService::current()->Notify(
374 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, 363 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
375 content::Source<Profile>(profile_), 364 content::Source<Profile>(profile_),
376 content::Details<ExtensionHost>(this)); 365 content::Details<ExtensionHost>(this));
(...skipping 19 matching lines...) Expand all
396 } 385 }
397 } 386 }
398 } 387 }
399 388
400 void ExtensionHost::CloseContents(WebContents* contents) { 389 void ExtensionHost::CloseContents(WebContents* contents) {
401 // TODO(mpcomplete): is this check really necessary? 390 // TODO(mpcomplete): is this check really necessary?
402 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || 391 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP ||
403 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || 392 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG ||
404 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE || 393 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE ||
405 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR || 394 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR ||
406 extension_host_type_ == chrome::VIEW_TYPE_APP_SHELL ||
407 extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 395 extension_host_type_ == chrome::VIEW_TYPE_PANEL) {
408 Close(); 396 Close();
409 } 397 }
410 } 398 }
411 399
412 bool ExtensionHost::ShouldSuppressDialogs() {
413 return extension_->is_platform_app();
414 }
415
416 void ExtensionHost::WillRunJavaScriptDialog() { 400 void ExtensionHost::WillRunJavaScriptDialog() {
417 ExtensionProcessManager* pm = 401 ExtensionProcessManager* pm =
418 ExtensionSystem::Get(profile_)->process_manager(); 402 ExtensionSystem::Get(profile_)->process_manager();
419 if (pm) 403 if (pm)
420 pm->IncrementLazyKeepaliveCount(extension()); 404 pm->IncrementLazyKeepaliveCount(extension());
421 } 405 }
422 406
423 void ExtensionHost::DidCloseJavaScriptDialog() { 407 void ExtensionHost::DidCloseJavaScriptDialog() {
424 ExtensionProcessManager* pm = 408 ExtensionProcessManager* pm =
425 ExtensionSystem::Get(profile_)->process_manager(); 409 ExtensionSystem::Get(profile_)->process_manager();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 ExtensionProcessManager* pm = 489 ExtensionProcessManager* pm =
506 ExtensionSystem::Get(profile_)->process_manager(); 490 ExtensionSystem::Get(profile_)->process_manager();
507 if (pm) 491 if (pm)
508 pm->DecrementLazyKeepaliveCount(extension()); 492 pm->DecrementLazyKeepaliveCount(extension());
509 } 493 }
510 494
511 495
512 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { 496 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) {
513 render_view_host_ = render_view_host; 497 render_view_host_ = render_view_host;
514 498
515 if (view_.get()) 499 if (view())
516 view_->RenderViewCreated(); 500 view()->RenderViewCreated();
517 501
518 // If the host is bound to a browser, then extract its window id. 502 // If the host is bound to a browser, then extract its window id.
519 // Extensions hosted in ExternalTabContainer objects may not have 503 // Extensions hosted in ExternalTabContainer objects may not have
520 // an associated browser. 504 // an associated browser.
521 const Browser* browser = GetBrowser(); 505 const Browser* browser = GetBrowser();
522 if (browser) { 506 if (browser) {
523 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId( 507 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId(
524 render_view_host->GetRoutingID(), 508 render_view_host->GetRoutingID(),
525 ExtensionTabUtil::GetWindowId(browser))); 509 ExtensionTabUtil::GetWindowId(browser)));
526 } 510 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 params.user_gesture = user_gesture; 579 params.user_gesture = user_gesture;
596 browser::Navigate(&params); 580 browser::Navigate(&params);
597 } 581 }
598 582
599 void ExtensionHost::RenderViewReady() { 583 void ExtensionHost::RenderViewReady() {
600 content::NotificationService::current()->Notify( 584 content::NotificationService::current()->Notify(
601 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, 585 chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
602 content::Source<Profile>(profile_), 586 content::Source<Profile>(profile_),
603 content::Details<ExtensionHost>(this)); 587 content::Details<ExtensionHost>(this));
604 } 588 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698