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

Side by Side Diff: chrome/browser/extensions/convert_user_script.cc

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes comments by eroman Created 9 years, 8 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) 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/browser/extensions/convert_user_script.h" 5 #include "chrome/browser/extensions/convert_user_script.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/memory/scoped_temp_dir.h" 13 #include "base/memory/scoped_temp_dir.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/sha2.h"
16 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "crypto/sha2.h"
17 #include "chrome/browser/extensions/user_script_master.h" 17 #include "chrome/browser/extensions/user_script_master.h"
18 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_constants.h" 20 #include "chrome/common/extensions/extension_constants.h"
21 #include "chrome/common/extensions/extension_file_util.h" 21 #include "chrome/common/extensions/extension_file_util.h"
22 #include "chrome/common/extensions/user_script.h" 22 #include "chrome/common/extensions/user_script.h"
23 #include "chrome/common/json_value_serializer.h" 23 #include "chrome/common/json_value_serializer.h"
24 #include "googleurl/src/gurl.h" 24 #include "googleurl/src/gurl.h"
25 25
26 namespace keys = extension_manifest_keys; 26 namespace keys = extension_manifest_keys;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 script_name = script.name_space() + "/" + script.name(); 65 script_name = script.name_space() + "/" + script.name();
66 else 66 else
67 script_name = original_url.spec(); 67 script_name = original_url.spec();
68 68
69 // Create the public key. 69 // Create the public key.
70 // User scripts are not signed, but the public key for an extension doubles as 70 // User scripts are not signed, but the public key for an extension doubles as
71 // its unique identity, and we need one of those. A user script's unique 71 // its unique identity, and we need one of those. A user script's unique
72 // identity is its namespace+name, so we hash that to create a public key. 72 // identity is its namespace+name, so we hash that to create a public key.
73 // There will be no corresponding private key, which means user scripts cannot 73 // There will be no corresponding private key, which means user scripts cannot
74 // be auto-updated, or claimed in the gallery. 74 // be auto-updated, or claimed in the gallery.
75 char raw[base::SHA256_LENGTH] = {0}; 75 char raw[crypto::SHA256_LENGTH] = {0};
76 std::string key; 76 std::string key;
77 base::SHA256HashString(script_name, raw, base::SHA256_LENGTH); 77 crypto::SHA256HashString(script_name, raw, crypto::SHA256_LENGTH);
78 base::Base64Encode(std::string(raw, base::SHA256_LENGTH), &key); 78 base::Base64Encode(std::string(raw, crypto::SHA256_LENGTH), &key);
79 79
80 // The script may not have a name field, but we need one for an extension. If 80 // The script may not have a name field, but we need one for an extension. If
81 // it is missing, use the filename of the original URL. 81 // it is missing, use the filename of the original URL.
82 if (!script.name().empty()) 82 if (!script.name().empty())
83 root->SetString(keys::kName, script.name()); 83 root->SetString(keys::kName, script.name());
84 else 84 else
85 root->SetString(keys::kName, original_url.ExtractFileName()); 85 root->SetString(keys::kName, original_url.ExtractFileName());
86 86
87 // Not all scripts have a version, but we need one. Default to 1.0 if it is 87 // Not all scripts have a version, but we need one. Default to 1.0 if it is
88 // missing. 88 // missing.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 Extension::NO_FLAGS, 153 Extension::NO_FLAGS,
154 error); 154 error);
155 if (!extension) { 155 if (!extension) {
156 NOTREACHED() << "Could not init extension " << *error; 156 NOTREACHED() << "Could not init extension " << *error;
157 return NULL; 157 return NULL;
158 } 158 }
159 159
160 temp_dir.Take(); // The caller takes ownership of the directory. 160 temp_dir.Take(); // The caller takes ownership of the directory.
161 return extension; 161 return extension;
162 } 162 }
OLDNEW
« no previous file with comments | « chrome/browser/enumerate_modules_model_win.cc ('k') | chrome/browser/extensions/convert_web_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698