diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-27 22:19:31 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-27 22:19:31 +0000 |
commit | b713fa5924ad131e13dc3dd148e1a3cb2eaed010 (patch) | |
tree | f988ba95569adc3957171ebbac84591c9fe0803c | |
parent | 0aa5831f558db13af78725f99d11ebce12f27e91 (diff) | |
download | chromium_src-b713fa5924ad131e13dc3dd148e1a3cb2eaed010.zip chromium_src-b713fa5924ad131e13dc3dd148e1a3cb2eaed010.tar.gz chromium_src-b713fa5924ad131e13dc3dd148e1a3cb2eaed010.tar.bz2 |
Revert 53849 - Implement most of the startup page controls in DOMUI prefs
Hooks up display of startup pages, removal of pages, and setting the startup pages to the currently open tabs.
Uses a select for now, but will eventually be replaced with a List so the favicons can be displayed.
BUG=48713
TEST=Startup pages can be viewed, removed, and set to current in DOMUI prefs.
Review URL: http://codereview.chromium.org/3046025
TBR=stuartmorgan@chromium.org
Review URL: http://codereview.chromium.org/3058018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53857 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/custom_home_pages_table_model.cc | 5 | ||||
-rw-r--r-- | chrome/browser/dom_ui/browser_options_handler.cc | 105 | ||||
-rw-r--r-- | chrome/browser/dom_ui/browser_options_handler.h | 32 | ||||
-rw-r--r-- | chrome/browser/resources/options/browser_options.html | 4 | ||||
-rw-r--r-- | chrome/browser/resources/options/browser_options.js | 71 |
5 files changed, 19 insertions, 198 deletions
diff --git a/chrome/browser/custom_home_pages_table_model.cc b/chrome/browser/custom_home_pages_table_model.cc index 2f2f38f..446aea5 100644 --- a/chrome/browser/custom_home_pages_table_model.cc +++ b/chrome/browser/custom_home_pages_table_model.cc @@ -14,7 +14,6 @@ #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" #include "gfx/codec/png_codec.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" @@ -85,9 +84,7 @@ void CustomHomePagesTableModel::SetToCurrentlyOpenPages() { for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { const GURL url = browser->GetTabContentsAt(tab_index)->GetURL(); - if (!url.is_empty() && - !(url.SchemeIs(chrome::kChromeUIScheme) && - url.host() == chrome::kChromeUIOptionsHost)) + if (!url.is_empty()) Add(add_index++, url); } } diff --git a/chrome/browser/dom_ui/browser_options_handler.cc b/chrome/browser/dom_ui/browser_options_handler.cc index fda6802..58d002d 100644 --- a/chrome/browser/dom_ui/browser_options_handler.cc +++ b/chrome/browser/dom_ui/browser_options_handler.cc @@ -10,15 +10,13 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "chrome/browser/custom_home_pages_table_model.h" #include "chrome/browser/profile.h" -#include "chrome/browser/session_startup_pref.h" #include "chrome/installer/util/browser_distribution.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" BrowserOptionsHandler::BrowserOptionsHandler() - : template_url_model_(NULL), startup_custom_pages_table_model_(NULL) { + : template_url_model_(NULL) { #if !defined(OS_MACOSX) default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); #endif @@ -77,18 +75,17 @@ void BrowserOptionsHandler::RegisterMessages() { dom_ui_->RegisterMessageCallback( "setDefaultSearchEngine", NewCallback(this, &BrowserOptionsHandler::SetDefaultSearchEngine)); - dom_ui_->RegisterMessageCallback( - "removeStartupPages", - NewCallback(this, &BrowserOptionsHandler::RemoveStartupPages)); - dom_ui_->RegisterMessageCallback( - "setStartupPagesToCurrentPages", - NewCallback(this, &BrowserOptionsHandler::SetStartupPagesToCurrentPages)); } void BrowserOptionsHandler::Initialize() { UpdateDefaultBrowserState(); - UpdateStartupPages(); - UpdateSearchEngines(); + + template_url_model_ = dom_ui_->GetProfile()->GetTemplateURLModel(); + if (template_url_model_) { + template_url_model_->Load(); + template_url_model_->AddObserver(this); + OnTemplateURLModelChanged(); + } } void BrowserOptionsHandler::UpdateDefaultBrowserState() { @@ -214,89 +211,3 @@ void BrowserOptionsHandler::SetDefaultSearchEngine(const Value* value) { template_url_model_->SetDefaultSearchProvider(model_urls[selected_index]); } -void BrowserOptionsHandler::UpdateSearchEngines() { - template_url_model_ = dom_ui_->GetProfile()->GetTemplateURLModel(); - if (template_url_model_) { - template_url_model_->Load(); - template_url_model_->AddObserver(this); - OnTemplateURLModelChanged(); - } -} - -void BrowserOptionsHandler::UpdateStartupPages() { - Profile* profile = dom_ui_->GetProfile(); - startup_custom_pages_table_model_.reset( - new CustomHomePagesTableModel(profile)); - startup_custom_pages_table_model_->SetObserver(this); - - const SessionStartupPref startup_pref = - SessionStartupPref::GetStartupPref(profile->GetPrefs()); - startup_custom_pages_table_model_->SetURLs(startup_pref.urls); -} - -void BrowserOptionsHandler::OnModelChanged() { - // TODO(stuartmorgan): Add support for showing favicons. - ListValue startup_pages; - int page_count = startup_custom_pages_table_model_->RowCount(); - for (int i = 0; i < page_count; ++i) { - DictionaryValue* entry = new DictionaryValue(); - entry->SetString(L"title", - startup_custom_pages_table_model_->GetText(i, 0)); - entry->SetString(L"tooltip", - startup_custom_pages_table_model_->GetTooltip(i)); - startup_pages.Append(entry); - } - - dom_ui_->CallJavascriptFunction(L"BrowserOptions.updateStartupPages", - startup_pages); -} - -void BrowserOptionsHandler::OnItemsChanged(int start, int length) { - OnModelChanged(); -} - -void BrowserOptionsHandler::OnItemsAdded(int start, int length) { - OnModelChanged(); -} - -void BrowserOptionsHandler::OnItemsRemoved(int start, int length) { - OnModelChanged(); -} - -void BrowserOptionsHandler::SetStartupPagesToCurrentPages(const Value* value) { - startup_custom_pages_table_model_->SetToCurrentlyOpenPages(); - SaveStartupPagesPref(); -} - -void BrowserOptionsHandler::RemoveStartupPages(const Value* value) { - if (!value || !value->IsType(Value::TYPE_LIST)) { - NOTREACHED(); - return; - } - const ListValue* param_values = static_cast<const ListValue*>(value); - for (int i = param_values->GetSize() - 1; i >= 0; --i) { - std::string string_value; - if (!param_values->GetString(i, &string_value)) { - NOTREACHED(); - return; - } - int selected_index = StringToInt(string_value); - if (selected_index < 0 || - selected_index >= startup_custom_pages_table_model_->RowCount()) { - NOTREACHED(); - return; - } - startup_custom_pages_table_model_->Remove(selected_index); - } - - SaveStartupPagesPref(); -} - -void BrowserOptionsHandler::SaveStartupPagesPref() { - PrefService* prefs = dom_ui_->GetProfile()->GetPrefs(); - - SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs); - pref.urls = startup_custom_pages_table_model_->GetURLs(); - - SessionStartupPref::SetStartupPref(prefs, pref); -} diff --git a/chrome/browser/dom_ui/browser_options_handler.h b/chrome/browser/dom_ui/browser_options_handler.h index 794b525..6c37bd5 100644 --- a/chrome/browser/dom_ui/browser_options_handler.h +++ b/chrome/browser/dom_ui/browser_options_handler.h @@ -6,18 +6,14 @@ #define CHROME_BROWSER_DOM_UI_BROWSER_OPTIONS_HANDLER_H_ #pragma once -#include "app/table_model_observer.h" #include "chrome/browser/dom_ui/options_ui.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/shell_integration.h" -class CustomHomePagesTableModel; - // Chrome browser options page UI handler. class BrowserOptionsHandler : public OptionsPageUIHandler, public ShellIntegration::DefaultBrowserObserver, - public TemplateURLModelObserver, - public TableModelObserver { + public TemplateURLModelObserver { public: BrowserOptionsHandler(); virtual ~BrowserOptionsHandler(); @@ -35,12 +31,6 @@ class BrowserOptionsHandler : public OptionsPageUIHandler, // TemplateURLModelObserver implementation. virtual void OnTemplateURLModelChanged(); - // TableModelObserver implementation. - virtual void OnModelChanged(); - virtual void OnItemsChanged(int start, int length); - virtual void OnItemsAdded(int start, int length); - virtual void OnItemsRemoved(int start, int length); - private: // Makes this the default browser. Called from DOMUI. void BecomeDefaultBrowser(const Value* value); @@ -48,12 +38,6 @@ class BrowserOptionsHandler : public OptionsPageUIHandler, // Sets the search engine at the given index to be default. Called from DOMUI. void SetDefaultSearchEngine(const Value* value); - // Removes the startup page at the given indexes. Called from DOMUI. - void RemoveStartupPages(const Value* value); - - // Sets the startup page set to the current pages. Called from DOMUI. - void SetStartupPagesToCurrentPages(const Value* value); - // Returns the string ID for the given default browser state. int StatusStringIdForState(ShellIntegration::DefaultBrowserState state); @@ -64,24 +48,10 @@ class BrowserOptionsHandler : public OptionsPageUIHandler, // Updates the UI with the given state for the default browser. void SetDefaultBrowserUIString(int status_string_id); - // Loads the current set of custom startup pages and reports it to the DOMUI. - void UpdateStartupPages(); - - // Loads the possible default search engine list and reports it to the DOMUI. - void UpdateSearchEngines(); - - // Writes the current set of startup pages to prefs. - void SaveStartupPagesPref(); - scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_; TemplateURLModel* template_url_model_; // Weak. - // TODO(stuartmorgan): Once there are no other clients of - // CustomHomePagesTableModel, consider changing it to something more like - // TemplateURLModel. - scoped_ptr<CustomHomePagesTableModel> startup_custom_pages_table_model_; - DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler); }; diff --git a/chrome/browser/resources/options/browser_options.html b/chrome/browser/resources/options/browser_options.html index 7a8ad39..abeb46e 100644 --- a/chrome/browser/resources/options/browser_options.html +++ b/chrome/browser/resources/options/browser_options.html @@ -13,13 +13,13 @@ pref="session.restore_on_startup" value="4"><span i18n-content="startupShowPages"></span></label> <div class="suboption"> - <select id="startupPages" size="3" multiple> + <select id="startupPages" size="3"> </select><br> <button id="startupAddButton" i18n-content="startupAddButton"></button> <button id="startupRemoveButton" disabled i18n-content="startupRemoveButton"></button> - <button id="startupUseCurrentButton" + <button id="startupUseCurrentButton" disabled i18n-content="startupUseCurrent"></button> </div> </div> diff --git a/chrome/browser/resources/options/browser_options.js b/chrome/browser/resources/options/browser_options.js index 53e0656..834c993 100644 --- a/chrome/browser/resources/options/browser_options.js +++ b/chrome/browser/resources/options/browser_options.js @@ -23,19 +23,15 @@ BrowserOptions.prototype = { // Call base class implementation to start preference initialization. OptionsPage.prototype.initializePage.call(this); - // Wire up controls. - var self = this; - $('startupPages').onchange = function(event) { - self.updateRemoveButtonState_(); - }; + // Wire up buttons. $('startupAddButton').onclick = function(event) { OptionsPage.showOverlay('addStartupPageOverlay'); }; $('startupRemoveButton').onclick = function(event) { - self.removeSelectedStartupPages_(); + // TODO(stuartmorgan): Remove selected element(s). }; $('startupUseCurrentButton').onclick = function(event) { - chrome.send('setStartupPagesToCurrentPages'); + // TODO(stuartmorgan): Add all open tabs (except this one). }; $('defaultSearchManageEnginesButton').onclick = function(event) { OptionsPage.showPageByName('searchEngines'); @@ -85,10 +81,10 @@ BrowserOptions.prototype = { updateSearchEngines_: function(engines, defaultValue) { this.clearSearchEngines_(); engineSelect = $('defaultSearchEngine'); - engineCount = engines.length; + engineCount = engines.length var defaultIndex = -1; for (var i = 0; i < engineCount; i++) { - var engine = engines[i]; + var engine = engines[i] var option = new Option(engine['name'], engine['index']); if (defaultValue == option.value) defaultIndex = i; @@ -99,55 +95,6 @@ BrowserOptions.prototype = { }, /** - * Clears the startup page list. - * @private - */ - clearStartupPages_: function() { - $('startupPages').textContent = ''; - }, - - /** - * Updates the startup pages list with the given entries. - * @param {Array} pages List of startup pages. - */ - updateStartupPages_: function(pages) { - // TODO(stuartmorgan): Replace <select> with a DOMUI List. - this.clearStartupPages_(); - pageList = $('startupPages'); - pageCount = pages.length; - for (var i = 0; i < pageCount; i++) { - var page = pages[i]; - var option = new Option(page['title']); - option.title = page['tooltip']; - pageList.appendChild(option); - } - - this.updateRemoveButtonState_(); - }, - - /** - * Sets the enabled state of the startup page Remove button based on - * the current selection in the startup pages list. - */ - updateRemoveButtonState_: function() { - $('startupRemoveButton').disabled = ($('startupPages').selectedIndex == -1); - }, - - /** - * Removes the selected startup pages. - */ - removeSelectedStartupPages_: function() { - var pageSelect = $('startupPages'); - var optionCount = pageSelect.options.length; - var selections = []; - for (var i = 0; i < optionCount; i++) { - if (pageSelect.options[i].selected) - selections.push(String(i)); - } - chrome.send('removeStartupPages', selections); - }, - - /** * Set the default search engine based on the popup selection. */ setDefaultBrowser: function() { @@ -163,12 +110,8 @@ BrowserOptions.prototype = { BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault) { BrowserOptions.getInstance().updateDefaultBrowserState_(statusString, isDefault); -}; +} BrowserOptions.updateSearchEngines = function(engines, defaultValue) { BrowserOptions.getInstance().updateSearchEngines_(engines, defaultValue); -}; - -BrowserOptions.updateStartupPages = function(pages) { - BrowserOptions.getInstance().updateStartupPages_(pages); -}; +} |