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

Side by Side Diff: chrome/common/extensions/user_script.cc

Issue 12792005: Allow extensions on chrome:// URLs, when flag is set and permission is explicitly requested (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More cleanup Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/user_script.h ('k') | extensions/common/url_pattern.h » ('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 (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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->WriteInt(pattern->valid_schemes()); 131 pickle->WriteInt(pattern->valid_schemes());
132 pickle->WriteString(pattern->GetAsString()); 132 pickle->WriteString(pattern->GetAsString());
133 pickle->WriteInt(pattern->allowed_schemes());
133 } 134 }
134 } 135 }
135 136
136 void UserScript::PickleScripts(::Pickle* pickle, 137 void UserScript::PickleScripts(::Pickle* pickle,
137 const FileList& scripts) const { 138 const FileList& scripts) const {
138 pickle->WriteUInt64(scripts.size()); 139 pickle->WriteUInt64(scripts.size());
139 for (FileList::const_iterator file = scripts.begin(); 140 for (FileList::const_iterator file = scripts.begin();
140 file != scripts.end(); ++file) { 141 file != scripts.end(); ++file) {
141 file->Pickle(pickle); 142 file->Pickle(pickle);
142 } 143 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 CHECK(pickle.ReadUInt64(iter, &num_patterns)); 182 CHECK(pickle.ReadUInt64(iter, &num_patterns));
182 183
183 pattern_list->ClearPatterns(); 184 pattern_list->ClearPatterns();
184 for (uint64 i = 0; i < num_patterns; ++i) { 185 for (uint64 i = 0; i < num_patterns; ++i) {
185 int valid_schemes; 186 int valid_schemes;
186 CHECK(pickle.ReadInt(iter, &valid_schemes)); 187 CHECK(pickle.ReadInt(iter, &valid_schemes));
187 std::string pattern_str; 188 std::string pattern_str;
188 URLPattern pattern(valid_schemes); 189 URLPattern pattern(valid_schemes);
189 CHECK(pickle.ReadString(iter, &pattern_str)); 190 CHECK(pickle.ReadString(iter, &pattern_str));
190 191
191 // We remove the file scheme if it's not actually allowed (see Extension:: 192 URLPattern::ParseResult result = pattern.Parse(pattern_str);
192 // LoadUserScriptHelper), but we need it temporarily while loading the 193 CHECK(URLPattern::PARSE_SUCCESS == result) <<
193 // pattern so that it's valid. 194 URLPattern::GetParseResultString(result) << " " << pattern_str.c_str();
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 195
196 int allowed_schemes;
197 if (pickle.ReadInt(iter, &allowed_schemes))
198 pattern.SetAllowedSchemes(allowed_schemes);
201 pattern_list->AddPattern(pattern); 199 pattern_list->AddPattern(pattern);
202 } 200 }
203 } 201 }
204 202
205 void UserScript::UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, 203 void UserScript::UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter,
206 FileList* scripts) { 204 FileList* scripts) {
207 uint64 num_files = 0; 205 uint64 num_files = 0;
208 CHECK(pickle.ReadUInt64(iter, &num_files)); 206 CHECK(pickle.ReadUInt64(iter, &num_files));
209 scripts->clear(); 207 scripts->clear();
210 for (uint64 i = 0; i < num_files; ++i) { 208 for (uint64 i = 0; i < num_files; ++i) {
211 File file; 209 File file;
212 file.Unpickle(pickle, iter); 210 file.Unpickle(pickle, iter);
213 scripts->push_back(file); 211 scripts->push_back(file);
214 } 212 }
215 } 213 }
216 214
217 } // namespace extensions 215 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/user_script.h ('k') | extensions/common/url_pattern.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698