| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 DownloadItem::DownloadState StateEnumFromString(const std::string& state) { | 165 DownloadItem::DownloadState StateEnumFromString(const std::string& state) { |
| 166 for (size_t i = 0; i < arraysize(kStateStrings); ++i) { | 166 for (size_t i = 0; i < arraysize(kStateStrings); ++i) { |
| 167 if ((kStateStrings[i] != NULL) && (state == kStateStrings[i])) | 167 if ((kStateStrings[i] != NULL) && (state == kStateStrings[i])) |
| 168 return static_cast<DownloadItem::DownloadState>(i); | 168 return static_cast<DownloadItem::DownloadState>(i); |
| 169 } | 169 } |
| 170 return DownloadItem::MAX_DOWNLOAD_STATE; | 170 return DownloadItem::MAX_DOWNLOAD_STATE; |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool ValidateFilename(const string16& filename) { | 173 bool ValidateFilename(const string16& filename) { |
| 174 // TODO(benjhayden): More robust validation of filename. | 174 // TODO(benjhayden): More robust validation of filename. |
| 175 if ((filename.find('/') != string16::npos) || |
| 176 (filename.find('\\') != string16::npos)) |
| 177 return false; |
| 175 if (filename.size() >= 2u && filename[0] == L'.' && filename[1] == L'.') | 178 if (filename.size() >= 2u && filename[0] == L'.' && filename[1] == L'.') |
| 176 return false; | 179 return false; |
| 177 | |
| 178 if (filename.size() >= 1u && filename[0] == L'/') | |
| 179 return false; | |
| 180 | |
| 181 return true; | 180 return true; |
| 182 } | 181 } |
| 183 | 182 |
| 184 scoped_ptr<base::DictionaryValue> DownloadItemToJSON(DownloadItem* item) { | 183 scoped_ptr<base::DictionaryValue> DownloadItemToJSON(DownloadItem* item) { |
| 185 base::DictionaryValue* json = new base::DictionaryValue(); | 184 base::DictionaryValue* json = new base::DictionaryValue(); |
| 186 json->SetInteger(kIdKey, item->GetId()); | 185 json->SetInteger(kIdKey, item->GetId()); |
| 187 json->SetString(kUrlKey, item->GetOriginalUrl().spec()); | 186 json->SetString(kUrlKey, item->GetOriginalUrl().spec()); |
| 188 json->SetString(kFilenameKey, item->GetFullPath().LossyDisplayName()); | 187 json->SetString(kFilenameKey, item->GetFullPath().LossyDisplayName()); |
| 189 json->SetString(kDangerKey, DangerString(item->GetDangerType())); | 188 json->SetString(kDangerKey, DangerString(item->GetDangerType())); |
| 190 if (item->GetDangerType() != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) | 189 if (item->GetDangerType() != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 ListValue args; | 1074 ListValue args; |
| 1076 args.Append(arg); | 1075 args.Append(arg); |
| 1077 std::string json_args; | 1076 std::string json_args; |
| 1078 base::JSONWriter::Write(&args, &json_args); | 1077 base::JSONWriter::Write(&args, &json_args); |
| 1079 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 1078 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 1080 event_name, | 1079 event_name, |
| 1081 json_args, | 1080 json_args, |
| 1082 profile_, | 1081 profile_, |
| 1083 GURL()); | 1082 GURL()); |
| 1084 } | 1083 } |
| OLD | NEW |