OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/ui/webui/cleanup_tool/cleanup_action_handler.h" | 5 #include "chrome/browser/ui/webui/cleanup_tool/cleanup_action_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" | |
10 #include "chrome/browser/ui/browser_dialogs.h" | |
11 #include "chrome/browser/ui/browser_finder.h" | |
9 | 12 |
10 CleanupActionHandler::CleanupActionHandler() {} | 13 CleanupActionHandler::CleanupActionHandler() {} |
11 | 14 |
12 CleanupActionHandler::~CleanupActionHandler() {} | 15 CleanupActionHandler::~CleanupActionHandler() {} |
13 | 16 |
14 void CleanupActionHandler::RegisterMessages() { | 17 void CleanupActionHandler::RegisterMessages() { |
15 web_ui()->RegisterMessageCallback( | 18 web_ui()->RegisterMessageCallback( |
16 "requestLastScanResult", | 19 "requestLastScanResult", |
17 base::Bind(&CleanupActionHandler::HandleRequestLastScanResult, | 20 base::Bind(&CleanupActionHandler::HandleRequestLastScanResult, |
18 base::Unretained(this))); | 21 base::Unretained(this))); |
22 web_ui()->RegisterMessageCallback( | |
23 "startCleanup", base::Bind(&CleanupActionHandler::HandleStartCleanup, | |
24 base::Unretained(this))); | |
19 } | 25 } |
20 | 26 |
21 void CleanupActionHandler::HandleRequestLastScanResult( | 27 void CleanupActionHandler::HandleRequestLastScanResult( |
22 const base::ListValue* args) { | 28 const base::ListValue* args) { |
23 std::string webui_callback_id; | 29 std::string webui_callback_id; |
24 CHECK_EQ(1U, args->GetSize()); | 30 CHECK_EQ(1U, args->GetSize()); |
25 bool success = args->GetString(0, &webui_callback_id); | 31 bool success = args->GetString(0, &webui_callback_id); |
26 DCHECK(success); | 32 DCHECK(success); |
27 | 33 |
28 base::DictionaryValue last_scan_results; | 34 base::DictionaryValue last_scan_results; |
29 // TODO(proberge): Return real information about the last run. | 35 // TODO(proberge): Return real information about the last run. |
30 // TODO(proberge): Localize strings once they are finalized. | 36 // TODO(proberge): Localize strings once they are finalized. |
31 last_scan_results.SetBoolean("hasScanResults", false); | 37 last_scan_results.SetBoolean("hasScanResults", false); |
32 last_scan_results.SetBoolean("isInfected", false); | 38 last_scan_results.SetBoolean("isInfected", false); |
33 last_scan_results.SetString("detectionStatusText", "No problems detected"); | 39 last_scan_results.SetString("detectionStatusText", "No problems detected"); |
34 last_scan_results.SetString("detectionTimeText", "Last scanned today"); | 40 last_scan_results.SetString("detectionTimeText", "Last scanned today"); |
35 | 41 |
36 AllowJavascript(); | 42 AllowJavascript(); |
37 ResolveJavascriptCallback(base::Value(webui_callback_id), last_scan_results); | 43 ResolveJavascriptCallback(base::Value(webui_callback_id), last_scan_results); |
38 } | 44 } |
45 | |
46 void CleanupActionHandler::HandleStartCleanup(const base::ListValue* args) { | |
47 std::string webui_callback_id; | |
48 CHECK_EQ(1U, args->GetSize()); | |
alito
2017/04/14 00:01:18
Move this to the previous line?
proberge
2017/04/18 19:24:28
Done.
| |
49 bool success = args->GetString(0, &webui_callback_id); | |
50 DCHECK(success); | |
51 | |
52 safe_browsing::DisplayUserInitiatedSRTPromptDialog( | |
53 base::Bind(&CleanupActionHandler::ReportCleanupResults, | |
54 base::Unretained(this), webui_callback_id)); | |
55 } | |
56 | |
57 void CleanupActionHandler::ReportCleanupResults( | |
58 const std::string& callback_id) { | |
59 base::DictionaryValue cleanup_results; | |
60 // TODO(proberge): Return real information about the cleanup. | |
61 cleanup_results.SetBoolean("wasCancelled", true); | |
62 | |
63 ResolveJavascriptCallback(base::Value(callback_id), cleanup_results); | |
64 } | |
OLD | NEW |