OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/options/advanced_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/advanced_options_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_util.h" |
| 13 #include "base/path_service.h" |
12 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 15 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/download/download_manager.h" | 17 #include "chrome/browser/download/download_manager.h" |
16 #include "chrome/browser/download/download_prefs.h" | 18 #include "chrome/browser/download/download_prefs.h" |
17 #include "chrome/browser/google/google_util.h" | 19 #include "chrome/browser/google/google_util.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 21 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
20 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | 22 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
21 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 23 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
22 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/service/service_process_control.h" | 25 #include "chrome/browser/service/service_process_control.h" |
24 #include "chrome/browser/ui/options/options_util.h" | 26 #include "chrome/browser/ui/options/options_util.h" |
25 #include "chrome/browser/ui/webui/options/options_managed_banner_handler.h" | 27 #include "chrome/browser/ui/webui/options/options_managed_banner_handler.h" |
| 28 #include "chrome/common/chrome_paths.h" |
26 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
29 #include "content/browser/tab_contents/tab_contents.h" | 32 #include "content/browser/tab_contents/tab_contents.h" |
30 #include "content/browser/tab_contents/tab_contents_view.h" | 33 #include "content/browser/tab_contents/tab_contents_view.h" |
31 #include "content/browser/user_metrics.h" | 34 #include "content/browser/user_metrics.h" |
32 #include "content/common/notification_details.h" | 35 #include "content/common/notification_details.h" |
33 #include "content/common/notification_type.h" | 36 #include "content/common/notification_type.h" |
34 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
35 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 google_util::AppendGoogleLocaleParam( | 180 google_util::AppendGoogleLocaleParam( |
178 GURL(chrome::kPrivacyLearnMoreURL)).spec()); | 181 GURL(chrome::kPrivacyLearnMoreURL)).spec()); |
179 } | 182 } |
180 | 183 |
181 void AdvancedOptionsHandler::Initialize() { | 184 void AdvancedOptionsHandler::Initialize() { |
182 DCHECK(web_ui_); | 185 DCHECK(web_ui_); |
183 SetupMetricsReportingCheckbox(); | 186 SetupMetricsReportingCheckbox(); |
184 SetupMetricsReportingSettingVisibility(); | 187 SetupMetricsReportingSettingVisibility(); |
185 SetupFontSizeLabel(); | 188 SetupFontSizeLabel(); |
186 SetupDownloadLocationPath(); | 189 SetupDownloadLocationPath(); |
| 190 download_path_checker_ = new DownloadPathChecker(this); |
| 191 download_path_checker_->CheckIfDownloadPathExists( |
| 192 default_download_location_.GetValue()); |
187 SetupPromptForDownload(); | 193 SetupPromptForDownload(); |
188 SetupAutoOpenFileTypesDisabledAttribute(); | 194 SetupAutoOpenFileTypesDisabledAttribute(); |
189 SetupProxySettingsSection(); | 195 SetupProxySettingsSection(); |
190 SetupSSLConfigSettings(); | 196 SetupSSLConfigSettings(); |
191 #if !defined(OS_CHROMEOS) | 197 #if !defined(OS_CHROMEOS) |
192 if (cloud_print_proxy_ui_enabled_) { | 198 if (cloud_print_proxy_ui_enabled_) { |
193 SetupCloudPrintProxySection(); | 199 SetupCloudPrintProxySection(); |
194 RefreshCloudPrintStatusFromService(); | 200 RefreshCloudPrintStatusFromService(); |
195 } else { | 201 } else { |
196 RemoveCloudPrintProxySection(); | 202 RemoveCloudPrintProxySection(); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 web_ui_->CallJavascriptFunction( | 638 web_ui_->CallJavascriptFunction( |
633 "options.AdvancedOptions.SetUseSSL3CheckboxState", checked, disabled); | 639 "options.AdvancedOptions.SetUseSSL3CheckboxState", checked, disabled); |
634 } | 640 } |
635 { | 641 { |
636 FundamentalValue checked(tls1_enabled_.GetValue()); | 642 FundamentalValue checked(tls1_enabled_.GetValue()); |
637 FundamentalValue disabled(tls1_enabled_.IsManaged()); | 643 FundamentalValue disabled(tls1_enabled_.IsManaged()); |
638 web_ui_->CallJavascriptFunction( | 644 web_ui_->CallJavascriptFunction( |
639 "options.AdvancedOptions.SetUseTLS1CheckboxState", checked, disabled); | 645 "options.AdvancedOptions.SetUseTLS1CheckboxState", checked, disabled); |
640 } | 646 } |
641 } | 647 } |
| 648 |
| 649 AdvancedOptionsHandler::DownloadPathChecker::DownloadPathChecker( |
| 650 AdvancedOptionsHandler* handler) |
| 651 : handler_(handler) { |
| 652 } |
| 653 |
| 654 AdvancedOptionsHandler::DownloadPathChecker::~DownloadPathChecker() { |
| 655 } |
| 656 |
| 657 void AdvancedOptionsHandler::DownloadPathChecker:: |
| 658 CheckIfDownloadPathExists(const FilePath& path) { |
| 659 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 660 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 661 NewRunnableMethod(this, |
| 662 &DownloadPathChecker::CheckIfDownloadPathExistsOnFileThread, path)); |
| 663 } |
| 664 |
| 665 void AdvancedOptionsHandler::DownloadPathChecker:: |
| 666 CheckIfDownloadPathExistsOnFileThread( |
| 667 const FilePath& path) { |
| 668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 669 if (!file_util::PathExists(path)) { |
| 670 FilePath new_path; |
| 671 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &new_path)) { |
| 672 // Create the |path| folder if we cannot get DIR_DEFAULT_DOWNLOADS |
| 673 // (This will be a rare case). |
| 674 new_path = path; |
| 675 } |
| 676 // Make sure that the folder does exist. |
| 677 if (!file_util::CreateDirectory(new_path)) |
| 678 LOG(ERROR) << "Failed to create " << new_path.value(); |
| 679 |
| 680 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 681 NewRunnableMethod(this, |
| 682 &DownloadPathChecker::OnDownloadPathChanged, new_path)); |
| 683 } |
| 684 } |
| 685 |
| 686 void AdvancedOptionsHandler::DownloadPathChecker:: |
| 687 OnDownloadPathChanged(const FilePath path) { |
| 688 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 689 if (handler_) { |
| 690 handler_->default_download_location_.SetValue(path); |
| 691 handler_->SetupDownloadLocationPath(); |
| 692 } |
| 693 } |
OLD | NEW |