| 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_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "base/version.h" | 16 #include "base/version.h" |
| 17 #include "chrome/browser/extensions/extension_install_prompt.h" | 17 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/download_interrupt_reasons.h" | 19 #include "content/public/browser/download_interrupt_reasons.h" |
| 20 #include "content/public/browser/download_item.h" | 20 #include "content/public/browser/download_item.h" |
| 21 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 23 #include "content/public/browser/web_contents_observer.h" |
| 23 #include "extensions/common/manifest_handlers/shared_module_info.h" | 24 #include "extensions/common/manifest_handlers/shared_module_info.h" |
| 24 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 class Profile; | 28 class Profile; |
| 28 | 29 |
| 29 namespace base { | 30 namespace base { |
| 30 class FilePath; | 31 class FilePath; |
| 31 } | 32 } |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 class NavigationController; | 35 class NavigationController; |
| 35 } | 36 } |
| 36 | 37 |
| 37 namespace extensions { | 38 namespace extensions { |
| 38 | 39 |
| 39 class Extension; | 40 class Extension; |
| 40 class Manifest; | 41 class Manifest; |
| 41 | 42 |
| 42 // Downloads and installs extensions from the web store. | 43 // Downloads and installs extensions from the web store. |
| 43 class WebstoreInstaller :public content::NotificationObserver, | 44 class WebstoreInstaller : public content::NotificationObserver, |
| 44 public content::DownloadItem::Observer, | 45 public content::DownloadItem::Observer, |
| 45 public base::RefCountedThreadSafe< | 46 public content::WebContentsObserver, |
| 46 WebstoreInstaller, content::BrowserThread::DeleteOnUIThread> { | 47 public base::RefCountedThreadSafe< |
| 48 WebstoreInstaller, |
| 49 content::BrowserThread::DeleteOnUIThread> { |
| 47 public: | 50 public: |
| 48 enum InstallSource { | 51 enum InstallSource { |
| 49 // Inline installs trigger slightly different behavior (install source | 52 // Inline installs trigger slightly different behavior (install source |
| 50 // is different, download referrers are the item's page in the gallery). | 53 // is different, download referrers are the item's page in the gallery). |
| 51 INSTALL_SOURCE_INLINE, | 54 INSTALL_SOURCE_INLINE, |
| 52 INSTALL_SOURCE_APP_LAUNCHER, | 55 INSTALL_SOURCE_APP_LAUNCHER, |
| 53 INSTALL_SOURCE_OTHER | 56 INSTALL_SOURCE_OTHER |
| 54 }; | 57 }; |
| 55 | 58 |
| 56 enum FailureReason { | 59 enum FailureReason { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 }; | 162 }; |
| 160 | 163 |
| 161 // Gets the Approval associated with the |download|, or NULL if there's none. | 164 // Gets the Approval associated with the |download|, or NULL if there's none. |
| 162 // Note that the Approval is owned by |download|. | 165 // Note that the Approval is owned by |download|. |
| 163 static const Approval* GetAssociatedApproval( | 166 static const Approval* GetAssociatedApproval( |
| 164 const content::DownloadItem& download); | 167 const content::DownloadItem& download); |
| 165 | 168 |
| 166 // Creates a WebstoreInstaller for downloading and installing the extension | 169 // Creates a WebstoreInstaller for downloading and installing the extension |
| 167 // with the given |id| from the Chrome Web Store. If |delegate| is not NULL, | 170 // with the given |id| from the Chrome Web Store. If |delegate| is not NULL, |
| 168 // it will be notified when the install succeeds or fails. The installer will | 171 // it will be notified when the install succeeds or fails. The installer will |
| 169 // use the specified |controller| to download the extension. Only one | 172 // use the controller obtained from |web_contents| to download the extension. |
| 170 // WebstoreInstaller can use a specific controller at any given time. This | 173 // Only one WebstoreInstaller can use a specific controller at any given time. |
| 171 // also associates the |approval| with this install. | 174 // This also associates the |approval| with this install. |
| 172 // Note: the delegate should stay alive until being called back. | 175 // Note: the delegate should stay alive until being called back. |
| 173 WebstoreInstaller(Profile* profile, | 176 WebstoreInstaller(Profile* profile, |
| 174 Delegate* delegate, | 177 Delegate* delegate, |
| 175 content::NavigationController* controller, | 178 content::WebContents* web_contents, |
| 176 const std::string& id, | 179 const std::string& id, |
| 177 scoped_ptr<Approval> approval, | 180 scoped_ptr<Approval> approval, |
| 178 InstallSource source); | 181 InstallSource source); |
| 179 | 182 |
| 180 // Starts downloading and installing the extension. | 183 // Starts downloading and installing the extension. |
| 181 void Start(); | 184 void Start(); |
| 182 | 185 |
| 183 // content::NotificationObserver | 186 // content::NotificationObserver |
| 184 virtual void Observe(int type, | 187 virtual void Observe(int type, |
| 185 const content::NotificationSource& source, | 188 const content::NotificationSource& source, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // this managed its installation. This also removes the associated | 233 // this managed its installation. This also removes the associated |
| 231 // PendingInstall. | 234 // PendingInstall. |
| 232 void ReportSuccess(); | 235 void ReportSuccess(); |
| 233 | 236 |
| 234 // Records stats regarding an interrupted webstore download item. | 237 // Records stats regarding an interrupted webstore download item. |
| 235 void RecordInterrupt(const content::DownloadItem* download) const; | 238 void RecordInterrupt(const content::DownloadItem* download) const; |
| 236 | 239 |
| 237 content::NotificationRegistrar registrar_; | 240 content::NotificationRegistrar registrar_; |
| 238 Profile* profile_; | 241 Profile* profile_; |
| 239 Delegate* delegate_; | 242 Delegate* delegate_; |
| 240 content::NavigationController* controller_; | |
| 241 std::string id_; | 243 std::string id_; |
| 242 InstallSource install_source_; | 244 InstallSource install_source_; |
| 243 // The DownloadItem is owned by the DownloadManager and is valid from when | 245 // The DownloadItem is owned by the DownloadManager and is valid from when |
| 244 // OnDownloadStarted is called (with no error) until OnDownloadDestroyed(). | 246 // OnDownloadStarted is called (with no error) until OnDownloadDestroyed(). |
| 245 content::DownloadItem* download_item_; | 247 content::DownloadItem* download_item_; |
| 246 scoped_ptr<Approval> approval_; | 248 scoped_ptr<Approval> approval_; |
| 247 GURL download_url_; | 249 GURL download_url_; |
| 248 | 250 |
| 249 // Pending modules. | 251 // Pending modules. |
| 250 std::list<SharedModuleInfo::ImportInfo> pending_modules_; | 252 std::list<SharedModuleInfo::ImportInfo> pending_modules_; |
| 251 // Total extension modules we need download and install (the main module and | 253 // Total extension modules we need download and install (the main module and |
| 252 // depedences). | 254 // depedences). |
| 253 int total_modules_; | 255 int total_modules_; |
| 254 bool download_started_; | 256 bool download_started_; |
| 255 }; | 257 }; |
| 256 | 258 |
| 257 } // namespace extensions | 259 } // namespace extensions |
| 258 | 260 |
| 259 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ | 261 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
| OLD | NEW |