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

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, 9 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_file_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_util.h" 10 #include "base/file_util.h"
(...skipping 12 matching lines...) Expand all
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/icons/icons_handler.h" 31 #include "chrome/common/extensions/api/icons/icons_handler.h"
32 #include "chrome/common/extensions/api/themes/theme_handler.h" 32 #include "chrome/common/extensions/api/themes/theme_handler.h"
33 #include "chrome/common/extensions/background_info.h"
33 #include "chrome/common/extensions/csp_handler.h" 34 #include "chrome/common/extensions/csp_handler.h"
34 #include "chrome/common/extensions/csp_validator.h" 35 #include "chrome/common/extensions/csp_validator.h"
35 #include "chrome/common/extensions/extension_manifest_constants.h" 36 #include "chrome/common/extensions/extension_manifest_constants.h"
36 #include "chrome/common/extensions/feature_switch.h" 37 #include "chrome/common/extensions/feature_switch.h"
37 #include "chrome/common/extensions/features/base_feature_provider.h" 38 #include "chrome/common/extensions/features/base_feature_provider.h"
38 #include "chrome/common/extensions/features/feature.h" 39 #include "chrome/common/extensions/features/feature.h"
39 #include "chrome/common/extensions/manifest.h" 40 #include "chrome/common/extensions/manifest.h"
40 #include "chrome/common/extensions/manifest_handler.h" 41 #include "chrome/common/extensions/manifest_handler.h"
41 #include "chrome/common/extensions/manifest_handler_helpers.h" 42 #include "chrome/common/extensions/manifest_handler_helpers.h"
42 #include "chrome/common/extensions/manifest_url_handler.h" 43 #include "chrome/common/extensions/manifest_url_handler.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Note: Component extensions have this right implicitly and do not need to be 142 // Note: Component extensions have this right implicitly and do not need to be
142 // added to this list. 143 // added to this list.
143 Extension::ScriptingWhitelist scripting_whitelist_; 144 Extension::ScriptingWhitelist scripting_whitelist_;
144 }; 145 };
145 146
146 bool ReadLaunchDimension(const extensions::Manifest* manifest, 147 bool ReadLaunchDimension(const extensions::Manifest* manifest,
147 const char* key, 148 const char* key,
148 int* target, 149 int* target,
149 bool is_valid_container, 150 bool is_valid_container,
150 string16* error) { 151 string16* error) {
151 Value* temp = NULL; 152 const Value* temp = NULL;
152 if (manifest->Get(key, &temp)) { 153 if (manifest->Get(key, &temp)) {
153 if (!is_valid_container) { 154 if (!is_valid_container) {
154 *error = ErrorUtils::FormatErrorMessageUTF16( 155 *error = ErrorUtils::FormatErrorMessageUTF16(
155 errors::kInvalidLaunchValueContainer, 156 errors::kInvalidLaunchValueContainer,
156 key); 157 key);
157 return false; 158 return false;
158 } 159 }
159 if (!temp->GetAsInteger(target) || *target < 0) { 160 if (!temp->GetAsInteger(target) || *target < 0) {
160 *target = 0; 161 *target = 0;
161 *error = ErrorUtils::FormatErrorMessageUTF16( 162 *error = ErrorUtils::FormatErrorMessageUTF16(
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 // static 503 // static
503 const Extension::ScriptingWhitelist* Extension::GetScriptingWhitelist() { 504 const Extension::ScriptingWhitelist* Extension::GetScriptingWhitelist() {
504 return ExtensionConfig::GetInstance()->whitelist(); 505 return ExtensionConfig::GetInstance()->whitelist();
505 } 506 }
506 507
507 bool Extension::ParsePermissions(const char* key, 508 bool Extension::ParsePermissions(const char* key,
508 string16* error, 509 string16* error,
509 APIPermissionSet* api_permissions, 510 APIPermissionSet* api_permissions,
510 URLPatternSet* host_permissions) { 511 URLPatternSet* host_permissions) {
511 if (manifest_->HasKey(key)) { 512 if (manifest_->HasKey(key)) {
512 ListValue* permissions = NULL; 513 const ListValue* permissions = NULL;
513 if (!manifest_->GetList(key, &permissions)) { 514 if (!manifest_->GetList(key, &permissions)) {
514 *error = ErrorUtils::FormatErrorMessageUTF16( 515 *error = ErrorUtils::FormatErrorMessageUTF16(
515 errors::kInvalidPermissions, ""); 516 errors::kInvalidPermissions, "");
516 return false; 517 return false;
517 } 518 }
518 519
519 // NOTE: We need to get the APIPermission before we check if features 520 // NOTE: We need to get the APIPermission before we check if features
520 // associated with them are available because the feature system does not 521 // associated with them are available because the feature system does not
521 // know about aliases. 522 // know about aliases.
522 523
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 return !content_pack_site_list_.empty(); 1097 return !content_pack_site_list_.empty();
1097 } 1098 }
1098 1099
1099 ExtensionResource Extension::GetContentPackSiteList() const { 1100 ExtensionResource Extension::GetContentPackSiteList() const {
1100 if (!is_content_pack()) 1101 if (!is_content_pack())
1101 return ExtensionResource(); 1102 return ExtensionResource();
1102 1103
1103 return GetResource(content_pack_site_list_); 1104 return GetResource(content_pack_site_list_);
1104 } 1105 }
1105 1106
1106 GURL Extension::GetBackgroundURL() const {
1107 if (background_scripts_.empty())
1108 return background_url_;
1109 return GetResourceURL(extension_filenames::kGeneratedBackgroundPageFilename);
1110 }
1111
1112 Extension::RuntimeData::RuntimeData() {} 1107 Extension::RuntimeData::RuntimeData() {}
1113 Extension::RuntimeData::RuntimeData(const PermissionSet* active) 1108 Extension::RuntimeData::RuntimeData(const PermissionSet* active)
1114 : active_permissions_(active) {} 1109 : active_permissions_(active) {}
1115 Extension::RuntimeData::~RuntimeData() {} 1110 Extension::RuntimeData::~RuntimeData() {}
1116 1111
1117 void Extension::RuntimeData::SetActivePermissions( 1112 void Extension::RuntimeData::SetActivePermissions(
1118 const PermissionSet* active) { 1113 const PermissionSet* active) {
1119 active_permissions_ = active; 1114 active_permissions_ = active;
1120 } 1115 }
1121 1116
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 1199
1205 return base::FilePath(path_str); 1200 return base::FilePath(path_str);
1206 #else 1201 #else
1207 return path; 1202 return path;
1208 #endif 1203 #endif
1209 } 1204 }
1210 1205
1211 bool Extension::LoadManagedModeFeatures(string16* error) { 1206 bool Extension::LoadManagedModeFeatures(string16* error) {
1212 if (!manifest_->HasKey(keys::kContentPack)) 1207 if (!manifest_->HasKey(keys::kContentPack))
1213 return true; 1208 return true;
1214 DictionaryValue* content_pack_value = NULL; 1209 const DictionaryValue* content_pack_value = NULL;
1215 if (!manifest_->GetDictionary(keys::kContentPack, &content_pack_value)) { 1210 if (!manifest_->GetDictionary(keys::kContentPack, &content_pack_value)) {
1216 *error = ASCIIToUTF16(errors::kInvalidContentPack); 1211 *error = ASCIIToUTF16(errors::kInvalidContentPack);
1217 return false; 1212 return false;
1218 } 1213 }
1219 1214
1220 if (!LoadManagedModeSites(content_pack_value, error)) 1215 if (!LoadManagedModeSites(content_pack_value, error))
1221 return false; 1216 return false;
1222 if (!LoadManagedModeConfigurations(content_pack_value, error)) 1217 if (!LoadManagedModeConfigurations(content_pack_value, error))
1223 return false; 1218 return false;
1224 1219
(...skipping 29 matching lines...) Expand all
1254 // See http://b/4946060 for more details. 1249 // See http://b/4946060 for more details.
1255 return id == std::string("nckgahadagoaajjgafhacjanaoiihapd"); 1250 return id == std::string("nckgahadagoaajjgafhacjanaoiihapd");
1256 } 1251 }
1257 1252
1258 Extension::Extension(const base::FilePath& path, 1253 Extension::Extension(const base::FilePath& path,
1259 scoped_ptr<extensions::Manifest> manifest) 1254 scoped_ptr<extensions::Manifest> manifest)
1260 : manifest_version_(0), 1255 : manifest_version_(0),
1261 incognito_split_mode_(false), 1256 incognito_split_mode_(false),
1262 offline_enabled_(false), 1257 offline_enabled_(false),
1263 converted_from_user_script_(false), 1258 converted_from_user_script_(false),
1264 background_page_is_persistent_(true),
1265 allow_background_js_access_(true),
1266 manifest_(manifest.release()), 1259 manifest_(manifest.release()),
1267 finished_parsing_manifest_(false), 1260 finished_parsing_manifest_(false),
1268 is_storage_isolated_(false), 1261 is_storage_isolated_(false),
1269 launch_container_(extension_misc::LAUNCH_TAB), 1262 launch_container_(extension_misc::LAUNCH_TAB),
1270 launch_width_(0), 1263 launch_width_(0),
1271 launch_height_(0), 1264 launch_height_(0),
1272 display_in_launcher_(true), 1265 display_in_launcher_(true),
1273 display_in_new_tab_page_(true), 1266 display_in_new_tab_page_(true),
1274 wants_file_access_(false), 1267 wants_file_access_(false),
1275 creation_flags_(0) { 1268 creation_flags_(0) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 is_storage_isolated_ = true; 1387 is_storage_isolated_ = true;
1395 return true; 1388 return true;
1396 } 1389 }
1397 1390
1398 // Other apps only get it if it is requested _and_ experimental APIs are 1391 // Other apps only get it if it is requested _and_ experimental APIs are
1399 // enabled. 1392 // enabled.
1400 if (!initial_api_permissions()->count(APIPermission::kExperimental) 1393 if (!initial_api_permissions()->count(APIPermission::kExperimental)
1401 || !is_app()) 1394 || !is_app())
1402 return true; 1395 return true;
1403 1396
1404 Value* tmp_isolation = NULL; 1397 const Value* tmp_isolation = NULL;
1405 if (!manifest_->Get(keys::kIsolation, &tmp_isolation)) 1398 if (!manifest_->Get(keys::kIsolation, &tmp_isolation))
1406 return true; 1399 return true;
1407 1400
1408 if (tmp_isolation->GetType() != Value::TYPE_LIST) { 1401 const ListValue* isolation_list = NULL;
1402 if (!tmp_isolation->GetAsList(&isolation_list)) {
1409 *error = ASCIIToUTF16(errors::kInvalidIsolation); 1403 *error = ASCIIToUTF16(errors::kInvalidIsolation);
1410 return false; 1404 return false;
1411 } 1405 }
1412 1406
1413 ListValue* isolation_list = static_cast<ListValue*>(tmp_isolation);
1414 for (size_t i = 0; i < isolation_list->GetSize(); ++i) { 1407 for (size_t i = 0; i < isolation_list->GetSize(); ++i) {
1415 std::string isolation_string; 1408 std::string isolation_string;
1416 if (!isolation_list->GetString(i, &isolation_string)) { 1409 if (!isolation_list->GetString(i, &isolation_string)) {
1417 *error = ErrorUtils::FormatErrorMessageUTF16( 1410 *error = ErrorUtils::FormatErrorMessageUTF16(
1418 errors::kInvalidIsolationValue, 1411 errors::kInvalidIsolationValue,
1419 base::UintToString(i)); 1412 base::UintToString(i));
1420 return false; 1413 return false;
1421 } 1414 }
1422 1415
1423 // Check for isolated storage. 1416 // Check for isolated storage.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 display_in_new_tab_page_ = display_in_launcher_; 1479 display_in_new_tab_page_ = display_in_launcher_;
1487 } 1480 }
1488 return true; 1481 return true;
1489 } 1482 }
1490 1483
1491 bool Extension::LoadExtent(const char* key, 1484 bool Extension::LoadExtent(const char* key,
1492 URLPatternSet* extent, 1485 URLPatternSet* extent,
1493 const char* list_error, 1486 const char* list_error,
1494 const char* value_error, 1487 const char* value_error,
1495 string16* error) { 1488 string16* error) {
1496 Value* temp_pattern_value = NULL; 1489 const Value* temp_pattern_value = NULL;
1497 if (!manifest_->Get(key, &temp_pattern_value)) 1490 if (!manifest_->Get(key, &temp_pattern_value))
1498 return true; 1491 return true;
1499 1492
1500 if (temp_pattern_value->GetType() != Value::TYPE_LIST) { 1493 const ListValue* pattern_list = NULL;
1494 if (!temp_pattern_value->GetAsList(&pattern_list)) {
1501 *error = ASCIIToUTF16(list_error); 1495 *error = ASCIIToUTF16(list_error);
1502 return false; 1496 return false;
1503 } 1497 }
1504 1498
1505 ListValue* pattern_list = static_cast<ListValue*>(temp_pattern_value);
1506 for (size_t i = 0; i < pattern_list->GetSize(); ++i) { 1499 for (size_t i = 0; i < pattern_list->GetSize(); ++i) {
1507 std::string pattern_string; 1500 std::string pattern_string;
1508 if (!pattern_list->GetString(i, &pattern_string)) { 1501 if (!pattern_list->GetString(i, &pattern_string)) {
1509 *error = ErrorUtils::FormatErrorMessageUTF16(value_error, 1502 *error = ErrorUtils::FormatErrorMessageUTF16(value_error,
1510 base::UintToString(i), 1503 base::UintToString(i),
1511 errors::kExpectString); 1504 errors::kExpectString);
1512 return false; 1505 return false;
1513 } 1506 }
1514 1507
1515 URLPattern pattern(kValidWebExtentSchemes); 1508 URLPattern pattern(kValidWebExtentSchemes);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 } 1549 }
1557 pattern.SetPath(pattern.path() + '*'); 1550 pattern.SetPath(pattern.path() + '*');
1558 1551
1559 extent->AddPattern(pattern); 1552 extent->AddPattern(pattern);
1560 } 1553 }
1561 1554
1562 return true; 1555 return true;
1563 } 1556 }
1564 1557
1565 bool Extension::LoadLaunchContainer(string16* error) { 1558 bool Extension::LoadLaunchContainer(string16* error) {
1566 Value* tmp_launcher_container = NULL; 1559 const Value* tmp_launcher_container = NULL;
1567 if (!manifest_->Get(keys::kLaunchContainer, &tmp_launcher_container)) 1560 if (!manifest_->Get(keys::kLaunchContainer, &tmp_launcher_container))
1568 return true; 1561 return true;
1569 1562
1570 std::string launch_container_string; 1563 std::string launch_container_string;
1571 if (!tmp_launcher_container->GetAsString(&launch_container_string)) { 1564 if (!tmp_launcher_container->GetAsString(&launch_container_string)) {
1572 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer); 1565 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer);
1573 return false; 1566 return false;
1574 } 1567 }
1575 1568
1576 if (launch_container_string == values::kLaunchContainerPanel) { 1569 if (launch_container_string == values::kLaunchContainerPanel) {
(...skipping 24 matching lines...) Expand all
1601 &launch_height_, 1594 &launch_height_,
1602 can_specify_initial_size, 1595 can_specify_initial_size,
1603 error)) { 1596 error)) {
1604 return false; 1597 return false;
1605 } 1598 }
1606 1599
1607 return true; 1600 return true;
1608 } 1601 }
1609 1602
1610 bool Extension::LoadLaunchURL(string16* error) { 1603 bool Extension::LoadLaunchURL(string16* error) {
1611 Value* temp = NULL; 1604 const Value* temp = NULL;
1612 1605
1613 // launch URL can be either local (to chrome-extension:// root) or an absolute 1606 // launch URL can be either local (to chrome-extension:// root) or an absolute
1614 // web URL. 1607 // web URL.
1615 if (manifest_->Get(keys::kLaunchLocalPath, &temp)) { 1608 if (manifest_->Get(keys::kLaunchLocalPath, &temp)) {
1616 if (manifest_->Get(keys::kLaunchWebURL, NULL)) { 1609 if (manifest_->Get(keys::kLaunchWebURL, NULL)) {
1617 *error = ASCIIToUTF16(errors::kLaunchPathAndURLAreExclusive); 1610 *error = ASCIIToUTF16(errors::kLaunchPathAndURLAreExclusive);
1618 return false; 1611 return false;
1619 } 1612 }
1620 1613
1621 if (manifest_->Get(keys::kWebURLs, NULL)) { 1614 if (manifest_->Get(keys::kWebURLs, NULL)) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 return true; 1712 return true;
1720 } 1713 }
1721 1714
1722 bool Extension::LoadSharedFeatures(string16* error) { 1715 bool Extension::LoadSharedFeatures(string16* error) {
1723 if (!LoadDescription(error) || 1716 if (!LoadDescription(error) ||
1724 !ManifestHandler::ParseExtension(this, error) || 1717 !ManifestHandler::ParseExtension(this, error) ||
1725 !LoadPlugins(error) || 1718 !LoadPlugins(error) ||
1726 !LoadNaClModules(error) || 1719 !LoadNaClModules(error) ||
1727 !LoadSandboxedPages(error) || 1720 !LoadSandboxedPages(error) ||
1728 !LoadRequirements(error) || 1721 !LoadRequirements(error) ||
1729 !LoadOfflineEnabled(error) || 1722 !LoadOfflineEnabled(error))
1730 // LoadBackgroundScripts() must be called before LoadBackgroundPage().
1731 !LoadBackgroundScripts(error) ||
1732 !LoadBackgroundPage(error) ||
1733 !LoadBackgroundPersistent(error) ||
1734 !LoadBackgroundAllowJSAccess(error))
1735 return false; 1723 return false;
1736 1724
1737 return true; 1725 return true;
1738 } 1726 }
1739 1727
1740 bool Extension::LoadDescription(string16* error) { 1728 bool Extension::LoadDescription(string16* error) {
1741 if (manifest_->HasKey(keys::kDescription) && 1729 if (manifest_->HasKey(keys::kDescription) &&
1742 !manifest_->GetString(keys::kDescription, &description_)) { 1730 !manifest_->GetString(keys::kDescription, &description_)) {
1743 *error = ASCIIToUTF16(errors::kInvalidDescription); 1731 *error = ASCIIToUTF16(errors::kInvalidDescription);
1744 return false; 1732 return false;
(...skipping 24 matching lines...) Expand all
1769 return false; 1757 return false;
1770 } 1758 }
1771 1759
1772 return true; 1760 return true;
1773 } 1761 }
1774 1762
1775 bool Extension::LoadPlugins(string16* error) { 1763 bool Extension::LoadPlugins(string16* error) {
1776 if (!manifest_->HasKey(keys::kPlugins)) 1764 if (!manifest_->HasKey(keys::kPlugins))
1777 return true; 1765 return true;
1778 1766
1779 ListValue* list_value = NULL; 1767 const ListValue* list_value = NULL;
1780 if (!manifest_->GetList(keys::kPlugins, &list_value)) { 1768 if (!manifest_->GetList(keys::kPlugins, &list_value)) {
1781 *error = ASCIIToUTF16(errors::kInvalidPlugins); 1769 *error = ASCIIToUTF16(errors::kInvalidPlugins);
1782 return false; 1770 return false;
1783 } 1771 }
1784 1772
1785 for (size_t i = 0; i < list_value->GetSize(); ++i) { 1773 for (size_t i = 0; i < list_value->GetSize(); ++i) {
1786 DictionaryValue* plugin_value = NULL; 1774 const DictionaryValue* plugin_value = NULL;
1787 if (!list_value->GetDictionary(i, &plugin_value)) { 1775 if (!list_value->GetDictionary(i, &plugin_value)) {
1788 *error = ASCIIToUTF16(errors::kInvalidPlugins); 1776 *error = ASCIIToUTF16(errors::kInvalidPlugins);
1789 return false; 1777 return false;
1790 } 1778 }
1791 // Get plugins[i].path. 1779 // Get plugins[i].path.
1792 std::string path_str; 1780 std::string path_str;
1793 if (!plugin_value->GetString(keys::kPluginsPath, &path_str)) { 1781 if (!plugin_value->GetString(keys::kPluginsPath, &path_str)) {
1794 *error = ErrorUtils::FormatErrorMessageUTF16( 1782 *error = ErrorUtils::FormatErrorMessageUTF16(
1795 errors::kInvalidPluginsPath, base::IntToString(i)); 1783 errors::kInvalidPluginsPath, base::IntToString(i));
1796 return false; 1784 return false;
(...skipping 24 matching lines...) Expand all
1821 plugins_.back().path = path().Append( 1809 plugins_.back().path = path().Append(
1822 base::FilePath::FromUTF8Unsafe(path_str)); 1810 base::FilePath::FromUTF8Unsafe(path_str));
1823 plugins_.back().is_public = is_public; 1811 plugins_.back().is_public = is_public;
1824 } 1812 }
1825 return true; 1813 return true;
1826 } 1814 }
1827 1815
1828 bool Extension::LoadNaClModules(string16* error) { 1816 bool Extension::LoadNaClModules(string16* error) {
1829 if (!manifest_->HasKey(keys::kNaClModules)) 1817 if (!manifest_->HasKey(keys::kNaClModules))
1830 return true; 1818 return true;
1831 ListValue* list_value = NULL; 1819 const ListValue* list_value = NULL;
1832 if (!manifest_->GetList(keys::kNaClModules, &list_value)) { 1820 if (!manifest_->GetList(keys::kNaClModules, &list_value)) {
1833 *error = ASCIIToUTF16(errors::kInvalidNaClModules); 1821 *error = ASCIIToUTF16(errors::kInvalidNaClModules);
1834 return false; 1822 return false;
1835 } 1823 }
1836 1824
1837 for (size_t i = 0; i < list_value->GetSize(); ++i) { 1825 for (size_t i = 0; i < list_value->GetSize(); ++i) {
1838 DictionaryValue* module_value = NULL; 1826 const DictionaryValue* module_value = NULL;
1839 if (!list_value->GetDictionary(i, &module_value)) { 1827 if (!list_value->GetDictionary(i, &module_value)) {
1840 *error = ASCIIToUTF16(errors::kInvalidNaClModules); 1828 *error = ASCIIToUTF16(errors::kInvalidNaClModules);
1841 return false; 1829 return false;
1842 } 1830 }
1843 1831
1844 // Get nacl_modules[i].path. 1832 // Get nacl_modules[i].path.
1845 std::string path_str; 1833 std::string path_str;
1846 if (!module_value->GetString(keys::kNaClModulesPath, &path_str)) { 1834 if (!module_value->GetString(keys::kNaClModulesPath, &path_str)) {
1847 *error = ErrorUtils::FormatErrorMessageUTF16( 1835 *error = ErrorUtils::FormatErrorMessageUTF16(
1848 errors::kInvalidNaClModulesPath, base::IntToString(i)); 1836 errors::kInvalidNaClModulesPath, base::IntToString(i));
(...skipping 13 matching lines...) Expand all
1862 nacl_modules_.back().mime_type = mime_type; 1850 nacl_modules_.back().mime_type = mime_type;
1863 } 1851 }
1864 1852
1865 return true; 1853 return true;
1866 } 1854 }
1867 1855
1868 bool Extension::LoadSandboxedPages(string16* error) { 1856 bool Extension::LoadSandboxedPages(string16* error) {
1869 if (!manifest_->HasPath(keys::kSandboxedPages)) 1857 if (!manifest_->HasPath(keys::kSandboxedPages))
1870 return true; 1858 return true;
1871 1859
1872 ListValue* list_value = NULL; 1860 const ListValue* list_value = NULL;
1873 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { 1861 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) {
1874 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); 1862 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList);
1875 return false; 1863 return false;
1876 } 1864 }
1877 for (size_t i = 0; i < list_value->GetSize(); ++i) { 1865 for (size_t i = 0; i < list_value->GetSize(); ++i) {
1878 std::string relative_path; 1866 std::string relative_path;
1879 if (!list_value->GetString(i, &relative_path)) { 1867 if (!list_value->GetString(i, &relative_path)) {
1880 *error = ErrorUtils::FormatErrorMessageUTF16( 1868 *error = ErrorUtils::FormatErrorMessageUTF16(
1881 errors::kInvalidSandboxedPage, base::IntToString(i)); 1869 errors::kInvalidSandboxedPage, base::IntToString(i));
1882 return false; 1870 return false;
(...skipping 30 matching lines...) Expand all
1913 CHECK(ContentSecurityPolicyIsSandboxed( 1901 CHECK(ContentSecurityPolicyIsSandboxed(
1914 sandboxed_pages_content_security_policy_, GetType())); 1902 sandboxed_pages_content_security_policy_, GetType()));
1915 } 1903 }
1916 1904
1917 return true; 1905 return true;
1918 } 1906 }
1919 1907
1920 bool Extension::LoadRequirements(string16* error) { 1908 bool Extension::LoadRequirements(string16* error) {
1921 // Before parsing requirements from the manifest, automatically default the 1909 // Before parsing requirements from the manifest, automatically default the
1922 // NPAPI plugin requirement based on whether it includes NPAPI plugins. 1910 // NPAPI plugin requirement based on whether it includes NPAPI plugins.
1923 ListValue* list_value = NULL; 1911 const ListValue* list_value = NULL;
1924 requirements_.npapi = 1912 requirements_.npapi =
1925 manifest_->GetList(keys::kPlugins, &list_value) && !list_value->empty(); 1913 manifest_->GetList(keys::kPlugins, &list_value) && !list_value->empty();
1926 1914
1927 if (!manifest_->HasKey(keys::kRequirements)) 1915 if (!manifest_->HasKey(keys::kRequirements))
1928 return true; 1916 return true;
1929 1917
1930 DictionaryValue* requirements_value = NULL; 1918 const DictionaryValue* requirements_value = NULL;
1931 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) { 1919 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) {
1932 *error = ASCIIToUTF16(errors::kInvalidRequirements); 1920 *error = ASCIIToUTF16(errors::kInvalidRequirements);
1933 return false; 1921 return false;
1934 } 1922 }
1935 1923
1936 for (DictionaryValue::Iterator it(*requirements_value); !it.IsAtEnd(); 1924 for (DictionaryValue::Iterator it(*requirements_value); !it.IsAtEnd();
1937 it.Advance()) { 1925 it.Advance()) {
1938 const DictionaryValue* requirement_value; 1926 const DictionaryValue* requirement_value;
1939 if (!it.value().GetAsDictionary(&requirement_value)) { 1927 if (!it.value().GetAsDictionary(&requirement_value)) {
1940 *error = ErrorUtils::FormatErrorMessageUTF16( 1928 *error = ErrorUtils::FormatErrorMessageUTF16(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1999 offline_enabled_ = is_platform_app(); 1987 offline_enabled_ = is_platform_app();
2000 return true; 1988 return true;
2001 } 1989 }
2002 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { 1990 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) {
2003 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled); 1991 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled);
2004 return false; 1992 return false;
2005 } 1993 }
2006 return true; 1994 return true;
2007 } 1995 }
2008 1996
2009 bool Extension::LoadBackgroundScripts(string16* error) {
2010 const std::string& key = is_platform_app() ?
2011 keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts;
2012 return LoadBackgroundScripts(key, error);
2013 }
2014
2015 bool Extension::LoadBackgroundScripts(const std::string& key, string16* error) {
2016 Value* background_scripts_value = NULL;
2017 if (!manifest_->Get(key, &background_scripts_value))
2018 return true;
2019
2020 CHECK(background_scripts_value);
2021 if (background_scripts_value->GetType() != Value::TYPE_LIST) {
2022 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts);
2023 return false;
2024 }
2025
2026 ListValue* background_scripts =
2027 static_cast<ListValue*>(background_scripts_value);
2028 for (size_t i = 0; i < background_scripts->GetSize(); ++i) {
2029 std::string script;
2030 if (!background_scripts->GetString(i, &script)) {
2031 *error = ErrorUtils::FormatErrorMessageUTF16(
2032 errors::kInvalidBackgroundScript, base::IntToString(i));
2033 return false;
2034 }
2035 background_scripts_.push_back(script);
2036 }
2037
2038 return true;
2039 }
2040
2041 bool Extension::LoadBackgroundPage(string16* error) {
2042 if (is_platform_app()) {
2043 return LoadBackgroundPage(keys::kPlatformAppBackgroundPage, error);
2044 }
2045
2046 if (!LoadBackgroundPage(keys::kBackgroundPage, error))
2047 return false;
2048 if (background_url_.is_empty()) {
2049 return LoadBackgroundPage(
2050 keys::kBackgroundPageLegacy, error);
2051 }
2052 return true;
2053 }
2054
2055 bool Extension::LoadBackgroundPage(const std::string& key, string16* error) {
2056 base::Value* background_page_value = NULL;
2057 if (!manifest_->Get(key, &background_page_value))
2058 return true;
2059
2060 if (!background_scripts_.empty()) {
2061 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination);
2062 return false;
2063 }
2064
2065
2066 std::string background_str;
2067 if (!background_page_value->GetAsString(&background_str)) {
2068 *error = ASCIIToUTF16(errors::kInvalidBackground);
2069 return false;
2070 }
2071
2072 if (is_hosted_app()) {
2073 background_url_ = GURL(background_str);
2074
2075 // Make sure "background" permission is set.
2076 if (!initial_api_permissions()->count(APIPermission::kBackground)) {
2077 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded);
2078 return false;
2079 }
2080 // Hosted apps require an absolute URL.
2081 if (!background_url_.is_valid()) {
2082 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
2083 return false;
2084 }
2085
2086 if (!(background_url_.SchemeIs("https") ||
2087 (CommandLine::ForCurrentProcess()->HasSwitch(
2088 switches::kAllowHTTPBackgroundPage) &&
2089 background_url_.SchemeIs("http")))) {
2090 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
2091 return false;
2092 }
2093 } else {
2094 background_url_ = GetResourceURL(background_str);
2095 }
2096
2097 return true;
2098 }
2099
2100 bool Extension::LoadBackgroundPersistent(string16* error) {
2101 if (is_platform_app()) {
2102 background_page_is_persistent_ = false;
2103 return true;
2104 }
2105
2106 Value* background_persistent = NULL;
2107 if (!manifest_->Get(keys::kBackgroundPersistent, &background_persistent))
2108 return true;
2109
2110 if (!background_persistent->GetAsBoolean(&background_page_is_persistent_)) {
2111 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent);
2112 return false;
2113 }
2114
2115 if (!has_background_page()) {
2116 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage);
2117 return false;
2118 }
2119
2120 return true;
2121 }
2122
2123 bool Extension::LoadBackgroundAllowJSAccess(string16* error) {
2124 Value* allow_js_access = NULL;
2125 if (!manifest_->Get(keys::kBackgroundAllowJsAccess, &allow_js_access))
2126 return true;
2127
2128 if (!allow_js_access->IsType(Value::TYPE_BOOLEAN) ||
2129 !allow_js_access->GetAsBoolean(&allow_background_js_access_)) {
2130 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess);
2131 return false;
2132 }
2133
2134 return true;
2135 }
2136
2137 bool Extension::LoadExtensionFeatures(string16* error) { 1997 bool Extension::LoadExtensionFeatures(string16* error) {
2138 if (manifest_->HasKey(keys::kConvertedFromUserScript)) 1998 if (manifest_->HasKey(keys::kConvertedFromUserScript))
2139 manifest_->GetBoolean(keys::kConvertedFromUserScript, 1999 manifest_->GetBoolean(keys::kConvertedFromUserScript,
2140 &converted_from_user_script_); 2000 &converted_from_user_script_);
2141 2001
2142 if (!LoadContentScripts(error) || 2002 if (!LoadContentScripts(error) ||
2143 !LoadSystemIndicator(error) || 2003 !LoadSystemIndicator(error) ||
2144 !LoadIncognitoMode(error)) 2004 !LoadIncognitoMode(error))
2145 return false; 2005 return false;
2146 2006
2147 return true; 2007 return true;
2148 } 2008 }
2149 2009
2150 bool Extension::LoadContentScripts(string16* error) { 2010 bool Extension::LoadContentScripts(string16* error) {
2151 if (!manifest_->HasKey(keys::kContentScripts)) 2011 if (!manifest_->HasKey(keys::kContentScripts))
2152 return true; 2012 return true;
2153 ListValue* list_value; 2013 const ListValue* list_value;
2154 if (!manifest_->GetList(keys::kContentScripts, &list_value)) { 2014 if (!manifest_->GetList(keys::kContentScripts, &list_value)) {
2155 *error = ASCIIToUTF16(errors::kInvalidContentScriptsList); 2015 *error = ASCIIToUTF16(errors::kInvalidContentScriptsList);
2156 return false; 2016 return false;
2157 } 2017 }
2158 2018
2159 for (size_t i = 0; i < list_value->GetSize(); ++i) { 2019 for (size_t i = 0; i < list_value->GetSize(); ++i) {
2160 DictionaryValue* content_script = NULL; 2020 const DictionaryValue* content_script = NULL;
2161 if (!list_value->GetDictionary(i, &content_script)) { 2021 if (!list_value->GetDictionary(i, &content_script)) {
2162 *error = ErrorUtils::FormatErrorMessageUTF16( 2022 *error = ErrorUtils::FormatErrorMessageUTF16(
2163 errors::kInvalidContentScript, base::IntToString(i)); 2023 errors::kInvalidContentScript, base::IntToString(i));
2164 return false; 2024 return false;
2165 } 2025 }
2166 2026
2167 UserScript script; 2027 UserScript script;
2168 if (!LoadUserScriptHelper(content_script, i, error, &script)) 2028 if (!LoadUserScriptHelper(content_script, i, error, &script))
2169 return false; // Failed to parse script context definition. 2029 return false; // Failed to parse script context definition.
2170 script.set_extension_id(id()); 2030 script.set_extension_id(id());
2171 if (converted_from_user_script_) { 2031 if (converted_from_user_script_) {
2172 script.set_emulate_greasemonkey(true); 2032 script.set_emulate_greasemonkey(true);
2173 script.set_match_all_frames(true); // Greasemonkey matches all frames. 2033 script.set_match_all_frames(true); // Greasemonkey matches all frames.
2174 } 2034 }
2175 content_scripts_.push_back(script); 2035 content_scripts_.push_back(script);
2176 } 2036 }
2177 return true; 2037 return true;
2178 } 2038 }
2179 2039
2180 bool Extension::LoadSystemIndicator(string16* error) { 2040 bool Extension::LoadSystemIndicator(string16* error) {
2181 if (!manifest_->HasKey(keys::kSystemIndicator)) { 2041 if (!manifest_->HasKey(keys::kSystemIndicator)) {
2182 // There was no manifest entry for the system indicator. 2042 // There was no manifest entry for the system indicator.
2183 return true; 2043 return true;
2184 } 2044 }
2185 2045
2186 DictionaryValue* system_indicator_value = NULL; 2046 const DictionaryValue* system_indicator_value = NULL;
2187 if (!manifest_->GetDictionary(keys::kSystemIndicator, 2047 if (!manifest_->GetDictionary(keys::kSystemIndicator,
2188 &system_indicator_value)) { 2048 &system_indicator_value)) {
2189 *error = ASCIIToUTF16(errors::kInvalidSystemIndicator); 2049 *error = ASCIIToUTF16(errors::kInvalidSystemIndicator);
2190 return false; 2050 return false;
2191 } 2051 }
2192 2052
2193 system_indicator_info_ = LoadExtensionActionInfoHelper( 2053 system_indicator_info_ = LoadExtensionActionInfoHelper(
2194 this, system_indicator_value, error); 2054 this, system_indicator_value, error);
2195 2055
2196 if (!system_indicator_info_.get()) { 2056 if (!system_indicator_info_.get()) {
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
2587 minimum_version_string); 2447 minimum_version_string);
2588 return false; 2448 return false;
2589 } 2449 }
2590 return true; 2450 return true;
2591 } 2451 }
2592 2452
2593 bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) const { 2453 bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) const {
2594 if (!is_platform_app()) 2454 if (!is_platform_app())
2595 return true; 2455 return true;
2596 2456
2597 if (!has_background_page()) { 2457 if (!BackgroundInfo::HasBackgroundPage(this)) {
2598 *utf8_error = errors::kBackgroundRequiredForPlatformApps; 2458 *utf8_error = errors::kBackgroundRequiredForPlatformApps;
2599 return false; 2459 return false;
2600 } 2460 }
2601 2461
2602 if (!incognito_split_mode_) { 2462 if (!incognito_split_mode_) {
2603 *utf8_error = errors::kInvalidIncognitoModeForPlatformApp; 2463 *utf8_error = errors::kInvalidIncognitoModeForPlatformApp;
2604 return false; 2464 return false;
2605 } 2465 }
2606 2466
2607 return true; 2467 return true;
2608 } 2468 }
2609 2469
2610 bool Extension::CheckConflictingFeatures(std::string* utf8_error) const { 2470 bool Extension::CheckConflictingFeatures(std::string* utf8_error) const {
2611 if (has_lazy_background_page() && 2471 if (BackgroundInfo::HasLazyBackgroundPage(this) &&
2612 HasAPIPermission(APIPermission::kWebRequest)) { 2472 HasAPIPermission(APIPermission::kWebRequest)) {
2613 *utf8_error = errors::kWebRequestConflictsWithLazyBackground; 2473 *utf8_error = errors::kWebRequestConflictsWithLazyBackground;
2614 return false; 2474 return false;
2615 } 2475 }
2616 2476
2617 return true; 2477 return true;
2618 } 2478 }
2619 2479
2620 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, 2480 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest,
2621 const std::string& id, 2481 const std::string& id,
(...skipping 17 matching lines...) Expand all
2639 2499
2640 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 2500 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
2641 const Extension* extension, 2501 const Extension* extension,
2642 const PermissionSet* permissions, 2502 const PermissionSet* permissions,
2643 Reason reason) 2503 Reason reason)
2644 : reason(reason), 2504 : reason(reason),
2645 extension(extension), 2505 extension(extension),
2646 permissions(permissions) {} 2506 permissions(permissions) {}
2647 2507
2648 } // namespace extensions 2508 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698