| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 GURL ret_val = GURL(extension_url.spec() + relative_path); | 199 GURL ret_val = GURL(extension_url.spec() + relative_path); |
| 200 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); | 200 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); |
| 201 | 201 |
| 202 return ret_val; | 202 return ret_val; |
| 203 } | 203 } |
| 204 | 204 |
| 205 bool Extension::GenerateId(const std::string& input, std::string* output) { | 205 bool Extension::GenerateId(const std::string& input, std::string* output) { |
| 206 CHECK(output); | 206 CHECK(output); |
| 207 if (input.length() == 0) | 207 if (input.length() == 0) |
| 208 return false; | 208 return false; |
| 209 | |
| 210 const uint8* ubuf = reinterpret_cast<const unsigned char*>(input.data()); | 209 const uint8* ubuf = reinterpret_cast<const unsigned char*>(input.data()); |
| 211 SHA256Context ctx; | 210 SHA256Context ctx; |
| 212 SHA256_Begin(&ctx); | 211 SHA256_Begin(&ctx); |
| 213 SHA256_Update(&ctx, ubuf, input.length()); | 212 SHA256_Update(&ctx, ubuf, input.length()); |
| 214 uint8 hash[Extension::kIdSize]; | 213 uint8 hash[Extension::kIdSize]; |
| 215 SHA256_End(&ctx, hash, NULL, sizeof(hash)); | 214 SHA256_End(&ctx, hash, NULL, sizeof(hash)); |
| 216 *output = StringToLowerASCII(HexEncode(hash, sizeof(hash))); | 215 *output = StringToLowerASCII(HexEncode(hash, sizeof(hash))); |
| 217 ConvertHexadecimalToIDAlphabet(output); | 216 ConvertHexadecimalToIDAlphabet(output); |
| 218 | |
| 219 return true; | 217 return true; |
| 220 } | 218 } |
| 221 | 219 |
| 222 // Helper method that loads a UserScript object from a dictionary in the | 220 // Helper method that loads a UserScript object from a dictionary in the |
| 223 // content_script list of the manifest. | 221 // content_script list of the manifest. |
| 224 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, | 222 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, |
| 225 int definition_index, std::string* error, | 223 int definition_index, std::string* error, |
| 226 UserScript* result) { | 224 UserScript* result) { |
| 227 // run_at | 225 // run_at |
| 228 if (content_script->HasKey(keys::kRunAt)) { | 226 if (content_script->HasKey(keys::kRunAt)) { |
| (...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 } | 1439 } |
| 1442 | 1440 |
| 1443 // Validate that the overrides are all strings | 1441 // Validate that the overrides are all strings |
| 1444 for (DictionaryValue::key_iterator iter = overrides->begin_keys(); | 1442 for (DictionaryValue::key_iterator iter = overrides->begin_keys(); |
| 1445 iter != overrides->end_keys(); ++iter) { | 1443 iter != overrides->end_keys(); ++iter) { |
| 1446 std::string page = WideToUTF8(*iter); | 1444 std::string page = WideToUTF8(*iter); |
| 1447 std::string val; | 1445 std::string val; |
| 1448 // Restrict override pages to a list of supported URLs. | 1446 // Restrict override pages to a list of supported URLs. |
| 1449 if ((page != chrome::kChromeUINewTabHost && | 1447 if ((page != chrome::kChromeUINewTabHost && |
| 1450 page != chrome::kChromeUIBookmarksHost && | 1448 page != chrome::kChromeUIBookmarksHost && |
| 1451 page != chrome::kChromeUIHistoryHost) || | 1449 page != chrome::kChromeUIHistoryHost && |
| 1450 page != chrome::kChromeUIPrintPreviewHost) || |
| 1452 !overrides->GetStringWithoutPathExpansion(*iter, &val)) { | 1451 !overrides->GetStringWithoutPathExpansion(*iter, &val)) { |
| 1453 *error = errors::kInvalidChromeURLOverrides; | 1452 *error = errors::kInvalidChromeURLOverrides; |
| 1454 return false; | 1453 return false; |
| 1455 } | 1454 } |
| 1456 // Replace the entry with a fully qualified chrome-extension:// URL. | 1455 // Replace the entry with a fully qualified chrome-extension:// URL. |
| 1457 chrome_url_overrides_[page] = GetResourceURL(val); | 1456 chrome_url_overrides_[page] = GetResourceURL(val); |
| 1458 } | 1457 } |
| 1459 | 1458 |
| 1460 // An extension may override at most one page. | 1459 // An extension may override at most one page. |
| 1461 if (overrides->size() > 1) { | 1460 if (overrides->size() > 1) { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1730 } else { | 1729 } else { |
| 1731 return false; | 1730 return false; |
| 1732 } | 1731 } |
| 1733 } else { | 1732 } else { |
| 1734 return true; | 1733 return true; |
| 1735 } | 1734 } |
| 1736 } | 1735 } |
| 1737 } | 1736 } |
| 1738 return false; | 1737 return false; |
| 1739 } | 1738 } |
| OLD | NEW |