| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extensions_service.h" | 5 #include "chrome/browser/extensions/extensions_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 143 |
| 144 PendingExtensionInfo::PendingExtensionInfo() | 144 PendingExtensionInfo::PendingExtensionInfo() |
| 145 : update_url(), | 145 : update_url(), |
| 146 expected_crx_type(PendingExtensionInfo::UNKNOWN), | 146 expected_crx_type(PendingExtensionInfo::UNKNOWN), |
| 147 is_from_sync(true), | 147 is_from_sync(true), |
| 148 install_silently(false), | 148 install_silently(false), |
| 149 enable_on_install(false), | 149 enable_on_install(false), |
| 150 enable_incognito_on_install(false), | 150 enable_incognito_on_install(false), |
| 151 install_source(Extension::INVALID) {} | 151 install_source(Extension::INVALID) {} |
| 152 | 152 |
| 153 |
| 154 ExtensionsService::ExtensionRuntimeData::ExtensionRuntimeData() |
| 155 : background_page_ready(false), |
| 156 being_upgraded(false) { |
| 157 } |
| 158 |
| 159 ExtensionsService::ExtensionRuntimeData::~ExtensionRuntimeData() { |
| 160 } |
| 161 |
| 153 // ExtensionsService. | 162 // ExtensionsService. |
| 154 | 163 |
| 155 const char* ExtensionsService::kInstallDirectoryName = "Extensions"; | 164 const char* ExtensionsService::kInstallDirectoryName = "Extensions"; |
| 156 const char* ExtensionsService::kCurrentVersionFileName = "Current Version"; | 165 const char* ExtensionsService::kCurrentVersionFileName = "Current Version"; |
| 157 | 166 |
| 158 // Implements IO for the ExtensionsService. | 167 // Implements IO for the ExtensionsService. |
| 159 | 168 |
| 160 class ExtensionsServiceBackend | 169 class ExtensionsServiceBackend |
| 161 : public base::RefCountedThreadSafe<ExtensionsServiceBackend>, | 170 : public base::RefCountedThreadSafe<ExtensionsServiceBackend>, |
| 162 public ExternalExtensionProvider::Visitor { | 171 public ExternalExtensionProvider::Visitor { |
| (...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 // Callers should not send us nonexistent extensions. | 1329 // Callers should not send us nonexistent extensions. |
| 1321 CHECK(extension.get()); | 1330 CHECK(extension.get()); |
| 1322 | 1331 |
| 1323 // Keep information about the extension so that we can reload it later | 1332 // Keep information about the extension so that we can reload it later |
| 1324 // even if it's not permanently installed. | 1333 // even if it's not permanently installed. |
| 1325 unloaded_extension_paths_[extension->id()] = extension->path(); | 1334 unloaded_extension_paths_[extension->id()] = extension->path(); |
| 1326 | 1335 |
| 1327 // Clean up if the extension is meant to be enabled after a reload. | 1336 // Clean up if the extension is meant to be enabled after a reload. |
| 1328 disabled_extension_paths_.erase(extension->id()); | 1337 disabled_extension_paths_.erase(extension->id()); |
| 1329 | 1338 |
| 1339 // Clean up runtime data. |
| 1340 extension_runtime_data_.erase(extension_id); |
| 1341 |
| 1330 ExtensionDOMUI::UnregisterChromeURLOverrides(profile_, | 1342 ExtensionDOMUI::UnregisterChromeURLOverrides(profile_, |
| 1331 extension->GetChromeURLOverrides()); | 1343 extension->GetChromeURLOverrides()); |
| 1332 | 1344 |
| 1333 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), | 1345 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), |
| 1334 disabled_extensions_.end(), | 1346 disabled_extensions_.end(), |
| 1335 extension.get()); | 1347 extension.get()); |
| 1336 if (iter != disabled_extensions_.end()) { | 1348 if (iter != disabled_extensions_.end()) { |
| 1337 disabled_extensions_.erase(iter); | 1349 disabled_extensions_.erase(iter); |
| 1338 NotificationService::current()->Notify( | 1350 NotificationService::current()->Notify( |
| 1339 NotificationType::EXTENSION_UNLOADED_DISABLED, | 1351 NotificationType::EXTENSION_UNLOADED_DISABLED, |
| 1340 Source<Profile>(profile_), | 1352 Source<Profile>(profile_), |
| 1341 Details<const Extension>(extension.get())); | 1353 Details<const Extension>(extension.get())); |
| 1342 return; | 1354 return; |
| 1343 } | 1355 } |
| 1344 | 1356 |
| 1345 iter = std::find(extensions_.begin(), extensions_.end(), extension.get()); | 1357 iter = std::find(extensions_.begin(), extensions_.end(), extension.get()); |
| 1346 | 1358 |
| 1347 // Remove the extension from our list. | 1359 // Remove the extension from our list. |
| 1348 extensions_.erase(iter); | 1360 extensions_.erase(iter); |
| 1349 | 1361 |
| 1350 NotifyExtensionUnloaded(extension.get()); | 1362 NotifyExtensionUnloaded(extension.get()); |
| 1351 UpdateActiveExtensionsInCrashReporter(); | 1363 UpdateActiveExtensionsInCrashReporter(); |
| 1352 } | 1364 } |
| 1353 | 1365 |
| 1354 void ExtensionsService::UnloadAllExtensions() { | 1366 void ExtensionsService::UnloadAllExtensions() { |
| 1355 extensions_.clear(); | 1367 extensions_.clear(); |
| 1356 disabled_extensions_.clear(); | 1368 disabled_extensions_.clear(); |
| 1369 extension_runtime_data_.clear(); |
| 1357 | 1370 |
| 1358 // TODO(erikkay) should there be a notification for this? We can't use | 1371 // TODO(erikkay) should there be a notification for this? We can't use |
| 1359 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 1372 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 1360 // or uninstalled, and UnloadAll is just part of shutdown. | 1373 // or uninstalled, and UnloadAll is just part of shutdown. |
| 1361 } | 1374 } |
| 1362 | 1375 |
| 1363 void ExtensionsService::ReloadExtensions() { | 1376 void ExtensionsService::ReloadExtensions() { |
| 1364 UnloadAllExtensions(); | 1377 UnloadAllExtensions(); |
| 1365 LoadAllExtensions(); | 1378 LoadAllExtensions(); |
| 1366 } | 1379 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 // CrxInstaller should have guaranteed that we aren't downgrading. | 1432 // CrxInstaller should have guaranteed that we aren't downgrading. |
| 1420 CHECK(extension->version()->CompareTo(*(old->version())) >= 0); | 1433 CHECK(extension->version()->CompareTo(*(old->version())) >= 0); |
| 1421 | 1434 |
| 1422 bool allow_silent_upgrade = | 1435 bool allow_silent_upgrade = |
| 1423 allow_privilege_increase || !Extension::IsPrivilegeIncrease( | 1436 allow_privilege_increase || !Extension::IsPrivilegeIncrease( |
| 1424 old, extension); | 1437 old, extension); |
| 1425 | 1438 |
| 1426 // Extensions get upgraded if silent upgrades are allowed, otherwise | 1439 // Extensions get upgraded if silent upgrades are allowed, otherwise |
| 1427 // they get disabled. | 1440 // they get disabled. |
| 1428 if (allow_silent_upgrade) { | 1441 if (allow_silent_upgrade) { |
| 1429 old->set_being_upgraded(true); | 1442 SetBeingUpgraded(old, true); |
| 1430 extension->set_being_upgraded(true); | 1443 SetBeingUpgraded(extension, true); |
| 1431 } | 1444 } |
| 1432 | 1445 |
| 1433 // To upgrade an extension in place, unload the old one and | 1446 // To upgrade an extension in place, unload the old one and |
| 1434 // then load the new one. | 1447 // then load the new one. |
| 1435 UnloadExtension(old->id()); | 1448 UnloadExtension(old->id()); |
| 1436 old = NULL; | 1449 old = NULL; |
| 1437 | 1450 |
| 1438 if (!allow_silent_upgrade) { | 1451 if (!allow_silent_upgrade) { |
| 1439 // Extension has changed permissions significantly. Disable it. We | 1452 // Extension has changed permissions significantly. Disable it. We |
| 1440 // send a notification below. | 1453 // send a notification below. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1458 NotificationType::EXTENSION_UPDATE_DISABLED, | 1471 NotificationType::EXTENSION_UPDATE_DISABLED, |
| 1459 Source<Profile>(profile_), | 1472 Source<Profile>(profile_), |
| 1460 Details<const Extension>(extension)); | 1473 Details<const Extension>(extension)); |
| 1461 break; | 1474 break; |
| 1462 default: | 1475 default: |
| 1463 NOTREACHED(); | 1476 NOTREACHED(); |
| 1464 break; | 1477 break; |
| 1465 } | 1478 } |
| 1466 } | 1479 } |
| 1467 | 1480 |
| 1468 extension->set_being_upgraded(false); | 1481 SetBeingUpgraded(extension, false); |
| 1469 | 1482 |
| 1470 UpdateActiveExtensionsInCrashReporter(); | 1483 UpdateActiveExtensionsInCrashReporter(); |
| 1471 | 1484 |
| 1472 if (profile_->GetTemplateURLModel()) | 1485 if (profile_->GetTemplateURLModel()) |
| 1473 profile_->GetTemplateURLModel()->RegisterExtensionKeyword(extension); | 1486 profile_->GetTemplateURLModel()->RegisterExtensionKeyword(extension); |
| 1474 | 1487 |
| 1475 // Load the icon for omnibox-enabled extensions so it will be ready to display | 1488 // Load the icon for omnibox-enabled extensions so it will be ready to display |
| 1476 // in the URL bar. | 1489 // in the URL bar. |
| 1477 if (!extension->omnibox_keyword().empty()) { | 1490 if (!extension->omnibox_keyword().empty()) { |
| 1478 omnibox_popup_icon_manager_.LoadIcon(extension); | 1491 omnibox_popup_icon_manager_.LoadIcon(extension); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1834 ExtensionIdSet ExtensionsService::GetAppIds() const { | 1847 ExtensionIdSet ExtensionsService::GetAppIds() const { |
| 1835 ExtensionIdSet result; | 1848 ExtensionIdSet result; |
| 1836 for (ExtensionList::const_iterator it = extensions_.begin(); | 1849 for (ExtensionList::const_iterator it = extensions_.begin(); |
| 1837 it != extensions_.end(); ++it) { | 1850 it != extensions_.end(); ++it) { |
| 1838 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT) | 1851 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT) |
| 1839 result.insert((*it)->id()); | 1852 result.insert((*it)->id()); |
| 1840 } | 1853 } |
| 1841 | 1854 |
| 1842 return result; | 1855 return result; |
| 1843 } | 1856 } |
| 1857 |
| 1858 bool ExtensionsService::IsBackgroundPageReady(const Extension* extension) { |
| 1859 return (extension->background_url().is_empty() || |
| 1860 extension_runtime_data_[extension->id()].background_page_ready); |
| 1861 } |
| 1862 |
| 1863 void ExtensionsService::SetBackgroundPageReady(const Extension* extension) { |
| 1864 DCHECK(!extension->background_url().is_empty()); |
| 1865 extension_runtime_data_[extension->id()].background_page_ready = true; |
| 1866 NotificationService::current()->Notify( |
| 1867 NotificationType::EXTENSION_BACKGROUND_PAGE_READY, |
| 1868 Source<const Extension>(extension), |
| 1869 NotificationService::NoDetails()); |
| 1870 } |
| 1871 |
| 1872 bool ExtensionsService::IsBeingUpgraded(const Extension* extension) { |
| 1873 return extension_runtime_data_[extension->id()].being_upgraded; |
| 1874 } |
| 1875 |
| 1876 void ExtensionsService::SetBeingUpgraded(const Extension* extension, |
| 1877 bool value) { |
| 1878 extension_runtime_data_[extension->id()].being_upgraded = value; |
| 1879 } |
| OLD | NEW |