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

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

Issue 906493004: Refactoring: de-couple Extensions from "script injection System" [render side]:2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@decouple_brower_isolated_world_1
Patch Set: Rebase. Created 5 years, 10 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->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 PickleConsumerInstanceInfo(pickle, consumer_instance_info_);
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::PickleConsumerInstanceInfo(
173 ::Pickle* pickle,
174 const ConsumerInstanceInfo& instance_info) const {
175 pickle->WriteInt(instance_info.type());
176 pickle->WriteInt(instance_info.id());
177 }
178
179 void UserScript::PickleRoutingInfo(::Pickle* pickle,
180 const RoutingInfo& routing_info) const {
181 pickle->WriteInt(routing_info.render_process_id);
182 pickle->WriteInt(routing_info.render_view_id);
183 }
184
170 void UserScript::PickleURLPatternSet(::Pickle* pickle, 185 void UserScript::PickleURLPatternSet(::Pickle* pickle,
171 const URLPatternSet& pattern_list) const { 186 const URLPatternSet& pattern_list) const {
172 pickle->WriteSizeT(pattern_list.patterns().size()); 187 pickle->WriteSizeT(pattern_list.patterns().size());
173 for (URLPatternSet::const_iterator pattern = pattern_list.begin(); 188 for (URLPatternSet::const_iterator pattern = pattern_list.begin();
174 pattern != pattern_list.end(); ++pattern) { 189 pattern != pattern_list.end(); ++pattern) {
175 pickle->WriteInt(pattern->valid_schemes()); 190 pickle->WriteInt(pattern->valid_schemes());
176 pickle->WriteString(pattern->GetAsString()); 191 pickle->WriteString(pattern->GetAsString());
177 } 192 }
178 } 193 }
179 194
(...skipping 13 matching lines...) Expand all
193 CHECK(run_location >= 0 && run_location < RUN_LOCATION_LAST); 208 CHECK(run_location >= 0 && run_location < RUN_LOCATION_LAST);
194 run_location_ = static_cast<RunLocation>(run_location); 209 run_location_ = static_cast<RunLocation>(run_location);
195 210
196 CHECK(iter->ReadInt(&user_script_id_)); 211 CHECK(iter->ReadInt(&user_script_id_));
197 CHECK(iter->ReadBool(&emulate_greasemonkey_)); 212 CHECK(iter->ReadBool(&emulate_greasemonkey_));
198 CHECK(iter->ReadBool(&match_all_frames_)); 213 CHECK(iter->ReadBool(&match_all_frames_));
199 CHECK(iter->ReadBool(&match_about_blank_)); 214 CHECK(iter->ReadBool(&match_about_blank_));
200 CHECK(iter->ReadBool(&incognito_enabled_)); 215 CHECK(iter->ReadBool(&incognito_enabled_));
201 216
202 UnpickleHostID(pickle, iter, &host_id_); 217 UnpickleHostID(pickle, iter, &host_id_);
218 UnpickleConsumerInstanceInfo(pickle, iter, &consumer_instance_info_);
219 UnpickleRoutingInfo(pickle, iter, &routing_info_);
203 UnpickleGlobs(pickle, iter, &globs_); 220 UnpickleGlobs(pickle, iter, &globs_);
204 UnpickleGlobs(pickle, iter, &exclude_globs_); 221 UnpickleGlobs(pickle, iter, &exclude_globs_);
205 UnpickleURLPatternSet(pickle, iter, &url_set_); 222 UnpickleURLPatternSet(pickle, iter, &url_set_);
206 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_); 223 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_);
207 UnpickleScripts(pickle, iter, &js_scripts_); 224 UnpickleScripts(pickle, iter, &js_scripts_);
208 UnpickleScripts(pickle, iter, &css_scripts_); 225 UnpickleScripts(pickle, iter, &css_scripts_);
209 } 226 }
210 227
211 void UserScript::UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, 228 void UserScript::UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter,
212 std::vector<std::string>* globs) { 229 std::vector<std::string>* globs) {
(...skipping 10 matching lines...) Expand all
223 void UserScript::UnpickleHostID(const ::Pickle& pickle, 240 void UserScript::UnpickleHostID(const ::Pickle& pickle,
224 PickleIterator* iter, 241 PickleIterator* iter,
225 HostID* host_id) { 242 HostID* host_id) {
226 int type = 0; 243 int type = 0;
227 std::string id; 244 std::string id;
228 CHECK(iter->ReadInt(&type)); 245 CHECK(iter->ReadInt(&type));
229 CHECK(iter->ReadString(&id)); 246 CHECK(iter->ReadString(&id));
230 *host_id = HostID(static_cast<HostID::HostType>(type), id); 247 *host_id = HostID(static_cast<HostID::HostType>(type), id);
231 } 248 }
232 249
250 void UserScript::UnpickleConsumerInstanceInfo(
251 const ::Pickle& pickle,
252 PickleIterator* iter,
253 ConsumerInstanceInfo* consumer_instance_info) {
254 int type = 0;
255 int id = 0;
256 CHECK(iter->ReadInt(&type));
257 CHECK(iter->ReadInt(&id));
258 *consumer_instance_info = ConsumerInstanceInfo(
259 static_cast<ConsumerInstanceInfo::InstanceType>(type), id);
260 }
261
262 void UserScript::UnpickleRoutingInfo(const ::Pickle& pickle,
263 PickleIterator* iter,
264 RoutingInfo* routing_info) {
265 CHECK(iter->ReadInt(&routing_info->render_process_id));
266 CHECK(iter->ReadInt(&routing_info->render_view_id));
267 }
268
233 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle, 269 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle,
234 PickleIterator* iter, 270 PickleIterator* iter,
235 URLPatternSet* pattern_list) { 271 URLPatternSet* pattern_list) {
236 size_t num_patterns = 0; 272 size_t num_patterns = 0;
237 CHECK(iter->ReadSizeT(&num_patterns)); 273 CHECK(iter->ReadSizeT(&num_patterns));
238 274
239 pattern_list->ClearPatterns(); 275 pattern_list->ClearPatterns();
240 for (size_t i = 0; i < num_patterns; ++i) { 276 for (size_t i = 0; i < num_patterns; ++i) {
241 int valid_schemes; 277 int valid_schemes;
242 CHECK(iter->ReadInt(&valid_schemes)); 278 CHECK(iter->ReadInt(&valid_schemes));
(...skipping 24 matching lines...) Expand all
267 } 303 }
268 304
269 bool operator<(const UserScript& script1, const UserScript& script2) { 305 bool operator<(const UserScript& script1, const UserScript& script2) {
270 // The only kind of script that should be compared is the kind that has its 306 // The only kind of script that should be compared is the kind that has its
271 // IDs initialized to a meaningful value. 307 // IDs initialized to a meaningful value.
272 DCHECK(script1.id() != -1 && script2.id() != -1); 308 DCHECK(script1.id() != -1 && script2.id() != -1);
273 return script1.id() < script2.id(); 309 return script1.id() < script2.id();
274 } 310 }
275 311
276 } // namespace extensions 312 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698