Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ash/chrome_new_window_client.h" | 5 #include "chrome/browser/ui/ash/chrome_new_window_client.h" |
| 6 | 6 |
| 7 #include "ash/content/keyboard_overlay/keyboard_overlay_view.h" | 7 #include "ash/content/keyboard_overlay/keyboard_overlay_view.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "chrome/browser/chromeos/file_manager/app_id.h" | 9 #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 10 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h" | 10 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" | 26 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "components/sessions/core/tab_restore_service.h" | 28 #include "components/sessions/core/tab_restore_service.h" |
| 29 #include "components/sessions/core/tab_restore_service_observer.h" | 29 #include "components/sessions/core/tab_restore_service_observer.h" |
| 30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/common/service_manager_connection.h" | 31 #include "content/public/common/service_manager_connection.h" |
| 32 #include "extensions/browser/extension_system.h" | 32 #include "extensions/browser/extension_system.h" |
| 33 #include "extensions/common/constants.h" | 33 #include "extensions/common/constants.h" |
| 34 #include "services/service_manager/public/cpp/connector.h" | 34 #include "services/service_manager/public/cpp/connector.h" |
| 35 #include "ui/base/window_open_disposition.h" | 35 #include "ui/base/window_open_disposition.h" |
| 36 #include "ui/wm/public/activation_client.h" | |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 void RestoreTabUsingProfile(Profile* profile) { | 40 void RestoreTabUsingProfile(Profile* profile) { |
| 40 sessions::TabRestoreService* service = | 41 sessions::TabRestoreService* service = |
| 41 TabRestoreServiceFactory::GetForProfile(profile); | 42 TabRestoreServiceFactory::GetForProfile(profile); |
| 42 service->RestoreMostRecentEntry(nullptr); | 43 service->RestoreMostRecentEntry(nullptr); |
| 43 } | 44 } |
| 44 | 45 |
| 46 // Returns the active browser that has active browser window, if any. | |
| 47 Browser* GetActiveBrowser() { | |
| 48 Browser* browser = BrowserList::GetInstance()->GetLastActive(); | |
| 49 if (browser) { | |
| 50 aura::Window* window = browser->window()->GetNativeWindow(); | |
| 51 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.
| |
| 52 aura::client::GetActivationClient(window->GetRootWindow()); | |
| 53 if (client->GetActiveWindow() == window) | |
| 54 return browser; | |
| 55 } | |
| 56 return nullptr; | |
| 57 } | |
| 58 | |
| 45 } // namespace | 59 } // namespace |
| 46 | 60 |
| 47 ChromeNewWindowClient::ChromeNewWindowClient() : binding_(this) { | 61 ChromeNewWindowClient::ChromeNewWindowClient() : binding_(this) { |
| 48 service_manager::Connector* connector = | 62 service_manager::Connector* connector = |
| 49 content::ServiceManagerConnection::GetForProcess()->GetConnector(); | 63 content::ServiceManagerConnection::GetForProcess()->GetConnector(); |
| 50 connector->BindInterface(ash_util::GetAshServiceName(), | 64 connector->BindInterface(ash_util::GetAshServiceName(), |
| 51 &new_window_controller_); | 65 &new_window_controller_); |
| 52 | 66 |
| 53 // Register this object as the client interface implementation. | 67 // Register this object as the client interface implementation. |
| 54 ash::mojom::NewWindowClientAssociatedPtrInfo ptr_info; | 68 ash::mojom::NewWindowClientAssociatedPtrInfo ptr_info; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 109 |
| 96 private: | 110 private: |
| 97 ChromeNewWindowClient* delegate_; | 111 ChromeNewWindowClient* delegate_; |
| 98 Profile* profile_; | 112 Profile* profile_; |
| 99 sessions::TabRestoreService* tab_restore_service_; | 113 sessions::TabRestoreService* tab_restore_service_; |
| 100 | 114 |
| 101 DISALLOW_COPY_AND_ASSIGN(TabRestoreHelper); | 115 DISALLOW_COPY_AND_ASSIGN(TabRestoreHelper); |
| 102 }; | 116 }; |
| 103 | 117 |
| 104 void ChromeNewWindowClient::NewTab() { | 118 void ChromeNewWindowClient::NewTab() { |
| 105 Browser* browser = BrowserList::GetInstance()->GetLastActive(); | 119 Browser* browser = GetActiveBrowser(); |
| 106 if (browser && browser->is_type_tabbed()) { | 120 if (browser && browser->is_type_tabbed()) { |
| 107 chrome::NewTab(browser); | 121 chrome::NewTab(browser); |
| 108 return; | 122 return; |
| 109 } | 123 } |
| 110 | 124 |
| 111 // Display a browser, setting the focus to the location bar after it is shown. | 125 // Display a browser, setting the focus to the location bar after it is shown. |
| 112 { | 126 { |
| 113 chrome::ScopedTabbedBrowserDisplayer displayer( | 127 chrome::ScopedTabbedBrowserDisplayer displayer( |
| 114 ProfileManager::GetActiveUserProfile()); | 128 ProfileManager::GetActiveUserProfile()); |
| 115 browser = displayer.browser(); | 129 browser = displayer.browser(); |
| 116 chrome::NewTab(browser); | 130 chrome::NewTab(browser); |
| 117 } | 131 } |
| 118 | 132 |
| 119 browser->SetFocusToLocationBar(false); | 133 browser->SetFocusToLocationBar(false); |
| 120 } | 134 } |
| 121 | 135 |
| 122 void ChromeNewWindowClient::NewWindow(bool is_incognito) { | 136 void ChromeNewWindowClient::NewWindow(bool is_incognito) { |
| 123 Browser* browser = BrowserList::GetInstance()->GetLastActive(); | 137 Browser* browser = GetActiveBrowser(); |
| 124 Profile* profile = (browser && browser->profile()) | 138 Profile* profile = (browser && browser->profile()) |
| 125 ? browser->profile()->GetOriginalProfile() | 139 ? browser->profile()->GetOriginalProfile() |
| 126 : ProfileManager::GetActiveUserProfile(); | 140 : ProfileManager::GetActiveUserProfile(); |
| 127 chrome::NewEmptyWindow(is_incognito ? profile->GetOffTheRecordProfile() | 141 chrome::NewEmptyWindow(is_incognito ? profile->GetOffTheRecordProfile() |
| 128 : profile); | 142 : profile); |
| 129 } | 143 } |
| 130 | 144 |
| 131 void ChromeNewWindowClient::OpenFileManager() { | 145 void ChromeNewWindowClient::OpenFileManager() { |
| 132 using file_manager::kFileManagerAppId; | 146 using file_manager::kFileManagerAppId; |
| 133 Profile* const profile = ProfileManager::GetActiveUserProfile(); | 147 Profile* const profile = ProfileManager::GetActiveUserProfile(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 Profile* const profile = ProfileManager::GetActiveUserProfile(); | 180 Profile* const profile = ProfileManager::GetActiveUserProfile(); |
| 167 chrome::ShowHelpForProfile(profile, chrome::HELP_SOURCE_KEYBOARD); | 181 chrome::ShowHelpForProfile(profile, chrome::HELP_SOURCE_KEYBOARD); |
| 168 } | 182 } |
| 169 | 183 |
| 170 void ChromeNewWindowClient::RestoreTab() { | 184 void ChromeNewWindowClient::RestoreTab() { |
| 171 if (tab_restore_helper_.get()) { | 185 if (tab_restore_helper_.get()) { |
| 172 DCHECK(!tab_restore_helper_->tab_restore_service()->IsLoaded()); | 186 DCHECK(!tab_restore_helper_->tab_restore_service()->IsLoaded()); |
| 173 return; | 187 return; |
| 174 } | 188 } |
| 175 | 189 |
| 176 Browser* browser = BrowserList::GetInstance()->GetLastActive(); | 190 Browser* browser = GetActiveBrowser(); |
| 177 Profile* profile = browser ? browser->profile() : NULL; | 191 Profile* profile = browser ? browser->profile() : nullptr; |
| 178 if (!profile) | 192 if (!profile) |
| 179 profile = ProfileManager::GetActiveUserProfile(); | 193 profile = ProfileManager::GetActiveUserProfile(); |
| 180 if (profile->IsOffTheRecord()) | 194 if (profile->IsOffTheRecord()) |
| 181 return; | 195 return; |
| 182 sessions::TabRestoreService* service = | 196 sessions::TabRestoreService* service = |
| 183 TabRestoreServiceFactory::GetForProfile(profile); | 197 TabRestoreServiceFactory::GetForProfile(profile); |
| 184 if (!service) | 198 if (!service) |
| 185 return; | 199 return; |
| 186 | 200 |
| 187 if (service->IsLoaded()) { | 201 if (service->IsLoaded()) { |
| 188 RestoreTabUsingProfile(profile); | 202 RestoreTabUsingProfile(profile); |
| 189 } else { | 203 } else { |
| 190 tab_restore_helper_.reset(new TabRestoreHelper(this, profile, service)); | 204 tab_restore_helper_.reset(new TabRestoreHelper(this, profile, service)); |
| 191 service->LoadTabsFromLastSession(); | 205 service->LoadTabsFromLastSession(); |
| 192 } | 206 } |
| 193 } | 207 } |
| 194 | 208 |
| 195 void ChromeNewWindowClient::ShowKeyboardOverlay() { | 209 void ChromeNewWindowClient::ShowKeyboardOverlay() { |
| 196 // TODO(mazda): Move the show logic to ash (http://crbug.com/124222). | 210 // TODO(mazda): Move the show logic to ash (http://crbug.com/124222). |
| 197 Profile* profile = ProfileManager::GetActiveUserProfile(); | 211 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 198 std::string url(chrome::kChromeUIKeyboardOverlayURL); | 212 std::string url(chrome::kChromeUIKeyboardOverlayURL); |
| 199 ash::KeyboardOverlayView::ShowDialog(profile, new ChromeWebContentsHandler, | 213 ash::KeyboardOverlayView::ShowDialog(profile, new ChromeWebContentsHandler, |
| 200 GURL(url)); | 214 GURL(url)); |
| 201 } | 215 } |
| 202 | 216 |
| 203 void ChromeNewWindowClient::ShowTaskManager() { | 217 void ChromeNewWindowClient::ShowTaskManager() { |
| 204 chrome::OpenTaskManager(NULL); | 218 chrome::OpenTaskManager(nullptr); |
| 205 } | 219 } |
| 206 | 220 |
| 207 void ChromeNewWindowClient::OpenFeedbackPage() { | 221 void ChromeNewWindowClient::OpenFeedbackPage() { |
| 208 chrome::OpenFeedbackDialog(BrowserList::GetInstance()->GetLastActive()); | 222 chrome::OpenFeedbackDialog(GetActiveBrowser()); |
| 209 } | 223 } |
| OLD | NEW |