OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/values.h" |
| 14 #include "chrome/browser/extensions/extension_install_ui.h" |
| 15 #include "chrome/browser/extensions/webstore_install_helper.h" |
| 16 #include "content/common/url_fetcher.h" |
| 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 18 |
| 19 class TabContents; |
| 20 class SafeWebstoreResponseParser; |
| 21 |
| 22 // Manages inline installs requested by a page (downloads and parses metadata |
| 23 // from the webstore, shows the install UI, starts the download once the user |
| 24 // confirms). Clients must implement the WebstoreInlineInstaller::Delegate |
| 25 // interface to be notified when the inline install completes (successfully or |
| 26 // not). |
| 27 class WebstoreInlineInstaller |
| 28 : public base::RefCountedThreadSafe<WebstoreInlineInstaller>, |
| 29 public ExtensionInstallUI::Delegate, |
| 30 public URLFetcher::Delegate, |
| 31 public WebstoreInstallHelper::Delegate { |
| 32 public: |
| 33 class Delegate { |
| 34 public: |
| 35 virtual void OnInlineInstallSuccess() = 0; |
| 36 virtual void OnInlineInstallFailure(const std::string& error) = 0; |
| 37 }; |
| 38 |
| 39 WebstoreInlineInstaller(TabContents* tab_contents, |
| 40 std::string webstore_item_id, |
| 41 Delegate* d); |
| 42 void BeginInstall(); |
| 43 |
| 44 // For use only in tests - sets a flag that makes invocations of |
| 45 // chrome.webstore.install skip putting up a real dialog, and instead act |
| 46 // as if the dialog choice was to proceed or abort. |
| 47 static void SetAutoConfirmForTests(bool should_proceed); |
| 48 |
| 49 private: |
| 50 friend class base::RefCountedThreadSafe<WebstoreInlineInstaller>; |
| 51 friend class SafeWebstoreResponseParser; |
| 52 |
| 53 virtual ~WebstoreInlineInstaller(); |
| 54 |
| 55 // Several delegate/client inteface implementations follow. The normal flow |
| 56 // (for successful installs) is: |
| 57 // |
| 58 // 1. BeginInstall: starts the fetch of data from the webstore |
| 59 // 2. OnURLFetchComplete: starts the parsing of data from the webstore |
| 60 // 3. OnWebstoreResponseParseSuccess: starts the parsing of the manifest and |
| 61 // fetching of icon data. |
| 62 // 4. OnWebstoreParseSuccess: shows the install UI |
| 63 // 5. InstallUIProceed: initiates the .crx download/install |
| 64 // |
| 65 // All flows (whether successful or not) end up in CompleteInstall, which |
| 66 // informs our delegate of success/failure. |
| 67 |
| 68 // UrlFetcher::Delegate interface implementation. |
| 69 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
| 70 |
| 71 // Client callbacks for SafeWebstoreResponseParser when parsing is complete. |
| 72 void OnWebstoreResponseParseSuccess(DictionaryValue* webstore_data); |
| 73 void OnWebstoreResponseParseFailure(const std::string& error); |
| 74 |
| 75 // WebstoreInstallHelper::Delegate interface implementation. |
| 76 virtual void OnWebstoreParseSuccess( |
| 77 const SkBitmap& icon, |
| 78 base::DictionaryValue* parsed_manifest) OVERRIDE; |
| 79 virtual void OnWebstoreParseFailure( |
| 80 InstallHelperResultCode result_code, |
| 81 const std::string& error_message) OVERRIDE; |
| 82 |
| 83 // ExtensionInstallUI::Delegate interface implementation. |
| 84 virtual void InstallUIProceed() OVERRIDE; |
| 85 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
| 86 |
| 87 void CompleteInstall(const std::string& error); |
| 88 |
| 89 TabContents* tab_contents_; |
| 90 std::string id_; |
| 91 Delegate* delegate_; |
| 92 |
| 93 // For fetching webstore JSON data. |
| 94 scoped_ptr<URLFetcher> webstore_data_url_fetcher_; |
| 95 |
| 96 // Extracted from the webstore JSON data response. |
| 97 std::string localized_name_; |
| 98 scoped_ptr<DictionaryValue> webstore_data_; |
| 99 scoped_ptr<DictionaryValue> manifest_; |
| 100 SkBitmap icon_; |
| 101 |
| 102 DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreInlineInstaller); |
| 103 }; |
| 104 |
| 105 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_ |
OLD | NEW |