Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_EXTENSIONS_WEBSTORE_STANDALONE_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_STANDALONE_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_STANDALONE_INSTALLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_STANDALONE_INSTALLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 // Follows the Template Method pattern. Implementing subclasses must override | 40 // Follows the Template Method pattern. Implementing subclasses must override |
| 41 // the primitive hooks in the corresponding section below. | 41 // the primitive hooks in the corresponding section below. |
| 42 | 42 |
| 43 class WebstoreStandaloneInstaller | 43 class WebstoreStandaloneInstaller |
| 44 : public base::RefCountedThreadSafe<WebstoreStandaloneInstaller>, | 44 : public base::RefCountedThreadSafe<WebstoreStandaloneInstaller>, |
| 45 public ExtensionInstallPrompt::Delegate, | 45 public ExtensionInstallPrompt::Delegate, |
| 46 public WebstoreDataFetcherDelegate, | 46 public WebstoreDataFetcherDelegate, |
| 47 public WebstoreInstaller::Delegate, | 47 public WebstoreInstaller::Delegate, |
| 48 public WebstoreInstallHelper::Delegate { | 48 public WebstoreInstallHelper::Delegate { |
| 49 public: | 49 public: |
| 50 enum InstallResult { | |
| 51 // Successful install. | |
| 52 INSTALL_SUCCESS, | |
| 53 // Unknown error. | |
| 54 INSTALL_UNKNOWN_ERROR, | |
| 55 // The install was aborted as the requestor is no longer alive. | |
| 56 INSTALL_ABORTED, | |
| 57 // The installation is not permitted. | |
| 58 INSTALL_NOT_PERMITTED, | |
| 59 // Invalid Chrome Web Store item ID. | |
| 60 INSTALL_INVALID_ID, | |
| 61 // Failed to retrieve extension metadata from the Web Store. | |
| 62 INSTALL_WEBSTORE_REQUEST_ERROR, | |
| 63 // The extension metadata retrieved from the Web Store was invalid. | |
| 64 INSTALL_INVALID_WEBSTORE_RESPONSE, | |
| 65 // An error occurred while parsing the extension manifest retrieved from the | |
| 66 // Web Store. | |
| 67 INSTALL_INVALID_MANIFEST, | |
| 68 // Failed to retrieve the extension's icon from the Web Store, or the icon | |
| 69 // was invalid. | |
| 70 INSTALL_ICON_ERROR, | |
| 71 // The user cancelled the installation. | |
| 72 INSTALL_USER_CANCELLED, | |
| 73 // The extension is blacklisted. | |
| 74 INSTALL_BLACKLISTED, | |
| 75 // Unsatisfied dependencies, such as shared modules. | |
| 76 INSTALL_MISSING_DEPENDENCIES | |
|
asargent_no_longer_on_chrome
2014/06/18 20:25:10
optional nit: I would personally find the comments
| |
| 77 }; | |
| 78 | |
| 50 // A callback for when the install process completes, successfully or not. If | 79 // A callback for when the install process completes, successfully or not. If |
| 51 // there was a failure, |success| will be false and |error| may contain a | 80 // there was a failure, |success| will be false and |error| may contain a |
| 52 // developer-readable error message about why it failed. | 81 // developer-readable error message about why it failed. |
| 53 typedef base::Callback<void(bool success, const std::string& error)> Callback; | 82 typedef base::Callback<void(bool success, const std::string& error)> Callback; |
| 54 | 83 |
| 55 WebstoreStandaloneInstaller(const std::string& webstore_item_id, | 84 WebstoreStandaloneInstaller(const std::string& webstore_item_id, |
| 56 Profile* profile, | 85 Profile* profile, |
| 57 const Callback& callback); | 86 const Callback& callback); |
| 58 void BeginInstall(); | 87 void BeginInstall(); |
| 59 | 88 |
| 60 protected: | 89 protected: |
| 61 virtual ~WebstoreStandaloneInstaller(); | 90 virtual ~WebstoreStandaloneInstaller(); |
| 62 | 91 |
| 92 // Called when the install should be aborted. The callback is cleared. | |
| 63 void AbortInstall(); | 93 void AbortInstall(); |
| 64 void InvokeCallback(const std::string& error); | 94 |
| 65 virtual void CompleteInstall(const std::string& error); | 95 // Called when the install is complete. |
| 96 virtual void CompleteInstall(InstallResult result, const std::string& error); | |
| 97 | |
| 98 // Called when the installer should proceed to prompt the user. | |
| 99 void ProceedWithInstallPrompt(); | |
| 100 | |
| 101 // Lazily creates a dummy extension for display from the parsed manifest. This | |
| 102 // is safe to call from OnManifestParsed() onwards. The manifest may be | |
| 103 // invalid, thus the caller must check that the return value is not NULL. | |
| 104 scoped_refptr<const Extension> GetLocalizedExtensionForDisplay(); | |
| 66 | 105 |
| 67 // Template Method's hooks to be implemented by subclasses. | 106 // Template Method's hooks to be implemented by subclasses. |
| 68 | 107 |
| 69 // Called at certain check points of the workflow to decide whether it makes | 108 // Called at certain check points of the workflow to decide whether it makes |
| 70 // sense to proceed with installation. A requestor can be a website that | 109 // sense to proceed with installation. A requestor can be a website that |
| 71 // initiated an inline installation, or a command line option. | 110 // initiated an inline installation, or a command line option. |
| 72 virtual bool CheckRequestorAlive() const = 0; | 111 virtual bool CheckRequestorAlive() const = 0; |
| 73 | 112 |
| 74 // Requestor's URL, if any. Should be an empty GURL if URL is meaningless | 113 // Requestor's URL, if any. Should be an empty GURL if URL is meaningless |
| 75 // (e.g. for a command line option). | 114 // (e.g. for a command line option). |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 101 const base::DictionaryValue& webstore_data, | 140 const base::DictionaryValue& webstore_data, |
| 102 std::string* error) const = 0; | 141 std::string* error) const = 0; |
| 103 | 142 |
| 104 // Perform all necessary checks to make sure that requestor is allowed to | 143 // Perform all necessary checks to make sure that requestor is allowed to |
| 105 // initiate this install (e.g. that the requestor's URL matches the verified | 144 // initiate this install (e.g. that the requestor's URL matches the verified |
| 106 // author's site specified in the extension's properties in the store). | 145 // author's site specified in the extension's properties in the store). |
| 107 virtual bool CheckRequestorPermitted( | 146 virtual bool CheckRequestorPermitted( |
| 108 const base::DictionaryValue& webstore_data, | 147 const base::DictionaryValue& webstore_data, |
| 109 std::string* error) const = 0; | 148 std::string* error) const = 0; |
| 110 | 149 |
| 111 // Perform all necessary checks after the manifest has been parsed to make | 150 // Will be called after the extension's manifest has been successfully parsed. |
| 112 // sure that the install should still proceed. | 151 // Subclasses can perform asynchronous checks at this point and call |
| 113 virtual bool CheckInstallValid( | 152 // ProceedWithInstallPrompt() to proceed with the install or otherwise call |
| 114 const base::DictionaryValue& manifest, | 153 // CompleteInstall() with an error code. The default implementation calls |
| 115 std::string* error); | 154 // ProceedWithInstallPrompt(). |
| 155 virtual void OnManifestParsed(); | |
| 116 | 156 |
| 117 // Returns an install UI to be shown. By default, this returns an install UI | 157 // Returns an install UI to be shown. By default, this returns an install UI |
| 118 // that is a transient child of the host window for GetWebContents(). | 158 // that is a transient child of the host window for GetWebContents(). |
| 119 virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI(); | 159 virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI(); |
| 120 | 160 |
| 121 // Create an approval to pass installation parameters to the CrxInstaller. | 161 // Create an approval to pass installation parameters to the CrxInstaller. |
| 122 virtual scoped_ptr<WebstoreInstaller::Approval> CreateApproval() const; | 162 virtual scoped_ptr<WebstoreInstaller::Approval> CreateApproval() const; |
| 123 | 163 |
| 124 // Accessors to be used by subclasses. | 164 // Accessors to be used by subclasses. |
| 125 bool show_user_count() const { return show_user_count_; } | 165 bool show_user_count() const { return show_user_count_; } |
| 126 const std::string& localized_user_count() const { | 166 const std::string& localized_user_count() const { |
| 127 return localized_user_count_; | 167 return localized_user_count_; |
| 128 } | 168 } |
| 129 double average_rating() const { return average_rating_; } | 169 double average_rating() const { return average_rating_; } |
| 130 int rating_count() const { return rating_count_; } | 170 int rating_count() const { return rating_count_; } |
| 131 void set_install_source(WebstoreInstaller::InstallSource source) { | 171 void set_install_source(WebstoreInstaller::InstallSource source) { |
| 132 install_source_ = source; | 172 install_source_ = source; |
| 133 } | 173 } |
| 134 WebstoreInstaller::InstallSource install_source() const { | 174 WebstoreInstaller::InstallSource install_source() const { |
| 135 return install_source_; | 175 return install_source_; |
| 136 } | 176 } |
| 137 Profile* profile() const { return profile_; } | 177 Profile* profile() const { return profile_; } |
| 138 const std::string& id() const { return id_; } | 178 const std::string& id() const { return id_; } |
| 139 const base::DictionaryValue* manifest() const { return manifest_.get(); } | 179 const base::DictionaryValue* manifest() const { return manifest_.get(); } |
| 180 const Extension* localized_extension_for_display() const { | |
| 181 return localized_extension_for_display_.get(); | |
| 182 } | |
| 140 | 183 |
| 141 private: | 184 private: |
| 142 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; | 185 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; |
| 143 FRIEND_TEST_ALL_PREFIXES(WebstoreStandaloneInstallerTest, DomainVerification); | 186 FRIEND_TEST_ALL_PREFIXES(WebstoreStandaloneInstallerTest, DomainVerification); |
| 144 | 187 |
| 145 // Several delegate/client interface implementations follow. The normal flow | 188 // Several delegate/client interface implementations follow. The normal flow |
| 146 // (for successful installs) is: | 189 // (for successful installs) is: |
| 147 // | 190 // |
| 148 // 1. BeginInstall: starts the fetch of data from the webstore | 191 // 1. BeginInstall: starts the fetch of data from the webstore |
| 149 // 2. OnURLFetchComplete: starts the parsing of data from the webstore | 192 // 2. OnURLFetchComplete: starts the parsing of data from the webstore |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 // Created by ShowInstallUI() when a prompt is shown (if | 258 // Created by ShowInstallUI() when a prompt is shown (if |
| 216 // the implementor returns a non-NULL in CreateInstallPrompt()). | 259 // the implementor returns a non-NULL in CreateInstallPrompt()). |
| 217 scoped_refptr<Extension> localized_extension_for_display_; | 260 scoped_refptr<Extension> localized_extension_for_display_; |
| 218 | 261 |
| 219 DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreStandaloneInstaller); | 262 DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreStandaloneInstaller); |
| 220 }; | 263 }; |
| 221 | 264 |
| 222 } // namespace extensions | 265 } // namespace extensions |
| 223 | 266 |
| 224 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_STANDALONE_INSTALLER_H_ | 267 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_STANDALONE_INSTALLER_H_ |
| OLD | NEW |