| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ | |
| 6 #define CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 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" | |
| 17 | |
| 18 class ExtensionEnableFlow; | |
| 19 class NativeWindowTracker; | |
| 20 class Profile; | |
| 21 | |
| 22 namespace content { | |
| 23 class WebContents; | |
| 24 } | |
| 25 | |
| 26 namespace extensions { | |
| 27 class Extension; | |
| 28 class ExtensionInstallChecker; | |
| 29 class ExtensionRegistry; | |
| 30 } | |
| 31 | |
| 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; | |
| 41 | |
| 42 // Returns true if launching ephemeral apps from the webstore is enabled. | |
| 43 static bool IsFeatureEnabled(); | |
| 44 | |
| 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); | |
| 51 | |
| 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); | |
| 57 | |
| 58 // Initiate app launch. | |
| 59 void Start(); | |
| 60 | |
| 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); | |
| 69 | |
| 70 ~EphemeralAppLauncher() override; | |
| 71 | |
| 72 // Creates an install checker. Allows tests to mock the install checker. | |
| 73 virtual scoped_ptr<extensions::ExtensionInstallChecker> | |
| 74 CreateInstallChecker(); | |
| 75 | |
| 76 // WebstoreStandaloneInstaller implementation overridden in tests. | |
| 77 scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override; | |
| 78 scoped_ptr<extensions::WebstoreInstaller::Approval> CreateApproval() | |
| 79 const override; | |
| 80 | |
| 81 private: | |
| 82 friend class base::RefCountedThreadSafe<EphemeralAppLauncher>; | |
| 83 friend class EphemeralAppLauncherTest; | |
| 84 | |
| 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); | |
| 90 | |
| 91 // Initiates the enable flow for an app before it can be launched. | |
| 92 void EnableInstalledApp(const extensions::Extension* extension); | |
| 93 | |
| 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(); | |
| 97 | |
| 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; | |
| 101 | |
| 102 // Navigates to the launch URL of a hosted app in a new browser tab. | |
| 103 bool LaunchHostedApp(const extensions::Extension* extension) const; | |
| 104 | |
| 105 // Notifies the client of the launch outcome. | |
| 106 void InvokeCallback(extensions::webstore_install::Result result, | |
| 107 const std::string& error); | |
| 108 | |
| 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); | |
| 112 | |
| 113 // Determines whether the app can be installed ephemerally. | |
| 114 void CheckEphemeralInstallPermitted(); | |
| 115 | |
| 116 // Install checker callback. | |
| 117 void OnInstallChecked(int check_failures); | |
| 118 | |
| 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; | |
| 136 | |
| 137 // content::WebContentsObserver implementation. | |
| 138 void WebContentsDestroyed() override; | |
| 139 | |
| 140 // ExtensionEnableFlowDelegate implementation. | |
| 141 void ExtensionEnableFlowFinished() override; | |
| 142 void ExtensionEnableFlowAborted(bool user_initiated) override; | |
| 143 | |
| 144 LaunchCallback launch_callback_; | |
| 145 | |
| 146 gfx::NativeWindow parent_window_; | |
| 147 scoped_ptr<NativeWindowTracker> parent_window_tracker_; | |
| 148 scoped_ptr<content::WebContents> dummy_web_contents_; | |
| 149 | |
| 150 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; | |
| 151 | |
| 152 scoped_ptr<extensions::ExtensionInstallChecker> install_checker_; | |
| 153 | |
| 154 DISALLOW_COPY_AND_ASSIGN(EphemeralAppLauncher); | |
| 155 }; | |
| 156 | |
| 157 #endif // CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ | |
| OLD | NEW |