Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1601)

Unified Diff: chrome/browser/extensions/bundle_installer.h

Issue 9414013: Add a webstore API for installing bundles of extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/bundle_installer.h
diff --git a/chrome/browser/extensions/bundle_installer.h b/chrome/browser/extensions/bundle_installer.h
new file mode 100644
index 0000000000000000000000000000000000000000..b36c075b589ae3470d5d07070e2f1c175d5c19d0
--- /dev/null
+++ b/chrome/browser/extensions/bundle_installer.h
@@ -0,0 +1,186 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_BUNDLE_INSTALLER_H_
+#define CHROME_BROWSER_EXTENSIONS_BUNDLE_INSTALLER_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/memory/linked_ptr.h"
+#include "chrome/browser/extensions/extension_install_ui.h"
+#include "chrome/browser/extensions/webstore_installer.h"
+#include "chrome/browser/extensions/webstore_install_helper.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/common/extensions/extension.h"
+
+namespace base {
+class DictionaryValue;
+} // namespace base
+
+namespace content {
+class NavigationController;
+} // namespace content
+
+class Browser;
+class Profile;
+
+namespace extensions {
+
+// Manages the installation life cycle for extension bundles.
+//
+// We install bundles in two steps:
+// 1) PromptForApproval: parse manifests and prompt the user
+// 2) CompleteInstall: install the CRXs and show confirmation bubble
+//
+class BundleInstaller : public WebstoreInstallHelper::Delegate,
+ public ExtensionInstallUI::Delegate,
+ public WebstoreInstaller::Delegate,
+ public BrowserList::Observer,
+ public base::RefCountedThreadSafe<BundleInstaller> {
+ public:
+ // Auto approve or cancel the permission prompt.
+ static void SetAutoApproveForTesting(bool approve);
+
+ class Delegate {
+ public:
+ virtual void OnBundleInstallApproved() {}
+ virtual void OnBundleInstallCanceled(bool user_initiated) {}
+ virtual void OnBundleInstallCompleted() {}
+ };
+
+ // Represents an individual member of the bundle.
+ struct Item {
+ // Items are in the PENDING state until they've been installed, or the
+ // install has failed or been canceled.
+ enum State {
+ STATE_PENDING,
+ STATE_INSTALLED,
+ STATE_FAILED
+ };
+
+ Item();
+
+ // Creates a dummy extension and sets the manifest's name to the item's
+ // localized name.
+ scoped_refptr<Extension> CreateDummyExtension(
+ base::DictionaryValue* manifest);
+
+ std::string id;
+ std::string manifest;
+ std::string localized_name;
+ State state;
+ };
+
+ typedef std::vector<Item> ItemList;
+
+ BundleInstaller(Profile* profile, const ItemList& items);
+ virtual ~BundleInstaller();
+
+ // Returns true if the user has approved the bundle's permissions.
+ bool approved() const { return approved_; }
+
+ // Gets the items in the given state.
+ ItemList GetItemsByState(Item::State state) const;
Yoyo Zhou 2012/02/22 00:20:26 GetItemsWithState, perhaps?
jstritar 2012/02/22 15:45:48 Done.
+
+ // Parses the extension manifests and then prompts the user to approve their
+ // permissions. One of OnBundleInstallApproved or OnBundleInstallCanceled
+ // will be called when complete if |delegate| is not NULL.
+ // Note: the |delegate| must stay alive until receiving the callback.
+ void PromptForApproval(Delegate* delegate);
+
+ // If the bundle has been approved, this downloads and installs the member
+ // extensions. OnBundleInstallComplete will be called when the process is
+ // complete and |delegate| is not NULL. The download process uses the
+ // specified |controller|. When complete, we show a confirmation bubble in
+ // the specified |browser|.
+ // Note: the |delegate| must stay alive until receiving the callback.
+ void CompleteInstall(content::NavigationController* controller,
+ Browser* browser,
+ Delegate* delegate);
+
+ private:
+ friend class base::RefCountedThreadSafe<BundleInstaller>;
+
+ typedef std::map<std::string, Item> ItemMap;
+ typedef std::map<std::string, linked_ptr<base::DictionaryValue> > ManifestMap;
+
+ // Displays the install bubble for |bundle| on |browser|.
+ // Note: this is a platform specific implementation.
+ static void ShowInstalledBubble(const BundleInstaller* bundle,
+ Browser* browser);
+
+ // Parses the manifests using WebstoreInstallHelper.
+ void ParseManifests();
+
+ // Notifies the delegate that the installation has been approved.
+ void ReportApproved();
+
+ // Notifies the delegate that the installation was canceled.
+ void ReportCanceled(bool user_initiated);
+
+ // Notifies the delegate that the installation is complete.
+ void ReportComplete();
+
+ // Prompts the user to install the bundle once we have dummy extensions for
+ // all the pending items.
+ void ShowPromptIfDoneParsing();
+
+ // Prompts the user to install the bundle.
+ void ShowPrompt();
+
+ // Displays the installed bubble once all items have installed or failed.
+ void ShowInstalledBubbleIfDone();
+
+ // WebstoreInstallHelper::Delegate implementation:
+ virtual void OnWebstoreParseSuccess(
+ const std::string& id,
+ const SkBitmap& icon,
+ base::DictionaryValue* parsed_manifest) OVERRIDE;
+ virtual void OnWebstoreParseFailure(
+ const std::string& id,
+ InstallHelperResultCode result_code,
+ const std::string& error_message) OVERRIDE;
+
+ // ExtensionInstallUI::Delegate implementation:
+ virtual void InstallUIProceed() OVERRIDE;
+ virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
+
+ // WebstoreInstaller::Delegate implementation:
+ virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
+ virtual void OnExtensionInstallFailure(const std::string& id,
+ const std::string& error) OVERRIDE;
+
+ // BrowserList::observer implementation:
+ virtual void OnBrowserAdded(const Browser* browser) OVERRIDE;
+ virtual void OnBrowserRemoved(const Browser* browser) OVERRIDE;
+ virtual void OnBrowserSetLastActive(const Browser* browser) OVERRIDE;
+
+ // Holds the Extensions used to generate the permission warnings.
+ ExtensionList dummy_extensions_;
+
+ // Holds the parsed manifests, indexed by the extension ids.
+ ManifestMap parsed_manifests_;
+
+ // True if the user has approved the bundle.
+ bool approved_;
+
+ // Holds the bundle's Items, indexed by their ids.
+ ItemMap items_;
+
+ // The browser to show the confirmation bubble for.
+ Browser* browser_;
+
+ // The profile that the bundle should be installed in.
+ Profile* profile_;
+
+ Delegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(BundleInstaller);
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_BUNDLE_INSTALLER_H_
« no previous file with comments | « no previous file | chrome/browser/extensions/bundle_installer.cc » ('j') | chrome/browser/extensions/bundle_installer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698