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

Side by Side Diff: chrome/browser/download/download_extension_api.cc

Issue 9110042: Re-enable DownloadsApiTest.Downloads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another rebase Created 8 years, 11 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 | « no previous file | chrome/browser/download/download_extension_apitest.cc » ('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/browser/download/download_extension_api.h" 5 #include "chrome/browser/download/download_extension_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <iterator> 9 #include <iterator>
10 #include <set> 10 #include <set>
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 case DownloadItem::COMPLETE: return kStateComplete; 113 case DownloadItem::COMPLETE: return kStateComplete;
114 case DownloadItem::INTERRUPTED: // fall through 114 case DownloadItem::INTERRUPTED: // fall through
115 case DownloadItem::CANCELLED: return kStateInterrupted; 115 case DownloadItem::CANCELLED: return kStateInterrupted;
116 case DownloadItem::REMOVING: // fall through 116 case DownloadItem::REMOVING: // fall through
117 default: 117 default:
118 NOTREACHED(); 118 NOTREACHED();
119 return ""; 119 return "";
120 } 120 }
121 } 121 }
122 122
123 bool ValidateFilename(const string16& filename) {
124 // TODO(benjhayden): More robust validation of filename.
125 if (filename.size() >= 2u && filename[0] == L'.' && filename[1] == L'.')
126 return false;
127
128 if (filename.size() >= 1u && filename[0] == L'/')
129 return false;
130
131 return true;
132 }
133
123 } // namespace 134 } // namespace
124 135
125 bool DownloadsFunctionInterface::RunImplImpl( 136 bool DownloadsFunctionInterface::RunImplImpl(
126 DownloadsFunctionInterface* pimpl) { 137 DownloadsFunctionInterface* pimpl) {
127 CHECK(pimpl); 138 CHECK(pimpl);
128 if (!pimpl->ParseArgs()) return false; 139 if (!pimpl->ParseArgs()) return false;
129 UMA_HISTOGRAM_ENUMERATION( 140 UMA_HISTOGRAM_ENUMERATION(
130 "Download.ApiFunctions", pimpl->function(), DOWNLOADS_FUNCTION_LAST); 141 "Download.ApiFunctions", pimpl->function(), DOWNLOADS_FUNCTION_LAST);
131 return pimpl->RunInternal(); 142 return pimpl->RunInternal();
132 } 143 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 base::DictionaryValue* options = NULL; 196 base::DictionaryValue* options = NULL;
186 std::string url; 197 std::string url;
187 iodata_.reset(new IOData()); 198 iodata_.reset(new IOData());
188 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); 199 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options));
189 EXTENSION_FUNCTION_VALIDATE(options->GetString(kUrlKey, &url)); 200 EXTENSION_FUNCTION_VALIDATE(options->GetString(kUrlKey, &url));
190 iodata_->url = GURL(url); 201 iodata_->url = GURL(url);
191 if (!iodata_->url.is_valid()) { 202 if (!iodata_->url.is_valid()) {
192 error_ = download_extension_errors::kInvalidURLError; 203 error_ = download_extension_errors::kInvalidURLError;
193 return false; 204 return false;
194 } 205 }
195 if (options->HasKey(kFilenameKey)) 206
207 if (options->HasKey(kFilenameKey)) {
196 EXTENSION_FUNCTION_VALIDATE(options->GetString( 208 EXTENSION_FUNCTION_VALIDATE(options->GetString(
197 kFilenameKey, &iodata_->filename)); 209 kFilenameKey, &iodata_->filename));
198 // TODO(benjhayden): More robust validation of filename. 210 if (!ValidateFilename(iodata_->filename)) {
199 if (((iodata_->filename[0] == L'.') && (iodata_->filename[1] == L'.')) || 211 error_ = download_extension_errors::kGenericError;
200 (iodata_->filename[0] == L'/')) { 212 return false;
201 error_ = download_extension_errors::kGenericError; 213 }
202 return false;
203 } 214 }
204 if (options->HasKey(kSaveAsKey)) 215
216 if (options->HasKey(kSaveAsKey)) {
205 EXTENSION_FUNCTION_VALIDATE(options->GetBoolean( 217 EXTENSION_FUNCTION_VALIDATE(options->GetBoolean(
206 kSaveAsKey, &iodata_->save_as)); 218 kSaveAsKey, &iodata_->save_as));
207 if (options->HasKey(kMethodKey)) 219 }
220
221 if (options->HasKey(kMethodKey)) {
208 EXTENSION_FUNCTION_VALIDATE(options->GetString( 222 EXTENSION_FUNCTION_VALIDATE(options->GetString(
209 kMethodKey, &iodata_->method)); 223 kMethodKey, &iodata_->method));
224 }
225
210 // It's ok to use a pointer to extra_headers without DeepCopy()ing because 226 // It's ok to use a pointer to extra_headers without DeepCopy()ing because
211 // |args_| (which owns *extra_headers) is guaranteed to live as long as 227 // |args_| (which owns *extra_headers) is guaranteed to live as long as
212 // |this|. 228 // |this|.
213 if (options->HasKey(kHeadersKey)) 229 if (options->HasKey(kHeadersKey)) {
214 EXTENSION_FUNCTION_VALIDATE(options->GetList( 230 EXTENSION_FUNCTION_VALIDATE(options->GetList(
215 kHeadersKey, &iodata_->extra_headers)); 231 kHeadersKey, &iodata_->extra_headers));
216 if (options->HasKey(kBodyKey)) 232 }
233
234 if (options->HasKey(kBodyKey)) {
217 EXTENSION_FUNCTION_VALIDATE(options->GetString( 235 EXTENSION_FUNCTION_VALIDATE(options->GetString(
218 kBodyKey, &iodata_->post_body)); 236 kBodyKey, &iodata_->post_body));
237 }
238
219 if (iodata_->extra_headers != NULL) { 239 if (iodata_->extra_headers != NULL) {
220 for (size_t index = 0; index < iodata_->extra_headers->GetSize(); ++index) { 240 for (size_t index = 0; index < iodata_->extra_headers->GetSize(); ++index) {
221 base::DictionaryValue* header = NULL; 241 base::DictionaryValue* header = NULL;
222 std::string name, value; 242 std::string name, value;
223 EXTENSION_FUNCTION_VALIDATE(iodata_->extra_headers->GetDictionary( 243 EXTENSION_FUNCTION_VALIDATE(iodata_->extra_headers->GetDictionary(
224 index, &header)); 244 index, &header));
225 EXTENSION_FUNCTION_VALIDATE(header->GetString( 245 EXTENSION_FUNCTION_VALIDATE(header->GetString(
226 kHeaderNameKey, &name)); 246 kHeaderNameKey, &name));
227 EXTENSION_FUNCTION_VALIDATE(header->GetString( 247 EXTENSION_FUNCTION_VALIDATE(header->GetString(
228 kHeaderValueKey, &value)); 248 kHeaderValueKey, &value));
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 ListValue args; 747 ListValue args;
728 args.Append(arg); 748 args.Append(arg);
729 std::string json_args; 749 std::string json_args;
730 base::JSONWriter::Write(&args, false, &json_args); 750 base::JSONWriter::Write(&args, false, &json_args);
731 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( 751 profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
732 event_name, 752 event_name,
733 json_args, 753 json_args,
734 profile_, 754 profile_,
735 GURL()); 755 GURL());
736 } 756 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_extension_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698