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

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

Issue 2227193002: Make UserScript non-copyable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync @tott Created 4 years, 4 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/browser/web_ui_user_script_loader.cc ('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
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // is "idle". Currently this uses the simple heuristic of: 66 // is "idle". Currently this uses the simple heuristic of:
67 // min(DOM_CONTENT_LOADED + TIMEOUT, ONLOAD), but no 67 // min(DOM_CONTENT_LOADED + TIMEOUT, ONLOAD), but no
68 // particular injection point is guaranteed. 68 // particular injection point is guaranteed.
69 RUN_DEFERRED, // The user script's injection was deferred for permissions 69 RUN_DEFERRED, // The user script's injection was deferred for permissions
70 // reasons, and was executed at a later time. 70 // reasons, and was executed at a later time.
71 BROWSER_DRIVEN, // The user script will be injected when triggered by an 71 BROWSER_DRIVEN, // The user script will be injected when triggered by an
72 // IPC in the browser process. 72 // IPC in the browser process.
73 RUN_LOCATION_LAST // Leave this as the last item. 73 RUN_LOCATION_LAST // Leave this as the last item.
74 }; 74 };
75 75
76 // Holds actual script file info. 76 // Holds script file info.
77 class File { 77 class File {
78 public: 78 public:
79 File(const base::FilePath& extension_root, 79 File(const base::FilePath& extension_root,
80 const base::FilePath& relative_path, 80 const base::FilePath& relative_path,
81 const GURL& url); 81 const GURL& url);
82 File(); 82 File();
83 File(const File& other); 83 File(const File& other);
84 ~File(); 84 ~File();
85 85
86 const base::FilePath& extension_root() const { return extension_root_; } 86 const base::FilePath& extension_root() const { return extension_root_; }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 GURL url_; 119 GURL url_;
120 120
121 // The script content. It can be set to either loaded_content_ or 121 // The script content. It can be set to either loaded_content_ or
122 // externally allocated string. 122 // externally allocated string.
123 base::StringPiece external_content_; 123 base::StringPiece external_content_;
124 124
125 // Set when the content is loaded by LoadContent 125 // Set when the content is loaded by LoadContent
126 std::string content_; 126 std::string content_;
127 }; 127 };
128 128
129 typedef std::vector<File> FileList; 129 using FileList = std::vector<std::unique_ptr<File>>;
130 130
131 // Type of a API consumer instance that user scripts will be injected on. 131 // Type of a API consumer instance that user scripts will be injected on.
132 enum ConsumerInstanceType { TAB, WEBVIEW }; 132 enum ConsumerInstanceType { TAB, WEBVIEW };
133 133
134 // Constructor. Default the run location to document end, which is like 134 // Constructor. Default the run location to document end, which is like
135 // Greasemonkey and probably more useful for typical scripts. 135 // Greasemonkey and probably more useful for typical scripts.
136 UserScript(); 136 UserScript();
137 UserScript(const UserScript& other);
138 ~UserScript(); 137 ~UserScript();
139 138
139 // Peforms a copy of all fields except file contents.
140 static std::unique_ptr<UserScript> CopyMetadataFrom(const UserScript& other);
141
140 const std::string& name_space() const { return name_space_; } 142 const std::string& name_space() const { return name_space_; }
141 void set_name_space(const std::string& name_space) { 143 void set_name_space(const std::string& name_space) {
142 name_space_ = name_space; 144 name_space_ = name_space;
143 } 145 }
144 146
145 const std::string& name() const { return name_; } 147 const std::string& name() const { return name_; }
146 void set_name(const std::string& name) { name_ = name; } 148 void set_name(const std::string& name) { name_ = name; }
147 149
148 const std::string& version() const { return version_; } 150 const std::string& version() const { return version_; }
149 void set_version(const std::string& version) { 151 void set_version(const std::string& version) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 return consumer_instance_type_; 212 return consumer_instance_type_;
211 } 213 }
212 void set_consumer_instance_type( 214 void set_consumer_instance_type(
213 const ConsumerInstanceType& consumer_instance_type) { 215 const ConsumerInstanceType& consumer_instance_type) {
214 consumer_instance_type_ = consumer_instance_type; 216 consumer_instance_type_ = consumer_instance_type;
215 } 217 }
216 218
217 int id() const { return user_script_id_; } 219 int id() const { return user_script_id_; }
218 void set_id(int id) { user_script_id_ = id; } 220 void set_id(int id) { user_script_id_ = id; }
219 221
222 // TODO(lazyboy): Incognito information is extension specific, it doesn't
223 // belong here. We should be able to determine this in the renderer/ where it
224 // is used.
220 bool is_incognito_enabled() const { return incognito_enabled_; } 225 bool is_incognito_enabled() const { return incognito_enabled_; }
221 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } 226 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; }
222 227
223 // Returns true if the script should be applied to the specified URL, false 228 // Returns true if the script should be applied to the specified URL, false
224 // otherwise. 229 // otherwise.
225 bool MatchesURL(const GURL& url) const; 230 bool MatchesURL(const GURL& url) const;
226 231
227 // Serialize the UserScript into a pickle. The content of the scripts and 232 // Serializes the UserScript into a pickle. The content of the scripts and
228 // paths to UserScript::Files will not be serialized! 233 // paths to UserScript::Files will not be serialized!
229 void Pickle(base::Pickle* pickle) const; 234 void Pickle(base::Pickle* pickle) const;
230 235
231 // Deserialize the script from a pickle. Note that this always succeeds 236 // Deserializes the script from a pickle. Note that this always succeeds
232 // because presumably we were the one that pickled it, and we did it 237 // because presumably we were the one that pickled it, and we did it
233 // correctly. 238 // correctly.
234 void Unpickle(const base::Pickle& pickle, base::PickleIterator* iter); 239 void Unpickle(const base::Pickle& pickle, base::PickleIterator* iter);
235 240
236 private: 241 private:
237 // base::Pickle helper functions used to pickle the individual types of 242 // base::Pickle helper functions used to pickle the individual types of
238 // components. 243 // components.
239 void PickleGlobs(base::Pickle* pickle, 244 void PickleGlobs(base::Pickle* pickle,
240 const std::vector<std::string>& globs) const; 245 const std::vector<std::string>& globs) const;
241 void PickleHostID(base::Pickle* pickle, const HostID& host_id) const; 246 void PickleHostID(base::Pickle* pickle, const HostID& host_id) const;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // Whether the user script should run in all frames, or only just the top one. 313 // Whether the user script should run in all frames, or only just the top one.
309 // Defaults to false. 314 // Defaults to false.
310 bool match_all_frames_; 315 bool match_all_frames_;
311 316
312 // Whether the user script should run in about:blank and about:srcdoc as well. 317 // Whether the user script should run in about:blank and about:srcdoc as well.
313 // Defaults to false. 318 // Defaults to false.
314 bool match_about_blank_; 319 bool match_about_blank_;
315 320
316 // True if the script should be injected into an incognito tab. 321 // True if the script should be injected into an incognito tab.
317 bool incognito_enabled_; 322 bool incognito_enabled_;
323
324 DISALLOW_COPY_AND_ASSIGN(UserScript);
318 }; 325 };
319 326
320 // Information we need while removing scripts from a UserScriptLoader. 327 // Information we need while removing scripts from a UserScriptLoader.
321 struct UserScriptIDPair { 328 struct UserScriptIDPair {
322 UserScriptIDPair(int id, const HostID& host_id); 329 UserScriptIDPair(int id, const HostID& host_id);
323 UserScriptIDPair(int id); 330 UserScriptIDPair(int id);
324 331
325 int id; 332 int id;
326 HostID host_id; 333 HostID host_id;
327 }; 334 };
328 335
329 // For storing UserScripts with unique IDs in sets.
330 bool operator<(const UserScript& script1, const UserScript& script2);
331
332 bool operator<(const UserScriptIDPair& a, const UserScriptIDPair& b); 336 bool operator<(const UserScriptIDPair& a, const UserScriptIDPair& b);
333 337
334 typedef std::vector<UserScript> UserScriptList; 338 using UserScriptList = std::vector<std::unique_ptr<UserScript>>;
335 339
336 } // namespace extensions 340 } // namespace extensions
337 341
338 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ 342 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_
OLDNEW
« no previous file with comments | « extensions/browser/web_ui_user_script_loader.cc ('k') | extensions/common/user_script.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698