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); | |
Yoyo Zhou
2014/08/29 22:23:29
EVERYTHING is probably not what you want. ENABLED?
oshima
2014/08/29 23:25:26
This is what ash is using for launcher (ChromeLaun
| |
47 DCHECK(extension); | |
48 if (!extension) | |
49 return false; | |
50 | |
51 // TODO(oshima): Support installation/enabling process. | |
52 if (!extensions::util::IsAppLaunchableWithoutEnabling(app_id, context)) | |
53 return false; | |
54 | |
55 int event_flags = 0; | |
56 AppLaunchParams params(Profile::FromBrowserContext(context), | |
57 extension, | |
58 event_flags, | |
59 chrome::HOST_DESKTOP_TYPE_ASH); | |
60 // TODO(oshima): rename HOST_DESTOP_TYPE_ASH to non native desktop. | |
61 | |
62 if (app_id == extension_misc::kWebStoreAppId) { | |
63 std::string source_value = | |
64 std::string(extension_urls::kLaunchSourceAppList); | |
65 // Set an override URL to include the source. | |
66 GURL extension_url = | |
67 extensions::AppLaunchInfo::GetFullLaunchURL(extension); | |
68 params.override_url = net::AppendQueryParameter( | |
69 extension_url, extension_urls::kWebstoreSourceField, source_value); | |
70 } | |
71 params.container = extensions::LAUNCH_CONTAINER_WINDOW; | |
72 | |
73 OpenApplication(params); | |
74 return true; | |
75 } | |
76 virtual bool UnloadApp(const std::string& app_id) OVERRIDE { | |
77 // TODO(skuhne): Implement using extension service. | |
78 return false; | |
79 } | |
80 | |
81 // ExtensionService for the browser context this is created for. | |
82 ExtensionService* extension_service_; | |
83 | |
84 // Installed extensions. | |
85 extensions::ExtensionSet extensions_; | |
86 | |
87 AthenaAppsClient apps_client_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(ChromeExtensionsDelegate); | |
90 }; | |
91 | |
92 } // namespace | |
93 | |
94 // static | |
95 void ExtensionsDelegate::CreateExtensionsDelegateForChrome( | |
96 content::BrowserContext* context) { | |
97 new ChromeExtensionsDelegate(context); | |
98 } | |
99 | |
100 } // namespace athena | |
OLD | NEW |