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/ui/webui/downloads_dom_handler.h" | 5 #include "chrome/browser/ui/webui/downloads_dom_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/i18n/time_formatting.h" | 14 #include "base/i18n/time_formatting.h" |
15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 16 #include "base/metrics/field_trial.h" |
16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
17 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
18 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
21 #include "base/value_conversions.h" | 22 #include "base/value_conversions.h" |
22 #include "base/values.h" | 23 #include "base/values.h" |
23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/download/download_crx_util.h" | 25 #include "chrome/browser/download/download_crx_util.h" |
25 #include "chrome/browser/download/download_danger_prompt.h" | 26 #include "chrome/browser/download/download_danger_prompt.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 file_value->SetString("file_name", file_name); | 161 file_value->SetString("file_name", file_name); |
161 file_value->SetString("url", download_item->GetURL().spec()); | 162 file_value->SetString("url", download_item->GetURL().spec()); |
162 file_value->SetBoolean("otr", incognito); | 163 file_value->SetBoolean("otr", incognito); |
163 file_value->SetInteger("total", static_cast<int>( | 164 file_value->SetInteger("total", static_cast<int>( |
164 download_item->GetTotalBytes())); | 165 download_item->GetTotalBytes())); |
165 file_value->SetBoolean("file_externally_removed", | 166 file_value->SetBoolean("file_externally_removed", |
166 download_item->GetFileExternallyRemoved()); | 167 download_item->GetFileExternallyRemoved()); |
167 file_value->SetBoolean("retry", false); // Overridden below if needed. | 168 file_value->SetBoolean("retry", false); // Overridden below if needed. |
168 file_value->SetBoolean("resume", download_item->CanResume()); | 169 file_value->SetBoolean("resume", download_item->CanResume()); |
169 | 170 |
| 171 std::string trial_condition = |
| 172 base::FieldTrialList::FindFullName(download_util::kFinchTrialName); |
| 173 |
170 switch (download_item->GetState()) { | 174 switch (download_item->GetState()) { |
171 case content::DownloadItem::IN_PROGRESS: | 175 case content::DownloadItem::IN_PROGRESS: |
172 if (download_item->IsDangerous()) { | 176 if (download_item->IsDangerous()) { |
173 file_value->SetString("state", "DANGEROUS"); | 177 file_value->SetString("state", "DANGEROUS"); |
174 // These are the only danger states that the UI is equipped to handle. | 178 // These are the only danger states that the UI is equipped to handle. |
175 DCHECK(download_item->GetDangerType() == | 179 DCHECK(download_item->GetDangerType() == |
176 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || | 180 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || |
177 download_item->GetDangerType() == | 181 download_item->GetDangerType() == |
178 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || | 182 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || |
179 download_item->GetDangerType() == | 183 download_item->GetDangerType() == |
180 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || | 184 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || |
181 download_item->GetDangerType() == | 185 download_item->GetDangerType() == |
182 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT || | 186 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT || |
183 download_item->GetDangerType() == | 187 download_item->GetDangerType() == |
184 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST || | 188 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST || |
185 download_item->GetDangerType() == | 189 download_item->GetDangerType() == |
186 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED); | 190 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED); |
187 const char* danger_type_value = | 191 const char* danger_type_value = |
188 GetDangerTypeString(download_item->GetDangerType()); | 192 GetDangerTypeString(download_item->GetDangerType()); |
189 file_value->SetString("danger_type", danger_type_value); | 193 file_value->SetString("danger_type", danger_type_value); |
| 194 if (!trial_condition.empty()) { |
| 195 string16 finch_string; |
| 196 content::DownloadDangerType danger_type = |
| 197 download_item->GetDangerType(); |
| 198 if (danger_type == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || |
| 199 danger_type == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || |
| 200 danger_type == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST) { |
| 201 finch_string = download_util::AssembleMalwareFinchString( |
| 202 trial_condition, file_name); |
| 203 } |
| 204 file_value->SetString("finch_string", finch_string); |
| 205 } |
190 } else if (download_item->IsPaused()) { | 206 } else if (download_item->IsPaused()) { |
191 file_value->SetString("state", "PAUSED"); | 207 file_value->SetString("state", "PAUSED"); |
192 } else { | 208 } else { |
193 file_value->SetString("state", "IN_PROGRESS"); | 209 file_value->SetString("state", "IN_PROGRESS"); |
194 } | 210 } |
195 | 211 |
196 file_value->SetString("progress_status_text", | 212 file_value->SetString("progress_status_text", |
197 download_util::GetProgressStatusText(download_item)); | 213 download_util::GetProgressStatusText(download_item)); |
198 | 214 |
199 file_value->SetInteger("percent", | 215 file_value->SetInteger("percent", |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 598 } |
583 | 599 |
584 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { | 600 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { |
585 web_ui()->CallJavascriptFunction("downloadsList", downloads); | 601 web_ui()->CallJavascriptFunction("downloadsList", downloads); |
586 } | 602 } |
587 | 603 |
588 void DownloadsDOMHandler::CallDownloadUpdated( | 604 void DownloadsDOMHandler::CallDownloadUpdated( |
589 const base::ListValue& download_item) { | 605 const base::ListValue& download_item) { |
590 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); | 606 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); |
591 } | 607 } |
OLD | NEW |