| Index: extensions/common/user_script.cc
|
| diff --git a/extensions/common/user_script.cc b/extensions/common/user_script.cc
|
| index ddf1fb39c0545226441ebdcd0809d996483d004f..35a39a12445193487a66eb4ccdfbb18b76ee0d2d 100644
|
| --- a/extensions/common/user_script.cc
|
| +++ b/extensions/common/user_script.cc
|
| @@ -72,43 +72,61 @@ int UserScript::ValidUserScriptSchemes(bool canExecuteScriptEverywhere) {
|
| return valid_schemes;
|
| }
|
|
|
| -UserScript::File::File(const base::FilePath& extension_root,
|
| - const base::FilePath& relative_path,
|
| - const GURL& url)
|
| +UserScriptFileInfo::UserScriptFileInfo(const base::FilePath& extension_root,
|
| + const base::FilePath& relative_path,
|
| + const GURL& url)
|
| : extension_root_(extension_root),
|
| relative_path_(relative_path),
|
| - url_(url) {
|
| -}
|
| + url_(url) {}
|
|
|
| -UserScript::File::File() {}
|
| +UserScriptFileInfo::UserScriptFileInfo() {}
|
|
|
| -UserScript::File::File(const File& other) = default;
|
| +UserScriptFileInfo::UserScriptFileInfo(const UserScriptFileInfo& other) =
|
| + default;
|
|
|
| -UserScript::File::~File() {}
|
| +UserScriptFileInfo::~UserScriptFileInfo() {}
|
|
|
| -UserScript::UserScript()
|
| - : run_location_(DOCUMENT_IDLE),
|
| - consumer_instance_type_(TAB),
|
| +void UserScriptFileInfo::Pickle(base::Pickle* pickle) const {
|
| + pickle->WriteString(url_.spec());
|
| + // Do not write path. It's not needed in the renderer.
|
| + // Do not write content. It will be serialized by other means.
|
| +}
|
| +
|
| +void UserScriptFileInfo::Unpickle(const base::Pickle& pickle,
|
| + base::PickleIterator* iter) {
|
| + // Read the url from the pickle.
|
| + std::string url;
|
| + CHECK(iter->ReadString(&url));
|
| + set_url(GURL(url));
|
| +}
|
| +
|
| +UserScriptInfo::UserScriptInfo()
|
| + : run_location_(UserScript::DOCUMENT_IDLE),
|
| + consumer_instance_type_(UserScript::TAB),
|
| user_script_id_(-1),
|
| emulate_greasemonkey_(false),
|
| match_all_frames_(false),
|
| match_about_blank_(false),
|
| incognito_enabled_(false) {}
|
|
|
| -UserScript::UserScript(const UserScript& other) = default;
|
| +UserScriptInfo::UserScriptInfo(const UserScriptInfo& other) = default;
|
|
|
| -UserScript::~UserScript() {
|
| -}
|
| +UserScriptInfo::~UserScriptInfo() {}
|
|
|
| -void UserScript::add_url_pattern(const URLPattern& pattern) {
|
| +ScriptMetadata::ScriptMetadata() {}
|
| +ScriptMetadata::ScriptMetadata(const UserScriptInfo& info)
|
| + : UserScriptInfo(info) {}
|
| +ScriptMetadata::~ScriptMetadata() {}
|
| +
|
| +void UserScriptInfo::add_url_pattern(const URLPattern& pattern) {
|
| url_set_.AddPattern(pattern);
|
| }
|
|
|
| -void UserScript::add_exclude_url_pattern(const URLPattern& pattern) {
|
| +void UserScriptInfo::add_exclude_url_pattern(const URLPattern& pattern) {
|
| exclude_url_set_.AddPattern(pattern);
|
| }
|
|
|
| -bool UserScript::MatchesURL(const GURL& url) const {
|
| +bool UserScriptInfo::MatchesURL(const GURL& url) const {
|
| if (!url_set_.is_empty()) {
|
| if (!url_set_.MatchesURL(url))
|
| return false;
|
| @@ -132,21 +150,7 @@ bool UserScript::MatchesURL(const GURL& url) const {
|
| return true;
|
| }
|
|
|
| -void UserScript::File::Pickle(base::Pickle* pickle) const {
|
| - pickle->WriteString(url_.spec());
|
| - // Do not write path. It's not needed in the renderer.
|
| - // Do not write content. It will be serialized by other means.
|
| -}
|
| -
|
| -void UserScript::File::Unpickle(const base::Pickle& pickle,
|
| - base::PickleIterator* iter) {
|
| - // Read the url from the pickle.
|
| - std::string url;
|
| - CHECK(iter->ReadString(&url));
|
| - set_url(GURL(url));
|
| -}
|
| -
|
| -void UserScript::Pickle(base::Pickle* pickle) const {
|
| +void UserScriptInfo::Pickle(base::Pickle* pickle) const {
|
| // Write the simple types to the pickle.
|
| pickle->WriteInt(run_location());
|
| pickle->WriteInt(user_script_id_);
|
| @@ -161,12 +165,10 @@ void UserScript::Pickle(base::Pickle* pickle) const {
|
| PickleGlobs(pickle, exclude_globs_);
|
| PickleURLPatternSet(pickle, url_set_);
|
| PickleURLPatternSet(pickle, exclude_url_set_);
|
| - PickleScripts(pickle, js_scripts_);
|
| - PickleScripts(pickle, css_scripts_);
|
| }
|
|
|
| -void UserScript::PickleGlobs(base::Pickle* pickle,
|
| - const std::vector<std::string>& globs) const {
|
| +void UserScriptInfo::PickleGlobs(base::Pickle* pickle,
|
| + const std::vector<std::string>& globs) const {
|
| pickle->WriteUInt32(globs.size());
|
| for (std::vector<std::string>::const_iterator glob = globs.begin();
|
| glob != globs.end(); ++glob) {
|
| @@ -174,14 +176,15 @@ void UserScript::PickleGlobs(base::Pickle* pickle,
|
| }
|
| }
|
|
|
| -void UserScript::PickleHostID(base::Pickle* pickle,
|
| - const HostID& host_id) const {
|
| +void UserScriptInfo::PickleHostID(base::Pickle* pickle,
|
| + const HostID& host_id) const {
|
| pickle->WriteInt(host_id.type());
|
| pickle->WriteString(host_id.id());
|
| }
|
|
|
| -void UserScript::PickleURLPatternSet(base::Pickle* pickle,
|
| - const URLPatternSet& pattern_list) const {
|
| +void UserScriptInfo::PickleURLPatternSet(
|
| + base::Pickle* pickle,
|
| + const URLPatternSet& pattern_list) const {
|
| pickle->WriteUInt32(pattern_list.patterns().size());
|
| for (URLPatternSet::const_iterator pattern = pattern_list.begin();
|
| pattern != pattern_list.end(); ++pattern) {
|
| @@ -190,22 +193,13 @@ 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) {
|
| - file->Pickle(pickle);
|
| - }
|
| -}
|
| -
|
| -void UserScript::Unpickle(const base::Pickle& pickle,
|
| - base::PickleIterator* iter) {
|
| +void UserScriptInfo::Unpickle(const base::Pickle& pickle,
|
| + base::PickleIterator* iter) {
|
| // Read the run location.
|
| int run_location = 0;
|
| CHECK(iter->ReadInt(&run_location));
|
| - CHECK(run_location >= 0 && run_location < RUN_LOCATION_LAST);
|
| - run_location_ = static_cast<RunLocation>(run_location);
|
| + CHECK(run_location >= 0 && run_location < UserScript::RUN_LOCATION_LAST);
|
| + run_location_ = static_cast<UserScript::RunLocation>(run_location);
|
|
|
| CHECK(iter->ReadInt(&user_script_id_));
|
| CHECK(iter->ReadBool(&emulate_greasemonkey_));
|
| @@ -218,19 +212,17 @@ void UserScript::Unpickle(const base::Pickle& pickle,
|
| int consumer_instance_type = 0;
|
| CHECK(iter->ReadInt(&consumer_instance_type));
|
| consumer_instance_type_ =
|
| - static_cast<ConsumerInstanceType>(consumer_instance_type);
|
| + static_cast<UserScript::ConsumerInstanceType>(consumer_instance_type);
|
|
|
| UnpickleGlobs(pickle, iter, &globs_);
|
| UnpickleGlobs(pickle, iter, &exclude_globs_);
|
| UnpickleURLPatternSet(pickle, iter, &url_set_);
|
| UnpickleURLPatternSet(pickle, iter, &exclude_url_set_);
|
| - UnpickleScripts(pickle, iter, &js_scripts_);
|
| - UnpickleScripts(pickle, iter, &css_scripts_);
|
| }
|
|
|
| -void UserScript::UnpickleGlobs(const base::Pickle& pickle,
|
| - base::PickleIterator* iter,
|
| - std::vector<std::string>* globs) {
|
| +void UserScriptInfo::UnpickleGlobs(const base::Pickle& pickle,
|
| + base::PickleIterator* iter,
|
| + std::vector<std::string>* globs) {
|
| uint32_t num_globs = 0;
|
| CHECK(iter->ReadUInt32(&num_globs));
|
| globs->clear();
|
| @@ -241,9 +233,9 @@ void UserScript::UnpickleGlobs(const base::Pickle& pickle,
|
| }
|
| }
|
|
|
| -void UserScript::UnpickleHostID(const base::Pickle& pickle,
|
| - base::PickleIterator* iter,
|
| - HostID* host_id) {
|
| +void UserScriptInfo::UnpickleHostID(const base::Pickle& pickle,
|
| + base::PickleIterator* iter,
|
| + HostID* host_id) {
|
| int type = 0;
|
| std::string id;
|
| CHECK(iter->ReadInt(&type));
|
| @@ -251,9 +243,9 @@ void UserScript::UnpickleHostID(const base::Pickle& pickle,
|
| *host_id = HostID(static_cast<HostID::HostType>(type), id);
|
| }
|
|
|
| -void UserScript::UnpickleURLPatternSet(const base::Pickle& pickle,
|
| - base::PickleIterator* iter,
|
| - URLPatternSet* pattern_list) {
|
| +void UserScriptInfo::UnpickleURLPatternSet(const base::Pickle& pickle,
|
| + base::PickleIterator* iter,
|
| + URLPatternSet* pattern_list) {
|
| uint32_t num_patterns = 0;
|
| CHECK(iter->ReadUInt32(&num_patterns));
|
|
|
| @@ -275,19 +267,6 @@ void UserScript::UnpickleURLPatternSet(const base::Pickle& pickle,
|
| }
|
| }
|
|
|
| -void UserScript::UnpickleScripts(const base::Pickle& pickle,
|
| - base::PickleIterator* iter,
|
| - FileList* scripts) {
|
| - uint32_t num_files = 0;
|
| - 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);
|
| - }
|
| -}
|
| -
|
| UserScriptIDPair::UserScriptIDPair(int id, const HostID& host_id)
|
| : id(id), host_id(host_id) {}
|
|
|
| @@ -297,11 +276,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
|
|
|