| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <iterator> | 8 #include <iterator> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "chrome/browser/extensions/extension_disabled_ui.h" | 43 #include "chrome/browser/extensions/extension_disabled_ui.h" |
| 44 #include "chrome/browser/extensions/extension_error_reporter.h" | 44 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 45 #include "chrome/browser/extensions/extension_error_ui.h" | 45 #include "chrome/browser/extensions/extension_error_ui.h" |
| 46 #include "chrome/browser/extensions/extension_host.h" | 46 #include "chrome/browser/extensions/extension_host.h" |
| 47 #include "chrome/browser/extensions/extension_install_ui.h" | 47 #include "chrome/browser/extensions/extension_install_ui.h" |
| 48 #include "chrome/browser/extensions/extension_process_manager.h" | 48 #include "chrome/browser/extensions/extension_process_manager.h" |
| 49 #include "chrome/browser/extensions/extension_sorting.h" | 49 #include "chrome/browser/extensions/extension_sorting.h" |
| 50 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 50 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 51 #include "chrome/browser/extensions/extension_sync_data.h" | 51 #include "chrome/browser/extensions/extension_sync_data.h" |
| 52 #include "chrome/browser/extensions/extension_system.h" | 52 #include "chrome/browser/extensions/extension_system.h" |
| 53 #include "chrome/browser/extensions/extension_util.h" |
| 53 #include "chrome/browser/extensions/external_install_ui.h" | 54 #include "chrome/browser/extensions/external_install_ui.h" |
| 54 #include "chrome/browser/extensions/external_provider_impl.h" | 55 #include "chrome/browser/extensions/external_provider_impl.h" |
| 55 #include "chrome/browser/extensions/external_provider_interface.h" | 56 #include "chrome/browser/extensions/external_provider_interface.h" |
| 56 #include "chrome/browser/extensions/installed_loader.h" | 57 #include "chrome/browser/extensions/installed_loader.h" |
| 57 #include "chrome/browser/extensions/management_policy.h" | 58 #include "chrome/browser/extensions/management_policy.h" |
| 58 #include "chrome/browser/extensions/pending_extension_manager.h" | 59 #include "chrome/browser/extensions/pending_extension_manager.h" |
| 59 #include "chrome/browser/extensions/permissions_updater.h" | 60 #include "chrome/browser/extensions/permissions_updater.h" |
| 60 #include "chrome/browser/extensions/unpacked_installer.h" | 61 #include "chrome/browser/extensions/unpacked_installer.h" |
| 61 #include "chrome/browser/extensions/update_observer.h" | 62 #include "chrome/browser/extensions/update_observer.h" |
| 62 #include "chrome/browser/extensions/updater/extension_updater.h" | 63 #include "chrome/browser/extensions/updater/extension_updater.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 278 |
| 278 const Extension* ExtensionService::GetInstalledApp(const GURL& url) const { | 279 const Extension* ExtensionService::GetInstalledApp(const GURL& url) const { |
| 279 const Extension* extension = extensions_.GetExtensionOrAppByURL(url); | 280 const Extension* extension = extensions_.GetExtensionOrAppByURL(url); |
| 280 return (extension && extension->is_app()) ? extension : NULL; | 281 return (extension && extension->is_app()) ? extension : NULL; |
| 281 } | 282 } |
| 282 | 283 |
| 283 bool ExtensionService::IsInstalledApp(const GURL& url) const { | 284 bool ExtensionService::IsInstalledApp(const GURL& url) const { |
| 284 return !!GetInstalledApp(url); | 285 return !!GetInstalledApp(url); |
| 285 } | 286 } |
| 286 | 287 |
| 287 const Extension* ExtensionService::GetIsolatedAppForRenderer( | |
| 288 int renderer_child_id) const { | |
| 289 std::set<std::string> extension_ids = | |
| 290 process_map_.GetExtensionsInProcess(renderer_child_id); | |
| 291 // All apps in one process share the same partition. | |
| 292 // It is only possible for the app to have isolated storage | |
| 293 // if there is only 1 app in the process. | |
| 294 if (extension_ids.size() != 1) | |
| 295 return NULL; | |
| 296 | |
| 297 const extensions::Extension* extension = | |
| 298 extensions_.GetByID(*(extension_ids.begin())); | |
| 299 // We still need to check if the extension has isolated storage, | |
| 300 // because it's common for there to be one extension in a process | |
| 301 // without isolated storage. | |
| 302 if (extension && | |
| 303 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) | |
| 304 return extension; | |
| 305 | |
| 306 return NULL; | |
| 307 } | |
| 308 | |
| 309 // static | 288 // static |
| 310 // This function is used to implement the command-line switch | 289 // This function is used to implement the command-line switch |
| 311 // --uninstall-extension, and to uninstall an extension via sync. The LOG | 290 // --uninstall-extension, and to uninstall an extension via sync. The LOG |
| 312 // statements within this function are used to inform the user if the uninstall | 291 // statements within this function are used to inform the user if the uninstall |
| 313 // cannot be done. | 292 // cannot be done. |
| 314 bool ExtensionService::UninstallExtensionHelper( | 293 bool ExtensionService::UninstallExtensionHelper( |
| 315 ExtensionService* extensions_service, | 294 ExtensionService* extensions_service, |
| 316 const std::string& extension_id) { | 295 const std::string& extension_id) { |
| 317 // We can't call UninstallExtension with an invalid extension ID. | 296 // We can't call UninstallExtension with an invalid extension ID. |
| 318 if (!extensions_service->GetInstalledExtension(extension_id)) { | 297 if (!extensions_service->GetInstalledExtension(extension_id)) { |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 } | 1222 } |
| 1244 | 1223 |
| 1245 Profile* ExtensionService::profile() { | 1224 Profile* ExtensionService::profile() { |
| 1246 return profile_; | 1225 return profile_; |
| 1247 } | 1226 } |
| 1248 | 1227 |
| 1249 extensions::ExtensionPrefs* ExtensionService::extension_prefs() { | 1228 extensions::ExtensionPrefs* ExtensionService::extension_prefs() { |
| 1250 return extension_prefs_; | 1229 return extension_prefs_; |
| 1251 } | 1230 } |
| 1252 | 1231 |
| 1232 const extensions::ExtensionPrefs* ExtensionService::extension_prefs() const { |
| 1233 return extension_prefs_; |
| 1234 } |
| 1235 |
| 1253 extensions::SettingsFrontend* ExtensionService::settings_frontend() { | 1236 extensions::SettingsFrontend* ExtensionService::settings_frontend() { |
| 1254 return settings_frontend_.get(); | 1237 return settings_frontend_.get(); |
| 1255 } | 1238 } |
| 1256 | 1239 |
| 1257 extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() { | 1240 extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() { |
| 1258 return extension_prefs()->content_settings_store(); | 1241 return extension_prefs()->content_settings_store(); |
| 1259 } | 1242 } |
| 1260 | 1243 |
| 1261 bool ExtensionService::is_ready() { | 1244 bool ExtensionService::is_ready() { |
| 1262 return ready_->is_signaled(); | 1245 return ready_->is_signaled(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 } | 1391 } |
| 1409 } | 1392 } |
| 1410 | 1393 |
| 1411 extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions(); | 1394 extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions(); |
| 1412 | 1395 |
| 1413 return syncer::SyncError(); | 1396 return syncer::SyncError(); |
| 1414 } | 1397 } |
| 1415 | 1398 |
| 1416 extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData( | 1399 extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData( |
| 1417 const Extension& extension) const { | 1400 const Extension& extension) const { |
| 1418 return extensions::ExtensionSyncData(extension, | 1401 return extensions::ExtensionSyncData( |
| 1419 IsExtensionEnabled(extension.id()), | 1402 extension, |
| 1420 IsIncognitoEnabled(extension.id())); | 1403 IsExtensionEnabled(extension.id()), |
| 1404 extension_util::IsIncognitoEnabled(extension.id(), this)); |
| 1421 } | 1405 } |
| 1422 | 1406 |
| 1423 extensions::AppSyncData ExtensionService::GetAppSyncData( | 1407 extensions::AppSyncData ExtensionService::GetAppSyncData( |
| 1424 const Extension& extension) const { | 1408 const Extension& extension) const { |
| 1425 return extensions::AppSyncData( | 1409 return extensions::AppSyncData( |
| 1426 extension, | 1410 extension, |
| 1427 IsExtensionEnabled(extension.id()), | 1411 IsExtensionEnabled(extension.id()), |
| 1428 IsIncognitoEnabled(extension.id()), | 1412 extension_util::IsIncognitoEnabled(extension.id(), this), |
| 1429 extension_prefs_->extension_sorting()->GetAppLaunchOrdinal( | 1413 extension_prefs_->extension_sorting()->GetAppLaunchOrdinal( |
| 1430 extension.id()), | 1414 extension.id()), |
| 1431 extension_prefs_->extension_sorting()->GetPageOrdinal(extension.id())); | 1415 extension_prefs_->extension_sorting()->GetPageOrdinal(extension.id())); |
| 1432 } | 1416 } |
| 1433 | 1417 |
| 1434 std::vector<extensions::ExtensionSyncData> | 1418 std::vector<extensions::ExtensionSyncData> |
| 1435 ExtensionService::GetExtensionSyncDataList() const { | 1419 ExtensionService::GetExtensionSyncDataList() const { |
| 1436 std::vector<extensions::ExtensionSyncData> extension_sync_list; | 1420 std::vector<extensions::ExtensionSyncData> extension_sync_list; |
| 1437 extension_sync_bundle_.GetExtensionSyncDataListHelper(extensions_, | 1421 extension_sync_bundle_.GetExtensionSyncDataListHelper(extensions_, |
| 1438 &extension_sync_list); | 1422 &extension_sync_list); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1563 EnableExtension(id); | 1547 EnableExtension(id); |
| 1564 else if (!IsPendingEnable(id)) | 1548 else if (!IsPendingEnable(id)) |
| 1565 DisableExtension(id, Extension::DISABLE_UNKNOWN_FROM_SYNC); | 1549 DisableExtension(id, Extension::DISABLE_UNKNOWN_FROM_SYNC); |
| 1566 | 1550 |
| 1567 // We need to cache some version information here because setting the | 1551 // We need to cache some version information here because setting the |
| 1568 // incognito flag invalidates the |extension| pointer (it reloads the | 1552 // incognito flag invalidates the |extension| pointer (it reloads the |
| 1569 // extension). | 1553 // extension). |
| 1570 bool extension_installed = (extension != NULL); | 1554 bool extension_installed = (extension != NULL); |
| 1571 int result = extension ? | 1555 int result = extension ? |
| 1572 extension->version()->CompareTo(extension_sync_data.version()) : 0; | 1556 extension->version()->CompareTo(extension_sync_data.version()) : 0; |
| 1573 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); | 1557 extension_util::SetIsIncognitoEnabled( |
| 1558 id, this, extension_sync_data.incognito_enabled()); |
| 1574 extension = NULL; // No longer safe to use. | 1559 extension = NULL; // No longer safe to use. |
| 1575 | 1560 |
| 1576 if (extension_installed) { | 1561 if (extension_installed) { |
| 1577 // If the extension is already installed, check if it's outdated. | 1562 // If the extension is already installed, check if it's outdated. |
| 1578 if (result < 0) { | 1563 if (result < 0) { |
| 1579 // Extension is outdated. | 1564 // Extension is outdated. |
| 1580 return false; | 1565 return false; |
| 1581 } | 1566 } |
| 1582 } else { | 1567 } else { |
| 1583 // TODO(akalin): Replace silent update with a list of enabled | 1568 // TODO(akalin): Replace silent update with a list of enabled |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1600 // never be removed (we'll never install a syncable version of the | 1585 // never be removed (we'll never install a syncable version of the |
| 1601 // extension), so that GetAllSyncData() continues to send it. | 1586 // extension), so that GetAllSyncData() continues to send it. |
| 1602 } | 1587 } |
| 1603 // Track pending extensions so that we can return them in GetAllSyncData(). | 1588 // Track pending extensions so that we can return them in GetAllSyncData(). |
| 1604 return false; | 1589 return false; |
| 1605 } | 1590 } |
| 1606 | 1591 |
| 1607 return true; | 1592 return true; |
| 1608 } | 1593 } |
| 1609 | 1594 |
| 1610 bool ExtensionService::IsIncognitoEnabled( | |
| 1611 const std::string& extension_id) const { | |
| 1612 const Extension* extension = GetInstalledExtension(extension_id); | |
| 1613 if (extension && !extension->can_be_incognito_enabled()) | |
| 1614 return false; | |
| 1615 // If this is an existing component extension we always allow it to | |
| 1616 // work in incognito mode. | |
| 1617 if (extension && extension->location() == Manifest::COMPONENT) | |
| 1618 return true; | |
| 1619 if (extension && extension->force_incognito_enabled()) | |
| 1620 return true; | |
| 1621 | |
| 1622 // Check the prefs. | |
| 1623 return extension_prefs_->IsIncognitoEnabled(extension_id); | |
| 1624 } | |
| 1625 | |
| 1626 void ExtensionService::SetIsIncognitoEnabled( | |
| 1627 const std::string& extension_id, bool enabled) { | |
| 1628 const Extension* extension = GetInstalledExtension(extension_id); | |
| 1629 if (extension && !extension->can_be_incognito_enabled()) | |
| 1630 return; | |
| 1631 if (extension && extension->location() == Manifest::COMPONENT) { | |
| 1632 // This shouldn't be called for component extensions unless they are | |
| 1633 // syncable. | |
| 1634 DCHECK(extensions::sync_helper::IsSyncable(extension)); | |
| 1635 | |
| 1636 // If we are here, make sure the we aren't trying to change the value. | |
| 1637 DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id)); | |
| 1638 | |
| 1639 return; | |
| 1640 } | |
| 1641 | |
| 1642 // Broadcast unloaded and loaded events to update browser state. Only bother | |
| 1643 // if the value changed and the extension is actually enabled, since there is | |
| 1644 // no UI otherwise. | |
| 1645 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); | |
| 1646 if (enabled == old_enabled) | |
| 1647 return; | |
| 1648 | |
| 1649 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); | |
| 1650 | |
| 1651 bool extension_is_enabled = extensions_.Contains(extension_id); | |
| 1652 | |
| 1653 // When we reload the extension the ID may be invalidated if we've passed it | |
| 1654 // by const ref everywhere. Make a copy to be safe. | |
| 1655 std::string id = extension_id; | |
| 1656 if (extension_is_enabled) | |
| 1657 ReloadExtension(id); | |
| 1658 | |
| 1659 // Reloading the extension invalidates the |extension| pointer. | |
| 1660 extension = GetInstalledExtension(id); | |
| 1661 if (extension) | |
| 1662 SyncExtensionChangeIfNeeded(*extension); | |
| 1663 } | |
| 1664 | |
| 1665 bool ExtensionService::CanCrossIncognito(const Extension* extension) const { | |
| 1666 // We allow the extension to see events and data from another profile iff it | |
| 1667 // uses "spanning" behavior and it has incognito access. "split" mode | |
| 1668 // extensions only see events for a matching profile. | |
| 1669 CHECK(extension); | |
| 1670 return IsIncognitoEnabled(extension->id()) && | |
| 1671 !extensions::IncognitoInfo::IsSplitMode(extension); | |
| 1672 } | |
| 1673 | |
| 1674 bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { | |
| 1675 if (extension->is_hosted_app()) | |
| 1676 return true; | |
| 1677 // Packaged apps and regular extensions need to be enabled specifically for | |
| 1678 // incognito (and split mode should be set). | |
| 1679 return extensions::IncognitoInfo::IsSplitMode(extension) && | |
| 1680 IsIncognitoEnabled(extension->id()); | |
| 1681 } | |
| 1682 | |
| 1683 void ExtensionService::OnExtensionMoved( | 1595 void ExtensionService::OnExtensionMoved( |
| 1684 const std::string& moved_extension_id, | 1596 const std::string& moved_extension_id, |
| 1685 const std::string& predecessor_extension_id, | 1597 const std::string& predecessor_extension_id, |
| 1686 const std::string& successor_extension_id) { | 1598 const std::string& successor_extension_id) { |
| 1687 extension_prefs_->extension_sorting()->OnExtensionMoved( | 1599 extension_prefs_->extension_sorting()->OnExtensionMoved( |
| 1688 moved_extension_id, | 1600 moved_extension_id, |
| 1689 predecessor_extension_id, | 1601 predecessor_extension_id, |
| 1690 successor_extension_id); | 1602 successor_extension_id); |
| 1691 | 1603 |
| 1692 const Extension* extension = GetInstalledExtension(moved_extension_id); | 1604 const Extension* extension = GetInstalledExtension(moved_extension_id); |
| 1693 if (extension) | 1605 if (extension) |
| 1694 SyncExtensionChangeIfNeeded(*extension); | 1606 SyncExtensionChangeIfNeeded(*extension); |
| 1695 } | 1607 } |
| 1696 | 1608 |
| 1697 bool ExtensionService::AllowFileAccess(const Extension* extension) const { | |
| 1698 return (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1699 switches::kDisableExtensionsFileAccessCheck) || | |
| 1700 extension_prefs_->AllowFileAccess(extension->id())); | |
| 1701 } | |
| 1702 | |
| 1703 void ExtensionService::SetAllowFileAccess(const Extension* extension, | |
| 1704 bool allow) { | |
| 1705 // Reload to update browser state. Only bother if the value changed and the | |
| 1706 // extension is actually enabled, since there is no UI otherwise. | |
| 1707 bool old_allow = AllowFileAccess(extension); | |
| 1708 if (allow == old_allow) | |
| 1709 return; | |
| 1710 | |
| 1711 extension_prefs_->SetAllowFileAccess(extension->id(), allow); | |
| 1712 | |
| 1713 bool extension_is_enabled = extensions_.Contains(extension->id()); | |
| 1714 if (extension_is_enabled) | |
| 1715 ReloadExtension(extension->id()); | |
| 1716 } | |
| 1717 | |
| 1718 // Some extensions will autoupdate themselves externally from Chrome. These | 1609 // Some extensions will autoupdate themselves externally from Chrome. These |
| 1719 // are typically part of some larger client application package. To support | 1610 // are typically part of some larger client application package. To support |
| 1720 // these, the extension will register its location in the the preferences file | 1611 // these, the extension will register its location in the the preferences file |
| 1721 // (and also, on Windows, in the registry) and this code will periodically | 1612 // (and also, on Windows, in the registry) and this code will periodically |
| 1722 // check that location for a .crx file, which it will then install locally if | 1613 // check that location for a .crx file, which it will then install locally if |
| 1723 // a new version is available. | 1614 // a new version is available. |
| 1724 // Errors are reported through ExtensionErrorReporter. Succcess is not | 1615 // Errors are reported through ExtensionErrorReporter. Succcess is not |
| 1725 // reported. | 1616 // reported. |
| 1726 void ExtensionService::CheckForExternalUpdates() { | 1617 void ExtensionService::CheckForExternalUpdates() { |
| 1727 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1618 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3222 } | 3113 } |
| 3223 | 3114 |
| 3224 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { | 3115 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
| 3225 update_observers_.AddObserver(observer); | 3116 update_observers_.AddObserver(observer); |
| 3226 } | 3117 } |
| 3227 | 3118 |
| 3228 void ExtensionService::RemoveUpdateObserver( | 3119 void ExtensionService::RemoveUpdateObserver( |
| 3229 extensions::UpdateObserver* observer) { | 3120 extensions::UpdateObserver* observer) { |
| 3230 update_observers_.RemoveObserver(observer); | 3121 update_observers_.RemoveObserver(observer); |
| 3231 } | 3122 } |
| OLD | NEW |