Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 12253022: Manifest handler for all keys background-related. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_path.h" 10 #include "base/file_path.h"
(...skipping 11 matching lines...) Expand all
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "base/version.h" 23 #include "base/version.h"
24 #include "chrome/common/chrome_constants.h" 24 #include "chrome/common/chrome_constants.h"
25 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/chrome_version_info.h" 26 #include "chrome/common/chrome_version_info.h"
27 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and 27 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and
28 // SystemIndicator have been moved out of Extension. 28 // SystemIndicator have been moved out of Extension.
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/themes/theme_handler.h" 31 #include "chrome/common/extensions/api/themes/theme_handler.h"
32 // TODO(yoz): should not need this include.
33 #include "chrome/common/extensions/background_info.h"
32 #include "chrome/common/extensions/csp_validator.h" 34 #include "chrome/common/extensions/csp_validator.h"
33 #include "chrome/common/extensions/extension_manifest_constants.h" 35 #include "chrome/common/extensions/extension_manifest_constants.h"
34 #include "chrome/common/extensions/extension_resource.h" 36 #include "chrome/common/extensions/extension_resource.h"
35 #include "chrome/common/extensions/feature_switch.h" 37 #include "chrome/common/extensions/feature_switch.h"
36 #include "chrome/common/extensions/features/base_feature_provider.h" 38 #include "chrome/common/extensions/features/base_feature_provider.h"
37 #include "chrome/common/extensions/features/feature.h" 39 #include "chrome/common/extensions/features/feature.h"
38 #include "chrome/common/extensions/manifest.h" 40 #include "chrome/common/extensions/manifest.h"
39 #include "chrome/common/extensions/manifest_handler.h" 41 #include "chrome/common/extensions/manifest_handler.h"
40 #include "chrome/common/extensions/manifest_handler_helpers.h" 42 #include "chrome/common/extensions/manifest_handler_helpers.h"
41 #include "chrome/common/extensions/manifest_url_handler.h" 43 #include "chrome/common/extensions/manifest_url_handler.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // Note: Component extensions have this right implicitly and do not need to be 167 // Note: Component extensions have this right implicitly and do not need to be
166 // added to this list. 168 // added to this list.
167 Extension::ScriptingWhitelist scripting_whitelist_; 169 Extension::ScriptingWhitelist scripting_whitelist_;
168 }; 170 };
169 171
170 bool ReadLaunchDimension(const extensions::Manifest* manifest, 172 bool ReadLaunchDimension(const extensions::Manifest* manifest,
171 const char* key, 173 const char* key,
172 int* target, 174 int* target,
173 bool is_valid_container, 175 bool is_valid_container,
174 string16* error) { 176 string16* error) {
175 Value* temp = NULL; 177 const Value* temp = NULL;
176 if (manifest->Get(key, &temp)) { 178 if (manifest->Get(key, &temp)) {
177 if (!is_valid_container) { 179 if (!is_valid_container) {
178 *error = ErrorUtils::FormatErrorMessageUTF16( 180 *error = ErrorUtils::FormatErrorMessageUTF16(
179 errors::kInvalidLaunchValueContainer, 181 errors::kInvalidLaunchValueContainer,
180 key); 182 key);
181 return false; 183 return false;
182 } 184 }
183 if (!temp->GetAsInteger(target) || *target < 0) { 185 if (!temp->GetAsInteger(target) || *target < 0) {
184 *target = 0; 186 *target = 0;
185 *error = ErrorUtils::FormatErrorMessageUTF16( 187 *error = ErrorUtils::FormatErrorMessageUTF16(
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 // static 589 // static
588 const Extension::ScriptingWhitelist* Extension::GetScriptingWhitelist() { 590 const Extension::ScriptingWhitelist* Extension::GetScriptingWhitelist() {
589 return ExtensionConfig::GetInstance()->whitelist(); 591 return ExtensionConfig::GetInstance()->whitelist();
590 } 592 }
591 593
592 bool Extension::ParsePermissions(const char* key, 594 bool Extension::ParsePermissions(const char* key,
593 string16* error, 595 string16* error,
594 APIPermissionSet* api_permissions, 596 APIPermissionSet* api_permissions,
595 URLPatternSet* host_permissions) { 597 URLPatternSet* host_permissions) {
596 if (manifest_->HasKey(key)) { 598 if (manifest_->HasKey(key)) {
597 ListValue* permissions = NULL; 599 const ListValue* permissions = NULL;
598 if (!manifest_->GetList(key, &permissions)) { 600 if (!manifest_->GetList(key, &permissions)) {
599 *error = ErrorUtils::FormatErrorMessageUTF16( 601 *error = ErrorUtils::FormatErrorMessageUTF16(
600 errors::kInvalidPermissions, ""); 602 errors::kInvalidPermissions, "");
601 return false; 603 return false;
602 } 604 }
603 605
604 // NOTE: We need to get the APIPermission before we check if features 606 // NOTE: We need to get the APIPermission before we check if features
605 // associated with them are available because the feature system does not 607 // associated with them are available because the feature system does not
606 // know about aliases. 608 // know about aliases.
607 609
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 return !content_pack_site_list_.empty(); 1189 return !content_pack_site_list_.empty();
1188 } 1190 }
1189 1191
1190 ExtensionResource Extension::GetContentPackSiteList() const { 1192 ExtensionResource Extension::GetContentPackSiteList() const {
1191 if (!is_content_pack()) 1193 if (!is_content_pack())
1192 return ExtensionResource(); 1194 return ExtensionResource();
1193 1195
1194 return GetResource(content_pack_site_list_); 1196 return GetResource(content_pack_site_list_);
1195 } 1197 }
1196 1198
1197 GURL Extension::GetBackgroundURL() const {
1198 if (background_scripts_.empty())
1199 return background_url_;
1200 return GetResourceURL(extension_filenames::kGeneratedBackgroundPageFilename);
1201 }
1202
1203 Extension::RuntimeData::RuntimeData() {} 1199 Extension::RuntimeData::RuntimeData() {}
1204 Extension::RuntimeData::RuntimeData(const PermissionSet* active) 1200 Extension::RuntimeData::RuntimeData(const PermissionSet* active)
1205 : active_permissions_(active) {} 1201 : active_permissions_(active) {}
1206 Extension::RuntimeData::~RuntimeData() {} 1202 Extension::RuntimeData::~RuntimeData() {}
1207 1203
1208 void Extension::RuntimeData::SetActivePermissions( 1204 void Extension::RuntimeData::SetActivePermissions(
1209 const PermissionSet* active) { 1205 const PermissionSet* active) {
1210 active_permissions_ = active; 1206 active_permissions_ = active;
1211 } 1207 }
1212 1208
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 1291
1296 return base::FilePath(path_str); 1292 return base::FilePath(path_str);
1297 #else 1293 #else
1298 return path; 1294 return path;
1299 #endif 1295 #endif
1300 } 1296 }
1301 1297
1302 bool Extension::LoadManagedModeFeatures(string16* error) { 1298 bool Extension::LoadManagedModeFeatures(string16* error) {
1303 if (!manifest_->HasKey(keys::kContentPack)) 1299 if (!manifest_->HasKey(keys::kContentPack))
1304 return true; 1300 return true;
1305 DictionaryValue* content_pack_value = NULL; 1301 const DictionaryValue* content_pack_value = NULL;
1306 if (!manifest_->GetDictionary(keys::kContentPack, &content_pack_value)) { 1302 if (!manifest_->GetDictionary(keys::kContentPack, &content_pack_value)) {
1307 *error = ASCIIToUTF16(errors::kInvalidContentPack); 1303 *error = ASCIIToUTF16(errors::kInvalidContentPack);
1308 return false; 1304 return false;
1309 } 1305 }
1310 1306
1311 if (!LoadManagedModeSites(content_pack_value, error)) 1307 if (!LoadManagedModeSites(content_pack_value, error))
1312 return false; 1308 return false;
1313 if (!LoadManagedModeConfigurations(content_pack_value, error)) 1309 if (!LoadManagedModeConfigurations(content_pack_value, error))
1314 return false; 1310 return false;
1315 1311
(...skipping 29 matching lines...) Expand all
1345 // See http://b/4946060 for more details. 1341 // See http://b/4946060 for more details.
1346 return id == std::string("nckgahadagoaajjgafhacjanaoiihapd"); 1342 return id == std::string("nckgahadagoaajjgafhacjanaoiihapd");
1347 } 1343 }
1348 1344
1349 Extension::Extension(const base::FilePath& path, 1345 Extension::Extension(const base::FilePath& path,
1350 scoped_ptr<extensions::Manifest> manifest) 1346 scoped_ptr<extensions::Manifest> manifest)
1351 : manifest_version_(0), 1347 : manifest_version_(0),
1352 incognito_split_mode_(false), 1348 incognito_split_mode_(false),
1353 offline_enabled_(false), 1349 offline_enabled_(false),
1354 converted_from_user_script_(false), 1350 converted_from_user_script_(false),
1355 background_page_is_persistent_(true),
1356 allow_background_js_access_(true),
1357 manifest_(manifest.release()), 1351 manifest_(manifest.release()),
1358 finished_parsing_manifest_(false), 1352 finished_parsing_manifest_(false),
1359 is_storage_isolated_(false), 1353 is_storage_isolated_(false),
1360 launch_container_(extension_misc::LAUNCH_TAB), 1354 launch_container_(extension_misc::LAUNCH_TAB),
1361 launch_width_(0), 1355 launch_width_(0),
1362 launch_height_(0), 1356 launch_height_(0),
1363 display_in_launcher_(true), 1357 display_in_launcher_(true),
1364 display_in_new_tab_page_(true), 1358 display_in_new_tab_page_(true),
1365 wants_file_access_(false), 1359 wants_file_access_(false),
1366 creation_flags_(0) { 1360 creation_flags_(0) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 is_storage_isolated_ = true; 1479 is_storage_isolated_ = true;
1486 return true; 1480 return true;
1487 } 1481 }
1488 1482
1489 // Other apps only get it if it is requested _and_ experimental APIs are 1483 // Other apps only get it if it is requested _and_ experimental APIs are
1490 // enabled. 1484 // enabled.
1491 if (!initial_api_permissions()->count(APIPermission::kExperimental) 1485 if (!initial_api_permissions()->count(APIPermission::kExperimental)
1492 || !is_app()) 1486 || !is_app())
1493 return true; 1487 return true;
1494 1488
1495 Value* tmp_isolation = NULL; 1489 const Value* tmp_isolation = NULL;
1496 if (!manifest_->Get(keys::kIsolation, &tmp_isolation)) 1490 if (!manifest_->Get(keys::kIsolation, &tmp_isolation))
1497 return true; 1491 return true;
1498 1492
1499 if (tmp_isolation->GetType() != Value::TYPE_LIST) { 1493 if (tmp_isolation->GetType() != Value::TYPE_LIST) {
1500 *error = ASCIIToUTF16(errors::kInvalidIsolation); 1494 *error = ASCIIToUTF16(errors::kInvalidIsolation);
1501 return false; 1495 return false;
1502 } 1496 }
1503 1497
1504 ListValue* isolation_list = static_cast<ListValue*>(tmp_isolation); 1498 const ListValue* isolation_list = NULL;
1499 tmp_isolation->GetAsList(&isolation_list);
Matt Perry 2013/02/15 20:15:02 As long as you using this method, combine it with
Yoyo Zhou 2013/02/16 00:54:04 Done.
1505 for (size_t i = 0; i < isolation_list->GetSize(); ++i) { 1500 for (size_t i = 0; i < isolation_list->GetSize(); ++i) {
1506 std::string isolation_string; 1501 std::string isolation_string;
1507 if (!isolation_list->GetString(i, &isolation_string)) { 1502 if (!isolation_list->GetString(i, &isolation_string)) {
1508 *error = ErrorUtils::FormatErrorMessageUTF16( 1503 *error = ErrorUtils::FormatErrorMessageUTF16(
1509 errors::kInvalidIsolationValue, 1504 errors::kInvalidIsolationValue,
1510 base::UintToString(i)); 1505 base::UintToString(i));
1511 return false; 1506 return false;
1512 } 1507 }
1513 1508
1514 // Check for isolated storage. 1509 // Check for isolated storage.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 display_in_new_tab_page_ = display_in_launcher_; 1572 display_in_new_tab_page_ = display_in_launcher_;
1578 } 1573 }
1579 return true; 1574 return true;
1580 } 1575 }
1581 1576
1582 bool Extension::LoadExtent(const char* key, 1577 bool Extension::LoadExtent(const char* key,
1583 URLPatternSet* extent, 1578 URLPatternSet* extent,
1584 const char* list_error, 1579 const char* list_error,
1585 const char* value_error, 1580 const char* value_error,
1586 string16* error) { 1581 string16* error) {
1587 Value* temp_pattern_value = NULL; 1582 const Value* temp_pattern_value = NULL;
1588 if (!manifest_->Get(key, &temp_pattern_value)) 1583 if (!manifest_->Get(key, &temp_pattern_value))
1589 return true; 1584 return true;
1590 1585
1591 if (temp_pattern_value->GetType() != Value::TYPE_LIST) { 1586 if (temp_pattern_value->GetType() != Value::TYPE_LIST) {
1592 *error = ASCIIToUTF16(list_error); 1587 *error = ASCIIToUTF16(list_error);
1593 return false; 1588 return false;
1594 } 1589 }
1595 1590
1596 ListValue* pattern_list = static_cast<ListValue*>(temp_pattern_value); 1591 const ListValue* pattern_list = NULL;
1592 temp_pattern_value->GetAsList(&pattern_list);
1597 for (size_t i = 0; i < pattern_list->GetSize(); ++i) { 1593 for (size_t i = 0; i < pattern_list->GetSize(); ++i) {
1598 std::string pattern_string; 1594 std::string pattern_string;
1599 if (!pattern_list->GetString(i, &pattern_string)) { 1595 if (!pattern_list->GetString(i, &pattern_string)) {
1600 *error = ErrorUtils::FormatErrorMessageUTF16(value_error, 1596 *error = ErrorUtils::FormatErrorMessageUTF16(value_error,
1601 base::UintToString(i), 1597 base::UintToString(i),
1602 errors::kExpectString); 1598 errors::kExpectString);
1603 return false; 1599 return false;
1604 } 1600 }
1605 1601
1606 URLPattern pattern(kValidWebExtentSchemes); 1602 URLPattern pattern(kValidWebExtentSchemes);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 } 1643 }
1648 pattern.SetPath(pattern.path() + '*'); 1644 pattern.SetPath(pattern.path() + '*');
1649 1645
1650 extent->AddPattern(pattern); 1646 extent->AddPattern(pattern);
1651 } 1647 }
1652 1648
1653 return true; 1649 return true;
1654 } 1650 }
1655 1651
1656 bool Extension::LoadLaunchContainer(string16* error) { 1652 bool Extension::LoadLaunchContainer(string16* error) {
1657 Value* tmp_launcher_container = NULL; 1653 const Value* tmp_launcher_container = NULL;
1658 if (!manifest_->Get(keys::kLaunchContainer, &tmp_launcher_container)) 1654 if (!manifest_->Get(keys::kLaunchContainer, &tmp_launcher_container))
1659 return true; 1655 return true;
1660 1656
1661 std::string launch_container_string; 1657 std::string launch_container_string;
1662 if (!tmp_launcher_container->GetAsString(&launch_container_string)) { 1658 if (!tmp_launcher_container->GetAsString(&launch_container_string)) {
1663 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer); 1659 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer);
1664 return false; 1660 return false;
1665 } 1661 }
1666 1662
1667 if (launch_container_string == values::kLaunchContainerPanel) { 1663 if (launch_container_string == values::kLaunchContainerPanel) {
(...skipping 24 matching lines...) Expand all
1692 &launch_height_, 1688 &launch_height_,
1693 can_specify_initial_size, 1689 can_specify_initial_size,
1694 error)) { 1690 error)) {
1695 return false; 1691 return false;
1696 } 1692 }
1697 1693
1698 return true; 1694 return true;
1699 } 1695 }
1700 1696
1701 bool Extension::LoadLaunchURL(string16* error) { 1697 bool Extension::LoadLaunchURL(string16* error) {
1702 Value* temp = NULL; 1698 const Value* temp = NULL;
1703 1699
1704 // launch URL can be either local (to chrome-extension:// root) or an absolute 1700 // launch URL can be either local (to chrome-extension:// root) or an absolute
1705 // web URL. 1701 // web URL.
1706 if (manifest_->Get(keys::kLaunchLocalPath, &temp)) { 1702 if (manifest_->Get(keys::kLaunchLocalPath, &temp)) {
1707 if (manifest_->Get(keys::kLaunchWebURL, NULL)) { 1703 if (manifest_->Get(keys::kLaunchWebURL, NULL)) {
1708 *error = ASCIIToUTF16(errors::kLaunchPathAndURLAreExclusive); 1704 *error = ASCIIToUTF16(errors::kLaunchPathAndURLAreExclusive);
1709 return false; 1705 return false;
1710 } 1706 }
1711 1707
1712 if (manifest_->Get(keys::kWebURLs, NULL)) { 1708 if (manifest_->Get(keys::kWebURLs, NULL)) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 } 1807 }
1812 1808
1813 bool Extension::LoadSharedFeatures(string16* error) { 1809 bool Extension::LoadSharedFeatures(string16* error) {
1814 if (!LoadDescription(error) || 1810 if (!LoadDescription(error) ||
1815 !LoadIcons(error) || 1811 !LoadIcons(error) ||
1816 !ManifestHandler::ParseExtension(this, error) || 1812 !ManifestHandler::ParseExtension(this, error) ||
1817 !LoadPlugins(error) || 1813 !LoadPlugins(error) ||
1818 !LoadNaClModules(error) || 1814 !LoadNaClModules(error) ||
1819 !LoadSandboxedPages(error) || 1815 !LoadSandboxedPages(error) ||
1820 !LoadRequirements(error) || 1816 !LoadRequirements(error) ||
1821 !LoadOfflineEnabled(error) || 1817 !LoadOfflineEnabled(error))
1822 // LoadBackgroundScripts() must be called before LoadBackgroundPage().
1823 !LoadBackgroundScripts(error) ||
1824 !LoadBackgroundPage(error) ||
1825 !LoadBackgroundPersistent(error) ||
1826 !LoadBackgroundAllowJSAccess(error))
1827 return false; 1818 return false;
1828 1819
1829 return true; 1820 return true;
1830 } 1821 }
1831 1822
1832 bool Extension::LoadDescription(string16* error) { 1823 bool Extension::LoadDescription(string16* error) {
1833 if (manifest_->HasKey(keys::kDescription) && 1824 if (manifest_->HasKey(keys::kDescription) &&
1834 !manifest_->GetString(keys::kDescription, &description_)) { 1825 !manifest_->GetString(keys::kDescription, &description_)) {
1835 *error = ASCIIToUTF16(errors::kInvalidDescription); 1826 *error = ASCIIToUTF16(errors::kInvalidDescription);
1836 return false; 1827 return false;
(...skipping 23 matching lines...) Expand all
1860 base::IntToString(kModernManifestVersion)); 1851 base::IntToString(kModernManifestVersion));
1861 return false; 1852 return false;
1862 } 1853 }
1863 1854
1864 return true; 1855 return true;
1865 } 1856 }
1866 1857
1867 bool Extension::LoadIcons(string16* error) { 1858 bool Extension::LoadIcons(string16* error) {
1868 if (!manifest_->HasKey(keys::kIcons)) 1859 if (!manifest_->HasKey(keys::kIcons))
1869 return true; 1860 return true;
1870 DictionaryValue* icons_value = NULL; 1861 const DictionaryValue* icons_value = NULL;
1871 if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) { 1862 if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) {
1872 *error = ASCIIToUTF16(errors::kInvalidIcons); 1863 *error = ASCIIToUTF16(errors::kInvalidIcons);
1873 return false; 1864 return false;
1874 } 1865 }
1875 1866
1876 return manifest_handler_helpers::LoadIconsFromDictionary( 1867 return manifest_handler_helpers::LoadIconsFromDictionary(
1877 icons_value, 1868 icons_value,
1878 extension_misc::kExtensionIconSizes, 1869 extension_misc::kExtensionIconSizes,
1879 extension_misc::kNumExtensionIconSizes, 1870 extension_misc::kNumExtensionIconSizes,
1880 &icons_, 1871 &icons_,
1881 error); 1872 error);
1882 } 1873 }
1883 1874
1884 bool Extension::LoadPlugins(string16* error) { 1875 bool Extension::LoadPlugins(string16* error) {
1885 if (!manifest_->HasKey(keys::kPlugins)) 1876 if (!manifest_->HasKey(keys::kPlugins))
1886 return true; 1877 return true;
1887 1878
1888 ListValue* list_value = NULL; 1879 const ListValue* list_value = NULL;
1889 if (!manifest_->GetList(keys::kPlugins, &list_value)) { 1880 if (!manifest_->GetList(keys::kPlugins, &list_value)) {
1890 *error = ASCIIToUTF16(errors::kInvalidPlugins); 1881 *error = ASCIIToUTF16(errors::kInvalidPlugins);
1891 return false; 1882 return false;
1892 } 1883 }
1893 1884
1894 for (size_t i = 0; i < list_value->GetSize(); ++i) { 1885 for (size_t i = 0; i < list_value->GetSize(); ++i) {
1895 DictionaryValue* plugin_value = NULL; 1886 const DictionaryValue* plugin_value = NULL;
1896 if (!list_value->GetDictionary(i, &plugin_value)) { 1887 if (!list_value->GetDictionary(i, &plugin_value)) {
1897 *error = ASCIIToUTF16(errors::kInvalidPlugins); 1888 *error = ASCIIToUTF16(errors::kInvalidPlugins);
1898 return false; 1889 return false;
1899 } 1890 }
1900 // Get plugins[i].path. 1891 // Get plugins[i].path.
1901 std::string path_str; 1892 std::string path_str;
1902 if (!plugin_value->GetString(keys::kPluginsPath, &path_str)) { 1893 if (!plugin_value->GetString(keys::kPluginsPath, &path_str)) {
1903 *error = ErrorUtils::FormatErrorMessageUTF16( 1894 *error = ErrorUtils::FormatErrorMessageUTF16(
1904 errors::kInvalidPluginsPath, base::IntToString(i)); 1895 errors::kInvalidPluginsPath, base::IntToString(i));
1905 return false; 1896 return false;
(...skipping 24 matching lines...) Expand all
1930 plugins_.back().path = path().Append( 1921 plugins_.back().path = path().Append(
1931 base::FilePath::FromUTF8Unsafe(path_str)); 1922 base::FilePath::FromUTF8Unsafe(path_str));
1932 plugins_.back().is_public = is_public; 1923 plugins_.back().is_public = is_public;
1933 } 1924 }
1934 return true; 1925 return true;
1935 } 1926 }
1936 1927
1937 bool Extension::LoadNaClModules(string16* error) { 1928 bool Extension::LoadNaClModules(string16* error) {
1938 if (!manifest_->HasKey(keys::kNaClModules)) 1929 if (!manifest_->HasKey(keys::kNaClModules))
1939 return true; 1930 return true;
1940 ListValue* list_value = NULL; 1931 const ListValue* list_value = NULL;
1941 if (!manifest_->GetList(keys::kNaClModules, &list_value)) { 1932 if (!manifest_->GetList(keys::kNaClModules, &list_value)) {
1942 *error = ASCIIToUTF16(errors::kInvalidNaClModules); 1933 *error = ASCIIToUTF16(errors::kInvalidNaClModules);
1943 return false; 1934 return false;
1944 } 1935 }
1945 1936
1946 for (size_t i = 0; i < list_value->GetSize(); ++i) { 1937 for (size_t i = 0; i < list_value->GetSize(); ++i) {
1947 DictionaryValue* module_value = NULL; 1938 const DictionaryValue* module_value = NULL;
1948 if (!list_value->GetDictionary(i, &module_value)) { 1939 if (!list_value->GetDictionary(i, &module_value)) {
1949 *error = ASCIIToUTF16(errors::kInvalidNaClModules); 1940 *error = ASCIIToUTF16(errors::kInvalidNaClModules);
1950 return false; 1941 return false;
1951 } 1942 }
1952 1943
1953 // Get nacl_modules[i].path. 1944 // Get nacl_modules[i].path.
1954 std::string path_str; 1945 std::string path_str;
1955 if (!module_value->GetString(keys::kNaClModulesPath, &path_str)) { 1946 if (!module_value->GetString(keys::kNaClModulesPath, &path_str)) {
1956 *error = ErrorUtils::FormatErrorMessageUTF16( 1947 *error = ErrorUtils::FormatErrorMessageUTF16(
1957 errors::kInvalidNaClModulesPath, base::IntToString(i)); 1948 errors::kInvalidNaClModulesPath, base::IntToString(i));
(...skipping 13 matching lines...) Expand all
1971 nacl_modules_.back().mime_type = mime_type; 1962 nacl_modules_.back().mime_type = mime_type;
1972 } 1963 }
1973 1964
1974 return true; 1965 return true;
1975 } 1966 }
1976 1967
1977 bool Extension::LoadSandboxedPages(string16* error) { 1968 bool Extension::LoadSandboxedPages(string16* error) {
1978 if (!manifest_->HasPath(keys::kSandboxedPages)) 1969 if (!manifest_->HasPath(keys::kSandboxedPages))
1979 return true; 1970 return true;
1980 1971
1981 ListValue* list_value = NULL; 1972 const ListValue* list_value = NULL;
1982 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { 1973 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) {
1983 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); 1974 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList);
1984 return false; 1975 return false;
1985 } 1976 }
1986 for (size_t i = 0; i < list_value->GetSize(); ++i) { 1977 for (size_t i = 0; i < list_value->GetSize(); ++i) {
1987 std::string relative_path; 1978 std::string relative_path;
1988 if (!list_value->GetString(i, &relative_path)) { 1979 if (!list_value->GetString(i, &relative_path)) {
1989 *error = ErrorUtils::FormatErrorMessageUTF16( 1980 *error = ErrorUtils::FormatErrorMessageUTF16(
1990 errors::kInvalidSandboxedPage, base::IntToString(i)); 1981 errors::kInvalidSandboxedPage, base::IntToString(i));
1991 return false; 1982 return false;
(...skipping 30 matching lines...) Expand all
2022 CHECK(ContentSecurityPolicyIsSandboxed( 2013 CHECK(ContentSecurityPolicyIsSandboxed(
2023 sandboxed_pages_content_security_policy_, GetType())); 2014 sandboxed_pages_content_security_policy_, GetType()));
2024 } 2015 }
2025 2016
2026 return true; 2017 return true;
2027 } 2018 }
2028 2019
2029 bool Extension::LoadRequirements(string16* error) { 2020 bool Extension::LoadRequirements(string16* error) {
2030 // Before parsing requirements from the manifest, automatically default the 2021 // Before parsing requirements from the manifest, automatically default the
2031 // NPAPI plugin requirement based on whether it includes NPAPI plugins. 2022 // NPAPI plugin requirement based on whether it includes NPAPI plugins.
2032 ListValue* list_value = NULL; 2023 const ListValue* list_value = NULL;
2033 requirements_.npapi = 2024 requirements_.npapi =
2034 manifest_->GetList(keys::kPlugins, &list_value) && !list_value->empty(); 2025 manifest_->GetList(keys::kPlugins, &list_value) && !list_value->empty();
2035 2026
2036 if (!manifest_->HasKey(keys::kRequirements)) 2027 if (!manifest_->HasKey(keys::kRequirements))
2037 return true; 2028 return true;
2038 2029
2039 DictionaryValue* requirements_value = NULL; 2030 const DictionaryValue* requirements_value = NULL;
2040 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) { 2031 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) {
2041 *error = ASCIIToUTF16(errors::kInvalidRequirements); 2032 *error = ASCIIToUTF16(errors::kInvalidRequirements);
2042 return false; 2033 return false;
2043 } 2034 }
2044 2035
2045 for (DictionaryValue::Iterator it(*requirements_value); !it.IsAtEnd(); 2036 for (DictionaryValue::Iterator it(*requirements_value); !it.IsAtEnd();
2046 it.Advance()) { 2037 it.Advance()) {
2047 const DictionaryValue* requirement_value; 2038 const DictionaryValue* requirement_value;
2048 if (!it.value().GetAsDictionary(&requirement_value)) { 2039 if (!it.value().GetAsDictionary(&requirement_value)) {
2049 *error = ErrorUtils::FormatErrorMessageUTF16( 2040 *error = ErrorUtils::FormatErrorMessageUTF16(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 offline_enabled_ = is_platform_app(); 2099 offline_enabled_ = is_platform_app();
2109 return true; 2100 return true;
2110 } 2101 }
2111 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { 2102 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) {
2112 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled); 2103 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled);
2113 return false; 2104 return false;
2114 } 2105 }
2115 return true; 2106 return true;
2116 } 2107 }
2117 2108
2118 bool Extension::LoadBackgroundScripts(string16* error) {
2119 const std::string& key = is_platform_app() ?
2120 keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts;
2121 return LoadBackgroundScripts(key, error);
2122 }
2123
2124 bool Extension::LoadBackgroundScripts(const std::string& key, string16* error) {
2125 Value* background_scripts_value = NULL;
2126 if (!manifest_->Get(key, &background_scripts_value))
2127 return true;
2128
2129 CHECK(background_scripts_value);
2130 if (background_scripts_value->GetType() != Value::TYPE_LIST) {
2131 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts);
2132 return false;
2133 }
2134
2135 ListValue* background_scripts =
2136 static_cast<ListValue*>(background_scripts_value);
2137 for (size_t i = 0; i < background_scripts->GetSize(); ++i) {
2138 std::string script;
2139 if (!background_scripts->GetString(i, &script)) {
2140 *error = ErrorUtils::FormatErrorMessageUTF16(
2141 errors::kInvalidBackgroundScript, base::IntToString(i));
2142 return false;
2143 }
2144 background_scripts_.push_back(script);
2145 }
2146
2147 return true;
2148 }
2149
2150 bool Extension::LoadBackgroundPage(string16* error) {
2151 if (is_platform_app()) {
2152 return LoadBackgroundPage(keys::kPlatformAppBackgroundPage, error);
2153 }
2154
2155 if (!LoadBackgroundPage(keys::kBackgroundPage, error))
2156 return false;
2157 if (background_url_.is_empty()) {
2158 return LoadBackgroundPage(
2159 keys::kBackgroundPageLegacy, error);
2160 }
2161 return true;
2162 }
2163
2164 bool Extension::LoadBackgroundPage(const std::string& key, string16* error) {
2165 base::Value* background_page_value = NULL;
2166 if (!manifest_->Get(key, &background_page_value))
2167 return true;
2168
2169 if (!background_scripts_.empty()) {
2170 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination);
2171 return false;
2172 }
2173
2174
2175 std::string background_str;
2176 if (!background_page_value->GetAsString(&background_str)) {
2177 *error = ASCIIToUTF16(errors::kInvalidBackground);
2178 return false;
2179 }
2180
2181 if (is_hosted_app()) {
2182 background_url_ = GURL(background_str);
2183
2184 // Make sure "background" permission is set.
2185 if (!initial_api_permissions()->count(APIPermission::kBackground)) {
2186 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded);
2187 return false;
2188 }
2189 // Hosted apps require an absolute URL.
2190 if (!background_url_.is_valid()) {
2191 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
2192 return false;
2193 }
2194
2195 if (!(background_url_.SchemeIs("https") ||
2196 (CommandLine::ForCurrentProcess()->HasSwitch(
2197 switches::kAllowHTTPBackgroundPage) &&
2198 background_url_.SchemeIs("http")))) {
2199 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
2200 return false;
2201 }
2202 } else {
2203 background_url_ = GetResourceURL(background_str);
2204 }
2205
2206 return true;
2207 }
2208
2209 bool Extension::LoadBackgroundPersistent(string16* error) {
2210 if (is_platform_app()) {
2211 background_page_is_persistent_ = false;
2212 return true;
2213 }
2214
2215 Value* background_persistent = NULL;
2216 if (!manifest_->Get(keys::kBackgroundPersistent, &background_persistent))
2217 return true;
2218
2219 if (!background_persistent->GetAsBoolean(&background_page_is_persistent_)) {
2220 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent);
2221 return false;
2222 }
2223
2224 if (!has_background_page()) {
2225 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage);
2226 return false;
2227 }
2228
2229 return true;
2230 }
2231
2232 bool Extension::LoadBackgroundAllowJSAccess(string16* error) {
2233 Value* allow_js_access = NULL;
2234 if (!manifest_->Get(keys::kBackgroundAllowJsAccess, &allow_js_access))
2235 return true;
2236
2237 if (!allow_js_access->IsType(Value::TYPE_BOOLEAN) ||
2238 !allow_js_access->GetAsBoolean(&allow_background_js_access_)) {
2239 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess);
2240 return false;
2241 }
2242
2243 return true;
2244 }
2245
2246 bool Extension::LoadExtensionFeatures(string16* error) { 2109 bool Extension::LoadExtensionFeatures(string16* error) {
2247 if (manifest_->HasKey(keys::kConvertedFromUserScript)) 2110 if (manifest_->HasKey(keys::kConvertedFromUserScript))
2248 manifest_->GetBoolean(keys::kConvertedFromUserScript, 2111 manifest_->GetBoolean(keys::kConvertedFromUserScript,
2249 &converted_from_user_script_); 2112 &converted_from_user_script_);
2250 2113
2251 if (!LoadContentScripts(error) || 2114 if (!LoadContentScripts(error) ||
2252 !LoadSystemIndicator(error) || 2115 !LoadSystemIndicator(error) ||
2253 !LoadIncognitoMode(error) || 2116 !LoadIncognitoMode(error) ||
2254 !LoadContentSecurityPolicy(error)) 2117 !LoadContentSecurityPolicy(error))
2255 return false; 2118 return false;
2256 2119
2257 return true; 2120 return true;
2258 } 2121 }
2259 2122
2260 bool Extension::LoadContentScripts(string16* error) { 2123 bool Extension::LoadContentScripts(string16* error) {
2261 if (!manifest_->HasKey(keys::kContentScripts)) 2124 if (!manifest_->HasKey(keys::kContentScripts))
2262 return true; 2125 return true;
2263 ListValue* list_value; 2126 const ListValue* list_value;
2264 if (!manifest_->GetList(keys::kContentScripts, &list_value)) { 2127 if (!manifest_->GetList(keys::kContentScripts, &list_value)) {
2265 *error = ASCIIToUTF16(errors::kInvalidContentScriptsList); 2128 *error = ASCIIToUTF16(errors::kInvalidContentScriptsList);
2266 return false; 2129 return false;
2267 } 2130 }
2268 2131
2269 for (size_t i = 0; i < list_value->GetSize(); ++i) { 2132 for (size_t i = 0; i < list_value->GetSize(); ++i) {
2270 DictionaryValue* content_script = NULL; 2133 const DictionaryValue* content_script = NULL;
2271 if (!list_value->GetDictionary(i, &content_script)) { 2134 if (!list_value->GetDictionary(i, &content_script)) {
2272 *error = ErrorUtils::FormatErrorMessageUTF16( 2135 *error = ErrorUtils::FormatErrorMessageUTF16(
2273 errors::kInvalidContentScript, base::IntToString(i)); 2136 errors::kInvalidContentScript, base::IntToString(i));
2274 return false; 2137 return false;
2275 } 2138 }
2276 2139
2277 UserScript script; 2140 UserScript script;
2278 if (!LoadUserScriptHelper(content_script, i, error, &script)) 2141 if (!LoadUserScriptHelper(content_script, i, error, &script))
2279 return false; // Failed to parse script context definition. 2142 return false; // Failed to parse script context definition.
2280 script.set_extension_id(id()); 2143 script.set_extension_id(id());
2281 if (converted_from_user_script_) { 2144 if (converted_from_user_script_) {
2282 script.set_emulate_greasemonkey(true); 2145 script.set_emulate_greasemonkey(true);
2283 script.set_match_all_frames(true); // Greasemonkey matches all frames. 2146 script.set_match_all_frames(true); // Greasemonkey matches all frames.
2284 } 2147 }
2285 content_scripts_.push_back(script); 2148 content_scripts_.push_back(script);
2286 } 2149 }
2287 return true; 2150 return true;
2288 } 2151 }
2289 2152
2290 bool Extension::LoadSystemIndicator(string16* error) { 2153 bool Extension::LoadSystemIndicator(string16* error) {
2291 if (!manifest_->HasKey(keys::kSystemIndicator)) { 2154 if (!manifest_->HasKey(keys::kSystemIndicator)) {
2292 // There was no manifest entry for the system indicator. 2155 // There was no manifest entry for the system indicator.
2293 return true; 2156 return true;
2294 } 2157 }
2295 2158
2296 DictionaryValue* system_indicator_value = NULL; 2159 const DictionaryValue* system_indicator_value = NULL;
2297 if (!manifest_->GetDictionary(keys::kSystemIndicator, 2160 if (!manifest_->GetDictionary(keys::kSystemIndicator,
2298 &system_indicator_value)) { 2161 &system_indicator_value)) {
2299 *error = ASCIIToUTF16(errors::kInvalidSystemIndicator); 2162 *error = ASCIIToUTF16(errors::kInvalidSystemIndicator);
2300 return false; 2163 return false;
2301 } 2164 }
2302 2165
2303 system_indicator_info_ = LoadExtensionActionInfoHelper( 2166 system_indicator_info_ = LoadExtensionActionInfoHelper(
2304 this, system_indicator_value, error); 2167 this, system_indicator_value, error);
2305 2168
2306 if (!system_indicator_info_.get()) { 2169 if (!system_indicator_info_.get()) {
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 minimum_version_string); 2593 minimum_version_string);
2731 return false; 2594 return false;
2732 } 2595 }
2733 return true; 2596 return true;
2734 } 2597 }
2735 2598
2736 bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) const { 2599 bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) const {
2737 if (!is_platform_app()) 2600 if (!is_platform_app())
2738 return true; 2601 return true;
2739 2602
2740 if (!has_background_page()) { 2603 if (!BackgroundInfo::HasBackgroundPage(this)) {
2741 *utf8_error = errors::kBackgroundRequiredForPlatformApps; 2604 *utf8_error = errors::kBackgroundRequiredForPlatformApps;
2742 return false; 2605 return false;
2743 } 2606 }
2744 2607
2745 if (!incognito_split_mode_) { 2608 if (!incognito_split_mode_) {
2746 *utf8_error = errors::kInvalidIncognitoModeForPlatformApp; 2609 *utf8_error = errors::kInvalidIncognitoModeForPlatformApp;
2747 return false; 2610 return false;
2748 } 2611 }
2749 2612
2750 return true; 2613 return true;
2751 } 2614 }
2752 2615
2753 bool Extension::CheckConflictingFeatures(std::string* utf8_error) const { 2616 bool Extension::CheckConflictingFeatures(std::string* utf8_error) const {
2754 if (has_lazy_background_page() && 2617 if (BackgroundInfo::HasLazyBackgroundPage(this) &&
2755 HasAPIPermission(APIPermission::kWebRequest)) { 2618 HasAPIPermission(APIPermission::kWebRequest)) {
2756 *utf8_error = errors::kWebRequestConflictsWithLazyBackground; 2619 *utf8_error = errors::kWebRequestConflictsWithLazyBackground;
2757 return false; 2620 return false;
2758 } 2621 }
2759 2622
2760 return true; 2623 return true;
2761 } 2624 }
2762 2625
2763 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, 2626 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest,
2764 const std::string& id, 2627 const std::string& id,
(...skipping 17 matching lines...) Expand all
2782 2645
2783 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 2646 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
2784 const Extension* extension, 2647 const Extension* extension,
2785 const PermissionSet* permissions, 2648 const PermissionSet* permissions,
2786 Reason reason) 2649 Reason reason)
2787 : reason(reason), 2650 : reason(reason),
2788 extension(extension), 2651 extension(extension),
2789 permissions(permissions) {} 2652 permissions(permissions) {}
2790 2653
2791 } // namespace extensions 2654 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698