| 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/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 } | 890 } |
| 891 | 891 |
| 892 // Extract the data we need for sync now, but don't actually sync until we've | 892 // Extract the data we need for sync now, but don't actually sync until we've |
| 893 // completed the uninstallation. | 893 // completed the uninstallation. |
| 894 SyncBundle* sync_bundle = GetSyncBundleForExtension(*extension); | 894 SyncBundle* sync_bundle = GetSyncBundleForExtension(*extension); |
| 895 | 895 |
| 896 SyncChange sync_change; | 896 SyncChange sync_change; |
| 897 if (sync_bundle) { | 897 if (sync_bundle) { |
| 898 ExtensionSyncData extension_sync_data(*extension, | 898 ExtensionSyncData extension_sync_data(*extension, |
| 899 IsExtensionEnabled(extension_id), | 899 IsExtensionEnabled(extension_id), |
| 900 IsIncognitoEnabled(extension_id)); | 900 IsIncognitoEnabled(extension_id), |
| 901 GetAppLaunchIndex(extension_id), |
| 902 GetPageIndex(extension_id)); |
| 901 sync_change = extension_sync_data.GetSyncChange(SyncChange::ACTION_DELETE); | 903 sync_change = extension_sync_data.GetSyncChange(SyncChange::ACTION_DELETE); |
| 902 } | 904 } |
| 903 | 905 |
| 904 UninstalledExtensionInfo uninstalled_extension_info(*extension); | 906 UninstalledExtensionInfo uninstalled_extension_info(*extension); |
| 905 | 907 |
| 906 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", | 908 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", |
| 907 extension->GetType(), 100); | 909 extension->GetType(), 100); |
| 908 RecordPermissionMessagesHistogram( | 910 RecordPermissionMessagesHistogram( |
| 909 extension, "Extensions.Permissions_Uninstall"); | 911 extension, "Extensions.Permissions_Uninstall"); |
| 910 | 912 |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 bool ExtensionService::SyncBundle::HasPendingExtensionId(const std::string& id) | 1730 bool ExtensionService::SyncBundle::HasPendingExtensionId(const std::string& id) |
| 1729 const { | 1731 const { |
| 1730 return pending_sync_data.find(id) != pending_sync_data.end(); | 1732 return pending_sync_data.find(id) != pending_sync_data.end(); |
| 1731 } | 1733 } |
| 1732 | 1734 |
| 1733 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { | 1735 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { |
| 1734 SyncBundle* sync_bundle = GetSyncBundleForExtension(extension); | 1736 SyncBundle* sync_bundle = GetSyncBundleForExtension(extension); |
| 1735 if (sync_bundle) { | 1737 if (sync_bundle) { |
| 1736 ExtensionSyncData extension_sync_data(extension, | 1738 ExtensionSyncData extension_sync_data(extension, |
| 1737 IsExtensionEnabled(extension.id()), | 1739 IsExtensionEnabled(extension.id()), |
| 1738 IsIncognitoEnabled(extension.id())); | 1740 IsIncognitoEnabled(extension.id()), |
| 1741 GetAppLaunchIndex(extension.id()), |
| 1742 GetPageIndex(extension.id())); |
| 1739 | 1743 |
| 1740 SyncChangeList sync_change_list(1, extension_sync_data.GetSyncChange( | 1744 SyncChangeList sync_change_list(1, extension_sync_data.GetSyncChange( |
| 1741 sync_bundle->HasExtensionId(extension.id()) ? | 1745 sync_bundle->HasExtensionId(extension.id()) ? |
| 1742 SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD)); | 1746 SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD)); |
| 1743 sync_bundle->sync_processor->ProcessSyncChanges( | 1747 sync_bundle->sync_processor->ProcessSyncChanges( |
| 1744 FROM_HERE, sync_change_list); | 1748 FROM_HERE, sync_change_list); |
| 1745 sync_bundle->synced_extensions.insert(extension.id()); | 1749 sync_bundle->synced_extensions.insert(extension.id()); |
| 1746 sync_bundle->pending_sync_data.erase(extension.id()); | 1750 sync_bundle->pending_sync_data.erase(extension.id()); |
| 1747 } | 1751 } |
| 1748 } | 1752 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1873 SyncBundle* bundle = GetSyncBundleForExtensionSyncData(extension_sync_data); | 1877 SyncBundle* bundle = GetSyncBundleForExtensionSyncData(extension_sync_data); |
| 1874 CHECK(bundle); | 1878 CHECK(bundle); |
| 1875 | 1879 |
| 1876 if (extension_sync_data.uninstalled()) | 1880 if (extension_sync_data.uninstalled()) |
| 1877 bundle->synced_extensions.erase(extension_sync_data.id()); | 1881 bundle->synced_extensions.erase(extension_sync_data.id()); |
| 1878 else | 1882 else |
| 1879 bundle->synced_extensions.insert(extension_sync_data.id()); | 1883 bundle->synced_extensions.insert(extension_sync_data.id()); |
| 1880 ProcessExtensionSyncData(extension_sync_data, *bundle); | 1884 ProcessExtensionSyncData(extension_sync_data, *bundle); |
| 1881 } | 1885 } |
| 1882 | 1886 |
| 1887 // Because the sync data includes the positions of applications it is |
| 1888 // possible for the applications to have been reordered due to the sync. |
| 1889 NotificationService::current()->Notify( |
| 1890 chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, |
| 1891 Source<ExtensionService>(this), |
| 1892 NotificationService::NoDetails()); |
| 1893 |
| 1883 return SyncError(); | 1894 return SyncError(); |
| 1884 } | 1895 } |
| 1885 | 1896 |
| 1886 void ExtensionService::GetSyncDataListHelper( | 1897 void ExtensionService::GetSyncDataListHelper( |
| 1887 const ExtensionList& extensions, | 1898 const ExtensionList& extensions, |
| 1888 const SyncBundle& bundle, | 1899 const SyncBundle& bundle, |
| 1889 std::vector<ExtensionSyncData>* sync_data_list) const { | 1900 std::vector<ExtensionSyncData>* sync_data_list) const { |
| 1890 for (ExtensionList::const_iterator it = extensions.begin(); | 1901 for (ExtensionList::const_iterator it = extensions.begin(); |
| 1891 it != extensions.end(); ++it) { | 1902 it != extensions.end(); ++it) { |
| 1892 const Extension& extension = **it; | 1903 const Extension& extension = **it; |
| 1893 if (bundle.filter(extension) && | 1904 if (bundle.filter(extension) && |
| 1894 // If we have pending extension data for this extension, then this | 1905 // If we have pending extension data for this extension, then this |
| 1895 // version is out of date. We'll sync back the version we got from | 1906 // version is out of date. We'll sync back the version we got from |
| 1896 // sync. | 1907 // sync. |
| 1897 !bundle.HasPendingExtensionId(extension.id())) { | 1908 !bundle.HasPendingExtensionId(extension.id())) { |
| 1898 sync_data_list->push_back( | 1909 sync_data_list->push_back( |
| 1899 ExtensionSyncData(extension, | 1910 ExtensionSyncData(extension, |
| 1900 IsExtensionEnabled(extension.id()), | 1911 IsExtensionEnabled(extension.id()), |
| 1901 IsIncognitoEnabled(extension.id()))); | 1912 IsIncognitoEnabled(extension.id()), |
| 1913 GetAppLaunchIndex(extension.id()), |
| 1914 GetPageIndex(extension.id()))); |
| 1902 } | 1915 } |
| 1903 } | 1916 } |
| 1904 } | 1917 } |
| 1905 | 1918 |
| 1906 std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList( | 1919 std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList( |
| 1907 const SyncBundle& bundle) const { | 1920 const SyncBundle& bundle) const { |
| 1908 std::vector<ExtensionSyncData> extension_sync_list; | 1921 std::vector<ExtensionSyncData> extension_sync_list; |
| 1909 GetSyncDataListHelper(extensions_, bundle, &extension_sync_list); | 1922 GetSyncDataListHelper(extensions_, bundle, &extension_sync_list); |
| 1910 GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list); | 1923 GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list); |
| 1911 GetSyncDataListHelper(terminated_extensions_, bundle, &extension_sync_list); | 1924 GetSyncDataListHelper(terminated_extensions_, bundle, &extension_sync_list); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1942 return; | 1955 return; |
| 1943 } | 1956 } |
| 1944 | 1957 |
| 1945 // Set user settings. | 1958 // Set user settings. |
| 1946 if (extension_sync_data.enabled()) { | 1959 if (extension_sync_data.enabled()) { |
| 1947 EnableExtension(id); | 1960 EnableExtension(id); |
| 1948 } else { | 1961 } else { |
| 1949 DisableExtension(id); | 1962 DisableExtension(id); |
| 1950 } | 1963 } |
| 1951 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); | 1964 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); |
| 1965 SetAppLaunchIndex(id, extension_sync_data.app_launch_index()); |
| 1966 SetPageIndex(id, extension_sync_data.page_index()); |
| 1952 | 1967 |
| 1953 if (extension) { | 1968 if (extension) { |
| 1954 // If the extension is already installed, check if it's outdated. | 1969 // If the extension is already installed, check if it's outdated. |
| 1955 int result = extension->version()->CompareTo(extension_sync_data.version()); | 1970 int result = extension->version()->CompareTo(extension_sync_data.version()); |
| 1956 if (result < 0) { | 1971 if (result < 0) { |
| 1957 // Extension is outdated. | 1972 // Extension is outdated. |
| 1958 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; | 1973 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; |
| 1959 CheckForUpdatesSoon(); | 1974 CheckForUpdatesSoon(); |
| 1960 } | 1975 } |
| 1961 } else { | 1976 } else { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2033 | 2048 |
| 2034 bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { | 2049 bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { |
| 2035 if (extension->is_hosted_app()) | 2050 if (extension->is_hosted_app()) |
| 2036 return true; | 2051 return true; |
| 2037 // Packaged apps and regular extensions need to be enabled specifically for | 2052 // Packaged apps and regular extensions need to be enabled specifically for |
| 2038 // incognito (and split mode should be set). | 2053 // incognito (and split mode should be set). |
| 2039 return extension->incognito_split_mode() && | 2054 return extension->incognito_split_mode() && |
| 2040 IsIncognitoEnabled(extension->id()); | 2055 IsIncognitoEnabled(extension->id()); |
| 2041 } | 2056 } |
| 2042 | 2057 |
| 2058 void ExtensionService::SetAppLauncherOrder( |
| 2059 const std::vector<std::string>& extension_ids) { |
| 2060 extension_prefs_->SetAppLauncherOrder(extension_ids); |
| 2061 |
| 2062 for (size_t i=0; i < extension_ids.size(); ++i) { |
| 2063 SetAppLaunchIndex(extension_ids[i], i); |
| 2064 } |
| 2065 } |
| 2066 |
| 2067 int32 ExtensionService::GetAppLaunchIndex(const std::string& extension_id) |
| 2068 const { |
| 2069 return extension_prefs_->GetAppLaunchIndex(extension_id); |
| 2070 } |
| 2071 |
| 2072 void ExtensionService::SetAppLaunchIndex(const std::string& extension_id, |
| 2073 int32 app_launch_index) { |
| 2074 extension_prefs_->SetAppLaunchIndex(extension_id, app_launch_index); |
| 2075 |
| 2076 const Extension* extension = GetInstalledExtension(extension_id); |
| 2077 if (extension) { |
| 2078 SyncExtensionChangeIfNeeded(*extension); |
| 2079 } |
| 2080 } |
| 2081 |
| 2082 int32 ExtensionService::GetPageIndex(const std::string& extension_id) const { |
| 2083 return extension_prefs_->GetPageIndex(extension_id); |
| 2084 } |
| 2085 |
| 2086 void ExtensionService::SetPageIndex(const std::string& extension_id, |
| 2087 int32 page_index) { |
| 2088 extension_prefs_->SetPageIndex(extension_id, page_index); |
| 2089 |
| 2090 const Extension* extension = GetInstalledExtension(extension_id); |
| 2091 if (extension) { |
| 2092 SyncExtensionChangeIfNeeded(*extension); |
| 2093 } |
| 2094 } |
| 2095 |
| 2043 bool ExtensionService::AllowFileAccess(const Extension* extension) { | 2096 bool ExtensionService::AllowFileAccess(const Extension* extension) { |
| 2044 return (CommandLine::ForCurrentProcess()->HasSwitch( | 2097 return (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2045 switches::kDisableExtensionsFileAccessCheck) || | 2098 switches::kDisableExtensionsFileAccessCheck) || |
| 2046 extension_prefs_->AllowFileAccess(extension->id())); | 2099 extension_prefs_->AllowFileAccess(extension->id())); |
| 2047 } | 2100 } |
| 2048 | 2101 |
| 2049 void ExtensionService::SetAllowFileAccess(const Extension* extension, | 2102 void ExtensionService::SetAllowFileAccess(const Extension* extension, |
| 2050 bool allow) { | 2103 bool allow) { |
| 2051 // Reload to update browser state. Only bother if the value changed and the | 2104 // Reload to update browser state. Only bother if the value changed and the |
| 2052 // extension is actually enabled, since there is no UI otherwise. | 2105 // extension is actually enabled, since there is no UI otherwise. |
| (...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2900 | 2953 |
| 2901 ExtensionService::NaClModuleInfoList::iterator | 2954 ExtensionService::NaClModuleInfoList::iterator |
| 2902 ExtensionService::FindNaClModule(const GURL& url) { | 2955 ExtensionService::FindNaClModule(const GURL& url) { |
| 2903 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2956 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2904 iter != nacl_module_list_.end(); ++iter) { | 2957 iter != nacl_module_list_.end(); ++iter) { |
| 2905 if (iter->url == url) | 2958 if (iter->url == url) |
| 2906 return iter; | 2959 return iter; |
| 2907 } | 2960 } |
| 2908 return nacl_module_list_.end(); | 2961 return nacl_module_list_.end(); |
| 2909 } | 2962 } |
| OLD | NEW |