extension_service.h revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file. 4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once 8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <map> 10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <string> 11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <vector> 12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/command_line.h" 14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/file_path.h" 15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/gtest_prod_util.h" 16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/linked_ptr.h" 17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/ref_counted.h" 18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/task.h" 19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/time.h" 20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/tuple.h" 21731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#include "chrome/browser/browser_thread.h" 22731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#include "chrome/browser/extensions/default_apps.h" 23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/extensions/extension_icon_manager.h" 24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/extensions/extension_menu_manager.h" 25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/extensions/extension_prefs.h" 26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/extensions/extension_process_manager.h" 27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/extensions/extension_toolbar_model.h" 28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/extensions/extensions_quota_service.h" 29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/extensions/external_extension_provider.h" 30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/extensions/sandboxed_extension_unpacker.h" 313345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#include "chrome/browser/prefs/pref_change_registrar.h" 32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/common/notification_observer.h" 33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/common/notification_registrar.h" 34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/common/extensions/extension.h" 35201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch#include "chrome/common/property_bag.h" 36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 3721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsenclass ExtensionServiceBackend; 38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ExtensionToolbarModel; 39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ExtensionUpdater; 40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass GURL; 41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass Profile; 42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass Version; 43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 4421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsentypedef bool (*ShouldInstallExtensionPredicate)(const Extension&); 4521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// A pending extension is an extension that hasn't been installed yet 47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// and is intended to be installed in the next auto-update cycle. The 48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// update URL of a pending extension may be blank, in which case a 49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// default one is assumed. 50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochstruct PendingExtensionInfo { 5121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen PendingExtensionInfo( 5221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen const GURL& update_url, 5321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen ShouldInstallExtensionPredicate should_install_extension, 5421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen bool is_from_sync, 5521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen bool install_silently, 5621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen bool enable_on_install, 5721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen bool enable_incognito_on_install, 5821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen Extension::Location install_source); 59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch PendingExtensionInfo(); 61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch GURL update_url; 6321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // When the extension is about to be installed, this function is 6421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // called. If this function returns true, the install proceeds. If 6521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // this function returns false, the install is aborted. 6621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen ShouldInstallExtensionPredicate should_install_extension; 673345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick bool is_from_sync; // This update check was initiated from sync. 68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool install_silently; 69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool enable_on_install; 70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool enable_incognito_on_install; 71731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick Extension::Location install_source; 72c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 73c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 74c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// A PendingExtensionMap is a map from IDs of pending extensions to 75c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// their info. 76c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochtypedef std::map<std::string, PendingExtensionInfo> PendingExtensionMap; 77c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 78c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This is an interface class to encapsulate the dependencies that 7921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen// ExtensionUpdater has on ExtensionService. This allows easy mocking. 80c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ExtensionUpdateService { 81c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public: 82c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual ~ExtensionUpdateService() {} 83c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual const ExtensionList* extensions() const = 0; 84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual const PendingExtensionMap& pending_extensions() const = 0; 85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void UpdateExtension(const std::string& id, const FilePath& path, 86c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const GURL& download_url) = 0; 87513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch virtual const Extension* GetExtensionById(const std::string& id, 88513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch bool include_disabled) = 0; 89c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void UpdateExtensionBlacklist( 90c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const std::vector<std::string>& blacklist) = 0; 913345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick virtual void CheckAdminBlacklist() = 0; 92c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual bool HasInstalledExtensions() = 0; 93c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 94c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual ExtensionPrefs* extension_prefs() = 0; 95c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 96c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 97c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Manages installed and running Chromium extensions. 9821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsenclass ExtensionService 9921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen : public base::RefCountedThreadSafe<ExtensionService, 100731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick BrowserThread::DeleteOnUIThread>, 101c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public ExtensionUpdateService, 102c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public NotificationObserver { 103c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public: 104c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Information about a registered component extension. 105c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch struct ComponentExtensionInfo { 106c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ComponentExtensionInfo(const std::string& manifest, 107c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const FilePath& root_directory) 108c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch : manifest(manifest), 109c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch root_directory(root_directory) { 110c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 111c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 112c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The extension's manifest. This is required for component extensions so 11321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // that ExtensionService doesn't need to go to disk to load them. 114c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch std::string manifest; 115c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 116c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Directory where the extension is stored. 117c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch FilePath root_directory; 118c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch }; 119c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 120c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The name of the directory inside the profile where extensions are 121c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // installed to. 122c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static const char* kInstallDirectoryName; 123c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 124c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // If auto-updates are turned on, default to running every 5 hours. 125c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static const int kDefaultUpdateFrequencySeconds = 60 * 60 * 5; 126c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 127c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The name of the file that the current active version number is stored in. 128c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static const char* kCurrentVersionFileName; 129c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 130c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Determine if a given extension download should be treated as if it came 131731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // from the gallery. Note that this is requires *both* that the download_url 132731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // match and that the download was referred from a gallery page. 133731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick bool IsDownloadFromGallery(const GURL& download_url, 134731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick const GURL& referrer_url); 135c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 136c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Determine if the downloaded extension came from the theme mini-gallery, 137c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Used to test if we need to show the "Loading" dialog for themes. 138c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static bool IsDownloadFromMiniGallery(const GURL& download_url); 139c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 14021d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // Returns whether the URL is from either a hosted or packaged app. 14121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen bool IsInstalledApp(const GURL& url); 14221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen 143731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // Attempts to uninstall an extension from a given ExtensionService. Returns 144731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // true iff the target extension exists. 14521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen static bool UninstallExtensionHelper(ExtensionService* extensions_service, 146731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick const std::string& extension_id); 147731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick 14821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // Constructor stores pointers to |profile| and |extension_prefs| but 14921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // ownership remains at caller. 15021d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen ExtensionService(Profile* profile, 151c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const CommandLine* command_line, 152c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const FilePath& install_directory, 15321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen ExtensionPrefs* extension_prefs, 154c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool autoupdate_enabled); 155c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 156c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Gets the list of currently installed extensions. 15721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen virtual const ExtensionList* extensions() const; 15821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen virtual const ExtensionList* disabled_extensions() const; 159c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 160c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Gets the set of pending extensions. 16121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen virtual const PendingExtensionMap& pending_extensions() const; 162c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 163c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Registers an extension to be loaded as a component extension. 164c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void register_component_extension(const ComponentExtensionInfo& info) { 165c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch component_extension_manifests_.push_back(info); 166c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 167c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 168c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Returns true if any extensions are installed. 16921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen virtual bool HasInstalledExtensions(); 170c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 171731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick const FilePath& install_directory() const { return install_directory_; } 172731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick 173731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick DefaultApps* default_apps() { return &default_apps_; } 174731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick 175c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Whether this extension can run in an incognito window. 176c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool IsIncognitoEnabled(const Extension* extension); 177513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch void SetIsIncognitoEnabled(const Extension* extension, bool enabled); 178513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch 179513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // Returns true if the given extension can see events and data from another 180513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // sub-profile (incognito to original profile, or vice versa). 181513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch bool CanCrossIncognito(const Extension* extension); 182c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 183c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Whether this extension can inject scripts into pages with file URLs. 184c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool AllowFileAccess(const Extension* extension); 185513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch void SetAllowFileAccess(const Extension* extension, bool allow); 186513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch 187201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // Getter and setter for the Browser Action visibility in the toolbar. 188201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch bool GetBrowserActionVisibility(const Extension* extension); 189201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch void SetBrowserActionVisibility(const Extension* extension, bool visible); 190201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch 191513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // Whether the background page, if any, is ready. We don't load other 192513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // components until then. If there is no background page, we consider it to 193513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // be ready. 194513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch bool IsBackgroundPageReady(const Extension* extension); 195513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch void SetBackgroundPageReady(const Extension* extension); 196513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch 197513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // Getter and setter for the flag that specifies whether the extension is 198513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // being upgraded. 199513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch bool IsBeingUpgraded(const Extension* extension); 200513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch void SetBeingUpgraded(const Extension* extension, bool value); 201c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 202201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // Getter for the extension's runtime data PropertyBag. 203201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch PropertyBag* GetPropertyBag(const Extension* extension); 204201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch 205c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Initialize and start all installed extensions. 206c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void Init(); 207c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 208c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Start up the extension event routers. 209c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void InitEventRouters(); 210c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 211c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Look up an extension by ID. 21221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen virtual const Extension* GetExtensionById(const std::string& id, 21321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen bool include_disabled); 214c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 215c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Install the extension file at |extension_path|. Will install as an 216c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // update if an older version is already installed. 217c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // For fresh installs, this method also causes the extension to be 218c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // immediately loaded. 219c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // TODO(aa): This method can be removed. It is only used by the unit tests, 220c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // and they could use CrxInstaller directly instead. 221c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void InstallExtension(const FilePath& extension_path); 222c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 223c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Updates a currently-installed extension with the contents from 224c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // |extension_path|. 225c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // TODO(aa): This method can be removed. ExtensionUpdater could use 226c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // CrxInstaller directly instead. 227c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void UpdateExtension(const std::string& id, 228c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const FilePath& extension_path, 229c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const GURL& download_url); 230c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 231c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Adds an extension in a pending state; the extension with the 232c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // given info will be installed on the next auto-update cycle. 233c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // 234c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // It is an error to call this with an already-installed extension 235c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // (even a disabled one). 236c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // 237c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // TODO(akalin): Replace |install_silently| with a list of 238c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // pre-enabled permissions. 2393345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick void AddPendingExtensionFromSync( 240c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const std::string& id, const GURL& update_url, 24121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen ShouldInstallExtensionPredicate should_install_extension, 2423345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick bool install_silently, bool enable_on_install, 2433345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick bool enable_incognito_on_install); 2443345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 2453345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Given an extension id and an update URL, schedule the extension 2463345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // to be fetched, installed, and activated. 2473345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick void AddPendingExtensionFromExternalUpdateUrl(const std::string& id, 248513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch const GURL& update_url, 249513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch Extension::Location location); 250c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 251731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // Like the above. Always installed silently, and defaults update url 252731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // from extension id. 253731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick void AddPendingExtensionFromDefaultAppList(const std::string& id); 254731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick 255c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Reloads the specified extension. 256c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void ReloadExtension(const std::string& extension_id); 257c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 258c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Uninstalls the specified extension. Callers should only call this method 259c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // with extensions that exist. |external_uninstall| is a magical parameter 260c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // that is only used to send information to ExtensionPrefs, which external 261c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // callers should never set to true. 262c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // TODO(aa): Remove |external_uninstall| -- this information should be passed 263c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // to ExtensionPrefs some other way. 264c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void UninstallExtension(const std::string& extension_id, 265c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool external_uninstall); 266c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 2673345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Enable or disable an extension. No action if the extension is already 2683345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // enabled/disabled. 269c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void EnableExtension(const std::string& extension_id); 270c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void DisableExtension(const std::string& extension_id); 271c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 272201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // Updates the |extension|'s granted permissions lists to include all 273201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // permissions in the |extension|'s manifest. 274201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch void GrantPermissions(const Extension* extension); 275201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch 276201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // Updates the |extension|'s granted permissions lists to include all 277201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // permissions in the |extension|'s manifest and re-enables the 278201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // extension. 279201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch void GrantPermissionsAndEnableExtension(const Extension* extension); 280201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch 281c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Load the extension from the directory |extension_path|. 282c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void LoadExtension(const FilePath& extension_path); 283c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 284c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Load any component extensions. 285c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void LoadComponentExtensions(); 286c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 287c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Load all known extensions (used by startup and testing code). 288c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void LoadAllExtensions(); 289c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 290c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Continues loading all know extensions. It can be called from 291c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // LoadAllExtensions or from file thread if we had to relocalize manifest 292c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // (write_to_prefs is true in that case). 293c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void ContinueLoadAllExtensions(ExtensionPrefs::ExtensionsInfo* info, 294c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch base::TimeTicks start_time, 295c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool write_to_prefs); 296c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 297c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Check for updates (or potentially new extensions from external providers) 298c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void CheckForExternalUpdates(); 299c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 300201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // Copies the list of force-installed extensions from the user PrefService 301201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // to ExternalPolicyExtensionProvider. 302201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch void UpdateExternalPolicyExtensionProvider(); 303201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch 304c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Unload the specified extension. 30521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen void UnloadExtension(const std::string& extension_id, 30621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen UnloadedExtensionInfo::Reason reason); 307c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 308c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Unload all extensions. This is currently only called on shutdown, and 309c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // does not send notifications. 310c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void UnloadAllExtensions(); 311c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 312c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Called only by testing. 313c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void ReloadExtensions(); 314c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 315c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Scan the extension directory and clean up the cruft. 316c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void GarbageCollectExtensions(); 317c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 318731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // The App that represents the web store. 319513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch const Extension* GetWebStoreApp(); 320731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick 321c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Lookup an extension by |url|. 322513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch const Extension* GetExtensionByURL(const GURL& url); 323c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 324c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // If there is an extension for the specified url it is returned. Otherwise 325c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // returns the extension whose web extent contains |url|. 326513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch const Extension* GetExtensionByWebExtent(const GURL& url); 327c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 328c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Returns an extension that contains any URL that overlaps with the given 329c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // extent, if one exists. 330513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch const Extension* GetExtensionByOverlappingWebExtent( 331513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch const ExtensionExtent& extent); 332c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 3333345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Returns true if |url| should get extension api bindings and be permitted 3343345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // to make api calls. Note that this is independent of what extension 3353345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // permissions the given extension has been granted. 3363345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick bool ExtensionBindingsAllowed(const GURL& url); 3373345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 338c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Returns the icon to display in the omnibox for the given extension. 339c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const SkBitmap& GetOmniboxIcon(const std::string& extension_id); 340c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 3413345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Returns the icon to display in the omnibox popup window for the given 3423345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // extension. 3433345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick const SkBitmap& GetOmniboxPopupIcon(const std::string& extension_id); 3443345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 345c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Clear all ExternalExtensionProviders. 346c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void ClearProvidersForTesting(); 347c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 348c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Sets an ExternalExtensionProvider for the service to use during testing. 349513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // Takes ownership of |test_provider|. 350513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch void AddProviderForTesting(ExternalExtensionProvider* test_provider); 351c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 352c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Called when the initial extensions load has completed. 353c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void OnLoadedInstalledExtensions(); 354c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 355c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Called when an extension has been loaded. 356201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch void OnExtensionLoaded(const Extension* extension); 357c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 358c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Called by the backend when an extension has been installed. 359201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch void OnExtensionInstalled(const Extension* extension); 360c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 361c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Called by the backend when an external extension is found. 3623345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick void OnExternalExtensionFileFound(const std::string& id, 3633345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick const std::string& version, 3643345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick const FilePath& path, 3653345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick Extension::Location location); 366c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 367201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // Checks if the privileges requested by |extension| have increased, and if 368201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // so, disables the extension and prompts the user to approve the change. 369201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch void DisableIfPrivilegeIncrease(const Extension* extension); 370201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch 371c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Go through each extensions in pref, unload blacklisted extensions 372c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // and update the blacklist state in pref. 373c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void UpdateExtensionBlacklist( 374c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const std::vector<std::string>& blacklist); 375c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 3763345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Go through each extension and unload those that the network admin has 3773345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // put on the blacklist (not to be confused with the Google managed blacklist 3783345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // set of extensions. 3793345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick virtual void CheckAdminBlacklist(); 3803345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 381c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; } 382c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool extensions_enabled() { return extensions_enabled_; } 383c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 384c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void set_show_extensions_prompts(bool enabled) { 385c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch show_extensions_prompts_ = enabled; 386c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 387c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 388c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool show_extensions_prompts() { 389c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch return show_extensions_prompts_; 390c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 391c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 392c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch Profile* profile() { return profile_; } 393c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 3943345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Profile calls this when it is being destroyed so that we know not to call 3953345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // it. 3963345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick void DestroyingProfile(); 397c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 39821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen virtual ExtensionPrefs* extension_prefs(); 399c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 400c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Whether the extension service is ready. 401201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // TODO(skerner): Get rid of this method. crbug.com/63756 402c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool is_ready() { return ready_; } 403c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 404c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Note that this may return NULL if autoupdate is not turned on. 405c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ExtensionUpdater* updater() { return updater_.get(); } 406c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 407c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ExtensionToolbarModel* toolbar_model() { return &toolbar_model_; } 408c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 409c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ExtensionsQuotaService* quota_service() { return "a_service_; } 410c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 411c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ExtensionMenuManager* menu_manager() { return &menu_manager_; } 412c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 4133345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick const std::map<GURL, int>& protected_storage_map() const { 4143345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick return protected_storage_map_; 4153345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick } 4163345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 417c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Notify the frontend that there was an error loading an extension. 41821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // This method is public because ExtensionServiceBackend can post to here. 419c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void ReportExtensionLoadError(const FilePath& extension_path, 420c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const std::string& error, 421c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch NotificationType type, 422c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool be_noisy); 423c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 4243345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // ExtensionHost of background page calls this method right after its render 4253345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // view has been created. 4263345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick void DidCreateRenderViewForBackgroundPage(ExtensionHost* host); 4273345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 428c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // NotificationObserver 429c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void Observe(NotificationType type, 430c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const NotificationSource& source, 431c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const NotificationDetails& details); 432c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 433731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // Whether there are any apps installed. Component apps are not included. 434731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick bool HasApps() const; 435731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick 436731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // Gets the set of loaded app ids. Component apps are not included. 437731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick ExtensionIdSet GetAppIds() const; 438c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 439c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private: 440731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick friend class BrowserThread; 44121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen friend class DeleteTask<ExtensionService>; 442c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 443513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // Contains Extension data that can change during the life of the process, 444513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // but does not persist across restarts. 445513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch struct ExtensionRuntimeData { 446513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // True if the background page is ready. 447513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch bool background_page_ready; 448513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch 449513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // True while the extension is being upgraded. 450513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch bool being_upgraded; 451513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch 452201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // Generic bag of runtime data that users can associate with extensions. 453201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch PropertyBag property_bag; 454201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch 455513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch ExtensionRuntimeData(); 456513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch ~ExtensionRuntimeData(); 457513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch }; 458513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap; 459513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch 46021d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen virtual ~ExtensionService(); 461513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch 462c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Clear all persistent data that may have been stored by the extension. 463c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void ClearExtensionData(const GURL& extension_url); 464c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 465c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Look up an extension by ID, optionally including either or both of enabled 466c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // and disabled extensions. 467513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch const Extension* GetExtensionByIdInternal(const std::string& id, 468513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch bool include_enabled, 469513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch bool include_disabled); 470c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 47121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // Like AddPendingExtension*() functions above, but assumes an 47221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // extension with the same id is not already installed. 473c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void AddPendingExtensionInternal( 474c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const std::string& id, const GURL& update_url, 47521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen ShouldInstallExtensionPredicate should_install_extension, 4763345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick bool is_from_sync, bool install_silently, 477731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick bool enable_on_install, bool enable_incognito_on_install, 478731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick Extension::Location install_source); 479c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 480c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Handles sending notification that |extension| was loaded. 481513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch void NotifyExtensionLoaded(const Extension* extension); 482c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 483c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Handles sending notification that |extension| was unloaded. 48421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen void NotifyExtensionUnloaded(const Extension* extension, 48521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen UnloadedExtensionInfo::Reason reason); 486c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 487c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Helper that updates the active extension list used for crash reporting. 488c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void UpdateActiveExtensionsInCrashReporter(); 489c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 490c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Helper method. Loads extension from prefs. 4913345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick void LoadInstalledExtension(const ExtensionInfo& info, bool write_to_prefs); 4923345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 4933345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Helper methods to configure the storage services accordingly. 494513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch void GrantProtectedStorage(const Extension* extension); 495513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch void RevokeProtectedStorage(const Extension* extension); 496513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch void GrantUnlimitedStorage(const Extension* extension); 497513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch void RevokeUnlimitedStorage(const Extension* extension); 498c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 49921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // The profile this ExtensionService is part of. 500c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch Profile* profile_; 501c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 50221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen // Preferences for the owning profile (weak reference). 50321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen ExtensionPrefs* extension_prefs_; 504c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 505c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The current list of installed extensions. 506c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ExtensionList extensions_; 507c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 508c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The list of installed extensions that have been disabled. 509c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ExtensionList disabled_extensions_; 510c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 511c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The set of pending extensions. 512c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch PendingExtensionMap pending_extensions_; 513c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 514513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch // The map of extension IDs to their runtime data. 515513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch ExtensionRuntimeDataMap extension_runtime_data_; 516513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch 517c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The full path to the directory where extensions are installed. 518c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch FilePath install_directory_; 519c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 520c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Whether or not extensions are enabled. 521c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool extensions_enabled_; 522c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 523c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Whether to notify users when they attempt to install an extension. 524c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool show_extensions_prompts_; 525c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 526c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The backend that will do IO on behalf of this instance. 52721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen scoped_refptr<ExtensionServiceBackend> backend_; 528c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 529c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Used by dispatchers to limit API quota for individual extensions. 530c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ExtensionsQuotaService quota_service_; 531c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 532201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // Record that Init() has been called, and NotificationType::EXTENSIONS_READY 533201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch // has fired. 534c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool ready_; 535c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 536c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Our extension updater, if updates are turned on. 537c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch scoped_refptr<ExtensionUpdater> updater_; 538c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 539c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The model that tracks extensions with BrowserAction buttons. 540c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ExtensionToolbarModel toolbar_model_; 541c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 542c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Map unloaded extensions' ids to their paths. When a temporarily loaded 543c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // extension is unloaded, we lose the infomation about it and don't have 544c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // any in the extension preferences file. 545c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch typedef std::map<std::string, FilePath> UnloadedExtensionPathMap; 546c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch UnloadedExtensionPathMap unloaded_extension_paths_; 547c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 5483345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Map disabled extensions' ids to their paths. When a temporarily loaded 5493345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // extension is disabled before it is reloaded, keep track of the path so that 5503345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // it can be re-enabled upon a successful load. 5513345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick typedef std::map<std::string, FilePath> DisabledExtensionPathMap; 5523345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick DisabledExtensionPathMap disabled_extension_paths_; 5533345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 554c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Map of inspector cookies that are detached, waiting for an extension to be 555c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // reloaded. 556c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch typedef std::map<std::string, int> OrphanedDevTools; 557c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch OrphanedDevTools orphaned_dev_tools_; 558c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 559c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch NotificationRegistrar registrar_; 5603345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick PrefChangeRegistrar pref_change_registrar_; 561c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 562c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Keeps track of menu items added by extensions. 563c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ExtensionMenuManager menu_manager_; 564c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 565c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Keeps track of favicon-sized omnibox icons for extensions. 566c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ExtensionIconManager omnibox_icon_manager_; 5673345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick ExtensionIconManager omnibox_popup_icon_manager_; 568c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 569c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // List of registered component extensions (see Extension::Location). 570c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; 571c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch RegisteredComponentExtensions component_extension_manifests_; 572c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 5733345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Collection of origins we've granted unlimited storage to. This is a 5743345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // map from origin to the number of extensions requiring unlimited 5753345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // storage within that origin. 5763345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick typedef std::map<GURL, int> UnlimitedStorageMap; 5773345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick UnlimitedStorageMap unlimited_storage_map_; 5783345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 5793345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Collection of origins whose storage is protected by "Clear browsing data." 5803345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // A map from origin to the number of Apps currently installed and therefore 5813345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // intrinsically protected. 5823345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick typedef std::map<GURL, int> ProtectedStorageMap; 5833345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick ProtectedStorageMap protected_storage_map_; 5843345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 585731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // Manages the installation of default apps and the promotion of them in the 586731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // app launcher. 587731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick DefaultApps default_apps_; 588731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick 589731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // Flag to make sure event routers are only initialized once. 590731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick bool event_routers_initialized_; 591731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick 59221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 593c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch UpdatePendingExtensionAlreadyInstalled); 59421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 5953345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick InstallAppsWithUnlimtedStorage); 59621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 5973345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick InstallAppsAndCheckStorageProtection); 59821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen DISALLOW_COPY_AND_ASSIGN(ExtensionService); 599c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 600c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 60121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 602