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

Unified Diff: extensions/common/user_script.cc

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/common/user_script.h ('k') | extensions/common/user_script_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/common/user_script.cc
diff --git a/extensions/common/user_script.cc b/extensions/common/user_script.cc
index ddf1fb39c0545226441ebdcd0809d996483d004f..f29a7f9a42fe5446a23ae2016daada1f2510c6a2 100644
--- a/extensions/common/user_script.cc
+++ b/extensions/common/user_script.cc
@@ -82,7 +82,11 @@ UserScript::File::File(const base::FilePath& extension_root,
UserScript::File::File() {}
-UserScript::File::File(const File& other) = default;
+// File content is not copied.
+UserScript::File::File(const File& other)
+ : extension_root_(other.extension_root_),
+ relative_path_(other.relative_path_),
+ url_(other.url_) {}
UserScript::File::~File() {}
@@ -95,11 +99,43 @@ UserScript::UserScript()
match_about_blank_(false),
incognito_enabled_(false) {}
-UserScript::UserScript(const UserScript& other) = default;
-
UserScript::~UserScript() {
}
+// static.
+std::unique_ptr<UserScript> UserScript::CopyMetadataFrom(
+ const UserScript& other) {
+ std::unique_ptr<UserScript> script(new UserScript());
+ script->run_location_ = other.run_location_;
+ script->name_space_ = other.name_space_;
+ script->name_ = other.name_;
+ script->description_ = other.description_;
+ script->version_ = other.version_;
+ script->globs_ = other.globs_;
+ script->exclude_globs_ = other.exclude_globs_;
+ script->url_set_ = other.url_set_;
+ script->exclude_url_set_ = other.exclude_url_set_;
+
+ // Note: File content is not copied.
+ for (const std::unique_ptr<File>& file : other.js_scripts()) {
+ std::unique_ptr<File> file_copy(new File(*file));
+ script->js_scripts_.push_back(std::move(file_copy));
+ }
+ for (const std::unique_ptr<File>& file : other.css_scripts()) {
+ std::unique_ptr<File> file_copy(new File(*file));
+ script->css_scripts_.push_back(std::move(file_copy));
+ }
+ script->host_id_ = other.host_id_;
+ script->consumer_instance_type_ = other.consumer_instance_type_;
+ script->user_script_id_ = other.user_script_id_;
+ script->emulate_greasemonkey_ = other.emulate_greasemonkey_;
+ script->match_all_frames_ = other.match_all_frames_;
+ script->match_about_blank_ = other.match_about_blank_;
+ script->incognito_enabled_ = other.incognito_enabled_;
+
+ return script;
+}
+
void UserScript::add_url_pattern(const URLPattern& pattern) {
url_set_.AddPattern(pattern);
}
@@ -193,10 +229,8 @@ void UserScript::PickleURLPatternSet(base::Pickle* pickle,
void UserScript::PickleScripts(base::Pickle* pickle,
const FileList& scripts) const {
pickle->WriteUInt32(scripts.size());
- for (FileList::const_iterator file = scripts.begin();
- file != scripts.end(); ++file) {
+ for (const std::unique_ptr<File>& file : scripts)
file->Pickle(pickle);
- }
}
void UserScript::Unpickle(const base::Pickle& pickle,
@@ -282,9 +316,9 @@ void UserScript::UnpickleScripts(const base::Pickle& pickle,
CHECK(iter->ReadUInt32(&num_files));
scripts->clear();
for (uint32_t i = 0; i < num_files; ++i) {
- File file;
- file.Unpickle(pickle, iter);
- scripts->push_back(file);
+ std::unique_ptr<File> file(new File());
+ file->Unpickle(pickle, iter);
+ scripts->push_back(std::move(file));
}
}
@@ -297,11 +331,4 @@ bool operator<(const UserScriptIDPair& a, const UserScriptIDPair& b) {
return a.id < b.id;
}
-bool operator<(const UserScript& script1, const UserScript& script2) {
- // The only kind of script that should be compared is the kind that has its
- // IDs initialized to a meaningful value.
- DCHECK(script1.id() != -1 && script2.id() != -1);
- return script1.id() < script2.id();
-}
-
} // namespace extensions
« no previous file with comments | « extensions/common/user_script.h ('k') | extensions/common/user_script_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698