| OLD | NEW |
| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (!script.version().empty()) | 90 if (!script.version().empty()) |
| 91 root->SetString(keys::kVersion, script.version()); | 91 root->SetString(keys::kVersion, script.version()); |
| 92 else | 92 else |
| 93 root->SetString(keys::kVersion, "1.0"); | 93 root->SetString(keys::kVersion, "1.0"); |
| 94 | 94 |
| 95 root->SetString(keys::kDescription, script.description()); | 95 root->SetString(keys::kDescription, script.description()); |
| 96 root->SetString(keys::kPublicKey, key); | 96 root->SetString(keys::kPublicKey, key); |
| 97 root->SetBoolean(keys::kConvertedFromUserScript, true); | 97 root->SetBoolean(keys::kConvertedFromUserScript, true); |
| 98 | 98 |
| 99 ListValue* js_files = new ListValue(); | 99 ListValue* js_files = new ListValue(); |
| 100 js_files->Append(Value::CreateStringValue("script.js")); | 100 js_files->Append(base::StringValue::New("script.js")); |
| 101 | 101 |
| 102 // If the script provides its own match patterns, we use those. Otherwise, we | 102 // If the script provides its own match patterns, we use those. Otherwise, we |
| 103 // generate some using the include globs. | 103 // generate some using the include globs. |
| 104 ListValue* matches = new ListValue(); | 104 ListValue* matches = new ListValue(); |
| 105 if (!script.url_patterns().is_empty()) { | 105 if (!script.url_patterns().is_empty()) { |
| 106 for (URLPatternSet::const_iterator i = script.url_patterns().begin(); | 106 for (URLPatternSet::const_iterator i = script.url_patterns().begin(); |
| 107 i != script.url_patterns().end(); ++i) { | 107 i != script.url_patterns().end(); ++i) { |
| 108 matches->Append(Value::CreateStringValue(i->GetAsString())); | 108 matches->Append(base::StringValue::New(i->GetAsString())); |
| 109 } | 109 } |
| 110 } else { | 110 } else { |
| 111 // TODO(aa): Derive tighter matches where possible. | 111 // TODO(aa): Derive tighter matches where possible. |
| 112 matches->Append(Value::CreateStringValue("http://*/*")); | 112 matches->Append(base::StringValue::New("http://*/*")); |
| 113 matches->Append(Value::CreateStringValue("https://*/*")); | 113 matches->Append(base::StringValue::New("https://*/*")); |
| 114 } | 114 } |
| 115 | 115 |
| 116 ListValue* includes = new ListValue(); | 116 ListValue* includes = new ListValue(); |
| 117 for (size_t i = 0; i < script.globs().size(); ++i) | 117 for (size_t i = 0; i < script.globs().size(); ++i) |
| 118 includes->Append(Value::CreateStringValue(script.globs().at(i))); | 118 includes->Append(base::StringValue::New(script.globs().at(i))); |
| 119 | 119 |
| 120 ListValue* excludes = new ListValue(); | 120 ListValue* excludes = new ListValue(); |
| 121 for (size_t i = 0; i < script.exclude_globs().size(); ++i) | 121 for (size_t i = 0; i < script.exclude_globs().size(); ++i) |
| 122 excludes->Append(Value::CreateStringValue(script.exclude_globs().at(i))); | 122 excludes->Append(base::StringValue::New(script.exclude_globs().at(i))); |
| 123 | 123 |
| 124 DictionaryValue* content_script = new DictionaryValue(); | 124 DictionaryValue* content_script = new DictionaryValue(); |
| 125 content_script->Set(keys::kMatches, matches); | 125 content_script->Set(keys::kMatches, matches); |
| 126 content_script->Set(keys::kIncludeGlobs, includes); | 126 content_script->Set(keys::kIncludeGlobs, includes); |
| 127 content_script->Set(keys::kExcludeGlobs, excludes); | 127 content_script->Set(keys::kExcludeGlobs, excludes); |
| 128 content_script->Set(keys::kJs, js_files); | 128 content_script->Set(keys::kJs, js_files); |
| 129 | 129 |
| 130 if (script.run_location() == UserScript::DOCUMENT_START) | 130 if (script.run_location() == UserScript::DOCUMENT_START) |
| 131 content_script->SetString(keys::kRunAt, values::kRunAtDocumentStart); | 131 content_script->SetString(keys::kRunAt, values::kRunAtDocumentStart); |
| 132 else if (script.run_location() == UserScript::DOCUMENT_END) | 132 else if (script.run_location() == UserScript::DOCUMENT_END) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 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 } |
| OLD | NEW |