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

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

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: format Created 5 years, 11 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 #ifndef EXTENSIONS_COMMON_USER_SCRIPT_H_ 5 #ifndef EXTENSIONS_COMMON_USER_SCRIPT_H_
6 #define EXTENSIONS_COMMON_USER_SCRIPT_H_ 6 #define EXTENSIONS_COMMON_USER_SCRIPT_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/memory/linked_ptr.h"
13 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
15 #include "extensions/common/consumer.h"
14 #include "extensions/common/url_pattern.h" 16 #include "extensions/common/url_pattern.h"
15 #include "extensions/common/url_pattern_set.h" 17 #include "extensions/common/url_pattern_set.h"
16 #include "url/gurl.h" 18 #include "url/gurl.h"
17 19
18 class Pickle; 20 class Pickle;
19 class PickleIterator; 21 class PickleIterator;
20 22
21 namespace extensions { 23 namespace extensions {
22 24
23 // Represents a user script, either a standalone one, or one that is part of an 25 // Represents a user script, either a standalone one, or one that is part of an
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 void add_exclude_url_pattern(const URLPattern& pattern); 189 void add_exclude_url_pattern(const URLPattern& pattern);
188 190
189 // List of js scripts for this user script 191 // List of js scripts for this user script
190 FileList& js_scripts() { return js_scripts_; } 192 FileList& js_scripts() { return js_scripts_; }
191 const FileList& js_scripts() const { return js_scripts_; } 193 const FileList& js_scripts() const { return js_scripts_; }
192 194
193 // List of css scripts for this user script 195 // List of css scripts for this user script
194 FileList& css_scripts() { return css_scripts_; } 196 FileList& css_scripts() { return css_scripts_; }
195 const FileList& css_scripts() const { return css_scripts_; } 197 const FileList& css_scripts() const { return css_scripts_; }
196 198
197 const std::string& extension_id() const { return extension_id_; } 199 const std::string& extension_id() const;
Fady Samuel 2015/01/07 19:19:40 This is no longer a trivial accessor and so it mus
Xi Han 2015/01/07 20:28:42 Renamed.
198 void set_extension_id(const std::string& id) { extension_id_ = id; } 200
201 ConsumerID* consumer_id() const { return consumer_id_.get(); }
202 void set_consumer_id(const ConsumerID& consumer_id) {
203 consumer_id_.reset(new ConsumerID(consumer_id));
204 }
199 205
200 int id() const { return user_script_id_; } 206 int id() const { return user_script_id_; }
201 void set_id(int id) { user_script_id_ = id; } 207 void set_id(int id) { user_script_id_ = id; }
202 208
203 bool is_incognito_enabled() const { return incognito_enabled_; } 209 bool is_incognito_enabled() const { return incognito_enabled_; }
204 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } 210 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; }
205 211
206 bool is_standalone() const { return extension_id_.empty(); } 212 bool is_standalone() const { return extension_id().empty(); }
207 213
208 // Returns true if the script should be applied to the specified URL, false 214 // Returns true if the script should be applied to the specified URL, false
209 // otherwise. 215 // otherwise.
210 bool MatchesURL(const GURL& url) const; 216 bool MatchesURL(const GURL& url) const;
211 217
212 // Serialize the UserScript into a pickle. The content of the scripts and 218 // Serialize the UserScript into a pickle. The content of the scripts and
213 // paths to UserScript::Files will not be serialized! 219 // paths to UserScript::Files will not be serialized!
214 void Pickle(::Pickle* pickle) const; 220 void Pickle(::Pickle* pickle) const;
215 221
216 // Deserialize the script from a pickle. Note that this always succeeds 222 // Deserialize the script from a pickle. Note that this always succeeds
217 // because presumably we were the one that pickled it, and we did it 223 // because presumably we were the one that pickled it, and we did it
218 // correctly. 224 // correctly.
219 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); 225 void Unpickle(const ::Pickle& pickle, PickleIterator* iter);
220 226
221 private: 227 private:
222 // Pickle helper functions used to pickle the individual types of components. 228 // Pickle helper functions used to pickle the individual types of components.
223 void PickleGlobs(::Pickle* pickle, 229 void PickleGlobs(::Pickle* pickle,
224 const std::vector<std::string>& globs) const; 230 const std::vector<std::string>& globs) const;
231 void PickleConsumerID(::Pickle* pickle,
232 linked_ptr<ConsumerID> consumer_id) const;
225 void PickleURLPatternSet(::Pickle* pickle, 233 void PickleURLPatternSet(::Pickle* pickle,
226 const URLPatternSet& pattern_list) const; 234 const URLPatternSet& pattern_list) const;
227 void PickleScripts(::Pickle* pickle, const FileList& scripts) const; 235 void PickleScripts(::Pickle* pickle, const FileList& scripts) const;
228 236
229 // Unpickle helper functions used to unpickle individual types of components. 237 // Unpickle helper functions used to unpickle individual types of components.
230 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, 238 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter,
231 std::vector<std::string>* globs); 239 std::vector<std::string>* globs);
240 ConsumerID* UnpickleConsumerID(const ::Pickle& pickle, PickleIterator* iter);
232 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, 241 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter,
233 URLPatternSet* pattern_list); 242 URLPatternSet* pattern_list);
234 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, 243 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter,
235 FileList* scripts); 244 FileList* scripts);
236 245
237 // The location to run the script inside the document. 246 // The location to run the script inside the document.
238 RunLocation run_location_; 247 RunLocation run_location_;
239 248
240 // The namespace of the script. This is used by Greasemonkey in the same way 249 // The namespace of the script. This is used by Greasemonkey in the same way
241 // as XML namespaces. Only used when parsing Greasemonkey-style scripts. 250 // as XML namespaces. Only used when parsing Greasemonkey-style scripts.
(...skipping 18 matching lines...) Expand all
260 // only used with scripts that are part of extensions. 269 // only used with scripts that are part of extensions.
261 URLPatternSet url_set_; 270 URLPatternSet url_set_;
262 URLPatternSet exclude_url_set_; 271 URLPatternSet exclude_url_set_;
263 272
264 // List of js scripts defined in content_scripts 273 // List of js scripts defined in content_scripts
265 FileList js_scripts_; 274 FileList js_scripts_;
266 275
267 // List of css scripts defined in content_scripts 276 // List of css scripts defined in content_scripts
268 FileList css_scripts_; 277 FileList css_scripts_;
269 278
270 // The ID of the extension this script is a part of, if any. Can be empty if 279 // The ID of the consumer this script is a part of. The host_id of the
271 // the script is a "standlone" user script. 280 // consumer_id can be empty if the script is a "standlone" user script.
272 std::string extension_id_; 281 linked_ptr<ConsumerID> consumer_id_;
Fady Samuel 2015/01/07 19:19:40 Why is this a linked_ptr? Can it be a scoped_ptr?
Xi Han 2015/01/07 20:28:42 No, it can't be a scoped_ptr, since scoped_ptr is
273 282
274 // The globally-unique id associated with this user script. Defaults to 283 // The globally-unique id associated with this user script. Defaults to
275 // -1 for invalid. 284 // -1 for invalid.
276 int user_script_id_; 285 int user_script_id_;
277 286
278 // Whether we should try to emulate Greasemonkey's APIs when running this 287 // Whether we should try to emulate Greasemonkey's APIs when running this
279 // script. 288 // script.
280 bool emulate_greasemonkey_; 289 bool emulate_greasemonkey_;
281 290
282 // Whether the user script should run in all frames, or only just the top one. 291 // Whether the user script should run in all frames, or only just the top one.
283 // Defaults to false. 292 // Defaults to false.
284 bool match_all_frames_; 293 bool match_all_frames_;
285 294
286 // Whether the user script should run in about:blank and about:srcdoc as well. 295 // Whether the user script should run in about:blank and about:srcdoc as well.
287 // Defaults to false. 296 // Defaults to false.
288 bool match_about_blank_; 297 bool match_about_blank_;
289 298
290 // True if the script should be injected into an incognito tab. 299 // True if the script should be injected into an incognito tab.
291 bool incognito_enabled_; 300 bool incognito_enabled_;
292 }; 301 };
293 302
294 // For storing UserScripts with unique IDs in sets. 303 // For storing UserScripts with unique IDs in sets.
295 bool operator<(const UserScript& script1, const UserScript& script2); 304 bool operator<(const UserScript& script1, const UserScript& script2);
296 305
297 typedef std::vector<UserScript> UserScriptList; 306 typedef std::vector<UserScript> UserScriptList;
298 307
299 } // namespace extensions 308 } // namespace extensions
300 309
301 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ 310 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698