Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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/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 DownloadOverwriteInfoBarDelegate::~DownloadOverwriteInfoBarDelegate() { | |
| 22 } | |
| 23 | |
| 24 // static | |
| 25 infobars::InfoBar* DownloadOverwriteInfoBarDelegate::Create( | |
| 26 content::DownloadItem* download, | |
| 27 const base::FilePath& suggested_path, | |
| 28 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { | |
| 29 if (!download) | |
| 30 return NULL; | |
| 31 content::WebContents* web_contents = download->GetWebContents(); | |
| 32 if (!web_contents) | |
| 33 return NULL; | |
| 34 | |
| 35 InfoBarService* infobar_service = | |
| 36 InfoBarService::FromWebContents(web_contents); | |
| 37 | |
| 38 scoped_ptr<infobars::InfoBar> infobar = | |
| 39 DownloadOverwriteInfoBar::CreateInfoBar( | |
| 40 make_scoped_ptr(new DownloadOverwriteInfoBarDelegate( | |
| 41 download, suggested_path, callback))); | |
| 42 return infobar_service->AddInfoBar(infobar.Pass()); | |
| 43 } | |
| 44 | |
| 45 bool DownloadOverwriteInfoBarDelegate::AcceptOverwrite() { | |
| 46 file_selected_callback_.Run(suggested_download_path_); | |
| 47 return true; | |
| 48 } | |
| 49 | |
| 50 bool DownloadOverwriteInfoBarDelegate::CancelDownload() { | |
| 51 file_selected_callback_.Run(base::FilePath()); | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 DownloadOverwriteInfoBarDelegate::DownloadOverwriteInfoBarDelegate( | |
|
Ted C
2014/10/27 15:30:11
this doesn't match the header order, the GetFileNa
Changwan Ryu
2014/10/28 04:59:44
Done.
| |
| 56 content::DownloadItem* download, | |
| 57 const base::FilePath& suggested_download_path, | |
| 58 const DownloadTargetDeterminerDelegate::FileSelectedCallback& | |
| 59 file_selected_callback) | |
| 60 : suggested_download_path_(suggested_download_path), | |
| 61 file_selected_callback_(file_selected_callback) { | |
| 62 } | |
| 63 | |
| 64 std::string DownloadOverwriteInfoBarDelegate::GetFileName() const { | |
| 65 return suggested_download_path_.BaseName().value(); | |
| 66 } | |
| 67 | |
| 68 std::string DownloadOverwriteInfoBarDelegate::GetDirName() const { | |
| 69 return suggested_download_path_.DirName().BaseName().value(); | |
| 70 } | |
| 71 | |
| 72 std::string DownloadOverwriteInfoBarDelegate::GetDirFullPath() const { | |
| 73 return suggested_download_path_.DirName().value(); | |
| 74 } | |
| 75 | |
| 76 } // namespace android | |
| 77 } // namespace chrome | |
| OLD | NEW |