Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/ui/webui/settings/downloads_handler.h" | 5 #include "chrome/browser/ui/webui/settings/downloads_handler.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/download/download_prefs.h" | 8 #include "chrome/browser/download/download_prefs.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/chrome_select_file_policy.h" | 10 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 DownloadsHandler::~DownloadsHandler() { | 27 DownloadsHandler::~DownloadsHandler() { |
| 28 // There may be pending file dialogs, we need to tell them that we've gone | 28 // There may be pending file dialogs, we need to tell them that we've gone |
| 29 // away so they don't try and call back to us. | 29 // away so they don't try and call back to us. |
| 30 if (select_folder_dialog_.get()) | 30 if (select_folder_dialog_.get()) |
| 31 select_folder_dialog_->ListenerDestroyed(); | 31 select_folder_dialog_->ListenerDestroyed(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void DownloadsHandler::RegisterMessages() { | 34 void DownloadsHandler::RegisterMessages() { |
| 35 web_ui()->RegisterMessageCallback( | 35 web_ui()->RegisterMessageCallback( |
| 36 "initializeDownloads", | 36 "initializeDownloads", |
|
Dan Beam
2017/02/27 05:50:36
where is this already called? was this just unuse
tommycli
2017/02/28 00:47:26
Yes, added in the previous CL, used in this CL for
| |
| 37 base::Bind(&DownloadsHandler::HandleInitialize, base::Unretained(this))); | 37 base::Bind(&DownloadsHandler::HandleInitialize, base::Unretained(this))); |
| 38 web_ui()->RegisterMessageCallback( | 38 web_ui()->RegisterMessageCallback( |
| 39 "resetAutoOpenFileTypes", | |
| 40 base::Bind(&DownloadsHandler::HandleResetAutoOpenFileTypes, | |
| 41 base::Unretained(this))); | |
| 42 web_ui()->RegisterMessageCallback( | |
| 39 "selectDownloadLocation", | 43 "selectDownloadLocation", |
| 40 base::Bind(&DownloadsHandler::HandleSelectDownloadLocation, | 44 base::Bind(&DownloadsHandler::HandleSelectDownloadLocation, |
| 41 base::Unretained(this))); | 45 base::Unretained(this))); |
| 42 } | 46 } |
| 43 | 47 |
| 44 void DownloadsHandler::OnJavascriptAllowed() { | 48 void DownloadsHandler::OnJavascriptAllowed() { |
| 45 pref_registrar_.Init(profile_->GetPrefs()); | 49 pref_registrar_.Init(profile_->GetPrefs()); |
| 46 pref_registrar_.Add( | 50 pref_registrar_.Add( |
| 47 prefs::kDownloadExtensionsToOpen, | 51 prefs::kDownloadExtensionsToOpen, |
| 48 base::Bind(&DownloadsHandler::SendAutoOpenDownloadsToJavascript, | 52 base::Bind(&DownloadsHandler::SendAutoOpenDownloadsToJavascript, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 61 void DownloadsHandler::SendAutoOpenDownloadsToJavascript() { | 65 void DownloadsHandler::SendAutoOpenDownloadsToJavascript() { |
| 62 content::DownloadManager* manager = | 66 content::DownloadManager* manager = |
| 63 content::BrowserContext::GetDownloadManager(profile_); | 67 content::BrowserContext::GetDownloadManager(profile_); |
| 64 bool auto_open_downloads = | 68 bool auto_open_downloads = |
| 65 manager && DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed(); | 69 manager && DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed(); |
| 66 CallJavascriptFunction("cr.webUIListenerCallback", | 70 CallJavascriptFunction("cr.webUIListenerCallback", |
| 67 base::StringValue("auto-open-downloads-changed"), | 71 base::StringValue("auto-open-downloads-changed"), |
| 68 base::FundamentalValue(auto_open_downloads)); | 72 base::FundamentalValue(auto_open_downloads)); |
| 69 } | 73 } |
| 70 | 74 |
| 75 void DownloadsHandler::HandleResetAutoOpenFileTypes( | |
| 76 const base::ListValue* args) { | |
| 77 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); | |
| 78 content::DownloadManager* manager = | |
| 79 content::BrowserContext::GetDownloadManager(profile_); | |
| 80 if (manager) | |
| 81 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); | |
| 82 } | |
| 83 | |
| 71 void DownloadsHandler::HandleSelectDownloadLocation( | 84 void DownloadsHandler::HandleSelectDownloadLocation( |
| 72 const base::ListValue* args) { | 85 const base::ListValue* args) { |
| 73 PrefService* pref_service = profile_->GetPrefs(); | 86 PrefService* pref_service = profile_->GetPrefs(); |
| 74 select_folder_dialog_ = ui::SelectFileDialog::Create( | 87 select_folder_dialog_ = ui::SelectFileDialog::Create( |
| 75 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | 88 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); |
| 76 ui::SelectFileDialog::FileTypeInfo info; | 89 ui::SelectFileDialog::FileTypeInfo info; |
| 77 info.allowed_paths = ui::SelectFileDialog::FileTypeInfo::NATIVE_OR_DRIVE_PATH; | 90 info.allowed_paths = ui::SelectFileDialog::FileTypeInfo::NATIVE_OR_DRIVE_PATH; |
| 78 select_folder_dialog_->SelectFile( | 91 select_folder_dialog_->SelectFile( |
| 79 ui::SelectFileDialog::SELECT_FOLDER, | 92 ui::SelectFileDialog::SELECT_FOLDER, |
| 80 l10n_util::GetStringUTF16(IDS_SETTINGS_DOWNLOAD_LOCATION), | 93 l10n_util::GetStringUTF16(IDS_SETTINGS_DOWNLOAD_LOCATION), |
| 81 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), &info, 0, | 94 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), &info, 0, |
| 82 base::FilePath::StringType(), | 95 base::FilePath::StringType(), |
| 83 web_ui()->GetWebContents()->GetTopLevelNativeWindow(), NULL); | 96 web_ui()->GetWebContents()->GetTopLevelNativeWindow(), NULL); |
| 84 } | 97 } |
| 85 | 98 |
| 86 void DownloadsHandler::FileSelected(const base::FilePath& path, | 99 void DownloadsHandler::FileSelected(const base::FilePath& path, |
| 87 int index, | 100 int index, |
| 88 void* params) { | 101 void* params) { |
| 89 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory")); | 102 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory")); |
| 90 PrefService* pref_service = profile_->GetPrefs(); | 103 PrefService* pref_service = profile_->GetPrefs(); |
| 91 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path); | 104 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path); |
| 92 pref_service->SetFilePath(prefs::kSaveFileDefaultDirectory, path); | 105 pref_service->SetFilePath(prefs::kSaveFileDefaultDirectory, path); |
| 93 } | 106 } |
| 94 | 107 |
| 95 } // namespace settings | 108 } // namespace settings |
| OLD | NEW |