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

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 9370013: Simplify the handling of crashed 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 393 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
394 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 394 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
395 395
396 // Figure out if extension installation should be enabled. 396 // Figure out if extension installation should be enabled.
397 if (command_line->HasSwitch(switches::kDisableExtensions)) { 397 if (command_line->HasSwitch(switches::kDisableExtensions)) {
398 extensions_enabled_ = false; 398 extensions_enabled_ = false;
399 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { 399 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) {
400 extensions_enabled_ = false; 400 extensions_enabled_ = false;
401 } 401 }
402 402
403 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
404 content::NotificationService::AllBrowserContextsAndSources());
405 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, 403 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
406 content::NotificationService::AllBrowserContextsAndSources()); 404 content::NotificationService::AllBrowserContextsAndSources());
407 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 405 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
408 content::NotificationService::AllBrowserContextsAndSources()); 406 content::NotificationService::AllBrowserContextsAndSources());
409 pref_change_registrar_.Init(profile->GetPrefs()); 407 pref_change_registrar_.Init(profile->GetPrefs());
410 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this); 408 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this);
411 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this); 409 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this);
412 410
413 // Set up the ExtensionUpdater 411 // Set up the ExtensionUpdater
414 if (autoupdate_enabled) { 412 if (autoupdate_enabled) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 450 }
453 451
454 const ExtensionSet* ExtensionService::extensions() const { 452 const ExtensionSet* ExtensionService::extensions() const {
455 return &extensions_; 453 return &extensions_;
456 } 454 }
457 455
458 const ExtensionSet* ExtensionService::disabled_extensions() const { 456 const ExtensionSet* ExtensionService::disabled_extensions() const {
459 return &disabled_extensions_; 457 return &disabled_extensions_;
460 } 458 }
461 459
462 const ExtensionSet* ExtensionService::terminated_extensions() const {
463 return &terminated_extensions_;
464 }
465
466 const ExtensionSet* ExtensionService::GenerateInstalledExtensionsSet() const { 460 const ExtensionSet* ExtensionService::GenerateInstalledExtensionsSet() const {
467 ExtensionSet* installed_extensions = new ExtensionSet(); 461 ExtensionSet* installed_extensions = new ExtensionSet();
468 installed_extensions->InsertAll(extensions_); 462 installed_extensions->InsertAll(extensions_);
469 installed_extensions->InsertAll(disabled_extensions_); 463 installed_extensions->InsertAll(disabled_extensions_);
470 installed_extensions->InsertAll(terminated_extensions_);
471 return installed_extensions; 464 return installed_extensions;
472 } 465 }
473 466
474 PendingExtensionManager* ExtensionService::pending_extension_manager() { 467 PendingExtensionManager* ExtensionService::pending_extension_manager() {
475 return &pending_extension_manager_; 468 return &pending_extension_manager_;
476 } 469 }
477 470
478 ExtensionService::~ExtensionService() { 471 ExtensionService::~ExtensionService() {
479 // No need to unload extensions here because they are profile-scoped, and the 472 // No need to unload extensions here because they are profile-scoped, and the
480 // profile is in the process of being deleted. 473 // profile is in the process of being deleted.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 550
558 #if defined(OS_CHROMEOS) && defined(USE_VIRTUAL_KEYBOARD) 551 #if defined(OS_CHROMEOS) && defined(USE_VIRTUAL_KEYBOARD)
559 ExtensionInputUiEventRouter::GetInstance()->Init(); 552 ExtensionInputUiEventRouter::GetInstance()->Init();
560 #endif 553 #endif
561 554
562 event_routers_initialized_ = true; 555 event_routers_initialized_ = true;
563 } 556 }
564 557
565 const Extension* ExtensionService::GetExtensionById( 558 const Extension* ExtensionService::GetExtensionById(
566 const std::string& id, bool include_disabled) const { 559 const std::string& id, bool include_disabled) const {
567 return GetExtensionByIdInternal(id, true, include_disabled, false); 560 return GetExtensionByIdInternal(id, true, include_disabled);
568 } 561 }
569 562
570 void ExtensionService::Init() { 563 void ExtensionService::Init() {
571 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 564 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
572 565
573 DCHECK(!ready_); // Can't redo init. 566 DCHECK(!ready_); // Can't redo init.
574 DCHECK_EQ(extensions_.size(), 0u); 567 DCHECK_EQ(extensions_.size(), 0u);
575 568
576 component_loader_->LoadAll(); 569 component_loader_->LoadAll();
577 extensions::InstalledLoader(this).LoadAllExtensions(); 570 extensions::InstalledLoader(this).LoadAllExtensions();
(...skipping 23 matching lines...) Expand all
601 const std::string& id, 594 const std::string& id,
602 const FilePath& extension_path, 595 const FilePath& extension_path,
603 const GURL& download_url, 596 const GURL& download_url,
604 CrxInstaller** out_crx_installer) { 597 CrxInstaller** out_crx_installer) {
605 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 598 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
606 599
607 PendingExtensionInfo pending_extension_info; 600 PendingExtensionInfo pending_extension_info;
608 bool is_pending_extension = pending_extension_manager_.GetById( 601 bool is_pending_extension = pending_extension_manager_.GetById(
609 id, &pending_extension_info); 602 id, &pending_extension_info);
610 603
611 const Extension* extension = 604 const Extension* extension = GetExtensionByIdInternal(id, true, true);
612 GetExtensionByIdInternal(id, true, true, false);
613 if (!is_pending_extension && !extension) { 605 if (!is_pending_extension && !extension) {
614 LOG(WARNING) << "Will not update extension " << id 606 LOG(WARNING) << "Will not update extension " << id
615 << " because it is not installed or pending"; 607 << " because it is not installed or pending";
616 // Delete extension_path since we're not creating a CrxInstaller 608 // Delete extension_path since we're not creating a CrxInstaller
617 // that would do it for us. 609 // that would do it for us.
618 if (!BrowserThread::PostTask( 610 if (!BrowserThread::PostTask(
619 BrowserThread::FILE, FROM_HERE, 611 BrowserThread::FILE, FROM_HERE,
620 base::Bind( 612 base::Bind(
621 &extension_file_util::DeleteFile, extension_path, false))) 613 &extension_file_util::DeleteFile, extension_path, false)))
622 NOTREACHED(); 614 NOTREACHED();
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 803
812 if (extension->is_hosted_app() && 804 if (extension->is_hosted_app() &&
813 !profile_->GetExtensionSpecialStoragePolicy()-> 805 !profile_->GetExtensionSpecialStoragePolicy()->
814 IsStorageProtected(launch_web_url_origin)) { 806 IsStorageProtected(launch_web_url_origin)) {
815 ExtensionDataDeleter::StartDeleting( 807 ExtensionDataDeleter::StartDeleting(
816 profile_, extension_id, launch_web_url_origin, is_storage_isolated); 808 profile_, extension_id, launch_web_url_origin, is_storage_isolated);
817 } 809 }
818 ExtensionDataDeleter::StartDeleting( 810 ExtensionDataDeleter::StartDeleting(
819 profile_, extension_id, extension->url(), is_storage_isolated); 811 profile_, extension_id, extension->url(), is_storage_isolated);
820 812
821 UntrackTerminatedExtension(extension_id);
822
823 // Notify interested parties that we've uninstalled this extension. 813 // Notify interested parties that we've uninstalled this extension.
824 content::NotificationService::current()->Notify( 814 content::NotificationService::current()->Notify(
825 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 815 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
826 content::Source<Profile>(profile_), 816 content::Source<Profile>(profile_),
827 content::Details<const std::string>(&extension_id)); 817 content::Details<const std::string>(&extension_id));
828 818
829 if (sync_bundle && sync_bundle->HasExtensionId(extension_id)) { 819 if (sync_bundle && sync_bundle->HasExtensionId(extension_id)) {
830 sync_bundle->sync_processor->ProcessSyncChanges( 820 sync_bundle->sync_processor->ProcessSyncChanges(
831 FROM_HERE, SyncChangeList(1, sync_change)); 821 FROM_HERE, SyncChangeList(1, sync_change));
832 sync_bundle->synced_extensions.erase(extension_id); 822 sync_bundle->synced_extensions.erase(extension_id);
(...skipping 15 matching lines...) Expand all
848 // Therefore, we clear warnings of this type for all extensions. 838 // Therefore, we clear warnings of this type for all extensions.
849 std::set<ExtensionWarningSet::WarningType> warnings; 839 std::set<ExtensionWarningSet::WarningType> warnings;
850 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); 840 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings);
851 extension_warnings_.ClearWarnings(warnings); 841 extension_warnings_.ClearWarnings(warnings);
852 842
853 return true; 843 return true;
854 } 844 }
855 845
856 bool ExtensionService::IsExtensionEnabled( 846 bool ExtensionService::IsExtensionEnabled(
857 const std::string& extension_id) const { 847 const std::string& extension_id) const {
858 if (extensions_.Contains(extension_id) || 848 if (extensions_.Contains(extension_id))
859 terminated_extensions_.Contains(extension_id))
860 return true; 849 return true;
861 850
862 if (disabled_extensions_.Contains(extension_id)) 851 if (disabled_extensions_.Contains(extension_id))
863 return false; 852 return false;
864 853
865 // If the extension hasn't been loaded yet, check the prefs for it. Assume 854 // If the extension hasn't been loaded yet, check the prefs for it. Assume
866 // enabled unless otherwise noted. 855 // enabled unless otherwise noted.
867 return !extension_prefs_->IsExtensionDisabled(extension_id) && 856 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
868 !extension_prefs_->IsExternalExtensionUninstalled(extension_id); 857 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
869 } 858 }
870 859
871 bool ExtensionService::IsExternalExtensionUninstalled( 860 bool ExtensionService::IsExternalExtensionUninstalled(
872 const std::string& extension_id) const { 861 const std::string& extension_id) const {
873 return extension_prefs_->IsExternalExtensionUninstalled(extension_id); 862 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
874 } 863 }
875 864
876 void ExtensionService::EnableExtension(const std::string& extension_id) { 865 void ExtensionService::EnableExtension(const std::string& extension_id) {
877 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 866 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
878 867
879 if (IsExtensionEnabled(extension_id)) 868 if (IsExtensionEnabled(extension_id))
880 return; 869 return;
881 870
882 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); 871 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
883 872
884 const Extension* extension = 873 const Extension* extension =
885 GetExtensionByIdInternal(extension_id, false, true, false); 874 GetExtensionByIdInternal(extension_id, false, true);
886 // This can happen if sync enables an extension that is not 875 // This can happen if sync enables an extension that is not
887 // installed yet. 876 // installed yet.
888 if (!extension) 877 if (!extension)
889 return; 878 return;
890 879
891 // Move it over to the enabled list. 880 // Move it over to the enabled list.
892 extensions_.Insert(make_scoped_refptr(extension)); 881 extensions_.Insert(make_scoped_refptr(extension));
893 disabled_extensions_.Remove(extension->id()); 882 disabled_extensions_.Remove(extension->id());
894 883
895 // Make sure any browser action contained within it is not hidden. 884 // Make sure any browser action contained within it is not hidden.
(...skipping 12 matching lines...) Expand all
908 return; 897 return;
909 898
910 const Extension* extension = GetInstalledExtension(extension_id); 899 const Extension* extension = GetInstalledExtension(extension_id);
911 // |extension| can be NULL if sync disables an extension that is not 900 // |extension| can be NULL if sync disables an extension that is not
912 // installed yet. 901 // installed yet.
913 if (extension && !Extension::UserMayDisable(extension->location())) 902 if (extension && !Extension::UserMayDisable(extension->location()))
914 return; 903 return;
915 904
916 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); 905 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
917 906
918 extension = GetExtensionByIdInternal(extension_id, true, false, true); 907 extension = GetExtensionByIdInternal(extension_id, true, false);
919 if (!extension) 908 if (!extension)
920 return; 909 return;
921 910
922 // Move it over to the disabled list. 911 // Move it over to the disabled list.
923 disabled_extensions_.Insert(make_scoped_refptr(extension)); 912 disabled_extensions_.Insert(make_scoped_refptr(extension));
924 if (extensions_.Contains(extension->id())) 913 if (extensions_.Contains(extension->id()))
925 extensions_.Remove(extension->id()); 914 extensions_.Remove(extension->id());
926 else
927 terminated_extensions_.Remove(extension->id());
928 915
929 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE); 916 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
930 917
931 SyncExtensionChangeIfNeeded(*extension); 918 SyncExtensionChangeIfNeeded(*extension);
932 919
933 // Deactivating one extension might have solved the problems of others. 920 // Deactivating one extension might have solved the problems of others.
934 // Therefore, we clear warnings of this type for all extensions. 921 // Therefore, we clear warnings of this type for all extensions.
935 std::set<ExtensionWarningSet::WarningType> warnings; 922 std::set<ExtensionWarningSet::WarningType> warnings;
936 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); 923 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings);
937 extension_warnings_.ClearWarnings(warnings); 924 extension_warnings_.ClearWarnings(warnings);
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 GetPageOrdinal(extension.id()))); 1447 GetPageOrdinal(extension.id())));
1461 } 1448 }
1462 } 1449 }
1463 } 1450 }
1464 1451
1465 std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList( 1452 std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList(
1466 const SyncBundle& bundle) const { 1453 const SyncBundle& bundle) const {
1467 std::vector<ExtensionSyncData> extension_sync_list; 1454 std::vector<ExtensionSyncData> extension_sync_list;
1468 GetSyncDataListHelper(extensions_, bundle, &extension_sync_list); 1455 GetSyncDataListHelper(extensions_, bundle, &extension_sync_list);
1469 GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list); 1456 GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list);
1470 GetSyncDataListHelper(terminated_extensions_, bundle, &extension_sync_list);
1471 1457
1472 for (std::map<std::string, ExtensionSyncData>::const_iterator i = 1458 for (std::map<std::string, ExtensionSyncData>::const_iterator i =
1473 bundle.pending_sync_data.begin(); 1459 bundle.pending_sync_data.begin();
1474 i != bundle.pending_sync_data.end(); 1460 i != bundle.pending_sync_data.end();
1475 ++i) { 1461 ++i) {
1476 extension_sync_list.push_back(i->second); 1462 extension_sync_list.push_back(i->second);
1477 } 1463 }
1478 1464
1479 return extension_sync_list; 1465 return extension_sync_list;
1480 } 1466 }
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 void ExtensionService::HandleExtensionAlertDetails(Browser* browser) { 1885 void ExtensionService::HandleExtensionAlertDetails(Browser* browser) {
1900 DCHECK(browser); 1886 DCHECK(browser);
1901 browser->ShowExtensionsTab(); 1887 browser->ShowExtensionsTab();
1902 } 1888 }
1903 1889
1904 void ExtensionService::UnloadExtension( 1890 void ExtensionService::UnloadExtension(
1905 const std::string& extension_id, 1891 const std::string& extension_id,
1906 extension_misc::UnloadedExtensionReason reason) { 1892 extension_misc::UnloadedExtensionReason reason) {
1907 // Make sure the extension gets deleted after we return from this function. 1893 // Make sure the extension gets deleted after we return from this function.
1908 scoped_refptr<const Extension> extension( 1894 scoped_refptr<const Extension> extension(
1909 GetExtensionByIdInternal(extension_id, true, true, false)); 1895 GetExtensionByIdInternal(extension_id, true, true));
1910 1896
1911 // This method can be called via PostTask, so the extension may have been 1897 // This method can be called via PostTask, so the extension may have been
1912 // unloaded by the time this runs. 1898 // unloaded by the time this runs.
1913 if (!extension) { 1899 if (!extension) {
1914 // In case the extension may have crashed/uninstalled. Allow the profile to 1900 // In case the extension may have crashed/uninstalled. Allow the profile to
1915 // clean up its RequestContexts. 1901 // clean up its RequestContexts.
1916 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); 1902 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason);
1917 return; 1903 return;
1918 } 1904 }
1919 1905
(...skipping 27 matching lines...) Expand all
1947 1933
1948 NotifyExtensionUnloaded(extension.get(), reason); 1934 NotifyExtensionUnloaded(extension.get(), reason);
1949 } 1935 }
1950 1936
1951 void ExtensionService::UnloadAllExtensions() { 1937 void ExtensionService::UnloadAllExtensions() {
1952 profile_->GetExtensionSpecialStoragePolicy()-> 1938 profile_->GetExtensionSpecialStoragePolicy()->
1953 RevokeRightsForAllExtensions(); 1939 RevokeRightsForAllExtensions();
1954 1940
1955 extensions_.Clear(); 1941 extensions_.Clear();
1956 disabled_extensions_.Clear(); 1942 disabled_extensions_.Clear();
1957 terminated_extensions_.Clear();
1958 extension_runtime_data_.clear(); 1943 extension_runtime_data_.clear();
1959 1944
1960 // TODO(erikkay) should there be a notification for this? We can't use 1945 // TODO(erikkay) should there be a notification for this? We can't use
1961 // EXTENSION_UNLOADED since that implies that the extension has been disabled 1946 // EXTENSION_UNLOADED since that implies that the extension has been disabled
1962 // or uninstalled, and UnloadAll is just part of shutdown. 1947 // or uninstalled, and UnloadAll is just part of shutdown.
1963 } 1948 }
1964 1949
1965 void ExtensionService::ReloadExtensions() { 1950 void ExtensionService::ReloadExtensions() {
1966 UnloadAllExtensions(); 1951 UnloadAllExtensions();
1967 component_loader_->LoadAll(); 1952 component_loader_->LoadAll();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 !extension->is_theme() && 2003 !extension->is_theme() &&
2019 extension->location() != Extension::COMPONENT && 2004 extension->location() != Extension::COMPONENT &&
2020 !Extension::IsExternalLocation(extension->location())) 2005 !Extension::IsExternalLocation(extension->location()))
2021 return; 2006 return;
2022 2007
2023 SetBeingUpgraded(extension, false); 2008 SetBeingUpgraded(extension, false);
2024 2009
2025 // The extension is now loaded, remove its data from unloaded extension map. 2010 // The extension is now loaded, remove its data from unloaded extension map.
2026 unloaded_extension_paths_.erase(extension->id()); 2011 unloaded_extension_paths_.erase(extension->id());
2027 2012
2028 // If a terminated extension is loaded, remove it from the terminated list.
2029 UntrackTerminatedExtension(extension->id());
2030
2031 // If the extension was disabled for a reload, then enable it. 2013 // If the extension was disabled for a reload, then enable it.
2032 if (disabled_extension_paths_.erase(extension->id()) > 0) 2014 if (disabled_extension_paths_.erase(extension->id()) > 0)
2033 EnableExtension(extension->id()); 2015 EnableExtension(extension->id());
2034 2016
2035 // Check if the extension's privileges have changed and disable the 2017 // Check if the extension's privileges have changed and disable the
2036 // extension if necessary. 2018 // extension if necessary.
2037 InitializePermissions(extension); 2019 InitializePermissions(extension);
2038 2020
2039 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id()); 2021 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id());
2040 if (disabled) { 2022 if (disabled) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 // maintain backwards compatibility while still having "omnibox" in the 2081 // maintain backwards compatibility while still having "omnibox" in the
2100 // manifest. If a user installs the extension on Chrome 9, the browser 2082 // manifest. If a user installs the extension on Chrome 9, the browser
2101 // will record the permissions it recognized, not including "omnibox." 2083 // will record the permissions it recognized, not including "omnibox."
2102 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome 2084 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
2103 // will disable the extension and prompt the user to approve the increase 2085 // will disable the extension and prompt the user to approve the increase
2104 // in privileges. The extension could then release a new version that 2086 // in privileges. The extension could then release a new version that
2105 // removes the "omnibox" permission. When the user upgrades, Chrome will 2087 // removes the "omnibox" permission. When the user upgrades, Chrome will
2106 // still remember that "omnibox" had been granted, so that if the 2088 // still remember that "omnibox" had been granted, so that if the
2107 // extension once again includes "omnibox" in an upgrade, the extension 2089 // extension once again includes "omnibox" in an upgrade, the extension
2108 // can upgrade without requiring this user's approval. 2090 // can upgrade without requiring this user's approval.
2109 const Extension* old = GetExtensionByIdInternal(extension->id(), 2091 const Extension* old = GetExtensionByIdInternal(extension->id(), true, true);
2110 true, true, false);
2111 bool is_extension_upgrade = old != NULL; 2092 bool is_extension_upgrade = old != NULL;
2112 bool is_privilege_increase = false; 2093 bool is_privilege_increase = false;
2113 2094
2114 // We only need to compare the granted permissions to the current permissions 2095 // We only need to compare the granted permissions to the current permissions
2115 // if the extension is not allowed to silently increase its permissions. 2096 // if the extension is not allowed to silently increase its permissions.
2116 if (!extension->CanSilentlyIncreasePermissions()) { 2097 if (!extension->CanSilentlyIncreasePermissions()) {
2117 // Add all the recognized permissions if the granted permissions list 2098 // Add all the recognized permissions if the granted permissions list
2118 // hasn't been initialized yet. 2099 // hasn't been initialized yet.
2119 scoped_refptr<ExtensionPermissionSet> granted_permissions = 2100 scoped_refptr<ExtensionPermissionSet> granted_permissions =
2120 extension_prefs_->GetGrantedPermissions(extension->id()); 2101 extension_prefs_->GetGrantedPermissions(extension->id());
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 } else { 2195 } else {
2215 // We explicitly want to re-enable an uninstalled external 2196 // We explicitly want to re-enable an uninstalled external
2216 // extension; if we're here, that means the user is manually 2197 // extension; if we're here, that means the user is manually
2217 // installing the extension. 2198 // installing the extension.
2218 if (IsExternalExtensionUninstalled(id)) { 2199 if (IsExternalExtensionUninstalled(id)) {
2219 initial_enable = true; 2200 initial_enable = true;
2220 } 2201 }
2221 } 2202 }
2222 2203
2223 // Do not record the install histograms for upgrades. 2204 // Do not record the install histograms for upgrades.
2224 if (!GetExtensionByIdInternal(extension->id(), true, true, false)) { 2205 if (!GetExtensionByIdInternal(extension->id(), true, true)) {
2225 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", 2206 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
2226 extension->GetType(), 100); 2207 extension->GetType(), 100);
2227 RecordPermissionMessagesHistogram( 2208 RecordPermissionMessagesHistogram(
2228 extension, "Extensions.Permissions_Install"); 2209 extension, "Extensions.Permissions_Install");
2229 } 2210 }
2230 2211
2231 extension_prefs_->OnExtensionInstalled( 2212 extension_prefs_->OnExtensionInstalled(
2232 extension, 2213 extension,
2233 initial_enable ? Extension::ENABLED : Extension::DISABLED, 2214 initial_enable ? Extension::ENABLED : Extension::DISABLED,
2234 from_webstore, 2215 from_webstore,
(...skipping 22 matching lines...) Expand all
2257 // TODO(benwells): Remove before launching platform apps. 2238 // TODO(benwells): Remove before launching platform apps.
2258 if (extension->is_platform_app()) { 2239 if (extension->is_platform_app()) {
2259 StartInstallApplicationShortcut(extension); 2240 StartInstallApplicationShortcut(extension);
2260 } 2241 }
2261 2242
2262 // Transfer ownership of |extension| to AddExtension. 2243 // Transfer ownership of |extension| to AddExtension.
2263 AddExtension(scoped_extension); 2244 AddExtension(scoped_extension);
2264 } 2245 }
2265 2246
2266 const Extension* ExtensionService::GetExtensionByIdInternal( 2247 const Extension* ExtensionService::GetExtensionByIdInternal(
2267 const std::string& id, bool include_enabled, bool include_disabled, 2248 const std::string& id, bool include_enabled, bool include_disabled) const {
2268 bool include_terminated) const {
2269 std::string lowercase_id = StringToLowerASCII(id); 2249 std::string lowercase_id = StringToLowerASCII(id);
2270 if (include_enabled) { 2250 if (include_enabled) {
2271 const Extension* extension = extensions_.GetByID(lowercase_id); 2251 const Extension* extension = extensions_.GetByID(lowercase_id);
2272 if (extension) 2252 if (extension)
2273 return extension; 2253 return extension;
2274 } 2254 }
2275 if (include_disabled) { 2255 if (include_disabled) {
2276 const Extension* extension = disabled_extensions_.GetByID(lowercase_id); 2256 const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
2277 if (extension) 2257 if (extension)
2278 return extension; 2258 return extension;
2279 } 2259 }
2280 if (include_terminated) {
2281 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
2282 if (extension)
2283 return extension;
2284 }
2285 return NULL; 2260 return NULL;
2286 } 2261 }
2287 2262
2288 void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
2289 if (!terminated_extensions_.Contains(extension->id()))
2290 terminated_extensions_.Insert(make_scoped_refptr(extension));
2291
2292 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE);
2293 }
2294
2295 void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
2296 std::string lowercase_id = StringToLowerASCII(id);
2297 terminated_extensions_.Remove(lowercase_id);
2298 }
2299
2300 const Extension* ExtensionService::GetTerminatedExtension(
2301 const std::string& id) const {
2302 return GetExtensionByIdInternal(id, false, false, true);
2303 }
2304
2305 const Extension* ExtensionService::GetInstalledExtension( 2263 const Extension* ExtensionService::GetInstalledExtension(
2306 const std::string& id) const { 2264 const std::string& id) const {
2307 return GetExtensionByIdInternal(id, true, true, true); 2265 return GetExtensionByIdInternal(id, true, true);
2308 } 2266 }
2309 2267
2310 const Extension* ExtensionService::GetWebStoreApp() { 2268 const Extension* ExtensionService::GetWebStoreApp() {
2311 return GetExtensionById(extension_misc::kWebStoreAppId, false); 2269 return GetExtensionById(extension_misc::kWebStoreAppId, false);
2312 } 2270 }
2313 2271
2314 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { 2272 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
2315 // Allow bindings for all packaged extensions and component hosted apps. 2273 // Allow bindings for all packaged extensions and component hosted apps.
2316 const Extension* extension = extensions_.GetExtensionOrAppByURL( 2274 const Extension* extension = extensions_.GetExtensionOrAppByURL(
2317 ExtensionURLInfo(url)); 2275 ExtensionURLInfo(url));
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2412 host->render_view_host()); 2370 host->render_view_host());
2413 content::DevToolsManager::GetInstance()->AttachClientHost(iter->second, 2371 content::DevToolsManager::GetInstance()->AttachClientHost(iter->second,
2414 agent); 2372 agent);
2415 orphaned_dev_tools_.erase(iter); 2373 orphaned_dev_tools_.erase(iter);
2416 } 2374 }
2417 2375
2418 void ExtensionService::Observe(int type, 2376 void ExtensionService::Observe(int type,
2419 const content::NotificationSource& source, 2377 const content::NotificationSource& source,
2420 const content::NotificationDetails& details) { 2378 const content::NotificationDetails& details) {
2421 switch (type) { 2379 switch (type) {
2422 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
2423 if (profile_ !=
2424 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
2425 break;
2426 }
2427
2428 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
2429
2430 // Mark the extension as terminated and Unload it. We want it to
2431 // be in a consistent state: either fully working or not loaded
2432 // at all, but never half-crashed. We do it in a PostTask so
2433 // that other handlers of this notification will still have
2434 // access to the Extension and ExtensionHost.
2435 MessageLoop::current()->PostTask(
2436 FROM_HERE,
2437 base::Bind(
2438 &ExtensionService::TrackTerminatedExtension,
2439 AsWeakPtr(),
2440 host->extension()));
2441 break;
2442 }
2443 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { 2380 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
2444 content::RenderProcessHost* process = 2381 content::RenderProcessHost* process =
2445 content::Source<content::RenderProcessHost>(source).ptr(); 2382 content::Source<content::RenderProcessHost>(source).ptr();
2446 Profile* host_profile = 2383 Profile* host_profile =
2447 Profile::FromBrowserContext(process->GetBrowserContext()); 2384 Profile::FromBrowserContext(process->GetBrowserContext());
2448 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) 2385 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2449 break; 2386 break;
2450 2387
2451 // Valid extension function names, used to setup bindings in renderer. 2388 // Valid extension function names, used to setup bindings in renderer.
2452 std::vector<std::string> function_names; 2389 std::vector<std::string> function_names;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2692 // 2629 //
2693 // To coexist with certain unit tests that don't have an IO thread message 2630 // To coexist with certain unit tests that don't have an IO thread message
2694 // loop available at ExtensionService shutdown, we lazy-initialize this 2631 // loop available at ExtensionService shutdown, we lazy-initialize this
2695 // object so that those cases neither create nor destroy a SocketController. 2632 // object so that those cases neither create nor destroy a SocketController.
2696 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 2633 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2697 if (!socket_controller_) { 2634 if (!socket_controller_) {
2698 socket_controller_ = new extensions::SocketController(); 2635 socket_controller_ = new extensions::SocketController();
2699 } 2636 }
2700 return socket_controller_; 2637 return socket_controller_;
2701 } 2638 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/renderer_host/chrome_render_view_host_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698