OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/json/json_file_value_serializer.h" | 14 #include "base/json/json_file_value_serializer.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/browser/extensions/user_script_master.h" | 18 #include "chrome/browser/extensions/user_script_master.h" |
19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/common/extensions/extension_file_util.h" | 21 #include "chrome/common/extensions/extension_file_util.h" |
22 #include "chrome/common/extensions/extension_manifest_constants.h" | 22 #include "chrome/common/extensions/extension_manifest_constants.h" |
23 #include "chrome/common/extensions/user_script.h" | 23 #include "chrome/common/extensions/user_script.h" |
24 #include "crypto/sha2.h" | 24 #include "crypto/sha2.h" |
| 25 #include "extensions/common/constants.h" |
25 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
26 | 27 |
27 namespace keys = extension_manifest_keys; | 28 namespace keys = extension_manifest_keys; |
28 namespace values = extension_manifest_values; | 29 namespace values = extension_manifest_values; |
29 | 30 |
30 namespace extensions { | 31 namespace extensions { |
31 | 32 |
32 scoped_refptr<Extension> ConvertUserScriptToExtension( | 33 scoped_refptr<Extension> ConvertUserScriptToExtension( |
33 const base::FilePath& user_script_path, const GURL& original_url, | 34 const base::FilePath& user_script_path, const GURL& original_url, |
34 const base::FilePath& extensions_dir, string16* error) { | 35 const base::FilePath& extensions_dir, string16* error) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 content_script->SetString(keys::kRunAt, values::kRunAtDocumentEnd); | 149 content_script->SetString(keys::kRunAt, values::kRunAtDocumentEnd); |
149 else if (script.run_location() == UserScript::DOCUMENT_IDLE) | 150 else if (script.run_location() == UserScript::DOCUMENT_IDLE) |
150 // This is the default, but store it just in case we change that. | 151 // This is the default, but store it just in case we change that. |
151 content_script->SetString(keys::kRunAt, values::kRunAtDocumentIdle); | 152 content_script->SetString(keys::kRunAt, values::kRunAtDocumentIdle); |
152 | 153 |
153 ListValue* content_scripts = new ListValue(); | 154 ListValue* content_scripts = new ListValue(); |
154 content_scripts->Append(content_script); | 155 content_scripts->Append(content_script); |
155 | 156 |
156 root->Set(keys::kContentScripts, content_scripts); | 157 root->Set(keys::kContentScripts, content_scripts); |
157 | 158 |
158 base::FilePath manifest_path = temp_dir.path().Append( | 159 base::FilePath manifest_path = temp_dir.path().Append(kManifestFilename); |
159 Extension::kManifestFilename); | |
160 JSONFileValueSerializer serializer(manifest_path); | 160 JSONFileValueSerializer serializer(manifest_path); |
161 if (!serializer.Serialize(*root)) { | 161 if (!serializer.Serialize(*root)) { |
162 *error = ASCIIToUTF16("Could not write JSON."); | 162 *error = ASCIIToUTF16("Could not write JSON."); |
163 return NULL; | 163 return NULL; |
164 } | 164 } |
165 | 165 |
166 // Write the script file. | 166 // Write the script file. |
167 if (!file_util::CopyFile(user_script_path, | 167 if (!file_util::CopyFile(user_script_path, |
168 temp_dir.path().AppendASCII("script.js"))) { | 168 temp_dir.path().AppendASCII("script.js"))) { |
169 *error = ASCIIToUTF16("Could not copy script file."); | 169 *error = ASCIIToUTF16("Could not copy script file."); |
(...skipping 13 matching lines...) Expand all Loading... |
183 if (!extension) { | 183 if (!extension) { |
184 NOTREACHED() << "Could not init extension " << *error; | 184 NOTREACHED() << "Could not init extension " << *error; |
185 return NULL; | 185 return NULL; |
186 } | 186 } |
187 | 187 |
188 temp_dir.Take(); // The caller takes ownership of the directory. | 188 temp_dir.Take(); // The caller takes ownership of the directory. |
189 return extension; | 189 return extension; |
190 } | 190 } |
191 | 191 |
192 } // namespace extensions | 192 } // namespace extensions |
OLD | NEW |