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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } | 285 } |
291 break; | 286 break; |
292 default: | 287 default: |
293 NOTREACHED() << "Unexpected notification sent."; | 288 NOTREACHED() << "Unexpected notification sent."; |
294 break; | 289 break; |
295 } | 290 } |
296 } | 291 } |
297 | 292 |
298 void ExtensionHost::ResizeDueToAutoResize(WebContents* source, | 293 void ExtensionHost::ResizeDueToAutoResize(WebContents* source, |
299 const gfx::Size& new_size) { | 294 const gfx::Size& new_size) { |
300 if (view_.get()) | 295 if (view()) |
301 view_->ResizeDueToAutoResize(new_size); | 296 view()->ResizeDueToAutoResize(new_size); |
302 } | 297 } |
303 | 298 |
304 void ExtensionHost::RenderViewGone(base::TerminationStatus status) { | 299 void ExtensionHost::RenderViewGone(base::TerminationStatus status) { |
305 // During browser shutdown, we may use sudden termination on an extension | 300 // 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. | 301 // process, so it is expected to lose our connection to the render view. |
307 // Do nothing. | 302 // Do nothing. |
308 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) | 303 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) |
309 return; | 304 return; |
310 | 305 |
311 // In certain cases, multiple ExtensionHost objects may have pointed to | 306 // In certain cases, multiple ExtensionHost objects may have pointed to |
(...skipping 23 matching lines...) Expand all Loading... |
335 | 330 |
336 render_view_host()->InsertCSS(string16(), css.as_string()); | 331 render_view_host()->InsertCSS(string16(), css.as_string()); |
337 } | 332 } |
338 | 333 |
339 void ExtensionHost::DidStopLoading() { | 334 void ExtensionHost::DidStopLoading() { |
340 bool notify = !did_stop_loading_; | 335 bool notify = !did_stop_loading_; |
341 did_stop_loading_ = true; | 336 did_stop_loading_ = true; |
342 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || | 337 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || |
343 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || | 338 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || |
344 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR || | 339 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) { | 340 extension_host_type_ == chrome::VIEW_TYPE_PANEL) { |
347 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) | 341 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) |
348 if (view_.get()) | 342 if (view()) |
349 view_->DidStopLoading(); | 343 view()->DidStopLoading(); |
350 #endif | 344 #endif |
351 } | 345 } |
352 if (notify) { | 346 if (notify) { |
353 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 347 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
354 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime", | 348 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime", |
355 since_created_.Elapsed()); | 349 since_created_.Elapsed()); |
356 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG) { | 350 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG) { |
357 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime", | 351 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime", |
358 since_created_.Elapsed()); | 352 since_created_.Elapsed()); |
359 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) { | 353 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) { |
360 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime", | 354 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime", |
361 since_created_.Elapsed()); | 355 since_created_.Elapsed()); |
362 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { | 356 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { |
363 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime", | 357 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime", |
364 since_created_.Elapsed()); | 358 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) { | 359 } else if (extension_host_type_ == chrome::VIEW_TYPE_PANEL) { |
368 UMA_HISTOGRAM_TIMES("Extensions.PanelLoadTime", since_created_.Elapsed()); | 360 UMA_HISTOGRAM_TIMES("Extensions.PanelLoadTime", since_created_.Elapsed()); |
369 } | 361 } |
370 | 362 |
371 // Send the notification last, because it might result in this being | 363 // Send the notification last, because it might result in this being |
372 // deleted. | 364 // deleted. |
373 content::NotificationService::current()->Notify( | 365 content::NotificationService::current()->Notify( |
374 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 366 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
375 content::Source<Profile>(profile_), | 367 content::Source<Profile>(profile_), |
376 content::Details<ExtensionHost>(this)); | 368 content::Details<ExtensionHost>(this)); |
(...skipping 19 matching lines...) Expand all Loading... |
396 } | 388 } |
397 } | 389 } |
398 } | 390 } |
399 | 391 |
400 void ExtensionHost::CloseContents(WebContents* contents) { | 392 void ExtensionHost::CloseContents(WebContents* contents) { |
401 // TODO(mpcomplete): is this check really necessary? | 393 // TODO(mpcomplete): is this check really necessary? |
402 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || | 394 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || |
403 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || | 395 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || |
404 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE || | 396 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE || |
405 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR || | 397 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) { | 398 extension_host_type_ == chrome::VIEW_TYPE_PANEL) { |
408 Close(); | 399 Close(); |
409 } | 400 } |
410 } | 401 } |
411 | 402 |
412 bool ExtensionHost::ShouldSuppressDialogs() { | |
413 return extension_->is_platform_app(); | |
414 } | |
415 | |
416 void ExtensionHost::WillRunJavaScriptDialog() { | 403 void ExtensionHost::WillRunJavaScriptDialog() { |
417 ExtensionProcessManager* pm = | 404 ExtensionProcessManager* pm = |
418 ExtensionSystem::Get(profile_)->process_manager(); | 405 ExtensionSystem::Get(profile_)->process_manager(); |
419 if (pm) | 406 if (pm) |
420 pm->IncrementLazyKeepaliveCount(extension()); | 407 pm->IncrementLazyKeepaliveCount(extension()); |
421 } | 408 } |
422 | 409 |
423 void ExtensionHost::DidCloseJavaScriptDialog() { | 410 void ExtensionHost::DidCloseJavaScriptDialog() { |
424 ExtensionProcessManager* pm = | 411 ExtensionProcessManager* pm = |
425 ExtensionSystem::Get(profile_)->process_manager(); | 412 ExtensionSystem::Get(profile_)->process_manager(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 ExtensionProcessManager* pm = | 492 ExtensionProcessManager* pm = |
506 ExtensionSystem::Get(profile_)->process_manager(); | 493 ExtensionSystem::Get(profile_)->process_manager(); |
507 if (pm) | 494 if (pm) |
508 pm->DecrementLazyKeepaliveCount(extension()); | 495 pm->DecrementLazyKeepaliveCount(extension()); |
509 } | 496 } |
510 | 497 |
511 | 498 |
512 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { | 499 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { |
513 render_view_host_ = render_view_host; | 500 render_view_host_ = render_view_host; |
514 | 501 |
515 if (view_.get()) | 502 if (view()) |
516 view_->RenderViewCreated(); | 503 view()->RenderViewCreated(); |
517 | 504 |
518 // If the host is bound to a browser, then extract its window id. | 505 // If the host is bound to a browser, then extract its window id. |
519 // Extensions hosted in ExternalTabContainer objects may not have | 506 // Extensions hosted in ExternalTabContainer objects may not have |
520 // an associated browser. | 507 // an associated browser. |
521 const Browser* browser = GetBrowser(); | 508 const Browser* browser = GetBrowser(); |
522 if (browser) { | 509 if (browser) { |
523 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId( | 510 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId( |
524 render_view_host->GetRoutingID(), | 511 render_view_host->GetRoutingID(), |
525 ExtensionTabUtil::GetWindowId(browser))); | 512 ExtensionTabUtil::GetWindowId(browser))); |
526 } | 513 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 params.user_gesture = user_gesture; | 582 params.user_gesture = user_gesture; |
596 browser::Navigate(¶ms); | 583 browser::Navigate(¶ms); |
597 } | 584 } |
598 | 585 |
599 void ExtensionHost::RenderViewReady() { | 586 void ExtensionHost::RenderViewReady() { |
600 content::NotificationService::current()->Notify( | 587 content::NotificationService::current()->Notify( |
601 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, | 588 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
602 content::Source<Profile>(profile_), | 589 content::Source<Profile>(profile_), |
603 content::Details<ExtensionHost>(this)); | 590 content::Details<ExtensionHost>(this)); |
604 } | 591 } |
OLD | NEW |