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

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

Issue 7823004: Convert SHA256_LENGTH from a constant-in-anonymous-enum to a static const. This defines the cons... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 3 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"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 script_name = script.name_space() + "/" + script.name(); 66 script_name = script.name_space() + "/" + script.name();
67 else 67 else
68 script_name = original_url.spec(); 68 script_name = original_url.spec();
69 69
70 // Create the public key. 70 // Create the public key.
71 // User scripts are not signed, but the public key for an extension doubles as 71 // User scripts are not signed, but the public key for an extension doubles as
72 // its unique identity, and we need one of those. A user script's unique 72 // its unique identity, and we need one of those. A user script's unique
73 // identity is its namespace+name, so we hash that to create a public key. 73 // identity is its namespace+name, so we hash that to create a public key.
74 // There will be no corresponding private key, which means user scripts cannot 74 // There will be no corresponding private key, which means user scripts cannot
75 // be auto-updated, or claimed in the gallery. 75 // be auto-updated, or claimed in the gallery.
76 char raw[crypto::SHA256_LENGTH] = {0}; 76 char raw[crypto::kSHA256Length] = {0};
77 std::string key; 77 std::string key;
78 crypto::SHA256HashString(script_name, raw, crypto::SHA256_LENGTH); 78 crypto::SHA256HashString(script_name, raw, crypto::kSHA256Length);
79 base::Base64Encode(std::string(raw, crypto::SHA256_LENGTH), &key); 79 base::Base64Encode(std::string(raw, crypto::kSHA256Length), &key);
80 80
81 // The script may not have a name field, but we need one for an extension. If 81 // The script may not have a name field, but we need one for an extension. If
82 // it is missing, use the filename of the original URL. 82 // it is missing, use the filename of the original URL.
83 if (!script.name().empty()) 83 if (!script.name().empty())
84 root->SetString(keys::kName, script.name()); 84 root->SetString(keys::kName, script.name());
85 else 85 else
86 root->SetString(keys::kName, original_url.ExtractFileName()); 86 root->SetString(keys::kName, original_url.ExtractFileName());
87 87
88 // Not all scripts have a version, but we need one. Default to 1.0 if it is 88 // Not all scripts have a version, but we need one. Default to 1.0 if it is
89 // missing. 89 // missing.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 Extension::NO_FLAGS, 162 Extension::NO_FLAGS,
163 error); 163 error);
164 if (!extension) { 164 if (!extension) {
165 NOTREACHED() << "Could not init extension " << *error; 165 NOTREACHED() << "Could not init extension " << *error;
166 return NULL; 166 return NULL;
167 } 167 }
168 168
169 temp_dir.Take(); // The caller takes ownership of the directory. 169 temp_dir.Take(); // The caller takes ownership of the directory.
170 return extension; 170 return extension;
171 } 171 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/convert_web_app.cc » ('j') | chrome/browser/extensions/convert_web_app.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698