Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ | 5 #ifndef CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ |
| 6 #define CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ | 6 #define CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | |
| 11 #include "base/scoped_observer.h" | 13 #include "base/scoped_observer.h" |
| 12 #include "chrome/browser/extensions/webstore_standalone_installer.h" | 14 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
| 13 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" | 15 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 15 | 17 |
| 16 class ExtensionEnableFlow; | 18 class ExtensionEnableFlow; |
| 17 class Profile; | 19 class Profile; |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| 20 class WebContents; | 22 class WebContents; |
| 21 } | 23 } |
| 22 | 24 |
| 23 namespace extensions { | 25 namespace extensions { |
| 24 class Extension; | 26 class Extension; |
| 27 class ExtensionInstallChecker; | |
| 25 class ExtensionRegistry; | 28 class ExtensionRegistry; |
| 26 } | 29 } |
| 27 | 30 |
| 28 // EphemeralAppLauncher manages the launching of ephemeral apps. It handles | 31 // EphemeralAppLauncher manages the launching of ephemeral apps. It handles |
| 29 // display of a prompt, initiates install of the app (if necessary) and finally | 32 // display of a prompt, initiates install of the app (if necessary) and finally |
| 30 // launches the app. | 33 // launches the app. |
| 31 class EphemeralAppLauncher : public extensions::WebstoreStandaloneInstaller, | 34 class EphemeralAppLauncher : public extensions::WebstoreStandaloneInstaller, |
| 32 public content::WebContentsObserver, | 35 public content::WebContentsObserver, |
| 33 public ExtensionEnableFlowDelegate { | 36 public ExtensionEnableFlowDelegate { |
| 34 public: | 37 public: |
| 35 typedef WebstoreStandaloneInstaller::Callback Callback; | 38 // All possible result codes returned in the LaunchCallback. |
| 39 enum LaunchResult { | |
| 40 // Successful launch. | |
| 41 LAUNCH_SUCCESS, | |
| 42 // Unknown or unspecified error. | |
| 43 LAUNCH_UNKNOWN_ERROR, | |
| 44 // Invalid extension ID for the app. | |
| 45 LAUNCH_INVALID_ID, | |
| 46 // An error occurred while parsing the app manifest. | |
| 47 LAUNCH_INVALID_MANIFEST, | |
| 48 // An error occurred while attempting to install the app ephemerally. | |
| 49 LAUNCH_INSTALL_ERROR, | |
| 50 // The user cancelled the launch. | |
| 51 LAUNCH_USER_CANCELLED, | |
| 52 // The feature is not available. | |
| 53 LAUNCH_FEATURE_DISABLED, | |
| 54 // The feature is not supported for the extension type. | |
| 55 LAUNCH_UNSUPPORTED_EXTENSION_TYPE, | |
| 56 // The app is blacklisted. | |
| 57 LAUNCH_BLACKLISTED, | |
| 58 // Unsatisfied dependencies (such as shared modules) or requirements. | |
| 59 LAUNCH_MISSING_DEPENDENCIES, | |
| 60 // The app is blocked by management policies. | |
| 61 LAUNCH_BLOCKED_BY_POLICY | |
|
asargent_no_longer_on_chrome
2014/06/18 20:25:10
Hmm, this enum seems to have a lot of overlap with
tmdiep
2014/06/18 22:28:34
I went back and forth with this issue a fair bit.
asargent_no_longer_on_chrome
2014/06/19 00:16:43
I think it might be ok to have a single enum somew
| |
| 62 }; | |
| 63 | |
| 64 typedef base::Callback<void(LaunchResult result, const std::string& error)> | |
| 65 LaunchCallback; | |
| 66 | |
| 67 // Returns true if launching ephemeral apps is enabled. | |
| 68 static bool IsFeatureEnabled(); | |
| 36 | 69 |
| 37 // Create for the app launcher. | 70 // Create for the app launcher. |
| 38 static scoped_refptr<EphemeralAppLauncher> CreateForLauncher( | 71 static scoped_refptr<EphemeralAppLauncher> CreateForLauncher( |
| 39 const std::string& webstore_item_id, | 72 const std::string& webstore_item_id, |
| 40 Profile* profile, | 73 Profile* profile, |
| 41 gfx::NativeWindow parent_window, | 74 gfx::NativeWindow parent_window, |
| 42 const Callback& callback); | 75 const LaunchCallback& callback); |
| 43 | 76 |
| 44 // Create for a link within a browser tab. | 77 // Create for a web contents. |
| 45 static scoped_refptr<EphemeralAppLauncher> CreateForLink( | 78 static scoped_refptr<EphemeralAppLauncher> CreateForWebContents( |
| 46 const std::string& webstore_item_id, | 79 const std::string& webstore_item_id, |
| 47 content::WebContents* web_contents); | 80 content::WebContents* web_contents, |
| 81 const LaunchCallback& callback); | |
| 48 | 82 |
| 49 // Initiate app launch. | 83 // Initiate app launch. |
| 50 void Start(); | 84 void Start(); |
| 51 | 85 |
| 52 private: | 86 protected: |
| 53 friend class base::RefCountedThreadSafe<EphemeralAppLauncher>; | |
| 54 | |
| 55 EphemeralAppLauncher(const std::string& webstore_item_id, | 87 EphemeralAppLauncher(const std::string& webstore_item_id, |
| 56 Profile* profile, | 88 Profile* profile, |
| 57 gfx::NativeWindow parent_window, | 89 gfx::NativeWindow parent_window, |
| 58 const Callback& callback); | 90 const LaunchCallback& callback); |
| 59 EphemeralAppLauncher(const std::string& webstore_item_id, | 91 EphemeralAppLauncher(const std::string& webstore_item_id, |
| 60 content::WebContents* web_contents, | 92 content::WebContents* web_contents, |
| 61 const Callback& callback); | 93 const LaunchCallback& callback); |
| 62 | 94 |
| 63 virtual ~EphemeralAppLauncher(); | 95 virtual ~EphemeralAppLauncher(); |
| 64 | 96 |
| 97 // Returns true if an app that is already installed in extension system can | |
| 98 // be launched. | |
| 99 bool CanLaunchInstalledApp(const extensions::Extension* extension, | |
| 100 LaunchResult* reason, | |
| 101 std::string* error); | |
| 102 | |
| 103 // Initiates the enable flow for an app before it can be launched. | |
| 104 void EnableInstalledApp(const extensions::Extension* extension); | |
| 105 | |
| 106 // After the ephemeral installation or enable flow are complete, attempts to | |
| 107 // launch the app and notify the client of the outcome. | |
| 108 void MaybeLaunchApp(); | |
| 109 | |
| 110 // Launches an app. At this point, it is assumed that the app is enabled and | |
| 111 // can be launched. | |
| 65 void LaunchApp(const extensions::Extension* extension) const; | 112 void LaunchApp(const extensions::Extension* extension) const; |
| 66 | 113 |
| 114 // Notifies the client of the launch outcome. | |
| 115 void InvokeCallback(LaunchResult result, const std::string& error); | |
| 116 | |
| 117 // Aborts the ephemeral install and notifies the client of the outcome. | |
| 118 void AbortLaunch(LaunchResult result, const std::string& error); | |
| 119 | |
| 120 // Creates an install checker. Allows tests to mock the install checker. | |
| 121 virtual scoped_ptr<extensions::ExtensionInstallChecker> | |
| 122 CreateInstallChecker(); | |
| 123 | |
| 124 // Determines whether the app can be installed ephemerally. | |
| 125 void CheckEphemeralInstallPermitted(); | |
| 126 | |
| 127 // Install checker callback. | |
| 128 void OnInstallChecked(int check_failures); | |
| 129 | |
| 67 // WebstoreStandaloneInstaller implementation. | 130 // WebstoreStandaloneInstaller implementation. |
| 68 virtual bool CheckRequestorAlive() const OVERRIDE; | 131 virtual bool CheckRequestorAlive() const OVERRIDE; |
| 69 virtual const GURL& GetRequestorURL() const OVERRIDE; | 132 virtual const GURL& GetRequestorURL() const OVERRIDE; |
| 70 virtual bool ShouldShowPostInstallUI() const OVERRIDE; | 133 virtual bool ShouldShowPostInstallUI() const OVERRIDE; |
| 71 virtual bool ShouldShowAppInstalledBubble() const OVERRIDE; | 134 virtual bool ShouldShowAppInstalledBubble() const OVERRIDE; |
| 72 virtual content::WebContents* GetWebContents() const OVERRIDE; | 135 virtual content::WebContents* GetWebContents() const OVERRIDE; |
| 73 virtual scoped_ptr<ExtensionInstallPrompt::Prompt> | 136 virtual scoped_ptr<ExtensionInstallPrompt::Prompt> |
| 74 CreateInstallPrompt() const OVERRIDE; | 137 CreateInstallPrompt() const OVERRIDE; |
| 75 virtual bool CheckInlineInstallPermitted( | 138 virtual bool CheckInlineInstallPermitted( |
| 76 const base::DictionaryValue& webstore_data, | 139 const base::DictionaryValue& webstore_data, |
| 77 std::string* error) const OVERRIDE; | 140 std::string* error) const OVERRIDE; |
| 78 virtual bool CheckRequestorPermitted( | 141 virtual bool CheckRequestorPermitted( |
| 79 const base::DictionaryValue& webstore_data, | 142 const base::DictionaryValue& webstore_data, |
| 80 std::string* error) const OVERRIDE; | 143 std::string* error) const OVERRIDE; |
| 81 virtual bool CheckInstallValid( | 144 virtual void OnManifestParsed() OVERRIDE; |
| 82 const base::DictionaryValue& manifest, | |
| 83 std::string* error) OVERRIDE; | |
| 84 virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() OVERRIDE; | 145 virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() OVERRIDE; |
| 85 virtual scoped_ptr<extensions::WebstoreInstaller::Approval> | 146 virtual scoped_ptr<extensions::WebstoreInstaller::Approval> |
| 86 CreateApproval() const OVERRIDE; | 147 CreateApproval() const OVERRIDE; |
| 87 virtual void CompleteInstall(const std::string& error) OVERRIDE; | 148 virtual void CompleteInstall(InstallResult result, |
| 149 const std::string& error) OVERRIDE; | |
| 88 | 150 |
| 89 // content::WebContentsObserver implementation. | 151 // content::WebContentsObserver implementation. |
| 90 virtual void WebContentsDestroyed() OVERRIDE; | 152 virtual void WebContentsDestroyed() OVERRIDE; |
| 91 | 153 |
| 92 // ExtensionEnableFlowDelegate implementation. | 154 // ExtensionEnableFlowDelegate implementation. |
| 93 virtual void ExtensionEnableFlowFinished() OVERRIDE; | 155 virtual void ExtensionEnableFlowFinished() OVERRIDE; |
| 94 virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; | 156 virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; |
| 95 | 157 |
| 158 private: | |
| 159 friend class base::RefCountedThreadSafe<EphemeralAppLauncher>; | |
| 160 friend class EphemeralAppLauncherTest; | |
| 161 | |
| 162 LaunchCallback launch_callback_; | |
| 163 | |
| 96 gfx::NativeWindow parent_window_; | 164 gfx::NativeWindow parent_window_; |
| 97 scoped_ptr<content::WebContents> dummy_web_contents_; | 165 scoped_ptr<content::WebContents> dummy_web_contents_; |
| 98 | 166 |
| 99 // Created in CheckInstallValid(). | 167 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; |
| 100 scoped_refptr<extensions::Extension> extension_; | |
| 101 | 168 |
| 102 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; | 169 scoped_ptr<extensions::ExtensionInstallChecker> install_checker_; |
| 103 | 170 |
| 104 DISALLOW_COPY_AND_ASSIGN(EphemeralAppLauncher); | 171 DISALLOW_COPY_AND_ASSIGN(EphemeralAppLauncher); |
| 105 }; | 172 }; |
| 106 | 173 |
| 107 #endif // CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ | 174 #endif // CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ |
| OLD | NEW |