diff options
author | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 18:39:07 +0000 |
---|---|---|
committer | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 18:39:07 +0000 |
commit | 06e91fa2cac43d84bc9bd08af2b38297ffb70cff (patch) | |
tree | f9fe1aa2e39efef4a407933380ba6b4d0d8fa25e /chrome | |
parent | c257caf62e5b2bcb0f59300b9a6dfd2e1316532c (diff) | |
download | chromium_src-06e91fa2cac43d84bc9bd08af2b38297ffb70cff.zip chromium_src-06e91fa2cac43d84bc9bd08af2b38297ffb70cff.tar.gz chromium_src-06e91fa2cac43d84bc9bd08af2b38297ffb70cff.tar.bz2 |
Removed custom code handling the Download prefs in the prefs UI.
Replaced with the "pref" attribute, which correctly follows values set by
policy and also triggers the "managed by your admin" banner. Most of the code
was dealing with preference combinations that are already handled by the policy
code.
BUG=95470
TEST=Set the download location policy or disable file dialogs policy. The UI elements in the preferences are correctly updated and/or disabled.
Review URL: http://codereview.chromium.org/7889037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101337 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 14 insertions, 88 deletions
diff --git a/chrome/browser/resources/options/advanced_options.html b/chrome/browser/resources/options/advanced_options.html index 5ba0ab2..4e05875 100644 --- a/chrome/browser/resources/options/advanced_options.html +++ b/chrome/browser/resources/options/advanced_options.html @@ -157,17 +157,19 @@ <div id="download-location-group"> <label> <span i18n-content="downloadLocationBrowseTitle"></span> - <input id="downloadLocationPath" class="weakrtl" type="text" size="36" disabled> + <input id="downloadLocationPath" class="weakrtl" type="text" + pref="download.default_directory" size="36"> </label> <button id="downloadLocationChangeButton" + pref="download.prompt_for_download" i18n-content="downloadLocationChangeButton"></button> </div> <div class="checkbox"> <label> - <input id="promptForDownload" metric="Options_AskForSaveLocation" - type="checkbox"> - <span id="promptForDownloadLabel" - i18n-content="downloadLocationAskForSaveLocation"></span> + <input id="promptForDownload" type="checkbox" + pref="download.prompt_for_download" + metric="Options_AskForSaveLocation"> + <span i18n-content="downloadLocationAskForSaveLocation"></span> </label> </div> <div id="auto-open-file-types-label" diff --git a/chrome/browser/resources/options/advanced_options.js b/chrome/browser/resources/options/advanced_options.js index 7a94e19..d3bfbc6 100644 --- a/chrome/browser/resources/options/advanced_options.js +++ b/chrome/browser/resources/options/advanced_options.js @@ -88,10 +88,10 @@ var OptionsPage = options.OptionsPage; $('downloadLocationChangeButton').onclick = function(event) { chrome.send('selectDownloadLocation'); }; - $('promptForDownload').onclick = function(event) { - chrome.send('promptForDownloadAction', - [String($('promptForDownload').checked)]); - }; + // This text field is always disabled. Setting ".disabled = true" isn't + // enough, since a policy can disable it but shouldn't re-enable when + // it is removed. + $('downloadLocationPath').setDisabled('readonly', true); } $('sslCheckRevocation').onclick = function(event) { @@ -171,26 +171,6 @@ var OptionsPage = options.OptionsPage; $('Custom').selected = true; }; - // Set the download path. - AdvancedOptions.SetDownloadLocationPath = function(path, disabled) { - if (!cr.isChromeOS) { - $('downloadLocationPath').value = path; - $('downloadLocationChangeButton').disabled = disabled; - } - }; - - // Set the prompt for download checkbox. - AdvancedOptions.SetPromptForDownload = function(checked, disabled) { - if (!cr.isChromeOS) { - $('promptForDownload').checked = checked; - $('promptForDownload').disabled = disabled; - if (disabled) - $('promptForDownloadLabel').className = 'informational-text'; - else - $('promptForDownloadLabel').className = ''; - } - }; - // Set the enabled state for the autoOpenFileTypesResetToDefault button. AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute = function(disabled) { if (!cr.isChromeOS) { diff --git a/chrome/browser/ui/webui/options/advanced_options_handler.cc b/chrome/browser/ui/webui/options/advanced_options_handler.cc index 8ee8129..bb1a745 100644 --- a/chrome/browser/ui/webui/options/advanced_options_handler.cc +++ b/chrome/browser/ui/webui/options/advanced_options_handler.cc @@ -201,8 +201,6 @@ void AdvancedOptionsHandler::Initialize() { SetupMetricsReportingCheckbox(); SetupMetricsReportingSettingVisibility(); SetupFontSizeLabel(); - SetupDownloadLocationPath(); - SetupPromptForDownload(); SetupAutoOpenFileTypesDisabledAttribute(); SetupProxySettingsSection(); SetupSSLConfigSettings(); @@ -244,11 +242,6 @@ WebUIMessageHandler* AdvancedOptionsHandler::Attach(WebUI* web_ui) { this); #endif - default_download_location_.Init(prefs::kDownloadDefaultDirectory, - prefs, this); - ask_for_save_location_.Init(prefs::kPromptForDownload, prefs, this); - allow_file_selection_dialogs_.Init(prefs::kAllowFileSelectionDialogs, - g_browser_process->local_state(), this); auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, prefs, this); default_font_size_.Init(prefs::kWebKitDefaultFontSize, prefs, this); proxy_prefs_.reset( @@ -264,9 +257,6 @@ void AdvancedOptionsHandler::RegisterMessages() { web_ui_->RegisterMessageCallback("selectDownloadLocation", NewCallback(this, &AdvancedOptionsHandler::HandleSelectDownloadLocation)); - web_ui_->RegisterMessageCallback("promptForDownloadAction", - NewCallback(this, - &AdvancedOptionsHandler::HandlePromptForDownload)); web_ui_->RegisterMessageCallback("autoOpenFileTypesAction", NewCallback(this, &AdvancedOptionsHandler::HandleAutoOpenButton)); @@ -313,12 +303,7 @@ void AdvancedOptionsHandler::Observe(int type, const NotificationDetails& details) { if (type == chrome::NOTIFICATION_PREF_CHANGED) { std::string* pref_name = Details<std::string>(details).ptr(); - if ((*pref_name == prefs::kDownloadDefaultDirectory) || - (*pref_name == prefs::kPromptForDownload) || - (*pref_name == prefs::kAllowFileSelectionDialogs)) { - SetupDownloadLocationPath(); - SetupPromptForDownload(); - } else if (*pref_name == prefs::kDownloadExtensionsToOpen) { + if (*pref_name == prefs::kDownloadExtensionsToOpen) { SetupAutoOpenFileTypesDisabledAttribute(); } else if (proxy_prefs_->IsObserved(*pref_name)) { SetupProxySettingsSection(); @@ -350,17 +335,11 @@ void AdvancedOptionsHandler::HandleSelectDownloadLocation( web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); } -void AdvancedOptionsHandler::HandlePromptForDownload( - const ListValue* args) { - std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); - ask_for_save_location_.SetValue(checked_str == "true"); -} - void AdvancedOptionsHandler::FileSelected(const FilePath& path, int index, void* params) { UserMetrics::RecordAction(UserMetricsAction("Options_SetDownloadDirectory")); - default_download_location_.SetValue(path); - SetupDownloadLocationPath(); + PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); + pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path); } void AdvancedOptionsHandler::OnCloudPrintSetupClosed() { @@ -552,28 +531,6 @@ void AdvancedOptionsHandler::SetupFontSizeLabel() { "options.AdvancedOptions.SetFontSize", font_size); } -void AdvancedOptionsHandler::SetupDownloadLocationPath() { - StringValue value(default_download_location_.GetValue().value()); - // In case allow_file_selection_dialogs_ is false, we will not display any - // file-selection dialogs but show an InfoBar. That is why we can disable - // the DownloadLocationPath-Chooser right-away. - base::FundamentalValue disabled(default_download_location_.IsManaged() || - !allow_file_selection_dialogs_.GetValue()); - web_ui_->CallJavascriptFunction( - "options.AdvancedOptions.SetDownloadLocationPath", value, disabled); -} - -void AdvancedOptionsHandler::SetupPromptForDownload() { - base::FundamentalValue checked(ask_for_save_location_.GetValue()); - // If either the DownloadDirectory is managed or if file-selection dialogs are - // disallowed then |ask_for_save_location_| must currently be false and cannot - // be changed. - base::FundamentalValue disabled(default_download_location_.IsManaged() || - !allow_file_selection_dialogs_.GetValue()); - web_ui_->CallJavascriptFunction( - "options.AdvancedOptions.SetPromptForDownload", checked, disabled); -} - void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() { // Set the enabled state for the AutoOpenFileTypesResetToDefault button. // We enable the button if the user has any auto-open file types registered. diff --git a/chrome/browser/ui/webui/options/advanced_options_handler.h b/chrome/browser/ui/webui/options/advanced_options_handler.h index be36630..8b8b853 100644 --- a/chrome/browser/ui/webui/options/advanced_options_handler.h +++ b/chrome/browser/ui/webui/options/advanced_options_handler.h @@ -47,10 +47,6 @@ class AdvancedOptionsHandler // the user for a destination folder using platform-specific APIs. void HandleSelectDownloadLocation(const ListValue* args); - // Callback for the "promptForDownloadAction" message. This will set - // the ask for save location pref accordingly. - void HandlePromptForDownload(const ListValue* args); - // Callback for the "autoOpenFileTypesResetToDefault" message. This will // remove all auto-open file-type settings. void HandleAutoOpenButton(const ListValue* args); @@ -132,12 +128,6 @@ class AdvancedOptionsHandler void SetupFontSizeLabel(); - // Setup the download path based on user preferences. - void SetupDownloadLocationPath(); - - // Setup the pref whether to prompt for download location every time. - void SetupPromptForDownload(); - // Setup the enabled state of the reset button. void SetupAutoOpenFileTypesDisabledAttribute(); @@ -164,9 +154,6 @@ class AdvancedOptionsHandler BooleanPrefMember background_mode_enabled_; #endif - FilePathPrefMember default_download_location_; - BooleanPrefMember ask_for_save_location_; - BooleanPrefMember allow_file_selection_dialogs_; StringPrefMember auto_open_files_; IntegerPrefMember default_font_size_; scoped_ptr<PrefSetObserver> proxy_prefs_; |