Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1704 void ExtensionService::CheckForUpdatesSoon() { | 1704 void ExtensionService::CheckForUpdatesSoon() { |
| 1705 if (updater()) { | 1705 if (updater()) { |
| 1706 updater()->CheckSoon(); | 1706 updater()->CheckSoon(); |
| 1707 } else { | 1707 } else { |
| 1708 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; | 1708 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; |
| 1709 } | 1709 } |
| 1710 } | 1710 } |
| 1711 | 1711 |
| 1712 namespace { | 1712 namespace { |
| 1713 bool IsSyncableNone(const Extension& extension) { return false; } | 1713 bool IsSyncableNone(const Extension& extension) { return false; } |
| 1714 } // namespace | 1714 } // namespace |
| 1715 | 1715 |
| 1716 ExtensionService::SyncBundle::SyncBundle() | 1716 ExtensionService::SyncBundle::SyncBundle() |
| 1717 : filter(IsSyncableNone), | 1717 : filter(IsSyncableNone), |
| 1718 sync_processor(NULL) { | 1718 sync_processor(NULL) { |
| 1719 } | 1719 } |
| 1720 | 1720 |
| 1721 ExtensionService::SyncBundle::~SyncBundle() { | 1721 ExtensionService::SyncBundle::~SyncBundle() { |
| 1722 } | 1722 } |
| 1723 | 1723 |
| 1724 bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const { | 1724 bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1935 // Handle uninstalls first. | 1935 // Handle uninstalls first. |
| 1936 if (extension_sync_data.uninstalled()) { | 1936 if (extension_sync_data.uninstalled()) { |
| 1937 std::string error; | 1937 std::string error; |
| 1938 if (!UninstallExtensionHelper(this, id)) { | 1938 if (!UninstallExtensionHelper(this, id)) { |
| 1939 LOG(WARNING) << "Could not uninstall extension " << id | 1939 LOG(WARNING) << "Could not uninstall extension " << id |
| 1940 << " for sync"; | 1940 << " for sync"; |
| 1941 } | 1941 } |
| 1942 return; | 1942 return; |
| 1943 } | 1943 } |
| 1944 | 1944 |
| 1945 // Set user settings. | |
| 1946 if (extension_sync_data.enabled()) { | |
| 1947 EnableExtension(id); | |
| 1948 } else { | |
| 1949 DisableExtension(id); | |
| 1950 } | |
| 1951 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); | |
|
Finnur
2011/10/27 15:23:32
I had to move this down to the bottom of the funct
akalin
2011/10/31 20:26:49
I'd prefer leaving this block as is, but caching a
| |
| 1952 | |
| 1953 if (extension) { | 1945 if (extension) { |
| 1954 // If the extension is already installed, check if it's outdated. | 1946 // If the extension is already installed, check if it's outdated. |
| 1955 int result = extension->version()->CompareTo(extension_sync_data.version()); | 1947 int result = extension->version()->CompareTo(extension_sync_data.version()); |
| 1956 if (result < 0) { | 1948 if (result < 0) { |
| 1957 // Extension is outdated. | 1949 // Extension is outdated. |
| 1958 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; | 1950 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; |
| 1959 CheckForUpdatesSoon(); | 1951 CheckForUpdatesSoon(); |
| 1960 } | 1952 } |
| 1961 } else { | 1953 } else { |
| 1962 // TODO(akalin): Replace silent update with a list of enabled | 1954 // TODO(akalin): Replace silent update with a list of enabled |
| 1963 // permissions. | 1955 // permissions. |
| 1964 const bool kInstallSilently = true; | 1956 const bool kInstallSilently = true; |
| 1965 if (!pending_extension_manager()->AddFromSync( | 1957 if (!pending_extension_manager()->AddFromSync( |
| 1966 id, | 1958 id, |
| 1967 extension_sync_data.update_url(), | 1959 extension_sync_data.update_url(), |
| 1968 bundle.filter, | 1960 bundle.filter, |
| 1969 kInstallSilently)) { | 1961 kInstallSilently)) { |
| 1970 LOG(WARNING) << "Could not add pending extension for " << id; | 1962 LOG(WARNING) << "Could not add pending extension for " << id; |
| 1971 // This means that the extension is already pending installation, with a | 1963 // This means that the extension is already pending installation, with a |
| 1972 // non-INTERNAL location. Add to pending_sync_data, even though it will | 1964 // non-INTERNAL location. Add to pending_sync_data, even though it will |
| 1973 // never be removed (we'll never install a syncable version of the | 1965 // never be removed (we'll never install a syncable version of the |
| 1974 // extension), so that GetAllSyncData() continues to send it. | 1966 // extension), so that GetAllSyncData() continues to send it. |
| 1975 } | 1967 } |
| 1976 // Track pending extensions so that we can return them in GetAllSyncData(). | 1968 // Track pending extensions so that we can return them in GetAllSyncData(). |
| 1977 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; | 1969 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; |
| 1978 CheckForUpdatesSoon(); | 1970 CheckForUpdatesSoon(); |
| 1979 } | 1971 } |
| 1972 | |
| 1973 // Set user settings. | |
| 1974 if (extension_sync_data.enabled()) { | |
| 1975 EnableExtension(id); | |
| 1976 } else { | |
| 1977 DisableExtension(id); | |
| 1978 } | |
| 1979 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); | |
| 1980 } | 1980 } |
| 1981 | 1981 |
| 1982 bool ExtensionService::IsIncognitoEnabled( | 1982 bool ExtensionService::IsIncognitoEnabled( |
| 1983 const std::string& extension_id) const { | 1983 const std::string& extension_id) const { |
| 1984 // If this is an existing component extension we always allow it to | 1984 // If this is an existing component extension we always allow it to |
| 1985 // work in incognito mode. | 1985 // work in incognito mode. |
| 1986 const Extension* extension = GetInstalledExtension(extension_id); | 1986 const Extension* extension = GetInstalledExtension(extension_id); |
| 1987 if (extension && extension->location() == Extension::COMPONENT) | 1987 if (extension && extension->location() == Extension::COMPONENT) |
| 1988 return true; | 1988 return true; |
| 1989 | 1989 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2002 | 2002 |
| 2003 // Broadcast unloaded and loaded events to update browser state. Only bother | 2003 // Broadcast unloaded and loaded events to update browser state. Only bother |
| 2004 // if the value changed and the extension is actually enabled, since there is | 2004 // if the value changed and the extension is actually enabled, since there is |
| 2005 // no UI otherwise. | 2005 // no UI otherwise. |
| 2006 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); | 2006 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); |
| 2007 if (enabled == old_enabled) | 2007 if (enabled == old_enabled) |
| 2008 return; | 2008 return; |
| 2009 | 2009 |
| 2010 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); | 2010 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); |
| 2011 | 2011 |
| 2012 // If the extension is enabled (and not terminated), unload and | 2012 bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(), |
| 2013 // reload it to update UI. | 2013 extension) != extensions_.end(); |
| 2014 const Extension* enabled_extension = GetExtensionById(extension_id, false); | 2014 if (extension_is_enabled) |
| 2015 if (enabled_extension) { | 2015 ReloadExtension(extension->id()); |
| 2016 NotifyExtensionUnloaded( | |
| 2017 enabled_extension, extension_misc::UNLOAD_REASON_DISABLE); | |
| 2018 NotifyExtensionLoaded(enabled_extension); | |
| 2019 } | |
| 2020 | |
| 2021 if (extension) | |
| 2022 SyncExtensionChangeIfNeeded(*extension); | |
|
Finnur
2011/10/27 15:23:32
These last two lines are not needed because Reload
| |
| 2023 } | 2016 } |
| 2024 | 2017 |
| 2025 bool ExtensionService::CanCrossIncognito(const Extension* extension) { | 2018 bool ExtensionService::CanCrossIncognito(const Extension* extension) { |
| 2026 // We allow the extension to see events and data from another profile iff it | 2019 // We allow the extension to see events and data from another profile iff it |
| 2027 // uses "spanning" behavior and it has incognito access. "split" mode | 2020 // uses "spanning" behavior and it has incognito access. "split" mode |
| 2028 // extensions only see events for a matching profile. | 2021 // extensions only see events for a matching profile. |
| 2029 CHECK(extension); | 2022 CHECK(extension); |
| 2030 return IsIncognitoEnabled(extension->id()) && | 2023 return IsIncognitoEnabled(extension->id()) && |
| 2031 !extension->incognito_split_mode(); | 2024 !extension->incognito_split_mode(); |
| 2032 } | 2025 } |
| (...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3014 | 3007 |
| 3015 ExtensionService::NaClModuleInfoList::iterator | 3008 ExtensionService::NaClModuleInfoList::iterator |
| 3016 ExtensionService::FindNaClModule(const GURL& url) { | 3009 ExtensionService::FindNaClModule(const GURL& url) { |
| 3017 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 3010 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 3018 iter != nacl_module_list_.end(); ++iter) { | 3011 iter != nacl_module_list_.end(); ++iter) { |
| 3019 if (iter->url == url) | 3012 if (iter->url == url) |
| 3020 return iter; | 3013 return iter; |
| 3021 } | 3014 } |
| 3022 return nacl_module_list_.end(); | 3015 return nacl_module_list_.end(); |
| 3023 } | 3016 } |
| OLD | NEW |