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_EXTENSION_SERVICE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 7 8 #include <map> 9 #include <memory> 10 #include <set> 11 #include <string> 12 #include <vector> 13 14 #include "base/compiler_specific.h" 15 #include "base/files/file_path.h" 16 #include "base/gtest_prod_util.h" 17 #include "base/macros.h" 18 #include "base/memory/ref_counted.h" 19 #include "base/memory/weak_ptr.h" 20 #include "base/optional.h" 21 #include "base/scoped_observer.h" 22 #include "base/strings/string16.h" 23 #include "chrome/browser/extensions/blocklist.h" 24 #include "chrome/browser/extensions/extension_management.h" 25 #include "chrome/browser/extensions/forced_extensions/force_installed_metrics.h" 26 #include "chrome/browser/extensions/forced_extensions/force_installed_tracker.h" 27 #include "chrome/browser/extensions/install_gate.h" 28 #include "chrome/browser/extensions/pending_extension_manager.h" 29 #include "chrome/browser/profiles/profile_manager.h" 30 #include "chrome/browser/profiles/profile_manager_observer.h" 31 #include "chrome/browser/upgrade_detector/upgrade_observer.h" 32 #include "components/sync/model/string_ordinal.h" 33 #include "content/public/browser/notification_observer.h" 34 #include "content/public/browser/notification_registrar.h" 35 #include "extensions/browser/api/declarative_net_request/ruleset_install_pref.h" 36 #include "extensions/browser/crx_file_info.h" 37 #include "extensions/browser/disable_reason.h" 38 #include "extensions/browser/extension_prefs.h" 39 #include "extensions/browser/extension_registrar.h" 40 #include "extensions/browser/external_provider_interface.h" 41 #include "extensions/browser/install_flag.h" 42 #include "extensions/browser/process_manager.h" 43 #include "extensions/browser/uninstall_reason.h" 44 #include "extensions/buildflags/buildflags.h" 45 #include "extensions/common/extension.h" 46 #include "extensions/common/extension_id.h" 47 #include "extensions/common/extension_set.h" 48 #include "extensions/common/manifest.h" 49 50 #if !BUILDFLAG(ENABLE_EXTENSIONS) 51 #error "Extensions must be enabled" 52 #endif 53 54 class BlocklistedExtensionSyncServiceTest; 55 class HostContentSettingsMap; 56 class Profile; 57 58 namespace base { 59 class CommandLine; 60 class OneShotEvent; 61 } // namespace base 62 63 FORWARD_DECLARE_TEST(BlocklistedExtensionSyncServiceTest, 64 SyncBlocklistedExtension); 65 66 namespace extensions { 67 class ComponentLoader; 68 class CrxInstaller; 69 class ExtensionActionStorageManager; 70 class ExtensionErrorController; 71 class ExtensionRegistry; 72 class ExtensionSystem; 73 class ExtensionUpdater; 74 class ExternalInstallManager; 75 class SharedModuleService; 76 class UpdateObserver; 77 enum class UnloadedExtensionReason; 78 79 // These values are logged to UMA. Entries should not be renumbered and 80 // numeric values should never be reused. Please keep in sync with 81 // "ExtensionUpdateCheckDataKey" in src/tools/metrics/histograms/enums.xml. 82 enum class ExtensionUpdateCheckDataKey { 83 // No update check data keys were found so no action was taken. 84 kNoKey = 0, 85 // The update check daya keys had a "_malware" key resulting in the extension 86 // being disabled. 87 kMalware = 1, 88 kMaxValue = kMalware 89 }; 90 91 // This is an interface class to encapsulate the dependencies that 92 // various classes have on ExtensionService. This allows easy mocking. 93 class ExtensionServiceInterface 94 : public base::SupportsWeakPtr<ExtensionServiceInterface> { 95 public: ~ExtensionServiceInterface()96 virtual ~ExtensionServiceInterface() {} 97 98 // Gets the object managing the set of pending extensions. 99 virtual PendingExtensionManager* pending_extension_manager() = 0; 100 101 // Installs an update with the contents from |extension_path|. Returns true if 102 // the install can be started. Sets |out_crx_installer| to the installer if 103 // one was started. 104 // TODO(aa): This method can be removed. ExtensionUpdater could use 105 // CrxInstaller directly instead. 106 virtual bool UpdateExtension(const CRXFileInfo& file, 107 bool file_ownership_passed, 108 CrxInstaller** out_crx_installer) = 0; 109 110 // Returns an update for an extension with the specified id, if installation 111 // of that update was previously delayed because the extension was in use. If 112 // no updates are pending for the extension returns NULL. 113 virtual const Extension* GetPendingExtensionUpdate( 114 const std::string& extension_id) const = 0; 115 116 // Attempts finishing installation of an update for an extension with the 117 // specified id, when installation of that extension was previously delayed. 118 // |install_immediately| - Whether the extension should be installed if it's 119 // currently in use. 120 // Returns whether the extension installation was finished. 121 virtual bool FinishDelayedInstallationIfReady(const std::string& extension_id, 122 bool install_immediately) = 0; 123 124 // Returns true if the extension with the given |extension_id| is enabled. 125 // This will only return a valid answer for installed extensions (regardless 126 // of whether it is currently loaded or not). Loaded extensions return true 127 // if they are currently loaded or terminated. Unloaded extensions will 128 // return true if they are not blocked, disabled, blocklisted or uninstalled 129 // (for external extensions). 130 virtual bool IsExtensionEnabled(const std::string& extension_id) const = 0; 131 132 // Go through each extension and unload those that are not allowed to run by 133 // management policy providers (ie. network admin and Google-managed 134 // blocklist). 135 virtual void CheckManagementPolicy() = 0; 136 137 // Safe to call multiple times in a row. 138 // 139 // TODO(akalin): Remove this method (and others) once we refactor 140 // themes sync to not use it directly. 141 virtual void CheckForUpdatesSoon() = 0; 142 143 // Adds |extension| to this ExtensionService and notifies observers that the 144 // extension has been loaded. 145 virtual void AddExtension(const Extension* extension) = 0; 146 147 // Check if we have preferences for the component extension and, if not or if 148 // the stored version differs, install the extension (without requirements 149 // checking) before calling AddExtension. 150 virtual void AddComponentExtension(const Extension* extension) = 0; 151 152 // Unload the specified extension. 153 virtual void UnloadExtension(const std::string& extension_id, 154 UnloadedExtensionReason reason) = 0; 155 156 // Remove the specified component extension. 157 virtual void RemoveComponentExtension(const std::string& extension_id) = 0; 158 159 // Whether a user is able to disable a given extension. 160 virtual bool UserCanDisableInstalledExtension( 161 const std::string& extension_id) = 0; 162 }; 163 164 // Manages installed and running Chromium extensions. An instance is shared 165 // between normal and incognito profiles. 166 class ExtensionService : public ExtensionServiceInterface, 167 public ExternalProviderInterface::VisitorInterface, 168 public content::NotificationObserver, 169 public Blocklist::Observer, 170 public ExtensionManagement::Observer, 171 public UpgradeObserver, 172 public ExtensionRegistrar::Delegate, 173 public ProfileManagerObserver { 174 public: 175 // Constructor stores pointers to |profile| and |extension_prefs| but 176 // ownership remains at caller. 177 ExtensionService(Profile* profile, 178 const base::CommandLine* command_line, 179 const base::FilePath& install_directory, 180 ExtensionPrefs* extension_prefs, 181 Blocklist* blocklist, 182 bool autoupdate_enabled, 183 bool extensions_enabled, 184 base::OneShotEvent* ready); 185 186 ~ExtensionService() override; 187 188 // ExtensionServiceInterface implementation. 189 // 190 PendingExtensionManager* pending_extension_manager() override; 191 bool UpdateExtension(const CRXFileInfo& file, 192 bool file_ownership_passed, 193 CrxInstaller** out_crx_installer) override; 194 bool IsExtensionEnabled(const std::string& extension_id) const override; 195 void UnloadExtension(const std::string& extension_id, 196 UnloadedExtensionReason reason) override; 197 void RemoveComponentExtension(const std::string& extension_id) override; 198 void AddExtension(const Extension* extension) override; 199 void AddComponentExtension(const Extension* extension) override; 200 const Extension* GetPendingExtensionUpdate( 201 const std::string& extension_id) const override; 202 bool FinishDelayedInstallationIfReady(const std::string& extension_id, 203 bool install_immediately) override; 204 void CheckManagementPolicy() override; 205 void CheckForUpdatesSoon() override; 206 207 // ExternalProvider::VisitorInterface implementation. 208 // Exposed for testing. 209 bool OnExternalExtensionFileFound( 210 const ExternalInstallInfoFile& info) override; 211 bool OnExternalExtensionUpdateUrlFound( 212 const ExternalInstallInfoUpdateUrl& info, 213 bool is_initial_load) override; 214 void OnExternalProviderReady( 215 const ExternalProviderInterface* provider) override; 216 void OnExternalProviderUpdateComplete( 217 const ExternalProviderInterface* provider, 218 const std::vector<ExternalInstallInfoUpdateUrl>& 219 external_update_url_extensions, 220 const std::vector<ExternalInstallInfoFile>& external_file_extensions, 221 const std::set<std::string>& removed_extensions) override; 222 223 // ExtensionManagement::Observer implementation: 224 void OnExtensionManagementSettingsChanged() override; 225 226 // Initialize and start all installed extensions. 227 void Init(); 228 229 // Called when the associated Profile is going to be destroyed. 230 void Shutdown(); 231 232 // Called when reloading an unpacked extension fails. 233 void OnUnpackedReloadFailure(const Extension* extension, 234 const base::FilePath& file_path, 235 const std::string& error); 236 237 // Reloads the specified extension, sending the onLaunched() event to it if it 238 // currently has any window showing. 239 // Allows noisy failures. 240 // NOTE: Reloading an extension can invalidate |extension_id| and Extension 241 // pointers for the given extension. Consider making a copy of |extension_id| 242 // first and retrieving a new Extension pointer afterwards. 243 void ReloadExtension(const std::string& extension_id); 244 245 // Suppresses noisy failures. 246 void ReloadExtensionWithQuietFailure(const std::string& extension_id); 247 248 // Uninstalls the specified extension. Callers should only call this method 249 // with extensions that exist. |reason| lets the caller specify why the 250 // extension is uninstalled. 251 // Note: this method synchronously removes the extension from the 252 // set of installed extensions stored in the ExtensionRegistry, but will 253 // asynchronously remove site-related data and the files stored on disk. 254 // Returns true if an uninstall was successfully triggered; this can fail if 255 // the extension cannot be uninstalled (such as a policy force-installed 256 // extension). 257 bool UninstallExtension(const std::string& extension_id, 258 UninstallReason reason, 259 base::string16* error); 260 261 // Enables the extension. If the extension is already enabled, does 262 // nothing. 263 void EnableExtension(const std::string& extension_id); 264 265 // Performs action based on Omaha attributes for the extension. 266 void PerformActionBasedOnOmahaAttributes(const std::string& extension_id, 267 const base::Value& attributes); 268 269 // Disables the extension. If the extension is already disabled, just adds 270 // the |disable_reasons| (a bitmask of disable_reason::DisableReason - there 271 // can be multiple DisableReasons e.g. when an extension comes in disabled 272 // from Sync). If the extension cannot be disabled (due to policy), does 273 // nothing. 274 void DisableExtension(const std::string& extension_id, int disable_reasons); 275 276 // Same as |DisableExtension|, but assumes that the request to disable 277 // |extension_id| originates from |source_extension| when evaluating whether 278 // the extension can be disabled. Please see |ExtensionMayModifySettings| 279 // for details. 280 void DisableExtensionWithSource( 281 const Extension* source_extension, 282 const std::string& extension_id, 283 disable_reason::DisableReason disable_reasons); 284 285 // Disable non-default and non-managed extensions with ids not in 286 // |except_ids|. Default extensions are those from the Web Store with 287 // |was_installed_by_default| flag. 288 void DisableUserExtensionsExcept(const std::vector<std::string>& except_ids); 289 290 // Puts all extensions in a blocked state: Unloading every extension, and 291 // preventing them from ever loading until UnblockAllExtensions is called. 292 // This state is stored in preferences, so persists until Chrome restarts. 293 // 294 // Component, external component and allowlisted policy installed extensions 295 // are exempt from being Blocked (see CanBlockExtension in .cc file). 296 void BlockAllExtensions(); 297 298 // All blocked extensions are reverted to their previous state, and are 299 // reloaded. Newly added extensions are no longer automatically blocked. 300 void UnblockAllExtensions(); 301 302 // Updates the |extension|'s granted permissions lists to include all 303 // permissions in the |extension|'s manifest and re-enables the 304 // extension. 305 void GrantPermissionsAndEnableExtension(const Extension* extension); 306 307 // Updates the |extension|'s granted permissions lists to include all 308 // permissions in the |extensions|'s manifest. 309 void GrantPermissions(const Extension* extension); 310 311 // Check for updates (or potentially new extensions from external providers) 312 void CheckForExternalUpdates(); 313 314 // Informs the service that an extension's files are in place for loading. 315 // 316 // |extension| the extension 317 // |page_ordinal| the location of the extension in the app 318 // launcher 319 // |install_flags| a bitmask of InstallFlags 320 // |ruleset_install_prefs| Install prefs needed for the Declarative Net 321 // Request API. 322 void OnExtensionInstalled(const Extension* extension, 323 const syncer::StringOrdinal& page_ordinal, 324 int install_flags, 325 const declarative_net_request::RulesetInstallPrefs& 326 ruleset_install_prefs = {}); OnExtensionInstalled(const Extension * extension,const syncer::StringOrdinal & page_ordinal)327 void OnExtensionInstalled(const Extension* extension, 328 const syncer::StringOrdinal& page_ordinal) { 329 OnExtensionInstalled(extension, page_ordinal, 330 static_cast<int>(kInstallFlagNone)); 331 } 332 333 // Checks for delayed installation for all pending installs. 334 void MaybeFinishDelayedInstallations(); 335 336 // ExtensionHost of background page calls this method right after its render 337 // view has been created. 338 void DidCreateRenderViewForBackgroundPage(ExtensionHost* host); 339 340 // Record a histogram using the PermissionMessage enum values for each 341 // permission in |e|. 342 // NOTE: If this is ever called with high frequency, the implementation may 343 // need to be made more efficient. 344 static void RecordPermissionMessagesHistogram(const Extension* extension, 345 const char* histogram); 346 347 // Unloads the given extension and marks the extension as terminated. This 348 // doesn't notify the user that the extension was terminated, if such a 349 // notification is desired the calling code is responsible for doing that. 350 void TerminateExtension(const std::string& extension_id); 351 352 // Register self and content settings API with the specified map. 353 static void RegisterContentSettings( 354 HostContentSettingsMap* host_content_settings_map, 355 Profile* profile); 356 357 // Adds/Removes update observers. 358 void AddUpdateObserver(UpdateObserver* observer); 359 void RemoveUpdateObserver(UpdateObserver* observer); 360 361 // Register/unregister an InstallGate with the service. 362 void RegisterInstallGate(ExtensionPrefs::DelayReason reason, 363 InstallGate* install_delayer); 364 void UnregisterInstallGate(InstallGate* install_delayer); 365 366 // Returns whether a user is able to disable a given extension or if that is 367 // not possible (for instance, extension was enabled by policy). 368 bool UserCanDisableInstalledExtension( 369 const std::string& extension_id) override; 370 371 ////////////////////////////////////////////////////////////////////////////// 372 // Simple Accessors 373 374 // Returns a WeakPtr to the ExtensionService. AsWeakPtr()375 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); } 376 377 // Returns profile_ as a BrowserContext. 378 content::BrowserContext* GetBrowserContext() const; 379 extensions_enabled()380 bool extensions_enabled() const { return extensions_enabled_; } 381 install_directory()382 const base::FilePath& install_directory() const { return install_directory_; } 383 delayed_installs()384 const ExtensionSet* delayed_installs() const { return &delayed_installs_; } 385 profile()386 Profile* profile() { return profile_; } 387 388 // Note that this may return NULL if autoupdate is not turned on. updater()389 ExtensionUpdater* updater() { return updater_.get(); } 390 component_loader()391 ComponentLoader* component_loader() { return component_loader_.get(); } 392 browser_terminating()393 bool browser_terminating() const { return browser_terminating_; } 394 shared_module_service()395 SharedModuleService* shared_module_service() { 396 return shared_module_service_.get(); 397 } 398 external_install_manager()399 ExternalInstallManager* external_install_manager() { 400 return external_install_manager_.get(); 401 } 402 force_installed_tracker()403 ForceInstalledTracker* force_installed_tracker() { 404 return &force_installed_tracker_; 405 } 406 407 ////////////////////////////////////////////////////////////////////////////// 408 // For Testing 409 410 // Unload all extensions. Does not send notifications. 411 void UnloadAllExtensionsForTest(); 412 413 // Reloads all extensions. Does not notify that extensions are ready. 414 void ReloadExtensionsForTest(); 415 416 // Clear all ExternalProviders. 417 void ClearProvidersForTesting(); 418 419 // Adds an ExternalProviderInterface for the service to use during testing. 420 void AddProviderForTesting( 421 std::unique_ptr<ExternalProviderInterface> test_provider); 422 423 // Simulate an extension being blocklisted for tests. 424 void BlocklistExtensionForTest(const std::string& extension_id); 425 426 #if defined(UNIT_TEST) FinishInstallationForTest(const Extension * extension)427 void FinishInstallationForTest(const Extension* extension) { 428 FinishInstallation(extension); 429 } 430 UninstallMigratedExtensionsForTest()431 void UninstallMigratedExtensionsForTest() { UninstallMigratedExtensions(); } 432 #endif 433 set_browser_terminating_for_test(bool value)434 void set_browser_terminating_for_test(bool value) { 435 browser_terminating_ = value; 436 } 437 438 // Set a callback to be called when all external providers are ready and their 439 // extensions have been installed. set_external_updates_finished_callback_for_test(const base::Closure & callback)440 void set_external_updates_finished_callback_for_test( 441 const base::Closure& callback) { 442 external_updates_finished_callback_ = callback; 443 } 444 445 // While disabled all calls to CheckForExternalUpdates() will bail out. 446 static base::AutoReset<bool> DisableExternalUpdatesForTesting(); 447 448 private: 449 // Loads extensions specified via a command line flag/switch. 450 void LoadExtensionsFromCommandLineFlag(const char* switch_name); 451 #if defined(OS_CHROMEOS) 452 void LoadSigninProfileTestExtension(const std::string& path); 453 #endif 454 455 // content::NotificationObserver implementation: 456 void Observe(int type, 457 const content::NotificationSource& source, 458 const content::NotificationDetails& details) override; 459 460 // Blocklist::Observer implementation. 461 void OnBlocklistUpdated() override; 462 463 // UpgradeObserver implementation. 464 void OnUpgradeRecommended() override; 465 466 // ExtensionRegistrar::Delegate implementation. 467 void PreAddExtension(const Extension* extension, 468 const Extension* old_extension) override; 469 void PostActivateExtension(scoped_refptr<const Extension> extension) override; 470 void PostDeactivateExtension( 471 scoped_refptr<const Extension> extension) override; 472 void LoadExtensionForReload( 473 const ExtensionId& extension_id, 474 const base::FilePath& path, 475 ExtensionRegistrar::LoadErrorBehavior load_error_behavior) override; 476 bool CanEnableExtension(const Extension* extension) override; 477 bool CanDisableExtension(const Extension* extension) override; 478 bool ShouldBlockExtension(const Extension* extension) override; 479 480 // ProfileManagerObserver implementation. 481 void OnProfileMarkedForPermanentDeletion(Profile* profile) override; 482 483 // For the extension in |version_path| with |id|, check to see if it's an 484 // externally managed extension. If so, uninstall it. 485 void CheckExternalUninstall(const std::string& id); 486 487 // Attempt to enable all disabled extensions which the only disabled reason is 488 // reloading. 489 void EnabledReloadableExtensions(); 490 491 // Finish install (if possible) of extensions that were still delayed while 492 // the browser was shut down. 493 void MaybeFinishShutdownDelayed(); 494 495 // Populates greylist_. 496 void LoadGreylistFromPrefs(); 497 498 // Signals *ready_ and sends a notification to the listeners. 499 void SetReadyAndNotifyListeners(); 500 501 // Returns true if all the external extension providers are ready. 502 bool AreAllExternalProvidersReady() const; 503 504 // Called once all external providers are ready. Checks for unclaimed 505 // external extensions. 506 void OnAllExternalProvidersReady(); 507 508 // Update preferences for a new or updated extension; notify observers that 509 // the extension is installed, e.g., to update event handlers on background 510 // pages; and perform other extension install tasks before calling 511 // AddExtension. 512 // |install_flags| is a bitmask of InstallFlags. 513 void AddNewOrUpdatedExtension( 514 const Extension* extension, 515 Extension::State initial_state, 516 int install_flags, 517 const syncer::StringOrdinal& page_ordinal, 518 const std::string& install_parameter, 519 const declarative_net_request::RulesetInstallPrefs& 520 ruleset_install_prefs); 521 522 // Common helper to finish installing the given extension. 523 void FinishInstallation(const Extension* extension); 524 525 // Sets the policy settings for the extension basically 526 // by delegating this to the permission_data_updater. 527 // Holds for default and policy settings. 528 void SetPolicySettingsForExtension(const Extension* extension); 529 530 // Disables the extension if the privilege level has increased 531 // (e.g., due to an upgrade). 532 void CheckPermissionsIncrease(const Extension* extension, 533 bool is_extension_loaded); 534 535 // Helper that updates the active extension list used for crash reporting. 536 void UpdateActiveExtensionsInCrashReporter(); 537 538 // Helper to get the disable reasons for an installed (or upgraded) extension. 539 // A return value of disable_reason::DISABLE_NONE indicates that we should 540 // enable this extension initially. 541 int GetDisableReasonsOnInstalled(const Extension* extension); 542 543 // Helper method to determine if an extension can be blocked. 544 bool CanBlockExtension(const Extension* extension) const; 545 546 // Enables an extension that was only previously disabled remotely. 547 void MaybeEnableRemotelyDisabledExtension(const std::string& extension_id); 548 549 // Helper to determine if installing an extensions should proceed immediately, 550 // or if we should delay the install until further notice, or if the install 551 // should be aborted. A pending install is delayed or aborted when any of the 552 // delayers say so and only proceeds when all delayers return INSTALL. 553 // |extension| is the extension to be installed. |install_immediately| is the 554 // install flag set with the install. |reason| is the reason associated with 555 // the install delayer that wants to defer or abort the install. 556 InstallGate::Action ShouldDelayExtensionInstall( 557 const Extension* extension, 558 bool install_immediately, 559 ExtensionPrefs::DelayReason* reason) const; 560 561 // Manages the blocklisted extensions, intended as callback from 562 // Blocklist::GetBlocklistedIDs. 563 void ManageBlocklist(const Blocklist::BlocklistStateMap& blocklisted_ids); 564 565 // Add extensions in |blocklisted| to blocklisted_extensions, remove 566 // extensions that are neither in |blocklisted|, nor in |unchanged|. 567 void UpdateBlocklistedExtensions(const ExtensionIdSet& to_blocklist, 568 const ExtensionIdSet& unchanged); 569 570 void UpdateGreylistedExtensions( 571 const ExtensionIdSet& greylist, 572 const ExtensionIdSet& unchanged, 573 const Blocklist::BlocklistStateMap& state_map); 574 575 // Used only by test code. 576 void UnloadAllExtensionsInternal(); 577 578 // Disable apps & extensions now to stop them from running after a profile 579 // has been conceptually deleted. Don't wait for full browser shutdown and 580 // the actual profile objects to be destroyed. 581 void OnProfileDestructionStarted(); 582 583 // Called on file task runner thread to uninstall extension. 584 static void UninstallExtensionOnFileThread( 585 const std::string& id, 586 Profile* profile, 587 const base::FilePath& install_dir, 588 const base::FilePath& extension_path); 589 590 // Called when the initial extensions load has completed. 591 void OnInstalledExtensionsLoaded(); 592 593 // Uninstall extensions that have been migrated to component extensions. 594 void UninstallMigratedExtensions(); 595 596 const base::CommandLine* command_line_ = nullptr; 597 598 // The normal profile associated with this ExtensionService. 599 Profile* profile_ = nullptr; 600 601 // The ExtensionSystem for the profile above. 602 ExtensionSystem* system_ = nullptr; 603 604 // Preferences for the owning profile. 605 ExtensionPrefs* extension_prefs_ = nullptr; 606 607 // Blocklist for the owning profile. 608 Blocklist* blocklist_ = nullptr; 609 610 // Sets of enabled/disabled/terminated/blocklisted extensions. Not owned. 611 ExtensionRegistry* registry_ = nullptr; 612 613 // Set of greylisted extensions. These extensions are disabled if they are 614 // already installed in Chromium at the time when they are added to 615 // the greylist. Unlike blocklisted extensions, greylisted ones are visible 616 // to the user and if user re-enables such an extension, they remain enabled. 617 // 618 // These extensions should appear in registry_. 619 ExtensionSet greylist_; 620 621 // Set of allowlisted enabled extensions loaded from the 622 // --disable-extensions-except command line flag. 623 std::set<std::string> disable_flag_exempted_extensions_; 624 625 // The list of extension installs delayed for various reasons. The reason 626 // for delayed install is stored in ExtensionPrefs. These are not part of 627 // ExtensionRegistry because they are not yet installed. 628 ExtensionSet delayed_installs_; 629 630 // Hold the set of pending extensions. 631 PendingExtensionManager pending_extension_manager_; 632 633 // The full path to the directory where extensions are installed. 634 base::FilePath install_directory_; 635 636 // Whether or not extensions are enabled. 637 bool extensions_enabled_ = true; 638 639 // Signaled when all extensions are loaded. 640 base::OneShotEvent* const ready_; 641 642 // Our extension updater, if updates are turned on. 643 std::unique_ptr<ExtensionUpdater> updater_; 644 645 content::NotificationRegistrar registrar_; 646 647 // Keeps track of loading and unloading component extensions. 648 std::unique_ptr<ComponentLoader> component_loader_; 649 650 // A collection of external extension providers. Each provider reads 651 // a source of external extension information. Examples include the 652 // windows registry and external_extensions.json. 653 ProviderCollection external_extension_providers_; 654 655 // Set to true by OnExternalExtensionUpdateUrlFound() when an external 656 // extension URL is found, and by CheckForUpdatesSoon() when an update check 657 // has to wait for the external providers. Used in 658 // OnAllExternalProvidersReady() to determine if an update check is needed to 659 // install pending extensions. 660 bool update_once_all_providers_are_ready_ = false; 661 662 // A callback to be called when all external providers are ready and their 663 // extensions have been installed. This happens on initial load and whenever 664 // a new entry is found. Normally this is a null callback, but is used in 665 // external provider related tests. 666 // TODO(mxnguyen): Change |external_updates_finished_callback_| to 667 // OnceClosure. 668 base::Closure external_updates_finished_callback_; 669 670 // Set when the browser is terminating. Prevents us from installing or 671 // updating additional extensions and allows in-progress installations to 672 // decide to abort. 673 bool browser_terminating_ = false; 674 675 // Set to true if this is the first time this ExtensionService has run. 676 // Used for specially handling external extensions that are installed the 677 // first time. 678 bool is_first_run_ = false; 679 680 // Set to true if extensions are all to be blocked. 681 bool block_extensions_ = false; 682 683 // The controller for the UI that alerts the user about any blocklisted 684 // extensions. 685 std::unique_ptr<ExtensionErrorController> error_controller_; 686 687 // The manager for extensions that were externally installed that is 688 // responsible for prompting the user about suspicious extensions. 689 std::unique_ptr<ExternalInstallManager> external_install_manager_; 690 691 std::unique_ptr<ExtensionActionStorageManager> 692 extension_action_storage_manager_; 693 694 // The SharedModuleService used to check for import dependencies. 695 std::unique_ptr<SharedModuleService> shared_module_service_; 696 697 base::ObserverList<UpdateObserver, true>::Unchecked update_observers_; 698 699 // Helper to register and unregister extensions. 700 ExtensionRegistrar extension_registrar_; 701 702 // Tracker of enterprise policy forced installation. 703 ForceInstalledTracker force_installed_tracker_; 704 705 // Reports force-installed extension metrics to UMA. 706 ForceInstalledMetrics force_installed_metrics_; 707 708 ScopedObserver<ProfileManager, ProfileManagerObserver> 709 profile_manager_observer_{this}; 710 711 using InstallGateRegistry = 712 std::map<ExtensionPrefs::DelayReason, InstallGate*>; 713 InstallGateRegistry install_delayer_registry_; 714 715 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 716 DestroyingProfileClearsExtensions); 717 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlocklistInPrefs); 718 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, NoUnsetBlocklistInPrefs); 719 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 720 BlocklistedExtensionWillNotInstall); 721 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 722 UnloadBlocklistedExtensionPolicy); 723 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 724 WillNotLoadBlocklistedExtensionsFromDirectory); 725 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, ReloadBlocklistedExtension); 726 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, RemoveExtensionFromBlocklist); 727 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, BlocklistedInPrefsFromStartup); 728 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, GreylistedExtensionDisabled); 729 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 730 GreylistDontEnableManuallyDisabled); 731 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, GreylistUnknownDontChange); 732 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 733 ManagementPolicyProhibitsEnableOnInstalled); 734 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 735 BlockAndUnblockBlocklistedExtension); 736 FRIEND_TEST_ALL_PREFIXES(::BlocklistedExtensionSyncServiceTest, 737 SyncBlocklistedExtension); 738 friend class ::BlocklistedExtensionSyncServiceTest; 739 740 DISALLOW_COPY_AND_ASSIGN(ExtensionService); 741 }; 742 743 } // namespace extensions 744 745 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 746