| 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/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // TODO(rdevlin.cronin): Remove these once all references have been removed as | 27 // TODO(rdevlin.cronin): Remove these once all references have been removed as |
| 28 // part of crbug.com/159265. | 28 // part of crbug.com/159265. |
| 29 #include "chrome/common/extensions/api/extension_action/action_info.h" | 29 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 30 #include "chrome/common/extensions/api/extension_action/page_action_handler.h" | 30 #include "chrome/common/extensions/api/extension_action/page_action_handler.h" |
| 31 #include "chrome/common/extensions/api/icons/icons_handler.h" | 31 #include "chrome/common/extensions/api/icons/icons_handler.h" |
| 32 #include "chrome/common/extensions/api/plugins/plugins_handler.h" | 32 #include "chrome/common/extensions/api/plugins/plugins_handler.h" |
| 33 #include "chrome/common/extensions/api/themes/theme_handler.h" | 33 #include "chrome/common/extensions/api/themes/theme_handler.h" |
| 34 #include "chrome/common/extensions/background_info.h" | 34 #include "chrome/common/extensions/background_info.h" |
| 35 #include "chrome/common/extensions/csp_handler.h" | 35 #include "chrome/common/extensions/csp_handler.h" |
| 36 #include "chrome/common/extensions/csp_validator.h" | 36 #include "chrome/common/extensions/csp_validator.h" |
| 37 #include "chrome/common/extensions/extension_icon_set.h" |
| 37 #include "chrome/common/extensions/extension_manifest_constants.h" | 38 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 38 #include "chrome/common/extensions/feature_switch.h" | 39 #include "chrome/common/extensions/feature_switch.h" |
| 39 #include "chrome/common/extensions/features/base_feature_provider.h" | 40 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 40 #include "chrome/common/extensions/features/feature.h" | 41 #include "chrome/common/extensions/features/feature.h" |
| 41 #include "chrome/common/extensions/incognito_handler.h" | 42 #include "chrome/common/extensions/incognito_handler.h" |
| 42 #include "chrome/common/extensions/manifest.h" | 43 #include "chrome/common/extensions/manifest.h" |
| 43 #include "chrome/common/extensions/manifest_handler.h" | 44 #include "chrome/common/extensions/manifest_handler.h" |
| 44 #include "chrome/common/extensions/manifest_handler_helpers.h" | 45 #include "chrome/common/extensions/manifest_handler_helpers.h" |
| 45 #include "chrome/common/extensions/manifest_url_handler.h" | 46 #include "chrome/common/extensions/manifest_url_handler.h" |
| 46 #include "chrome/common/extensions/permissions/api_permission_set.h" | 47 #include "chrome/common/extensions/permissions/api_permission_set.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 if ((*i)->ManifestEntryForbidden()) { | 161 if ((*i)->ManifestEntryForbidden()) { |
| 161 *error = ErrorUtils::FormatErrorMessageUTF16( | 162 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 162 errors::kPermissionNotAllowedInManifest, | 163 errors::kPermissionNotAllowedInManifest, |
| 163 (*i)->info()->name()); | 164 (*i)->info()->name()); |
| 164 return true; | 165 return true; |
| 165 } | 166 } |
| 166 } | 167 } |
| 167 return false; | 168 return false; |
| 168 } | 169 } |
| 169 | 170 |
| 170 // Helper method to load an ExtensionAction from the page_action, script_badge, | |
| 171 // browser_action, or system_indicator entries in the manifest. | |
| 172 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and | |
| 173 // SystemIndicator have been moved out of Extension. | |
| 174 scoped_ptr<ActionInfo> LoadExtensionActionInfoHelper( | |
| 175 const Extension* extension, | |
| 176 const DictionaryValue* extension_action, | |
| 177 string16* error) { | |
| 178 return manifest_handler_helpers::LoadActionInfo( | |
| 179 extension, extension_action, error); | |
| 180 } | |
| 181 | |
| 182 } // namespace | 171 } // namespace |
| 183 | 172 |
| 184 #if defined(OS_WIN) | 173 #if defined(OS_WIN) |
| 185 const char Extension::kExtensionRegistryPath[] = | 174 const char Extension::kExtensionRegistryPath[] = |
| 186 "Software\\Google\\Chrome\\Extensions"; | 175 "Software\\Google\\Chrome\\Extensions"; |
| 187 #endif | 176 #endif |
| 188 | 177 |
| 189 const char Extension::kMimeType[] = "application/x-chrome-extension"; | 178 const char Extension::kMimeType[] = "application/x-chrome-extension"; |
| 190 | 179 |
| 191 const int Extension::kValidWebExtentSchemes = | 180 const int Extension::kValidWebExtentSchemes = |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 ContainsManifestForbiddenPermission(optional_api_permissions, error)) { | 1295 ContainsManifestForbiddenPermission(optional_api_permissions, error)) { |
| 1307 return false; | 1296 return false; |
| 1308 } | 1297 } |
| 1309 | 1298 |
| 1310 if (!LoadAppIsolation(error)) | 1299 if (!LoadAppIsolation(error)) |
| 1311 return false; | 1300 return false; |
| 1312 | 1301 |
| 1313 if (!LoadSharedFeatures(error)) | 1302 if (!LoadSharedFeatures(error)) |
| 1314 return false; | 1303 return false; |
| 1315 | 1304 |
| 1316 if (!LoadExtensionFeatures(error)) | 1305 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
| 1317 return false; | 1306 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
| 1307 &converted_from_user_script_); |
| 1318 | 1308 |
| 1319 if (!LoadManagedModeFeatures(error)) | 1309 if (!LoadManagedModeFeatures(error)) |
| 1320 return false; | 1310 return false; |
| 1321 | 1311 |
| 1322 if (HasMultipleUISurfaces()) { | 1312 if (HasMultipleUISurfaces()) { |
| 1323 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); | 1313 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); |
| 1324 return false; | 1314 return false; |
| 1325 } | 1315 } |
| 1326 | 1316 |
| 1327 finished_parsing_manifest_ = true; | 1317 finished_parsing_manifest_ = true; |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1906 offline_enabled_ = is_platform_app(); | 1896 offline_enabled_ = is_platform_app(); |
| 1907 return true; | 1897 return true; |
| 1908 } | 1898 } |
| 1909 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { | 1899 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { |
| 1910 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled); | 1900 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled); |
| 1911 return false; | 1901 return false; |
| 1912 } | 1902 } |
| 1913 return true; | 1903 return true; |
| 1914 } | 1904 } |
| 1915 | 1905 |
| 1916 bool Extension::LoadExtensionFeatures(string16* error) { | |
| 1917 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | |
| 1918 manifest_->GetBoolean(keys::kConvertedFromUserScript, | |
| 1919 &converted_from_user_script_); | |
| 1920 | |
| 1921 return LoadSystemIndicator(error); | |
| 1922 } | |
| 1923 | |
| 1924 bool Extension::LoadSystemIndicator(string16* error) { | |
| 1925 if (!manifest_->HasKey(keys::kSystemIndicator)) { | |
| 1926 // There was no manifest entry for the system indicator. | |
| 1927 return true; | |
| 1928 } | |
| 1929 | |
| 1930 const DictionaryValue* system_indicator_value = NULL; | |
| 1931 if (!manifest_->GetDictionary(keys::kSystemIndicator, | |
| 1932 &system_indicator_value)) { | |
| 1933 *error = ASCIIToUTF16(errors::kInvalidSystemIndicator); | |
| 1934 return false; | |
| 1935 } | |
| 1936 | |
| 1937 system_indicator_info_ = LoadExtensionActionInfoHelper( | |
| 1938 this, system_indicator_value, error); | |
| 1939 | |
| 1940 if (!system_indicator_info_.get()) { | |
| 1941 return false; | |
| 1942 } | |
| 1943 | |
| 1944 // Because the manifest was successfully parsed, auto-grant the permission. | |
| 1945 // TODO(dewittj) Add this for all extension action APIs. | |
| 1946 initial_api_permissions()->insert(APIPermission::kSystemIndicator); | |
| 1947 | |
| 1948 return true; | |
| 1949 } | |
| 1950 | |
| 1951 bool Extension::HasMultipleUISurfaces() const { | 1906 bool Extension::HasMultipleUISurfaces() const { |
| 1952 int num_surfaces = 0; | 1907 int num_surfaces = 0; |
| 1953 | 1908 |
| 1954 if (ActionInfo::GetPageActionInfo(this)) | 1909 if (ActionInfo::GetPageActionInfo(this)) |
| 1955 ++num_surfaces; | 1910 ++num_surfaces; |
| 1956 | 1911 |
| 1957 if (ActionInfo::GetBrowserActionInfo(this)) | 1912 if (ActionInfo::GetBrowserActionInfo(this)) |
| 1958 ++num_surfaces; | 1913 ++num_surfaces; |
| 1959 | 1914 |
| 1960 if (is_app()) | 1915 if (is_app()) |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2123 | 2078 |
| 2124 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 2079 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 2125 const Extension* extension, | 2080 const Extension* extension, |
| 2126 const PermissionSet* permissions, | 2081 const PermissionSet* permissions, |
| 2127 Reason reason) | 2082 Reason reason) |
| 2128 : reason(reason), | 2083 : reason(reason), |
| 2129 extension(extension), | 2084 extension(extension), |
| 2130 permissions(permissions) {} | 2085 permissions(permissions) {} |
| 2131 | 2086 |
| 2132 } // namespace extensions | 2087 } // namespace extensions |
| OLD | NEW |