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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 if (!script.version().empty()) | 96 if (!script.version().empty()) |
97 root->SetString(keys::kVersion, script.version()); | 97 root->SetString(keys::kVersion, script.version()); |
98 else | 98 else |
99 root->SetString(keys::kVersion, "1.0"); | 99 root->SetString(keys::kVersion, "1.0"); |
100 | 100 |
101 root->SetString(keys::kDescription, script.description()); | 101 root->SetString(keys::kDescription, script.description()); |
102 root->SetString(keys::kPublicKey, key); | 102 root->SetString(keys::kPublicKey, key); |
103 root->SetBoolean(keys::kConvertedFromUserScript, true); | 103 root->SetBoolean(keys::kConvertedFromUserScript, true); |
104 | 104 |
105 base::ListValue* js_files = new base::ListValue(); | 105 base::ListValue* js_files = new base::ListValue(); |
106 js_files->Append(new base::StringValue("script.js")); | 106 js_files->AppendString("script.js"); |
107 | 107 |
108 // If the script provides its own match patterns, we use those. Otherwise, we | 108 // If the script provides its own match patterns, we use those. Otherwise, we |
109 // generate some using the include globs. | 109 // generate some using the include globs. |
110 base::ListValue* matches = new base::ListValue(); | 110 base::ListValue* matches = new base::ListValue(); |
111 if (!script.url_patterns().is_empty()) { | 111 if (!script.url_patterns().is_empty()) { |
112 for (URLPatternSet::const_iterator i = script.url_patterns().begin(); | 112 for (URLPatternSet::const_iterator i = script.url_patterns().begin(); |
113 i != script.url_patterns().end(); ++i) { | 113 i != script.url_patterns().end(); ++i) { |
114 matches->Append(new base::StringValue(i->GetAsString())); | 114 matches->AppendString(i->GetAsString()); |
115 } | 115 } |
116 } else { | 116 } else { |
117 // TODO(aa): Derive tighter matches where possible. | 117 // TODO(aa): Derive tighter matches where possible. |
118 matches->Append(new base::StringValue("http://*/*")); | 118 matches->AppendString("http://*/*"); |
119 matches->Append(new base::StringValue("https://*/*")); | 119 matches->AppendString("https://*/*"); |
120 } | 120 } |
121 | 121 |
122 // Read the exclude matches, if any are present. | 122 // Read the exclude matches, if any are present. |
123 base::ListValue* exclude_matches = new base::ListValue(); | 123 base::ListValue* exclude_matches = new base::ListValue(); |
124 if (!script.exclude_url_patterns().is_empty()) { | 124 if (!script.exclude_url_patterns().is_empty()) { |
125 for (URLPatternSet::const_iterator i = | 125 for (URLPatternSet::const_iterator i = |
126 script.exclude_url_patterns().begin(); | 126 script.exclude_url_patterns().begin(); |
127 i != script.exclude_url_patterns().end(); ++i) { | 127 i != script.exclude_url_patterns().end(); ++i) { |
128 exclude_matches->Append(new base::StringValue(i->GetAsString())); | 128 exclude_matches->AppendString(i->GetAsString()); |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 base::ListValue* includes = new base::ListValue(); | 132 base::ListValue* includes = new base::ListValue(); |
133 for (size_t i = 0; i < script.globs().size(); ++i) | 133 for (size_t i = 0; i < script.globs().size(); ++i) |
134 includes->Append(new base::StringValue(script.globs().at(i))); | 134 includes->AppendString(script.globs().at(i)); |
135 | 135 |
136 base::ListValue* excludes = new base::ListValue(); | 136 base::ListValue* excludes = new base::ListValue(); |
137 for (size_t i = 0; i < script.exclude_globs().size(); ++i) | 137 for (size_t i = 0; i < script.exclude_globs().size(); ++i) |
138 excludes->Append(new base::StringValue(script.exclude_globs().at(i))); | 138 excludes->AppendString(script.exclude_globs().at(i)); |
139 | 139 |
140 base::DictionaryValue* content_script = new base::DictionaryValue(); | 140 base::DictionaryValue* content_script = new base::DictionaryValue(); |
141 content_script->Set(keys::kMatches, matches); | 141 content_script->Set(keys::kMatches, matches); |
142 content_script->Set(keys::kExcludeMatches, exclude_matches); | 142 content_script->Set(keys::kExcludeMatches, exclude_matches); |
143 content_script->Set(keys::kIncludeGlobs, includes); | 143 content_script->Set(keys::kIncludeGlobs, includes); |
144 content_script->Set(keys::kExcludeGlobs, excludes); | 144 content_script->Set(keys::kExcludeGlobs, excludes); |
145 content_script->Set(keys::kJs, js_files); | 145 content_script->Set(keys::kJs, js_files); |
146 | 146 |
147 if (script.run_location() == UserScript::DOCUMENT_START) | 147 if (script.run_location() == UserScript::DOCUMENT_START) |
148 content_script->SetString(keys::kRunAt, values::kRunAtDocumentStart); | 148 content_script->SetString(keys::kRunAt, values::kRunAtDocumentStart); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 if (!extension.get()) { | 184 if (!extension.get()) { |
185 NOTREACHED() << "Could not init extension " << *error; | 185 NOTREACHED() << "Could not init extension " << *error; |
186 return NULL; | 186 return NULL; |
187 } | 187 } |
188 | 188 |
189 temp_dir.Take(); // The caller takes ownership of the directory. | 189 temp_dir.Take(); // The caller takes ownership of the directory. |
190 return extension; | 190 return extension; |
191 } | 191 } |
192 | 192 |
193 } // namespace extensions | 193 } // namespace extensions |
OLD | NEW |