| 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/extensions/api/downloads/downloads_api.h" | 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 bool visible = platform_util::IsVisible(web_contents->GetNativeView()); | 1264 bool visible = platform_util::IsVisible(web_contents->GetNativeView()); |
| 1265 if (!visible) { | 1265 if (!visible) { |
| 1266 if (retries > 0) { | 1266 if (retries > 0) { |
| 1267 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1267 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1268 FROM_HERE, base::Bind(&DownloadsAcceptDangerFunction::PromptOrWait, | 1268 FROM_HERE, base::Bind(&DownloadsAcceptDangerFunction::PromptOrWait, |
| 1269 this, download_id, retries - 1), | 1269 this, download_id, retries - 1), |
| 1270 base::TimeDelta::FromMilliseconds(100)); | 1270 base::TimeDelta::FromMilliseconds(100)); |
| 1271 return; | 1271 return; |
| 1272 } | 1272 } |
| 1273 error_ = errors::kInvisibleContext; | 1273 error_ = errors::kInvisibleContext; |
| 1274 SendResponse(error_.empty()); | 1274 SendResponse(false); |
| 1275 return; | 1275 return; |
| 1276 } | 1276 } |
| 1277 RecordApiFunctions(DOWNLOADS_FUNCTION_ACCEPT_DANGER); | 1277 RecordApiFunctions(DOWNLOADS_FUNCTION_ACCEPT_DANGER); |
| 1278 // DownloadDangerPrompt displays a modal dialog using native widgets that the | 1278 // DownloadDangerPrompt displays a modal dialog using native widgets that the |
| 1279 // user must either accept or cancel. It cannot be scripted. | 1279 // user must either accept or cancel. It cannot be scripted. |
| 1280 DownloadDangerPrompt* prompt = DownloadDangerPrompt::Create( | 1280 DownloadDangerPrompt* prompt = DownloadDangerPrompt::Create( |
| 1281 download_item, | 1281 download_item, |
| 1282 web_contents, | 1282 web_contents, |
| 1283 true, | 1283 true, |
| 1284 base::Bind(&DownloadsAcceptDangerFunction::DangerPromptCallback, | 1284 base::Bind(&DownloadsAcceptDangerFunction::DangerPromptCallback, |
| 1285 this, download_id)); | 1285 this, download_id)); |
| 1286 // DownloadDangerPrompt deletes itself | 1286 // DownloadDangerPrompt deletes itself |
| 1287 if (on_prompt_created_ && !on_prompt_created_->is_null()) | 1287 if (on_prompt_created_ && !on_prompt_created_->is_null()) |
| 1288 on_prompt_created_->Run(prompt); | 1288 on_prompt_created_->Run(prompt); |
| 1289 SendResponse(error_.empty()); | 1289 // Function finishes in DangerPromptCallback(). |
| 1290 } | 1290 } |
| 1291 | 1291 |
| 1292 void DownloadsAcceptDangerFunction::DangerPromptCallback( | 1292 void DownloadsAcceptDangerFunction::DangerPromptCallback( |
| 1293 int download_id, DownloadDangerPrompt::Action action) { | 1293 int download_id, DownloadDangerPrompt::Action action) { |
| 1294 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1294 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1295 DownloadItem* download_item = | 1295 DownloadItem* download_item = |
| 1296 GetDownload(GetProfile(), include_incognito(), download_id); | 1296 GetDownload(GetProfile(), include_incognito(), download_id); |
| 1297 if (InvalidId(download_item, &error_) || | 1297 if (InvalidId(download_item, &error_) || |
| 1298 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, | 1298 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, |
| 1299 errors::kNotInProgress, &error_)) | 1299 errors::kNotInProgress, &error_)) |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1903 return; | 1903 return; |
| 1904 base::Time now(base::Time::Now()); | 1904 base::Time now(base::Time::Now()); |
| 1905 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); | 1905 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); |
| 1906 if (delta <= kFileExistenceRateLimitSeconds) | 1906 if (delta <= kFileExistenceRateLimitSeconds) |
| 1907 return; | 1907 return; |
| 1908 last_checked_removal_ = now; | 1908 last_checked_removal_ = now; |
| 1909 manager->CheckForHistoryFilesRemoval(); | 1909 manager->CheckForHistoryFilesRemoval(); |
| 1910 } | 1910 } |
| 1911 | 1911 |
| 1912 } // namespace extensions | 1912 } // namespace extensions |
| OLD | NEW |