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

Unified Diff: chrome/browser/download/download_item_model.cc

Issue 55063002: Prefer opening PDF downloads in the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reorganize some code to address comments. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_item_model.cc
diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc
index 2913b0e2d3c1be7e20a88c9ca49ed96a5caaaf6b..7b360b8559f93d5d299abca5c561a9ae3a0aa298 100644
--- a/chrome/browser/download/download_item_model.cc
+++ b/chrome/browser/download/download_item_model.cc
@@ -12,7 +12,10 @@
#include "base/strings/utf_string_conversions.h"
#include "base/supports_user_data.h"
#include "base/time/time.h"
+#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_crx_util.h"
+#include "chrome/browser/download/download_service.h"
+#include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/safe_browsing/download_feedback_service.h"
#include "content/public/browser/download_danger_type.h"
#include "content/public/browser/download_interrupt_reasons.h"
@@ -52,6 +55,13 @@ class DownloadItemModelData : public base::SupportsUserData::Data {
should_notify_ui_ = should_notify_ui;
}
+ bool should_prefer_opening_in_browser() const {
+ return should_prefer_opening_in_browser_;
+ }
+ void set_should_prefer_opening_in_browser(bool preference) {
+ should_prefer_opening_in_browser_ = preference;
+ }
+
private:
DownloadItemModelData();
virtual ~DownloadItemModelData() {}
@@ -65,6 +75,10 @@ class DownloadItemModelData : public base::SupportsUserData::Data {
// Whether the UI should be notified when the download is ready to be
// presented.
bool should_notify_ui_;
+
+ // Whether the download should be opened in the browser vs. the system handler
+ // for the file type.
+ bool should_prefer_opening_in_browser_;
};
// static
@@ -90,7 +104,8 @@ DownloadItemModelData* DownloadItemModelData::GetOrCreate(
DownloadItemModelData::DownloadItemModelData()
: should_show_in_shelf_(true),
- should_notify_ui_(false) {
+ should_notify_ui_(false),
+ should_prefer_opening_in_browser_(false) {
}
string16 InterruptReasonStatusMessage(int reason) {
@@ -532,6 +547,16 @@ void DownloadItemModel::SetShouldNotifyUI(bool should_notify) {
data->set_should_notify_ui(should_notify);
}
+bool DownloadItemModel::ShouldPreferOpeningInBrowser() const {
+ const DownloadItemModelData* data = DownloadItemModelData::Get(download_);
+ return data && data->should_prefer_opening_in_browser();
+}
+
+void DownloadItemModel::SetShouldPreferOpeningInBrowser(bool preference) {
+ DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_);
+ data->set_should_prefer_opening_in_browser(preference);
+}
+
string16 DownloadItemModel::GetProgressSizesString() const {
string16 size_ratio;
int64 size = GetCompletedBytes();
@@ -605,3 +630,17 @@ string16 DownloadItemModel::GetInProgressStatusString() const {
// Instead of displaying "0 B" we say "Starting..."
return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING);
}
+
+void DownloadItemModel::OpenUsingPlatformHandler() {
+ DownloadService* download_service =
+ DownloadServiceFactory::GetForBrowserContext(
+ download_->GetBrowserContext());
+ if (!download_service)
+ return;
+
+ ChromeDownloadManagerDelegate* delegate =
+ download_service->GetDownloadManagerDelegate();
+ if (!delegate)
+ return;
+ delegate->OpenDownloadUsingPlatformHandler(download_);
+}

Powered by Google App Engine
This is Rietveld 408576698