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