Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: extensions/common/user_script.cc

Issue 822453002: Introduce HostID and de-couple Extensions from "script injection System" [browser side] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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()); 141 pickle->WriteString(extension_id());
142 pickle->WriteInt(user_script_id_); 142 pickle->WriteInt(user_script_id_);
143 pickle->WriteBool(emulate_greasemonkey()); 143 pickle->WriteBool(emulate_greasemonkey());
144 pickle->WriteBool(match_all_frames()); 144 pickle->WriteBool(match_all_frames());
145 pickle->WriteBool(match_about_blank()); 145 pickle->WriteBool(match_about_blank());
146 pickle->WriteBool(is_incognito_enabled()); 146 pickle->WriteBool(is_incognito_enabled());
147 147
148 PickleConsumerID(pickle, consumer_id());
148 PickleGlobs(pickle, globs_); 149 PickleGlobs(pickle, globs_);
149 PickleGlobs(pickle, exclude_globs_); 150 PickleGlobs(pickle, exclude_globs_);
150 PickleURLPatternSet(pickle, url_set_); 151 PickleURLPatternSet(pickle, url_set_);
151 PickleURLPatternSet(pickle, exclude_url_set_); 152 PickleURLPatternSet(pickle, exclude_url_set_);
152 PickleScripts(pickle, js_scripts_); 153 PickleScripts(pickle, js_scripts_);
153 PickleScripts(pickle, css_scripts_); 154 PickleScripts(pickle, css_scripts_);
154 } 155 }
155 156
156 void UserScript::PickleGlobs(::Pickle* pickle, 157 void UserScript::PickleGlobs(::Pickle* pickle,
157 const std::vector<std::string>& globs) const { 158 const std::vector<std::string>& globs) const {
158 pickle->WriteSizeT(globs.size()); 159 pickle->WriteSizeT(globs.size());
159 for (std::vector<std::string>::const_iterator glob = globs.begin(); 160 for (std::vector<std::string>::const_iterator glob = globs.begin();
160 glob != globs.end(); ++glob) { 161 glob != globs.end(); ++glob) {
161 pickle->WriteString(*glob); 162 pickle->WriteString(*glob);
162 } 163 }
163 } 164 }
164 165
166 void UserScript::PickleConsumerID(::Pickle* pickle,
167 const ConsumerID& consumer_id) const {
168 pickle->WriteInt(consumer_id.host_type);
169 pickle->WriteString(consumer_id.host_id);
170 pickle->WriteInt(consumer_id.instance_type);
171 pickle->WriteInt(consumer_id.instance_id);
172 }
173
165 void UserScript::PickleURLPatternSet(::Pickle* pickle, 174 void UserScript::PickleURLPatternSet(::Pickle* pickle,
166 const URLPatternSet& pattern_list) const { 175 const URLPatternSet& pattern_list) const {
167 pickle->WriteSizeT(pattern_list.patterns().size()); 176 pickle->WriteSizeT(pattern_list.patterns().size());
168 for (URLPatternSet::const_iterator pattern = pattern_list.begin(); 177 for (URLPatternSet::const_iterator pattern = pattern_list.begin();
169 pattern != pattern_list.end(); ++pattern) { 178 pattern != pattern_list.end(); ++pattern) {
170 pickle->WriteInt(pattern->valid_schemes()); 179 pickle->WriteInt(pattern->valid_schemes());
171 pickle->WriteString(pattern->GetAsString()); 180 pickle->WriteString(pattern->GetAsString());
172 } 181 }
173 } 182 }
174 183
(...skipping 13 matching lines...) Expand all
188 CHECK(run_location >= 0 && run_location < RUN_LOCATION_LAST); 197 CHECK(run_location >= 0 && run_location < RUN_LOCATION_LAST);
189 run_location_ = static_cast<RunLocation>(run_location); 198 run_location_ = static_cast<RunLocation>(run_location);
190 199
191 CHECK(iter->ReadString(&extension_id_)); 200 CHECK(iter->ReadString(&extension_id_));
192 CHECK(iter->ReadInt(&user_script_id_)); 201 CHECK(iter->ReadInt(&user_script_id_));
193 CHECK(iter->ReadBool(&emulate_greasemonkey_)); 202 CHECK(iter->ReadBool(&emulate_greasemonkey_));
194 CHECK(iter->ReadBool(&match_all_frames_)); 203 CHECK(iter->ReadBool(&match_all_frames_));
195 CHECK(iter->ReadBool(&match_about_blank_)); 204 CHECK(iter->ReadBool(&match_about_blank_));
196 CHECK(iter->ReadBool(&incognito_enabled_)); 205 CHECK(iter->ReadBool(&incognito_enabled_));
197 206
207 UnpickleConsumerID(pickle, iter, &consumer_id_);
198 UnpickleGlobs(pickle, iter, &globs_); 208 UnpickleGlobs(pickle, iter, &globs_);
199 UnpickleGlobs(pickle, iter, &exclude_globs_); 209 UnpickleGlobs(pickle, iter, &exclude_globs_);
200 UnpickleURLPatternSet(pickle, iter, &url_set_); 210 UnpickleURLPatternSet(pickle, iter, &url_set_);
201 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_); 211 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_);
202 UnpickleScripts(pickle, iter, &js_scripts_); 212 UnpickleScripts(pickle, iter, &js_scripts_);
203 UnpickleScripts(pickle, iter, &css_scripts_); 213 UnpickleScripts(pickle, iter, &css_scripts_);
204 } 214 }
205 215
206 void UserScript::UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, 216 void UserScript::UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter,
207 std::vector<std::string>* globs) { 217 std::vector<std::string>* globs) {
208 size_t num_globs = 0; 218 size_t num_globs = 0;
209 CHECK(iter->ReadSizeT(&num_globs)); 219 CHECK(iter->ReadSizeT(&num_globs));
210 globs->clear(); 220 globs->clear();
211 for (size_t i = 0; i < num_globs; ++i) { 221 for (size_t i = 0; i < num_globs; ++i) {
212 std::string glob; 222 std::string glob;
213 CHECK(iter->ReadString(&glob)); 223 CHECK(iter->ReadString(&glob));
214 globs->push_back(glob); 224 globs->push_back(glob);
215 } 225 }
216 } 226 }
217 227
228 void UserScript::UnpickleConsumerID(const ::Pickle& pickle,
229 PickleIterator* iter,
230 ConsumerID* consumer_id) {
231 int host_type;
232 int instance_type;
233 CHECK(iter->ReadInt(&host_type));
234 consumer_id->host_type = static_cast<HostType>(host_type);
235 CHECK(iter->ReadString(&consumer_id->host_id));
236 CHECK(iter->ReadInt(&instance_type));
237 consumer_id->instance_type = static_cast<InstanceType>(instance_type);
238 CHECK(iter->ReadInt(&consumer_id->instance_id));
239 }
240
218 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle, 241 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle,
219 PickleIterator* iter, 242 PickleIterator* iter,
220 URLPatternSet* pattern_list) { 243 URLPatternSet* pattern_list) {
221 size_t num_patterns = 0; 244 size_t num_patterns = 0;
222 CHECK(iter->ReadSizeT(&num_patterns)); 245 CHECK(iter->ReadSizeT(&num_patterns));
223 246
224 pattern_list->ClearPatterns(); 247 pattern_list->ClearPatterns();
225 for (size_t i = 0; i < num_patterns; ++i) { 248 for (size_t i = 0; i < num_patterns; ++i) {
226 int valid_schemes; 249 int valid_schemes;
227 CHECK(iter->ReadInt(&valid_schemes)); 250 CHECK(iter->ReadInt(&valid_schemes));
(...skipping 24 matching lines...) Expand all
252 } 275 }
253 276
254 bool operator<(const UserScript& script1, const UserScript& script2) { 277 bool operator<(const UserScript& script1, const UserScript& script2) {
255 // The only kind of script that should be compared is the kind that has its 278 // The only kind of script that should be compared is the kind that has its
256 // IDs initialized to a meaningful value. 279 // IDs initialized to a meaningful value.
257 DCHECK(script1.id() != -1 && script2.id() != -1); 280 DCHECK(script1.id() != -1 && script2.id() != -1);
258 return script1.id() < script2.id(); 281 return script1.id() < script2.id();
259 } 282 }
260 283
261 } // namespace extensions 284 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698