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/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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 std::string url; | 373 std::string url; |
374 iodata_.reset(new IOData()); | 374 iodata_.reset(new IOData()); |
375 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); | 375 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); |
376 EXTENSION_FUNCTION_VALIDATE(options->GetString(kUrlKey, &url)); | 376 EXTENSION_FUNCTION_VALIDATE(options->GetString(kUrlKey, &url)); |
377 iodata_->url = GURL(url); | 377 iodata_->url = GURL(url); |
378 if (!iodata_->url.is_valid()) { | 378 if (!iodata_->url.is_valid()) { |
379 error_ = download_extension_errors::kInvalidURLError; | 379 error_ = download_extension_errors::kInvalidURLError; |
380 return false; | 380 return false; |
381 } | 381 } |
382 | 382 |
| 383 if (!iodata_->url.SchemeIs("data") && |
| 384 iodata_->url.GetOrigin() != GetExtension()->url().GetOrigin() && |
| 385 !GetExtension()->HasHostPermission(iodata_->url)) { |
| 386 error_ = download_extension_errors::kInvalidURLError; |
| 387 return false; |
| 388 } |
| 389 |
383 if (options->HasKey(kFilenameKey)) { | 390 if (options->HasKey(kFilenameKey)) { |
384 EXTENSION_FUNCTION_VALIDATE(options->GetString( | 391 EXTENSION_FUNCTION_VALIDATE(options->GetString( |
385 kFilenameKey, &iodata_->filename)); | 392 kFilenameKey, &iodata_->filename)); |
386 if (!ValidateFilename(iodata_->filename)) { | 393 if (!ValidateFilename(iodata_->filename)) { |
387 error_ = download_extension_errors::kGenericError; | 394 error_ = download_extension_errors::kGenericError; |
388 return false; | 395 return false; |
389 } | 396 } |
390 } | 397 } |
391 | 398 |
392 if (options->HasKey(kSaveAsKey)) { | 399 if (options->HasKey(kSaveAsKey)) { |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 ListValue args; | 1082 ListValue args; |
1076 args.Append(arg); | 1083 args.Append(arg); |
1077 std::string json_args; | 1084 std::string json_args; |
1078 base::JSONWriter::Write(&args, &json_args); | 1085 base::JSONWriter::Write(&args, &json_args); |
1079 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 1086 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
1080 event_name, | 1087 event_name, |
1081 json_args, | 1088 json_args, |
1082 profile_, | 1089 profile_, |
1083 GURL()); | 1090 GURL()); |
1084 } | 1091 } |
OLD | NEW |