Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "athena/extensions/public/extensions_delegate.h" | |
| 6 | |
| 7 #include "athena/extensions/chrome/athena_apps_client.h" | |
| 8 #include "base/macros.h" | |
| 9 #include "chrome/browser/extensions/extension_service.h" | |
| 10 #include "chrome/browser/extensions/extension_util.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/browser/ui/extensions/application_launch.h" | |
| 13 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | |
| 14 #include "extensions/browser/extension_registry.h" | |
| 15 #include "extensions/browser/extension_system.h" | |
| 16 #include "extensions/common/extension_set.h" | |
| 17 #include "extensions/common/extension_urls.h" | |
| 18 #include "net/base/url_util.h" | |
| 19 | |
| 20 namespace athena { | |
| 21 namespace { | |
| 22 | |
| 23 class ChromeExtensionsDelegate : public ExtensionsDelegate { | |
| 24 public: | |
| 25 explicit ChromeExtensionsDelegate(content::BrowserContext* context) | |
| 26 : extension_service_( | |
| 27 extensions::ExtensionSystem::Get(context)->extension_service()) { | |
| 28 apps::AppsClient::Set(&apps_client_); | |
| 29 } | |
| 30 | |
| 31 virtual ~ChromeExtensionsDelegate() {} | |
| 32 | |
| 33 private: | |
| 34 // ExtensionsDelegate: | |
| 35 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE { | |
| 36 return extension_service_->GetBrowserContext(); | |
| 37 } | |
| 38 virtual const extensions::ExtensionSet& GetInstalledExtensions() OVERRIDE { | |
| 39 return *extension_service_->extensions(); | |
| 40 } | |
| 41 virtual bool LaunchApp(const std::string& app_id) OVERRIDE { | |
| 42 // Check Running apps | |
| 43 content::BrowserContext* context = GetBrowserContext(); | |
| 44 const extensions::Extension* extension = | |
| 45 extensions::ExtensionRegistry::Get(context)->GetExtensionById( | |
| 46 app_id, extensions::ExtensionRegistry::EVERYTHING); | |
|
Jun Mukai
2014/08/28 22:50:45
DCHECK(extension)? The code below simply assumes
oshima
2014/08/28 23:59:04
Done.
| |
| 47 | |
| 48 if (!extensions::util::IsAppLaunchableWithoutEnabling(app_id, context)) { | |
| 49 // TODO(oshima): Support installation/enabling process. | |
| 50 return false; | |
| 51 } | |
| 52 int event_flags = 0; | |
| 53 AppLaunchParams params(Profile::FromBrowserContext(context), | |
| 54 extension, | |
| 55 event_flags, | |
| 56 chrome::HOST_DESKTOP_TYPE_ASH); | |
| 57 // TODO(oshima): rename HOST_DESTOP_TYPE_ASH to non native desktop. | |
| 58 | |
| 59 if (app_id == extension_misc::kWebStoreAppId) { | |
| 60 std::string source_value = | |
| 61 std::string(extension_urls::kLaunchSourceAppList); | |
| 62 // Set an override URL to include the source. | |
| 63 GURL extension_url = | |
| 64 extensions::AppLaunchInfo::GetFullLaunchURL(extension); | |
| 65 params.override_url = net::AppendQueryParameter( | |
| 66 extension_url, extension_urls::kWebstoreSourceField, source_value); | |
| 67 } | |
| 68 params.container = extensions::LAUNCH_CONTAINER_WINDOW; | |
| 69 | |
| 70 OpenApplication(params); | |
| 71 return true; | |
| 72 } | |
| 73 virtual bool UnloadApp(const std::string& app_id) OVERRIDE { | |
| 74 // TODO(skuhne): Implement using extension service. | |
| 75 return false; | |
| 76 } | |
| 77 | |
| 78 // ExtensionService for the browser context this is created for. | |
| 79 ExtensionService* extension_service_; | |
| 80 | |
| 81 // Installed extensions. | |
| 82 extensions::ExtensionSet extensions_; | |
| 83 | |
| 84 AthenaAppsClient apps_client_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(ChromeExtensionsDelegate); | |
| 87 }; | |
| 88 | |
| 89 } // namespace | |
| 90 | |
| 91 // static | |
| 92 void ExtensionsDelegate::CreateExtensionsDelegateForChrome( | |
| 93 content::BrowserContext* context) { | |
| 94 new ChromeExtensionsDelegate(context); | |
| 95 } | |
| 96 | |
| 97 } // namespace athena | |
| OLD | NEW |