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

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

Issue 959413003: Implement <webview>.addContentScript/removeContentScript API [1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // Write the simple types to the pickle. 140 // Write the simple types to the pickle.
141 pickle->WriteInt(run_location()); 141 pickle->WriteInt(run_location());
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 PickleHostID(pickle, host_id_); 148 PickleHostID(pickle, host_id_);
149 pickle->WriteInt(consumer_instance_type()); 149 pickle->WriteInt(consumer_instance_type());
150 PickleRoutingInfo(pickle, routing_info_);
151 PickleGlobs(pickle, globs_); 150 PickleGlobs(pickle, globs_);
152 PickleGlobs(pickle, exclude_globs_); 151 PickleGlobs(pickle, exclude_globs_);
153 PickleURLPatternSet(pickle, url_set_); 152 PickleURLPatternSet(pickle, url_set_);
154 PickleURLPatternSet(pickle, exclude_url_set_); 153 PickleURLPatternSet(pickle, exclude_url_set_);
155 PickleScripts(pickle, js_scripts_); 154 PickleScripts(pickle, js_scripts_);
156 PickleScripts(pickle, css_scripts_); 155 PickleScripts(pickle, css_scripts_);
157 } 156 }
158 157
159 void UserScript::PickleGlobs(::Pickle* pickle, 158 void UserScript::PickleGlobs(::Pickle* pickle,
160 const std::vector<std::string>& globs) const { 159 const std::vector<std::string>& globs) const {
161 pickle->WriteSizeT(globs.size()); 160 pickle->WriteSizeT(globs.size());
162 for (std::vector<std::string>::const_iterator glob = globs.begin(); 161 for (std::vector<std::string>::const_iterator glob = globs.begin();
163 glob != globs.end(); ++glob) { 162 glob != globs.end(); ++glob) {
164 pickle->WriteString(*glob); 163 pickle->WriteString(*glob);
165 } 164 }
166 } 165 }
167 166
168 void UserScript::PickleHostID(::Pickle* pickle, const HostID& host_id) const { 167 void UserScript::PickleHostID(::Pickle* pickle, const HostID& host_id) const {
169 pickle->WriteInt(host_id.type()); 168 pickle->WriteInt(host_id.type());
170 pickle->WriteString(host_id.id()); 169 pickle->WriteString(host_id.id());
171 } 170 }
172 171
173 void UserScript::PickleRoutingInfo(::Pickle* pickle,
174 const RoutingInfo& routing_info) const {
175 pickle->WriteInt(routing_info.render_process_id);
176 pickle->WriteInt(routing_info.render_view_id);
177 }
178
179 void UserScript::PickleURLPatternSet(::Pickle* pickle, 172 void UserScript::PickleURLPatternSet(::Pickle* pickle,
180 const URLPatternSet& pattern_list) const { 173 const URLPatternSet& pattern_list) const {
181 pickle->WriteSizeT(pattern_list.patterns().size()); 174 pickle->WriteSizeT(pattern_list.patterns().size());
182 for (URLPatternSet::const_iterator pattern = pattern_list.begin(); 175 for (URLPatternSet::const_iterator pattern = pattern_list.begin();
183 pattern != pattern_list.end(); ++pattern) { 176 pattern != pattern_list.end(); ++pattern) {
184 pickle->WriteInt(pattern->valid_schemes()); 177 pickle->WriteInt(pattern->valid_schemes());
185 pickle->WriteString(pattern->GetAsString()); 178 pickle->WriteString(pattern->GetAsString());
186 } 179 }
187 } 180 }
188 181
(...skipping 19 matching lines...) Expand all
208 CHECK(iter->ReadBool(&match_about_blank_)); 201 CHECK(iter->ReadBool(&match_about_blank_));
209 CHECK(iter->ReadBool(&incognito_enabled_)); 202 CHECK(iter->ReadBool(&incognito_enabled_));
210 203
211 UnpickleHostID(pickle, iter, &host_id_); 204 UnpickleHostID(pickle, iter, &host_id_);
212 205
213 int consumer_instance_type = 0; 206 int consumer_instance_type = 0;
214 CHECK(iter->ReadInt(&consumer_instance_type)); 207 CHECK(iter->ReadInt(&consumer_instance_type));
215 consumer_instance_type_ = 208 consumer_instance_type_ =
216 static_cast<ConsumerInstanceType>(consumer_instance_type); 209 static_cast<ConsumerInstanceType>(consumer_instance_type);
217 210
218 UnpickleRoutingInfo(pickle, iter, &routing_info_);
219 UnpickleGlobs(pickle, iter, &globs_); 211 UnpickleGlobs(pickle, iter, &globs_);
220 UnpickleGlobs(pickle, iter, &exclude_globs_); 212 UnpickleGlobs(pickle, iter, &exclude_globs_);
221 UnpickleURLPatternSet(pickle, iter, &url_set_); 213 UnpickleURLPatternSet(pickle, iter, &url_set_);
222 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_); 214 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_);
223 UnpickleScripts(pickle, iter, &js_scripts_); 215 UnpickleScripts(pickle, iter, &js_scripts_);
224 UnpickleScripts(pickle, iter, &css_scripts_); 216 UnpickleScripts(pickle, iter, &css_scripts_);
225 } 217 }
226 218
227 void UserScript::UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, 219 void UserScript::UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter,
228 std::vector<std::string>* globs) { 220 std::vector<std::string>* globs) {
(...skipping 10 matching lines...) Expand all
239 void UserScript::UnpickleHostID(const ::Pickle& pickle, 231 void UserScript::UnpickleHostID(const ::Pickle& pickle,
240 PickleIterator* iter, 232 PickleIterator* iter,
241 HostID* host_id) { 233 HostID* host_id) {
242 int type = 0; 234 int type = 0;
243 std::string id; 235 std::string id;
244 CHECK(iter->ReadInt(&type)); 236 CHECK(iter->ReadInt(&type));
245 CHECK(iter->ReadString(&id)); 237 CHECK(iter->ReadString(&id));
246 *host_id = HostID(static_cast<HostID::HostType>(type), id); 238 *host_id = HostID(static_cast<HostID::HostType>(type), id);
247 } 239 }
248 240
249 void UserScript::UnpickleRoutingInfo(const ::Pickle& pickle,
250 PickleIterator* iter,
251 RoutingInfo* routing_info) {
252 CHECK(iter->ReadInt(&routing_info->render_process_id));
253 CHECK(iter->ReadInt(&routing_info->render_view_id));
254 }
255
256 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle, 241 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle,
257 PickleIterator* iter, 242 PickleIterator* iter,
258 URLPatternSet* pattern_list) { 243 URLPatternSet* pattern_list) {
259 size_t num_patterns = 0; 244 size_t num_patterns = 0;
260 CHECK(iter->ReadSizeT(&num_patterns)); 245 CHECK(iter->ReadSizeT(&num_patterns));
261 246
262 pattern_list->ClearPatterns(); 247 pattern_list->ClearPatterns();
263 for (size_t i = 0; i < num_patterns; ++i) { 248 for (size_t i = 0; i < num_patterns; ++i) {
264 int valid_schemes; 249 int valid_schemes;
265 CHECK(iter->ReadInt(&valid_schemes)); 250 CHECK(iter->ReadInt(&valid_schemes));
(...skipping 24 matching lines...) Expand all
290 } 275 }
291 276
292 bool operator<(const UserScript& script1, const UserScript& script2) { 277 bool operator<(const UserScript& script1, const UserScript& script2) {
293 // 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
294 // IDs initialized to a meaningful value. 279 // IDs initialized to a meaningful value.
295 DCHECK(script1.id() != -1 && script2.id() != -1); 280 DCHECK(script1.id() != -1 && script2.id() != -1);
296 return script1.id() < script2.id(); 281 return script1.id() < script2.id();
297 } 282 }
298 283
299 } // namespace extensions 284 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698