OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/common/user_script.h" | 5 #include "extensions/common/user_script.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 void UserScript::File::Unpickle(const ::Pickle& pickle, PickleIterator* iter) { | 131 void UserScript::File::Unpickle(const ::Pickle& pickle, PickleIterator* iter) { |
132 // Read the url from the pickle. | 132 // Read the url from the pickle. |
133 std::string url; | 133 std::string url; |
134 CHECK(iter->ReadString(&url)); | 134 CHECK(iter->ReadString(&url)); |
135 set_url(GURL(url)); | 135 set_url(GURL(url)); |
136 } | 136 } |
137 | 137 |
138 void UserScript::Pickle(::Pickle* pickle) const { | 138 void UserScript::Pickle(::Pickle* pickle) const { |
139 // Write the simple types to the pickle. | 139 // Write the simple types to the pickle. |
140 pickle->WriteInt(run_location()); | 140 pickle->WriteInt(run_location()); |
141 pickle->WriteString(extension_id()); | |
142 pickle->WriteInt(user_script_id_); | 141 pickle->WriteInt(user_script_id_); |
143 pickle->WriteBool(emulate_greasemonkey()); | 142 pickle->WriteBool(emulate_greasemonkey()); |
144 pickle->WriteBool(match_all_frames()); | 143 pickle->WriteBool(match_all_frames()); |
145 pickle->WriteBool(match_about_blank()); | 144 pickle->WriteBool(match_about_blank()); |
146 pickle->WriteBool(is_incognito_enabled()); | 145 pickle->WriteBool(is_incognito_enabled()); |
147 | 146 |
| 147 PickleHostID(pickle, host_id_); |
148 PickleGlobs(pickle, globs_); | 148 PickleGlobs(pickle, globs_); |
149 PickleGlobs(pickle, exclude_globs_); | 149 PickleGlobs(pickle, exclude_globs_); |
150 PickleURLPatternSet(pickle, url_set_); | 150 PickleURLPatternSet(pickle, url_set_); |
151 PickleURLPatternSet(pickle, exclude_url_set_); | 151 PickleURLPatternSet(pickle, exclude_url_set_); |
152 PickleScripts(pickle, js_scripts_); | 152 PickleScripts(pickle, js_scripts_); |
153 PickleScripts(pickle, css_scripts_); | 153 PickleScripts(pickle, css_scripts_); |
154 } | 154 } |
155 | 155 |
156 void UserScript::PickleGlobs(::Pickle* pickle, | 156 void UserScript::PickleGlobs(::Pickle* pickle, |
157 const std::vector<std::string>& globs) const { | 157 const std::vector<std::string>& globs) const { |
158 pickle->WriteSizeT(globs.size()); | 158 pickle->WriteSizeT(globs.size()); |
159 for (std::vector<std::string>::const_iterator glob = globs.begin(); | 159 for (std::vector<std::string>::const_iterator glob = globs.begin(); |
160 glob != globs.end(); ++glob) { | 160 glob != globs.end(); ++glob) { |
161 pickle->WriteString(*glob); | 161 pickle->WriteString(*glob); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
| 165 void UserScript::PickleHostID(::Pickle* pickle, const HostID& host_id) const { |
| 166 pickle->WriteInt(host_id.type()); |
| 167 pickle->WriteString(host_id.id()); |
| 168 } |
| 169 |
165 void UserScript::PickleURLPatternSet(::Pickle* pickle, | 170 void UserScript::PickleURLPatternSet(::Pickle* pickle, |
166 const URLPatternSet& pattern_list) const { | 171 const URLPatternSet& pattern_list) const { |
167 pickle->WriteSizeT(pattern_list.patterns().size()); | 172 pickle->WriteSizeT(pattern_list.patterns().size()); |
168 for (URLPatternSet::const_iterator pattern = pattern_list.begin(); | 173 for (URLPatternSet::const_iterator pattern = pattern_list.begin(); |
169 pattern != pattern_list.end(); ++pattern) { | 174 pattern != pattern_list.end(); ++pattern) { |
170 pickle->WriteInt(pattern->valid_schemes()); | 175 pickle->WriteInt(pattern->valid_schemes()); |
171 pickle->WriteString(pattern->GetAsString()); | 176 pickle->WriteString(pattern->GetAsString()); |
172 } | 177 } |
173 } | 178 } |
174 | 179 |
175 void UserScript::PickleScripts(::Pickle* pickle, | 180 void UserScript::PickleScripts(::Pickle* pickle, |
176 const FileList& scripts) const { | 181 const FileList& scripts) const { |
177 pickle->WriteSizeT(scripts.size()); | 182 pickle->WriteSizeT(scripts.size()); |
178 for (FileList::const_iterator file = scripts.begin(); | 183 for (FileList::const_iterator file = scripts.begin(); |
179 file != scripts.end(); ++file) { | 184 file != scripts.end(); ++file) { |
180 file->Pickle(pickle); | 185 file->Pickle(pickle); |
181 } | 186 } |
182 } | 187 } |
183 | 188 |
184 void UserScript::Unpickle(const ::Pickle& pickle, PickleIterator* iter) { | 189 void UserScript::Unpickle(const ::Pickle& pickle, PickleIterator* iter) { |
185 // Read the run location. | 190 // Read the run location. |
186 int run_location = 0; | 191 int run_location = 0; |
187 CHECK(iter->ReadInt(&run_location)); | 192 CHECK(iter->ReadInt(&run_location)); |
188 CHECK(run_location >= 0 && run_location < RUN_LOCATION_LAST); | 193 CHECK(run_location >= 0 && run_location < RUN_LOCATION_LAST); |
189 run_location_ = static_cast<RunLocation>(run_location); | 194 run_location_ = static_cast<RunLocation>(run_location); |
190 | 195 |
191 CHECK(iter->ReadString(&extension_id_)); | |
192 CHECK(iter->ReadInt(&user_script_id_)); | 196 CHECK(iter->ReadInt(&user_script_id_)); |
193 CHECK(iter->ReadBool(&emulate_greasemonkey_)); | 197 CHECK(iter->ReadBool(&emulate_greasemonkey_)); |
194 CHECK(iter->ReadBool(&match_all_frames_)); | 198 CHECK(iter->ReadBool(&match_all_frames_)); |
195 CHECK(iter->ReadBool(&match_about_blank_)); | 199 CHECK(iter->ReadBool(&match_about_blank_)); |
196 CHECK(iter->ReadBool(&incognito_enabled_)); | 200 CHECK(iter->ReadBool(&incognito_enabled_)); |
197 | 201 |
| 202 UnpickleHostID(pickle, iter, &host_id_); |
198 UnpickleGlobs(pickle, iter, &globs_); | 203 UnpickleGlobs(pickle, iter, &globs_); |
199 UnpickleGlobs(pickle, iter, &exclude_globs_); | 204 UnpickleGlobs(pickle, iter, &exclude_globs_); |
200 UnpickleURLPatternSet(pickle, iter, &url_set_); | 205 UnpickleURLPatternSet(pickle, iter, &url_set_); |
201 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_); | 206 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_); |
202 UnpickleScripts(pickle, iter, &js_scripts_); | 207 UnpickleScripts(pickle, iter, &js_scripts_); |
203 UnpickleScripts(pickle, iter, &css_scripts_); | 208 UnpickleScripts(pickle, iter, &css_scripts_); |
204 } | 209 } |
205 | 210 |
206 void UserScript::UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, | 211 void UserScript::UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, |
207 std::vector<std::string>* globs) { | 212 std::vector<std::string>* globs) { |
208 size_t num_globs = 0; | 213 size_t num_globs = 0; |
209 CHECK(iter->ReadSizeT(&num_globs)); | 214 CHECK(iter->ReadSizeT(&num_globs)); |
210 globs->clear(); | 215 globs->clear(); |
211 for (size_t i = 0; i < num_globs; ++i) { | 216 for (size_t i = 0; i < num_globs; ++i) { |
212 std::string glob; | 217 std::string glob; |
213 CHECK(iter->ReadString(&glob)); | 218 CHECK(iter->ReadString(&glob)); |
214 globs->push_back(glob); | 219 globs->push_back(glob); |
215 } | 220 } |
216 } | 221 } |
217 | 222 |
| 223 void UserScript::UnpickleHostID(const ::Pickle& pickle, |
| 224 PickleIterator* iter, |
| 225 HostID* host_id) { |
| 226 int type = 0; |
| 227 std::string id; |
| 228 CHECK(iter->ReadInt(&type)); |
| 229 CHECK(iter->ReadString(&id)); |
| 230 *host_id = HostID(static_cast<HostID::HostType>(type), id); |
| 231 } |
| 232 |
218 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle, | 233 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle, |
219 PickleIterator* iter, | 234 PickleIterator* iter, |
220 URLPatternSet* pattern_list) { | 235 URLPatternSet* pattern_list) { |
221 size_t num_patterns = 0; | 236 size_t num_patterns = 0; |
222 CHECK(iter->ReadSizeT(&num_patterns)); | 237 CHECK(iter->ReadSizeT(&num_patterns)); |
223 | 238 |
224 pattern_list->ClearPatterns(); | 239 pattern_list->ClearPatterns(); |
225 for (size_t i = 0; i < num_patterns; ++i) { | 240 for (size_t i = 0; i < num_patterns; ++i) { |
226 int valid_schemes; | 241 int valid_schemes; |
227 CHECK(iter->ReadInt(&valid_schemes)); | 242 CHECK(iter->ReadInt(&valid_schemes)); |
(...skipping 24 matching lines...) Expand all Loading... |
252 } | 267 } |
253 | 268 |
254 bool operator<(const UserScript& script1, const UserScript& script2) { | 269 bool operator<(const UserScript& script1, const UserScript& script2) { |
255 // The only kind of script that should be compared is the kind that has its | 270 // The only kind of script that should be compared is the kind that has its |
256 // IDs initialized to a meaningful value. | 271 // IDs initialized to a meaningful value. |
257 DCHECK(script1.id() != -1 && script2.id() != -1); | 272 DCHECK(script1.id() != -1 && script2.id() != -1); |
258 return script1.id() < script2.id(); | 273 return script1.id() < script2.id(); |
259 } | 274 } |
260 | 275 |
261 } // namespace extensions | 276 } // namespace extensions |
OLD | NEW |