| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 if (!script.version().empty()) | 95 if (!script.version().empty()) |
| 96 root->SetString(keys::kVersion, script.version()); | 96 root->SetString(keys::kVersion, script.version()); |
| 97 else | 97 else |
| 98 root->SetString(keys::kVersion, "1.0"); | 98 root->SetString(keys::kVersion, "1.0"); |
| 99 | 99 |
| 100 root->SetString(keys::kDescription, script.description()); | 100 root->SetString(keys::kDescription, script.description()); |
| 101 root->SetString(keys::kPublicKey, key); | 101 root->SetString(keys::kPublicKey, key); |
| 102 root->SetBoolean(keys::kConvertedFromUserScript, true); | 102 root->SetBoolean(keys::kConvertedFromUserScript, true); |
| 103 | 103 |
| 104 base::ListValue* js_files = new base::ListValue(); | 104 base::ListValue* js_files = new base::ListValue(); |
| 105 js_files->Append(Value::CreateStringValue("script.js")); | 105 js_files->Append(new base::StringValue("script.js")); |
| 106 | 106 |
| 107 // If the script provides its own match patterns, we use those. Otherwise, we | 107 // If the script provides its own match patterns, we use those. Otherwise, we |
| 108 // generate some using the include globs. | 108 // generate some using the include globs. |
| 109 base::ListValue* matches = new base::ListValue(); | 109 base::ListValue* matches = new base::ListValue(); |
| 110 if (!script.url_patterns().is_empty()) { | 110 if (!script.url_patterns().is_empty()) { |
| 111 for (URLPatternSet::const_iterator i = script.url_patterns().begin(); | 111 for (URLPatternSet::const_iterator i = script.url_patterns().begin(); |
| 112 i != script.url_patterns().end(); ++i) { | 112 i != script.url_patterns().end(); ++i) { |
| 113 matches->Append(Value::CreateStringValue(i->GetAsString())); | 113 matches->Append(new base::StringValue(i->GetAsString())); |
| 114 } | 114 } |
| 115 } else { | 115 } else { |
| 116 // TODO(aa): Derive tighter matches where possible. | 116 // TODO(aa): Derive tighter matches where possible. |
| 117 matches->Append(Value::CreateStringValue("http://*/*")); | 117 matches->Append(new base::StringValue("http://*/*")); |
| 118 matches->Append(Value::CreateStringValue("https://*/*")); | 118 matches->Append(new base::StringValue("https://*/*")); |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Read the exclude matches, if any are present. | 121 // Read the exclude matches, if any are present. |
| 122 base::ListValue* exclude_matches = new base::ListValue(); | 122 base::ListValue* exclude_matches = new base::ListValue(); |
| 123 if (!script.exclude_url_patterns().is_empty()) { | 123 if (!script.exclude_url_patterns().is_empty()) { |
| 124 for (URLPatternSet::const_iterator i = | 124 for (URLPatternSet::const_iterator i = |
| 125 script.exclude_url_patterns().begin(); | 125 script.exclude_url_patterns().begin(); |
| 126 i != script.exclude_url_patterns().end(); ++i) { | 126 i != script.exclude_url_patterns().end(); ++i) { |
| 127 exclude_matches->Append(Value::CreateStringValue(i->GetAsString())); | 127 exclude_matches->Append(new base::StringValue(i->GetAsString())); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 base::ListValue* includes = new base::ListValue(); | 131 base::ListValue* includes = new base::ListValue(); |
| 132 for (size_t i = 0; i < script.globs().size(); ++i) | 132 for (size_t i = 0; i < script.globs().size(); ++i) |
| 133 includes->Append(Value::CreateStringValue(script.globs().at(i))); | 133 includes->Append(new base::StringValue(script.globs().at(i))); |
| 134 | 134 |
| 135 base::ListValue* excludes = new base::ListValue(); | 135 base::ListValue* excludes = new base::ListValue(); |
| 136 for (size_t i = 0; i < script.exclude_globs().size(); ++i) | 136 for (size_t i = 0; i < script.exclude_globs().size(); ++i) |
| 137 excludes->Append(Value::CreateStringValue(script.exclude_globs().at(i))); | 137 excludes->Append(new base::StringValue(script.exclude_globs().at(i))); |
| 138 | 138 |
| 139 DictionaryValue* content_script = new DictionaryValue(); | 139 DictionaryValue* content_script = new DictionaryValue(); |
| 140 content_script->Set(keys::kMatches, matches); | 140 content_script->Set(keys::kMatches, matches); |
| 141 content_script->Set(keys::kExcludeMatches, exclude_matches); | 141 content_script->Set(keys::kExcludeMatches, exclude_matches); |
| 142 content_script->Set(keys::kIncludeGlobs, includes); | 142 content_script->Set(keys::kIncludeGlobs, includes); |
| 143 content_script->Set(keys::kExcludeGlobs, excludes); | 143 content_script->Set(keys::kExcludeGlobs, excludes); |
| 144 content_script->Set(keys::kJs, js_files); | 144 content_script->Set(keys::kJs, js_files); |
| 145 | 145 |
| 146 if (script.run_location() == UserScript::DOCUMENT_START) | 146 if (script.run_location() == UserScript::DOCUMENT_START) |
| 147 content_script->SetString(keys::kRunAt, values::kRunAtDocumentStart); | 147 content_script->SetString(keys::kRunAt, values::kRunAtDocumentStart); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 if (!extension.get()) { | 183 if (!extension.get()) { |
| 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 |