OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_BUNDLE_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_BUNDLE_INSTALLER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/memory/linked_ptr.h" |
| 13 #include "chrome/browser/extensions/extension_install_ui.h" |
| 14 #include "chrome/browser/extensions/webstore_installer.h" |
| 15 #include "chrome/browser/extensions/webstore_install_helper.h" |
| 16 #include "chrome/browser/ui/browser_list.h" |
| 17 #include "chrome/common/extensions/extension.h" |
| 18 |
| 19 namespace base { |
| 20 class DictionaryValue; |
| 21 } // namespace base |
| 22 |
| 23 namespace content { |
| 24 class NavigationController; |
| 25 } // namespace content |
| 26 |
| 27 class Browser; |
| 28 class Profile; |
| 29 |
| 30 namespace extensions { |
| 31 |
| 32 // Manages the installation life cycle for extension bundles. |
| 33 // |
| 34 // We install bundles in two steps: |
| 35 // 1) PromptForApproval: parse manifests and prompt the user |
| 36 // 2) CompleteInstall: install the CRXs and show confirmation bubble |
| 37 // |
| 38 class BundleInstaller : public WebstoreInstallHelper::Delegate, |
| 39 public ExtensionInstallUI::Delegate, |
| 40 public WebstoreInstaller::Delegate, |
| 41 public BrowserList::Observer, |
| 42 public base::RefCountedThreadSafe<BundleInstaller> { |
| 43 public: |
| 44 // Auto approve or cancel the permission prompt. |
| 45 static void SetAutoApproveForTesting(bool approve); |
| 46 |
| 47 class Delegate { |
| 48 public: |
| 49 virtual void OnBundleInstallApproved() {} |
| 50 virtual void OnBundleInstallCanceled(bool user_initiated) {} |
| 51 virtual void OnBundleInstallCompleted() {} |
| 52 }; |
| 53 |
| 54 // Represents an individual member of the bundle. |
| 55 struct Item { |
| 56 // Items are in the PENDING state until they've been installed, or the |
| 57 // install has failed or been canceled. |
| 58 enum State { |
| 59 STATE_PENDING, |
| 60 STATE_INSTALLED, |
| 61 STATE_FAILED |
| 62 }; |
| 63 |
| 64 Item(); |
| 65 |
| 66 std::string id; |
| 67 std::string manifest; |
| 68 std::string localized_name; |
| 69 State state; |
| 70 }; |
| 71 |
| 72 typedef std::vector<Item> ItemList; |
| 73 |
| 74 BundleInstaller(Profile* profile, const ItemList& items); |
| 75 virtual ~BundleInstaller(); |
| 76 |
| 77 // Returns true if the user has approved the bundle's permissions. |
| 78 bool approved() const { return approved_; } |
| 79 |
| 80 // Gets the items in the given state. |
| 81 ItemList GetItemsWithState(Item::State state) const; |
| 82 |
| 83 // Parses the extension manifests and then prompts the user to approve their |
| 84 // permissions. One of OnBundleInstallApproved or OnBundleInstallCanceled |
| 85 // will be called when complete if |delegate| is not NULL. |
| 86 // Note: the |delegate| must stay alive until receiving the callback. |
| 87 void PromptForApproval(Delegate* delegate); |
| 88 |
| 89 // If the bundle has been approved, this downloads and installs the member |
| 90 // extensions. OnBundleInstallComplete will be called when the process is |
| 91 // complete and |delegate| is not NULL. The download process uses the |
| 92 // specified |controller|. When complete, we show a confirmation bubble in |
| 93 // the specified |browser|. |
| 94 // Note: the |delegate| must stay alive until receiving the callback. |
| 95 void CompleteInstall(content::NavigationController* controller, |
| 96 Browser* browser, |
| 97 Delegate* delegate); |
| 98 |
| 99 private: |
| 100 friend class base::RefCountedThreadSafe<BundleInstaller>; |
| 101 |
| 102 typedef std::map<std::string, Item> ItemMap; |
| 103 typedef std::map<std::string, linked_ptr<base::DictionaryValue> > ManifestMap; |
| 104 |
| 105 // Displays the install bubble for |bundle| on |browser|. |
| 106 // Note: this is a platform specific implementation. |
| 107 static void ShowInstalledBubble(const BundleInstaller* bundle, |
| 108 Browser* browser); |
| 109 |
| 110 // Parses the manifests using WebstoreInstallHelper. |
| 111 void ParseManifests(); |
| 112 |
| 113 // Notifies the delegate that the installation has been approved. |
| 114 void ReportApproved(); |
| 115 |
| 116 // Notifies the delegate that the installation was canceled. |
| 117 void ReportCanceled(bool user_initiated); |
| 118 |
| 119 // Notifies the delegate that the installation is complete. |
| 120 void ReportComplete(); |
| 121 |
| 122 // Prompts the user to install the bundle once we have dummy extensions for |
| 123 // all the pending items. |
| 124 void ShowPromptIfDoneParsing(); |
| 125 |
| 126 // Prompts the user to install the bundle. |
| 127 void ShowPrompt(); |
| 128 |
| 129 // Displays the installed bubble once all items have installed or failed. |
| 130 void ShowInstalledBubbleIfDone(); |
| 131 |
| 132 // WebstoreInstallHelper::Delegate implementation: |
| 133 virtual void OnWebstoreParseSuccess( |
| 134 const std::string& id, |
| 135 const SkBitmap& icon, |
| 136 base::DictionaryValue* parsed_manifest) OVERRIDE; |
| 137 virtual void OnWebstoreParseFailure( |
| 138 const std::string& id, |
| 139 InstallHelperResultCode result_code, |
| 140 const std::string& error_message) OVERRIDE; |
| 141 |
| 142 // ExtensionInstallUI::Delegate implementation: |
| 143 virtual void InstallUIProceed() OVERRIDE; |
| 144 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
| 145 |
| 146 // WebstoreInstaller::Delegate implementation: |
| 147 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE; |
| 148 virtual void OnExtensionInstallFailure(const std::string& id, |
| 149 const std::string& error) OVERRIDE; |
| 150 |
| 151 // BrowserList::observer implementation: |
| 152 virtual void OnBrowserAdded(const Browser* browser) OVERRIDE; |
| 153 virtual void OnBrowserRemoved(const Browser* browser) OVERRIDE; |
| 154 virtual void OnBrowserSetLastActive(const Browser* browser) OVERRIDE; |
| 155 |
| 156 // Holds the Extensions used to generate the permission warnings. |
| 157 ExtensionList dummy_extensions_; |
| 158 |
| 159 // Holds the parsed manifests, indexed by the extension ids. |
| 160 ManifestMap parsed_manifests_; |
| 161 |
| 162 // True if the user has approved the bundle. |
| 163 bool approved_; |
| 164 |
| 165 // Holds the bundle's Items, indexed by their ids. |
| 166 ItemMap items_; |
| 167 |
| 168 // The browser to show the confirmation bubble for. |
| 169 Browser* browser_; |
| 170 |
| 171 // The profile that the bundle should be installed in. |
| 172 Profile* profile_; |
| 173 |
| 174 Delegate* delegate_; |
| 175 |
| 176 DISALLOW_COPY_AND_ASSIGN(BundleInstaller); |
| 177 }; |
| 178 |
| 179 } // namespace extensions |
| 180 |
| 181 #endif // CHROME_BROWSER_EXTENSIONS_BUNDLE_INSTALLER_H_ |
OLD | NEW |