OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/user_script.h" | 5 #include "chrome/common/extensions/user_script.h" |
6 | 6 |
7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 glob != globs.end(); ++glob) { | 121 glob != globs.end(); ++glob) { |
122 pickle->WriteString(*glob); | 122 pickle->WriteString(*glob); |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 void UserScript::PickleURLPatternSet(::Pickle* pickle, | 126 void UserScript::PickleURLPatternSet(::Pickle* pickle, |
127 const URLPatternSet& pattern_list) const { | 127 const URLPatternSet& pattern_list) const { |
128 pickle->WriteUInt64(pattern_list.patterns().size()); | 128 pickle->WriteUInt64(pattern_list.patterns().size()); |
129 for (URLPatternSet::const_iterator pattern = pattern_list.begin(); | 129 for (URLPatternSet::const_iterator pattern = pattern_list.begin(); |
130 pattern != pattern_list.end(); ++pattern) { | 130 pattern != pattern_list.end(); ++pattern) { |
| 131 pickle->WriteString(pattern->GetAsString()); |
131 pickle->WriteInt(pattern->valid_schemes()); | 132 pickle->WriteInt(pattern->valid_schemes()); |
132 pickle->WriteString(pattern->GetAsString()); | |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 void UserScript::PickleScripts(::Pickle* pickle, | 136 void UserScript::PickleScripts(::Pickle* pickle, |
137 const FileList& scripts) const { | 137 const FileList& scripts) const { |
138 pickle->WriteUInt64(scripts.size()); | 138 pickle->WriteUInt64(scripts.size()); |
139 for (FileList::const_iterator file = scripts.begin(); | 139 for (FileList::const_iterator file = scripts.begin(); |
140 file != scripts.end(); ++file) { | 140 file != scripts.end(); ++file) { |
141 file->Pickle(pickle); | 141 file->Pickle(pickle); |
142 } | 142 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 175 } |
176 | 176 |
177 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle, | 177 void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle, |
178 PickleIterator* iter, | 178 PickleIterator* iter, |
179 URLPatternSet* pattern_list) { | 179 URLPatternSet* pattern_list) { |
180 uint64 num_patterns = 0; | 180 uint64 num_patterns = 0; |
181 CHECK(pickle.ReadUInt64(iter, &num_patterns)); | 181 CHECK(pickle.ReadUInt64(iter, &num_patterns)); |
182 | 182 |
183 pattern_list->ClearPatterns(); | 183 pattern_list->ClearPatterns(); |
184 for (uint64 i = 0; i < num_patterns; ++i) { | 184 for (uint64 i = 0; i < num_patterns; ++i) { |
| 185 std::string pattern_str; |
| 186 URLPattern pattern(kValidUserScriptSchemes); |
| 187 CHECK(pickle.ReadString(iter, &pattern_str)); |
| 188 |
| 189 URLPattern::ParseResult result = pattern.Parse(pattern_str); |
| 190 CHECK(URLPattern::PARSE_SUCCESS == result) << |
| 191 URLPattern::GetParseResultString(result) << " " << pattern_str.c_str(); |
| 192 |
185 int valid_schemes; | 193 int valid_schemes; |
186 CHECK(pickle.ReadInt(iter, &valid_schemes)); | 194 CHECK(pickle.ReadInt(iter, &valid_schemes)); |
187 std::string pattern_str; | 195 pattern.SetValidSchemes(valid_schemes); |
188 URLPattern pattern(valid_schemes); | |
189 CHECK(pickle.ReadString(iter, &pattern_str)); | |
190 | |
191 // We remove the file scheme if it's not actually allowed (see Extension:: | |
192 // LoadUserScriptHelper), but we need it temporarily while loading the | |
193 // pattern so that it's valid. | |
194 bool had_file_scheme = (valid_schemes & URLPattern::SCHEME_FILE) != 0; | |
195 if (!had_file_scheme) | |
196 pattern.SetValidSchemes(valid_schemes | URLPattern::SCHEME_FILE); | |
197 CHECK(URLPattern::PARSE_SUCCESS == pattern.Parse(pattern_str)); | |
198 if (!had_file_scheme) | |
199 pattern.SetValidSchemes(valid_schemes); | |
200 | |
201 pattern_list->AddPattern(pattern); | 196 pattern_list->AddPattern(pattern); |
202 } | 197 } |
203 } | 198 } |
204 | 199 |
205 void UserScript::UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, | 200 void UserScript::UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, |
206 FileList* scripts) { | 201 FileList* scripts) { |
207 uint64 num_files = 0; | 202 uint64 num_files = 0; |
208 CHECK(pickle.ReadUInt64(iter, &num_files)); | 203 CHECK(pickle.ReadUInt64(iter, &num_files)); |
209 scripts->clear(); | 204 scripts->clear(); |
210 for (uint64 i = 0; i < num_files; ++i) { | 205 for (uint64 i = 0; i < num_files; ++i) { |
211 File file; | 206 File file; |
212 file.Unpickle(pickle, iter); | 207 file.Unpickle(pickle, iter); |
213 scripts->push_back(file); | 208 scripts->push_back(file); |
214 } | 209 } |
215 } | 210 } |
216 | 211 |
217 } // namespace extensions | 212 } // namespace extensions |
OLD | NEW |