OLD | NEW |
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 #include "extensions/common/user_script.h" | 5 #include "extensions/common/user_script.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "extensions/common/switches.h" | 10 #include "extensions/common/switches.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 relative_path_(relative_path), | 63 relative_path_(relative_path), |
64 url_(url) { | 64 url_(url) { |
65 } | 65 } |
66 | 66 |
67 UserScript::File::File() {} | 67 UserScript::File::File() {} |
68 | 68 |
69 UserScript::File::~File() {} | 69 UserScript::File::~File() {} |
70 | 70 |
71 UserScript::UserScript() | 71 UserScript::UserScript() |
72 : run_location_(DOCUMENT_IDLE), | 72 : run_location_(DOCUMENT_IDLE), |
| 73 user_script_id_(-1), |
73 emulate_greasemonkey_(false), | 74 emulate_greasemonkey_(false), |
74 match_all_frames_(false), | 75 match_all_frames_(false), |
75 match_about_blank_(false), | 76 match_about_blank_(false), |
76 incognito_enabled_(false) {} | 77 incognito_enabled_(false) {} |
77 | 78 |
78 UserScript::~UserScript() { | 79 UserScript::~UserScript() { |
79 } | 80 } |
80 | 81 |
81 void UserScript::add_url_pattern(const URLPattern& pattern) { | 82 void UserScript::add_url_pattern(const URLPattern& pattern) { |
82 url_set_.AddPattern(pattern); | 83 url_set_.AddPattern(pattern); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // Read the url from the pickle. | 121 // Read the url from the pickle. |
121 std::string url; | 122 std::string url; |
122 CHECK(pickle.ReadString(iter, &url)); | 123 CHECK(pickle.ReadString(iter, &url)); |
123 set_url(GURL(url)); | 124 set_url(GURL(url)); |
124 } | 125 } |
125 | 126 |
126 void UserScript::Pickle(::Pickle* pickle) const { | 127 void UserScript::Pickle(::Pickle* pickle) const { |
127 // Write the simple types to the pickle. | 128 // Write the simple types to the pickle. |
128 pickle->WriteInt(run_location()); | 129 pickle->WriteInt(run_location()); |
129 pickle->WriteString(extension_id()); | 130 pickle->WriteString(extension_id()); |
| 131 pickle->WriteInt64(user_script_id_); |
130 pickle->WriteBool(emulate_greasemonkey()); | 132 pickle->WriteBool(emulate_greasemonkey()); |
131 pickle->WriteBool(match_all_frames()); | 133 pickle->WriteBool(match_all_frames()); |
132 pickle->WriteBool(match_about_blank()); | 134 pickle->WriteBool(match_about_blank()); |
133 pickle->WriteBool(is_incognito_enabled()); | 135 pickle->WriteBool(is_incognito_enabled()); |
134 | 136 |
135 PickleGlobs(pickle, globs_); | 137 PickleGlobs(pickle, globs_); |
136 PickleGlobs(pickle, exclude_globs_); | 138 PickleGlobs(pickle, exclude_globs_); |
137 PickleURLPatternSet(pickle, url_set_); | 139 PickleURLPatternSet(pickle, url_set_); |
138 PickleURLPatternSet(pickle, exclude_url_set_); | 140 PickleURLPatternSet(pickle, exclude_url_set_); |
139 PickleScripts(pickle, js_scripts_); | 141 PickleScripts(pickle, js_scripts_); |
(...skipping 29 matching lines...) Expand all Loading... |
169 } | 171 } |
170 | 172 |
171 void UserScript::Unpickle(const ::Pickle& pickle, PickleIterator* iter) { | 173 void UserScript::Unpickle(const ::Pickle& pickle, PickleIterator* iter) { |
172 // Read the run location. | 174 // Read the run location. |
173 int run_location = 0; | 175 int run_location = 0; |
174 CHECK(pickle.ReadInt(iter, &run_location)); | 176 CHECK(pickle.ReadInt(iter, &run_location)); |
175 CHECK(run_location >= 0 && run_location < RUN_LOCATION_LAST); | 177 CHECK(run_location >= 0 && run_location < RUN_LOCATION_LAST); |
176 run_location_ = static_cast<RunLocation>(run_location); | 178 run_location_ = static_cast<RunLocation>(run_location); |
177 | 179 |
178 CHECK(pickle.ReadString(iter, &extension_id_)); | 180 CHECK(pickle.ReadString(iter, &extension_id_)); |
| 181 CHECK(pickle.ReadInt64(iter, &user_script_id_)); |
179 CHECK(pickle.ReadBool(iter, &emulate_greasemonkey_)); | 182 CHECK(pickle.ReadBool(iter, &emulate_greasemonkey_)); |
180 CHECK(pickle.ReadBool(iter, &match_all_frames_)); | 183 CHECK(pickle.ReadBool(iter, &match_all_frames_)); |
181 CHECK(pickle.ReadBool(iter, &match_about_blank_)); | 184 CHECK(pickle.ReadBool(iter, &match_about_blank_)); |
182 CHECK(pickle.ReadBool(iter, &incognito_enabled_)); | 185 CHECK(pickle.ReadBool(iter, &incognito_enabled_)); |
183 | 186 |
184 UnpickleGlobs(pickle, iter, &globs_); | 187 UnpickleGlobs(pickle, iter, &globs_); |
185 UnpickleGlobs(pickle, iter, &exclude_globs_); | 188 UnpickleGlobs(pickle, iter, &exclude_globs_); |
186 UnpickleURLPatternSet(pickle, iter, &url_set_); | 189 UnpickleURLPatternSet(pickle, iter, &url_set_); |
187 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_); | 190 UnpickleURLPatternSet(pickle, iter, &exclude_url_set_); |
188 UnpickleScripts(pickle, iter, &js_scripts_); | 191 UnpickleScripts(pickle, iter, &js_scripts_); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 CHECK(pickle.ReadUInt64(iter, &num_files)); | 234 CHECK(pickle.ReadUInt64(iter, &num_files)); |
232 scripts->clear(); | 235 scripts->clear(); |
233 for (uint64 i = 0; i < num_files; ++i) { | 236 for (uint64 i = 0; i < num_files; ++i) { |
234 File file; | 237 File file; |
235 file.Unpickle(pickle, iter); | 238 file.Unpickle(pickle, iter); |
236 scripts->push_back(file); | 239 scripts->push_back(file); |
237 } | 240 } |
238 } | 241 } |
239 | 242 |
240 } // namespace extensions | 243 } // namespace extensions |
OLD | NEW |