| 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 <ApplicationServices/ApplicationServices.h> | 5 #include <ApplicationServices/ApplicationServices.h> |
| 6 #import <Cocoa/Cocoa.h> | 6 #import <Cocoa/Cocoa.h> |
| 7 | 7 |
| 8 #include "apps/app_shim/app_shim_handler_mac.h" | 8 #include "apps/app_shim/app_shim_handler_mac.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 void CreateAppList(Profile* profile); | 58 void CreateAppList(Profile* profile); |
| 59 void ShowWindowNearDock(); | 59 void ShowWindowNearDock(); |
| 60 | 60 |
| 61 // AppListService overrides: | 61 // AppListService overrides: |
| 62 virtual void Init(Profile* initial_profile) OVERRIDE; | 62 virtual void Init(Profile* initial_profile) OVERRIDE; |
| 63 virtual void ShowAppList(Profile* requested_profile) OVERRIDE; | 63 virtual void ShowAppList(Profile* requested_profile) OVERRIDE; |
| 64 virtual void DismissAppList() OVERRIDE; | 64 virtual void DismissAppList() OVERRIDE; |
| 65 virtual bool IsAppListVisible() const OVERRIDE; | 65 virtual bool IsAppListVisible() const OVERRIDE; |
| 66 virtual void EnableAppList() OVERRIDE; | |
| 67 virtual gfx::NativeWindow GetAppListWindow() OVERRIDE; | 66 virtual gfx::NativeWindow GetAppListWindow() OVERRIDE; |
| 68 | 67 |
| 68 // AppListServiceImpl override: |
| 69 virtual void CreateShortcut() OVERRIDE; |
| 70 |
| 69 // AppShimHandler overrides: | 71 // AppShimHandler overrides: |
| 70 virtual void OnShimLaunch(apps::AppShimHandler::Host* host, | 72 virtual void OnShimLaunch(apps::AppShimHandler::Host* host, |
| 71 apps::AppShimLaunchType launch_type) OVERRIDE; | 73 apps::AppShimLaunchType launch_type) OVERRIDE; |
| 72 virtual void OnShimClose(apps::AppShimHandler::Host* host) OVERRIDE; | 74 virtual void OnShimClose(apps::AppShimHandler::Host* host) OVERRIDE; |
| 73 virtual void OnShimFocus(apps::AppShimHandler::Host* host, | 75 virtual void OnShimFocus(apps::AppShimHandler::Host* host, |
| 74 apps::AppShimFocusType focus_type) OVERRIDE; | 76 apps::AppShimFocusType focus_type) OVERRIDE; |
| 75 virtual void OnShimSetHidden(apps::AppShimHandler::Host* host, | 77 virtual void OnShimSetHidden(apps::AppShimHandler::Host* host, |
| 76 bool hidden) OVERRIDE; | 78 bool hidden) OVERRIDE; |
| 77 virtual void OnShimQuit(apps::AppShimHandler::Host* host) OVERRIDE; | 79 virtual void OnShimQuit(apps::AppShimHandler::Host* host) OVERRIDE; |
| 78 | 80 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 shortcut_info.favicon.Add( | 165 shortcut_info.favicon.Add( |
| 164 *resource_bundle.GetImageSkiaNamed(IDR_APP_LIST_256)); | 166 *resource_bundle.GetImageSkiaNamed(IDR_APP_LIST_256)); |
| 165 } | 167 } |
| 166 | 168 |
| 167 // TODO(tapted): Create a dock icon using chrome/browser/mac/dock.h . | 169 // TODO(tapted): Create a dock icon using chrome/browser/mac/dock.h . |
| 168 web_app::CreateShortcuts(shortcut_info, | 170 web_app::CreateShortcuts(shortcut_info, |
| 169 ShellIntegration::ShortcutLocations(), | 171 ShellIntegration::ShortcutLocations(), |
| 170 web_app::ALLOW_DUPLICATE_SHORTCUTS); | 172 web_app::ALLOW_DUPLICATE_SHORTCUTS); |
| 171 } | 173 } |
| 172 | 174 |
| 173 // Check that there is an app list shim. If enabling and there is not, make one. | |
| 174 // If disabling with --enable-app-list-shim=0, and there is one, delete it. | |
| 175 void CheckAppListShimOnFileThread(const base::FilePath& profile_path) { | |
| 176 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
| 177 const bool enable = | |
| 178 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppListShim); | |
| 179 base::FilePath install_path = web_app::GetAppInstallPath( | |
| 180 GetAppListShortcutInfo(profile_path)); | |
| 181 if (enable == file_util::PathExists(install_path)) | |
| 182 return; | |
| 183 | |
| 184 if (enable) { | |
| 185 content::BrowserThread::PostTask( | |
| 186 content::BrowserThread::UI, FROM_HERE, | |
| 187 base::Bind(&CreateAppListShim, profile_path)); | |
| 188 return; | |
| 189 } | |
| 190 | |
| 191 // Sanity check because deleting things recursively is scary. | |
| 192 CHECK(install_path.MatchesExtension(".app")); | |
| 193 base::Delete(install_path, true /* recursive */); | |
| 194 } | |
| 195 | |
| 196 void CreateShortcutsInDefaultLocation( | 175 void CreateShortcutsInDefaultLocation( |
| 197 const ShellIntegration::ShortcutInfo& shortcut_info) { | 176 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 198 web_app::CreateShortcuts(shortcut_info, | 177 web_app::CreateShortcuts(shortcut_info, |
| 199 ShellIntegration::ShortcutLocations(), | 178 ShellIntegration::ShortcutLocations(), |
| 200 web_app::ALLOW_DUPLICATE_SHORTCUTS); | 179 web_app::ALLOW_DUPLICATE_SHORTCUTS); |
| 201 } | 180 } |
| 202 | 181 |
| 203 AppListControllerDelegateCocoa::AppListControllerDelegateCocoa() {} | 182 AppListControllerDelegateCocoa::AppListControllerDelegateCocoa() {} |
| 204 | 183 |
| 205 AppListControllerDelegateCocoa::~AppListControllerDelegateCocoa() {} | 184 AppListControllerDelegateCocoa::~AppListControllerDelegateCocoa() {} |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 new AppListViewDelegate(new AppListControllerDelegateCocoa(), profile())); | 239 new AppListViewDelegate(new AppListControllerDelegateCocoa(), profile())); |
| 261 window_controller_.reset([[AppListWindowController alloc] init]); | 240 window_controller_.reset([[AppListWindowController alloc] init]); |
| 262 [[window_controller_ appListViewController] setDelegate:delegate.Pass()]; | 241 [[window_controller_ appListViewController] setDelegate:delegate.Pass()]; |
| 263 } | 242 } |
| 264 | 243 |
| 265 void AppListServiceMac::Init(Profile* initial_profile) { | 244 void AppListServiceMac::Init(Profile* initial_profile) { |
| 266 // On Mac, Init() is called multiple times for a process: any time there is no | 245 // On Mac, Init() is called multiple times for a process: any time there is no |
| 267 // browser window open and a new window is opened, and during process startup | 246 // browser window open and a new window is opened, and during process startup |
| 268 // to handle the silent launch case (e.g. for app shims). In the startup case, | 247 // to handle the silent launch case (e.g. for app shims). In the startup case, |
| 269 // a profile has not yet been determined so |initial_profile| will be NULL. | 248 // a profile has not yet been determined so |initial_profile| will be NULL. |
| 270 if (initial_profile) { | 249 static bool init_called_with_profile = false; |
| 271 static bool checked_shim = false; | 250 if (initial_profile && !init_called_with_profile) { |
| 272 if (!checked_shim) { | 251 init_called_with_profile = true; |
| 273 checked_shim = true; | 252 SharedDesktopInit(initial_profile); |
| 274 content::BrowserThread::PostTask( | |
| 275 content::BrowserThread::FILE, FROM_HERE, | |
| 276 base::Bind(&CheckAppListShimOnFileThread, | |
| 277 initial_profile->GetPath())); | |
| 278 } | |
| 279 } | 253 } |
| 280 | 254 |
| 281 static bool init_called = false; | 255 static bool init_called = false; |
| 282 if (init_called) | 256 if (init_called) |
| 283 return; | 257 return; |
| 284 | 258 |
| 285 init_called = true; | 259 init_called = true; |
| 286 apps::AppShimHandler::RegisterHandler(app_mode::kAppListModeId, | 260 apps::AppShimHandler::RegisterHandler(app_mode::kAppListModeId, |
| 287 AppListServiceMac::GetInstance()); | 261 AppListServiceMac::GetInstance()); |
| 288 } | 262 } |
| 289 | 263 |
| 290 void AppListServiceMac::ShowAppList(Profile* requested_profile) { | 264 void AppListServiceMac::ShowAppList(Profile* requested_profile) { |
| 291 InvalidatePendingProfileLoads(); | 265 InvalidatePendingProfileLoads(); |
| 292 | 266 |
| 293 if (IsAppListVisible() && (requested_profile == profile())) { | 267 if (IsAppListVisible() && (requested_profile == profile())) { |
| 294 ShowWindowNearDock(); | 268 ShowWindowNearDock(); |
| 295 return; | 269 return; |
| 296 } | 270 } |
| 297 | 271 |
| 298 SaveProfilePathToLocalState(requested_profile->GetPath()); | 272 SetProfilePath(requested_profile->GetPath()); |
| 299 | 273 |
| 300 DismissAppList(); | 274 DismissAppList(); |
| 301 CreateAppList(requested_profile); | 275 CreateAppList(requested_profile); |
| 302 ShowWindowNearDock(); | 276 ShowWindowNearDock(); |
| 303 } | 277 } |
| 304 | 278 |
| 305 void AppListServiceMac::DismissAppList() { | 279 void AppListServiceMac::DismissAppList() { |
| 306 if (!IsAppListVisible()) | 280 if (!IsAppListVisible()) |
| 307 return; | 281 return; |
| 308 | 282 |
| 309 [[window_controller_ window] close]; | 283 [[window_controller_ window] close]; |
| 310 | 284 |
| 311 FOR_EACH_OBSERVER(apps::AppShimHandler::Host, | 285 FOR_EACH_OBSERVER(apps::AppShimHandler::Host, |
| 312 observers_, | 286 observers_, |
| 313 OnAppClosed()); | 287 OnAppClosed()); |
| 314 } | 288 } |
| 315 | 289 |
| 316 bool AppListServiceMac::IsAppListVisible() const { | 290 bool AppListServiceMac::IsAppListVisible() const { |
| 317 return [[window_controller_ window] isVisible]; | 291 return [[window_controller_ window] isVisible]; |
| 318 } | 292 } |
| 319 | 293 |
| 320 void AppListServiceMac::EnableAppList() { | 294 void AppListServiceMac::CreateShortcut() { |
| 321 // TODO(tapted): Implement enable logic here for OSX. | 295 CreateAppListShim(GetProfilePath(base::FilePath())); |
| 322 } | 296 } |
| 323 | 297 |
| 324 NSWindow* AppListServiceMac::GetAppListWindow() { | 298 NSWindow* AppListServiceMac::GetAppListWindow() { |
| 325 return [window_controller_ window]; | 299 return [window_controller_ window]; |
| 326 } | 300 } |
| 327 | 301 |
| 328 void AppListServiceMac::OnShimLaunch(apps::AppShimHandler::Host* host, | 302 void AppListServiceMac::OnShimLaunch(apps::AppShimHandler::Host* host, |
| 329 apps::AppShimLaunchType launch_type) { | 303 apps::AppShimLaunchType launch_type) { |
| 330 ShowForSavedProfile(); | 304 ShowForSavedProfile(); |
| 331 observers_.AddObserver(host); | 305 observers_.AddObserver(host); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 432 |
| 459 // static | 433 // static |
| 460 AppListService* AppListService::Get() { | 434 AppListService* AppListService::Get() { |
| 461 return AppListServiceMac::GetInstance(); | 435 return AppListServiceMac::GetInstance(); |
| 462 } | 436 } |
| 463 | 437 |
| 464 // static | 438 // static |
| 465 void AppListService::InitAll(Profile* initial_profile) { | 439 void AppListService::InitAll(Profile* initial_profile) { |
| 466 Get()->Init(initial_profile); | 440 Get()->Init(initial_profile); |
| 467 } | 441 } |
| OLD | NEW |