| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/instant/instant_loader.h" | 5 #include "chrome/browser/instant/instant_loader.h" |
| 6 | 6 |
| 7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 8 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" | 8 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
| 9 #include "chrome/browser/favicon/favicon_tab_helper.h" | 9 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 10 #include "chrome/browser/history/history_tab_helper.h" | 10 #include "chrome/browser/history/history_tab_helper.h" |
| 11 #include "chrome/browser/instant/instant_controller.h" | 11 #include "chrome/browser/instant/instant_controller.h" |
| 12 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" | 12 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" |
| 13 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 13 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 14 #include "chrome/browser/ui/constrained_window_tab_helper.h" | |
| 15 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" | |
| 16 #include "chrome/browser/ui/search/search_tab_helper.h" | 14 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 17 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 18 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" | 16 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" |
| 17 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" |
| 18 #include "chrome/browser/ui/web_contents_modal_dialog_manager_delegate.h" |
| 19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
| 21 #include "content/public/browser/render_widget_host_view.h" | 21 #include "content/public/browser/render_widget_host_view.h" |
| 22 #include "content/public/browser/web_contents_delegate.h" | 22 #include "content/public/browser/web_contents_delegate.h" |
| 23 #include "content/public/browser/web_contents_view.h" | 23 #include "content/public/browser/web_contents_view.h" |
| 24 #include "ipc/ipc_message.h" | 24 #include "ipc/ipc_message.h" |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 int kUserDataKey; | 28 int kUserDataKey; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 39 InstantLoader* const loader_; | 39 InstantLoader* const loader_; |
| 40 | 40 |
| 41 DISALLOW_COPY_AND_ASSIGN(InstantLoaderUserData); | 41 DISALLOW_COPY_AND_ASSIGN(InstantLoaderUserData); |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 } | 44 } |
| 45 | 45 |
| 46 // WebContentsDelegateImpl ----------------------------------------------------- | 46 // WebContentsDelegateImpl ----------------------------------------------------- |
| 47 | 47 |
| 48 class InstantLoader::WebContentsDelegateImpl | 48 class InstantLoader::WebContentsDelegateImpl |
| 49 : public ConstrainedWindowTabHelperDelegate, | 49 : public WebContentsModalDialogManagerDelegate, |
| 50 public CoreTabHelperDelegate, | 50 public CoreTabHelperDelegate, |
| 51 public content::WebContentsDelegate { | 51 public content::WebContentsDelegate { |
| 52 public: | 52 public: |
| 53 explicit WebContentsDelegateImpl(InstantLoader* loader); | 53 explicit WebContentsDelegateImpl(InstantLoader* loader); |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 // Overridden from ConstrainedWindowTabHelperDelegate: | 56 // Overridden from WebContentsModalDialogManagerDelegate: |
| 57 virtual bool ShouldFocusConstrainedWindow() OVERRIDE; | 57 virtual bool ShouldFocusWebContentsModalDialog() OVERRIDE; |
| 58 | 58 |
| 59 // Overridden from CoreTabHelperDelegate: | 59 // Overridden from CoreTabHelperDelegate: |
| 60 virtual void SwapTabContents(content::WebContents* old_contents, | 60 virtual void SwapTabContents(content::WebContents* old_contents, |
| 61 content::WebContents* new_contents) OVERRIDE; | 61 content::WebContents* new_contents) OVERRIDE; |
| 62 | 62 |
| 63 // Overridden from content::WebContentsDelegate: | 63 // Overridden from content::WebContentsDelegate: |
| 64 virtual bool ShouldSuppressDialogs() OVERRIDE; | 64 virtual bool ShouldSuppressDialogs() OVERRIDE; |
| 65 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; | 65 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; |
| 66 virtual void LostCapture() OVERRIDE; | 66 virtual void LostCapture() OVERRIDE; |
| 67 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; | 67 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 InstantLoader* const loader_; | 83 InstantLoader* const loader_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateImpl); | 85 DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateImpl); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 InstantLoader::WebContentsDelegateImpl::WebContentsDelegateImpl( | 88 InstantLoader::WebContentsDelegateImpl::WebContentsDelegateImpl( |
| 89 InstantLoader* loader) | 89 InstantLoader* loader) |
| 90 : loader_(loader) { | 90 : loader_(loader) { |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool InstantLoader::WebContentsDelegateImpl::ShouldFocusConstrainedWindow() { | 93 bool InstantLoader::WebContentsDelegateImpl::ShouldFocusWebContentsModalDialog( |
| 94 // Return false so that constrained windows are not initially focused. If we | 94 ) { |
| 95 // did otherwise the preview would prematurely get committed when focus goes | 95 // Return false so that web contents modal dialogs are not initially |
| 96 // to the constrained window. | 96 // focused. If we did otherwise the preview would prematurely get committed |
| 97 // when focus goes to the dialog. |
| 97 return false; | 98 return false; |
| 98 } | 99 } |
| 99 | 100 |
| 100 void InstantLoader::WebContentsDelegateImpl::SwapTabContents( | 101 void InstantLoader::WebContentsDelegateImpl::SwapTabContents( |
| 101 content::WebContents* old_contents, | 102 content::WebContents* old_contents, |
| 102 content::WebContents* new_contents) { | 103 content::WebContents* new_contents) { |
| 103 // If this is being called, something is swapping in to loader's |contents_| | 104 // If this is being called, something is swapping in to loader's |contents_| |
| 104 // before we've added it to the tab strip. | 105 // before we've added it to the tab strip. |
| 105 loader_->ReplacePreviewContents(old_contents, new_contents); | 106 loader_->ReplacePreviewContents(old_contents, new_contents); |
| 106 } | 107 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 // contents is added to the tab strip. | 358 // contents is added to the tab strip. |
| 358 | 359 |
| 359 // Tab helpers to control popups. | 360 // Tab helpers to control popups. |
| 360 BlockedContentTabHelper::CreateForWebContents(contents()); | 361 BlockedContentTabHelper::CreateForWebContents(contents()); |
| 361 BlockedContentTabHelper::FromWebContents(contents())-> | 362 BlockedContentTabHelper::FromWebContents(contents())-> |
| 362 SetAllContentsBlocked(true); | 363 SetAllContentsBlocked(true); |
| 363 TabSpecificContentSettings::CreateForWebContents(contents()); | 364 TabSpecificContentSettings::CreateForWebContents(contents()); |
| 364 TabSpecificContentSettings::FromWebContents(contents())-> | 365 TabSpecificContentSettings::FromWebContents(contents())-> |
| 365 SetPopupsBlocked(true); | 366 SetPopupsBlocked(true); |
| 366 | 367 |
| 367 // A tab helper to control constrained windows. | 368 // A manager to control web contents modal dialogs. |
| 368 ConstrainedWindowTabHelper::CreateForWebContents(contents()); | 369 WebContentsModalDialogManager::CreateForWebContents(contents()); |
| 369 ConstrainedWindowTabHelper::FromWebContents(contents())-> | 370 WebContentsModalDialogManager::FromWebContents(contents())-> |
| 370 set_delegate(delegate_.get()); | 371 set_delegate(delegate_.get()); |
| 371 | 372 |
| 372 // A tab helper to catch prerender content swapping shenanigans. | 373 // A tab helper to catch prerender content swapping shenanigans. |
| 373 CoreTabHelper::CreateForWebContents(contents()); | 374 CoreTabHelper::CreateForWebContents(contents()); |
| 374 CoreTabHelper::FromWebContents(contents())->set_delegate(delegate_.get()); | 375 CoreTabHelper::FromWebContents(contents())->set_delegate(delegate_.get()); |
| 375 | 376 |
| 376 // Tab helpers used when committing a preview. | 377 // Tab helpers used when committing a preview. |
| 377 chrome::search::SearchTabHelper::CreateForWebContents(contents()); | 378 chrome::search::SearchTabHelper::CreateForWebContents(contents()); |
| 378 HistoryTabHelper::CreateForWebContents(contents()); | 379 HistoryTabHelper::CreateForWebContents(contents()); |
| 379 | 380 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 403 contents_->RemoveUserData(&kUserDataKey); | 404 contents_->RemoveUserData(&kUserDataKey); |
| 404 contents_->SetDelegate(NULL); | 405 contents_->SetDelegate(NULL); |
| 405 | 406 |
| 406 // Undo tab helper work done in SetupPreviewContents(). | 407 // Undo tab helper work done in SetupPreviewContents(). |
| 407 | 408 |
| 408 BlockedContentTabHelper::FromWebContents(contents())-> | 409 BlockedContentTabHelper::FromWebContents(contents())-> |
| 409 SetAllContentsBlocked(false); | 410 SetAllContentsBlocked(false); |
| 410 TabSpecificContentSettings::FromWebContents(contents())-> | 411 TabSpecificContentSettings::FromWebContents(contents())-> |
| 411 SetPopupsBlocked(false); | 412 SetPopupsBlocked(false); |
| 412 | 413 |
| 413 ConstrainedWindowTabHelper::FromWebContents(contents())-> | 414 WebContentsModalDialogManager::FromWebContents(contents())-> |
| 414 set_delegate(NULL); | 415 set_delegate(NULL); |
| 415 | 416 |
| 416 CoreTabHelper::FromWebContents(contents())->set_delegate(NULL); | 417 CoreTabHelper::FromWebContents(contents())->set_delegate(NULL); |
| 417 | 418 |
| 418 #if defined(OS_MACOSX) | 419 #if defined(OS_MACOSX) |
| 419 if (content::RenderWidgetHostView* rwhv = | 420 if (content::RenderWidgetHostView* rwhv = |
| 420 contents_->GetRenderWidgetHostView()) | 421 contents_->GetRenderWidgetHostView()) |
| 421 rwhv->SetTakesFocusOnlyOnMouseDown(false); | 422 rwhv->SetTakesFocusOnlyOnMouseDown(false); |
| 422 registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 423 registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 423 content::Source<content::NavigationController>( | 424 content::Source<content::NavigationController>( |
| 424 &contents_->GetController())); | 425 &contents_->GetController())); |
| 425 #endif | 426 #endif |
| 426 } | 427 } |
| 427 | 428 |
| 428 void InstantLoader::ReplacePreviewContents(content::WebContents* old_contents, | 429 void InstantLoader::ReplacePreviewContents(content::WebContents* old_contents, |
| 429 content::WebContents* new_contents) { | 430 content::WebContents* new_contents) { |
| 430 DCHECK_EQ(old_contents, contents()); | 431 DCHECK_EQ(old_contents, contents()); |
| 431 CleanupPreviewContents(); | 432 CleanupPreviewContents(); |
| 432 // We release here without deleting so that the caller still has the | 433 // We release here without deleting so that the caller still has the |
| 433 // responsibility for deleting the WebContents. | 434 // responsibility for deleting the WebContents. |
| 434 ignore_result(contents_.release()); | 435 ignore_result(contents_.release()); |
| 435 contents_.reset(new_contents); | 436 contents_.reset(new_contents); |
| 436 SetupPreviewContents(); | 437 SetupPreviewContents(); |
| 437 controller_->SwappedWebContents(); | 438 controller_->SwappedWebContents(); |
| 438 } | 439 } |
| OLD | NEW |