OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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/android/download_overwrite_infobar_delegate.h" |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" |
| 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/infobars/core/infobar.h" |
| 13 #include "content/public/browser/download_item.h" |
| 14 #include "content/public/browser/web_contents.h" |
| 15 #include "grit/theme_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" |
| 17 |
| 18 namespace chrome { |
| 19 namespace android { |
| 20 |
| 21 // static |
| 22 infobars::InfoBar* DownloadOverwriteInfoBarDelegate::Create( |
| 23 content::DownloadItem* download, |
| 24 const base::FilePath& suggested_path, |
| 25 const FileSelectedCallback& callback) { |
| 26 DCHECK(download); |
| 27 if (!download) |
| 28 return NULL; |
| 29 content::WebContents* web_contents = download->GetWebContents(); |
| 30 if (!web_contents) |
| 31 return NULL; |
| 32 |
| 33 InfoBarService* infobar_service = |
| 34 InfoBarService::FromWebContents(web_contents); |
| 35 |
| 36 DownloadOverwriteInfoBarDelegate* const delegate = |
| 37 new DownloadOverwriteInfoBarDelegate(download, suggested_path, callback); |
| 38 infobars::InfoBar* infobar = DownloadOverwriteInfoBar::CreateInfoBar( |
| 39 scoped_ptr<DownloadOverwriteInfoBarDelegate>(delegate)).release(); |
| 40 return infobar_service->AddInfoBar(scoped_ptr<infobars::InfoBar>(infobar)); |
| 41 } |
| 42 |
| 43 bool DownloadOverwriteInfoBarDelegate::Accept() { |
| 44 callback_.Run(suggested_path_); |
| 45 return true; |
| 46 } |
| 47 |
| 48 bool DownloadOverwriteInfoBarDelegate::Cancel() { |
| 49 callback_.Run(base::FilePath()); |
| 50 return true; |
| 51 } |
| 52 |
| 53 DownloadOverwriteInfoBarDelegate::DownloadOverwriteInfoBarDelegate( |
| 54 content::DownloadItem* download, |
| 55 const base::FilePath& suggested_path, |
| 56 const FileSelectedCallback& callback) : |
| 57 pending_id_(download->GetId()), |
| 58 suggested_path_(suggested_path), |
| 59 callback_(callback) { |
| 60 } |
| 61 |
| 62 DownloadOverwriteInfoBarDelegate::~DownloadOverwriteInfoBarDelegate() { |
| 63 } |
| 64 |
| 65 std::string DownloadOverwriteInfoBarDelegate::GetFileName() const { |
| 66 return suggested_path_.BaseName().value(); |
| 67 } |
| 68 |
| 69 std::string DownloadOverwriteInfoBarDelegate::GetDirName() const { |
| 70 return suggested_path_.DirName().BaseName().value(); |
| 71 } |
| 72 |
| 73 std::string DownloadOverwriteInfoBarDelegate::GetDirFullPath() const { |
| 74 return suggested_path_.DirName().value(); |
| 75 } |
| 76 |
| 77 DownloadOverwriteInfoBarDelegate* |
| 78 DownloadOverwriteInfoBarDelegate::AsDownloadOverwriteInfoBarDelegate() { |
| 79 return this; |
| 80 } |
| 81 |
| 82 } // namespace android |
| 83 } // namespace chrome |
OLD | NEW |