Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: chrome/browser/ui/gtk/download/download_item_gtk.cc

Issue 8503018: Split DownloadItem into an ABC, an Impl, and a Mock. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: merge Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/gtk/download/download_item_gtk.h" 5 #include "chrome/browser/ui/gtk/download/download_item_gtk.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 286
287 // Make sure this widget has been destroyed and the pointer we hold to it 287 // Make sure this widget has been destroyed and the pointer we hold to it
288 // NULLed. 288 // NULLed.
289 DCHECK(!status_label_); 289 DCHECK(!status_label_);
290 } 290 }
291 291
292 void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) { 292 void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) {
293 DCHECK_EQ(download, get_download()); 293 DCHECK_EQ(download, get_download());
294 294
295 if (dangerous_prompt_ != NULL && 295 if (dangerous_prompt_ != NULL &&
296 download->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED) { 296 download->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED) {
297 // We have been approved. 297 // We have been approved.
298 gtk_widget_set_no_show_all(body_.get(), FALSE); 298 gtk_widget_set_no_show_all(body_.get(), FALSE);
299 gtk_widget_set_no_show_all(menu_button_, FALSE); 299 gtk_widget_set_no_show_all(menu_button_, FALSE);
300 gtk_widget_show_all(hbox_.get()); 300 gtk_widget_show_all(hbox_.get());
301 gtk_widget_destroy(dangerous_prompt_); 301 gtk_widget_destroy(dangerous_prompt_);
302 gtk_widget_set_size_request(body_.get(), kBodyWidth, -1); 302 gtk_widget_set_size_request(body_.get(), kBodyWidth, -1);
303 dangerous_prompt_ = NULL; 303 dangerous_prompt_ = NULL;
304 304
305 // We may free some shelf space for showing more download items. 305 // We may free some shelf space for showing more download items.
306 parent_shelf_->MaybeShowMoreDownloadItems(); 306 parent_shelf_->MaybeShowMoreDownloadItems();
307 } 307 }
308 308
309 if (download->GetUserVerifiedFilePath() != icon_filepath_) { 309 if (download->GetUserVerifiedFilePath() != icon_filepath_) {
310 // Turns out the file path is "Unconfirmed %d.crdownload" for dangerous 310 // Turns out the file path is "Unconfirmed %d.crdownload" for dangerous
311 // downloads. When the download is confirmed, the file is renamed on 311 // downloads. When the download is confirmed, the file is renamed on
312 // another thread, so reload the icon if the download filename changes. 312 // another thread, so reload the icon if the download filename changes.
313 LoadIcon(); 313 LoadIcon();
314 314
315 UpdateTooltip(); 315 UpdateTooltip();
316 } 316 }
317 317
318 switch (download->state()) { 318 switch (download->GetState()) {
319 case DownloadItem::REMOVING: 319 case DownloadItem::REMOVING:
320 parent_shelf_->RemoveDownloadItem(this); // This will delete us! 320 parent_shelf_->RemoveDownloadItem(this); // This will delete us!
321 return; 321 return;
322 case DownloadItem::CANCELLED: 322 case DownloadItem::CANCELLED:
323 StopDownloadProgress(); 323 StopDownloadProgress();
324 gtk_widget_queue_draw(progress_area_.get()); 324 gtk_widget_queue_draw(progress_area_.get());
325 break; 325 break;
326 case DownloadItem::INTERRUPTED: 326 case DownloadItem::INTERRUPTED:
327 StopDownloadProgress(); 327 StopDownloadProgress();
328 328
329 complete_animation_.Show(); 329 complete_animation_.Show();
330 break; 330 break;
331 case DownloadItem::COMPLETE: 331 case DownloadItem::COMPLETE:
332 // auto_opened() may change after the download's initial transition to 332 // GetAutoOpened() may change after the download's initial transition to
333 // COMPLETE, so we check it before the idemopotency shield below. 333 // COMPLETE, so we check it before the idemopotency shield below.
334 if (download->auto_opened()) { 334 if (download->GetAutoOpened()) {
335 parent_shelf_->RemoveDownloadItem(this); // This will delete us! 335 parent_shelf_->RemoveDownloadItem(this); // This will delete us!
336 return; 336 return;
337 } 337 }
338 338
339 // We've already handled the completion specific actions; skip 339 // We've already handled the completion specific actions; skip
340 // doing the non-idempotent ones again. 340 // doing the non-idempotent ones again.
341 if (download_complete_) 341 if (download_complete_)
342 break; 342 break;
343 343
344 StopDownloadProgress(); 344 StopDownloadProgress();
345 345
346 // Set up the widget as a drag source. 346 // Set up the widget as a drag source.
347 DownloadItemDrag::SetSource(body_.get(), get_download(), icon_large_); 347 DownloadItemDrag::SetSource(body_.get(), get_download(), icon_large_);
348 348
349 complete_animation_.Show(); 349 complete_animation_.Show();
350 download_complete_ = true; 350 download_complete_ = true;
351 break; 351 break;
352 case DownloadItem::IN_PROGRESS: 352 case DownloadItem::IN_PROGRESS:
353 get_download()->is_paused() ? 353 get_download()->IsPaused() ?
354 StopDownloadProgress() : StartDownloadProgress(); 354 StopDownloadProgress() : StartDownloadProgress();
355 break; 355 break;
356 default: 356 default:
357 NOTREACHED(); 357 NOTREACHED();
358 } 358 }
359 359
360 status_text_ = UTF16ToUTF8(download_model_->GetStatusText()); 360 status_text_ = UTF16ToUTF8(download_model_->GetStatusText());
361 UpdateStatusLabel(status_text_); 361 UpdateStatusLabel(status_text_);
362 } 362 }
363 363
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 UpdateStatusLabel(status_text_); 410 UpdateStatusLabel(status_text_);
411 UpdateDangerWarning(); 411 UpdateDangerWarning();
412 } 412 }
413 } 413 }
414 414
415 DownloadItem* DownloadItemGtk::get_download() { 415 DownloadItem* DownloadItemGtk::get_download() {
416 return download_model_->download(); 416 return download_model_->download();
417 } 417 }
418 418
419 bool DownloadItemGtk::IsDangerous() { 419 bool DownloadItemGtk::IsDangerous() {
420 return get_download()->safety_state() == DownloadItem::DANGEROUS; 420 return get_download()->GetSafetyState() == DownloadItem::DANGEROUS;
421 } 421 }
422 422
423 // Download progress animation functions. 423 // Download progress animation functions.
424 424
425 void DownloadItemGtk::UpdateDownloadProgress() { 425 void DownloadItemGtk::UpdateDownloadProgress() {
426 progress_angle_ = (progress_angle_ + 426 progress_angle_ = (progress_angle_ +
427 download_util::kUnknownIncrementDegrees) % 427 download_util::kUnknownIncrementDegrees) %
428 download_util::kMaxDegrees; 428 download_util::kMaxDegrees;
429 gtk_widget_queue_draw(progress_area_.get()); 429 gtk_widget_queue_draw(progress_area_.get());
430 } 430 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 l10n_util::GetStringUTF16(IDS_PROMPT_UNSAFE_DOWNLOAD_URL); 566 l10n_util::GetStringUTF16(IDS_PROMPT_UNSAFE_DOWNLOAD_URL);
567 } else { 567 } else {
568 // It's a dangerous file type (e.g.: an executable). 568 // It's a dangerous file type (e.g.: an executable).
569 DCHECK(get_download()->GetDangerType() == 569 DCHECK(get_download()->GetDangerType() ==
570 DownloadStateInfo::DANGEROUS_FILE); 570 DownloadStateInfo::DANGEROUS_FILE);
571 if (ChromeDownloadManagerDelegate::IsExtensionDownload(get_download())) { 571 if (ChromeDownloadManagerDelegate::IsExtensionDownload(get_download())) {
572 dangerous_warning = 572 dangerous_warning =
573 l10n_util::GetStringUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); 573 l10n_util::GetStringUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION);
574 } else { 574 } else {
575 string16 elided_filename = ui::ElideFilename( 575 string16 elided_filename = ui::ElideFilename(
576 get_download()->target_name(), gfx::Font(), kTextWidth); 576 get_download()->GetTargetName(), gfx::Font(), kTextWidth);
577 dangerous_warning = 577 dangerous_warning =
578 l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD, 578 l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD,
579 elided_filename); 579 elided_filename);
580 } 580 }
581 } 581 }
582 582
583 if (theme_service_->UsingNativeTheme()) { 583 if (theme_service_->UsingNativeTheme()) {
584 gtk_util::SetLabelColor(dangerous_label_, NULL); 584 gtk_util::SetLabelColor(dangerous_label_, NULL);
585 } else { 585 } else {
586 GdkColor color = theme_service_->GetGdkColor( 586 GdkColor color = theme_service_->GetGdkColor(
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 get_download()->DangerousDownloadValidated(); 884 get_download()->DangerousDownloadValidated();
885 } 885 }
886 886
887 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { 887 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) {
888 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", 888 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download",
889 base::Time::Now() - creation_time_); 889 base::Time::Now() - creation_time_);
890 if (get_download()->IsPartialDownload()) 890 if (get_download()->IsPartialDownload())
891 get_download()->Cancel(true); 891 get_download()->Cancel(true);
892 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 892 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
893 } 893 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/custom_drag.cc ('k') | chrome/browser/ui/gtk/download/download_shelf_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698