• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/download/download_permission_request.h"
6 
7 #include "content/public/browser/web_contents.h"
8 #include "grit/generated_resources.h"
9 #include "grit/theme_resources.h"
10 #include "ui/base/l10n/l10n_util.h"
11 
DownloadPermissionRequest(base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host)12 DownloadPermissionRequest::DownloadPermissionRequest(
13     base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host)
14     : host_(host) {}
15 
~DownloadPermissionRequest()16 DownloadPermissionRequest::~DownloadPermissionRequest() {}
17 
GetIconID() const18 int DownloadPermissionRequest::GetIconID() const {
19   return IDR_INFOBAR_MULTIPLE_DOWNLOADS;
20 }
21 
GetMessageText() const22 base::string16 DownloadPermissionRequest::GetMessageText() const {
23   return l10n_util::GetStringUTF16(IDS_MULTI_DOWNLOAD_WARNING);
24 }
25 
GetMessageTextFragment() const26 base::string16 DownloadPermissionRequest::GetMessageTextFragment() const {
27   return l10n_util::GetStringUTF16(IDS_MULTI_DOWNLOAD_PERMISSION_FRAGMENT);
28 }
29 
HasUserGesture() const30 bool DownloadPermissionRequest::HasUserGesture() const {
31   // TODO(gbillock): user gesture for multiple downloads is difficult to
32   // propagate, and the normal thing is that it is background.
33   return false;
34 }
35 
GetRequestingHostname() const36 GURL DownloadPermissionRequest::GetRequestingHostname() const {
37   const content::WebContents* web_contents = host_->web_contents();
38   if (web_contents) {
39     return web_contents->GetURL();
40   }
41   return GURL();
42 }
43 
PermissionGranted()44 void DownloadPermissionRequest::PermissionGranted() {
45   if (host_) {
46     // This may invalidate |host_|.
47     host_->Accept();
48   }
49 }
50 
PermissionDenied()51 void DownloadPermissionRequest::PermissionDenied() {
52   if (host_) {
53     // This may invalidate |host_|.
54     host_->Cancel();
55   }
56 }
57 
Cancelled()58 void DownloadPermissionRequest::Cancelled() {
59   // TODO(gbillock): There's currently no suitable method for telling the host
60   // that a request is cancelled.
61 }
62 
RequestFinished()63 void DownloadPermissionRequest::RequestFinished() {
64   delete this;
65 }
66