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

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: nits 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
« no previous file with comments | « extensions/common/host_id.h ('k') | extensions/common/user_script.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "extensions/common/host_id.h"
14 #include "extensions/common/url_pattern.h" 15 #include "extensions/common/url_pattern.h"
15 #include "extensions/common/url_pattern_set.h" 16 #include "extensions/common/url_pattern_set.h"
16 #include "url/gurl.h" 17 #include "url/gurl.h"
17 18
18 class Pickle; 19 class Pickle;
19 class PickleIterator; 20 class PickleIterator;
20 21
21 namespace extensions { 22 namespace extensions {
22 23
23 // Represents a user script, either a standalone one, or one that is part of an 24 // 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); 188 void add_exclude_url_pattern(const URLPattern& pattern);
188 189
189 // List of js scripts for this user script 190 // List of js scripts for this user script
190 FileList& js_scripts() { return js_scripts_; } 191 FileList& js_scripts() { return js_scripts_; }
191 const FileList& js_scripts() const { return js_scripts_; } 192 const FileList& js_scripts() const { return js_scripts_; }
192 193
193 // List of css scripts for this user script 194 // List of css scripts for this user script
194 FileList& css_scripts() { return css_scripts_; } 195 FileList& css_scripts() { return css_scripts_; }
195 const FileList& css_scripts() const { return css_scripts_; } 196 const FileList& css_scripts() const { return css_scripts_; }
196 197
197 const std::string& extension_id() const { return extension_id_; } 198 const std::string& extension_id() const { return host_id_.id(); }
198 void set_extension_id(const std::string& id) { extension_id_ = id; } 199
200 const HostID& host_id() const { return host_id_; }
201 void set_host_id(const HostID& host_id) { host_id_ = host_id; }
199 202
200 int id() const { return user_script_id_; } 203 int id() const { return user_script_id_; }
201 void set_id(int id) { user_script_id_ = id; } 204 void set_id(int id) { user_script_id_ = id; }
202 205
203 bool is_incognito_enabled() const { return incognito_enabled_; } 206 bool is_incognito_enabled() const { return incognito_enabled_; }
204 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } 207 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; }
205 208
206 bool is_standalone() const { return extension_id_.empty(); } 209 bool is_standalone() const { return extension_id().empty(); }
207 210
208 // Returns true if the script should be applied to the specified URL, false 211 // Returns true if the script should be applied to the specified URL, false
209 // otherwise. 212 // otherwise.
210 bool MatchesURL(const GURL& url) const; 213 bool MatchesURL(const GURL& url) const;
211 214
212 // Serialize the UserScript into a pickle. The content of the scripts and 215 // Serialize the UserScript into a pickle. The content of the scripts and
213 // paths to UserScript::Files will not be serialized! 216 // paths to UserScript::Files will not be serialized!
214 void Pickle(::Pickle* pickle) const; 217 void Pickle(::Pickle* pickle) const;
215 218
216 // Deserialize the script from a pickle. Note that this always succeeds 219 // 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 220 // because presumably we were the one that pickled it, and we did it
218 // correctly. 221 // correctly.
219 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); 222 void Unpickle(const ::Pickle& pickle, PickleIterator* iter);
220 223
221 private: 224 private:
222 // Pickle helper functions used to pickle the individual types of components. 225 // Pickle helper functions used to pickle the individual types of components.
223 void PickleGlobs(::Pickle* pickle, 226 void PickleGlobs(::Pickle* pickle,
224 const std::vector<std::string>& globs) const; 227 const std::vector<std::string>& globs) const;
228 void PickleHostID(::Pickle* pickle, const HostID& host_id) const;
225 void PickleURLPatternSet(::Pickle* pickle, 229 void PickleURLPatternSet(::Pickle* pickle,
226 const URLPatternSet& pattern_list) const; 230 const URLPatternSet& pattern_list) const;
227 void PickleScripts(::Pickle* pickle, const FileList& scripts) const; 231 void PickleScripts(::Pickle* pickle, const FileList& scripts) const;
228 232
229 // Unpickle helper functions used to unpickle individual types of components. 233 // Unpickle helper functions used to unpickle individual types of components.
230 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, 234 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter,
231 std::vector<std::string>* globs); 235 std::vector<std::string>* globs);
236 void UnpickleHostID(const ::Pickle& pickle,
237 PickleIterator* iter,
238 HostID* host_id);
232 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, 239 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter,
233 URLPatternSet* pattern_list); 240 URLPatternSet* pattern_list);
234 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, 241 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter,
235 FileList* scripts); 242 FileList* scripts);
236 243
237 // The location to run the script inside the document. 244 // The location to run the script inside the document.
238 RunLocation run_location_; 245 RunLocation run_location_;
239 246
240 // The namespace of the script. This is used by Greasemonkey in the same way 247 // 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. 248 // 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. 267 // only used with scripts that are part of extensions.
261 URLPatternSet url_set_; 268 URLPatternSet url_set_;
262 URLPatternSet exclude_url_set_; 269 URLPatternSet exclude_url_set_;
263 270
264 // List of js scripts defined in content_scripts 271 // List of js scripts defined in content_scripts
265 FileList js_scripts_; 272 FileList js_scripts_;
266 273
267 // List of css scripts defined in content_scripts 274 // List of css scripts defined in content_scripts
268 FileList css_scripts_; 275 FileList css_scripts_;
269 276
270 // The ID of the extension this script is a part of, if any. Can be empty if 277 // The ID of the host this script is a part of. The |ID| of the
271 // the script is a "standlone" user script. 278 // |host_id| can be empty if the script is a "standlone" user script.
272 std::string extension_id_; 279 HostID host_id_;
273 280
274 // The globally-unique id associated with this user script. Defaults to 281 // The globally-unique id associated with this user script. Defaults to
275 // -1 for invalid. 282 // -1 for invalid.
276 int user_script_id_; 283 int user_script_id_;
277 284
278 // Whether we should try to emulate Greasemonkey's APIs when running this 285 // Whether we should try to emulate Greasemonkey's APIs when running this
279 // script. 286 // script.
280 bool emulate_greasemonkey_; 287 bool emulate_greasemonkey_;
281 288
282 // Whether the user script should run in all frames, or only just the top one. 289 // Whether the user script should run in all frames, or only just the top one.
283 // Defaults to false. 290 // Defaults to false.
284 bool match_all_frames_; 291 bool match_all_frames_;
285 292
286 // Whether the user script should run in about:blank and about:srcdoc as well. 293 // Whether the user script should run in about:blank and about:srcdoc as well.
287 // Defaults to false. 294 // Defaults to false.
288 bool match_about_blank_; 295 bool match_about_blank_;
289 296
290 // True if the script should be injected into an incognito tab. 297 // True if the script should be injected into an incognito tab.
291 bool incognito_enabled_; 298 bool incognito_enabled_;
292 }; 299 };
293 300
294 // For storing UserScripts with unique IDs in sets. 301 // For storing UserScripts with unique IDs in sets.
295 bool operator<(const UserScript& script1, const UserScript& script2); 302 bool operator<(const UserScript& script1, const UserScript& script2);
296 303
297 typedef std::vector<UserScript> UserScriptList; 304 typedef std::vector<UserScript> UserScriptList;
298 305
299 } // namespace extensions 306 } // namespace extensions
300 307
301 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ 308 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_
OLDNEW
« no previous file with comments | « extensions/common/host_id.h ('k') | extensions/common/user_script.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698