| 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" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/browser/extensions/extension_install_prompt.h" | 13 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 14 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h" | 14 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h" |
| 15 #include "chrome/browser/extensions/webstore_install_helper.h" | 15 #include "chrome/browser/extensions/webstore_install_helper.h" |
| 16 #include "chrome/browser/extensions/webstore_install_result.h" |
| 16 #include "chrome/browser/extensions/webstore_installer.h" | 17 #include "chrome/browser/extensions/webstore_installer.h" |
| 17 #include "net/url_request/url_fetcher_delegate.h" | 18 #include "net/url_request/url_fetcher_delegate.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 | 20 |
| 20 class GURL; | 21 class GURL; |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class DictionaryValue; | 24 class DictionaryValue; |
| 24 } | 25 } |
| 25 | 26 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 53 typedef base::Callback<void(bool success, const std::string& error)> Callback; | 54 typedef base::Callback<void(bool success, const std::string& error)> Callback; |
| 54 | 55 |
| 55 WebstoreStandaloneInstaller(const std::string& webstore_item_id, | 56 WebstoreStandaloneInstaller(const std::string& webstore_item_id, |
| 56 Profile* profile, | 57 Profile* profile, |
| 57 const Callback& callback); | 58 const Callback& callback); |
| 58 void BeginInstall(); | 59 void BeginInstall(); |
| 59 | 60 |
| 60 protected: | 61 protected: |
| 61 virtual ~WebstoreStandaloneInstaller(); | 62 virtual ~WebstoreStandaloneInstaller(); |
| 62 | 63 |
| 64 // Called when the install should be aborted. The callback is cleared. |
| 63 void AbortInstall(); | 65 void AbortInstall(); |
| 64 void InvokeCallback(const std::string& error); | 66 |
| 65 virtual void CompleteInstall(const std::string& error); | 67 // Called when the install is complete. |
| 68 virtual void CompleteInstall(webstore_install::Result result, |
| 69 const std::string& error); |
| 70 |
| 71 // Called when the installer should proceed to prompt the user. |
| 72 void ProceedWithInstallPrompt(); |
| 73 |
| 74 // Lazily creates a dummy extension for display from the parsed manifest. This |
| 75 // is safe to call from OnManifestParsed() onwards. The manifest may be |
| 76 // invalid, thus the caller must check that the return value is not NULL. |
| 77 scoped_refptr<const Extension> GetLocalizedExtensionForDisplay(); |
| 66 | 78 |
| 67 // Template Method's hooks to be implemented by subclasses. | 79 // Template Method's hooks to be implemented by subclasses. |
| 68 | 80 |
| 69 // Called at certain check points of the workflow to decide whether it makes | 81 // 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 | 82 // sense to proceed with installation. A requestor can be a website that |
| 71 // initiated an inline installation, or a command line option. | 83 // initiated an inline installation, or a command line option. |
| 72 virtual bool CheckRequestorAlive() const = 0; | 84 virtual bool CheckRequestorAlive() const = 0; |
| 73 | 85 |
| 74 // Requestor's URL, if any. Should be an empty GURL if URL is meaningless | 86 // Requestor's URL, if any. Should be an empty GURL if URL is meaningless |
| 75 // (e.g. for a command line option). | 87 // (e.g. for a command line option). |
| (...skipping 25 matching lines...) Expand all Loading... |
| 101 const base::DictionaryValue& webstore_data, | 113 const base::DictionaryValue& webstore_data, |
| 102 std::string* error) const = 0; | 114 std::string* error) const = 0; |
| 103 | 115 |
| 104 // Perform all necessary checks to make sure that requestor is allowed to | 116 // 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 | 117 // 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). | 118 // author's site specified in the extension's properties in the store). |
| 107 virtual bool CheckRequestorPermitted( | 119 virtual bool CheckRequestorPermitted( |
| 108 const base::DictionaryValue& webstore_data, | 120 const base::DictionaryValue& webstore_data, |
| 109 std::string* error) const = 0; | 121 std::string* error) const = 0; |
| 110 | 122 |
| 111 // Perform all necessary checks after the manifest has been parsed to make | 123 // Will be called after the extension's manifest has been successfully parsed. |
| 112 // sure that the install should still proceed. | 124 // Subclasses can perform asynchronous checks at this point and call |
| 113 virtual bool CheckInstallValid( | 125 // ProceedWithInstallPrompt() to proceed with the install or otherwise call |
| 114 const base::DictionaryValue& manifest, | 126 // CompleteInstall() with an error code. The default implementation calls |
| 115 std::string* error); | 127 // ProceedWithInstallPrompt(). |
| 128 virtual void OnManifestParsed(); |
| 116 | 129 |
| 117 // Returns an install UI to be shown. By default, this returns an install UI | 130 // 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(). | 131 // that is a transient child of the host window for GetWebContents(). |
| 119 virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI(); | 132 virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI(); |
| 120 | 133 |
| 121 // Create an approval to pass installation parameters to the CrxInstaller. | 134 // Create an approval to pass installation parameters to the CrxInstaller. |
| 122 virtual scoped_ptr<WebstoreInstaller::Approval> CreateApproval() const; | 135 virtual scoped_ptr<WebstoreInstaller::Approval> CreateApproval() const; |
| 123 | 136 |
| 124 // Accessors to be used by subclasses. | 137 // Accessors to be used by subclasses. |
| 125 bool show_user_count() const { return show_user_count_; } | 138 bool show_user_count() const { return show_user_count_; } |
| 126 const std::string& localized_user_count() const { | 139 const std::string& localized_user_count() const { |
| 127 return localized_user_count_; | 140 return localized_user_count_; |
| 128 } | 141 } |
| 129 double average_rating() const { return average_rating_; } | 142 double average_rating() const { return average_rating_; } |
| 130 int rating_count() const { return rating_count_; } | 143 int rating_count() const { return rating_count_; } |
| 131 void set_install_source(WebstoreInstaller::InstallSource source) { | 144 void set_install_source(WebstoreInstaller::InstallSource source) { |
| 132 install_source_ = source; | 145 install_source_ = source; |
| 133 } | 146 } |
| 134 WebstoreInstaller::InstallSource install_source() const { | 147 WebstoreInstaller::InstallSource install_source() const { |
| 135 return install_source_; | 148 return install_source_; |
| 136 } | 149 } |
| 137 Profile* profile() const { return profile_; } | 150 Profile* profile() const { return profile_; } |
| 138 const std::string& id() const { return id_; } | 151 const std::string& id() const { return id_; } |
| 139 const base::DictionaryValue* manifest() const { return manifest_.get(); } | 152 const base::DictionaryValue* manifest() const { return manifest_.get(); } |
| 153 const Extension* localized_extension_for_display() const { |
| 154 return localized_extension_for_display_.get(); |
| 155 } |
| 140 | 156 |
| 141 private: | 157 private: |
| 142 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; | 158 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; |
| 143 FRIEND_TEST_ALL_PREFIXES(WebstoreStandaloneInstallerTest, DomainVerification); | 159 FRIEND_TEST_ALL_PREFIXES(WebstoreStandaloneInstallerTest, DomainVerification); |
| 144 | 160 |
| 145 // Several delegate/client interface implementations follow. The normal flow | 161 // Several delegate/client interface implementations follow. The normal flow |
| 146 // (for successful installs) is: | 162 // (for successful installs) is: |
| 147 // | 163 // |
| 148 // 1. BeginInstall: starts the fetch of data from the webstore | 164 // 1. BeginInstall: starts the fetch of data from the webstore |
| 149 // 2. OnURLFetchComplete: starts the parsing of data from the webstore | 165 // 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 | 231 // Created by ShowInstallUI() when a prompt is shown (if |
| 216 // the implementor returns a non-NULL in CreateInstallPrompt()). | 232 // the implementor returns a non-NULL in CreateInstallPrompt()). |
| 217 scoped_refptr<Extension> localized_extension_for_display_; | 233 scoped_refptr<Extension> localized_extension_for_display_; |
| 218 | 234 |
| 219 DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreStandaloneInstaller); | 235 DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreStandaloneInstaller); |
| 220 }; | 236 }; |
| 221 | 237 |
| 222 } // namespace extensions | 238 } // namespace extensions |
| 223 | 239 |
| 224 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_STANDALONE_INSTALLER_H_ | 240 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_STANDALONE_INSTALLER_H_ |
| OLD | NEW |