 Chromium Code Reviews
 Chromium Code Reviews Issue 777543002:
  Create hosted app shims on Mac.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 777543002:
  Create hosted app shims on Mac.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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/apps/app_shim/extension_app_shim_handler_mac.h" | 5 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" | 
| 6 | 6 | 
| 7 #include "apps/app_lifetime_monitor_factory.h" | 7 #include "apps/app_lifetime_monitor_factory.h" | 
| 8 #include "apps/launcher.h" | 8 #include "apps/launcher.h" | 
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" | 
| 10 #include "base/logging.h" | 10 #include "base/logging.h" | 
| 11 #include "chrome/browser/apps/app_shim/app_shim_host_manager_mac.h" | 11 #include "chrome/browser/apps/app_shim/app_shim_host_manager_mac.h" | 
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" | 
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" | 
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" | 
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" | 
| 16 #include "chrome/browser/ui/extensions/application_launch.h" | |
| 16 #include "chrome/browser/ui/extensions/extension_enable_flow.h" | 17 #include "chrome/browser/ui/extensions/extension_enable_flow.h" | 
| 17 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" | 18 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" | 
| 18 #include "chrome/browser/web_applications/web_app_mac.h" | 19 #include "chrome/browser/web_applications/web_app_mac.h" | 
| 19 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" | 
| 20 #include "chrome/common/extensions/extension_metrics.h" | 21 #include "chrome/common/extensions/extension_metrics.h" | 
| 22 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | |
| 21 #include "chrome/common/mac/app_shim_messages.h" | 23 #include "chrome/common/mac/app_shim_messages.h" | 
| 22 #include "components/crx_file/id_util.h" | 24 #include "components/crx_file/id_util.h" | 
| 23 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" | 
| 24 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" | 
| 25 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" | 
| 26 #include "extensions/browser/app_window/app_window.h" | 28 #include "extensions/browser/app_window/app_window.h" | 
| 27 #include "extensions/browser/app_window/app_window_registry.h" | 29 #include "extensions/browser/app_window/app_window_registry.h" | 
| 28 #include "extensions/browser/app_window/native_app_window.h" | 30 #include "extensions/browser/app_window/native_app_window.h" | 
| 29 #include "extensions/browser/extension_host.h" | 31 #include "extensions/browser/extension_host.h" | 
| 30 #include "extensions/browser/extension_registry.h" | 32 #include "extensions/browser/extension_registry.h" | 
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 return AppWindowRegistry::Get(profile)->GetAppWindowsForApp(extension_id); | 164 return AppWindowRegistry::Get(profile)->GetAppWindowsForApp(extension_id); | 
| 163 } | 165 } | 
| 164 | 166 | 
| 165 const extensions::Extension* | 167 const extensions::Extension* | 
| 166 ExtensionAppShimHandler::Delegate::GetAppExtension( | 168 ExtensionAppShimHandler::Delegate::GetAppExtension( | 
| 167 Profile* profile, | 169 Profile* profile, | 
| 168 const std::string& extension_id) { | 170 const std::string& extension_id) { | 
| 169 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); | 171 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); | 
| 170 const extensions::Extension* extension = | 172 const extensions::Extension* extension = | 
| 171 registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); | 173 registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); | 
| 172 return extension && extension->is_platform_app() ? extension : NULL; | 174 return extension && | 
| 175 (extension->is_platform_app() || extension->is_hosted_app()) | |
| 
jackhou1
2014/12/03 05:12:05
The indentation here looks a bit awkward. Run "git
 
mitchellj
2014/12/04 04:53:52
Acknowledged.
 | |
| 176 ? extension : NULL; | |
| 173 } | 177 } | 
| 174 | 178 | 
| 175 void ExtensionAppShimHandler::Delegate::EnableExtension( | 179 void ExtensionAppShimHandler::Delegate::EnableExtension( | 
| 176 Profile* profile, | 180 Profile* profile, | 
| 177 const std::string& extension_id, | 181 const std::string& extension_id, | 
| 178 const base::Callback<void()>& callback) { | 182 const base::Callback<void()>& callback) { | 
| 179 (new EnableViaPrompt(profile, extension_id, callback))->Run(); | 183 (new EnableViaPrompt(profile, extension_id, callback))->Run(); | 
| 180 } | 184 } | 
| 181 | 185 | 
| 182 void ExtensionAppShimHandler::Delegate::LaunchApp( | 186 void ExtensionAppShimHandler::Delegate::LaunchApp( | 
| 183 Profile* profile, | 187 Profile* profile, | 
| 184 const extensions::Extension* extension, | 188 const extensions::Extension* extension, | 
| 185 const std::vector<base::FilePath>& files) { | 189 const std::vector<base::FilePath>& files) { | 
| 186 extensions::RecordAppLaunchType( | 190 extensions::RecordAppLaunchType( | 
| 187 extension_misc::APP_LAUNCH_CMD_LINE_APP, extension->GetType()); | 191 extension_misc::APP_LAUNCH_CMD_LINE_APP, extension->GetType()); | 
| 192 if (extension->is_hosted_app()) { | |
| 193 AppLaunchParams launch_params( | |
| 194 profile, | |
| 195 extension, | |
| 196 NEW_FOREGROUND_TAB, | |
| 197 extensions::SOURCE_COMMAND_LINE); | |
| 198 OpenApplication(launch_params); | |
| 
jackhou1
2014/12/03 05:12:05
Return here since the rest of this function is spe
 
mitchellj
2014/12/04 04:53:52
Done.
 | |
| 199 } | |
| 188 if (files.empty()) { | 200 if (files.empty()) { | 
| 189 apps::LaunchPlatformApp( | 201 apps::LaunchPlatformApp( | 
| 190 profile, extension, extensions::SOURCE_COMMAND_LINE); | 202 profile, extension, extensions::SOURCE_COMMAND_LINE); | 
| 191 } else { | 203 } else { | 
| 192 for (std::vector<base::FilePath>::const_iterator it = files.begin(); | 204 for (std::vector<base::FilePath>::const_iterator it = files.begin(); | 
| 193 it != files.end(); ++it) { | 205 it != files.end(); ++it) { | 
| 194 apps::LaunchPlatformAppWithPath(profile, extension, *it); | 206 apps::LaunchPlatformAppWithPath(profile, extension, *it); | 
| 195 } | 207 } | 
| 196 } | 208 } | 
| 197 } | 209 } | 
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 } | 393 } | 
| 382 | 394 | 
| 383 // TODO(jeremya): Handle the case that launching the app fails. Probably we | 395 // TODO(jeremya): Handle the case that launching the app fails. Probably we | 
| 384 // need to watch for 'app successfully launched' or at least 'background page | 396 // need to watch for 'app successfully launched' or at least 'background page | 
| 385 // exists/was created' and time out with failure if we don't see that sign of | 397 // exists/was created' and time out with failure if we don't see that sign of | 
| 386 // life within a certain window. | 398 // life within a certain window. | 
| 387 const extensions::Extension* extension = | 399 const extensions::Extension* extension = | 
| 388 delegate_->GetAppExtension(profile, app_id); | 400 delegate_->GetAppExtension(profile, app_id); | 
| 389 if (extension) { | 401 if (extension) { | 
| 390 delegate_->LaunchApp(profile, extension, files); | 402 delegate_->LaunchApp(profile, extension, files); | 
| 403 // If it's a hosted app, just kill it immediately after opening for now. | |
| 404 if (extension->is_hosted_app()) { | |
| 
jackhou1
2014/12/03 05:12:05
No braces on single line if block.
 
mitchellj
2014/12/04 04:53:52
Done.
 | |
| 405 host->OnAppLaunchComplete(APP_SHIM_LAUNCH_DUPLICATE_HOST); | |
| 406 } | |
| 391 return; | 407 return; | 
| 392 } | 408 } | 
| 393 | 409 | 
| 394 delegate_->EnableExtension( | 410 delegate_->EnableExtension( | 
| 395 profile, app_id, | 411 profile, app_id, | 
| 396 base::Bind(&ExtensionAppShimHandler::OnExtensionEnabled, | 412 base::Bind(&ExtensionAppShimHandler::OnExtensionEnabled, | 
| 397 weak_factory_.GetWeakPtr(), | 413 weak_factory_.GetWeakPtr(), | 
| 398 host->GetProfilePath(), app_id, files)); | 414 host->GetProfilePath(), app_id, files)); | 
| 399 } | 415 } | 
| 400 | 416 | 
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 if (hosts_.empty()) | 565 if (hosts_.empty()) | 
| 550 delegate_->MaybeTerminate(); | 566 delegate_->MaybeTerminate(); | 
| 551 } | 567 } | 
| 552 | 568 | 
| 553 void ExtensionAppShimHandler::OnAppStop(Profile* profile, | 569 void ExtensionAppShimHandler::OnAppStop(Profile* profile, | 
| 554 const std::string& app_id) {} | 570 const std::string& app_id) {} | 
| 555 | 571 | 
| 556 void ExtensionAppShimHandler::OnChromeTerminating() {} | 572 void ExtensionAppShimHandler::OnChromeTerminating() {} | 
| 557 | 573 | 
| 558 } // namespace apps | 574 } // namespace apps | 
| OLD | NEW |