Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 case DownloadItem::COMPLETE: return kStateComplete; | 107 case DownloadItem::COMPLETE: return kStateComplete; |
| 108 case DownloadItem::INTERRUPTED: // fall through | 108 case DownloadItem::INTERRUPTED: // fall through |
| 109 case DownloadItem::CANCELLED: return kStateInterrupted; | 109 case DownloadItem::CANCELLED: return kStateInterrupted; |
| 110 case DownloadItem::REMOVING: // fall through | 110 case DownloadItem::REMOVING: // fall through |
| 111 default: | 111 default: |
| 112 NOTREACHED(); | 112 NOTREACHED(); |
| 113 return ""; | 113 return ""; |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool ValidateFilename(const string16& filename) { | |
|
benjhayden
2012/01/09 15:22:49
It strikes me that a more robust, perhaps equally
| |
| 118 // TODO(benjhayden): More robust validation of filename. | |
| 119 if (filename.size() >= 2u && filename[0] == L'.' && filename[1] == L'.') | |
| 120 return false; | |
| 121 | |
| 122 if (filename.size() >= 1u && filename[0] == L'/') | |
| 123 return false; | |
| 124 | |
| 125 return true; | |
| 126 } | |
| 127 | |
| 117 } // namespace | 128 } // namespace |
| 118 | 129 |
| 119 bool DownloadsFunctionInterface::RunImplImpl( | 130 bool DownloadsFunctionInterface::RunImplImpl( |
| 120 DownloadsFunctionInterface* pimpl) { | 131 DownloadsFunctionInterface* pimpl) { |
| 121 CHECK(pimpl); | 132 CHECK(pimpl); |
| 122 if (!pimpl->ParseArgs()) return false; | 133 if (!pimpl->ParseArgs()) return false; |
| 123 UMA_HISTOGRAM_ENUMERATION( | 134 UMA_HISTOGRAM_ENUMERATION( |
| 124 "Download.ApiFunctions", pimpl->function(), DOWNLOADS_FUNCTION_LAST); | 135 "Download.ApiFunctions", pimpl->function(), DOWNLOADS_FUNCTION_LAST); |
| 125 return pimpl->RunInternal(); | 136 return pimpl->RunInternal(); |
| 126 } | 137 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 base::DictionaryValue* options = NULL; | 190 base::DictionaryValue* options = NULL; |
| 180 std::string url; | 191 std::string url; |
| 181 iodata_.reset(new IOData()); | 192 iodata_.reset(new IOData()); |
| 182 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); | 193 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); |
| 183 EXTENSION_FUNCTION_VALIDATE(options->GetString(kUrlKey, &url)); | 194 EXTENSION_FUNCTION_VALIDATE(options->GetString(kUrlKey, &url)); |
| 184 iodata_->url = GURL(url); | 195 iodata_->url = GURL(url); |
| 185 if (!iodata_->url.is_valid()) { | 196 if (!iodata_->url.is_valid()) { |
| 186 error_ = download_extension_errors::kInvalidURLError; | 197 error_ = download_extension_errors::kInvalidURLError; |
| 187 return false; | 198 return false; |
| 188 } | 199 } |
| 189 if (options->HasKey(kFilenameKey)) | 200 |
| 201 if (options->HasKey(kFilenameKey)) { | |
| 190 EXTENSION_FUNCTION_VALIDATE(options->GetString( | 202 EXTENSION_FUNCTION_VALIDATE(options->GetString( |
| 191 kFilenameKey, &iodata_->filename)); | 203 kFilenameKey, &iodata_->filename)); |
| 192 // TODO(benjhayden): More robust validation of filename. | 204 if (!ValidateFilename(iodata_->filename)) { |
| 193 if (((iodata_->filename[0] == L'.') && (iodata_->filename[1] == L'.')) || | 205 error_ = download_extension_errors::kGenericError; |
| 194 (iodata_->filename[0] == L'/')) { | 206 return false; |
| 195 error_ = download_extension_errors::kGenericError; | 207 } |
| 196 return false; | |
| 197 } | 208 } |
| 198 if (options->HasKey(kSaveAsKey)) | 209 |
| 210 if (options->HasKey(kSaveAsKey)) { | |
|
benjhayden
2012/01/09 15:22:49
I thought that the style guide forbade braces arou
cbentzel
2012/01/09 19:16:41
Not if the body spans multiple lines.
| |
| 199 EXTENSION_FUNCTION_VALIDATE(options->GetBoolean( | 211 EXTENSION_FUNCTION_VALIDATE(options->GetBoolean( |
| 200 kSaveAsKey, &iodata_->save_as)); | 212 kSaveAsKey, &iodata_->save_as)); |
| 201 if (options->HasKey(kMethodKey)) | 213 } |
| 214 | |
| 215 if (options->HasKey(kMethodKey)) { | |
| 202 EXTENSION_FUNCTION_VALIDATE(options->GetString( | 216 EXTENSION_FUNCTION_VALIDATE(options->GetString( |
| 203 kMethodKey, &iodata_->method)); | 217 kMethodKey, &iodata_->method)); |
| 218 } | |
| 219 | |
| 204 // It's ok to use a pointer to extra_headers without DeepCopy()ing because | 220 // It's ok to use a pointer to extra_headers without DeepCopy()ing because |
| 205 // |args_| (which owns *extra_headers) is guaranteed to live as long as | 221 // |args_| (which owns *extra_headers) is guaranteed to live as long as |
| 206 // |this|. | 222 // |this|. |
| 207 if (options->HasKey(kHeadersKey)) | 223 if (options->HasKey(kHeadersKey)) { |
| 208 EXTENSION_FUNCTION_VALIDATE(options->GetList( | 224 EXTENSION_FUNCTION_VALIDATE(options->GetList( |
| 209 kHeadersKey, &iodata_->extra_headers)); | 225 kHeadersKey, &iodata_->extra_headers)); |
| 210 if (options->HasKey(kBodyKey)) | 226 } |
| 227 | |
| 228 if (options->HasKey(kBodyKey)) { | |
| 211 EXTENSION_FUNCTION_VALIDATE(options->GetString( | 229 EXTENSION_FUNCTION_VALIDATE(options->GetString( |
| 212 kBodyKey, &iodata_->post_body)); | 230 kBodyKey, &iodata_->post_body)); |
| 231 } | |
| 232 | |
| 213 if (iodata_->extra_headers != NULL) { | 233 if (iodata_->extra_headers != NULL) { |
| 214 for (size_t index = 0; index < iodata_->extra_headers->GetSize(); ++index) { | 234 for (size_t index = 0; index < iodata_->extra_headers->GetSize(); ++index) { |
| 215 base::DictionaryValue* header = NULL; | 235 base::DictionaryValue* header = NULL; |
| 216 std::string name, value; | 236 std::string name, value; |
| 217 EXTENSION_FUNCTION_VALIDATE(iodata_->extra_headers->GetDictionary( | 237 EXTENSION_FUNCTION_VALIDATE(iodata_->extra_headers->GetDictionary( |
| 218 index, &header)); | 238 index, &header)); |
| 219 EXTENSION_FUNCTION_VALIDATE(header->GetString( | 239 EXTENSION_FUNCTION_VALIDATE(header->GetString( |
| 220 kHeaderNameKey, &name)); | 240 kHeaderNameKey, &name)); |
| 221 EXTENSION_FUNCTION_VALIDATE(header->GetString( | 241 EXTENSION_FUNCTION_VALIDATE(header->GetString( |
| 222 kHeaderValueKey, &value)); | 242 kHeaderValueKey, &value)); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 ListValue args; | 621 ListValue args; |
| 602 args.Append(arg); | 622 args.Append(arg); |
| 603 std::string json_args; | 623 std::string json_args; |
| 604 base::JSONWriter::Write(&args, false, &json_args); | 624 base::JSONWriter::Write(&args, false, &json_args); |
| 605 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 625 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 606 event_name, | 626 event_name, |
| 607 json_args, | 627 json_args, |
| 608 profile_, | 628 profile_, |
| 609 GURL()); | 629 GURL()); |
| 610 } | 630 } |
| OLD | NEW |