| 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/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 const std::string& relative_path) { | 365 const std::string& relative_path) { |
| 366 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme)); | 366 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme)); |
| 367 DCHECK_EQ("/", extension_url.path()); | 367 DCHECK_EQ("/", extension_url.path()); |
| 368 | 368 |
| 369 GURL ret_val = GURL(extension_url.spec() + relative_path); | 369 GURL ret_val = GURL(extension_url.spec() + relative_path); |
| 370 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); | 370 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); |
| 371 | 371 |
| 372 return ret_val; | 372 return ret_val; |
| 373 } | 373 } |
| 374 | 374 |
| 375 bool Extension::IsResourceWebAccessible(const std::string& relative_path) |
| 376 const { |
| 377 // For old manifest versions which do not specify web_accessible_resources |
| 378 // we always allow resource loads. |
| 379 if (manifest_version() < 2 && !HasWebAccessibleResources()) |
| 380 return true; |
| 381 |
| 382 if (web_accessible_resources_.find(relative_path) != |
| 383 web_accessible_resources_.end()) |
| 384 return true; |
| 385 |
| 386 return false; |
| 387 } |
| 388 |
| 389 bool Extension::HasWebAccessibleResources() const { |
| 390 if (web_accessible_resources_.size()) |
| 391 return true; |
| 392 |
| 393 return false; |
| 394 } |
| 395 |
| 375 bool Extension::GenerateId(const std::string& input, std::string* output) { | 396 bool Extension::GenerateId(const std::string& input, std::string* output) { |
| 376 DCHECK(output); | 397 DCHECK(output); |
| 377 uint8 hash[Extension::kIdSize]; | 398 uint8 hash[Extension::kIdSize]; |
| 378 crypto::SHA256HashString(input, hash, sizeof(hash)); | 399 crypto::SHA256HashString(input, hash, sizeof(hash)); |
| 379 *output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash))); | 400 *output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash))); |
| 380 ConvertHexadecimalToIDAlphabet(output); | 401 ConvertHexadecimalToIDAlphabet(output); |
| 381 | 402 |
| 382 return true; | 403 return true; |
| 383 } | 404 } |
| 384 | 405 |
| (...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1821 return false; // Failed to parse script context definition. | 1842 return false; // Failed to parse script context definition. |
| 1822 script.set_extension_id(id()); | 1843 script.set_extension_id(id()); |
| 1823 if (converted_from_user_script_) { | 1844 if (converted_from_user_script_) { |
| 1824 script.set_emulate_greasemonkey(true); | 1845 script.set_emulate_greasemonkey(true); |
| 1825 script.set_match_all_frames(true); // Greasemonkey matches all frames. | 1846 script.set_match_all_frames(true); // Greasemonkey matches all frames. |
| 1826 } | 1847 } |
| 1827 content_scripts_.push_back(script); | 1848 content_scripts_.push_back(script); |
| 1828 } | 1849 } |
| 1829 } | 1850 } |
| 1830 | 1851 |
| 1852 // Initialize web accessible resources (optional). |
| 1853 if (manifest->HasKey(keys::kWebAccessibleResources)) { |
| 1854 ListValue* list_value; |
| 1855 if (!manifest->GetList(keys::kWebAccessibleResources, &list_value)) { |
| 1856 *error = ASCIIToUTF16(errors::kInvalidWebAccessibleResourcesList); |
| 1857 return false; |
| 1858 } |
| 1859 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
| 1860 std::string relative_path; |
| 1861 if (!list_value->GetString(i, &relative_path)) { |
| 1862 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 1863 errors::kInvalidWebAccessibleResource, base::IntToString(i)); |
| 1864 return false; |
| 1865 } |
| 1866 if (relative_path[0] != '/') |
| 1867 relative_path = '/' + relative_path; |
| 1868 web_accessible_resources_.insert(relative_path); |
| 1869 } |
| 1870 } |
| 1871 |
| 1831 // Initialize page action (optional). | 1872 // Initialize page action (optional). |
| 1832 DictionaryValue* page_action_value = NULL; | 1873 DictionaryValue* page_action_value = NULL; |
| 1833 | 1874 |
| 1834 if (manifest->HasKey(keys::kPageActions)) { | 1875 if (manifest->HasKey(keys::kPageActions)) { |
| 1835 ListValue* list_value = NULL; | 1876 ListValue* list_value = NULL; |
| 1836 if (!manifest->GetList(keys::kPageActions, &list_value)) { | 1877 if (!manifest->GetList(keys::kPageActions, &list_value)) { |
| 1837 *error = ASCIIToUTF16(errors::kInvalidPageActionsList); | 1878 *error = ASCIIToUTF16(errors::kInvalidPageActionsList); |
| 1838 return false; | 1879 return false; |
| 1839 } | 1880 } |
| 1840 | 1881 |
| (...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2980 already_disabled(false), | 3021 already_disabled(false), |
| 2981 extension(extension) {} | 3022 extension(extension) {} |
| 2982 | 3023 |
| 2983 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3024 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 2984 const Extension* extension, | 3025 const Extension* extension, |
| 2985 const ExtensionPermissionSet* permissions, | 3026 const ExtensionPermissionSet* permissions, |
| 2986 Reason reason) | 3027 Reason reason) |
| 2987 : reason(reason), | 3028 : reason(reason), |
| 2988 extension(extension), | 3029 extension(extension), |
| 2989 permissions(permissions) {} | 3030 permissions(permissions) {} |
| OLD | NEW |