| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "crypto/sha2.h" | 24 #include "crypto/sha2.h" |
| 25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 26 | 26 |
| 27 namespace keys = extension_manifest_keys; | 27 namespace keys = extension_manifest_keys; |
| 28 namespace values = extension_manifest_values; | 28 namespace values = extension_manifest_values; |
| 29 | 29 |
| 30 namespace extensions { | 30 namespace extensions { |
| 31 | 31 |
| 32 scoped_refptr<Extension> ConvertUserScriptToExtension( | 32 scoped_refptr<Extension> ConvertUserScriptToExtension( |
| 33 const FilePath& user_script_path, const GURL& original_url, | 33 const FilePath& user_script_path, const GURL& original_url, |
| 34 string16* error) { | 34 const FilePath& extensions_dir, string16* error) { |
| 35 std::string content; | 35 std::string content; |
| 36 if (!file_util::ReadFileToString(user_script_path, &content)) { | 36 if (!file_util::ReadFileToString(user_script_path, &content)) { |
| 37 *error = ASCIIToUTF16("Could not read source file."); | 37 *error = ASCIIToUTF16("Could not read source file."); |
| 38 return NULL; | 38 return NULL; |
| 39 } | 39 } |
| 40 | 40 |
| 41 if (!IsStringUTF8(content)) { | 41 if (!IsStringUTF8(content)) { |
| 42 *error = ASCIIToUTF16("User script must be UTF8 encoded."); | 42 *error = ASCIIToUTF16("User script must be UTF8 encoded."); |
| 43 return NULL; | 43 return NULL; |
| 44 } | 44 } |
| 45 | 45 |
| 46 UserScript script; | 46 UserScript script; |
| 47 if (!UserScriptMaster::ScriptReloader::ParseMetadataHeader(content, | 47 if (!UserScriptMaster::ScriptReloader::ParseMetadataHeader(content, |
| 48 &script)) { | 48 &script)) { |
| 49 *error = ASCIIToUTF16("Invalid script header."); | 49 *error = ASCIIToUTF16("Invalid script header."); |
| 50 return NULL; | 50 return NULL; |
| 51 } | 51 } |
| 52 | 52 |
| 53 FilePath user_data_temp_dir = extension_file_util::GetUserDataTempDir(); | 53 FilePath install_temp_dir = |
| 54 if (user_data_temp_dir.empty()) { | 54 extension_file_util::GetInstallTempDir(extensions_dir); |
| 55 if (install_temp_dir.empty()) { |
| 55 *error = ASCIIToUTF16("Could not get path to profile temporary directory."); | 56 *error = ASCIIToUTF16("Could not get path to profile temporary directory."); |
| 56 return NULL; | 57 return NULL; |
| 57 } | 58 } |
| 58 | 59 |
| 59 ScopedTempDir temp_dir; | 60 ScopedTempDir temp_dir; |
| 60 if (!temp_dir.CreateUniqueTempDirUnderPath(user_data_temp_dir)) { | 61 if (!temp_dir.CreateUniqueTempDirUnderPath(install_temp_dir)) { |
| 61 *error = ASCIIToUTF16("Could not create temporary directory."); | 62 *error = ASCIIToUTF16("Could not create temporary directory."); |
| 62 return NULL; | 63 return NULL; |
| 63 } | 64 } |
| 64 | 65 |
| 65 // Create the manifest | 66 // Create the manifest |
| 66 scoped_ptr<DictionaryValue> root(new DictionaryValue); | 67 scoped_ptr<DictionaryValue> root(new DictionaryValue); |
| 67 std::string script_name; | 68 std::string script_name; |
| 68 if (!script.name().empty() && !script.name_space().empty()) | 69 if (!script.name().empty() && !script.name_space().empty()) |
| 69 script_name = script.name_space() + "/" + script.name(); | 70 script_name = script.name_space() + "/" + script.name(); |
| 70 else | 71 else |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 if (!extension) { | 183 if (!extension) { |
| 183 NOTREACHED() << "Could not init extension " << *error; | 184 NOTREACHED() << "Could not init extension " << *error; |
| 184 return NULL; | 185 return NULL; |
| 185 } | 186 } |
| 186 | 187 |
| 187 temp_dir.Take(); // The caller takes ownership of the directory. | 188 temp_dir.Take(); // The caller takes ownership of the directory. |
| 188 return extension; | 189 return extension; |
| 189 } | 190 } |
| 190 | 191 |
| 191 } // namespace extensions | 192 } // namespace extensions |
| OLD | NEW |