Chromium Code Reviews| 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/ui/ash/chrome_shell_delegate.h" | 5 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/host/root_window_host_factory.h" | 8 #include "ash/host/root_window_host_factory.h" |
| 9 #include "ash/launcher/launcher_types.h" | 9 #include "ash/launcher/launcher_types.h" |
| 10 #include "ash/magnifier/magnifier_constants.h" | 10 #include "ash/magnifier/magnifier_constants.h" |
| 11 #include "ash/session_state_delegate.h" | 11 #include "ash/session_state_delegate.h" |
| 12 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
| 13 #include "ash/system/tray/system_tray_delegate.h" | 13 #include "ash/system/tray/system_tray_delegate.h" |
| 14 #include "ash/wm/window_properties.h" | 14 #include "ash/wm/window_properties.h" |
| 15 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "chrome/browser/app_mode/app_mode_utils.h" | 20 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 21 #include "chrome/browser/extensions/shell_window_registry.h" | 21 #include "chrome/browser/extensions/shell_window_registry.h" |
| 22 #include "chrome/browser/lifetime/application_lifetime.h" | 22 #include "chrome/browser/lifetime/application_lifetime.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/sessions/tab_restore_service.h" | 24 #include "chrome/browser/sessions/tab_restore_service.h" |
| 25 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 25 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 26 #include "chrome/browser/sessions/tab_restore_service_observer.h" | |
| 26 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" | 27 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
| 27 #include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h" | 28 #include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h" |
| 28 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h" | 29 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h" |
| 29 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 30 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 30 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 31 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
| 31 #include "chrome/browser/ui/ash/session_state_delegate.h" | 32 #include "chrome/browser/ui/ash/session_state_delegate.h" |
| 32 #include "chrome/browser/ui/ash/user_action_handler.h" | 33 #include "chrome/browser/ui/ash/user_action_handler.h" |
| 33 #include "chrome/browser/ui/ash/window_positioner.h" | 34 #include "chrome/browser/ui/ash/window_positioner.h" |
| 34 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
| 35 #include "chrome/browser/ui/browser_commands.h" | 36 #include "chrome/browser/ui/browser_commands.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 50 #include "ui/aura/window.h" | 51 #include "ui/aura/window.h" |
| 51 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 52 | 53 |
| 53 #if defined(OS_CHROMEOS) | 54 #if defined(OS_CHROMEOS) |
| 54 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" | 55 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" |
| 55 #endif | 56 #endif |
| 56 | 57 |
| 57 // static | 58 // static |
| 58 ChromeShellDelegate* ChromeShellDelegate::instance_ = NULL; | 59 ChromeShellDelegate* ChromeShellDelegate::instance_ = NULL; |
| 59 | 60 |
| 61 namespace { | |
| 62 | |
| 63 void RestoreTabUsingProfile(Profile* profile) { | |
| 64 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile); | |
| 65 service->RestoreMostRecentEntry(NULL, chrome::HOST_DESKTOP_TYPE_ASH); | |
| 66 } | |
| 67 | |
| 68 } // namespace | |
| 69 | |
| 70 // TabRestoreHelper is used to restore a tab. In particular when the user | |
| 71 // attempts to a restore a tab if the TabRestoreService hasn't finished loading | |
| 72 // this waits for it. Once the TabRestoreService finishes loading the tab is | |
| 73 // restored. | |
| 74 class ChromeShellDelegate::TabRestoreHelper : public TabRestoreServiceObserver { | |
| 75 public: | |
| 76 TabRestoreHelper(ChromeShellDelegate* delegate, | |
| 77 Profile* profile, | |
| 78 TabRestoreService* service) | |
| 79 : delegate_(delegate), | |
| 80 profile_(profile), | |
| 81 tab_restore_service_(service) { | |
| 82 tab_restore_service_->AddObserver(this); | |
| 83 } | |
| 84 | |
| 85 virtual ~TabRestoreHelper() { | |
| 86 tab_restore_service_->RemoveObserver(this); | |
| 87 } | |
| 88 | |
| 89 TabRestoreService* tab_restore_service() { return tab_restore_service_; } | |
| 90 | |
| 91 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE { | |
| 92 } | |
| 93 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE { | |
| 94 // This destroys us. | |
| 95 delegate_->tab_restore_helper_.reset(); | |
| 96 } | |
| 97 | |
| 98 virtual void TabRestoreServiceLoaded(TabRestoreService* service) OVERRIDE { | |
| 99 RestoreTabUsingProfile(profile_); | |
| 100 // This destroys us. | |
| 101 delegate_->tab_restore_helper_.reset(); | |
| 102 } | |
| 103 | |
| 104 private: | |
| 105 ChromeShellDelegate* delegate_; | |
| 106 Profile* profile_; | |
| 107 TabRestoreService* tab_restore_service_; | |
| 108 | |
| 109 DISALLOW_COPY_AND_ASSIGN(TabRestoreHelper); | |
| 110 }; | |
| 111 | |
| 60 ChromeShellDelegate::ChromeShellDelegate() | 112 ChromeShellDelegate::ChromeShellDelegate() |
| 61 : window_positioner_(new ash::WindowPositioner()), | 113 : window_positioner_(new ash::WindowPositioner()), |
| 62 weak_factory_(this), | 114 weak_factory_(this), |
| 63 launcher_delegate_(NULL) { | 115 launcher_delegate_(NULL) { |
| 64 instance_ = this; | 116 instance_ = this; |
| 65 PlatformInit(); | 117 PlatformInit(); |
| 66 } | 118 } |
| 67 | 119 |
| 68 ChromeShellDelegate::~ChromeShellDelegate() { | 120 ChromeShellDelegate::~ChromeShellDelegate() { |
| 69 if (instance_ == this) | 121 if (instance_ == this) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 | 195 |
| 144 // Get out of fullscreen when in fullscreen mode. | 196 // Get out of fullscreen when in fullscreen mode. |
| 145 if (ash::wm::IsWindowFullscreen(window)) { | 197 if (ash::wm::IsWindowFullscreen(window)) { |
| 146 ToggleFullscreen(); | 198 ToggleFullscreen(); |
| 147 return; | 199 return; |
| 148 } | 200 } |
| 149 ash::wm::ToggleMaximizedWindow(window); | 201 ash::wm::ToggleMaximizedWindow(window); |
| 150 } | 202 } |
| 151 | 203 |
| 152 void ChromeShellDelegate::RestoreTab() { | 204 void ChromeShellDelegate::RestoreTab() { |
| 153 Browser* browser = GetTargetBrowser(); | 205 if (tab_restore_helper_.get()) { |
| 154 // Do not restore tabs while in the incognito mode. | 206 DCHECK(!tab_restore_helper_->tab_restore_service()->IsLoaded()); |
| 155 if (browser->profile()->IsOffTheRecord()) | 207 return; |
| 208 } | |
| 209 | |
| 210 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); | |
|
James Cook
2013/05/09 16:36:31
I think the old code will create a new browser win
sky
2013/05/09 16:42:12
This is done at line 65 now. Specifically:
service
James Cook
2013/05/09 16:48:30
Ah, I didn't notice RestoreMostRecentEntry did tha
| |
| 211 Profile* profile = browser ? browser->profile() : NULL; | |
| 212 if (!profile) | |
| 213 profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | |
| 214 if (profile->IsOffTheRecord()) | |
| 156 return; | 215 return; |
| 157 TabRestoreService* service = | 216 TabRestoreService* service = |
| 158 TabRestoreServiceFactory::GetForProfile(browser->profile()); | 217 TabRestoreServiceFactory::GetForProfile(profile); |
| 159 if (!service) | 218 if (!service) |
| 160 return; | 219 return; |
| 220 | |
| 161 if (service->IsLoaded()) { | 221 if (service->IsLoaded()) { |
| 162 chrome::RestoreTab(browser); | 222 RestoreTabUsingProfile(profile); |
| 163 } else { | 223 } else { |
| 224 tab_restore_helper_.reset(new TabRestoreHelper(this, profile, service)); | |
| 164 service->LoadTabsFromLastSession(); | 225 service->LoadTabsFromLastSession(); |
| 165 // LoadTabsFromLastSession is asynchronous, so TabRestoreService has not | |
| 166 // finished loading the entries at this point. Wait for next event cycle | |
| 167 // which loads the restored tab entries. | |
| 168 MessageLoop::current()->PostTask( | |
| 169 FROM_HERE, | |
| 170 base::Bind(&ChromeShellDelegate::RestoreTab, | |
| 171 weak_factory_.GetWeakPtr())); | |
| 172 } | 226 } |
| 173 } | 227 } |
| 174 | 228 |
| 175 void ChromeShellDelegate::ShowTaskManager() { | 229 void ChromeShellDelegate::ShowTaskManager() { |
| 176 chrome::OpenTaskManager(NULL, false); | 230 chrome::OpenTaskManager(NULL, false); |
| 177 } | 231 } |
| 178 | 232 |
| 179 content::BrowserContext* ChromeShellDelegate::GetCurrentBrowserContext() { | 233 content::BrowserContext* ChromeShellDelegate::GetCurrentBrowserContext() { |
| 180 return ProfileManager::GetDefaultProfile(); | 234 return ProfileManager::GetDefaultProfile(); |
| 181 } | 235 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 return browser; | 431 return browser; |
| 378 return chrome::FindOrCreateTabbedBrowser( | 432 return chrome::FindOrCreateTabbedBrowser( |
| 379 ProfileManager::GetDefaultProfileOrOffTheRecord(), | 433 ProfileManager::GetDefaultProfileOrOffTheRecord(), |
| 380 chrome::HOST_DESKTOP_TYPE_ASH); | 434 chrome::HOST_DESKTOP_TYPE_ASH); |
| 381 } | 435 } |
| 382 | 436 |
| 383 keyboard::KeyboardControllerProxy* | 437 keyboard::KeyboardControllerProxy* |
| 384 ChromeShellDelegate::CreateKeyboardControllerProxy() { | 438 ChromeShellDelegate::CreateKeyboardControllerProxy() { |
| 385 return new AshKeyboardControllerProxy(); | 439 return new AshKeyboardControllerProxy(); |
| 386 } | 440 } |
| OLD | NEW |