| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/blocked_content/app_modal_dialog_helper.h" | 5 #include "chrome/browser/ui/blocked_content/app_modal_dialog_helper.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_finder.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
| 9 #include "chrome/browser/ui/browser_list.h" | 9 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/browser/web_contents_delegate.h" | 12 #include "content/public/browser/web_contents_delegate.h" |
| 13 | 13 |
| 14 AppModalDialogHelper::AppModalDialogHelper(content::WebContents* dialog_host) | 14 AppModalDialogHelper::AppModalDialogHelper(content::WebContents* dialog_host) |
| 15 : popup_(nullptr) { | 15 : popup_(nullptr) { |
| 16 // If the WebContents that triggered this dialog is not currently focused, we | 16 // If the WebContents that triggered this dialog is not currently focused, we |
| 17 // want to store a potential popup here to restore it after the dialog was | 17 // want to store a potential popup here to restore it after the dialog was |
| 18 // closed. | 18 // closed. |
| 19 chrome::HostDesktopType desktop_type = | 19 chrome::HostDesktopType desktop_type = |
| 20 chrome::GetHostDesktopTypeForNativeView(dialog_host->GetNativeView()); | 20 chrome::GetHostDesktopTypeForNativeView(dialog_host->GetNativeView()); |
| 21 Browser* active_browser = | 21 Browser* active_browser = |
| 22 BrowserList::GetInstance(desktop_type)->GetLastActive(); | 22 BrowserList::GetInstance(desktop_type)->GetLastActive(); |
| 23 content::WebContents* active_web_contents = | 23 content::WebContents* active_web_contents = |
| 24 active_browser->tab_strip_model()->GetActiveWebContents(); | 24 active_browser->tab_strip_model()->GetActiveWebContents(); |
| 25 if (active_browser->is_type_popup() && | 25 if (active_browser->is_type_popup() && |
| 26 active_web_contents && |
| 26 active_web_contents->GetOpener() == dialog_host) { | 27 active_web_contents->GetOpener() == dialog_host) { |
| 27 // It's indeed a popup from the dialog opening WebContents. Store it, so | 28 // It's indeed a popup from the dialog opening WebContents. Store it, so |
| 28 // we can focus it later. | 29 // we can focus it later. |
| 29 popup_ = active_web_contents; | 30 popup_ = active_web_contents; |
| 30 Observe(popup_); | 31 Observe(popup_); |
| 31 } | 32 } |
| 32 } | 33 } |
| 33 | 34 |
| 34 AppModalDialogHelper::~AppModalDialogHelper() { | 35 AppModalDialogHelper::~AppModalDialogHelper() { |
| 35 if (popup_) | 36 if (popup_) |
| 36 popup_->GetDelegate()->ActivateContents(popup_); | 37 popup_->GetDelegate()->ActivateContents(popup_); |
| 37 } | 38 } |
| 38 | 39 |
| 39 void AppModalDialogHelper::WebContentsDestroyed() { | 40 void AppModalDialogHelper::WebContentsDestroyed() { |
| 40 popup_ = nullptr; | 41 popup_ = nullptr; |
| 41 } | 42 } |
| OLD | NEW |