| 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 <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "chrome/browser/extensions/active_install_data.h" | 14 #include "chrome/browser/extensions/active_install_data.h" |
| 15 #include "chrome/browser/extensions/extension_install_prompt.h" | 15 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 16 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h" | 16 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h" |
| 17 #include "chrome/browser/extensions/webstore_install_helper.h" | 17 #include "chrome/browser/extensions/webstore_install_helper.h" |
| 18 #include "chrome/browser/extensions/webstore_installer.h" | 18 #include "chrome/browser/extensions/webstore_installer.h" |
| 19 #include "chrome/common/extensions/webstore_install_result.h" | 19 #include "chrome/common/extensions/webstore_install_result.h" |
| 20 #include "net/url_request/url_fetcher_delegate.h" | 20 #include "net/url_request/url_fetcher_delegate.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 | 22 |
| 23 class GURL; | 23 class GURL; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 // In the very least this should return a dummy WebContents (required | 114 // In the very least this should return a dummy WebContents (required |
| 115 // by some calls even when no prompt or other UI is shown). A non-dummy | 115 // by some calls even when no prompt or other UI is shown). A non-dummy |
| 116 // WebContents is required if the prompt returned by CreateInstallPromt() | 116 // WebContents is required if the prompt returned by CreateInstallPromt() |
| 117 // contains a navigable link(s). Returned WebContents should correspond | 117 // contains a navigable link(s). Returned WebContents should correspond |
| 118 // to |profile| passed into the constructor. | 118 // to |profile| passed into the constructor. |
| 119 virtual content::WebContents* GetWebContents() const = 0; | 119 virtual content::WebContents* GetWebContents() const = 0; |
| 120 | 120 |
| 121 // Should return an installation prompt with desired properties or NULL if | 121 // Should return an installation prompt with desired properties or NULL if |
| 122 // no prompt should be shown. | 122 // no prompt should be shown. |
| 123 virtual scoped_ptr<ExtensionInstallPrompt::Prompt> CreateInstallPrompt() | 123 virtual std::unique_ptr<ExtensionInstallPrompt::Prompt> CreateInstallPrompt() |
| 124 const = 0; | 124 const = 0; |
| 125 | 125 |
| 126 // Perform all necessary checks to make sure inline install is permitted, | 126 // Perform all necessary checks to make sure inline install is permitted, |
| 127 // e.g. in the extension's properties in the store. The implementation may | 127 // e.g. in the extension's properties in the store. The implementation may |
| 128 // choose to ignore such properties. | 128 // choose to ignore such properties. |
| 129 virtual bool CheckInlineInstallPermitted( | 129 virtual bool CheckInlineInstallPermitted( |
| 130 const base::DictionaryValue& webstore_data, | 130 const base::DictionaryValue& webstore_data, |
| 131 std::string* error) const = 0; | 131 std::string* error) const = 0; |
| 132 | 132 |
| 133 // Perform all necessary checks to make sure that requestor is allowed to | 133 // Perform all necessary checks to make sure that requestor is allowed to |
| 134 // initiate this install (e.g. that the requestor's URL matches the verified | 134 // initiate this install (e.g. that the requestor's URL matches the verified |
| 135 // author's site specified in the extension's properties in the store). | 135 // author's site specified in the extension's properties in the store). |
| 136 virtual bool CheckRequestorPermitted( | 136 virtual bool CheckRequestorPermitted( |
| 137 const base::DictionaryValue& webstore_data, | 137 const base::DictionaryValue& webstore_data, |
| 138 std::string* error) const = 0; | 138 std::string* error) const = 0; |
| 139 | 139 |
| 140 // Will be called after the extension's manifest has been successfully parsed. | 140 // Will be called after the extension's manifest has been successfully parsed. |
| 141 // Subclasses can perform asynchronous checks at this point and call | 141 // Subclasses can perform asynchronous checks at this point and call |
| 142 // ProceedWithInstallPrompt() to proceed with the install or otherwise call | 142 // ProceedWithInstallPrompt() to proceed with the install or otherwise call |
| 143 // CompleteInstall() with an error code. The default implementation calls | 143 // CompleteInstall() with an error code. The default implementation calls |
| 144 // ProceedWithInstallPrompt(). | 144 // ProceedWithInstallPrompt(). |
| 145 virtual void OnManifestParsed(); | 145 virtual void OnManifestParsed(); |
| 146 | 146 |
| 147 // Returns an install UI to be shown. By default, this returns an install UI | 147 // Returns an install UI to be shown. By default, this returns an install UI |
| 148 // that is a transient child of the host window for GetWebContents(). | 148 // that is a transient child of the host window for GetWebContents(). |
| 149 virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI(); | 149 virtual std::unique_ptr<ExtensionInstallPrompt> CreateInstallUI(); |
| 150 | 150 |
| 151 // Create an approval to pass installation parameters to the CrxInstaller. | 151 // Create an approval to pass installation parameters to the CrxInstaller. |
| 152 virtual scoped_ptr<WebstoreInstaller::Approval> CreateApproval() const; | 152 virtual std::unique_ptr<WebstoreInstaller::Approval> CreateApproval() const; |
| 153 | 153 |
| 154 // Called once the install prompt has finished. | 154 // Called once the install prompt has finished. |
| 155 virtual void OnInstallPromptDone(ExtensionInstallPrompt::Result result); | 155 virtual void OnInstallPromptDone(ExtensionInstallPrompt::Result result); |
| 156 | 156 |
| 157 // Accessors to be used by subclasses. | 157 // Accessors to be used by subclasses. |
| 158 bool show_user_count() const { return show_user_count_; } | 158 bool show_user_count() const { return show_user_count_; } |
| 159 const std::string& localized_user_count() const { | 159 const std::string& localized_user_count() const { |
| 160 return localized_user_count_; | 160 return localized_user_count_; |
| 161 } | 161 } |
| 162 double average_rating() const { return average_rating_; } | 162 double average_rating() const { return average_rating_; } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 187 // 4. OnWebstoreParseSuccess: shows the install UI | 187 // 4. OnWebstoreParseSuccess: shows the install UI |
| 188 // 5. InstallUIProceed: initiates the .crx download/install | 188 // 5. InstallUIProceed: initiates the .crx download/install |
| 189 // | 189 // |
| 190 // All flows (whether successful or not) end up in CompleteInstall, which | 190 // All flows (whether successful or not) end up in CompleteInstall, which |
| 191 // informs our delegate of success/failure. | 191 // informs our delegate of success/failure. |
| 192 | 192 |
| 193 // WebstoreDataFetcherDelegate interface implementation. | 193 // WebstoreDataFetcherDelegate interface implementation. |
| 194 void OnWebstoreRequestFailure() override; | 194 void OnWebstoreRequestFailure() override; |
| 195 | 195 |
| 196 void OnWebstoreResponseParseSuccess( | 196 void OnWebstoreResponseParseSuccess( |
| 197 scoped_ptr<base::DictionaryValue> webstore_data) override; | 197 std::unique_ptr<base::DictionaryValue> webstore_data) override; |
| 198 | 198 |
| 199 void OnWebstoreResponseParseFailure(const std::string& error) override; | 199 void OnWebstoreResponseParseFailure(const std::string& error) override; |
| 200 | 200 |
| 201 // WebstoreInstallHelper::Delegate interface implementation. | 201 // WebstoreInstallHelper::Delegate interface implementation. |
| 202 void OnWebstoreParseSuccess(const std::string& id, | 202 void OnWebstoreParseSuccess(const std::string& id, |
| 203 const SkBitmap& icon, | 203 const SkBitmap& icon, |
| 204 base::DictionaryValue* parsed_manifest) override; | 204 base::DictionaryValue* parsed_manifest) override; |
| 205 void OnWebstoreParseFailure(const std::string& id, | 205 void OnWebstoreParseFailure(const std::string& id, |
| 206 InstallHelperResultCode result_code, | 206 InstallHelperResultCode result_code, |
| 207 const std::string& error_message) override; | 207 const std::string& error_message) override; |
| 208 | 208 |
| 209 // WebstoreInstaller::Delegate interface implementation. | 209 // WebstoreInstaller::Delegate interface implementation. |
| 210 void OnExtensionInstallSuccess(const std::string& id) override; | 210 void OnExtensionInstallSuccess(const std::string& id) override; |
| 211 void OnExtensionInstallFailure( | 211 void OnExtensionInstallFailure( |
| 212 const std::string& id, | 212 const std::string& id, |
| 213 const std::string& error, | 213 const std::string& error, |
| 214 WebstoreInstaller::FailureReason reason) override; | 214 WebstoreInstaller::FailureReason reason) override; |
| 215 | 215 |
| 216 void ShowInstallUI(); | 216 void ShowInstallUI(); |
| 217 void OnWebStoreDataFetcherDone(); | 217 void OnWebStoreDataFetcherDone(); |
| 218 | 218 |
| 219 // Input configuration. | 219 // Input configuration. |
| 220 std::string id_; | 220 std::string id_; |
| 221 Callback callback_; | 221 Callback callback_; |
| 222 Profile* profile_; | 222 Profile* profile_; |
| 223 WebstoreInstaller::InstallSource install_source_; | 223 WebstoreInstaller::InstallSource install_source_; |
| 224 | 224 |
| 225 // Installation dialog and its underlying prompt. | 225 // Installation dialog and its underlying prompt. |
| 226 scoped_ptr<ExtensionInstallPrompt> install_ui_; | 226 std::unique_ptr<ExtensionInstallPrompt> install_ui_; |
| 227 scoped_ptr<ExtensionInstallPrompt::Prompt> install_prompt_; | 227 std::unique_ptr<ExtensionInstallPrompt::Prompt> install_prompt_; |
| 228 | 228 |
| 229 // For fetching webstore JSON data. | 229 // For fetching webstore JSON data. |
| 230 scoped_ptr<WebstoreDataFetcher> webstore_data_fetcher_; | 230 std::unique_ptr<WebstoreDataFetcher> webstore_data_fetcher_; |
| 231 | 231 |
| 232 // Extracted from the webstore JSON data response. | 232 // Extracted from the webstore JSON data response. |
| 233 std::string localized_name_; | 233 std::string localized_name_; |
| 234 std::string localized_description_; | 234 std::string localized_description_; |
| 235 bool show_user_count_; | 235 bool show_user_count_; |
| 236 std::string localized_user_count_; | 236 std::string localized_user_count_; |
| 237 double average_rating_; | 237 double average_rating_; |
| 238 int rating_count_; | 238 int rating_count_; |
| 239 scoped_ptr<base::DictionaryValue> webstore_data_; | 239 std::unique_ptr<base::DictionaryValue> webstore_data_; |
| 240 scoped_ptr<base::DictionaryValue> manifest_; | 240 std::unique_ptr<base::DictionaryValue> manifest_; |
| 241 SkBitmap icon_; | 241 SkBitmap icon_; |
| 242 | 242 |
| 243 // Active install registered with the InstallTracker. | 243 // Active install registered with the InstallTracker. |
| 244 scoped_ptr<ScopedActiveInstall> scoped_active_install_; | 244 std::unique_ptr<ScopedActiveInstall> scoped_active_install_; |
| 245 | 245 |
| 246 // Created by ShowInstallUI() when a prompt is shown (if | 246 // Created by ShowInstallUI() when a prompt is shown (if |
| 247 // the implementor returns a non-NULL in CreateInstallPrompt()). | 247 // the implementor returns a non-NULL in CreateInstallPrompt()). |
| 248 scoped_refptr<Extension> localized_extension_for_display_; | 248 scoped_refptr<Extension> localized_extension_for_display_; |
| 249 | 249 |
| 250 DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreStandaloneInstaller); | 250 DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreStandaloneInstaller); |
| 251 }; | 251 }; |
| 252 | 252 |
| 253 } // namespace extensions | 253 } // namespace extensions |
| 254 | 254 |
| 255 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_STANDALONE_INSTALLER_H_ | 255 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_STANDALONE_INSTALLER_H_ |
| OLD | NEW |