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

Side by Side Diff: trunk/src/chrome/browser/download/download_item_model.cc

Issue 61623006: Revert 233460 "Prefer opening PDF downloads in the browser." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 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) 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_item_model.h" 5 #include "chrome/browser/download/download_item_model.h"
6 6
7 #include "base/i18n/number_formatting.h" 7 #include "base/i18n/number_formatting.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/supports_user_data.h" 13 #include "base/supports_user_data.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/download/chrome_download_manager_delegate.h"
16 #include "chrome/browser/download/download_crx_util.h" 15 #include "chrome/browser/download/download_crx_util.h"
17 #include "chrome/browser/download/download_service.h"
18 #include "chrome/browser/download/download_service_factory.h"
19 #include "chrome/browser/download/download_stats.h"
20 #include "chrome/browser/safe_browsing/download_feedback_service.h" 16 #include "chrome/browser/safe_browsing/download_feedback_service.h"
21 #include "content/public/browser/download_danger_type.h" 17 #include "content/public/browser/download_danger_type.h"
22 #include "content/public/browser/download_interrupt_reasons.h" 18 #include "content/public/browser/download_interrupt_reasons.h"
23 #include "content/public/browser/download_item.h" 19 #include "content/public/browser/download_item.h"
24 #include "grit/chromium_strings.h" 20 #include "grit/chromium_strings.h"
25 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/l10n/time_format.h" 23 #include "ui/base/l10n/time_format.h"
28 #include "ui/base/text/bytes_formatting.h" 24 #include "ui/base/text/bytes_formatting.h"
29 #include "ui/gfx/text_elider.h" 25 #include "ui/gfx/text_elider.h"
(...skipping 19 matching lines...) Expand all
49 bool should_show_in_shelf() const { return should_show_in_shelf_; } 45 bool should_show_in_shelf() const { return should_show_in_shelf_; }
50 void set_should_show_in_shelf(bool should_show_in_shelf) { 46 void set_should_show_in_shelf(bool should_show_in_shelf) {
51 should_show_in_shelf_ = should_show_in_shelf; 47 should_show_in_shelf_ = should_show_in_shelf;
52 } 48 }
53 49
54 bool should_notify_ui() const { return should_notify_ui_; } 50 bool should_notify_ui() const { return should_notify_ui_; }
55 void set_should_notify_ui(bool should_notify_ui) { 51 void set_should_notify_ui(bool should_notify_ui) {
56 should_notify_ui_ = should_notify_ui; 52 should_notify_ui_ = should_notify_ui;
57 } 53 }
58 54
59 bool should_prefer_opening_in_browser() const {
60 return should_prefer_opening_in_browser_;
61 }
62 void set_should_prefer_opening_in_browser(bool preference) {
63 should_prefer_opening_in_browser_ = preference;
64 }
65
66 private: 55 private:
67 DownloadItemModelData(); 56 DownloadItemModelData();
68 virtual ~DownloadItemModelData() {} 57 virtual ~DownloadItemModelData() {}
69 58
70 static const char kKey[]; 59 static const char kKey[];
71 60
72 // Whether the download should be displayed in the download shelf. True by 61 // Whether the download should be displayed in the download shelf. True by
73 // default. 62 // default.
74 bool should_show_in_shelf_; 63 bool should_show_in_shelf_;
75 64
76 // Whether the UI should be notified when the download is ready to be 65 // Whether the UI should be notified when the download is ready to be
77 // presented. 66 // presented.
78 bool should_notify_ui_; 67 bool should_notify_ui_;
79
80 // Whether the download should be opened in the browser vs. the system handler
81 // for the file type.
82 bool should_prefer_opening_in_browser_;
83 }; 68 };
84 69
85 // static 70 // static
86 const char DownloadItemModelData::kKey[] = "DownloadItemModelData key"; 71 const char DownloadItemModelData::kKey[] = "DownloadItemModelData key";
87 72
88 // static 73 // static
89 const DownloadItemModelData* DownloadItemModelData::Get( 74 const DownloadItemModelData* DownloadItemModelData::Get(
90 const DownloadItem* download) { 75 const DownloadItem* download) {
91 return static_cast<const DownloadItemModelData*>(download->GetUserData(kKey)); 76 return static_cast<const DownloadItemModelData*>(download->GetUserData(kKey));
92 } 77 }
93 78
94 // static 79 // static
95 DownloadItemModelData* DownloadItemModelData::GetOrCreate( 80 DownloadItemModelData* DownloadItemModelData::GetOrCreate(
96 DownloadItem* download) { 81 DownloadItem* download) {
97 DownloadItemModelData* data = 82 DownloadItemModelData* data =
98 static_cast<DownloadItemModelData*>(download->GetUserData(kKey)); 83 static_cast<DownloadItemModelData*>(download->GetUserData(kKey));
99 if (data == NULL) { 84 if (data == NULL) {
100 data = new DownloadItemModelData(); 85 data = new DownloadItemModelData();
101 download->SetUserData(kKey, data); 86 download->SetUserData(kKey, data);
102 } 87 }
103 return data; 88 return data;
104 } 89 }
105 90
106 DownloadItemModelData::DownloadItemModelData() 91 DownloadItemModelData::DownloadItemModelData()
107 : should_show_in_shelf_(true), 92 : should_show_in_shelf_(true),
108 should_notify_ui_(false), 93 should_notify_ui_(false) {
109 should_prefer_opening_in_browser_(false) {
110 } 94 }
111 95
112 string16 InterruptReasonStatusMessage(int reason) { 96 string16 InterruptReasonStatusMessage(int reason) {
113 int string_id = 0; 97 int string_id = 0;
114 98
115 switch (reason) { 99 switch (reason) {
116 case content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED: 100 case content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED:
117 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_ACCESS_DENIED; 101 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_ACCESS_DENIED;
118 break; 102 break;
119 case content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE: 103 case content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE:
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 bool DownloadItemModel::ShouldNotifyUI() const { 525 bool DownloadItemModel::ShouldNotifyUI() const {
542 const DownloadItemModelData* data = DownloadItemModelData::Get(download_); 526 const DownloadItemModelData* data = DownloadItemModelData::Get(download_);
543 return data && data->should_notify_ui(); 527 return data && data->should_notify_ui();
544 } 528 }
545 529
546 void DownloadItemModel::SetShouldNotifyUI(bool should_notify) { 530 void DownloadItemModel::SetShouldNotifyUI(bool should_notify) {
547 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_); 531 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_);
548 data->set_should_notify_ui(should_notify); 532 data->set_should_notify_ui(should_notify);
549 } 533 }
550 534
551 bool DownloadItemModel::ShouldPreferOpeningInBrowser() const {
552 const DownloadItemModelData* data = DownloadItemModelData::Get(download_);
553 return data && data->should_prefer_opening_in_browser();
554 }
555
556 void DownloadItemModel::SetShouldPreferOpeningInBrowser(bool preference) {
557 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_);
558 data->set_should_prefer_opening_in_browser(preference);
559 }
560
561 string16 DownloadItemModel::GetProgressSizesString() const { 535 string16 DownloadItemModel::GetProgressSizesString() const {
562 string16 size_ratio; 536 string16 size_ratio;
563 int64 size = GetCompletedBytes(); 537 int64 size = GetCompletedBytes();
564 int64 total = GetTotalBytes(); 538 int64 total = GetTotalBytes();
565 if (total > 0) { 539 if (total > 0) {
566 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total); 540 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total);
567 string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, false); 541 string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, false);
568 542
569 // In RTL locales, we render the text "size/total" in an RTL context. This 543 // In RTL locales, we render the text "size/total" in an RTL context. This
570 // is problematic since a string such as "123/456 MB" is displayed 544 // is problematic since a string such as "123/456 MB" is displayed
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 } 598 }
625 599
626 // In progress download with no known time left and non-zero completed bytes: 600 // In progress download with no known time left and non-zero completed bytes:
627 // "100/120 MB" or "100 MB" 601 // "100/120 MB" or "100 MB"
628 if (GetCompletedBytes() > 0) 602 if (GetCompletedBytes() > 0)
629 return size_ratio; 603 return size_ratio;
630 604
631 // Instead of displaying "0 B" we say "Starting..." 605 // Instead of displaying "0 B" we say "Starting..."
632 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); 606 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING);
633 } 607 }
634
635 void DownloadItemModel::OpenUsingPlatformHandler() {
636 DownloadService* download_service =
637 DownloadServiceFactory::GetForBrowserContext(
638 download_->GetBrowserContext());
639 if (!download_service)
640 return;
641
642 ChromeDownloadManagerDelegate* delegate =
643 download_service->GetDownloadManagerDelegate();
644 if (!delegate)
645 return;
646 delegate->OpenDownloadUsingPlatformHandler(download_);
647 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM);
648 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698