Chromium Code Reviews| Index: chrome/browser/ui/ash/chrome_new_window_client.cc |
| diff --git a/chrome/browser/ui/ash/chrome_new_window_client.cc b/chrome/browser/ui/ash/chrome_new_window_client.cc |
| index 27f1ecb4c14cde1484d615614d1b51db9d0129e3..3209e22a3873bd03e47aa5797a5c1372dc29bdfa 100644 |
| --- a/chrome/browser/ui/ash/chrome_new_window_client.cc |
| +++ b/chrome/browser/ui/ash/chrome_new_window_client.cc |
| @@ -33,6 +33,7 @@ |
| #include "extensions/common/constants.h" |
| #include "services/service_manager/public/cpp/connector.h" |
| #include "ui/base/window_open_disposition.h" |
| +#include "ui/wm/public/activation_client.h" |
| namespace { |
| @@ -42,6 +43,19 @@ void RestoreTabUsingProfile(Profile* profile) { |
| service->RestoreMostRecentEntry(nullptr); |
| } |
| +// Returns the active browser that has active browser window, if any. |
| +Browser* GetActiveBrowser() { |
| + Browser* browser = BrowserList::GetInstance()->GetLastActive(); |
| + if (browser) { |
| + aura::Window* window = browser->window()->GetNativeWindow(); |
| + aura::client::ActivationClient* client = |
|
oshima
2017/01/30 18:09:24
nit: include activation_client.h
Qiang(Joe) Xu
2017/01/31 06:55:55
It is added in this patch.
|
| + aura::client::GetActivationClient(window->GetRootWindow()); |
| + if (client->GetActiveWindow() == window) |
| + return browser; |
| + } |
| + return nullptr; |
| +} |
| + |
| } // namespace |
| ChromeNewWindowClient::ChromeNewWindowClient() : binding_(this) { |
| @@ -102,7 +116,7 @@ class ChromeNewWindowClient::TabRestoreHelper |
| }; |
| void ChromeNewWindowClient::NewTab() { |
| - Browser* browser = BrowserList::GetInstance()->GetLastActive(); |
| + Browser* browser = GetActiveBrowser(); |
| if (browser && browser->is_type_tabbed()) { |
| chrome::NewTab(browser); |
| return; |
| @@ -120,7 +134,7 @@ void ChromeNewWindowClient::NewTab() { |
| } |
| void ChromeNewWindowClient::NewWindow(bool is_incognito) { |
| - Browser* browser = BrowserList::GetInstance()->GetLastActive(); |
| + Browser* browser = GetActiveBrowser(); |
| Profile* profile = (browser && browser->profile()) |
| ? browser->profile()->GetOriginalProfile() |
| : ProfileManager::GetActiveUserProfile(); |
| @@ -173,8 +187,8 @@ void ChromeNewWindowClient::RestoreTab() { |
| return; |
| } |
| - Browser* browser = BrowserList::GetInstance()->GetLastActive(); |
| - Profile* profile = browser ? browser->profile() : NULL; |
| + Browser* browser = GetActiveBrowser(); |
| + Profile* profile = browser ? browser->profile() : nullptr; |
| if (!profile) |
| profile = ProfileManager::GetActiveUserProfile(); |
| if (profile->IsOffTheRecord()) |
| @@ -201,9 +215,9 @@ void ChromeNewWindowClient::ShowKeyboardOverlay() { |
| } |
| void ChromeNewWindowClient::ShowTaskManager() { |
| - chrome::OpenTaskManager(NULL); |
| + chrome::OpenTaskManager(nullptr); |
| } |
| void ChromeNewWindowClient::OpenFeedbackPage() { |
| - chrome::OpenFeedbackDialog(BrowserList::GetInstance()->GetLastActive()); |
| + chrome::OpenFeedbackDialog(GetActiveBrowser()); |
| } |