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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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->WriteInt(user_script_id_); | 141 pickle->WriteInt(user_script_id_); |
142 pickle->WriteBool(emulate_greasemonkey()); | 142 pickle->WriteBool(emulate_greasemonkey()); |
143 pickle->WriteBool(match_all_frames()); | 143 pickle->WriteBool(match_all_frames()); |
144 pickle->WriteBool(match_about_blank()); | 144 pickle->WriteBool(match_about_blank()); |
145 pickle->WriteBool(is_incognito_enabled()); | 145 pickle->WriteBool(is_incognito_enabled()); |
146 | 146 |
147 PickleHostID(pickle, host_id_); | 147 PickleHostID(pickle, host_id_); |
| 148 pickle->WriteInt(consumer_instance_type()); |
| 149 PickleRoutingInfo(pickle, routing_info_); |
148 PickleGlobs(pickle, globs_); | 150 PickleGlobs(pickle, globs_); |
149 PickleGlobs(pickle, exclude_globs_); | 151 PickleGlobs(pickle, exclude_globs_); |
150 PickleURLPatternSet(pickle, url_set_); | 152 PickleURLPatternSet(pickle, url_set_); |
151 PickleURLPatternSet(pickle, exclude_url_set_); | 153 PickleURLPatternSet(pickle, exclude_url_set_); |
152 PickleScripts(pickle, js_scripts_); | 154 PickleScripts(pickle, js_scripts_); |
153 PickleScripts(pickle, css_scripts_); | 155 PickleScripts(pickle, css_scripts_); |
154 } | 156 } |
155 | 157 |
156 void UserScript::PickleGlobs(::Pickle* pickle, | 158 void UserScript::PickleGlobs(::Pickle* pickle, |
157 const std::vector<std::string>& globs) const { | 159 const std::vector<std::string>& globs) const { |
158 pickle->WriteSizeT(globs.size()); | 160 pickle->WriteSizeT(globs.size()); |
159 for (std::vector<std::string>::const_iterator glob = globs.begin(); | 161 for (std::vector<std::string>::const_iterator glob = globs.begin(); |
160 glob != globs.end(); ++glob) { | 162 glob != globs.end(); ++glob) { |
161 pickle->WriteString(*glob); | 163 pickle->WriteString(*glob); |
162 } | 164 } |
163 } | 165 } |
164 | 166 |
165 void UserScript::PickleHostID(::Pickle* pickle, const HostID& host_id) const { | 167 void UserScript::PickleHostID(::Pickle* pickle, const HostID& host_id) const { |
166 pickle->WriteInt(host_id.type()); | 168 pickle->WriteInt(host_id.type()); |
167 pickle->WriteString(host_id.id()); | 169 pickle->WriteString(host_id.id()); |
168 } | 170 } |
169 | 171 |
| 172 void UserScript::PickleRoutingInfo(::Pickle* pickle, |
| 173 const RoutingInfo& routing_info) const { |
| 174 pickle->WriteInt(routing_info.render_process_id); |
| 175 pickle->WriteInt(routing_info.render_view_id); |
| 176 } |
| 177 |
170 void UserScript::PickleURLPatternSet(::Pickle* pickle, | 178 void UserScript::PickleURLPatternSet(::Pickle* pickle, |
171 const URLPatternSet& pattern_list) const { | 179 const URLPatternSet& pattern_list) const { |
172 pickle->WriteSizeT(pattern_list.patterns().size()); | 180 pickle->WriteSizeT(pattern_list.patterns().size()); |
173 for (URLPatternSet::const_iterator pattern = pattern_list.begin(); | 181 for (URLPatternSet::const_iterator pattern = pattern_list.begin(); |
174 pattern != pattern_list.end(); ++pattern) { | 182 pattern != pattern_list.end(); ++pattern) { |
175 pickle->WriteInt(pattern->valid_schemes()); | 183 pickle->WriteInt(pattern->valid_schemes()); |
176 pickle->WriteString(pattern->GetAsString()); | 184 pickle->WriteString(pattern->GetAsString()); |
177 } | 185 } |
178 } | 186 } |
179 | 187 |
(...skipping 13 matching lines...) Expand all Loading... |
193 CHECK(run_location >= 0 && run_location < RUN_LOCATION_LAST); | 201 CHECK(run_location >= 0 && run_location < RUN_LOCATION_LAST); |
194 run_location_ = static_cast<RunLocation>(run_location); | 202 run_location_ = static_cast<RunLocation>(run_location); |
195 | 203 |
196 CHECK(iter->ReadInt(&user_script_id_)); | 204 CHECK(iter->ReadInt(&user_script_id_)); |
197 CHECK(iter->ReadBool(&emulate_greasemonkey_)); | 205 CHECK(iter->ReadBool(&emulate_greasemonkey_)); |
198 CHECK(iter->ReadBool(&match_all_frames_)); | 206 CHECK(iter->ReadBool(&match_all_frames_)); |
199 CHECK(iter->ReadBool(&match_about_blank_)); | 207 CHECK(iter->ReadBool(&match_about_blank_)); |
200 CHECK(iter->ReadBool(&incognito_enabled_)); | 208 CHECK(iter->ReadBool(&incognito_enabled_)); |
201 | 209 |
202 UnpickleHostID(pickle, iter, &host_id_); | 210 UnpickleHostID(pickle, iter, &host_id_); |
| 211 |
| 212 int consumer_instance_type = 0; |
| 213 CHECK(iter->ReadInt(&consumer_instance_type)); |
| 214 consumer_instance_type_ = |
| 215 static_cast<ConsumerInstanceType>(consumer_instance_type); |
| 216 |
| 217 UnpickleRoutingInfo(pickle, iter, &routing_info_); |
203 UnpickleGlobs(pickle, iter, &globs_); | 218 UnpickleGlobs(pickle, iter, &globs_); |
204 UnpickleGlobs(pickle, iter, &exclude_globs_); | 219 UnpickleGlobs(pickle, iter, &exclude_globs_); |
205 UnpickleURLPatternSet(pickle, iter, &url_set_); | 220 UnpickleURLPatternSet(pickle, iter, &url_set_); |
206 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_); | 221 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_); |
207 UnpickleScripts(pickle, iter, &js_scripts_); | 222 UnpickleScripts(pickle, iter, &js_scripts_); |
208 UnpickleScripts(pickle, iter, &css_scripts_); | 223 UnpickleScripts(pickle, iter, &css_scripts_); |
209 } | 224 } |
210 | 225 |
211 void UserScript::UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, | 226 void UserScript::UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, |
212 std::vector<std::string>* globs) { | 227 std::vector<std::string>* globs) { |
(...skipping 10 matching lines...) Expand all Loading... |
223 void UserScript::UnpickleHostID(const ::Pickle& pickle, | 238 void UserScript::UnpickleHostID(const ::Pickle& pickle, |
224 PickleIterator* iter, | 239 PickleIterator* iter, |
225 HostID* host_id) { | 240 HostID* host_id) { |
226 int type = 0; | 241 int type = 0; |
227 std::string id; | 242 std::string id; |
228 CHECK(iter->ReadInt(&type)); | 243 CHECK(iter->ReadInt(&type)); |
229 CHECK(iter->ReadString(&id)); | 244 CHECK(iter->ReadString(&id)); |
230 *host_id = HostID(static_cast<HostID::HostType>(type), id); | 245 *host_id = HostID(static_cast<HostID::HostType>(type), id); |
231 } | 246 } |
232 | 247 |
| 248 void UserScript::UnpickleRoutingInfo(const ::Pickle& pickle, |
| 249 PickleIterator* iter, |
| 250 RoutingInfo* routing_info) { |
| 251 CHECK(iter->ReadInt(&routing_info->render_process_id)); |
| 252 CHECK(iter->ReadInt(&routing_info->render_view_id)); |
| 253 } |
| 254 |
233 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle, | 255 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle, |
234 PickleIterator* iter, | 256 PickleIterator* iter, |
235 URLPatternSet* pattern_list) { | 257 URLPatternSet* pattern_list) { |
236 size_t num_patterns = 0; | 258 size_t num_patterns = 0; |
237 CHECK(iter->ReadSizeT(&num_patterns)); | 259 CHECK(iter->ReadSizeT(&num_patterns)); |
238 | 260 |
239 pattern_list->ClearPatterns(); | 261 pattern_list->ClearPatterns(); |
240 for (size_t i = 0; i < num_patterns; ++i) { | 262 for (size_t i = 0; i < num_patterns; ++i) { |
241 int valid_schemes; | 263 int valid_schemes; |
242 CHECK(iter->ReadInt(&valid_schemes)); | 264 CHECK(iter->ReadInt(&valid_schemes)); |
(...skipping 24 matching lines...) Expand all Loading... |
267 } | 289 } |
268 | 290 |
269 bool operator<(const UserScript& script1, const UserScript& script2) { | 291 bool operator<(const UserScript& script1, const UserScript& script2) { |
270 // The only kind of script that should be compared is the kind that has its | 292 // The only kind of script that should be compared is the kind that has its |
271 // IDs initialized to a meaningful value. | 293 // IDs initialized to a meaningful value. |
272 DCHECK(script1.id() != -1 && script2.id() != -1); | 294 DCHECK(script1.id() != -1 && script2.id() != -1); |
273 return script1.id() < script2.id(); | 295 return script1.id() < script2.id(); |
274 } | 296 } |
275 | 297 |
276 } // namespace extensions | 298 } // namespace extensions |
OLD | NEW |