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