Roll src/third_party/WebKit bf18a82:a9cee16 (svn 185297:185304)
[chromium-blink-merge.git] / athena / extensions / chrome / extensions_delegate_impl.cc
blobfeedc8e7375fb4b924ef9f621efc8ef89c60c997
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.
5 #include "athena/extensions/public/extensions_delegate.h"
7 #include "athena/extensions/chrome/athena_chrome_app_window_client.h"
8 #include "athena/extensions/chrome/athena_extension_install_ui.h"
9 #include "base/macros.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_util.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/extensions/application_launch.h"
15 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
16 #include "extensions/browser/extension_registry.h"
17 #include "extensions/browser/extension_system.h"
18 #include "extensions/common/constants.h"
19 #include "extensions/common/extension_set.h"
20 #include "extensions/common/extension_urls.h"
21 #include "net/base/url_util.h"
23 namespace athena {
24 namespace {
26 class ChromeExtensionsDelegate : public ExtensionsDelegate {
27 public:
28 explicit ChromeExtensionsDelegate(content::BrowserContext* context)
29 : extension_service_(
30 extensions::ExtensionSystem::Get(context)->extension_service()) {
31 extensions::AppWindowClient::Set(&app_window_client_);
34 ~ChromeExtensionsDelegate() override {
35 extensions::AppWindowClient::Set(nullptr);
38 private:
39 // ExtensionsDelegate:
40 content::BrowserContext* GetBrowserContext() const override {
41 return extension_service_->GetBrowserContext();
43 const extensions::ExtensionSet& GetInstalledExtensions() override {
44 return extensions::ExtensionRegistry::Get(GetBrowserContext())
45 ->enabled_extensions();
47 bool LaunchApp(const std::string& app_id) override {
48 // Check Running apps
49 content::BrowserContext* context = GetBrowserContext();
50 const extensions::Extension* extension =
51 extensions::ExtensionRegistry::Get(context)->GetExtensionById(
52 app_id, extensions::ExtensionRegistry::EVERYTHING);
53 DCHECK(extension);
54 if (!extension)
55 return false;
57 // TODO(oshima): Support installation/enabling process.
58 if (!extensions::util::IsAppLaunchableWithoutEnabling(app_id, context))
59 return false;
61 int event_flags = 0;
62 AppLaunchParams params(Profile::FromBrowserContext(context),
63 extension,
64 event_flags,
65 chrome::HOST_DESKTOP_TYPE_ASH);
66 // TODO(oshima): rename HOST_DESTOP_TYPE_ASH to non native desktop.
68 if (app_id == extensions::kWebStoreAppId) {
69 std::string source_value =
70 std::string(extension_urls::kLaunchSourceAppList);
71 // Set an override URL to include the source.
72 GURL extension_url =
73 extensions::AppLaunchInfo::GetFullLaunchURL(extension);
74 params.override_url = net::AppendQueryParameter(
75 extension_url, extension_urls::kWebstoreSourceField, source_value);
77 params.container = extensions::LAUNCH_CONTAINER_WINDOW;
79 OpenApplication(params);
80 return true;
83 bool UnloadApp(const std::string& app_id) override {
84 // TODO(skuhne): Implement using extension service.
85 return false;
88 scoped_ptr<extensions::ExtensionInstallUI> CreateExtensionInstallUI()
89 override {
90 return scoped_ptr<extensions::ExtensionInstallUI>(
91 new AthenaExtensionInstallUI());
94 // ExtensionService for the browser context this is created for.
95 ExtensionService* extension_service_;
97 // Installed extensions.
98 extensions::ExtensionSet extensions_;
100 AthenaChromeAppWindowClient app_window_client_;
102 DISALLOW_COPY_AND_ASSIGN(ChromeExtensionsDelegate);
105 } // namespace
107 // static
108 void ExtensionsDelegate::CreateExtensionsDelegate(
109 content::BrowserContext* context) {
110 new ChromeExtensionsDelegate(context);
113 } // namespace athena