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

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

Issue 399068: Move base64 from 'net/base' into 'base'. (Closed)
Patch Set: rebase Created 11 years, 1 month 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
« no previous file with comments | « chrome/browser/chrome_plugin_host.cc ('k') | chrome/browser/extensions/extension_creator.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/file_path.h" 11 #include "base/file_path.h"
11 #include "base/file_util.h" 12 #include "base/file_util.h"
12 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
13 #include "base/sha2.h" 14 #include "base/sha2.h"
14 #include "base/string_util.h" 15 #include "base/string_util.h"
15 #include "chrome/browser/extensions/user_script_master.h" 16 #include "chrome/browser/extensions/user_script_master.h"
16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_constants.h" 18 #include "chrome/common/extensions/extension_constants.h"
18 #include "chrome/common/extensions/user_script.h" 19 #include "chrome/common/extensions/user_script.h"
19 #include "chrome/common/json_value_serializer.h" 20 #include "chrome/common/json_value_serializer.h"
20 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
21 #include "net/base/base64.h"
22 22
23 namespace keys = extension_manifest_keys; 23 namespace keys = extension_manifest_keys;
24 24
25 Extension* ConvertUserScriptToExtension(const FilePath& user_script_path, 25 Extension* ConvertUserScriptToExtension(const FilePath& user_script_path,
26 const GURL& original_url, 26 const GURL& original_url,
27 std::string* error) { 27 std::string* error) {
28 std::string content; 28 std::string content;
29 if (!file_util::ReadFileToString(user_script_path, &content)) { 29 if (!file_util::ReadFileToString(user_script_path, &content)) {
30 *error = "Could not read source file: " + 30 *error = "Could not read source file: " +
31 WideToASCII(user_script_path.ToWStringHack()); 31 WideToASCII(user_script_path.ToWStringHack());
(...skipping 23 matching lines...) Expand all
55 55
56 // Create the public key. 56 // Create the public key.
57 // User scripts are not signed, but the public key for an extension doubles as 57 // User scripts are not signed, but the public key for an extension doubles as
58 // its unique identity, and we need one of those. A user script's unique 58 // its unique identity, and we need one of those. A user script's unique
59 // identity is its namespace+name, so we hash that to create a public key. 59 // identity is its namespace+name, so we hash that to create a public key.
60 // There will be no corresponding private key, which means user scripts cannot 60 // There will be no corresponding private key, which means user scripts cannot
61 // be auto-updated, or claimed in the gallery. 61 // be auto-updated, or claimed in the gallery.
62 char raw[base::SHA256_LENGTH] = {0}; 62 char raw[base::SHA256_LENGTH] = {0};
63 std::string key; 63 std::string key;
64 base::SHA256HashString(script_name, raw, base::SHA256_LENGTH); 64 base::SHA256HashString(script_name, raw, base::SHA256_LENGTH);
65 net::Base64Encode(std::string(raw, base::SHA256_LENGTH), &key); 65 base::Base64Encode(std::string(raw, base::SHA256_LENGTH), &key);
66 66
67 // The script may not have a name field, but we need one for an extension. If 67 // The script may not have a name field, but we need one for an extension. If
68 // it is missing, use the filename of the original URL. 68 // it is missing, use the filename of the original URL.
69 if (!script.name().empty()) 69 if (!script.name().empty())
70 root->SetString(keys::kName, script.name()); 70 root->SetString(keys::kName, script.name());
71 else 71 else
72 root->SetString(keys::kName, original_url.ExtractFileName()); 72 root->SetString(keys::kName, original_url.ExtractFileName());
73 73
74 root->SetString(keys::kDescription, script.description()); 74 root->SetString(keys::kDescription, script.description());
75 root->SetString(keys::kVersion, "1.0"); 75 root->SetString(keys::kVersion, "1.0");
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 scoped_ptr<Extension> extension(new Extension(temp_dir.path())); 130 scoped_ptr<Extension> extension(new Extension(temp_dir.path()));
131 if (!extension->InitFromValue(*root, false, error)) { 131 if (!extension->InitFromValue(*root, false, error)) {
132 NOTREACHED() << "Could not init extension " << *error; 132 NOTREACHED() << "Could not init extension " << *error;
133 return NULL; 133 return NULL;
134 } 134 }
135 135
136 temp_dir.Take(); // The caller takes ownership of the directory. 136 temp_dir.Take(); // The caller takes ownership of the directory.
137 return extension.release(); 137 return extension.release();
138 } 138 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_plugin_host.cc ('k') | chrome/browser/extensions/extension_creator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698