Use app list item shadow for app list folders.
[chromium-blink-merge.git] / chrome / browser / apps / ephemeral_app_launcher.h
blob1ffab6584c20ac7e0626172d95d1c5a36b38c840
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_
6 #define CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/scoped_observer.h"
14 #include "chrome/browser/extensions/webstore_standalone_installer.h"
15 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
16 #include "content/public/browser/web_contents_observer.h"
18 class ExtensionEnableFlow;
19 class NativeWindowTracker;
20 class Profile;
22 namespace content {
23 class WebContents;
26 namespace extensions {
27 class Extension;
28 class ExtensionInstallChecker;
29 class ExtensionRegistry;
32 // EphemeralAppLauncher manages the launching of ephemeral apps. It handles
33 // display of a prompt, initiates install of the app (if necessary) and finally
34 // launches the app.
35 class EphemeralAppLauncher : public extensions::WebstoreStandaloneInstaller,
36 public content::WebContentsObserver,
37 public ExtensionEnableFlowDelegate {
38 public:
39 typedef base::Callback<void(extensions::webstore_install::Result result,
40 const std::string& error)> LaunchCallback;
42 // Returns true if launching ephemeral apps from the webstore is enabled.
43 static bool IsFeatureEnabled();
45 // Create for the app launcher.
46 static scoped_refptr<EphemeralAppLauncher> CreateForLauncher(
47 const std::string& webstore_item_id,
48 Profile* profile,
49 gfx::NativeWindow parent_window,
50 const LaunchCallback& callback);
52 // Create for a web contents.
53 static scoped_refptr<EphemeralAppLauncher> CreateForWebContents(
54 const std::string& webstore_item_id,
55 content::WebContents* web_contents,
56 const LaunchCallback& callback);
58 // Initiate app launch.
59 void Start();
61 protected:
62 EphemeralAppLauncher(const std::string& webstore_item_id,
63 Profile* profile,
64 gfx::NativeWindow parent_window,
65 const LaunchCallback& callback);
66 EphemeralAppLauncher(const std::string& webstore_item_id,
67 content::WebContents* web_contents,
68 const LaunchCallback& callback);
70 ~EphemeralAppLauncher() override;
72 // Creates an install checker. Allows tests to mock the install checker.
73 virtual scoped_ptr<extensions::ExtensionInstallChecker>
74 CreateInstallChecker();
76 // WebstoreStandaloneInstaller implementation overridden in tests.
77 scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override;
78 scoped_ptr<extensions::WebstoreInstaller::Approval> CreateApproval()
79 const override;
81 private:
82 friend class base::RefCountedThreadSafe<EphemeralAppLauncher>;
83 friend class EphemeralAppLauncherTest;
85 // Returns true if an app that is already installed in extension system can
86 // be launched.
87 bool CanLaunchInstalledApp(const extensions::Extension* extension,
88 extensions::webstore_install::Result* reason,
89 std::string* error);
91 // Initiates the enable flow for an app before it can be launched.
92 void EnableInstalledApp(const extensions::Extension* extension);
94 // After the ephemeral installation or enable flow are complete, attempts to
95 // launch the app and notify the client of the outcome.
96 void MaybeLaunchApp();
98 // Launches an app. At this point, it is assumed that the app is enabled and
99 // can be launched.
100 void LaunchApp(const extensions::Extension* extension) const;
102 // Navigates to the launch URL of a hosted app in a new browser tab.
103 bool LaunchHostedApp(const extensions::Extension* extension) const;
105 // Notifies the client of the launch outcome.
106 void InvokeCallback(extensions::webstore_install::Result result,
107 const std::string& error);
109 // Aborts the ephemeral install and notifies the client of the outcome.
110 void AbortLaunch(extensions::webstore_install::Result result,
111 const std::string& error);
113 // Determines whether the app can be installed ephemerally.
114 void CheckEphemeralInstallPermitted();
116 // Install checker callback.
117 void OnInstallChecked(int check_failures);
119 // WebstoreStandaloneInstaller implementation.
120 void InitInstallData(
121 extensions::ActiveInstallData* install_data) const override;
122 bool CheckRequestorAlive() const override;
123 const GURL& GetRequestorURL() const override;
124 bool ShouldShowPostInstallUI() const override;
125 bool ShouldShowAppInstalledBubble() const override;
126 content::WebContents* GetWebContents() const override;
127 scoped_refptr<ExtensionInstallPrompt::Prompt> CreateInstallPrompt()
128 const override;
129 bool CheckInlineInstallPermitted(const base::DictionaryValue& webstore_data,
130 std::string* error) const override;
131 bool CheckRequestorPermitted(const base::DictionaryValue& webstore_data,
132 std::string* error) const override;
133 void OnManifestParsed() override;
134 void CompleteInstall(extensions::webstore_install::Result result,
135 const std::string& error) override;
137 // content::WebContentsObserver implementation.
138 void WebContentsDestroyed() override;
140 // ExtensionEnableFlowDelegate implementation.
141 void ExtensionEnableFlowFinished() override;
142 void ExtensionEnableFlowAborted(bool user_initiated) override;
144 LaunchCallback launch_callback_;
146 gfx::NativeWindow parent_window_;
147 scoped_ptr<NativeWindowTracker> parent_window_tracker_;
148 scoped_ptr<content::WebContents> dummy_web_contents_;
150 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_;
152 scoped_ptr<extensions::ExtensionInstallChecker> install_checker_;
154 DISALLOW_COPY_AND_ASSIGN(EphemeralAppLauncher);
157 #endif // CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_