diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 22:37:45 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 22:37:45 +0000 |
commit | 579e319b672d1e703249fa9f236c6b9dbb7909b5 (patch) | |
tree | d3823bf4be2c4180bd7f174405ecece4a62cc78a | |
parent | 7f66520ba5dd150bbdbaad746539a4206d483dc1 (diff) | |
download | chromium_src-579e319b672d1e703249fa9f236c6b9dbb7909b5.zip chromium_src-579e319b672d1e703249fa9f236c6b9dbb7909b5.tar.gz chromium_src-579e319b672d1e703249fa9f236c6b9dbb7909b5.tar.bz2 |
Options: Remove the GTK and Views native options code.
BUG=75320
TEST=none
Review URL: http://codereview.chromium.org/6670011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77878 0039d316-1c4b-4281-b951-d872f2087c98
110 files changed, 18 insertions, 19554 deletions
diff --git a/chrome/browser/content_setting_bubble_model.cc b/chrome/browser/content_setting_bubble_model.cc index abe89f7..96f609d 100644 --- a/chrome/browser/content_setting_bubble_model.cc +++ b/chrome/browser/content_setting_bubble_model.cc @@ -120,7 +120,7 @@ class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { virtual void OnManageLinkClicked() { if (tab_contents()) - tab_contents()->delegate()->ShowContentSettingsWindow(content_type()); + tab_contents()->delegate()->ShowContentSettingsPage(content_type()); } }; diff --git a/chrome/browser/notifications/notification_options_menu_model.cc b/chrome/browser/notifications/notification_options_menu_model.cc index c524643..b04b5a9 100644 --- a/chrome/browser/notifications/notification_options_menu_model.cc +++ b/chrome/browser/notifications/notification_options_menu_model.cc @@ -11,6 +11,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/notifications/balloon_collection.h" +#include "chrome/browser/notifications/balloon_host.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_ui_manager.h" @@ -20,13 +21,10 @@ #include "chrome/common/content_settings_types.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/url_constants.h" +#include "content/browser/tab_contents/tab_contents.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" -#if defined(OS_WIN) -#include "chrome/browser/ui/views/browser_dialogs.h" -#endif // OS_WIN - // Menu commands const int kTogglePermissionCommand = 0; const int kToggleExtensionCommand = 1; @@ -154,8 +152,8 @@ bool NotificationOptionsMenuModel::IsItemForCommandIdDynamic(int command_id) string16 NotificationOptionsMenuModel::GetLabelForCommandId(int command_id) const { - // TODO(tfarina,johnnyg): Removed this code if we decide to close - // notifications after permissions are revoked. + // TODO(tfarina,johnnyg): Remove this code if we decide to close notifications + // after permissions are revoked. if (command_id == kTogglePermissionCommand || command_id == kToggleExtensionCommand) { const Notification& notification = balloon_->notification(); @@ -236,21 +234,10 @@ void NotificationOptionsMenuModel::ExecuteCommand(int command_id) { break; } case kOpenContentSettingsCommand: { - Browser* browser = BrowserList::GetLastActive(); - if (browser) { - static_cast<TabContentsDelegate*>(browser)->ShowContentSettingsWindow( - CONTENT_SETTINGS_TYPE_NOTIFICATIONS); - } else { -#if defined(OS_WIN) - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kChromeFrame)) { - // We may not have a browser if this is a chrome frame process. - browser::ShowContentSettingsWindow(NULL, - CONTENT_SETTINGS_TYPE_DEFAULT, - balloon_->profile()); - } -#endif // OS_WIN - } + TabContents* tab_contents = + balloon_->view()->GetHost()->associated_tab_contents(); + tab_contents->delegate()->ShowContentSettingsPage( + CONTENT_SETTINGS_TYPE_NOTIFICATIONS); break; } default: diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 48e4437..391f904d 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -1422,10 +1422,8 @@ void RenderViewContextMenu::ExecuteCommand(int id) { } case IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS: - ShowFontsLanguagesWindow( - platform_util::GetTopLevel( - source_tab_contents_->GetContentNativeView()), - LANGUAGES_PAGE, profile_); + OpenURL(GURL(chrome::kLanguageOptionsSubPage), NEW_FOREGROUND_TAB, + PageTransition::LINK); break; case IDC_SPELLPANEL_TOGGLE: diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index c145042..4c7ada2 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -3194,8 +3194,7 @@ void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { window()->ShowRepostFormWarningDialog(tab_contents); } -void Browser::ShowContentSettingsWindow(ContentSettingsType content_type) { - // TODO(jhawkins): Remove BrowserWindow::ShowContentSettingsWindow. +void Browser::ShowContentSettingsPage(ContentSettingsType content_type) { ShowOptionsTab( chrome::kContentSettingsExceptionsSubPage + std::string(kHashMark) + ContentSettingsHandler::ContentSettingsTypeToGroupName(content_type)); diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index f03b572..88bf2ac 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -803,7 +803,7 @@ class Browser : public TabHandlerDelegate, bool* is_keyboard_shortcut); virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); - virtual void ShowContentSettingsWindow(ContentSettingsType content_type); + virtual void ShowContentSettingsPage(ContentSettingsType content_type); virtual void ShowCollectedCookiesDialog(TabContents* tab_contents); virtual bool ShouldAddNavigationToHistory( const history::HistoryAddPageArgs& add_page_args, diff --git a/chrome/browser/ui/browser_window.h b/chrome/browser/ui/browser_window.h index 4019d5d..9e7f252 100644 --- a/chrome/browser/ui/browser_window.h +++ b/chrome/browser/ui/browser_window.h @@ -228,10 +228,6 @@ class BrowserWindow { // Shows the repost form confirmation dialog box. virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) = 0; - // Shows the Content Settings dialog box. - virtual void ShowContentSettingsWindow(ContentSettingsType content_type, - Profile* profile) = 0; - // Shows the collected cookies dialog box. virtual void ShowCollectedCookiesDialog(TabContents* tab_contents) = 0; diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.h b/chrome/browser/ui/cocoa/browser_window_cocoa.h index 6106a3f..e72bc14 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.h +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.h @@ -79,8 +79,6 @@ class BrowserWindowCocoa : public BrowserWindow, virtual bool IsDownloadShelfVisible() const; virtual DownloadShelf* GetDownloadShelf(); virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); - virtual void ShowContentSettingsWindow(ContentSettingsType content_type, - Profile* profile); virtual void ShowCollectedCookiesDialog(TabContents* tab_contents); virtual void ShowProfileErrorDialog(int message_id); virtual void ShowThemeInstallBubble(); diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm index 6f915d1..b3b4c003 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm @@ -328,12 +328,6 @@ void BrowserWindowCocoa::ShowRepostFormWarningDialog( RepostFormWarningMac::Create(GetNativeHandle(), tab_contents); } -void BrowserWindowCocoa::ShowContentSettingsWindow( - ContentSettingsType settings_type, - Profile* profile) { - NOTIMPLEMENTED(); -} - void BrowserWindowCocoa::ShowCollectedCookiesDialog(TabContents* tab_contents) { // Deletes itself on close. new CollectedCookiesMac(GetNativeHandle(), tab_contents); diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index 8394e3f..f74e19b 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -61,7 +61,6 @@ #include "chrome/browser/ui/gtk/keyword_editor_view.h" #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" #include "chrome/browser/ui/gtk/nine_box.h" -#include "chrome/browser/ui/gtk/options/content_settings_window_gtk.h" #include "chrome/browser/ui/gtk/reload_button_gtk.h" #include "chrome/browser/ui/gtk/repost_form_warning_gtk.h" #include "chrome/browser/ui/gtk/status_bubble_gtk.h" @@ -885,12 +884,6 @@ void BrowserWindowGtk::ShowRepostFormWarningDialog(TabContents* tab_contents) { new RepostFormWarningGtk(GetNativeHandle(), tab_contents); } -void BrowserWindowGtk::ShowContentSettingsWindow( - ContentSettingsType content_type, - Profile* profile) { - ContentSettingsWindowGtk::Show(GetNativeHandle(), content_type, profile); -} - void BrowserWindowGtk::ShowCollectedCookiesDialog(TabContents* tab_contents) { // Deletes itself on close. new CollectedCookiesGtk(GetNativeHandle(), tab_contents); diff --git a/chrome/browser/ui/gtk/browser_window_gtk.h b/chrome/browser/ui/gtk/browser_window_gtk.h index 65b789c..755584e 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.h +++ b/chrome/browser/ui/gtk/browser_window_gtk.h @@ -98,8 +98,6 @@ class BrowserWindowGtk : public BrowserWindow, virtual bool IsDownloadShelfVisible() const; virtual DownloadShelf* GetDownloadShelf(); virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); - virtual void ShowContentSettingsWindow(ContentSettingsType content_type, - Profile* profile); virtual void ShowCollectedCookiesDialog(TabContents* tab_contents); virtual void ShowProfileErrorDialog(int message_id); virtual void ShowThemeInstallBubble(); diff --git a/chrome/browser/ui/gtk/content_setting_bubble_gtk.cc b/chrome/browser/ui/gtk/content_setting_bubble_gtk.cc index c4162ba..9fe4ef1 100644 --- a/chrome/browser/ui/gtk/content_setting_bubble_gtk.cc +++ b/chrome/browser/ui/gtk/content_setting_bubble_gtk.cc @@ -17,7 +17,6 @@ #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" #include "chrome/browser/ui/gtk/gtk_theme_provider.h" #include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/options/content_settings_window_gtk.h" #include "chrome/common/content_settings.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_source.h" diff --git a/chrome/browser/ui/gtk/options/advanced_contents_gtk.cc b/chrome/browser/ui/gtk/options/advanced_contents_gtk.cc deleted file mode 100644 index 46d0554..0000000 --- a/chrome/browser/ui/gtk/options/advanced_contents_gtk.cc +++ /dev/null @@ -1,1199 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/advanced_contents_gtk.h" - -#include <sys/types.h> -#include <sys/wait.h> - -#include <string> -#include <vector> - -#include "base/basictypes.h" -#include "base/command_line.h" -#include "base/environment.h" -#include "base/file_util.h" -#include "base/path_service.h" -#include "base/process_util.h" -#include "base/string_tokenizer.h" -#include "base/nix/xdg_util.h" -#include "chrome/browser/browser_list.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/download/download_manager.h" -#include "chrome/browser/download/download_prefs.h" -#include "chrome/browser/fonts_languages_window.h" -#include "chrome/browser/google/google_util.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/prefs/pref_set_observer.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/safe_browsing/safe_browsing_service.h" -#include "chrome/browser/ui/gtk/clear_browsing_data_dialog_gtk.h" -#include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/options/content_settings_window_gtk.h" -#include "chrome/browser/ui/gtk/options/options_layout_gtk.h" -#include "chrome/browser/ui/options/options_page_base.h" -#include "chrome/browser/ui/options/options_util.h" -#include "chrome/browser/ui/options/show_options_url.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/process_watcher.h" -#include "chrome/common/url_constants.h" -#include "content/browser/renderer_host/resource_dispatcher_host.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/gtk/gtk_signal.h" -#include "ui/base/l10n/l10n_util.h" - -namespace { - -// Command used to configure GNOME proxy settings. The command was renamed -// in January 2009, so both are used to work on both old and new systems. -const char* kOldGNOMEProxyConfigCommand[] = {"gnome-network-preferences", NULL}; -const char* kGNOMEProxyConfigCommand[] = {"gnome-network-properties", NULL}; -// KDE3 and KDE4 are only slightly different, but incompatible. Go figure. -const char* kKDE3ProxyConfigCommand[] = {"kcmshell", "proxy", NULL}; -const char* kKDE4ProxyConfigCommand[] = {"kcmshell4", "proxy", NULL}; - -// The URL for Linux ssl certificate configuration help. -const char* const kLinuxCertificatesConfigUrl = - "http://code.google.com/p/chromium/wiki/LinuxCertManagement"; - -// The URL for Linux proxy configuration help when not running under a -// supported desktop environment. -const char kLinuxProxyConfigUrl[] = "about:linux-proxy-config"; - -// The pixel width we wrap labels at. -// TODO(evanm): make the labels wrap at the appropriate width. -#if defined(OS_CHROMEOS) -// ChromeOS uses IDS_OPTIONS_DIALOG_WIDTH_CHARS for options dialog width, which -// is slightly smaller than the Gtk options dialog's 500px. -const int kWrapWidth = 445; -#else -const int kWrapWidth = 475; -#endif - -GtkWidget* CreateWrappedLabel(int string_id) { - GtkWidget* label = gtk_label_new( - l10n_util::GetStringUTF8(string_id).c_str()); - gtk_util::SetLabelWidth(label, kWrapWidth); - return label; -} - -GtkWidget* CreateCheckButtonWithWrappedLabel(int string_id) { - GtkWidget* checkbox = gtk_check_button_new(); - gtk_container_add(GTK_CONTAINER(checkbox), - CreateWrappedLabel(string_id)); - return checkbox; -} - -GtkWidget* AddCheckButtonWithWrappedLabel(int string_id, - GtkWidget* container, - GCallback handler, - gpointer data) { - GtkWidget* checkbox = CreateCheckButtonWithWrappedLabel(string_id); - gtk_box_pack_start(GTK_BOX(container), checkbox, FALSE, FALSE, 0); - g_signal_connect(checkbox, "toggled", handler, data); - - return checkbox; -} - -// Don't let the widget handle scroll events. Instead, pass it on to the -// parent widget. -gboolean PassScrollToParent(GtkWidget* widget, GdkEvent* event, - gpointer unused) { - if (widget->parent) - gtk_propagate_event(widget->parent, event); - - return TRUE; -} - -// Recursively search for a combo box among the children of |widget|. -void SearchForComboBox(GtkWidget* widget, gpointer data) { - if (GTK_IS_COMBO_BOX(widget)) { - *reinterpret_cast<GtkWidget**>(data) = widget; - } else if (GTK_IS_CONTAINER(widget)) { - gtk_container_foreach(GTK_CONTAINER(widget), SearchForComboBox, data); - } -} - -// Letting the combo boxes in the advanced options page handle scroll events is -// annoying because they fight with the scrolled window. Also, -// GtkFileChooserButton is buggy in that if you scroll on it very quickly it -// spews Gtk-WARNINGs, which causes us to crash in debug. This function disables -// scrolling for the combo box in |widget| (the first one it finds in a DFS). -void DisableScrolling(GtkWidget* widget) { - gpointer combo_box_ptr = NULL; - SearchForComboBox(widget, &combo_box_ptr); - - if (!combo_box_ptr) { - NOTREACHED() << " Did not find a combo box in this widget."; - return; - } - - g_signal_connect(GTK_WIDGET(combo_box_ptr), "scroll-event", - G_CALLBACK(PassScrollToParent), NULL); -} - -} // anonymous namespace - - -/////////////////////////////////////////////////////////////////////////////// -// DownloadSection - -class DownloadSection : public OptionsPageBase { - public: - explicit DownloadSection(Profile* profile); - virtual ~DownloadSection() {} - - GtkWidget* get_page_widget() const { - return page_; - } - - private: - // Overridden from OptionsPageBase. - virtual void NotifyPrefChanged(const std::string* pref_name); - - // Helper function for reacting to managed prefs. - void UpdateWidgetsForManagedPrefs(); - - // Callbacks for the widgets. - static void OnDownloadLocationChanged(GtkFileChooser* widget, - DownloadSection* section); - static void OnDownloadAskForSaveLocationChanged(GtkWidget* widget, - DownloadSection* section); - static void OnResetFileHandlersClicked(GtkButton *button, - DownloadSection* section); - - // The widgets for the download options. - GtkWidget* download_location_button_; - GtkWidget* download_ask_for_save_location_checkbox_; - GtkWidget* reset_file_handlers_label_; - GtkWidget* reset_file_handlers_button_; - - // The widget containing the options for this section. - GtkWidget* page_; - - // Pref members. - FilePathPrefMember default_download_location_; - BooleanPrefMember ask_for_save_location_; - StringPrefMember auto_open_files_; - - // Flag to ignore gtk callbacks while we are loading prefs, to avoid - // then turning around and saving them again. - bool pref_changing_; - - DISALLOW_COPY_AND_ASSIGN(DownloadSection); -}; - -DownloadSection::DownloadSection(Profile* profile) - : OptionsPageBase(profile), - pref_changing_(true) { - page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - // Download location options. - download_location_button_ = gtk_file_chooser_button_new( - l10n_util::GetStringUTF8( - IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_WINDOW_TITLE).c_str(), - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); - g_signal_connect(download_location_button_, "selection-changed", - G_CALLBACK(OnDownloadLocationChanged), this); - DisableScrolling(download_location_button_); - - // Add the default download path to the list of shortcuts in the selector. - FilePath default_download_path; - if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, - &default_download_path)) { - NOTREACHED(); - } else { - if (!gtk_file_chooser_add_shortcut_folder( - GTK_FILE_CHOOSER(download_location_button_), - default_download_path.value().c_str(), - NULL)) { - NOTREACHED(); - } - } - - GtkWidget* download_location_control = gtk_util::CreateLabeledControlsGroup( - NULL, - l10n_util::GetStringUTF8( - IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE).c_str(), - download_location_button_, - NULL); - gtk_box_pack_start(GTK_BOX(page_), download_location_control, - FALSE, FALSE, 0); - - download_ask_for_save_location_checkbox_ = CreateCheckButtonWithWrappedLabel( - IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION); - gtk_box_pack_start(GTK_BOX(page_), download_ask_for_save_location_checkbox_, - FALSE, FALSE, 0); - g_signal_connect(download_ask_for_save_location_checkbox_, "clicked", - G_CALLBACK(OnDownloadAskForSaveLocationChanged), this); - - // Option for resetting file handlers. - reset_file_handlers_label_ = CreateWrappedLabel( - IDS_OPTIONS_AUTOOPENFILETYPES_INFO); - gtk_misc_set_alignment(GTK_MISC(reset_file_handlers_label_), 0, 0); - gtk_box_pack_start(GTK_BOX(page_), reset_file_handlers_label_, - FALSE, FALSE, 0); - - reset_file_handlers_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8( - IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT).c_str()); - g_signal_connect(reset_file_handlers_button_, "clicked", - G_CALLBACK(OnResetFileHandlersClicked), this); - // Stick it in an hbox so it doesn't expand to the whole width. - GtkWidget* button_hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(button_hbox), - reset_file_handlers_button_, - FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(page_), - gtk_util::IndentWidget(button_hbox), - FALSE, FALSE, 0); - - // Init prefs watchers. - default_download_location_.Init(prefs::kDownloadDefaultDirectory, - profile->GetPrefs(), this); - ask_for_save_location_.Init(prefs::kPromptForDownload, - profile->GetPrefs(), this); - auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, profile->GetPrefs(), - this); - - NotifyPrefChanged(NULL); -} - -void DownloadSection::NotifyPrefChanged(const std::string* pref_name) { - pref_changing_ = true; - if (!pref_name || *pref_name == prefs::kDownloadDefaultDirectory) { - gtk_file_chooser_set_current_folder( - GTK_FILE_CHOOSER(download_location_button_), - default_download_location_.GetValue().value().c_str()); - } - - if (!pref_name || *pref_name == prefs::kPromptForDownload) { - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(download_ask_for_save_location_checkbox_), - ask_for_save_location_.GetValue()); - } - - if (!pref_name || *pref_name == prefs::kDownloadExtensionsToOpen) { - DownloadPrefs* prefs = profile()->GetDownloadManager()->download_prefs(); - bool enabled = prefs->IsAutoOpenUsed(); - gtk_widget_set_sensitive(reset_file_handlers_label_, enabled); - gtk_widget_set_sensitive(reset_file_handlers_button_, enabled); - } - UpdateWidgetsForManagedPrefs(); - pref_changing_ = false; -} - -void DownloadSection::UpdateWidgetsForManagedPrefs() { - const bool enabled = !default_download_location_.IsManaged(); - gtk_widget_set_sensitive(download_location_button_, enabled); - gtk_widget_set_sensitive(download_ask_for_save_location_checkbox_, enabled); -} - -// static -void DownloadSection::OnDownloadLocationChanged(GtkFileChooser* widget, - DownloadSection* section) { - if (section->pref_changing_) - return; - - gchar* folder = gtk_file_chooser_get_filename(widget); - FilePath path(folder); - g_free(folder); - // Gtk seems to call this signal multiple times, so we only set the pref and - // metric if something actually changed. - if (path != section->default_download_location_.GetValue()) { - section->default_download_location_.SetValue(path); - section->UserMetricsRecordAction( - UserMetricsAction("Options_SetDownloadDirectory"), - section->profile()->GetPrefs()); - } -} - -// static -void DownloadSection::OnDownloadAskForSaveLocationChanged( - GtkWidget* widget, DownloadSection* section) { - if (section->pref_changing_) - return; - bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - if (enabled) { - section->UserMetricsRecordAction( - UserMetricsAction("Options_AskForSaveLocation_Enable"), - section->profile()->GetPrefs()); - } else { - section->UserMetricsRecordAction( - UserMetricsAction("Options_AskForSaveLocation_Disable"), - section->profile()->GetPrefs()); - } - section->ask_for_save_location_.SetValue(enabled); -} - -// static -void DownloadSection::OnResetFileHandlersClicked(GtkButton *button, - DownloadSection* section) { - section->profile()->GetDownloadManager()->download_prefs()->ResetAutoOpen(); - section->UserMetricsRecordAction( - UserMetricsAction("Options_ResetAutoOpenFiles"), - section->profile()->GetPrefs()); -} - -/////////////////////////////////////////////////////////////////////////////// -// NetworkSection - -class NetworkSection : public OptionsPageBase { - public: - explicit NetworkSection(Profile* profile); - virtual ~NetworkSection() {} - - GtkWidget* get_page_widget() const { - return page_; - } - - private: - // Overridden from OptionsPageBase. - virtual void NotifyPrefChanged(const std::string* pref_name); - - struct ProxyConfigCommand { - std::string binary; - const char** argv; - }; - // The callback functions for invoking the proxy config dialog. - static void OnChangeProxiesButtonClicked(GtkButton *button, - NetworkSection* section); - // Detect, and if possible, start the appropriate proxy config utility. On - // failure to do so, show the Linux proxy config URL in a new tab instead. - static void DetectAndStartProxyConfigUtil(Profile* profile); - // Show the proxy config URL in a new tab. - static void ShowLinuxProxyConfigUrl(Profile* profile); - // Search $PATH to find one of the commands. Store the full path to - // it in the |binary| field and the command array index in in |index|. - static bool SearchPATH(ProxyConfigCommand* commands, size_t ncommands, - size_t* index); - // Start the given proxy configuration utility. - static void StartProxyConfigUtil(Profile* profile, - const ProxyConfigCommand& command); - - // Tracks the state of proxy preferences. - scoped_ptr<PrefSetObserver> proxy_prefs_; - - // The widget containing the options for this section. - GtkWidget* page_; - - // The proxy configuration button. - GtkWidget* change_proxies_button_; - - DISALLOW_COPY_AND_ASSIGN(NetworkSection); -}; - -NetworkSection::NetworkSection(Profile* profile) - : OptionsPageBase(profile) { - page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - GtkWidget* proxy_description_label = CreateWrappedLabel( - IDS_OPTIONS_PROXIES_LABEL); - gtk_misc_set_alignment(GTK_MISC(proxy_description_label), 0, 0); - gtk_box_pack_start(GTK_BOX(page_), proxy_description_label, - FALSE, FALSE, 0); - - change_proxies_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8( - IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON).c_str()); - g_signal_connect(change_proxies_button_, "clicked", - G_CALLBACK(OnChangeProxiesButtonClicked), this); - - // Stick it in an hbox so it doesn't expand to the whole width. - GtkWidget* button_hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(button_hbox), - change_proxies_button_, - FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(page_), - gtk_util::IndentWidget(button_hbox), - FALSE, FALSE, 0); - - proxy_prefs_.reset(PrefSetObserver::CreateProxyPrefSetObserver( - profile->GetPrefs(), this)); - NotifyPrefChanged(NULL); -} - -void NetworkSection::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || proxy_prefs_->IsObserved(*pref_name)) - gtk_widget_set_sensitive(change_proxies_button_, - !proxy_prefs_->IsManaged()); -} - -// static -void NetworkSection::DetectAndStartProxyConfigUtil(Profile* profile) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - scoped_ptr<base::Environment> env(base::Environment::Create()); - - ProxyConfigCommand command; - bool found_command = false; - switch (base::nix::GetDesktopEnvironment(env.get())) { - case base::nix::DESKTOP_ENVIRONMENT_GNOME: { - size_t index; - ProxyConfigCommand commands[2]; - commands[0].argv = kGNOMEProxyConfigCommand; - commands[1].argv = kOldGNOMEProxyConfigCommand; - found_command = SearchPATH(commands, 2, &index); - if (found_command) - command = commands[index]; - break; - } - - case base::nix::DESKTOP_ENVIRONMENT_KDE3: - command.argv = kKDE3ProxyConfigCommand; - found_command = SearchPATH(&command, 1, NULL); - break; - - case base::nix::DESKTOP_ENVIRONMENT_KDE4: - command.argv = kKDE4ProxyConfigCommand; - found_command = SearchPATH(&command, 1, NULL); - break; - - case base::nix::DESKTOP_ENVIRONMENT_XFCE: - case base::nix::DESKTOP_ENVIRONMENT_OTHER: - break; - } - - if (found_command) { - StartProxyConfigUtil(profile, command); - } else { - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableFunction(&NetworkSection::ShowLinuxProxyConfigUrl, profile)); - } -} - -// static -void NetworkSection::ShowLinuxProxyConfigUrl(Profile* profile) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - scoped_ptr<base::Environment> env(base::Environment::Create()); - const char* name = base::nix::GetDesktopEnvironmentName(env.get()); - if (name) - LOG(ERROR) << "Could not find " << name << " network settings in $PATH"; - browser::ShowOptionsURL(profile, GURL(kLinuxProxyConfigUrl)); -} - -// static -void NetworkSection::OnChangeProxiesButtonClicked(GtkButton *button, - NetworkSection* section) { - section->UserMetricsRecordAction(UserMetricsAction("Options_ChangeProxies"), - NULL); - BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, - NewRunnableFunction(&NetworkSection::DetectAndStartProxyConfigUtil, - section->profile())); -} - -// static -bool NetworkSection::SearchPATH(ProxyConfigCommand* commands, size_t ncommands, - size_t* index) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - const char* path = getenv("PATH"); - if (!path) - return false; - FilePath bin_path; - CStringTokenizer tk(path, path + strlen(path), ":"); - // Search $PATH looking for the commands in order. - while (tk.GetNext()) { - for (size_t i = 0; i < ncommands; i++) { - bin_path = FilePath(tk.token()).Append(commands[i].argv[0]); - if (file_util::PathExists(bin_path)) { - commands[i].binary = bin_path.value(); - if (index) - *index = i; - return true; - } - } - } - // Did not find any of the binaries in $PATH. - return false; -} - -// static -void NetworkSection::StartProxyConfigUtil(Profile* profile, - const ProxyConfigCommand& command) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - std::vector<std::string> argv; - argv.push_back(command.binary); - for (size_t i = 1; command.argv[i]; i++) - argv.push_back(command.argv[i]); - base::file_handle_mapping_vector no_files; - base::ProcessHandle handle; - if (!base::LaunchApp(argv, no_files, false, &handle)) { - LOG(ERROR) << "StartProxyConfigUtil failed to start " << command.binary; - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableFunction(&NetworkSection::ShowLinuxProxyConfigUrl, profile)); - return; - } - ProcessWatcher::EnsureProcessGetsReaped(handle); -} - -/////////////////////////////////////////////////////////////////////////////// -// TranslateSection - -class TranslateSection : public OptionsPageBase { - public: - explicit TranslateSection(Profile* profile); - virtual ~TranslateSection() {} - - GtkWidget* get_page_widget() const { - return page_; - } - - private: - // Overridden from OptionsPageBase. - virtual void NotifyPrefChanged(const std::string* pref_name); - - CHROMEGTK_CALLBACK_0(TranslateSection, void, OnTranslateClicked); - - // Preferences for this section: - BooleanPrefMember enable_translate_; - - // The widget containing the options for this section. - GtkWidget* page_; - - // The checkbox. - GtkWidget* translate_checkbox_; - - // Flag to ignore gtk callbacks while we are loading prefs, to avoid - // then turning around and saving them again. - bool pref_changing_; - - DISALLOW_COPY_AND_ASSIGN(TranslateSection); -}; - -TranslateSection::TranslateSection(Profile* profile) - : OptionsPageBase(profile), - pref_changing_(true) { - page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - translate_checkbox_ = CreateCheckButtonWithWrappedLabel( - IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE); - gtk_box_pack_start(GTK_BOX(page_), translate_checkbox_, - FALSE, FALSE, 0); - g_signal_connect(translate_checkbox_, "clicked", - G_CALLBACK(OnTranslateClickedThunk), this); - - // Init member prefs so we can update the controls if prefs change. - enable_translate_.Init(prefs::kEnableTranslate, profile->GetPrefs(), this); - - NotifyPrefChanged(NULL); -} - -void TranslateSection::NotifyPrefChanged(const std::string* pref_name) { - pref_changing_ = true; - if (!pref_name || *pref_name == prefs::kEnableTranslate) { - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(translate_checkbox_), enable_translate_.GetValue()); - } - pref_changing_ = false; -} - -void TranslateSection::OnTranslateClicked(GtkWidget* widget) { - if (pref_changing_) - return; - bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - UserMetricsRecordAction( - enabled ? - UserMetricsAction("Options_Translate_Enable") : - UserMetricsAction("Options_Translate_Disable"), - profile()->GetPrefs()); - enable_translate_.SetValue(enabled); -} - -/////////////////////////////////////////////////////////////////////////////// -// PrivacySection - -class PrivacySection : public OptionsPageBase { - public: - explicit PrivacySection(Profile* profile); - virtual ~PrivacySection() {} - - GtkWidget* get_page_widget() const { - return page_; - } - - private: - // Overridden from OptionsPageBase. - virtual void NotifyPrefChanged(const std::string* pref_name); - - // Try to make the the crash stats consent and the metrics upload - // permission match the |reporting_enabled_checkbox_|. - void ResolveMetricsReportingEnabled(); - - // The callback functions for the options widgets. - static void OnContentSettingsClicked(GtkButton* button, - PrivacySection* privacy_section); - static void OnClearBrowsingDataButtonClicked(GtkButton* widget, - PrivacySection* page); - static void OnLearnMoreLinkClicked(GtkButton *button, - PrivacySection* privacy_section); - static void OnEnableLinkDoctorChange(GtkWidget* widget, - PrivacySection* options_window); - static void OnEnableSuggestChange(GtkWidget* widget, - PrivacySection* options_window); - static void OnDNSPrefetchingChange(GtkWidget* widget, - PrivacySection* options_window); - static void OnSafeBrowsingChange(GtkWidget* widget, - PrivacySection* options_window); - static void OnLoggingChange(GtkWidget* widget, - PrivacySection* options_window); - - // The widget containing the options for this section. - GtkWidget* page_; - - // The widgets for the privacy options. - GtkWidget* enable_link_doctor_checkbox_; - GtkWidget* enable_suggest_checkbox_; - GtkWidget* enable_dns_prefetching_checkbox_; - GtkWidget* enable_safe_browsing_checkbox_; -#if defined(GOOGLE_CHROME_BUILD) - GtkWidget* reporting_enabled_checkbox_; -#endif - - // Preferences for this section: - BooleanPrefMember alternate_error_pages_; - BooleanPrefMember use_suggest_; - BooleanPrefMember dns_prefetch_enabled_; - BooleanPrefMember safe_browsing_; - BooleanPrefMember enable_metrics_recording_; - - // Flag to ignore gtk callbacks while we are loading prefs, to avoid - // then turning around and saving them again. - bool pref_changing_; - - DISALLOW_COPY_AND_ASSIGN(PrivacySection); -}; - -PrivacySection::PrivacySection(Profile* profile) - : OptionsPageBase(profile), - pref_changing_(true) { - page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - GtkWidget* content_button = gtk_button_new_with_label( - l10n_util::GetStringUTF8( - IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON).c_str()); - g_signal_connect(content_button, "clicked", - G_CALLBACK(OnContentSettingsClicked), this); - - GtkWidget* clear_data_button = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON).c_str()); - g_signal_connect(clear_data_button, "clicked", - G_CALLBACK(OnClearBrowsingDataButtonClicked), this); - - // Stick it in an hbox so it doesn't expand to the whole width. - GtkWidget* button_hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(button_hbox), content_button, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(button_hbox), clear_data_button, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(page_), gtk_util::IndentWidget(button_hbox), - FALSE, FALSE, 0); - - GtkWidget* section_description_label = CreateWrappedLabel( - IDS_OPTIONS_DISABLE_SERVICES); - gtk_misc_set_alignment(GTK_MISC(section_description_label), 0, 0); - gtk_box_pack_start(GTK_BOX(page_), section_description_label, - FALSE, FALSE, 0); - - GtkWidget* learn_more_link = gtk_chrome_link_button_new( - l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); - // Stick it in an hbox so it doesn't expand to the whole width. - GtkWidget* learn_more_hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(learn_more_hbox), learn_more_link, - FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(page_), learn_more_hbox, - FALSE, FALSE, 0); - g_signal_connect(learn_more_link, "clicked", - G_CALLBACK(OnLearnMoreLinkClicked), this); - - enable_link_doctor_checkbox_ = CreateCheckButtonWithWrappedLabel( - IDS_OPTIONS_LINKDOCTOR_PREF); - gtk_box_pack_start(GTK_BOX(page_), enable_link_doctor_checkbox_, - FALSE, FALSE, 0); - g_signal_connect(enable_link_doctor_checkbox_, "clicked", - G_CALLBACK(OnEnableLinkDoctorChange), this); - - enable_suggest_checkbox_ = CreateCheckButtonWithWrappedLabel( - IDS_OPTIONS_SUGGEST_PREF); - gtk_box_pack_start(GTK_BOX(page_), enable_suggest_checkbox_, - FALSE, FALSE, 0); - g_signal_connect(enable_suggest_checkbox_, "clicked", - G_CALLBACK(OnEnableSuggestChange), this); - - enable_dns_prefetching_checkbox_ = CreateCheckButtonWithWrappedLabel( - IDS_NETWORK_DNS_PREFETCH_ENABLED_DESCRIPTION); - gtk_box_pack_start(GTK_BOX(page_), enable_dns_prefetching_checkbox_, - FALSE, FALSE, 0); - g_signal_connect(enable_dns_prefetching_checkbox_, "clicked", - G_CALLBACK(OnDNSPrefetchingChange), this); - - enable_safe_browsing_checkbox_ = CreateCheckButtonWithWrappedLabel( - IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION); - gtk_box_pack_start(GTK_BOX(page_), enable_safe_browsing_checkbox_, - FALSE, FALSE, 0); - g_signal_connect(enable_safe_browsing_checkbox_, "clicked", - G_CALLBACK(OnSafeBrowsingChange), this); - -#if defined(GOOGLE_CHROME_BUILD) - reporting_enabled_checkbox_ = CreateCheckButtonWithWrappedLabel( - IDS_OPTIONS_ENABLE_LOGGING); - gtk_box_pack_start(GTK_BOX(page_), reporting_enabled_checkbox_, - FALSE, FALSE, 0); - g_signal_connect(reporting_enabled_checkbox_, "clicked", - G_CALLBACK(OnLoggingChange), this); -#endif - - // Init member prefs so we can update the controls if prefs change. - alternate_error_pages_.Init(prefs::kAlternateErrorPagesEnabled, - profile->GetPrefs(), this); - use_suggest_.Init(prefs::kSearchSuggestEnabled, - profile->GetPrefs(), this); - dns_prefetch_enabled_.Init(prefs::kDnsPrefetchingEnabled, - profile->GetPrefs(), this); - safe_browsing_.Init(prefs::kSafeBrowsingEnabled, profile->GetPrefs(), this); - enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, - g_browser_process->local_state(), this); - NotifyPrefChanged(NULL); -} - -// static -void PrivacySection::OnContentSettingsClicked(GtkButton* button, - PrivacySection* privacy_section) { - ContentSettingsWindowGtk::Show( - GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), - CONTENT_SETTINGS_TYPE_DEFAULT, - privacy_section->profile()); -} - -// static -void PrivacySection::OnClearBrowsingDataButtonClicked(GtkButton* widget, - PrivacySection* section) { - ClearBrowsingDataDialogGtk::Show( - GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), - section->profile()); -} - -// static -void PrivacySection::OnLearnMoreLinkClicked(GtkButton *button, - PrivacySection* privacy_section) { - GURL url = google_util::AppendGoogleLocaleParam( - GURL(chrome::kPrivacyLearnMoreURL)); - browser::ShowOptionsURL(privacy_section->profile(), url); -} - -// static -void PrivacySection::OnEnableLinkDoctorChange(GtkWidget* widget, - PrivacySection* privacy_section) { - if (privacy_section->pref_changing_) - return; - bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - privacy_section->UserMetricsRecordAction( - enabled ? - UserMetricsAction("Options_LinkDoctorCheckbox_Enable") : - UserMetricsAction("Options_LinkDoctorCheckbox_Disable"), - privacy_section->profile()->GetPrefs()); - privacy_section->alternate_error_pages_.SetValue(enabled); -} - -// static -void PrivacySection::OnEnableSuggestChange(GtkWidget* widget, - PrivacySection* privacy_section) { - if (privacy_section->pref_changing_) - return; - bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - privacy_section->UserMetricsRecordAction( - enabled ? - UserMetricsAction("Options_UseSuggestCheckbox_Enable") : - UserMetricsAction("Options_UseSuggestCheckbox_Disable"), - privacy_section->profile()->GetPrefs()); - privacy_section->use_suggest_.SetValue(enabled); -} - -// static -void PrivacySection::OnDNSPrefetchingChange(GtkWidget* widget, - PrivacySection* privacy_section) { - if (privacy_section->pref_changing_) - return; - bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - privacy_section->UserMetricsRecordAction( - enabled ? - UserMetricsAction("Options_DnsPrefetchCheckbox_Enable") : - UserMetricsAction("Options_DnsPrefetchCheckbox_Disable"), - privacy_section->profile()->GetPrefs()); - privacy_section->dns_prefetch_enabled_.SetValue(enabled); -} - -// static -void PrivacySection::OnSafeBrowsingChange(GtkWidget* widget, - PrivacySection* privacy_section) { - if (privacy_section->pref_changing_) - return; - bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - privacy_section->UserMetricsRecordAction( - enabled ? - UserMetricsAction("Options_SafeBrowsingCheckbox_Enable") : - UserMetricsAction("Options_SafeBrowsingCheckbox_Disable"), - privacy_section->profile()->GetPrefs()); - privacy_section->safe_browsing_.SetValue(enabled); - SafeBrowsingService* safe_browsing_service = - g_browser_process->resource_dispatcher_host()->safe_browsing_service(); - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( - safe_browsing_service, &SafeBrowsingService::OnEnable, enabled)); -} - -// static -void PrivacySection::OnLoggingChange(GtkWidget* widget, - PrivacySection* privacy_section) { - if (privacy_section->pref_changing_) - return; - bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - privacy_section->UserMetricsRecordAction( - enabled ? - UserMetricsAction("Options_MetricsReportingCheckbox_Enable") : - UserMetricsAction("Options_MetricsReportingCheckbox_Disable"), - privacy_section->profile()->GetPrefs()); - // Prevent us from being called again by ResolveMetricsReportingEnabled - // resetting the checkbox if there was a problem. - g_signal_handlers_block_by_func(widget, - reinterpret_cast<gpointer>(OnLoggingChange), - privacy_section); - privacy_section->ResolveMetricsReportingEnabled(); - g_signal_handlers_unblock_by_func(widget, - reinterpret_cast<gpointer>(OnLoggingChange), - privacy_section); - privacy_section->enable_metrics_recording_.SetValue(enabled); -} - -void PrivacySection::NotifyPrefChanged(const std::string* pref_name) { - pref_changing_ = true; - if (!pref_name || *pref_name == prefs::kAlternateErrorPagesEnabled) { - gtk_widget_set_sensitive( - GTK_WIDGET(enable_link_doctor_checkbox_), - !alternate_error_pages_.IsManaged()); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(enable_link_doctor_checkbox_), - alternate_error_pages_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kSearchSuggestEnabled) { - gtk_widget_set_sensitive( - GTK_WIDGET(enable_suggest_checkbox_), - !use_suggest_.IsManaged()); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(enable_suggest_checkbox_), - use_suggest_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kDnsPrefetchingEnabled) { - gtk_widget_set_sensitive( - GTK_WIDGET(enable_dns_prefetching_checkbox_), - !dns_prefetch_enabled_.IsManaged()); - bool enabled = dns_prefetch_enabled_.GetValue(); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(enable_dns_prefetching_checkbox_), enabled); - } - if (!pref_name || *pref_name == prefs::kSafeBrowsingEnabled) { - gtk_widget_set_sensitive( - GTK_WIDGET(enable_safe_browsing_checkbox_), - !safe_browsing_.IsManaged()); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(enable_safe_browsing_checkbox_), - safe_browsing_.GetValue()); - } -#if defined(GOOGLE_CHROME_BUILD) - if (!pref_name || *pref_name == prefs::kMetricsReportingEnabled) { - gtk_widget_set_sensitive( - GTK_WIDGET(reporting_enabled_checkbox_), - !enable_metrics_recording_.IsManaged()); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(reporting_enabled_checkbox_), - enable_metrics_recording_.GetValue()); - ResolveMetricsReportingEnabled(); - } -#endif - pref_changing_ = false; -} - -void PrivacySection::ResolveMetricsReportingEnabled() { -#if defined(GOOGLE_CHROME_BUILD) - bool enabled = gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(reporting_enabled_checkbox_)); - - enabled = OptionsUtil::ResolveMetricsReportingEnabled(enabled); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(reporting_enabled_checkbox_), - enabled); -#endif -} - -/////////////////////////////////////////////////////////////////////////////// -// SecuritySection - -class SecuritySection : public OptionsPageBase { - public: - explicit SecuritySection(Profile* profile); - virtual ~SecuritySection() {} - - GtkWidget* get_page_widget() const { - return page_; - } - - private: - // Overridden from OptionsPageBase. - virtual void NotifyPrefChanged(const std::string* pref_name); - - // The callback functions for the options widgets. - static void OnManageCertificatesClicked(GtkButton* button, - SecuritySection* section); - static void OnRevCheckingEnabledToggled(GtkToggleButton* togglebutton, - SecuritySection* section); - static void OnSSL3EnabledToggled(GtkToggleButton* togglebutton, - SecuritySection* section); - static void OnTLS1EnabledToggled(GtkToggleButton* togglebutton, - SecuritySection* section); - - // The widget containing the options for this section. - GtkWidget* page_; - GtkWidget* rev_checking_enabled_checkbox_; - GtkWidget* ssl3_enabled_checkbox_; - GtkWidget* tls1_enabled_checkbox_; - - // SSLConfigService prefs. - BooleanPrefMember rev_checking_enabled_; - BooleanPrefMember ssl3_enabled_; - BooleanPrefMember tls1_enabled_; - - // Flag to ignore gtk callbacks while we are loading prefs, to avoid - // then turning around and saving them again. - bool pref_changing_; - - DISALLOW_COPY_AND_ASSIGN(SecuritySection); -}; - -SecuritySection::SecuritySection(Profile* profile) - : OptionsPageBase(profile), - pref_changing_(true) { - page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - GtkWidget* manage_certificates_label = CreateWrappedLabel( - IDS_OPTIONS_CERTIFICATES_LABEL); - gtk_misc_set_alignment(GTK_MISC(manage_certificates_label), 0, 0); - gtk_box_pack_start(GTK_BOX(page_), manage_certificates_label, - FALSE, FALSE, 0); - - // TODO(mattm): change this to a button to launch the system certificate - // manager, when one exists. - GtkWidget* manage_certificates_link = gtk_chrome_link_button_new( - l10n_util::GetStringUTF8(IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON).c_str()); - // Stick it in an hbox so it doesn't expand to the whole width. - GtkWidget* manage_certificates_hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(manage_certificates_hbox), - manage_certificates_link, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(page_), - gtk_util::IndentWidget(manage_certificates_hbox), - FALSE, FALSE, 0); - g_signal_connect(manage_certificates_link, "clicked", - G_CALLBACK(OnManageCertificatesClicked), this); - - // TODO(mattm): should have a description label here and have the checkboxes - // indented, but IDS_OPTIONS_SSL_GROUP_DESCRIPTION isn't appropriate and - // didn't think of adding a Linux specific one before the string freeze. - rev_checking_enabled_checkbox_ = AddCheckButtonWithWrappedLabel( - IDS_OPTIONS_SSL_CHECKREVOCATION, page_, - G_CALLBACK(OnRevCheckingEnabledToggled), this); - ssl3_enabled_checkbox_ = AddCheckButtonWithWrappedLabel( - IDS_OPTIONS_SSL_USESSL3, page_, G_CALLBACK(OnSSL3EnabledToggled), this); - tls1_enabled_checkbox_ = AddCheckButtonWithWrappedLabel( - IDS_OPTIONS_SSL_USETLS1, page_, G_CALLBACK(OnTLS1EnabledToggled), this); - - rev_checking_enabled_.Init(prefs::kCertRevocationCheckingEnabled, - profile->GetPrefs(), this); - ssl3_enabled_.Init(prefs::kSSL3Enabled, profile->GetPrefs(), this); - tls1_enabled_.Init(prefs::kTLS1Enabled, profile->GetPrefs(), this); - - NotifyPrefChanged(NULL); -} - -void SecuritySection::NotifyPrefChanged(const std::string* pref_name) { - pref_changing_ = true; - if (!pref_name || *pref_name == prefs::kCertRevocationCheckingEnabled) { - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(rev_checking_enabled_checkbox_), - rev_checking_enabled_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kSSL3Enabled) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ssl3_enabled_checkbox_), - ssl3_enabled_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kTLS1Enabled) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tls1_enabled_checkbox_), - tls1_enabled_.GetValue()); - } - pref_changing_ = false; -} - - -// static -void SecuritySection::OnManageCertificatesClicked(GtkButton* button, - SecuritySection* section) { - browser::ShowOptionsURL(section->profile(), - GURL(kLinuxCertificatesConfigUrl)); -} - -// static -void SecuritySection::OnRevCheckingEnabledToggled(GtkToggleButton* togglebutton, - SecuritySection* section) { - if (section->pref_changing_) - return; - - bool enabled = gtk_toggle_button_get_active(togglebutton); - if (enabled) { - section->UserMetricsRecordAction( - UserMetricsAction("Options_CheckCertRevocation_Enable"), - NULL); - } else { - section->UserMetricsRecordAction( - UserMetricsAction("Options_CheckCertRevocation_Disable"), - NULL); - } - section->rev_checking_enabled_.SetValue(enabled); -} - -// static -void SecuritySection::OnSSL3EnabledToggled(GtkToggleButton* togglebutton, - SecuritySection* section) { - if (section->pref_changing_) - return; - - bool enabled = gtk_toggle_button_get_active(togglebutton); - if (enabled) { - section->UserMetricsRecordAction(UserMetricsAction("Options_SSL3_Enable"), - NULL); - } else { - section->UserMetricsRecordAction(UserMetricsAction("Options_SSL3_Disable"), - NULL); - } - section->ssl3_enabled_.SetValue(enabled); -} - -// static -void SecuritySection::OnTLS1EnabledToggled(GtkToggleButton* togglebutton, - SecuritySection* section) { - if (section->pref_changing_) - return; - - bool enabled = gtk_toggle_button_get_active(togglebutton); - if (enabled) { - section->UserMetricsRecordAction(UserMetricsAction("Options_TLS1_Enable"), - NULL); - } else { - section->UserMetricsRecordAction(UserMetricsAction("Options_TLS1_Disable"), - NULL); - } - section->tls1_enabled_.SetValue(enabled); -} - -/////////////////////////////////////////////////////////////////////////////// -// WebContentSection - -class WebContentSection : public OptionsPageBase { - public: - explicit WebContentSection(Profile* profile); - virtual ~WebContentSection() {} - - GtkWidget* get_page_widget() const { - return page_; - } - - private: - // The callback functions for the options widgets. - static void OnFontsAndLanguagesButtonClicked(GtkButton *button, - WebContentSection* section); - - // The widget containing the options for this section. - GtkWidget* page_; - - DISALLOW_COPY_AND_ASSIGN(WebContentSection); -}; - -WebContentSection::WebContentSection(Profile* profile) - : OptionsPageBase(profile) { - page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - GtkWidget* fonts_and_languages_label = CreateWrappedLabel( - IDS_OPTIONS_FONTSETTINGS_INFO); - gtk_misc_set_alignment(GTK_MISC(fonts_and_languages_label), 0, 0); - gtk_box_pack_start(GTK_BOX(page_), fonts_and_languages_label, - FALSE, FALSE, 0); - - GtkWidget* fonts_and_languages_button = gtk_button_new_with_label( - l10n_util::GetStringUTF8( - IDS_OPTIONS_FONTSETTINGS_CONFIGUREFONTS_BUTTON).c_str()); - g_signal_connect(fonts_and_languages_button, "clicked", - G_CALLBACK(OnFontsAndLanguagesButtonClicked), this); - // Stick it in an hbox so it doesn't expand to the whole width. - GtkWidget* button_hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(button_hbox), - fonts_and_languages_button, - FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(page_), - gtk_util::IndentWidget(button_hbox), - FALSE, FALSE, 0); - - // TODO(mattm): gears options would go here if we supported gears -} - -// static -void WebContentSection::OnFontsAndLanguagesButtonClicked( - GtkButton *button, WebContentSection* section) { - ShowFontsLanguagesWindow(GTK_WINDOW(gtk_widget_get_toplevel(section->page_)), - FONTS_ENCODING_PAGE, - section->profile()); -} - -/////////////////////////////////////////////////////////////////////////////// -// AdvancedContentsGtk - -AdvancedContentsGtk::AdvancedContentsGtk(Profile* profile) - : profile_(profile) { - Init(); -} - -AdvancedContentsGtk::~AdvancedContentsGtk() { -} - -void AdvancedContentsGtk::Init() { - scoped_ptr<OptionsLayoutBuilderGtk> - options_builder(OptionsLayoutBuilderGtk::Create()); - - privacy_section_.reset(new PrivacySection(profile_)); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY), - privacy_section_->get_page_widget(), false); - - network_section_.reset(new NetworkSection(profile_)); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK), - network_section_->get_page_widget(), false); - - translate_section_.reset(new TranslateSection(profile_)); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_TRANSLATE), - translate_section_->get_page_widget(), false); - - download_section_.reset(new DownloadSection(profile_)); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME), - download_section_->get_page_widget(), false); - - web_content_section_.reset(new WebContentSection(profile_)); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT), - web_content_section_->get_page_widget(), false); - - security_section_.reset(new SecuritySection(profile_)); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY), - security_section_->get_page_widget(), false); - - page_ = options_builder->get_page_widget(); -} diff --git a/chrome/browser/ui/gtk/options/advanced_contents_gtk.h b/chrome/browser/ui/gtk/options/advanced_contents_gtk.h deleted file mode 100644 index b1d6485..0000000 --- a/chrome/browser/ui/gtk/options/advanced_contents_gtk.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_ADVANCED_CONTENTS_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_ADVANCED_CONTENTS_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include "base/basictypes.h" -#include "base/scoped_ptr.h" - -class Profile; -class DownloadSection; -class NetworkSection; -class PrivacySection; -class SecuritySection; -class TranslateSection; -class WebContentSection; - -class AdvancedContentsGtk { - public: - explicit AdvancedContentsGtk(Profile* profile); - virtual ~AdvancedContentsGtk(); - - GtkWidget* get_page_widget() const { - return page_; - } - - private: - void Init(); - - // The profile. - Profile* profile_; - - // The sections of the page. - scoped_ptr<DownloadSection> download_section_; - scoped_ptr<NetworkSection> network_section_; - scoped_ptr<TranslateSection> translate_section_; - scoped_ptr<PrivacySection> privacy_section_; - scoped_ptr<SecuritySection> security_section_; - scoped_ptr<WebContentSection> web_content_section_; - - // The widget containing the advanced options sections. - GtkWidget* page_; - - DISALLOW_COPY_AND_ASSIGN(AdvancedContentsGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_ADVANCED_CONTENTS_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/advanced_page_gtk.cc b/chrome/browser/ui/gtk/options/advanced_page_gtk.cc deleted file mode 100644 index 3c7c354..0000000 --- a/chrome/browser/ui/gtk/options/advanced_page_gtk.cc +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/advanced_page_gtk.h" - -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/options/options_util.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - -AdvancedPageGtk::AdvancedPageGtk(Profile* profile) - : OptionsPageBase(profile), - advanced_contents_(profile), - managed_prefs_banner_(profile->GetPrefs(), OPTIONS_PAGE_ADVANCED) { - Init(); -} - -AdvancedPageGtk::~AdvancedPageGtk() { -} - -void AdvancedPageGtk::Init() { - page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - gtk_container_set_border_width(GTK_CONTAINER(page_), - gtk_util::kContentAreaBorder); - - gtk_box_pack_start(GTK_BOX(page_), managed_prefs_banner_.banner_widget(), - false, false, 0); - - GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); - gtk_container_add(GTK_CONTAINER(page_), scroll_window); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), - GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC); - // Note that typically we call gtk_scrolled_window_set_shadow_type right - // here, but the add_with_viewport method of GtkScrolledWindow already adds - // its own shadow. - gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll_window), - advanced_contents_.get_page_widget()); - - GtkWidget* button_box = gtk_hbutton_box_new(); - gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_END); - GtkWidget* reset_button = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_OPTIONS_RESET).c_str()); - g_signal_connect(reset_button, "clicked", - G_CALLBACK(OnResetToDefaultsClickedThunk), this); - gtk_container_add(GTK_CONTAINER(button_box), reset_button); - gtk_box_pack_start(GTK_BOX(page_), button_box, FALSE, FALSE, 0); -} - -void AdvancedPageGtk::OnResetToDefaultsClicked(GtkWidget* button) { - UserMetricsRecordAction(UserMetricsAction("Options_ResetToDefaults"), NULL); - GtkWidget* dialog_ = gtk_message_dialog_new( - GTK_WINDOW(gtk_widget_get_toplevel(page_)), - static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL), - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - "%s", - l10n_util::GetStringUTF8(IDS_OPTIONS_RESET_MESSAGE).c_str()); - gtk_util::ApplyMessageDialogQuirks(dialog_); - gtk_dialog_add_buttons( - GTK_DIALOG(dialog_), - l10n_util::GetStringUTF8(IDS_OPTIONS_RESET_CANCELLABEL).c_str(), - GTK_RESPONSE_CANCEL, - l10n_util::GetStringUTF8(IDS_OPTIONS_RESET_OKLABEL).c_str(), - GTK_RESPONSE_OK, - NULL); - gtk_window_set_title(GTK_WINDOW(dialog_), - l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str()); - g_signal_connect(dialog_, "response", - G_CALLBACK(OnResetToDefaultsResponseThunk), this); - - gtk_util::ShowDialog(dialog_); -} - -void AdvancedPageGtk::OnResetToDefaultsResponse(GtkWidget* dialog, - int response_id) { - if (response_id == GTK_RESPONSE_OK) { - OptionsUtil::ResetToDefaults(profile()); - } - gtk_widget_destroy(dialog); -} diff --git a/chrome/browser/ui/gtk/options/advanced_page_gtk.h b/chrome/browser/ui/gtk/options/advanced_page_gtk.h deleted file mode 100644 index 39277ef..0000000 --- a/chrome/browser/ui/gtk/options/advanced_page_gtk.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_ADVANCED_PAGE_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_ADVANCED_PAGE_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/gtk/options/advanced_contents_gtk.h" -#include "chrome/browser/ui/gtk/options/managed_prefs_banner_gtk.h" -#include "chrome/browser/ui/options/options_page_base.h" -#include "ui/base/gtk/gtk_signal.h" - -class Profile; - -class AdvancedPageGtk : public OptionsPageBase { - public: - explicit AdvancedPageGtk(Profile* profile); - virtual ~AdvancedPageGtk(); - - GtkWidget* get_page_widget() const { - return page_; - } - - private: - void Init(); - - // Callback for reset to default button. - CHROMEGTK_CALLBACK_0(AdvancedPageGtk, void, OnResetToDefaultsClicked); - - // Callback for reset to default confirmation dialog. - CHROMEGTK_CALLBACK_1(AdvancedPageGtk, void, OnResetToDefaultsResponse, int); - - // The contents of the scroll box. - AdvancedContentsGtk advanced_contents_; - - // The widget containing the options for this page. - GtkWidget* page_; - - // Tracks managed preference warning banner state. - ManagedPrefsBannerGtk managed_prefs_banner_; - - DISALLOW_COPY_AND_ASSIGN(AdvancedPageGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_ADVANCED_PAGE_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/content_exception_editor.cc b/chrome/browser/ui/gtk/options/content_exception_editor.cc deleted file mode 100644 index e31078c..0000000 --- a/chrome/browser/ui/gtk/options/content_exception_editor.cc +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/content_exception_editor.h" - -#include "base/message_loop.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/content_exceptions_table_model.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "grit/app_resources.h" -#include "grit/generated_resources.h" -#include "grit/theme_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" - -ContentExceptionEditor::ContentExceptionEditor( - GtkWindow* parent, - ContentExceptionEditor::Delegate* delegate, - ContentExceptionsTableModel* model, - bool allow_off_the_record, - int index, - const ContentSettingsPattern& pattern, - ContentSetting setting, - bool is_off_the_record) - : delegate_(delegate), - model_(model), - cb_model_(model->content_type()), - index_(index), - pattern_(pattern), - setting_(setting) { - dialog_ = gtk_dialog_new_with_buttons( - l10n_util::GetStringUTF8(is_new() ? - IDS_EXCEPTION_EDITOR_NEW_TITLE : - IDS_EXCEPTION_EDITOR_TITLE).c_str(), - parent, - // Non-modal. - static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - NULL); - gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_OK); - - entry_ = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(entry_), pattern_.AsString().c_str()); - g_signal_connect(entry_, "changed", G_CALLBACK(OnEntryChangedThunk), this); - gtk_entry_set_activates_default(GTK_ENTRY(entry_), TRUE); - - pattern_image_ = gtk_image_new_from_pixbuf(NULL); - - action_combo_ = gtk_combo_box_new_text(); - for (int i = 0; i < cb_model_.GetItemCount(); ++i) { - gtk_combo_box_append_text(GTK_COMBO_BOX(action_combo_), - UTF16ToUTF8(cb_model_.GetItemAt(i)).c_str()); - } - gtk_combo_box_set_active(GTK_COMBO_BOX(action_combo_), - cb_model_.IndexForSetting(setting_)); - - otr_checkbox_ = gtk_check_button_new_with_label( - l10n_util::GetStringUTF8(IDS_EXCEPTION_EDITOR_OTR_TITLE).c_str()); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(otr_checkbox_), - is_off_the_record); - - GtkWidget* table = gtk_util::CreateLabeledControlsGroup( - NULL, - l10n_util::GetStringUTF8(IDS_EXCEPTION_EDITOR_PATTERN_TITLE).c_str(), - gtk_util::CreateEntryImageHBox(entry_, pattern_image_), - l10n_util::GetStringUTF8(IDS_EXCEPTION_EDITOR_ACTION_TITLE).c_str(), - action_combo_, - NULL); - if (allow_off_the_record) { - gtk_table_attach(GTK_TABLE(table), otr_checkbox_, - 0, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 0); - } - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), table, - FALSE, FALSE, 0); - - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), - gtk_util::kContentAreaSpacing); - - // Prime the state of the buttons. - OnEntryChanged(entry_); - - gtk_util::ShowDialog(dialog_); - - g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); - g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); -} - -bool ContentExceptionEditor::IsPatternValid( - const ContentSettingsPattern& pattern, - bool is_off_the_record) const { - bool is_valid_pattern = pattern.IsValid() && - (model_->IndexOfExceptionByPattern(pattern, is_off_the_record) == -1); - - return is_new() ? is_valid_pattern : (!pattern.AsString().empty() && - ((pattern_ == pattern) || is_valid_pattern)); -} - -void ContentExceptionEditor::UpdateImage(GtkWidget* image, bool is_valid) { - return gtk_image_set_from_pixbuf(GTK_IMAGE(image), - ResourceBundle::GetSharedInstance().GetPixbufNamed( - is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT)); -} - -void ContentExceptionEditor::OnEntryChanged(GtkWidget* entry) { - ContentSettingsPattern new_pattern(gtk_entry_get_text(GTK_ENTRY(entry))); - bool is_off_the_record = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(otr_checkbox_)); - bool is_valid = IsPatternValid(new_pattern, is_off_the_record); - gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_), - GTK_RESPONSE_OK, is_valid); - UpdateImage(pattern_image_, is_valid); -} - -void ContentExceptionEditor::OnResponse(GtkWidget* dialog, int response_id) { - if (response_id == GTK_RESPONSE_OK) { - // Notify our delegate to update everything. - ContentSettingsPattern new_pattern(gtk_entry_get_text(GTK_ENTRY(entry_))); - ContentSetting setting = cb_model_.SettingForIndex( - gtk_combo_box_get_active(GTK_COMBO_BOX(action_combo_))); - bool is_off_the_record = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(otr_checkbox_)); - delegate_->AcceptExceptionEdit( - new_pattern, setting, is_off_the_record, index_, is_new()); - } - - gtk_widget_destroy(dialog_); -} - -void ContentExceptionEditor::OnWindowDestroy(GtkWidget* widget) { - MessageLoop::current()->DeleteSoon(FROM_HERE, this); -} diff --git a/chrome/browser/ui/gtk/options/content_exception_editor.h b/chrome/browser/ui/gtk/options/content_exception_editor.h deleted file mode 100644 index 6839838..0000000 --- a/chrome/browser/ui/gtk/options/content_exception_editor.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_EXCEPTION_EDITOR_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_EXCEPTION_EDITOR_H_ -#pragma once - -#include <gtk/gtk.h> - -#include "chrome/browser/content_exceptions_table_model.h" -#include "chrome/browser/content_setting_combo_model.h" -#include "chrome/common/content_settings.h" -#include "chrome/common/content_settings_types.h" -#include "ui/base/gtk/gtk_signal.h" - -// An editor which lets the user create or edit an individual exception to the -// current content setting policy. (i.e. let www.google.com always show -// images). Modal to parent. -class ContentExceptionEditor { - public: - class Delegate { - public: - // Invoked when the user accepts the edit. - virtual void AcceptExceptionEdit( - const ContentSettingsPattern& pattern, - ContentSetting setting, - bool is_off_the_record, - int index, - bool is_new) = 0; - - protected: - virtual ~Delegate() {} - }; - - ContentExceptionEditor(GtkWindow* parent, - Delegate* delegate, - ContentExceptionsTableModel* model, - bool allow_off_the_record, - int index, - const ContentSettingsPattern& pattern, - ContentSetting setting, - bool is_off_the_record); - virtual ~ContentExceptionEditor() {} - - private: - // Returns true if we're adding a new item. - bool is_new() const { return index_ == -1; } - - bool IsPatternValid(const ContentSettingsPattern& pattern, - bool is_off_the_record) const; - - void UpdateImage(GtkWidget* image, bool is_valid); - - // GTK callbacks - CHROMEGTK_CALLBACK_0(ContentExceptionEditor, void, OnEntryChanged); - CHROMEGTK_CALLBACK_1(ContentExceptionEditor, void, OnResponse, int); - CHROMEGTK_CALLBACK_0(ContentExceptionEditor, void, OnWindowDestroy); - - Delegate* delegate_; - ContentExceptionsTableModel* model_; - - // The model for Combobox widget. - ContentSettingComboModel cb_model_; - - // Index of the item being edited. If -1, indicates this is a new entry. - const int index_; - const ContentSettingsPattern pattern_; - const ContentSetting setting_; - - // UI widgets. - GtkWidget* dialog_; - GtkWidget* entry_; - GtkWidget* pattern_image_; - GtkWidget* action_combo_; - GtkWidget* otr_checkbox_; - - DISALLOW_COPY_AND_ASSIGN(ContentExceptionEditor); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_EXCEPTION_EDITOR_H_ diff --git a/chrome/browser/ui/gtk/options/content_exceptions_window_gtk.cc b/chrome/browser/ui/gtk/options/content_exceptions_window_gtk.cc deleted file mode 100644 index a3edcf0..0000000 --- a/chrome/browser/ui/gtk/options/content_exceptions_window_gtk.cc +++ /dev/null @@ -1,336 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/content_exceptions_window_gtk.h" - -#include <set> - -#include "base/message_loop.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/options/content_exception_editor.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/gtk_util.h" - -namespace { - -// Singletons for each possible exception window. -ContentExceptionsWindowGtk* instances[CONTENT_SETTINGS_NUM_TYPES] = { NULL }; - -} // namespace - -// static -void ContentExceptionsWindowGtk::ShowExceptionsWindow( - GtkWindow* parent, - HostContentSettingsMap* map, - HostContentSettingsMap* off_the_record_map, - ContentSettingsType type) { - DCHECK(map); - DCHECK(type < CONTENT_SETTINGS_NUM_TYPES); - // Geolocation exceptions are handled by SimpleContentExceptionsWindow. - DCHECK_NE(type, CONTENT_SETTINGS_TYPE_GEOLOCATION); - // Notification exceptions are handled by SimpleContentExceptionsWindow. - DCHECK_NE(type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); - - if (!instances[type]) { - // Create the options window. - instances[type] = - new ContentExceptionsWindowGtk(parent, map, off_the_record_map, type); - } else { - gtk_util::PresentWindow(instances[type]->dialog_, 0); - } -} - -ContentExceptionsWindowGtk::~ContentExceptionsWindowGtk() { -} - -ContentExceptionsWindowGtk::ContentExceptionsWindowGtk( - GtkWindow* parent, - HostContentSettingsMap* map, - HostContentSettingsMap* off_the_record_map, - ContentSettingsType type) - : allow_off_the_record_(off_the_record_map) { - // Build the list backing that GTK uses, along with an adapter which will - // sort stuff without changing the underlying backing store. - list_store_ = gtk_list_store_new(COL_COUNT, G_TYPE_STRING, G_TYPE_STRING, - PANGO_TYPE_STYLE); - sort_list_store_ = gtk_tree_model_sort_new_with_model( - GTK_TREE_MODEL(list_store_)); - treeview_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(sort_list_store_)); - g_object_unref(list_store_); - g_object_unref(sort_list_store_); - - // Set up the properties of the treeview - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview_), TRUE); - g_signal_connect(treeview_, "row-activated", - G_CALLBACK(OnTreeViewRowActivateThunk), this); - - GtkTreeViewColumn* pattern_column = gtk_tree_view_column_new_with_attributes( - l10n_util::GetStringUTF8(IDS_EXCEPTIONS_PATTERN_HEADER).c_str(), - gtk_cell_renderer_text_new(), - "text", COL_PATTERN, - "style", COL_OTR, - NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_), pattern_column); - gtk_tree_view_column_set_sort_column_id(pattern_column, COL_PATTERN); - - GtkTreeViewColumn* action_column = gtk_tree_view_column_new_with_attributes( - l10n_util::GetStringUTF8(IDS_EXCEPTIONS_ACTION_HEADER).c_str(), - gtk_cell_renderer_text_new(), - "text", COL_ACTION, - "style", COL_OTR, - NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_), action_column); - gtk_tree_view_column_set_sort_column_id(action_column, COL_ACTION); - - treeview_selection_ = gtk_tree_view_get_selection( - GTK_TREE_VIEW(treeview_)); - gtk_tree_selection_set_mode(treeview_selection_, GTK_SELECTION_MULTIPLE); - g_signal_connect(treeview_selection_, "changed", - G_CALLBACK(OnTreeSelectionChangedThunk), this); - - // Bind |list_store_| to our C++ model. - model_.reset(new ContentExceptionsTableModel(map, off_the_record_map, type)); - model_adapter_.reset(new gtk_tree::TableAdapter(this, list_store_, - model_.get())); - // Force a reload of everything to copy data into |list_store_|. - model_adapter_->OnModelChanged(); - - dialog_ = gtk_dialog_new_with_buttons( - GetWindowTitle().c_str(), - parent, - static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE, - NULL); - gtk_window_set_default_size(GTK_WINDOW(dialog_), 500, -1); - // Allow browser windows to go in front of the options dialog in metacity. - gtk_window_set_type_hint(GTK_WINDOW(dialog_), GDK_WINDOW_TYPE_HINT_NORMAL); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), - gtk_util::kContentAreaSpacing); - - GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), hbox); - - GtkWidget* treeview_box = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - // Create a scrolled window to wrap the treeview widget. - GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), - GTK_SHADOW_ETCHED_IN); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_container_add(GTK_CONTAINER(scrolled), treeview_); - gtk_box_pack_start(GTK_BOX(treeview_box), scrolled, TRUE, TRUE, 0); - - // If we also have an OTR profile, inform the user that OTR exceptions are - // displayed in italics. - if (allow_off_the_record_) { - GtkWidget* incognito_label = gtk_label_new( - l10n_util::GetStringUTF8(IDS_EXCEPTIONS_OTR_IN_ITALICS).c_str()); - PangoAttrList* attributes = pango_attr_list_new(); - pango_attr_list_insert(attributes, - pango_attr_style_new(PANGO_STYLE_ITALIC)); - gtk_label_set_attributes(GTK_LABEL(incognito_label), attributes); - pango_attr_list_unref(attributes); - gtk_misc_set_alignment(GTK_MISC(incognito_label), 0, 0); - gtk_box_pack_start(GTK_BOX(treeview_box), incognito_label, FALSE, FALSE, 0); - } - - gtk_box_pack_start(GTK_BOX(hbox), treeview_box, TRUE, TRUE, 0); - - GtkWidget* button_box = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - GtkWidget* add_button = gtk_util::BuildDialogButton(dialog_, - IDS_EXCEPTIONS_ADD_BUTTON, - GTK_STOCK_ADD); - g_signal_connect(add_button, "clicked", G_CALLBACK(AddThunk), this); - gtk_box_pack_start(GTK_BOX(button_box), add_button, FALSE, FALSE, 0); - - edit_button_ = gtk_util::BuildDialogButton(dialog_, - IDS_EXCEPTIONS_EDIT_BUTTON, - GTK_STOCK_EDIT); - g_signal_connect(edit_button_, "clicked", G_CALLBACK(EditThunk), this); - gtk_box_pack_start(GTK_BOX(button_box), edit_button_, FALSE, FALSE, 0); - - remove_button_ = gtk_util::BuildDialogButton(dialog_, - IDS_EXCEPTIONS_REMOVE_BUTTON, - GTK_STOCK_REMOVE); - g_signal_connect(remove_button_, "clicked", G_CALLBACK(RemoveThunk), this); - gtk_box_pack_start(GTK_BOX(button_box), remove_button_, FALSE, FALSE, 0); - - remove_all_button_ = gtk_util::BuildDialogButton( - dialog_, - IDS_EXCEPTIONS_REMOVEALL_BUTTON, - GTK_STOCK_CLEAR); - g_signal_connect(remove_all_button_, "clicked", G_CALLBACK(RemoveAllThunk), - this); - gtk_box_pack_start(GTK_BOX(button_box), remove_all_button_, FALSE, FALSE, 0); - - gtk_box_pack_start(GTK_BOX(hbox), button_box, FALSE, FALSE, 0); - - UpdateButtonState(); - - gtk_util::ShowDialogWithLocalizedSize(dialog_, - IDS_CONTENT_EXCEPTION_DIALOG_WIDTH_CHARS, - -1, - true); - - g_signal_connect(dialog_, "response", G_CALLBACK(gtk_widget_destroy), NULL); - g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); -} - -void ContentExceptionsWindowGtk::SetColumnValues(int row, GtkTreeIter* iter) { - string16 pattern = model_->GetText(row, IDS_EXCEPTIONS_PATTERN_HEADER); - gtk_list_store_set(list_store_, iter, COL_PATTERN, - UTF16ToUTF8(pattern).c_str(), -1); - - string16 action = model_->GetText(row, IDS_EXCEPTIONS_ACTION_HEADER); - gtk_list_store_set(list_store_, iter, COL_ACTION, - UTF16ToUTF8(action).c_str(), -1); - - bool is_off_the_record = model_->entry_is_off_the_record(row); - PangoStyle style = - is_off_the_record ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL; - gtk_list_store_set(list_store_, iter, COL_OTR, style, -1); -} - -void ContentExceptionsWindowGtk::AcceptExceptionEdit( - const ContentSettingsPattern& pattern, - ContentSetting setting, - bool is_off_the_record, - int index, - bool is_new) { - DCHECK(!is_off_the_record || allow_off_the_record_); - - if (!is_new) - model_->RemoveException(index); - - model_->AddException(pattern, setting, is_off_the_record); - - int new_index = model_->IndexOfExceptionByPattern(pattern, is_off_the_record); - DCHECK_NE(-1, new_index); - - gtk_tree::SelectAndFocusRowNum(new_index, GTK_TREE_VIEW(treeview_)); - - UpdateButtonState(); -} - -void ContentExceptionsWindowGtk::UpdateButtonState() { - int num_selected = gtk_tree_selection_count_selected_rows( - treeview_selection_); - int row_count = gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(sort_list_store_), NULL); - - // TODO(erg): http://crbug.com/34177 , support editing of more than one entry - // at a time. - gtk_widget_set_sensitive(edit_button_, num_selected == 1); - gtk_widget_set_sensitive(remove_button_, num_selected >= 1); - gtk_widget_set_sensitive(remove_all_button_, row_count > 0); -} - -void ContentExceptionsWindowGtk::Add(GtkWidget* widget) { - new ContentExceptionEditor(GTK_WINDOW(dialog_), - this, model_.get(), allow_off_the_record_, -1, - ContentSettingsPattern(), - CONTENT_SETTING_BLOCK, false); -} - -void ContentExceptionsWindowGtk::Edit(GtkWidget* widget) { - std::set<std::pair<int, int> > indices; - GetSelectedModelIndices(&indices); - DCHECK_GT(indices.size(), 0u); - int index = indices.begin()->first; - const HostContentSettingsMap::PatternSettingPair& entry = - model_->entry_at(index); - new ContentExceptionEditor(GTK_WINDOW(dialog_), this, model_.get(), - allow_off_the_record_, index, - entry.first, entry.second, - model_->entry_is_off_the_record(index)); -} - -void ContentExceptionsWindowGtk::Remove(GtkWidget* widget) { - std::set<std::pair<int, int> > model_selected_indices; - GetSelectedModelIndices(&model_selected_indices); - - int selected_row = gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(sort_list_store_), NULL); - for (std::set<std::pair<int, int> >::reverse_iterator i = - model_selected_indices.rbegin(); - i != model_selected_indices.rend(); ++i) { - model_->RemoveException(i->first); - selected_row = std::min(selected_row, i->second); - } - - int row_count = model_->RowCount(); - if (row_count <= 0) - return; - if (selected_row >= row_count) - selected_row = row_count - 1; - gtk_tree::SelectAndFocusRowNum(selected_row, - GTK_TREE_VIEW(treeview_)); - - UpdateButtonState(); -} - -void ContentExceptionsWindowGtk::RemoveAll(GtkWidget* widget) { - model_->RemoveAll(); - UpdateButtonState(); -} - -std::string ContentExceptionsWindowGtk::GetWindowTitle() const { - switch (model_->content_type()) { - case CONTENT_SETTINGS_TYPE_COOKIES: - return l10n_util::GetStringUTF8(IDS_COOKIE_EXCEPTION_TITLE); - case CONTENT_SETTINGS_TYPE_IMAGES: - return l10n_util::GetStringUTF8(IDS_IMAGES_EXCEPTION_TITLE); - case CONTENT_SETTINGS_TYPE_JAVASCRIPT: - return l10n_util::GetStringUTF8(IDS_JS_EXCEPTION_TITLE); - case CONTENT_SETTINGS_TYPE_PLUGINS: - return l10n_util::GetStringUTF8(IDS_PLUGINS_EXCEPTION_TITLE); - case CONTENT_SETTINGS_TYPE_POPUPS: - return l10n_util::GetStringUTF8(IDS_POPUP_EXCEPTION_TITLE); - default: - NOTREACHED(); - } - return std::string(); -} - -void ContentExceptionsWindowGtk::GetSelectedModelIndices( - std::set<std::pair<int, int> >* indices) { - GtkTreeModel* model; - GList* paths = gtk_tree_selection_get_selected_rows(treeview_selection_, - &model); - for (GList* item = paths; item; item = item->next) { - GtkTreePath* sorted_path = reinterpret_cast<GtkTreePath*>(item->data); - int sorted_row = gtk_tree::GetRowNumForPath(sorted_path); - GtkTreePath* path = gtk_tree_model_sort_convert_path_to_child_path( - GTK_TREE_MODEL_SORT(sort_list_store_), sorted_path); - int row = gtk_tree::GetRowNumForPath(path); - gtk_tree_path_free(path); - indices->insert(std::make_pair(row, sorted_row)); - } - - g_list_foreach(paths, (GFunc)gtk_tree_path_free, NULL); - g_list_free(paths); -} - -void ContentExceptionsWindowGtk::OnTreeViewRowActivate( - GtkWidget* sender, - GtkTreePath* path, - GtkTreeViewColumn* column) { - Edit(sender); -} - -void ContentExceptionsWindowGtk::OnWindowDestroy(GtkWidget* widget) { - instances[model_->content_type()] = NULL; - MessageLoop::current()->DeleteSoon(FROM_HERE, this); -} - -void ContentExceptionsWindowGtk::OnTreeSelectionChanged( - GtkWidget* selection) { - UpdateButtonState(); -} diff --git a/chrome/browser/ui/gtk/options/content_exceptions_window_gtk.h b/chrome/browser/ui/gtk/options/content_exceptions_window_gtk.h deleted file mode 100644 index 2f1940e..0000000 --- a/chrome/browser/ui/gtk/options/content_exceptions_window_gtk.h +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_EXCEPTIONS_WINDOW_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_EXCEPTIONS_WINDOW_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include <string> - -#include "base/scoped_ptr.h" -#include "chrome/browser/content_exceptions_table_model.h" -#include "chrome/browser/ui/gtk/gtk_tree.h" -#include "chrome/browser/ui/gtk/options/content_exception_editor.h" -#include "chrome/common/content_settings.h" -#include "chrome/common/content_settings_types.h" -#include "ui/base/gtk/gtk_signal.h" - -class HostContentSettingsMap; - -// Dialog that lists each of the exceptions to the current content policy, and -// has options for adding/editing/removing entries. Modal to parrent. -class ContentExceptionsWindowGtk : public gtk_tree::TableAdapter::Delegate, - public ContentExceptionEditor::Delegate { - public: - static void ShowExceptionsWindow(GtkWindow* window, - HostContentSettingsMap* map, - HostContentSettingsMap* off_the_record_map, - ContentSettingsType content_type); - - ~ContentExceptionsWindowGtk(); - - // gtk_tree::TableAdapter::Delegate implementation: - virtual void SetColumnValues(int row, GtkTreeIter* iter); - - // ContentExceptionEditor::Delegate implementation: - virtual void AcceptExceptionEdit( - const ContentSettingsPattern& pattern, - ContentSetting setting, - bool is_off_the_record, - int index, - bool is_new); - - private: - // Column ids for |list_store_|. - enum { - COL_PATTERN, - COL_ACTION, - COL_OTR, - COL_COUNT - }; - - ContentExceptionsWindowGtk(GtkWindow* parent, - HostContentSettingsMap* map, - HostContentSettingsMap* off_the_record_map, - ContentSettingsType type); - - // Updates which buttons are enabled. - void UpdateButtonState(); - - // Callbacks for the buttons. - CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void, Add); - CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void, Edit); - CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void, Remove); - CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void, RemoveAll); - - // Returns the title of the window (changes based on what ContentSettingsType - // was set to in the constructor). - std::string GetWindowTitle() const; - - // Gets the selected indicies in the two list stores. Indicies are returned - // in <list_store_, sort_list_store_> order. - void GetSelectedModelIndices(std::set<std::pair<int, int> >* indices); - - // GTK Callbacks - CHROMEGTK_CALLBACK_2(ContentExceptionsWindowGtk, void, - OnTreeViewRowActivate, GtkTreePath*, GtkTreeViewColumn*); - CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void, OnWindowDestroy); - CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void, - OnTreeSelectionChanged); - - // The list presented in |treeview_|. Separate from |list_store_|, the list - // that backs |sort_model_|. This separation comes so the user can sort the - // data on screen without changing the underlying |list_store_|. - GtkTreeModel* sort_list_store_; - - // The backing to |sort_list_store_|. Doesn't change when sorted. - GtkListStore* list_store_; - - // The C++, views-ish, cross-platform model class that actually contains the - // gold standard data. - scoped_ptr<ContentExceptionsTableModel> model_; - - // True if we also show exceptions from an OTR profile. - bool allow_off_the_record_; - - // The adapter that ferries data back and forth between |model_| and - // |list_store_| whenever either of them change. - scoped_ptr<gtk_tree::TableAdapter> model_adapter_; - - // The exception window. - GtkWidget* dialog_; - - // The treeview that presents the site/action pairs. - GtkWidget* treeview_; - - // The current user selection from |treeview_|. - GtkTreeSelection* treeview_selection_; - - // Buttons. - GtkWidget* edit_button_; - GtkWidget* remove_button_; - GtkWidget* remove_all_button_; - - friend class ContentExceptionsWindowGtkUnittest; -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_EXCEPTIONS_WINDOW_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/content_exceptions_window_gtk_unittest.cc b/chrome/browser/ui/gtk/options/content_exceptions_window_gtk_unittest.cc deleted file mode 100644 index 16b8f0c..0000000 --- a/chrome/browser/ui/gtk/options/content_exceptions_window_gtk_unittest.cc +++ /dev/null @@ -1,211 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/content_exceptions_window_gtk.h" - -#include "chrome/test/testing_profile.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" - -using ::testing::ElementsAre; - -class ContentExceptionsWindowGtkUnittest : public testing::Test { - public: - ContentExceptionsWindowGtkUnittest() - : ui_thread_(BrowserThread::UI, &message_loop_), - host_content_settings_map_(profile_.GetHostContentSettingsMap()), - window_(NULL) { - } - - ~ContentExceptionsWindowGtkUnittest() { - // This will delete window_ too. - gtk_widget_destroy(window_->dialog_); - message_loop_.RunAllPending(); - } - - void AddException(const std::string& pattern, ContentSetting value) { - host_content_settings_map_->SetContentSetting( - ContentSettingsPattern(pattern), - CONTENT_SETTINGS_TYPE_JAVASCRIPT, - "", - value); - } - - void BuildWindow() { - window_ = new ContentExceptionsWindowGtk( - NULL, - host_content_settings_map_, - NULL, - CONTENT_SETTINGS_TYPE_JAVASCRIPT); - } - - // Actions: - void SelectRows(const std::vector<int>& rows) { - gtk_tree_selection_unselect_all(window_->treeview_selection_); - - for (std::vector<int>::const_iterator it = rows.begin(); it != rows.end(); - ++it) { - GtkTreeIter iter; - if (!gtk_tree_model_iter_nth_child(window_->sort_list_store_, - &iter, NULL, *it)) { - NOTREACHED(); - return; - } - - gtk_tree_selection_select_iter(window_->treeview_selection_, &iter); - } - } - - void Remove() { - window_->Remove(window_->remove_button_); - } - - // Getters: - - void GetSelectedRows(std::set<std::pair<int, int> >* selected) { - window_->GetSelectedModelIndices(selected); - } - - int StoreListStoreCount() { - return gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(window_->sort_list_store_), NULL); - } - - int ListStoreCount() { - return gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(window_->list_store_), NULL); - } - - std::set<std::string> Paths() { - std::set<std::string> paths; - GtkTreeIter iter; - bool valid = gtk_tree_model_get_iter_first( - GTK_TREE_MODEL(window_->sort_list_store_), &iter); - - while (valid) { - gchar* str = NULL; - gtk_tree_model_get(GTK_TREE_MODEL(window_->sort_list_store_), &iter, - 0, &str, -1); - paths.insert(str); - g_free(str); - - valid = gtk_tree_model_iter_next( - GTK_TREE_MODEL(window_->sort_list_store_), &iter); - } - - return paths; - } - - // Whether certain widgets are enabled: - bool EditButtonSensitive() { - return GTK_WIDGET_SENSITIVE(window_->edit_button_); - } - - bool RemoveButtonSensitive() { - return GTK_WIDGET_SENSITIVE(window_->remove_button_); - } - - bool RemoveAllSensitive() { - return GTK_WIDGET_SENSITIVE(window_->remove_all_button_); - } - - private: - MessageLoop message_loop_; - BrowserThread ui_thread_; - - TestingProfile profile_; - HostContentSettingsMap* host_content_settings_map_; - - ContentExceptionsWindowGtk* window_; -}; - -TEST_F(ContentExceptionsWindowGtkUnittest, TestEmptyDisplay) { - BuildWindow(); - - EXPECT_EQ(0, StoreListStoreCount()); - EXPECT_EQ(0, ListStoreCount()); - - EXPECT_FALSE(RemoveAllSensitive()); -} - -TEST_F(ContentExceptionsWindowGtkUnittest, TestDisplay) { - AddException("a", CONTENT_SETTING_BLOCK); - AddException("b", CONTENT_SETTING_ALLOW); - - BuildWindow(); - - EXPECT_EQ(2, StoreListStoreCount()); - EXPECT_EQ(2, ListStoreCount()); - - EXPECT_TRUE(RemoveAllSensitive()); -} - -TEST_F(ContentExceptionsWindowGtkUnittest, TestSelection) { - AddException("a", CONTENT_SETTING_BLOCK); - - BuildWindow(); - - EXPECT_FALSE(EditButtonSensitive()); - EXPECT_FALSE(RemoveButtonSensitive()); - - std::vector<int> rows; - rows.push_back(0); - SelectRows(rows); - - EXPECT_TRUE(EditButtonSensitive()); - EXPECT_TRUE(RemoveButtonSensitive()); -} - -TEST_F(ContentExceptionsWindowGtkUnittest, TestSimpleRemoval) { - AddException("a", CONTENT_SETTING_BLOCK); - AddException("b", CONTENT_SETTING_ALLOW); - AddException("c", CONTENT_SETTING_BLOCK); - AddException("d", CONTENT_SETTING_ALLOW); - - BuildWindow(); - - std::vector<int> rows; - rows.push_back(1); - SelectRows(rows); - - Remove(); - - EXPECT_EQ(3, StoreListStoreCount()); - EXPECT_EQ(3, ListStoreCount()); - EXPECT_TRUE(EditButtonSensitive()); - EXPECT_TRUE(RemoveButtonSensitive()); - - std::set<std::pair<int, int> > selected; - GetSelectedRows(&selected); - - ASSERT_EQ(1u, selected.size()); - EXPECT_EQ(1, selected.begin()->first); - EXPECT_EQ(1, selected.begin()->second); - EXPECT_THAT(Paths(), ElementsAre("a", "c", "d")); -} - -TEST_F(ContentExceptionsWindowGtkUnittest, TestComplexRemoval) { - AddException("a", CONTENT_SETTING_BLOCK); - AddException("b", CONTENT_SETTING_ALLOW); - AddException("c", CONTENT_SETTING_BLOCK); - AddException("d", CONTENT_SETTING_ALLOW); - AddException("e", CONTENT_SETTING_BLOCK); - - BuildWindow(); - - std::vector<int> rows; - rows.push_back(1); - rows.push_back(3); - SelectRows(rows); - - Remove(); - - std::set<std::pair<int, int> > selected; - GetSelectedRows(&selected); - - ASSERT_EQ(1u, selected.size()); - EXPECT_EQ(1, selected.begin()->first); - EXPECT_EQ(1, selected.begin()->second); - EXPECT_THAT(Paths(), ElementsAre("a", "c", "e")); -} diff --git a/chrome/browser/ui/gtk/options/content_filter_page_gtk.cc b/chrome/browser/ui/gtk/options/content_filter_page_gtk.cc deleted file mode 100644 index 6de0638..0000000 --- a/chrome/browser/ui/gtk/options/content_filter_page_gtk.cc +++ /dev/null @@ -1,319 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/content_filter_page_gtk.h" - -#include "base/command_line.h" -#include "chrome/browser/content_settings/content_settings_details.h" -#include "chrome/browser/content_settings/content_settings_pattern.h" -#include "chrome/browser/geolocation/geolocation_content_settings_map.h" -#include "chrome/browser/geolocation/geolocation_exceptions_table_model.h" -#include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/notification_exceptions_table_model.h" -#include "chrome/browser/plugin_exceptions_table_model.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/gtk/browser_window_gtk.h" -#include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/options/content_exceptions_window_gtk.h" -#include "chrome/browser/ui/gtk/options/simple_content_exceptions_window.h" -#include "chrome/browser/ui/options/show_options_url.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/url_constants.h" -#include "content/common/notification_details.h" -#include "content/common/notification_service.h" -#include "content/common/notification_type.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" - -ContentFilterPageGtk::ContentFilterPageGtk(Profile* profile, - ContentSettingsType content_type) - : OptionsPageBase(profile), - content_type_(content_type), - ask_radio_(NULL), - ignore_toggle_(false) { - static const int kTitleIDs[] = { - 0, // This dialog isn't used for cookies. - IDS_IMAGES_SETTING_LABEL, - IDS_JS_SETTING_LABEL, - IDS_PLUGIN_SETTING_LABEL, - IDS_POPUP_SETTING_LABEL, - IDS_GEOLOCATION_SETTING_LABEL, - IDS_NOTIFICATIONS_SETTING_LABEL, - 0, // This dialog isn't used for prerender. - }; - COMPILE_ASSERT(arraysize(kTitleIDs) == CONTENT_SETTINGS_NUM_TYPES, - kTitleIDs_IncorrectSize); - - GtkWidget* title_label = gtk_util::CreateBoldLabel( - l10n_util::GetStringUTF8(kTitleIDs[content_type_])); - page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(page_), title_label, FALSE, FALSE, 0); - gtk_container_add(GTK_CONTAINER(page_), InitGroup()); -} - -ContentFilterPageGtk::~ContentFilterPageGtk() { -} - - -GtkWidget* ContentFilterPageGtk::InitGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - static const int kAllowIDs[] = { - 0, // This dialog isn't used for cookies. - IDS_IMAGES_LOAD_RADIO, - IDS_JS_ALLOW_RADIO, - IDS_PLUGIN_LOAD_RADIO, - IDS_POPUP_ALLOW_RADIO, - IDS_GEOLOCATION_ALLOW_RADIO, - IDS_NOTIFICATIONS_ALLOW_RADIO, - 0, // This dialog isn't used for prerender. - }; - COMPILE_ASSERT(arraysize(kAllowIDs) == CONTENT_SETTINGS_NUM_TYPES, - kAllowIDs_IncorrectSize); - allow_radio_ = gtk_radio_button_new_with_label(NULL, - l10n_util::GetStringUTF8(kAllowIDs[content_type_]).c_str()); - gtk_box_pack_start(GTK_BOX(vbox), allow_radio_, FALSE, FALSE, 0); - - static const int kAskIDs[] = { - 0, // This dialog isn't used for cookies. - 0, - 0, - IDS_PLUGIN_ASK_RADIO, - 0, - IDS_GEOLOCATION_ASK_RADIO, - IDS_NOTIFICATIONS_ASK_RADIO, - 0, // This dialog isn't used for prerender. - }; - COMPILE_ASSERT(arraysize(kAskIDs) == CONTENT_SETTINGS_NUM_TYPES, - kAskIDs_IncorrectSize); - int askID = kAskIDs[content_type_]; - if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS && - !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableClickToPlay)) { - askID = 0; - } - - if (askID) { - ask_radio_ = gtk_radio_button_new_with_label_from_widget( - GTK_RADIO_BUTTON(allow_radio_), - l10n_util::GetStringUTF8(askID).c_str()); - gtk_box_pack_start(GTK_BOX(vbox), ask_radio_, FALSE, FALSE, 0); - } - - static const int kBlockIDs[] = { - 0, // This dialog isn't used for cookies. - IDS_IMAGES_NOLOAD_RADIO, - IDS_JS_DONOTALLOW_RADIO, - IDS_PLUGIN_NOLOAD_RADIO, - IDS_POPUP_BLOCK_RADIO, - IDS_GEOLOCATION_BLOCK_RADIO, - IDS_NOTIFICATIONS_BLOCK_RADIO, - 0, // This dialog isn't used for prerender. - }; - COMPILE_ASSERT(arraysize(kBlockIDs) == CONTENT_SETTINGS_NUM_TYPES, - kBlockIDs_IncorrectSize); - block_radio_ = gtk_radio_button_new_with_label_from_widget( - GTK_RADIO_BUTTON(allow_radio_), - l10n_util::GetStringUTF8(kBlockIDs[content_type_]).c_str()); - gtk_box_pack_start(GTK_BOX(vbox), block_radio_, FALSE, FALSE, 0); - - exceptions_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_COOKIES_EXCEPTIONS_BUTTON).c_str()); - GtkWidget* hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(hbox), exceptions_button_, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); - - g_signal_connect(G_OBJECT(allow_radio_), "toggled", - G_CALLBACK(OnAllowToggledThunk), this); - if (ask_radio_) { - g_signal_connect(G_OBJECT(ask_radio_), "toggled", - G_CALLBACK(OnAllowToggledThunk), this); - } - g_signal_connect(G_OBJECT(block_radio_), "toggled", - G_CALLBACK(OnAllowToggledThunk), this); - - g_signal_connect(G_OBJECT(exceptions_button_), "clicked", - G_CALLBACK(OnExceptionsClickedThunk), this); - - // Add the "Disable individual plug-ins..." link on the plug-ins page. - if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS) { - GtkWidget* plugins_page_link = gtk_chrome_link_button_new( - l10n_util::GetStringUTF8(IDS_PLUGIN_SELECTIVE_DISABLE).c_str()); - g_signal_connect(G_OBJECT(plugins_page_link), "clicked", - G_CALLBACK(OnPluginsPageLinkClickedThunk), this); - - hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(hbox), plugins_page_link, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); - } - - // Now that the buttons have been added to the view hierarchy, it's safe to - // call SetChecked() on them. So Update the Buttons. - ignore_toggle_ = true; - UpdateButtonsState(); - ignore_toggle_ = false; - - // Register for CONTENT_SETTINGS_CHANGED notifications to update the UI - // aften content settings change. - registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED, - NotificationService::AllSources()); - registrar_.Add(this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, - NotificationService::AllSources()); - registrar_.Add(this, NotificationType::GEOLOCATION_SETTINGS_CHANGED, - NotificationService::AllSources()); - - return vbox; -} - -void ContentFilterPageGtk::UpdateButtonsState() { - // Get default_setting. - ContentSetting default_setting; - // If the content setting is managed, sensitive is set to false and the radio - // buttons will be disabled. - bool sensitive = true; - if (content_type_ == CONTENT_SETTINGS_TYPE_GEOLOCATION) { - default_setting = profile()->GetGeolocationContentSettingsMap()-> - GetDefaultContentSetting(); - sensitive = !profile()->GetGeolocationContentSettingsMap()-> - IsDefaultContentSettingManaged(); - } else if (content_type_ == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { - default_setting = profile()->GetDesktopNotificationService()-> - GetDefaultContentSetting(); - sensitive = !profile()->GetDesktopNotificationService()-> - IsDefaultContentSettingManaged(); - } else { - default_setting = profile()->GetHostContentSettingsMap()-> - GetDefaultContentSetting(content_type_); - sensitive = !profile()->GetHostContentSettingsMap()-> - IsDefaultContentSettingManaged(content_type_); - } - // Set UI state. - if (default_setting == CONTENT_SETTING_ALLOW) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(allow_radio_), TRUE); - } else if (default_setting == CONTENT_SETTING_ASK) { - DCHECK(ask_radio_); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ask_radio_), TRUE); - } else { - DCHECK(default_setting == CONTENT_SETTING_BLOCK); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(block_radio_), TRUE); - } - - // Disable the UI if the default content setting is managed. - gtk_widget_set_sensitive(allow_radio_, sensitive); - gtk_widget_set_sensitive(block_radio_, sensitive); - if (ask_radio_) - gtk_widget_set_sensitive(ask_radio_, sensitive); - gtk_widget_set_sensitive(exceptions_button_, sensitive); -} - -void ContentFilterPageGtk::OnAllowToggled(GtkWidget* toggle_button) { - if (ignore_toggle_) - return; - - if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button))) { - // When selecting a radio button, we get two signals (one for the old radio - // being toggled off, one for the new one being toggled on.) Ignore the - // signal for toggling off the old button. - return; - } - - DCHECK((toggle_button == allow_radio_) || - (toggle_button == ask_radio_) || - (toggle_button == block_radio_)); - - ContentSetting default_setting = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(allow_radio_)) ? - CONTENT_SETTING_ALLOW : - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(block_radio_)) ? - CONTENT_SETTING_BLOCK : CONTENT_SETTING_ASK; - - DCHECK(ask_radio_ || default_setting != CONTENT_SETTING_ASK); - if (content_type_ == CONTENT_SETTINGS_TYPE_GEOLOCATION) { - profile()->GetGeolocationContentSettingsMap()->SetDefaultContentSetting( - default_setting); - } else if (content_type_ == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { - profile()->GetDesktopNotificationService()->SetDefaultContentSetting( - default_setting); - } else { - profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( - content_type_, default_setting); - } -} - -void ContentFilterPageGtk::OnExceptionsClicked(GtkWidget* button) { - if (content_type_ == CONTENT_SETTINGS_TYPE_GEOLOCATION) { - SimpleContentExceptionsWindow::ShowExceptionsWindow( - GTK_WINDOW(gtk_widget_get_toplevel(button)), - new GeolocationExceptionsTableModel( - profile()->GetGeolocationContentSettingsMap()), - IDS_GEOLOCATION_EXCEPTION_TITLE); - return; - } - if (content_type_ == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { - SimpleContentExceptionsWindow::ShowExceptionsWindow( - GTK_WINDOW(gtk_widget_get_toplevel(button)), - new NotificationExceptionsTableModel( - profile()->GetDesktopNotificationService()), - IDS_NOTIFICATIONS_EXCEPTION_TITLE); - return; - } - HostContentSettingsMap* settings_map = - profile()->GetHostContentSettingsMap(); - HostContentSettingsMap* otr_settings_map = - profile()->HasOffTheRecordProfile() ? - profile()->GetOffTheRecordProfile()->GetHostContentSettingsMap() : - NULL; - if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS && - CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableResourceContentSettings)) { - PluginExceptionsTableModel* model = - new PluginExceptionsTableModel(settings_map, otr_settings_map); - model->LoadSettings(); - SimpleContentExceptionsWindow::ShowExceptionsWindow( - GTK_WINDOW(gtk_widget_get_toplevel(button)), - model, - IDS_PLUGINS_EXCEPTION_TITLE); - return; - } - ContentExceptionsWindowGtk::ShowExceptionsWindow( - GTK_WINDOW(gtk_widget_get_toplevel(button)), - settings_map, otr_settings_map, content_type_); -} - -void ContentFilterPageGtk::OnPluginsPageLinkClicked(GtkWidget* button) { - browser::ShowOptionsURL(profile(), GURL(chrome::kChromeUIPluginsURL)); -} - -void ContentFilterPageGtk::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::CONTENT_SETTINGS_CHANGED) { - NotifyContentSettingsChanged( - Details<const ContentSettingsDetails>(details).ptr()); - } else if (type == NotificationType::GEOLOCATION_SETTINGS_CHANGED) { - NotifyContentSettingsChanged( - Details<const ContentSettingsDetails>(details).ptr()); - } else if (type == NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED) { - ContentSettingsDetails content_settings_details( - ContentSettingsPattern(), - CONTENT_SETTINGS_TYPE_NOTIFICATIONS, - ""); - NotifyContentSettingsChanged(&content_settings_details); - } else { - OptionsPageBase::Observe(type, source, details); - } -} - -void ContentFilterPageGtk::NotifyContentSettingsChanged( - const ContentSettingsDetails *details) { - if (details->type() == CONTENT_SETTINGS_TYPE_DEFAULT || - details->type() == content_type_) { - ignore_toggle_ = true; - UpdateButtonsState(); - ignore_toggle_ = false; - } -} diff --git a/chrome/browser/ui/gtk/options/content_filter_page_gtk.h b/chrome/browser/ui/gtk/options/content_filter_page_gtk.h deleted file mode 100644 index 83ff178..0000000 --- a/chrome/browser/ui/gtk/options/content_filter_page_gtk.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_FILTER_PAGE_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_FILTER_PAGE_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/ui/options/options_page_base.h" -#include "chrome/common/content_settings.h" -#include "chrome/common/content_settings_types.h" -#include "content/common/notification_registrar.h" -#include "ui/base/gtk/gtk_signal.h" - -class ContentSettingsDetails; - -// A page in the content settings window. Used for everything but the Cookies -// page (which has a much more complex dialog). A |content_type| is passed into -// the constructor and the correct strings and settings are used. -class ContentFilterPageGtk : public OptionsPageBase { - public: - ContentFilterPageGtk(Profile* profile, ContentSettingsType content_type); - virtual ~ContentFilterPageGtk(); - - GtkWidget* get_page_widget() const { - return page_; - } - - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - private: - // This method is called during initialization to set the initial state of the - // buttons and called after a default content setting change (either value - // change or "is managed" state). - virtual void UpdateButtonsState(); - - virtual void NotifyContentSettingsChanged( - const ContentSettingsDetails* details); - - // Builds the content of the dialog. - GtkWidget* InitGroup(); - - CHROMEGTK_CALLBACK_0(ContentFilterPageGtk, void, OnAllowToggled); - CHROMEGTK_CALLBACK_0(ContentFilterPageGtk, void, OnExceptionsClicked); - CHROMEGTK_CALLBACK_0(ContentFilterPageGtk, void, OnPluginsPageLinkClicked); - - ContentSettingsType content_type_; - - GtkWidget* page_; - - // Controls for the content filter tab page. - GtkWidget* allow_radio_; - GtkWidget* ask_radio_; - GtkWidget* block_radio_; - - GtkWidget* exceptions_button_; - - NotificationRegistrar registrar_; - - // If state of the UI is not changed by a user-action we need to ignore - // "toggled" events. - bool ignore_toggle_; - - DISALLOW_COPY_AND_ASSIGN(ContentFilterPageGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_FILTER_PAGE_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/content_page_gtk.cc b/chrome/browser/ui/gtk/options/content_page_gtk.cc deleted file mode 100644 index 8c4bed2..0000000 --- a/chrome/browser/ui/gtk/options/content_page_gtk.cc +++ /dev/null @@ -1,586 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/content_page_gtk.h" - -#include <string> - -#include "base/command_line.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/defaults.h" -#include "chrome/browser/importer/importer_data_types.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/sync_ui_util.h" -#include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" -#include "chrome/browser/ui/gtk/gtk_theme_provider.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/importer/import_dialog_gtk.h" -#include "chrome/browser/ui/gtk/options/options_layout_gtk.h" -#include "chrome/browser/ui/gtk/options/passwords_exceptions_window_gtk.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "content/common/notification_service.h" -#include "grit/app_resources.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/gtk_util.h" - -namespace { - -// Background color for the status label when it's showing an error. -static const GdkColor kSyncLabelErrorBgColor = GDK_COLOR_RGB(0xff, 0x9a, 0x9a); - -// Helper for WrapLabelAtAllocationHack. -void OnLabelAllocate(GtkWidget* label, GtkAllocation* allocation) { - gtk_util::SetLabelWidth(label, allocation->width); - - // Disconnect ourselves. Repeatedly resizing based on allocation causes - // the dialog to become unshrinkable. - g_signal_handlers_disconnect_by_func( - label, reinterpret_cast<gpointer>(OnLabelAllocate), NULL); -} - -// Set the label to use a request size equal to its initial allocation -// size. This causes the label to wrap at the width of the container -// it is in, instead of at the default width. This is called a hack -// because GTK doesn't really work when a widget to make its size -// request depend on its allocation. It does, however, have the -// intended effect of wrapping the label at the proper width. -void WrapLabelAtAllocationHack(GtkWidget* label) { - g_signal_connect(label, "size-allocate", - G_CALLBACK(OnLabelAllocate), NULL); -} - -} // anonymous namespace - -/////////////////////////////////////////////////////////////////////////////// -// ContentPageGtk, public: - -ContentPageGtk::ContentPageGtk(Profile* profile) - : OptionsPageBase(profile), - sync_status_label_background_(NULL), - sync_status_label_(NULL), - sync_action_link_background_(NULL), - sync_action_link_(NULL), - sync_start_stop_button_(NULL), - sync_customize_button_(NULL), - privacy_dashboard_link_(NULL), - initializing_(true), - sync_service_(NULL), - managed_prefs_banner_(profile->GetPrefs(), OPTIONS_PAGE_CONTENT) { - if (profile->GetProfileSyncService()) { - sync_service_ = profile->GetProfileSyncService(); - sync_service_->AddObserver(this); - } - - // Prepare the group options layout. - scoped_ptr<OptionsLayoutBuilderGtk> - options_builder(OptionsLayoutBuilderGtk::CreateOptionallyCompactLayout()); - options_builder->AddWidget(managed_prefs_banner_.banner_widget(), false); - if (sync_service_) { - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_SYNC_OPTIONS_GROUP_NAME), - InitSyncGroup(), false); - UpdateSyncControls(); - } - - // Add preferences observers. - ask_to_save_passwords_.Init(prefs::kPasswordManagerEnabled, - profile->GetPrefs(), this); - form_autofill_enabled_.Init(prefs::kAutoFillEnabled, - profile->GetPrefs(), this); - if (browser_defaults::kCanToggleSystemTitleBar) { - use_custom_chrome_frame_.Init(prefs::kUseCustomChromeFrame, - profile->GetPrefs(), this); - } - - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_GROUP_NAME), - InitPasswordSavingGroup(), false); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_AUTOFILL_SETTING_WINDOWS_GROUP_NAME), - InitFormAutoFillGroup(), false); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_BROWSING_DATA_GROUP_NAME), - InitBrowsingDataGroup(), false); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_APPEARANCE_GROUP_NAME), - InitThemesGroup(), false); - page_ = options_builder->get_page_widget(); - - // Load initial values. - NotifyPrefChanged(NULL); - - registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, - NotificationService::AllSources()); - ObserveThemeChanged(); -} - -ContentPageGtk::~ContentPageGtk() { - if (sync_service_) - sync_service_->RemoveObserver(this); -} - -/////////////////////////////////////////////////////////////////////////////// -// ContentsPageView, ProfileSyncServiceObserver implementation: - -void ContentPageGtk::OnStateChanged() { - // If the UI controls are not yet initialized, then don't do anything. This - // can happen if the Options dialog is up, but the Content tab is not yet - // clicked. - if (!initializing_) - UpdateSyncControls(); -} - -/////////////////////////////////////////////////////////////////////////////// -// ContentPageGtk, private: - -// If |pref_name| is NULL, set the state of all the widgets. (This is used -// in ContentPageGtk() above to initialize the dialog.) Otherwise, reset the -// state of the widget for the given preference name, as it has changed. -void ContentPageGtk::NotifyPrefChanged(const std::string* pref_name) { - initializing_ = true; - if (!pref_name || *pref_name == prefs::kPasswordManagerEnabled) { - if (ask_to_save_passwords_.GetValue()) { - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(passwords_asktosave_radio_), TRUE); - } else { - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(passwords_neversave_radio_), TRUE); - } - bool isPasswordManagerEnabled = !ask_to_save_passwords_.IsManaged(); - gtk_widget_set_sensitive(passwords_asktosave_radio_, - isPasswordManagerEnabled); - gtk_widget_set_sensitive(passwords_neversave_radio_, - isPasswordManagerEnabled); - gtk_widget_set_sensitive(show_passwords_button_, - isPasswordManagerEnabled || - ask_to_save_passwords_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kAutoFillEnabled) { - bool disabled_by_policy = form_autofill_enabled_.IsManaged() && - !form_autofill_enabled_.GetValue(); - gtk_widget_set_sensitive(autofill_button_, !disabled_by_policy); - } - if (browser_defaults::kCanToggleSystemTitleBar && - (!pref_name || *pref_name == prefs::kUseCustomChromeFrame)) { - if (use_custom_chrome_frame_.GetValue()) { - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(system_title_bar_hide_radio_), TRUE); - } else { - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(system_title_bar_show_radio_), TRUE); - } - } - initializing_ = false; -} - -void ContentPageGtk::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::BROWSER_THEME_CHANGED) - ObserveThemeChanged(); - else - OptionsPageBase::Observe(type, source, details); -} - -void ContentPageGtk::ObserveThemeChanged() { -#if defined(TOOLKIT_GTK) - GtkThemeProvider* provider = GtkThemeProvider::GetFrom(profile()); - bool is_gtk_theme = provider->UseGtkTheme(); - gtk_widget_set_sensitive(gtk_theme_button_, !is_gtk_theme); -#else - BrowserThemeProvider* provider = - reinterpret_cast<BrowserThemeProvider*>(profile()->GetThemeProvider()); - bool is_gtk_theme = false; -#endif - - bool is_classic_theme = !is_gtk_theme && provider->UsingDefaultTheme(); - gtk_widget_set_sensitive(themes_reset_button_, !is_classic_theme); -} - -GtkWidget* ContentPageGtk::InitPasswordSavingGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - // Ask to save radio button. - passwords_asktosave_radio_ = gtk_radio_button_new_with_label(NULL, - l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_ASKTOSAVE).c_str()); - g_signal_connect(passwords_asktosave_radio_, "toggled", - G_CALLBACK(OnPasswordRadioToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), passwords_asktosave_radio_, FALSE, - FALSE, 0); - - // Never save radio button. - passwords_neversave_radio_ = gtk_radio_button_new_with_label_from_widget( - GTK_RADIO_BUTTON(passwords_asktosave_radio_), - l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_NEVERSAVE).c_str()); - g_signal_connect(passwords_neversave_radio_, "toggled", - G_CALLBACK(OnPasswordRadioToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), passwords_neversave_radio_, FALSE, - FALSE, 0); - - // Add the show passwords button into its own horizontal box so it does not - // depend on the spacing above. - GtkWidget* button_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); - gtk_container_add(GTK_CONTAINER(vbox), button_hbox); - show_passwords_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_SHOWPASSWORDS).c_str()); - g_signal_connect(show_passwords_button_, "clicked", - G_CALLBACK(OnShowPasswordsButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(button_hbox), show_passwords_button_, FALSE, - FALSE, 0); - - return vbox; -} - -GtkWidget* ContentPageGtk::InitFormAutoFillGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - GtkWidget* button_hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); - gtk_container_add(GTK_CONTAINER(vbox), button_hbox); - - // AutoFill button. - autofill_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_AUTOFILL_OPTIONS).c_str()); - - g_signal_connect(G_OBJECT(autofill_button_), "clicked", - G_CALLBACK(OnAutoFillButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(button_hbox), autofill_button_, FALSE, FALSE, 0); - - return vbox; -} - -GtkWidget* ContentPageGtk::InitBrowsingDataGroup() { - GtkWidget* button_box = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); - - // Import button. - GtkWidget* import_button = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_OPTIONS_IMPORT_DATA_BUTTON).c_str()); - g_signal_connect(import_button, "clicked", - G_CALLBACK(OnImportButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(button_box), import_button, FALSE, FALSE, 0); - - return button_box; -} - -GtkWidget* ContentPageGtk::InitThemesGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); - -#if defined(TOOLKIT_GTK) - // GTK theme button. - gtk_theme_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_THEMES_GTK_BUTTON).c_str()); - g_signal_connect(gtk_theme_button_, "clicked", - G_CALLBACK(OnGtkThemeButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(hbox), gtk_theme_button_, FALSE, FALSE, 0); -#endif - - // Reset theme button. - themes_reset_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_THEMES_SET_CLASSIC).c_str()); - g_signal_connect(themes_reset_button_, "clicked", - G_CALLBACK(OnResetDefaultThemeButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(hbox), themes_reset_button_, FALSE, FALSE, 0); - - // Get themes button. - GtkWidget* themes_gallery_button = gtk_chrome_link_button_new( - l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_BUTTON).c_str()); - g_signal_connect(themes_gallery_button, "clicked", - G_CALLBACK(OnGetThemesButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(hbox), themes_gallery_button, FALSE, FALSE, 0); - - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); - - // "Use system title bar and borders" radio buttons. - if (browser_defaults::kCanToggleSystemTitleBar) { - // Use system title bar and borders - system_title_bar_show_radio_ = gtk_radio_button_new_with_label(NULL, - l10n_util::GetStringUTF8(IDS_SHOW_WINDOW_DECORATIONS_RADIO).c_str()); - g_signal_connect(system_title_bar_show_radio_, "toggled", - G_CALLBACK(OnSystemTitleBarRadioToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), system_title_bar_show_radio_, FALSE, - FALSE, 0); - - // Hide system title bar and use custom borders - system_title_bar_hide_radio_ = gtk_radio_button_new_with_label_from_widget( - GTK_RADIO_BUTTON(system_title_bar_show_radio_), - l10n_util::GetStringUTF8(IDS_HIDE_WINDOW_DECORATIONS_RADIO).c_str()); - g_signal_connect(system_title_bar_hide_radio_, "toggled", - G_CALLBACK(OnSystemTitleBarRadioToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), system_title_bar_hide_radio_, FALSE, - FALSE, 0); - } - - return vbox; -} - -GtkWidget* ContentPageGtk::InitSyncGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - // Sync label. - sync_status_label_background_ = gtk_event_box_new(); - sync_status_label_ = gtk_label_new(""); - WrapLabelAtAllocationHack(sync_status_label_); - - gtk_misc_set_alignment(GTK_MISC(sync_status_label_), 0, 0.5); - gtk_box_pack_start(GTK_BOX(vbox), sync_status_label_background_, FALSE, - FALSE, 0); - gtk_container_add(GTK_CONTAINER(sync_status_label_background_), - sync_status_label_); - - // Sync action link. - GtkWidget* link_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); - sync_action_link_background_ = gtk_event_box_new(); - sync_action_link_ = gtk_chrome_link_button_new(""); - g_signal_connect(sync_action_link_, "clicked", - G_CALLBACK(OnSyncActionLinkClickedThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), link_hbox, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(link_hbox), sync_action_link_background_, FALSE, - FALSE, 0); - gtk_container_add(GTK_CONTAINER(sync_action_link_background_), - sync_action_link_); - gtk_widget_hide(sync_action_link_background_); - - // Add the sync button into its own horizontal box so it does not - // depend on the spacing above. - GtkWidget* button_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); - gtk_container_add(GTK_CONTAINER(vbox), button_hbox); - sync_start_stop_button_ = gtk_button_new_with_label(""); - g_signal_connect(sync_start_stop_button_, "clicked", - G_CALLBACK(OnSyncStartStopButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(button_hbox), sync_start_stop_button_, FALSE, - FALSE, 0); - sync_customize_button_ = gtk_button_new_with_label(""); - g_signal_connect(sync_customize_button_, "clicked", - G_CALLBACK(OnSyncCustomizeButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(button_hbox), sync_customize_button_, FALSE, - FALSE, 0); - - // Add the privacy dashboard link. - GtkWidget* dashboard_link_hbox = - gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); - GtkWidget* dashboard_link_background = gtk_event_box_new(); - std::string dashboard_link_label = - l10n_util::GetStringUTF8(IDS_SYNC_PRIVACY_DASHBOARD_LINK_LABEL); - privacy_dashboard_link_ = - gtk_chrome_link_button_new(dashboard_link_label.c_str()); - g_signal_connect(privacy_dashboard_link_, "clicked", - G_CALLBACK(OnPrivacyDashboardLinkClickedThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), dashboard_link_hbox, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(dashboard_link_hbox), - dashboard_link_background, FALSE, FALSE, 0); - gtk_container_add(GTK_CONTAINER(dashboard_link_background), - privacy_dashboard_link_); - - - return vbox; -} - -void ContentPageGtk::UpdateSyncControls() { - DCHECK(sync_service_); - string16 status_label; - string16 link_label; - std::string customize_button_label; - bool managed = sync_service_->IsManaged(); - bool sync_setup_completed = sync_service_->HasSyncSetupCompleted(); - bool status_has_error = sync_ui_util::GetStatusLabels(sync_service_, - &status_label, &link_label) == sync_ui_util::SYNC_ERROR; - customize_button_label = - l10n_util::GetStringUTF8(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL); - - std::string start_stop_button_label; - bool is_start_stop_button_sensitive = false; - if (sync_setup_completed) { - start_stop_button_label = - l10n_util::GetStringUTF8(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); - is_start_stop_button_sensitive = !managed; - } else if (sync_service_->SetupInProgress()) { - start_stop_button_label = - l10n_util::GetStringUTF8(IDS_SYNC_NTP_SETUP_IN_PROGRESS); - is_start_stop_button_sensitive = false; - } else { - start_stop_button_label = - l10n_util::GetStringUTF8(IDS_SYNC_START_SYNC_BUTTON_LABEL); - is_start_stop_button_sensitive = !managed; - } - gtk_widget_set_no_show_all(sync_start_stop_button_, FALSE); - gtk_widget_show(sync_start_stop_button_); - gtk_widget_set_sensitive(sync_start_stop_button_, - is_start_stop_button_sensitive); - gtk_button_set_label(GTK_BUTTON(sync_start_stop_button_), - start_stop_button_label.c_str()); - - gtk_label_set_label(GTK_LABEL(sync_status_label_), - UTF16ToUTF8(status_label).c_str()); - - gtk_widget_set_child_visible(sync_customize_button_, - sync_setup_completed && !status_has_error); - gtk_button_set_label(GTK_BUTTON(sync_customize_button_), - customize_button_label.c_str()); - gtk_widget_set_sensitive(sync_customize_button_, !managed); - gtk_chrome_link_button_set_label(GTK_CHROME_LINK_BUTTON(sync_action_link_), - UTF16ToUTF8(link_label).c_str()); - if (link_label.empty()) { - gtk_widget_set_no_show_all(sync_action_link_background_, TRUE); - gtk_widget_hide(sync_action_link_background_); - } else { - gtk_widget_set_no_show_all(sync_action_link_background_, FALSE); - gtk_widget_show(sync_action_link_background_); - } - gtk_widget_set_sensitive(sync_action_link_, !managed); - if (status_has_error) { - gtk_widget_modify_bg(sync_status_label_background_, GTK_STATE_NORMAL, - &kSyncLabelErrorBgColor); - gtk_widget_modify_bg(sync_action_link_background_, GTK_STATE_NORMAL, - &kSyncLabelErrorBgColor); - } else { - gtk_widget_modify_bg(sync_status_label_background_, GTK_STATE_NORMAL, NULL); - gtk_widget_modify_bg(sync_action_link_background_, GTK_STATE_NORMAL, NULL); - } -} - -void ContentPageGtk::OnAutoFillButtonClicked(GtkWidget* widget) { - ShowAutoFillDialog(NULL, profile()->GetPersonalDataManager(), profile()); -} - -void ContentPageGtk::OnImportButtonClicked(GtkWidget* widget) { - ImportDialogGtk::Show( - GTK_WINDOW(gtk_widget_get_toplevel(widget)), - profile(), importer::ALL); -} - -void ContentPageGtk::OnGtkThemeButtonClicked(GtkWidget* widget) { - UserMetricsRecordAction(UserMetricsAction("Options_GtkThemeSet"), - profile()->GetPrefs()); - profile()->SetNativeTheme(); -} - -void ContentPageGtk::OnResetDefaultThemeButtonClicked(GtkWidget* widget) { - UserMetricsRecordAction(UserMetricsAction("Options_ThemesReset"), - profile()->GetPrefs()); - profile()->ClearTheme(); -} - -void ContentPageGtk::OnGetThemesButtonClicked(GtkWidget* widget) { - UserMetricsRecordAction(UserMetricsAction("Options_ThemesGallery"), - profile()->GetPrefs()); - BrowserList::GetLastActive()->OpenThemeGalleryTabAndActivate(); -} - -void ContentPageGtk::OnSystemTitleBarRadioToggled(GtkWidget* widget) { - DCHECK(browser_defaults::kCanToggleSystemTitleBar); - if (initializing_) - return; - - // We get two signals when selecting a radio button, one for the old radio - // being toggled off and one for the new one being toggled on. Ignore the - // signal for the toggling off the old button. - if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) - return; - - bool use_custom = gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(system_title_bar_hide_radio_)); - if (use_custom) { - UserMetricsRecordAction(UserMetricsAction("Options_CustomFrame_Enable"), - profile()->GetPrefs()); - } else { - UserMetricsRecordAction(UserMetricsAction("Options_CustomFrame_Disable"), - profile()->GetPrefs()); - } - - use_custom_chrome_frame_.SetValue(use_custom); -} - -void ContentPageGtk::OnShowPasswordsButtonClicked(GtkWidget* widget) { - ShowPasswordsExceptionsWindow(profile()); -} - -void ContentPageGtk::OnPasswordRadioToggled(GtkWidget* widget) { - if (initializing_) - return; - - // We get two signals when selecting a radio button, one for the old radio - // being toggled off and one for the new one being toggled on. Ignore the - // signal for the toggling off the old button. - if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) - return; - - bool enabled = gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(passwords_asktosave_radio_)); - if (enabled) { - UserMetricsRecordAction(UserMetricsAction("Options_PasswordManager_Enable"), - profile()->GetPrefs()); - } else { - UserMetricsRecordAction( - UserMetricsAction("Options_PasswordManager_Disable"), - profile()->GetPrefs()); - } - ask_to_save_passwords_.SetValue(enabled); -} - -void ContentPageGtk::OnSyncStartStopButtonClicked(GtkWidget* widget) { - DCHECK(sync_service_ && !sync_service_->IsManaged()); - - if (sync_service_->HasSyncSetupCompleted()) { - GtkWidget* dialog = gtk_message_dialog_new( - GTK_WINDOW(gtk_widget_get_toplevel(widget)), - static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL), - GTK_MESSAGE_WARNING, - GTK_BUTTONS_NONE, - "%s", - l10n_util::GetStringUTF8( - IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL).c_str()); - gtk_util::ApplyMessageDialogQuirks(dialog); - gtk_window_set_title(GTK_WINDOW(dialog), - l10n_util::GetStringUTF8( - IDS_SYNC_STOP_SYNCING_DIALOG_TITLE).c_str()); - gtk_dialog_add_buttons( - GTK_DIALOG(dialog), - l10n_util::GetStringUTF8(IDS_CANCEL).c_str(), - GTK_RESPONSE_REJECT, - l10n_util::GetStringUTF8( - IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL).c_str(), - GTK_RESPONSE_ACCEPT, - NULL); - - g_signal_connect(dialog, "response", - G_CALLBACK(OnStopSyncDialogResponseThunk), this); - - gtk_util::ShowDialog(dialog); - return; - } else { - sync_service_->ShowLoginDialog(NULL); - ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_OPTIONS); - } -} - -void ContentPageGtk::OnSyncCustomizeButtonClicked(GtkWidget* widget) { - // sync_customize_button_ should be invisible if sync is not yet set up. - DCHECK(sync_service_ && !sync_service_->IsManaged() && - sync_service_->HasSyncSetupCompleted()); - sync_service_->ShowConfigure(NULL); -} - -void ContentPageGtk::OnSyncActionLinkClicked(GtkWidget* widget) { - DCHECK(sync_service_ && !sync_service_->IsManaged()); - sync_service_->ShowErrorUI(NULL); -} - -void ContentPageGtk::OnStopSyncDialogResponse(GtkWidget* widget, int response) { - if (response == GTK_RESPONSE_ACCEPT) { - sync_service_->DisableForUser(); - ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); - } - gtk_widget_destroy(widget); -} - -void ContentPageGtk::OnPrivacyDashboardLinkClicked(GtkWidget* widget) { - BrowserList::GetLastActive()->OpenPrivacyDashboardTabAndActivate(); -} diff --git a/chrome/browser/ui/gtk/options/content_page_gtk.h b/chrome/browser/ui/gtk/options/content_page_gtk.h deleted file mode 100644 index 313e402..0000000 --- a/chrome/browser/ui/gtk/options/content_page_gtk.h +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_PAGE_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_PAGE_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include <string> - -#include "chrome/browser/autofill/personal_data_manager.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/ui/gtk/options/managed_prefs_banner_gtk.h" -#include "chrome/browser/ui/options/options_page_base.h" -#include "ui/base/gtk/gtk_signal.h" - -class Profile; - -class ContentPageGtk : public OptionsPageBase, - public ProfileSyncServiceObserver { - public: - explicit ContentPageGtk(Profile* profile); - ~ContentPageGtk(); - - GtkWidget* get_page_widget() const { - return page_; - } - - // ProfileSyncServiceObserver method. - virtual void OnStateChanged(); - - private: - // Updates various sync controls based on the current sync state. - void UpdateSyncControls(); - - // Overridden from OptionsPageBase. - virtual void NotifyPrefChanged(const std::string* pref_name); - - // Overridden from OptionsPageBase. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - // Update content area after a theme changed. - void ObserveThemeChanged(); - - // Initialize the option group widgets, return their container. - GtkWidget* InitPasswordSavingGroup(); - GtkWidget* InitFormAutoFillGroup(); - GtkWidget* InitBrowsingDataGroup(); - GtkWidget* InitThemesGroup(); - GtkWidget* InitSyncGroup(); - - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnImportButtonClicked); - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnGtkThemeButtonClicked); - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnResetDefaultThemeButtonClicked); - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnGetThemesButtonClicked); - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnSystemTitleBarRadioToggled); - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnShowPasswordsButtonClicked); - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnPasswordRadioToggled); - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnAutoFillButtonClicked); - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnSyncStartStopButtonClicked); - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnSyncCustomizeButtonClicked); - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnSyncActionLinkClicked); - CHROMEGTK_CALLBACK_1(ContentPageGtk, void, OnStopSyncDialogResponse, int); - CHROMEGTK_CALLBACK_0(ContentPageGtk, void, OnPrivacyDashboardLinkClicked); - - // Widgets for the Password saving group. - GtkWidget* passwords_asktosave_radio_; - GtkWidget* passwords_neversave_radio_; - GtkWidget* show_passwords_button_; - - // Widgets for the AutoFill group. - GtkWidget* autofill_button_; - - // Widgets for the Appearance group. - GtkWidget* system_title_bar_show_radio_; - GtkWidget* system_title_bar_hide_radio_; - GtkWidget* themes_reset_button_; -#if defined(TOOLKIT_GTK) - GtkWidget* gtk_theme_button_; -#endif - - // Widgets for the Sync group. - GtkWidget* sync_status_label_background_; - GtkWidget* sync_status_label_; - GtkWidget* sync_action_link_background_; - GtkWidget* sync_action_link_; - GtkWidget* sync_start_stop_button_; - GtkWidget* sync_customize_button_; - GtkWidget* privacy_dashboard_link_; - - // The parent GtkTable widget - GtkWidget* page_; - - // Pref members. - BooleanPrefMember ask_to_save_passwords_; - BooleanPrefMember form_autofill_enabled_; - BooleanPrefMember use_custom_chrome_frame_; - - // Flag to ignore gtk callbacks while we are loading prefs, to avoid - // then turning around and saving them again. - bool initializing_; - - NotificationRegistrar registrar_; - - // Cached pointer to ProfileSyncService, if it exists. Kept up to date - // and NULL-ed out on destruction. - ProfileSyncService* sync_service_; - - // Tracks managed preference warning banner state. - ManagedPrefsBannerGtk managed_prefs_banner_; - - DISALLOW_COPY_AND_ASSIGN(ContentPageGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_PAGE_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/content_settings_window_gtk.cc b/chrome/browser/ui/gtk/options/content_settings_window_gtk.cc deleted file mode 100644 index 98a494c..0000000 --- a/chrome/browser/ui/gtk/options/content_settings_window_gtk.cc +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/content_settings_window_gtk.h" - -#include <string> - -#include "base/command_line.h" -#include "base/message_loop.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/gtk/browser_window_gtk.h" -#include "chrome/browser/ui/gtk/gtk_tree.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/common/content_settings_types.h" -#include "chrome/common/pref_names.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" - -namespace { - -// The singleton options window object. -ContentSettingsWindowGtk* settings_window = NULL; - -} // namespace - -// static -void ContentSettingsWindowGtk::Show(GtkWindow* parent, - ContentSettingsType page, - Profile* profile) { - DCHECK(profile); - - if (!settings_window) { - // Create the options window. - settings_window = new ContentSettingsWindowGtk(parent, profile); - } - settings_window->ShowContentSettingsTab(page); -} - -ContentSettingsWindowGtk::ContentSettingsWindowGtk(GtkWindow* parent, - Profile* profile) - : profile_(profile), - cookie_page_(profile), - image_page_(profile, CONTENT_SETTINGS_TYPE_IMAGES), - javascript_page_(profile, CONTENT_SETTINGS_TYPE_JAVASCRIPT), - plugin_page_(profile, CONTENT_SETTINGS_TYPE_PLUGINS), - popup_page_(profile, CONTENT_SETTINGS_TYPE_POPUPS), - geolocation_page_(profile, CONTENT_SETTINGS_TYPE_GEOLOCATION), - notifications_page_(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { - const struct { - int message_id; - GtkWidget* widget; - } kNotebookPages[] = { - { IDS_COOKIES_TAB_LABEL, cookie_page_.get_page_widget() }, - { IDS_IMAGES_TAB_LABEL, image_page_.get_page_widget() }, - { IDS_JAVASCRIPT_TAB_LABEL, javascript_page_.get_page_widget() }, - { IDS_PLUGIN_TAB_LABEL, plugin_page_.get_page_widget() }, - { IDS_POPUP_TAB_LABEL, popup_page_.get_page_widget() }, - { IDS_GEOLOCATION_TAB_LABEL, geolocation_page_.get_page_widget() }, - { IDS_NOTIFICATIONS_TAB_LABEL, notifications_page_.get_page_widget() }, - }; - - // We don't need to observe changes in this value. - last_selected_page_.Init(prefs::kContentSettingsWindowLastTabIndex, - profile->GetPrefs(), NULL); - - std::string dialog_name = l10n_util::GetStringUTF8( - IDS_CONTENT_SETTINGS_TITLE); - dialog_ = gtk_dialog_new_with_buttons( - dialog_name.c_str(), - parent, - static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE, - NULL); - gtk_window_set_policy(GTK_WINDOW(dialog_), FALSE, FALSE, TRUE); - - gtk_window_set_default_size(GTK_WINDOW(dialog_), 500, -1); - // Allow browser windows to go in front of the options dialog in metacity. - gtk_window_set_type_hint(GTK_WINDOW(dialog_), GDK_WINDOW_TYPE_HINT_NORMAL); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), - gtk_util::kContentAreaSpacing); - gtk_util::SetWindowIcon(GTK_WINDOW(dialog_)); - - // Create hbox with list view and notebook. - GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kContentAreaSpacing); - - list_ = gtk_tree_view_new(); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list_), FALSE); - - GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( - "List Item", renderer, "text", 0, NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(list_), column); - - const int kColumnCount = 1; - GtkListStore* store = gtk_list_store_new(kColumnCount, G_TYPE_STRING); - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kNotebookPages); ++i) { - GtkTreeIter iter; - gtk_list_store_append(store, &iter); - std::string label = l10n_util::GetStringUTF8(kNotebookPages[i].message_id); - gtk_list_store_set(store, &iter, 0, label.c_str(), -1); - } - gtk_tree_view_set_model(GTK_TREE_VIEW(list_), GTK_TREE_MODEL(store)); - g_object_unref(store); - - // Needs to happen after the model is all set up. - GtkTreeSelection* selection = gtk_tree_view_get_selection( - GTK_TREE_VIEW(list_)); - gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); - - // Wrap the list widget in a scrolled window in order to have a frame. - GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), - GTK_SHADOW_ETCHED_IN); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), - GTK_POLICY_NEVER, GTK_POLICY_NEVER); - gtk_container_add(GTK_CONTAINER(scrolled), list_); - gtk_box_pack_start(GTK_BOX(hbox), scrolled, FALSE, FALSE, 0); - - notebook_ = gtk_notebook_new(); - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kNotebookPages); ++i) { - gtk_notebook_append_page(GTK_NOTEBOOK(notebook_), - kNotebookPages[i].widget, - NULL); - } - gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook_), FALSE); - gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook_), FALSE); - gtk_box_pack_start(GTK_BOX(hbox), notebook_, FALSE, FALSE, 0); - DCHECK_EQ(gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook_)), - CONTENT_SETTINGS_NUM_TYPES); - - // Create vbox with "Features:" text and hbox below. - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - GtkWidget* label = gtk_label_new( - l10n_util::GetStringUTF8(IDS_CONTENT_SETTINGS_FEATURES_LABEL).c_str()); - gtk_misc_set_alignment(GTK_MISC(label), 0, .5); - gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), vbox); - - // Need to show the notebook before connecting switch-page signal, otherwise - // we'll immediately get a signal switching to page 0 and overwrite our - // last_selected_page_ value. - gtk_util::ShowDialogWithLocalizedSize(dialog_, -1, -1, true); - - g_signal_connect(notebook_, "switch-page", - G_CALLBACK(OnSwitchPageThunk), this); - g_signal_connect(selection, "changed", - G_CALLBACK(OnListSelectionChangedThunk), this); - - // We only have one button and don't do any special handling, so just hook it - // directly to gtk_widget_destroy. - g_signal_connect(dialog_, "response", G_CALLBACK(gtk_widget_destroy), NULL); - - g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); -} - -ContentSettingsWindowGtk::~ContentSettingsWindowGtk() { -} - -void ContentSettingsWindowGtk::ShowContentSettingsTab( - ContentSettingsType page) { - // Bring options window to front if it already existed and isn't already - // in front - gtk_util::PresentWindow(dialog_, gtk_get_current_event_time()); - - if (page == CONTENT_SETTINGS_TYPE_DEFAULT) { - // Remember the last visited page from local state. - page = static_cast<ContentSettingsType>(last_selected_page_.GetValue()); - if (page == CONTENT_SETTINGS_TYPE_DEFAULT) - page = CONTENT_SETTINGS_TYPE_COOKIES; - } - // If the page number is out of bounds, reset to the first tab. - if (page < 0 || page >= gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook_))) - page = CONTENT_SETTINGS_TYPE_COOKIES; - - gtk_tree::SelectAndFocusRowNum(page, GTK_TREE_VIEW(list_)); -} - -void ContentSettingsWindowGtk::OnSwitchPage( - GtkWidget* notebook, - GtkNotebookPage* page, - guint page_num) { - int index = page_num; - DCHECK(index > CONTENT_SETTINGS_TYPE_DEFAULT && - index < CONTENT_SETTINGS_NUM_TYPES); - - // Keep list in sync. - GtkTreeModel* model; - GtkTreeIter iter; - if (gtk_tree_selection_get_selected( - gtk_tree_view_get_selection(GTK_TREE_VIEW(list_)), &model, &iter)) { - gint row_index = gtk_tree::GetRowNumForIter(model, &iter); - if (row_index == index) - return; - } - gtk_tree::SelectAndFocusRowNum(index, GTK_TREE_VIEW(list_)); -} - -void ContentSettingsWindowGtk::OnWindowDestroy(GtkWidget* widget) { - settings_window = NULL; - MessageLoop::current()->DeleteSoon(FROM_HERE, this); -} - -void ContentSettingsWindowGtk::OnListSelectionChanged( - GtkTreeSelection* selection) { - GtkTreeModel* model; - GtkTreeIter iter; - if (!gtk_tree_selection_get_selected(selection, &model, &iter)) { - NOTREACHED(); - return; - } - gint row_index = gtk_tree::GetRowNumForIter(model, &iter); - DCHECK(row_index > CONTENT_SETTINGS_TYPE_DEFAULT && - row_index < CONTENT_SETTINGS_NUM_TYPES); - - last_selected_page_.SetValue(row_index); - - if (row_index != gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook_))) - gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook_), row_index); -} diff --git a/chrome/browser/ui/gtk/options/content_settings_window_gtk.h b/chrome/browser/ui/gtk/options/content_settings_window_gtk.h deleted file mode 100644 index 2729c1e..0000000 --- a/chrome/browser/ui/gtk/options/content_settings_window_gtk.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_SETTINGS_WINDOW_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_SETTINGS_WINDOW_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include "base/scoped_ptr.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/gtk/options/content_filter_page_gtk.h" -#include "chrome/browser/ui/gtk/options/cookie_filter_page_gtk.h" -#include "chrome/common/content_settings_types.h" -#include "ui/base/gtk/gtk_signal.h" - -// A window that presents options to the user for blocking various kinds of -// content in webpages (cookies, javascript, images, popups). -class ContentSettingsWindowGtk { - public: - // Shows the current content settings page, opening a new one if it doesn't - // exist. - static void Show(GtkWindow* parent, ContentSettingsType page, - Profile* profile); - static void RegisterUserPrefs(PrefService* prefs); - - explicit ContentSettingsWindowGtk(GtkWindow* parent, Profile* profile); - virtual ~ContentSettingsWindowGtk(); - - private: - // Shows the Tab corresponding to the specified Content Settings page. - void ShowContentSettingsTab(ContentSettingsType page); - - CHROMEGTK_CALLBACK_2(ContentSettingsWindowGtk, void, OnSwitchPage, - GtkNotebookPage*, guint); - CHROMEGTK_CALLBACK_0(ContentSettingsWindowGtk, void, OnWindowDestroy); - CHROMEG_CALLBACK_0(ContentSettingsWindowGtk, void, OnListSelectionChanged, - GtkTreeSelection*); - - // The options dialog. - GtkWidget* dialog_; - - // The container of the option pages. - GtkWidget* notebook_; - GtkWidget* list_; - - // The Profile associated with these options. - Profile* profile_; - - // The last page the user was on when they opened the ContentSettings window. - IntegerPrefMember last_selected_page_; - - // The individual page implementations. Note that we have a specialized one - // for cookies (which have more complex rules) and use the same basic page - // layout for each other type. - CookieFilterPageGtk cookie_page_; - ContentFilterPageGtk image_page_; - ContentFilterPageGtk javascript_page_; - ContentFilterPageGtk plugin_page_; - ContentFilterPageGtk popup_page_; - ContentFilterPageGtk geolocation_page_; - ContentFilterPageGtk notifications_page_; - - DISALLOW_COPY_AND_ASSIGN(ContentSettingsWindowGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_CONTENT_SETTINGS_WINDOW_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/cookie_filter_page_gtk.cc b/chrome/browser/ui/gtk/options/cookie_filter_page_gtk.cc deleted file mode 100644 index 1fa51e7..0000000 --- a/chrome/browser/ui/gtk/options/cookie_filter_page_gtk.cc +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/cookie_filter_page_gtk.h" - -#include "base/auto_reset.h" -#include "base/command_line.h" -#include "chrome/browser/browsing_data_local_storage_helper.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/gtk/browser_window_gtk.h" -#include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/options/content_exceptions_window_gtk.h" -#include "chrome/browser/ui/gtk/options/cookies_view.h" -#include "chrome/browser/ui/options/show_options_url.h" -#include "chrome/common/pref_names.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" - -namespace { - -// Stick small widgets in an hbox so it doesn't expand to the whole width. -GtkWidget* WrapInHBox(GtkWidget* widget) { - GtkWidget* hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 0); - return hbox; -} - -} // namespace - -CookieFilterPageGtk::CookieFilterPageGtk(Profile* profile) - : OptionsPageBase(profile), - ignore_toggle_(false) { - // The pref members must be initialized first since the pref values are read - // afterwards when we initialize the cookie storing group. - clear_site_data_on_exit_.Init(prefs::kClearSiteDataOnExit, - profile->GetPrefs(), this); - - block_third_party_cookies_.Init(prefs::kBlockThirdPartyCookies, - profile->GetPrefs(), this); - - managed_default_cookies_setting_.Init(prefs::kManagedDefaultCookiesSetting, - profile->GetPrefs(), this); - - GtkWidget* title_label = gtk_util::CreateBoldLabel( - l10n_util::GetStringUTF8(IDS_MODIFY_COOKIE_STORING_LABEL)); - page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(page_), title_label, FALSE, FALSE, 0); - gtk_container_add(GTK_CONTAINER(page_), InitCookieStoringGroup()); -} - -CookieFilterPageGtk::~CookieFilterPageGtk() { -} - -void CookieFilterPageGtk::NotifyPrefChanged(const std::string* pref_name) { - AutoReset<bool> toggle_guard(&ignore_toggle_, true); - - if (!pref_name || *pref_name == prefs::kClearSiteDataOnExit) { - UpdateUiState(); - } - if (!pref_name || *pref_name == prefs::kManagedDefaultCookiesSetting) { - UpdateUiState(); - } - if (!pref_name || *pref_name == prefs::kBlockThirdPartyCookies) { - UpdateUiState(); - } -} - -void CookieFilterPageGtk::HighlightGroup(OptionsGroup highlight_group) { - // TODO(erg): implement group highlighting -} - -GtkWidget* CookieFilterPageGtk::InitCookieStoringGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - allow_radio_ = gtk_radio_button_new_with_label(NULL, - l10n_util::GetStringUTF8(IDS_COOKIES_ALLOW_RADIO).c_str()); - g_signal_connect(G_OBJECT(allow_radio_), "toggled", - G_CALLBACK(OnCookiesAllowToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), allow_radio_, FALSE, FALSE, 0); - - block_radio_ = gtk_radio_button_new_with_label_from_widget( - GTK_RADIO_BUTTON(allow_radio_), - l10n_util::GetStringUTF8(IDS_COOKIES_BLOCK_RADIO).c_str()); - g_signal_connect(G_OBJECT(block_radio_), "toggled", - G_CALLBACK(OnCookiesAllowToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), block_radio_, FALSE, FALSE, 0); - - exceptions_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_COOKIES_EXCEPTIONS_BUTTON).c_str()); - g_signal_connect(G_OBJECT(exceptions_button_), "clicked", - G_CALLBACK(OnExceptionsClickedThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), WrapInHBox(exceptions_button_), - FALSE, FALSE, 0); - - block_3rdparty_check_ = gtk_check_button_new_with_label( - l10n_util::GetStringUTF8(IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX).c_str()); - g_signal_connect(G_OBJECT(block_3rdparty_check_), "toggled", - G_CALLBACK(OnBlockThirdPartyToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), block_3rdparty_check_, FALSE, FALSE, 0); - - clear_on_close_check_ = gtk_check_button_new_with_label( - l10n_util::GetStringUTF8(IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX).c_str()); - g_signal_connect(G_OBJECT(clear_on_close_check_), "toggled", - G_CALLBACK(OnClearOnCloseToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), clear_on_close_check_, FALSE, FALSE, 0); - - show_cookies_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_COOKIES_SHOW_COOKIES_BUTTON).c_str()); - g_signal_connect(G_OBJECT(show_cookies_button_), "clicked", - G_CALLBACK(OnShowCookiesClickedThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), WrapInHBox(show_cookies_button_), - FALSE, FALSE, 0); - - GtkWidget* flash_settings_link = gtk_chrome_link_button_new( - l10n_util::GetStringUTF8(IDS_FLASH_STORAGE_SETTINGS).c_str()); - g_signal_connect(G_OBJECT(flash_settings_link), "clicked", - G_CALLBACK(OnFlashLinkClickedThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), WrapInHBox(flash_settings_link), - FALSE, FALSE, 0); - - ignore_toggle_ = true; - UpdateUiState(); - ignore_toggle_ = false; - - return vbox; -}; - -void CookieFilterPageGtk::UpdateUiState() { - // Get default_setting. - ContentSetting default_setting; - default_setting = profile()->GetHostContentSettingsMap()-> - GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); - - // Set UI state. - if (default_setting == CONTENT_SETTING_ALLOW) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(allow_radio_), TRUE); - } else { - DCHECK(default_setting == CONTENT_SETTING_BLOCK); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(block_radio_), TRUE); - } - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(clear_on_close_check_), - clear_site_data_on_exit_.GetValue()); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(block_3rdparty_check_), - block_third_party_cookies_.GetValue()); - - // Disable the UI if any of the settings is managed. - gtk_widget_set_sensitive(clear_on_close_check_, - !clear_site_data_on_exit_.IsManaged()); - gtk_widget_set_sensitive(block_3rdparty_check_, - !block_third_party_cookies_.IsManaged()); - bool sensitive = true; - if (profile()->GetHostContentSettingsMap()->IsDefaultContentSettingManaged( - CONTENT_SETTINGS_TYPE_COOKIES)) { - sensitive = false; - } - gtk_widget_set_sensitive(allow_radio_, sensitive); - gtk_widget_set_sensitive(block_radio_, sensitive); - gtk_widget_set_sensitive(exceptions_button_, sensitive); -} - -void CookieFilterPageGtk::OnCookiesAllowToggled(GtkWidget* toggle_button) { - if (ignore_toggle_) - return; - - if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button))) { - // When selecting a radio button, we get two signals (one for the old radio - // being toggled off, one for the new one being toggled on.) Ignore the - // signal for toggling off the old button. - return; - } - - ContentSetting setting = CONTENT_SETTING_ALLOW; - if (toggle_button == allow_radio_) - setting = CONTENT_SETTING_ALLOW; - else if (toggle_button == block_radio_) - setting = CONTENT_SETTING_BLOCK; - - profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( - CONTENT_SETTINGS_TYPE_COOKIES, setting); -} - -void CookieFilterPageGtk::OnExceptionsClicked(GtkWidget* button) { - HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); - HostContentSettingsMap* otr_settings_map = - profile()->HasOffTheRecordProfile() ? - profile()->GetOffTheRecordProfile()->GetHostContentSettingsMap() : - NULL; - ContentExceptionsWindowGtk::ShowExceptionsWindow( - GTK_WINDOW(gtk_widget_get_toplevel(button)), - settings_map, otr_settings_map, CONTENT_SETTINGS_TYPE_COOKIES); -} - -void CookieFilterPageGtk::OnBlockThirdPartyToggled(GtkWidget* toggle_button) { - if (ignore_toggle_) - return; - - HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); - settings_map->SetBlockThirdPartyCookies( - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button))); -} - -void CookieFilterPageGtk::OnClearOnCloseToggled(GtkWidget* toggle_button) { - if (ignore_toggle_) - return; - - clear_site_data_on_exit_.SetValue( - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button))); -} - -void CookieFilterPageGtk::OnShowCookiesClicked(GtkWidget* button) { - UserMetricsRecordAction(UserMetricsAction("Options_ShowCookies"), NULL); - CookiesView::Show(GTK_WINDOW(gtk_widget_get_toplevel(button)), - profile(), - new BrowsingDataDatabaseHelper(profile()), - new BrowsingDataLocalStorageHelper(profile()), - new BrowsingDataAppCacheHelper(profile()), - BrowsingDataIndexedDBHelper::Create(profile())); -} - -void CookieFilterPageGtk::OnFlashLinkClicked(GtkWidget* button) { - browser::ShowOptionsURL( - profile(), GURL(l10n_util::GetStringUTF8(IDS_FLASH_STORAGE_URL))); -} diff --git a/chrome/browser/ui/gtk/options/cookie_filter_page_gtk.h b/chrome/browser/ui/gtk/options/cookie_filter_page_gtk.h deleted file mode 100644 index 82c0128..0000000 --- a/chrome/browser/ui/gtk/options/cookie_filter_page_gtk.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_COOKIE_FILTER_PAGE_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_COOKIE_FILTER_PAGE_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include <string> - -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/options/options_page_base.h" -#include "ui/base/gtk/gtk_signal.h" - -class Profile; - -// A page in the content settings window for cookie options. This dialog has -// more options as is more complicated then all the other pages implemented -// with ContentPageGtk. -class CookieFilterPageGtk : public OptionsPageBase { - public: - explicit CookieFilterPageGtk(Profile* profile); - virtual ~CookieFilterPageGtk(); - - GtkWidget* get_page_widget() const { - return page_; - } - - private: - // Updates the UI state. - virtual void UpdateUiState(); - - // Overridden from OptionsPageBase - virtual void NotifyPrefChanged(const std::string* pref_name); - virtual void HighlightGroup(OptionsGroup highlight_group); - - CHROMEGTK_CALLBACK_0(CookieFilterPageGtk, void, OnCookiesAllowToggled); - CHROMEGTK_CALLBACK_0(CookieFilterPageGtk, void, OnExceptionsClicked); - CHROMEGTK_CALLBACK_0(CookieFilterPageGtk, void, OnBlockThirdPartyToggled); - CHROMEGTK_CALLBACK_0(CookieFilterPageGtk, void, OnClearOnCloseToggled); - CHROMEGTK_CALLBACK_0(CookieFilterPageGtk, void, OnShowCookiesClicked); - CHROMEGTK_CALLBACK_0(CookieFilterPageGtk, void, OnFlashLinkClicked); - - GtkWidget* InitCookieStoringGroup(); - - // Widgets of the cookie storing group - GtkWidget* allow_radio_; - GtkWidget* block_radio_; - - GtkWidget* exceptions_button_; - GtkWidget* block_3rdparty_check_; - GtkWidget* clear_on_close_check_; - GtkWidget* show_cookies_button_; - - // The parent GtkTable widget - GtkWidget* page_; - - // If state of the UI is not changed by a user-action we need to ignore - // "toggled" events. - bool ignore_toggle_; - - // Clear locally stored site data on exit pref. - BooleanPrefMember clear_site_data_on_exit_; - - // Block third-party-cookies. - BooleanPrefMember block_third_party_cookies_; - - // Managed default-cookies-setting. - IntegerPrefMember managed_default_cookies_setting_; - - DISALLOW_COPY_AND_ASSIGN(CookieFilterPageGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_COOKIE_FILTER_PAGE_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/cookies_view.cc b/chrome/browser/ui/gtk/options/cookies_view.cc deleted file mode 100644 index dc7be33..0000000 --- a/chrome/browser/ui/gtk/options/cookies_view.cc +++ /dev/null @@ -1,396 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/cookies_view.h" - -#include <gdk/gdkkeysyms.h> -#include <set> -#include <string> - -#include "base/message_loop.h" -#include "base/string_util.h" -#include "chrome/browser/cookies_tree_model.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/gtk_util.h" - -namespace { - -// Initial size for dialog. -const int kDialogDefaultWidth = 550; -const int kDialogDefaultHeight = 550; - -// Delay after entering filter text before filtering occurs. -const int kSearchFilterDelayMs = 500; - -// Response ids for our custom buttons. -enum { - RESPONSE_REMOVE = 1, - RESPONSE_REMOVE_ALL -}; - -// The currently open cookie manager, if any. -CookiesView* instance_ = NULL; - -} // namespace - -CookiesView::~CookiesView() { - if (destroy_dialog_in_destructor_) - gtk_widget_destroy(dialog_); -} - -// static -void CookiesView::Show( - GtkWindow* parent, - Profile* profile, - BrowsingDataDatabaseHelper* browsing_data_database_helper, - BrowsingDataLocalStorageHelper* browsing_data_local_storage_helper, - BrowsingDataAppCacheHelper* browsing_data_appcache_helper, - BrowsingDataIndexedDBHelper* browsing_data_indexed_db_helper) { - DCHECK(profile); - DCHECK(browsing_data_database_helper); - DCHECK(browsing_data_local_storage_helper); - DCHECK(browsing_data_appcache_helper); - DCHECK(browsing_data_indexed_db_helper); - - // If there's already an existing editor window, activate it. - if (instance_) { - gtk_util::PresentWindow(instance_->dialog_, 0); - } else { - instance_ = new CookiesView(parent, - profile, - browsing_data_database_helper, - browsing_data_local_storage_helper, - browsing_data_appcache_helper, - browsing_data_indexed_db_helper); - } -} - -CookiesView::CookiesView( - GtkWindow* parent, - Profile* profile, - BrowsingDataDatabaseHelper* browsing_data_database_helper, - BrowsingDataLocalStorageHelper* browsing_data_local_storage_helper, - BrowsingDataAppCacheHelper* browsing_data_appcache_helper, - BrowsingDataIndexedDBHelper* browsing_data_indexed_db_helper) - : profile_(profile), - browsing_data_database_helper_(browsing_data_database_helper), - browsing_data_local_storage_helper_(browsing_data_local_storage_helper), - browsing_data_appcache_helper_(browsing_data_appcache_helper), - browsing_data_indexed_db_helper_(browsing_data_indexed_db_helper), - filter_update_factory_(this), - destroy_dialog_in_destructor_(false) { - Init(parent); - - gtk_util::ShowDialogWithLocalizedSize(dialog_, - IDS_COOKIES_DIALOG_WIDTH_CHARS, - -1, - true); - - gtk_chrome_cookie_view_clear(GTK_CHROME_COOKIE_VIEW(cookie_display_)); -} - -void CookiesView::TestDestroySynchronously() { - g_signal_handler_disconnect(dialog_, destroy_handler_); - destroy_dialog_in_destructor_ = true; -} - -void CookiesView::Init(GtkWindow* parent) { - dialog_ = gtk_dialog_new_with_buttons( - l10n_util::GetStringUTF8( - IDS_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE).c_str(), - parent, - static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE, - NULL); - // Allow browser windows to go in front of the options dialog in metacity. - gtk_window_set_type_hint(GTK_WINDOW(dialog_), GDK_WINDOW_TYPE_HINT_NORMAL); - gtk_util::SetWindowIcon(GTK_WINDOW(dialog_)); - - remove_button_ = gtk_util::AddButtonToDialog( - dialog_, - gfx::ConvertAcceleratorsFromWindowsStyle( - l10n_util::GetStringUTF8(IDS_COOKIES_REMOVE_LABEL)).c_str(), - GTK_STOCK_REMOVE, - RESPONSE_REMOVE); - gtk_button_set_use_underline(GTK_BUTTON(remove_button_), TRUE); - gtk_button_box_set_child_secondary( - GTK_BUTTON_BOX(GTK_DIALOG(dialog_)->action_area), - remove_button_, - TRUE); - - remove_all_button_ = gtk_util::AddButtonToDialog( - dialog_, - gfx::ConvertAcceleratorsFromWindowsStyle( - l10n_util::GetStringUTF8(IDS_COOKIES_REMOVE_ALL_LABEL)).c_str(), - GTK_STOCK_CLEAR, - RESPONSE_REMOVE_ALL); - gtk_button_set_use_underline(GTK_BUTTON(remove_all_button_), TRUE); - gtk_button_box_set_child_secondary( - GTK_BUTTON_BOX(GTK_DIALOG(dialog_)->action_area), - remove_all_button_, - TRUE); - - gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_CLOSE); - gtk_window_set_default_size(GTK_WINDOW(dialog_), kDialogDefaultWidth, - kDialogDefaultHeight); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), - gtk_util::kContentAreaSpacing); - g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); - destroy_handler_ = g_signal_connect(dialog_, "destroy", - G_CALLBACK(OnWindowDestroyThunk), this); - - // Filtering controls. - GtkWidget* filter_hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); - filter_entry_ = gtk_entry_new(); - g_signal_connect(filter_entry_, "activate", - G_CALLBACK(OnFilterEntryActivatedThunk), this); - g_signal_connect(filter_entry_, "changed", - G_CALLBACK(OnFilterEntryChangedThunk), this); - gtk_box_pack_start(GTK_BOX(filter_hbox), filter_entry_, - TRUE, TRUE, 0); - filter_clear_button_ = gtk_button_new_with_mnemonic( - gfx::ConvertAcceleratorsFromWindowsStyle( - l10n_util::GetStringUTF8(IDS_COOKIES_CLEAR_SEARCH_LABEL)).c_str()); - g_signal_connect(filter_clear_button_, "clicked", - G_CALLBACK(OnFilterClearButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(filter_hbox), filter_clear_button_, - FALSE, FALSE, 0); - - GtkWidget* filter_controls = gtk_util::CreateLabeledControlsGroup(NULL, - l10n_util::GetStringUTF8(IDS_COOKIES_SEARCH_LABEL).c_str(), filter_hbox, - NULL); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), filter_controls, - FALSE, FALSE, 0); - - // Cookie list. - GtkWidget* cookie_list_vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), cookie_list_vbox, - TRUE, TRUE, 0); - - description_label_ = gtk_label_new( - l10n_util::GetStringUTF8(IDS_COOKIES_INFO_LABEL).c_str()); - gtk_misc_set_alignment(GTK_MISC(description_label_), 0, 0.5); - gtk_box_pack_start(GTK_BOX(cookie_list_vbox), description_label_, - FALSE, FALSE, 0); - - GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), - GTK_SHADOW_ETCHED_IN); - gtk_box_pack_start(GTK_BOX(cookie_list_vbox), scroll_window, TRUE, TRUE, 0); - - cookies_tree_model_.reset(new CookiesTreeModel( - profile_->GetRequestContext()->GetCookieStore()->GetCookieMonster(), - browsing_data_database_helper_, - browsing_data_local_storage_helper_, - NULL, - browsing_data_appcache_helper_, - browsing_data_indexed_db_helper_)); - cookies_tree_adapter_.reset( - new gtk_tree::TreeAdapter(this, cookies_tree_model_.get())); - tree_ = gtk_tree_view_new_with_model( - GTK_TREE_MODEL(cookies_tree_adapter_->tree_store())); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_), FALSE); - gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(tree_), TRUE); - gtk_container_add(GTK_CONTAINER(scroll_window), tree_); - - GtkTreeViewColumn* title_column = gtk_tree_view_column_new(); - GtkCellRenderer* pixbuf_renderer = gtk_cell_renderer_pixbuf_new(); - gtk_tree_view_column_pack_start(title_column, pixbuf_renderer, FALSE); - gtk_tree_view_column_add_attribute(title_column, pixbuf_renderer, "pixbuf", - gtk_tree::TreeAdapter::COL_ICON); - GtkCellRenderer* title_renderer = gtk_cell_renderer_text_new(); - gtk_tree_view_column_pack_start(title_column, title_renderer, TRUE); - gtk_tree_view_column_add_attribute(title_column, title_renderer, "text", - gtk_tree::TreeAdapter::COL_TITLE); - gtk_tree_view_column_set_title( - title_column, l10n_util::GetStringUTF8( - IDS_COOKIES_DOMAIN_COLUMN_HEADER).c_str()); - gtk_tree_view_append_column(GTK_TREE_VIEW(tree_), title_column); - g_signal_connect(tree_, "key-press-event", - G_CALLBACK(OnTreeViewKeyPressThunk), this); - g_signal_connect(tree_, "row-expanded", - G_CALLBACK(OnTreeViewRowExpandedThunk), this); - - selection_ = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_)); - gtk_tree_selection_set_mode(selection_, GTK_SELECTION_SINGLE); - g_signal_connect(selection_, "changed", - G_CALLBACK(OnTreeViewSelectionChangeThunk), this); - - cookie_display_ = gtk_chrome_cookie_view_new(FALSE); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), - cookie_display_, FALSE, FALSE, 0); - - // Populate the view. - cookies_tree_adapter_->Init(); - SetInitialTreeState(); - EnableControls(); -} - -void CookiesView::SetInitialTreeState() { - if (cookies_tree_model_->GetChildCount(cookies_tree_model_->GetRoot())) - gtk_tree::SelectAndFocusRowNum(0, GTK_TREE_VIEW(tree_)); -} - -void CookiesView::EnableControls() { - GtkTreeIter iter; - bool selected = gtk_tree_selection_get_selected(selection_, NULL, &iter); - gtk_widget_set_sensitive(remove_button_, selected); - gtk_widget_set_sensitive( - remove_all_button_, - cookies_tree_model_->GetChildCount(cookies_tree_model_->GetRoot())); - - const gchar* filter_text = gtk_entry_get_text(GTK_ENTRY(filter_entry_)); - gtk_widget_set_sensitive(filter_clear_button_, filter_text && *filter_text); - - if (selected) { - CookieTreeNode::DetailedInfo detailed_info = - static_cast<CookieTreeNode*>( - cookies_tree_adapter_->GetNode(&iter))->GetDetailedInfo(); - if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { - gtk_chrome_cookie_view_display_cookie( - GTK_CHROME_COOKIE_VIEW(cookie_display_), - detailed_info.cookie->Domain(), - *detailed_info.cookie); - } else if (detailed_info.node_type == - CookieTreeNode::DetailedInfo::TYPE_DATABASE) { - gtk_chrome_cookie_view_display_database( - GTK_CHROME_COOKIE_VIEW(cookie_display_), - *detailed_info.database_info); - } else if (detailed_info.node_type == - CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) { - gtk_chrome_cookie_view_display_local_storage( - GTK_CHROME_COOKIE_VIEW(cookie_display_), - *detailed_info.local_storage_info); - } else if (detailed_info.node_type == - CookieTreeNode::DetailedInfo::TYPE_APPCACHE) { - gtk_chrome_cookie_view_display_app_cache( - GTK_CHROME_COOKIE_VIEW(cookie_display_), - *detailed_info.appcache_info); - } else if (detailed_info.node_type == - CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB) { - gtk_chrome_cookie_view_display_indexed_db( - GTK_CHROME_COOKIE_VIEW(cookie_display_), - *detailed_info.indexed_db_info); - } else { - gtk_chrome_cookie_view_clear(GTK_CHROME_COOKIE_VIEW(cookie_display_)); - } - } else { - gtk_chrome_cookie_view_clear(GTK_CHROME_COOKIE_VIEW(cookie_display_)); - } -} - -void CookiesView::RemoveSelectedItems() { - GtkTreeIter iter; - bool selected = gtk_tree_selection_get_selected(selection_, NULL, &iter); - if (selected) { - GtkTreePath* path = gtk_tree_model_get_path( - GTK_TREE_MODEL(cookies_tree_adapter_->tree_store()), - &iter); - CookieTreeNode* node = static_cast<CookieTreeNode*>( - cookies_tree_adapter_->GetNode(&iter)); - cookies_tree_model_->DeleteCookieNode(node); - // After removing a node, try to select the "next" node. - // We call gtk_tree_model_get_iter to check if there is still a node at the - // pointed to by path. If not, we try to select the previous node in that - // subtree. If that subtree is empty, we then try to select the parent. - if (gtk_tree_model_get_iter( - GTK_TREE_MODEL(cookies_tree_adapter_->tree_store()), - &iter, - path)) { - gtk_tree_selection_select_iter(selection_, &iter); - } else if (gtk_tree_path_prev(path)) { - gtk_tree_selection_select_path(selection_, path); - } else if (gtk_tree_path_up(path)) { - gtk_tree_selection_select_path(selection_, path); - } - gtk_tree_path_free(path); - } -} - -void CookiesView::OnAnyModelUpdateStart() { - g_signal_handlers_block_by_func( - selection_, reinterpret_cast<gpointer>(OnTreeViewSelectionChangeThunk), - this); -} - -void CookiesView::OnAnyModelUpdate() { - g_signal_handlers_unblock_by_func( - selection_, reinterpret_cast<gpointer>(OnTreeViewSelectionChangeThunk), - this); - EnableControls(); -} - -void CookiesView::OnResponse(GtkWidget* dialog, int response_id) { - if (response_id == RESPONSE_REMOVE) { - RemoveSelectedItems(); - } else if (response_id == RESPONSE_REMOVE_ALL) { - cookies_tree_model_->DeleteAllStoredObjects(); - } else { - gtk_widget_destroy(dialog); - } -} - -void CookiesView::OnWindowDestroy(GtkWidget* widget) { - instance_ = NULL; - MessageLoop::current()->DeleteSoon(FROM_HERE, this); -} - -void CookiesView::OnTreeViewSelectionChange(GtkWidget* selection) { - EnableControls(); -} - -gboolean CookiesView::OnTreeViewKeyPress(GtkWidget* tree_view, - GdkEventKey* key) { - if (key->keyval == GDK_Delete) { - RemoveSelectedItems(); - return TRUE; - } - return FALSE; -} - -void CookiesView::OnTreeViewRowExpanded(GtkWidget* tree_view, - GtkTreeIter* iter, - GtkTreePath* path) { - // When a row in the tree is expanded, expand all the children too. - g_signal_handlers_block_by_func( - tree_view, reinterpret_cast<gpointer>(OnTreeViewRowExpandedThunk), this); - gtk_tree_view_expand_row(GTK_TREE_VIEW(tree_view), path, TRUE); - g_signal_handlers_unblock_by_func( - tree_view, reinterpret_cast<gpointer>(OnTreeViewRowExpandedThunk), this); -} - -void CookiesView::UpdateFilterResults() { - const gchar* text = gtk_entry_get_text(GTK_ENTRY(filter_entry_)); - if (text) { - cookies_tree_model_->UpdateSearchResults(UTF8ToWide(text)); - SetInitialTreeState(); - } -} - -void CookiesView::OnFilterEntryActivated(GtkWidget* entry) { - filter_update_factory_.RevokeAll(); - UpdateFilterResults(); -} - -void CookiesView::OnFilterEntryChanged(GtkWidget* editable) { - filter_update_factory_.RevokeAll(); - MessageLoop::current()->PostDelayedTask(FROM_HERE, - filter_update_factory_.NewRunnableMethod( - &CookiesView::UpdateFilterResults), kSearchFilterDelayMs); - EnableControls(); -} - -void CookiesView::OnFilterClearButtonClicked(GtkWidget* button) { - gtk_entry_set_text(GTK_ENTRY(filter_entry_), ""); - filter_update_factory_.RevokeAll(); - UpdateFilterResults(); -} diff --git a/chrome/browser/ui/gtk/options/cookies_view.h b/chrome/browser/ui/gtk/options/cookies_view.h deleted file mode 100644 index 26d72f6..0000000 --- a/chrome/browser/ui/gtk/options/cookies_view.h +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// This is the Gtk implementation of the Cookie Manager dialog. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_COOKIES_VIEW_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_COOKIES_VIEW_H_ -#pragma once - -#include <gtk/gtk.h> - -#include "base/basictypes.h" -#include "base/gtest_prod_util.h" -#include "base/scoped_ptr.h" -#include "base/task.h" -#include "chrome/browser/browsing_data_appcache_helper.h" -#include "chrome/browser/browsing_data_database_helper.h" -#include "chrome/browser/browsing_data_indexed_db_helper.h" -#include "chrome/browser/browsing_data_local_storage_helper.h" -#include "chrome/browser/ui/gtk/gtk_chrome_cookie_view.h" -#include "chrome/browser/ui/gtk/gtk_tree.h" -#include "net/base/cookie_monster.h" -#include "ui/base/gtk/gtk_signal.h" - -class CookieDisplayGtk; -class CookiesTreeModel; -class CookiesViewTest; -class Profile; - -// CookiesView is thread-hostile, and should only be called on the UI thread. -// Usage: -// CookiesView::Show(profile); -// Once the CookiesView is shown, it is responsible for deleting itself when the -// user closes the dialog. - -class CookiesView : public gtk_tree::TreeAdapter::Delegate { - public: - virtual ~CookiesView(); - - // Create (if necessary) and show the cookie manager window. - static void Show( - GtkWindow* parent, - Profile* profile, - BrowsingDataDatabaseHelper* browsing_data_database_helper, - BrowsingDataLocalStorageHelper* browsing_data_local_storage_helper, - BrowsingDataAppCacheHelper* browsing_data_appcache_helper, - BrowsingDataIndexedDBHelper* browsing_data_indexed_db_helper); - - // gtk_tree::TreeAdapter::Delegate implementation. - virtual void OnAnyModelUpdateStart(); - virtual void OnAnyModelUpdate(); - - private: - CookiesView( - GtkWindow* parent, - Profile* profile, - BrowsingDataDatabaseHelper* browsing_data_database_helper, - BrowsingDataLocalStorageHelper* browsing_data_local_storage_helper, - BrowsingDataAppCacheHelper* browsing_data_appcache_helper, - BrowsingDataIndexedDBHelper* browsing_data_indexed_db_helper); - - // A method only used in unit tests that sets a bit inside this class that - // lets it be stack allocated. - void TestDestroySynchronously(); - - // Initialize the dialog contents and layout. - void Init(GtkWindow* parent); - - // Set the initial selection and tree expanded state. - void SetInitialTreeState(); - - // Set sensitivity of buttons based on selection and filter state. - void EnableControls(); - - // Remove any cookies that are currently selected. - void RemoveSelectedItems(); - - CHROMEGTK_CALLBACK_1(CookiesView, void, OnResponse, int); - CHROMEGTK_CALLBACK_0(CookiesView, void, OnWindowDestroy); - // Callback for the table. - CHROMEGTK_CALLBACK_0(CookiesView, void, OnTreeViewSelectionChange); - CHROMEGTK_CALLBACK_1(CookiesView, gboolean, OnTreeViewKeyPress, - GdkEventKey*); - CHROMEGTK_CALLBACK_2(CookiesView, void, OnTreeViewRowExpanded, - GtkTreeIter*, GtkTreePath*); - // Callbacks for user actions filtering the list. - CHROMEGTK_CALLBACK_0(CookiesView, void, OnFilterEntryActivated); - CHROMEGTK_CALLBACK_0(CookiesView, void, OnFilterEntryChanged); - CHROMEGTK_CALLBACK_0(CookiesView, void, OnFilterClearButtonClicked); - - // Filter the list against the text in |filter_entry_|. - void UpdateFilterResults(); - - - // The parent widget. - GtkWidget* dialog_; - - // Widgets of the dialog. - GtkWidget* description_label_; - GtkWidget* filter_entry_; - GtkWidget* filter_clear_button_; - GtkWidget* remove_button_; - GtkWidget* remove_all_button_; - - // The table listing the cookies. - GtkWidget* tree_; - GtkTreeSelection* selection_; - - GtkWidget* cookie_display_; - - // The profile and related helpers. - Profile* profile_; - scoped_refptr<BrowsingDataDatabaseHelper> browsing_data_database_helper_; - scoped_refptr<BrowsingDataLocalStorageHelper> - browsing_data_local_storage_helper_; - scoped_refptr<BrowsingDataAppCacheHelper> browsing_data_appcache_helper_; - scoped_refptr<BrowsingDataIndexedDBHelper> browsing_data_indexed_db_helper_; - - // A factory to construct Runnable Methods so that we can be called back to - // re-evaluate the model after the search query string changes. - ScopedRunnableMethodFactory<CookiesView> filter_update_factory_; - - // The Cookies Table model. - scoped_ptr<CookiesTreeModel> cookies_tree_model_; - scoped_ptr<gtk_tree::TreeAdapter> cookies_tree_adapter_; - - // A reference to the "destroy" signal handler for this object. We disconnect - // from this signal if we need to be destroyed synchronously. - gulong destroy_handler_; - - // Whether we own |dialog_| or the other way around. - bool destroy_dialog_in_destructor_; - - friend class CookiesViewTest; - FRIEND_TEST_ALL_PREFIXES(CookiesViewTest, Empty); - FRIEND_TEST_ALL_PREFIXES(CookiesViewTest, Noop); - FRIEND_TEST_ALL_PREFIXES(CookiesViewTest, RemoveAll); - FRIEND_TEST_ALL_PREFIXES(CookiesViewTest, RemoveAllWithDefaultSelected); - FRIEND_TEST_ALL_PREFIXES(CookiesViewTest, Remove); - FRIEND_TEST_ALL_PREFIXES(CookiesViewTest, RemoveCookiesByType); - FRIEND_TEST_ALL_PREFIXES(CookiesViewTest, RemoveByDomain); - FRIEND_TEST_ALL_PREFIXES(CookiesViewTest, RemoveDefaultSelection); - FRIEND_TEST_ALL_PREFIXES(CookiesViewTest, Filter); - FRIEND_TEST_ALL_PREFIXES(CookiesViewTest, FilterRemoveAll); - FRIEND_TEST_ALL_PREFIXES(CookiesViewTest, FilterRemove); - - DISALLOW_COPY_AND_ASSIGN(CookiesView); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_COOKIES_VIEW_H_ diff --git a/chrome/browser/ui/gtk/options/cookies_view_unittest.cc b/chrome/browser/ui/gtk/options/cookies_view_unittest.cc deleted file mode 100644 index 60db7b4..0000000 --- a/chrome/browser/ui/gtk/options/cookies_view_unittest.cc +++ /dev/null @@ -1,1202 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/cookies_view.h" - -#include <string> -#include <vector> - -#include <gtk/gtk.h> - -#include "base/string_util.h" -#include "chrome/browser/mock_browsing_data_appcache_helper.h" -#include "chrome/browser/mock_browsing_data_database_helper.h" -#include "chrome/browser/mock_browsing_data_indexed_db_helper.h" -#include "chrome/browser/mock_browsing_data_local_storage_helper.h" -#include "chrome/browser/ui/gtk/gtk_chrome_cookie_view.h" -#include "chrome/common/net/url_request_context_getter.h" -#include "chrome/test/testing_profile.h" -#include "net/url_request/url_request_context.h" -#include "testing/gtest/include/gtest/gtest.h" - -class CookiesViewTest : public testing::Test { - public: - CookiesViewTest() : io_thread_(BrowserThread::IO, &message_loop_) { - } - - virtual ~CookiesViewTest() { - } - - virtual void SetUp() { - profile_.reset(new TestingProfile()); - profile_->CreateRequestContext(); - mock_browsing_data_database_helper_ = - new MockBrowsingDataDatabaseHelper(profile_.get()); - mock_browsing_data_local_storage_helper_ = - new MockBrowsingDataLocalStorageHelper(profile_.get()); - mock_browsing_data_appcache_helper_ = - new MockBrowsingDataAppCacheHelper(profile_.get()); - mock_browsing_data_indexed_db_helper_ = - new MockBrowsingDataIndexedDBHelper(profile_.get()); - } - - void CheckDetailsSensitivity(gboolean expected_cookies, - gboolean expected_database, - gboolean expected_local_storage, - gboolean expected_appcache, - gboolean expected_indexed_db, - const CookiesView& cookies_view) { - GtkChromeCookieView* display = GTK_CHROME_COOKIE_VIEW( - cookies_view.cookie_display_); - - // Cookies - EXPECT_EQ(expected_cookies, - GTK_WIDGET_SENSITIVE(display->cookie_name_entry_)); - EXPECT_EQ(expected_cookies, - GTK_WIDGET_SENSITIVE(display->cookie_content_entry_)); - EXPECT_EQ(expected_cookies, - GTK_WIDGET_SENSITIVE(display->cookie_domain_entry_)); - EXPECT_EQ(expected_cookies, - GTK_WIDGET_SENSITIVE(display->cookie_path_entry_)); - EXPECT_EQ(expected_cookies, - GTK_WIDGET_SENSITIVE(display->cookie_send_for_entry_)); - EXPECT_EQ(expected_cookies, - GTK_WIDGET_SENSITIVE(display->cookie_created_entry_)); - EXPECT_EQ(expected_cookies, - GTK_WIDGET_SENSITIVE(display->cookie_expires_entry_)); - // Database - EXPECT_EQ(expected_database, - GTK_WIDGET_SENSITIVE(display->database_description_entry_)); - EXPECT_EQ(expected_database, - GTK_WIDGET_SENSITIVE(display->database_size_entry_)); - EXPECT_EQ(expected_database, - GTK_WIDGET_SENSITIVE(display->database_last_modified_entry_)); - // Local Storage - EXPECT_EQ(expected_local_storage, - GTK_WIDGET_SENSITIVE(display->local_storage_origin_entry_)); - EXPECT_EQ(expected_local_storage, - GTK_WIDGET_SENSITIVE(display->local_storage_size_entry_)); - EXPECT_EQ(expected_local_storage, GTK_WIDGET_SENSITIVE( - display->local_storage_last_modified_entry_)); - // AppCache - EXPECT_EQ(expected_appcache, - GTK_WIDGET_SENSITIVE(display->appcache_manifest_entry_)); - EXPECT_EQ(expected_appcache, - GTK_WIDGET_SENSITIVE(display->appcache_size_entry_)); - EXPECT_EQ(expected_appcache, - GTK_WIDGET_SENSITIVE(display->appcache_created_entry_)); - EXPECT_EQ(expected_appcache, - GTK_WIDGET_SENSITIVE(display->appcache_last_accessed_entry_)); - // IndexedDB - EXPECT_EQ(expected_indexed_db, - GTK_WIDGET_SENSITIVE(display->indexed_db_origin_entry_)); - EXPECT_EQ(expected_indexed_db, - GTK_WIDGET_SENSITIVE(display->indexed_db_size_entry_)); - EXPECT_EQ(expected_indexed_db, - GTK_WIDGET_SENSITIVE(display->indexed_db_last_modified_entry_)); - } - - // Get the cookie names in the cookie list, as a comma seperated string. - // (Note that the CookieMonster cookie list is sorted by domain.) - // Ex: - // monster->SetCookie(GURL("http://b"), "X=1") - // monster->SetCookie(GURL("http://a"), "Y=1") - // EXPECT_STREQ("Y,X", GetMonsterCookies(monster).c_str()); - std::string GetMonsterCookies(net::CookieMonster* monster) { - std::vector<std::string> parts; - net::CookieList cookie_list = monster->GetAllCookies(); - for (size_t i = 0; i < cookie_list.size(); ++i) - parts.push_back(cookie_list[i].Name()); - return JoinString(parts, ','); - } - - typedef std::pair<std::vector<std::string>*, GtkTreeView*> - DisplayedCookiesData; - - static gboolean GetDisplayedCookiesHelper(GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer user_data) { - DisplayedCookiesData* data = - reinterpret_cast<DisplayedCookiesData*>(user_data); - gchar* title; - gtk_tree_model_get(model, iter, - gtk_tree::TreeAdapter::COL_TITLE, &title, - -1); - std::string str; - if (gtk_tree_path_get_depth(path) > 1) { - // There isn't a function to check if a row is visible, instead we have to - // check whether the parent is expanded. - GtkTreePath* parent_path = gtk_tree_path_copy(path); - gtk_tree_path_up(parent_path); - str.append( - gtk_tree_path_get_depth(parent_path), - gtk_tree_view_row_expanded(data->second, parent_path) ? '+' : '_'); - gtk_tree_path_free(parent_path); - } - str += title; - g_free(title); - data->first->push_back(str); - return FALSE; - } - - // Get the cookie names displayed in the dialog in the order they are - // displayed, as a comma seperated string. - // Items are prefixed with _ or + up to their indent level. - // _ when hidden (parent is closed) and + when visible (parent is expanded). - // Ex: EXPECT_STREQ("a,+Cookies,++Y,b,_Cookies,__X", - // GetDisplayedCookies(cookies_view).c_str()); - std::string GetDisplayedCookies(const CookiesView& cookies_view) { - GtkTreeStore* tree_store = cookies_view.cookies_tree_adapter_->tree_store(); - std::vector<std::string> parts; - DisplayedCookiesData helper_data(&parts, GTK_TREE_VIEW(cookies_view.tree_)); - gtk_tree_model_foreach(GTK_TREE_MODEL(tree_store), - GetDisplayedCookiesHelper, &helper_data); - return JoinString(parts, ','); - } - - bool ExpandByPath(const CookiesView& cookies_view, const char* path_str) { - GtkTreePath* path = gtk_tree_path_new_from_string(path_str); - if (!path) - return false; - bool rv = gtk_tree_view_expand_row(GTK_TREE_VIEW(cookies_view.tree_), path, - FALSE); - gtk_tree_path_free(path); - return rv; - } - - bool SelectByPath(const CookiesView& cookies_view, const char* path_str) { - GtkTreePath* path = gtk_tree_path_new_from_string(path_str); - if (!path) - return false; - gtk_tree_selection_select_path(cookies_view.selection_, path); - bool rv = gtk_tree_selection_path_is_selected(cookies_view.selection_, - path); - gtk_tree_path_free(path); - return rv; - } - - std::string GetSelectedPath(const CookiesView& cookies_view) { - std::string result; - GtkTreeIter iter; - bool selected = gtk_tree_selection_get_selected(cookies_view.selection_, - NULL, &iter); - if (selected) { - gchar* path_str = gtk_tree_model_get_string_from_iter( - GTK_TREE_MODEL(cookies_view.cookies_tree_adapter_->tree_store()), - &iter); - if (path_str) { - result = path_str; - g_free(path_str); - } - } - return result; - } - - protected: - MessageLoop message_loop_; - BrowserThread io_thread_; - - scoped_ptr<TestingProfile> profile_; - scoped_refptr<MockBrowsingDataDatabaseHelper> - mock_browsing_data_database_helper_; - scoped_refptr<MockBrowsingDataLocalStorageHelper> - mock_browsing_data_local_storage_helper_; - scoped_refptr<MockBrowsingDataAppCacheHelper> - mock_browsing_data_appcache_helper_; - scoped_refptr<MockBrowsingDataIndexedDBHelper> - mock_browsing_data_indexed_db_helper_; -}; - -TEST_F(CookiesViewTest, Empty) { - CookiesView cookies_view(NULL, - profile_.get(), - mock_browsing_data_database_helper_, - mock_browsing_data_local_storage_helper_, - mock_browsing_data_appcache_helper_, - mock_browsing_data_indexed_db_helper_); - cookies_view.TestDestroySynchronously(); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); -} - -TEST_F(CookiesViewTest, Noop) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo0"), "C=1"); - monster->SetCookie(GURL("http://foo0"), "D=1"); - monster->SetCookie(GURL("http://foo1"), "B=1"); - monster->SetCookie(GURL("http://foo1"), "A=1"); - monster->SetCookie(GURL("http://foo1"), "E=1"); - monster->SetCookie(GURL("http://foo2"), "G=1"); - monster->SetCookie(GURL("http://foo2"), "X=1"); - CookiesView cookies_view(NULL, - profile_.get(), - mock_browsing_data_database_helper_, - mock_browsing_data_local_storage_helper_, - mock_browsing_data_appcache_helper_, - mock_browsing_data_indexed_db_helper_); - cookies_view.TestDestroySynchronously(); - mock_browsing_data_database_helper_->AddDatabaseSamples(); - mock_browsing_data_database_helper_->Notify(); - mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); - mock_browsing_data_local_storage_helper_->Notify(); - EXPECT_STREQ("foo0,_Cookies,__C,__D," - "foo1,_Cookies,__A,__B,__E," - "foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); -} - -TEST_F(CookiesViewTest, RemoveAll) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo"), "A=1"); - monster->SetCookie(GURL("http://foo2"), "B=1"); - CookiesView cookies_view(NULL, - profile_.get(), - mock_browsing_data_database_helper_, - mock_browsing_data_local_storage_helper_, - mock_browsing_data_appcache_helper_, - mock_browsing_data_indexed_db_helper_); - cookies_view.TestDestroySynchronously(); - mock_browsing_data_database_helper_->AddDatabaseSamples(); - mock_browsing_data_database_helper_->Notify(); - mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); - mock_browsing_data_local_storage_helper_->Notify(); - - // Reset the selection of the first row. - gtk_tree_selection_unselect_all(cookies_view.selection_); - - { - SCOPED_TRACE("Before removing"); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - EXPECT_STREQ("foo,_Cookies,__A,foo2,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - } - - mock_browsing_data_database_helper_->Reset(); - mock_browsing_data_local_storage_helper_->Reset(); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_)); - { - SCOPED_TRACE("After removing"); - EXPECT_EQ(0u, monster->GetAllCookies().size()); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); - EXPECT_TRUE(mock_browsing_data_database_helper_->AllDeleted()); - EXPECT_TRUE(mock_browsing_data_local_storage_helper_->AllDeleted()); - } -} - -TEST_F(CookiesViewTest, RemoveAllWithDefaultSelected) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo"), "A=1"); - monster->SetCookie(GURL("http://foo2"), "B=1"); - CookiesView cookies_view(NULL, - profile_.get(), - mock_browsing_data_database_helper_, - mock_browsing_data_local_storage_helper_, - mock_browsing_data_appcache_helper_, - mock_browsing_data_indexed_db_helper_); - cookies_view.TestDestroySynchronously(); - mock_browsing_data_database_helper_->AddDatabaseSamples(); - mock_browsing_data_database_helper_->Notify(); - mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); - mock_browsing_data_local_storage_helper_->Notify(); - - EXPECT_STREQ("0", GetSelectedPath(cookies_view).c_str()); - EXPECT_EQ(1, gtk_tree_selection_count_selected_rows(cookies_view.selection_)); - { - SCOPED_TRACE("Before removing"); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - EXPECT_STREQ("foo,_Cookies,__A,foo2,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - } - - mock_browsing_data_database_helper_->Reset(); - mock_browsing_data_local_storage_helper_->Reset(); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_)); - { - SCOPED_TRACE("After removing"); - EXPECT_EQ(0u, monster->GetAllCookies().size()); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(0, - gtk_tree_selection_count_selected_rows(cookies_view.selection_)); - EXPECT_TRUE(mock_browsing_data_database_helper_->AllDeleted()); - EXPECT_TRUE(mock_browsing_data_local_storage_helper_->AllDeleted()); - } -} - -TEST_F(CookiesViewTest, Remove) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo1"), "A=1"); - monster->SetCookie(GURL("http://foo2"), "B=1"); - monster->SetCookie(GURL("http://foo2"), "C=1"); - CookiesView cookies_view(NULL, - profile_.get(), - mock_browsing_data_database_helper_, - mock_browsing_data_local_storage_helper_, - mock_browsing_data_appcache_helper_, - mock_browsing_data_indexed_db_helper_); - cookies_view.TestDestroySynchronously(); - mock_browsing_data_database_helper_->AddDatabaseSamples(); - mock_browsing_data_database_helper_->Notify(); - mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); - mock_browsing_data_local_storage_helper_->Notify(); - - ASSERT_TRUE(ExpandByPath(cookies_view, "1")); - ASSERT_TRUE(SelectByPath(cookies_view, "1:0:0")); - - { - SCOPED_TRACE("First selection"); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(TRUE, FALSE, FALSE, FALSE, FALSE, cookies_view); - EXPECT_STREQ("foo1,_Cookies,__A,foo2,+Cookies,++B,++C," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - } - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - { - SCOPED_TRACE("First selection removed"); - EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("foo1,_Cookies,__A,foo2,+Cookies,++C," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_STREQ("1:0:0", GetSelectedPath(cookies_view).c_str()); - CheckDetailsSensitivity(TRUE, FALSE, FALSE, FALSE, FALSE, cookies_view); - } - - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - { - SCOPED_TRACE("Second selection"); - EXPECT_STREQ("A", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("foo1,_Cookies,__A," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_STREQ("", GetSelectedPath(cookies_view).c_str()); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - } - - ASSERT_TRUE(ExpandByPath(cookies_view, "0")); - EXPECT_STREQ("foo1,+Cookies,++A," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - ASSERT_TRUE(SelectByPath(cookies_view, "0:0:0")); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - { - SCOPED_TRACE("Second selection removed"); - EXPECT_EQ(0u, monster->GetAllCookies().size()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - EXPECT_STREQ("gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - } - - ASSERT_TRUE(ExpandByPath(cookies_view, "0")); - EXPECT_STREQ("gdbhost1,+Web Databases,++db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - ASSERT_TRUE(SelectByPath(cookies_view, "0:0:0")); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - { - SCOPED_TRACE("Third selection removed"); - EXPECT_EQ(0u, monster->GetAllCookies().size()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - EXPECT_STREQ("gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_TRUE(mock_browsing_data_database_helper_->last_deleted_origin_ == - "http_gdbhost1_1"); - EXPECT_TRUE(mock_browsing_data_database_helper_->last_deleted_db_ == - "db1"); - } - - ASSERT_TRUE(ExpandByPath(cookies_view, "1")); - EXPECT_STREQ("gdbhost2,_Web Databases,__db2," - "host1,+Local Storage,++http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - ASSERT_TRUE(SelectByPath(cookies_view, "1:0:0")); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - { - SCOPED_TRACE("Fourth selection removed"); - EXPECT_EQ(0u, monster->GetAllCookies().size()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - EXPECT_STREQ("gdbhost2,_Web Databases,__db2," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_TRUE(mock_browsing_data_local_storage_helper_->last_deleted_file_ == - FilePath(FILE_PATH_LITERAL("file1"))); - } -} - -TEST_F(CookiesViewTest, RemoveCookiesByType) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo0"), "C=1"); - monster->SetCookie(GURL("http://foo0"), "D=1"); - monster->SetCookie(GURL("http://foo1"), "B=1"); - monster->SetCookie(GURL("http://foo1"), "A=1"); - monster->SetCookie(GURL("http://foo1"), "E=1"); - monster->SetCookie(GURL("http://foo2"), "G=1"); - monster->SetCookie(GURL("http://foo2"), "X=1"); - CookiesView cookies_view(NULL, - profile_.get(), - mock_browsing_data_database_helper_, - mock_browsing_data_local_storage_helper_, - mock_browsing_data_appcache_helper_, - mock_browsing_data_indexed_db_helper_); - cookies_view.TestDestroySynchronously(); - mock_browsing_data_database_helper_->AddDatabaseSamples(); - mock_browsing_data_database_helper_->Notify(); - mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); - mock_browsing_data_local_storage_helper_->Notify(); - - EXPECT_STREQ("foo0,_Cookies,__C,__D," - "foo1,_Cookies,__A,__B,__E," - "foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - ASSERT_TRUE(ExpandByPath(cookies_view, "1")); - EXPECT_STREQ("foo0,_Cookies,__C,__D," - "foo1,+Cookies,++A,++B,++E," - "foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - ASSERT_TRUE(SelectByPath(cookies_view, "1:0")); - - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("C,D,G,X", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("foo0,_Cookies,__C,__D," - "foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - ASSERT_TRUE(ExpandByPath(cookies_view, "0")); - EXPECT_STREQ("foo0,+Cookies,++C,++D," - "foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - ASSERT_TRUE(SelectByPath(cookies_view, "0:0")); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("G,X", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - ASSERT_TRUE(ExpandByPath(cookies_view, "0")); - EXPECT_STREQ("foo2,+Cookies,++G,++X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - ASSERT_TRUE(SelectByPath(cookies_view, "0:0")); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - ASSERT_TRUE(ExpandByPath(cookies_view, "0")); - EXPECT_STREQ("gdbhost1,+Web Databases,++db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - ASSERT_TRUE(SelectByPath(cookies_view, "0:0")); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_TRUE(mock_browsing_data_database_helper_->last_deleted_origin_ == - "http_gdbhost1_1"); - EXPECT_TRUE(mock_browsing_data_database_helper_->last_deleted_db_ == - "db1"); - - ASSERT_TRUE(ExpandByPath(cookies_view, "1")); - EXPECT_STREQ("gdbhost2,_Web Databases,__db2," - "host1,+Local Storage,++http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - ASSERT_TRUE(SelectByPath(cookies_view, "1:0")); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("gdbhost2,_Web Databases,__db2," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_TRUE(mock_browsing_data_local_storage_helper_->last_deleted_file_ == - FilePath(FILE_PATH_LITERAL("file1"))); -} - -TEST_F(CookiesViewTest, RemoveByDomain) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo0"), "C=1"); - monster->SetCookie(GURL("http://foo0"), "D=1"); - monster->SetCookie(GURL("http://foo1"), "B=1"); - monster->SetCookie(GURL("http://foo1"), "A=1"); - monster->SetCookie(GURL("http://foo1"), "E=1"); - monster->SetCookie(GURL("http://foo2"), "G=1"); - monster->SetCookie(GURL("http://foo2"), "X=1"); - CookiesView cookies_view(NULL, - profile_.get(), - mock_browsing_data_database_helper_, - mock_browsing_data_local_storage_helper_, - mock_browsing_data_appcache_helper_, - mock_browsing_data_indexed_db_helper_); - cookies_view.TestDestroySynchronously(); - mock_browsing_data_database_helper_->AddDatabaseSamples(); - mock_browsing_data_database_helper_->Notify(); - mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); - mock_browsing_data_local_storage_helper_->Notify(); - - EXPECT_STREQ("foo0,_Cookies,__C,__D," - "foo1,_Cookies,__A,__B,__E," - "foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - ASSERT_TRUE(SelectByPath(cookies_view, "1")); - - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("C,D,G,X", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("foo0,_Cookies,__C,__D," - "foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_STREQ("1", GetSelectedPath(cookies_view).c_str()); - - ASSERT_TRUE(SelectByPath(cookies_view, "0")); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("G,X", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_STREQ("0", GetSelectedPath(cookies_view).c_str()); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_STREQ("0", GetSelectedPath(cookies_view).c_str()); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_TRUE(mock_browsing_data_database_helper_->last_deleted_origin_ == - "http_gdbhost1_1"); - EXPECT_TRUE(mock_browsing_data_database_helper_->last_deleted_db_ == - "db1"); - EXPECT_STREQ("0", GetSelectedPath(cookies_view).c_str()); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_TRUE(mock_browsing_data_database_helper_->last_deleted_origin_ == - "http_gdbhost2_2"); - EXPECT_TRUE(mock_browsing_data_database_helper_->last_deleted_db_ == - "db2"); - EXPECT_STREQ("0", GetSelectedPath(cookies_view).c_str()); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_TRUE(mock_browsing_data_local_storage_helper_->last_deleted_file_ == - FilePath(FILE_PATH_LITERAL("file1"))); - EXPECT_STREQ("0", GetSelectedPath(cookies_view).c_str()); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_TRUE(mock_browsing_data_local_storage_helper_->last_deleted_file_ == - FilePath(FILE_PATH_LITERAL("file2"))); - - EXPECT_EQ(0, gtk_tree_selection_count_selected_rows(cookies_view.selection_)); -} - -TEST_F(CookiesViewTest, RemoveDefaultSelection) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo0"), "C=1"); - monster->SetCookie(GURL("http://foo0"), "D=1"); - monster->SetCookie(GURL("http://foo1"), "B=1"); - monster->SetCookie(GURL("http://foo1"), "A=1"); - monster->SetCookie(GURL("http://foo1"), "E=1"); - monster->SetCookie(GURL("http://foo2"), "G=1"); - monster->SetCookie(GURL("http://foo2"), "X=1"); - CookiesView cookies_view(NULL, - profile_.get(), - mock_browsing_data_database_helper_, - mock_browsing_data_local_storage_helper_, - mock_browsing_data_appcache_helper_, - mock_browsing_data_indexed_db_helper_); - cookies_view.TestDestroySynchronously(); - mock_browsing_data_database_helper_->AddDatabaseSamples(); - mock_browsing_data_database_helper_->Notify(); - mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); - mock_browsing_data_local_storage_helper_->Notify(); - - EXPECT_STREQ("foo0,_Cookies,__C,__D," - "foo1,_Cookies,__A,__B,__E," - "foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("B,A,E,G,X", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("foo1,_Cookies,__A,__B,__E," - "foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("G,X", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("foo2,_Cookies,__G,__X," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); - - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); -} - -TEST_F(CookiesViewTest, Filter) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo0"), "C=1"); - monster->SetCookie(GURL("http://bar0"), "D=1"); - monster->SetCookie(GURL("http://foo1"), "B=1"); - monster->SetCookie(GURL("http://bar1"), "A=1"); - CookiesView cookies_view(NULL, - profile_.get(), - mock_browsing_data_database_helper_, - mock_browsing_data_local_storage_helper_, - mock_browsing_data_appcache_helper_, - mock_browsing_data_indexed_db_helper_); - cookies_view.TestDestroySynchronously(); - mock_browsing_data_database_helper_->AddDatabaseSamples(); - mock_browsing_data_database_helper_->Notify(); - mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); - mock_browsing_data_local_storage_helper_->Notify(); - - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,_Cookies,__A," - "foo0,_Cookies,__C," - "foo1,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.filter_clear_button_)); - - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar"); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.filter_clear_button_)); - // Entering text doesn't immediately filter the results. - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,_Cookies,__A," - "foo0,_Cookies,__C," - "foo1,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - // Results are filtered immediately if you activate (hit enter in the entry). - gtk_widget_activate(cookies_view.filter_entry_); - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,_Cookies,__A", - GetDisplayedCookies(cookies_view).c_str()); - - gtk_button_clicked(GTK_BUTTON(cookies_view.filter_clear_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.filter_clear_button_)); - EXPECT_STREQ("", gtk_entry_get_text(GTK_ENTRY(cookies_view.filter_entry_))); - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,_Cookies,__A," - "foo0,_Cookies,__C," - "foo1,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "hos"); - gtk_widget_activate(cookies_view.filter_entry_); - EXPECT_STREQ("gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); -} - -TEST_F(CookiesViewTest, FilterRemoveAll) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo0"), "C=1"); - monster->SetCookie(GURL("http://bar0"), "D=1"); - monster->SetCookie(GURL("http://foo1"), "B=1"); - monster->SetCookie(GURL("http://bar1"), "A=1"); - CookiesView cookies_view(NULL, - profile_.get(), - mock_browsing_data_database_helper_, - mock_browsing_data_local_storage_helper_, - mock_browsing_data_appcache_helper_, - mock_browsing_data_indexed_db_helper_); - cookies_view.TestDestroySynchronously(); - mock_browsing_data_database_helper_->AddDatabaseSamples(); - mock_browsing_data_database_helper_->Notify(); - mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); - mock_browsing_data_local_storage_helper_->Notify(); - - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,_Cookies,__A," - "foo0,_Cookies,__C," - "foo1,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.filter_clear_button_)); - - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar"); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.filter_clear_button_)); - // Entering text doesn't immediately filter the results. - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,_Cookies,__A," - "foo0,_Cookies,__C," - "foo1,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - // Results are filtered immediately if you activate (hit enter in the entry). - gtk_widget_activate(cookies_view.filter_entry_); - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,_Cookies,__A", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_)); - - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_STREQ("", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.filter_clear_button_)); - - gtk_button_clicked(GTK_BUTTON(cookies_view.filter_clear_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.filter_clear_button_)); - EXPECT_STREQ("", gtk_entry_get_text(GTK_ENTRY(cookies_view.filter_entry_))); - EXPECT_STREQ("foo0,_Cookies,__C," - "foo1,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); -} - -TEST_F(CookiesViewTest, FilterRemove) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo0"), "C=1"); - monster->SetCookie(GURL("http://bar0"), "D=1"); - monster->SetCookie(GURL("http://foo1"), "B=1"); - monster->SetCookie(GURL("http://bar1"), "A=1"); - monster->SetCookie(GURL("http://bar1"), "E=1"); - CookiesView cookies_view(NULL, - profile_.get(), - mock_browsing_data_database_helper_, - mock_browsing_data_local_storage_helper_, - mock_browsing_data_appcache_helper_, - mock_browsing_data_indexed_db_helper_); - cookies_view.TestDestroySynchronously(); - mock_browsing_data_database_helper_->AddDatabaseSamples(); - mock_browsing_data_database_helper_->Notify(); - mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); - mock_browsing_data_local_storage_helper_->Notify(); - - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,_Cookies,__A,__E," - "foo0,_Cookies,__C," - "foo1,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - // All default paths; order will be creation time. - EXPECT_STREQ("C,D,B,A,E", GetMonsterCookies(monster).c_str()); - - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.filter_clear_button_)); - - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar"); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.filter_clear_button_)); - // Entering text doesn't immediately filter the results. - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,_Cookies,__A,__E," - "foo0,_Cookies,__C," - "foo1,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - // Results are filtered immediately if you activate (hit enter in the entry). - gtk_widget_activate(cookies_view.filter_entry_); - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,_Cookies,__A,__E", - GetDisplayedCookies(cookies_view).c_str()); - - ASSERT_TRUE(ExpandByPath(cookies_view, "1")); - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,+Cookies,++A,++E", - GetDisplayedCookies(cookies_view).c_str()); - ASSERT_TRUE(SelectByPath(cookies_view, "1:0:0")); - - { - SCOPED_TRACE("First selection"); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(TRUE, FALSE, FALSE, FALSE, FALSE, cookies_view); - } - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - { - SCOPED_TRACE("First selection removed"); - EXPECT_STREQ("C,D,B,E", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("bar0,_Cookies,__D," - "bar1,+Cookies,++E", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_STREQ("1:0:0", GetSelectedPath(cookies_view).c_str()); - CheckDetailsSensitivity(TRUE, FALSE, FALSE, FALSE, FALSE, cookies_view); - } - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - { - SCOPED_TRACE("Second selection"); - EXPECT_STREQ("C,D,B", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("bar0,_Cookies,__D", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - } - - ASSERT_TRUE(ExpandByPath(cookies_view, "0")); - ASSERT_TRUE(SelectByPath(cookies_view, "0:0:0")); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - { - SCOPED_TRACE("Second selection removed"); - EXPECT_STREQ("C,B", GetMonsterCookies(monster).c_str()); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); - } - - gtk_button_clicked(GTK_BUTTON(cookies_view.filter_clear_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.filter_clear_button_)); - EXPECT_STREQ("", gtk_entry_get_text(GTK_ENTRY(cookies_view.filter_entry_))); - EXPECT_STREQ("foo0,_Cookies,__C," - "foo1,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "hos"); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.filter_clear_button_)); - // Entering text doesn't immediately filter the results. - EXPECT_STREQ("foo0,_Cookies,__C," - "foo1,_Cookies,__B," - "gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - // Results are filtered immediately if you activate (hit enter in the entry). - gtk_widget_activate(cookies_view.filter_entry_); - EXPECT_STREQ("gdbhost1,_Web Databases,__db1," - "gdbhost2,_Web Databases,__db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - - ASSERT_TRUE(ExpandByPath(cookies_view, "1")); - EXPECT_STREQ("gdbhost1,_Web Databases,__db1," - "gdbhost2,+Web Databases,++db2," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - ASSERT_TRUE(SelectByPath(cookies_view, "1:0:0")); - - { - SCOPED_TRACE("First selection"); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, TRUE, FALSE, FALSE, FALSE, cookies_view); - } - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - { - SCOPED_TRACE("First selection removed"); - EXPECT_STREQ("C,B", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("gdbhost1,_Web Databases,__db1," - "host1,_Local Storage,__http://host1:1/," - "host2,_Local Storage,__http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - } - - ASSERT_TRUE(ExpandByPath(cookies_view, "2")); - EXPECT_STREQ("gdbhost1,_Web Databases,__db1," - "host1,_Local Storage,__http://host1:1/," - "host2,+Local Storage,++http://host2:2/", - GetDisplayedCookies(cookies_view).c_str()); - ASSERT_TRUE(SelectByPath(cookies_view, "2:0:0")); - - { - SCOPED_TRACE("First selection"); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, TRUE, FALSE, FALSE, cookies_view); - } - - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - - { - SCOPED_TRACE("First selection removed"); - EXPECT_STREQ("C,B", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("gdbhost1,_Web Databases,__db1," - "host1,_Local Storage,__http://host1:1/", - GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, FALSE, FALSE, FALSE, FALSE, cookies_view); - } -} diff --git a/chrome/browser/ui/gtk/options/fonts_languages_window_gtk.cc b/chrome/browser/ui/gtk/options/fonts_languages_window_gtk.cc deleted file mode 100644 index 909b31c..0000000 --- a/chrome/browser/ui/gtk/options/fonts_languages_window_gtk.cc +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/fonts_languages_window.h" - -#include <gtk/gtk.h> - -#include "base/message_loop.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/options/fonts_page_gtk.h" -#include "chrome/browser/ui/gtk/options/languages_page_gtk.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - -/////////////////////////////////////////////////////////////////////////////// -// FontsLanguagesWindowGtk -// -// The contents of the Options dialog window. - -class FontsLanguagesWindowGtk { - public: - explicit FontsLanguagesWindowGtk(Profile* profile); - ~FontsLanguagesWindowGtk(); - - // Shows the tab corresponding to the specified |page|. - void ShowTabPage(gfx::NativeWindow window, FontsLanguagesPage page); - - private: - static void OnWindowDestroy(GtkWidget* widget, - FontsLanguagesWindowGtk* window); - - // The fonts and languages dialog. - GtkWidget *dialog_; - - // The container of the option pages. - GtkWidget *notebook_; - - // The Profile associated with these options. - Profile* profile_; - - // The fonts page. - FontsPageGtk fonts_page_; - - // The languages page. - LanguagesPageGtk languages_page_; - - DISALLOW_COPY_AND_ASSIGN(FontsLanguagesWindowGtk); -}; - -static FontsLanguagesWindowGtk* instance_ = NULL; - -/////////////////////////////////////////////////////////////////////////////// -// FontsLanguagesWindowGtk, public: - -FontsLanguagesWindowGtk::FontsLanguagesWindowGtk(Profile* profile) - // Always show preferences for the original profile. Most state when off - // the record comes from the original profile, but we explicitly use - // the original profile to avoid potential problems. - : profile_(profile->GetOriginalProfile()), - fonts_page_(profile_), - languages_page_(profile_) { - dialog_ = gtk_dialog_new_with_buttons( - l10n_util::GetStringUTF8(IDS_FONT_LANGUAGE_SETTING_WINDOWS_TITLE).c_str(), - // Prefs window is shared between all browser windows. - NULL, - // Non-modal. - GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE, - NULL); - - gtk_window_set_default_size(GTK_WINDOW(dialog_), 500, -1); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), - gtk_util::kContentAreaSpacing); - - notebook_ = gtk_notebook_new(); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), notebook_); - - // Fonts and Encoding tab. - gtk_notebook_append_page( - GTK_NOTEBOOK(notebook_), - fonts_page_.get_page_widget(), - gtk_label_new( - l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_FONT_TAB_TITLE).c_str())); - - // Langauges tab. - gtk_notebook_append_page( - GTK_NOTEBOOK(notebook_), - languages_page_.get_page_widget(), - gtk_label_new( - l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_TAB_TITLE).c_str())); - - // Show the notebook. - gtk_util::ShowDialogWithLocalizedSize(dialog_, -1, -1, false); - - // We only have one button and don't do any special handling, so just hook it - // directly to gtk_widget_destroy. - g_signal_connect_swapped(dialog_, "response", G_CALLBACK(gtk_widget_destroy), - dialog_); - - g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroy), this); -} - -FontsLanguagesWindowGtk::~FontsLanguagesWindowGtk() { -} - -void FontsLanguagesWindowGtk::ShowTabPage(gfx::NativeWindow window, - FontsLanguagesPage page) { - // Center our dialog over whoever displayed us. - gtk_util::CenterOverWindow(GTK_WINDOW(dialog_), window); - - // Bring options window to front if it already existed and isn't already - // in front. - gtk_util::PresentWindow(dialog_, 0); - - // If the page is out of bounds, reset to the first tab. - if (page < 0 || page >= gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook_))) - page = FONTS_ENCODING_PAGE; - - // Switch the tab to the selected |page|. - gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook_), page); -} - -/////////////////////////////////////////////////////////////////////////////// -// FontsLanguagesWindowGtk, private: - -// static -void FontsLanguagesWindowGtk::OnWindowDestroy(GtkWidget* widget, - FontsLanguagesWindowGtk* window) { - instance_ = NULL; - MessageLoop::current()->DeleteSoon(FROM_HERE, window); -} - -void ShowFontsLanguagesWindow(gfx::NativeWindow window, - FontsLanguagesPage page, - Profile* profile) { - DCHECK(profile); - // If there's already an existing fonts and language window, activate it and - // switch to the specified page. - if (!instance_) - instance_ = new FontsLanguagesWindowGtk(profile); - - instance_->ShowTabPage(window, page); -} diff --git a/chrome/browser/ui/gtk/options/fonts_page_gtk.cc b/chrome/browser/ui/gtk/options/fonts_page_gtk.cc deleted file mode 100644 index 32a9f3b..0000000 --- a/chrome/browser/ui/gtk/options/fonts_page_gtk.cc +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/fonts_page_gtk.h" - -#include <string> - -#include "base/stringprintf.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/default_encoding_combo_model.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/options/options_layout_gtk.h" -#include "chrome/common/pref_names.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/font.h" - -namespace { - -// Make a Gtk font name string from a font family name and pixel size. -std::string MakeFontName(std::string family_name, int pixel_size) { - // The given font might not be available (the default fonts we use are not - // installed by default on some distros). So figure out which font we are - // actually falling back to and display that. (See crbug.com/31381.) - string16 actual_family_name = gfx::Font( - UTF8ToUTF16(family_name), pixel_size).GetFontName(); - std::string fontname; - // TODO(mattm): We can pass in the size in pixels (px), and the font button - // actually honors it, but when you open the selector it interprets it as - // points. See crbug.com/17857 - base::SStringPrintf(&fontname, "%s, %dpx", - UTF16ToUTF8(actual_family_name).c_str(), pixel_size); - return fontname; -} - -} // namespace - -FontsPageGtk::FontsPageGtk(Profile* profile) : OptionsPageBase(profile) { - Init(); -} - -FontsPageGtk::~FontsPageGtk() { -} - -void FontsPageGtk::Init() { - scoped_ptr<OptionsLayoutBuilderGtk> - options_builder(OptionsLayoutBuilderGtk::Create()); - serif_font_button_ = gtk_font_button_new(); - gtk_font_button_set_use_font(GTK_FONT_BUTTON(serif_font_button_), TRUE); - gtk_font_button_set_use_size(GTK_FONT_BUTTON(serif_font_button_), TRUE); - g_signal_connect(serif_font_button_, "font-set", - G_CALLBACK(OnSerifFontSetThunk), this); - - sans_font_button_ = gtk_font_button_new(); - gtk_font_button_set_use_font(GTK_FONT_BUTTON(sans_font_button_), TRUE); - gtk_font_button_set_use_size(GTK_FONT_BUTTON(sans_font_button_), TRUE); - g_signal_connect(sans_font_button_, "font-set", - G_CALLBACK(OnSansFontSetThunk), this); - - fixed_font_button_ = gtk_font_button_new(); - gtk_font_button_set_use_font(GTK_FONT_BUTTON(fixed_font_button_), TRUE); - gtk_font_button_set_use_size(GTK_FONT_BUTTON(fixed_font_button_), TRUE); - g_signal_connect(fixed_font_button_, "font-set", - G_CALLBACK(OnFixedFontSetThunk), this); - - GtkWidget* font_controls = gtk_util::CreateLabeledControlsGroup(NULL, - l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SERIF_LABEL).c_str(), - serif_font_button_, - l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SANS_SERIF_LABEL).c_str(), - sans_font_button_, - l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_FIXED_WIDTH_LABEL).c_str(), - fixed_font_button_, - NULL); - - options_builder->AddOptionGroup(l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_FONT_SUB_DIALOG_FONT_TITLE), - font_controls, false); - - InitDefaultEncodingComboBox(); - std::string encoding_group_description = l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_FONT_DEFAULT_ENCODING_SELECTOR_LABEL); - GtkWidget* encoding_controls = gtk_util::CreateLabeledControlsGroup(NULL, - encoding_group_description.c_str(), - default_encoding_combobox_, - NULL); - options_builder->AddOptionGroup(l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_FONT_SUB_DIALOG_ENCODING_TITLE), - encoding_controls, false); - - page_ = options_builder->get_page_widget(); - - serif_name_.Init(prefs::kWebKitSerifFontFamily, profile()->GetPrefs(), this); - sans_serif_name_.Init(prefs::kWebKitSansSerifFontFamily, - profile()->GetPrefs(), this); - variable_width_size_.Init(prefs::kWebKitDefaultFontSize, - profile()->GetPrefs(), this); - - fixed_width_name_.Init(prefs::kWebKitFixedFontFamily, profile()->GetPrefs(), - this); - fixed_width_size_.Init(prefs::kWebKitDefaultFixedFontSize, - profile()->GetPrefs(), this); - - default_encoding_.Init(prefs::kDefaultCharset, profile()->GetPrefs(), this); - - NotifyPrefChanged(NULL); -} - -void FontsPageGtk::InitDefaultEncodingComboBox() { - default_encoding_combobox_ = gtk_combo_box_new_text(); - g_signal_connect(default_encoding_combobox_, "changed", - G_CALLBACK(OnDefaultEncodingChangedThunk), this); - default_encoding_combobox_model_.reset(new DefaultEncodingComboboxModel); - for (int i = 0; i < default_encoding_combobox_model_->GetItemCount(); ++i) { - gtk_combo_box_append_text( - GTK_COMBO_BOX(default_encoding_combobox_), - UTF16ToUTF8(default_encoding_combobox_model_->GetItemAt(i)).c_str()); - } -} - -void FontsPageGtk::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || *pref_name == prefs::kWebKitSerifFontFamily || - *pref_name == prefs::kWebKitDefaultFontSize) { - gtk_font_button_set_font_name(GTK_FONT_BUTTON(serif_font_button_), - MakeFontName(serif_name_.GetValue(), - variable_width_size_.GetValue()).c_str()); - } - if (!pref_name || *pref_name == prefs::kWebKitSansSerifFontFamily || - *pref_name == prefs::kWebKitDefaultFontSize) { - gtk_font_button_set_font_name(GTK_FONT_BUTTON(sans_font_button_), - MakeFontName(sans_serif_name_.GetValue(), - variable_width_size_.GetValue()).c_str()); - } - if (!pref_name || *pref_name == prefs::kWebKitFixedFontFamily || - *pref_name == prefs::kWebKitDefaultFixedFontSize) { - gtk_font_button_set_font_name(GTK_FONT_BUTTON(fixed_font_button_), - MakeFontName(fixed_width_name_.GetValue(), - fixed_width_size_.GetValue()).c_str()); - } - if (!pref_name || *pref_name == prefs::kDefaultCharset) { - gtk_combo_box_set_active( - GTK_COMBO_BOX(default_encoding_combobox_), - default_encoding_combobox_model_->GetSelectedEncodingIndex(profile())); - } -} - -void FontsPageGtk::SetFontsFromButton(StringPrefMember* name_pref, - IntegerPrefMember* size_pref, - GtkWidget* font_button) { - PangoFontDescription* desc = pango_font_description_from_string( - gtk_font_button_get_font_name(GTK_FONT_BUTTON(font_button))); - int size = pango_font_description_get_size(desc); - name_pref->SetValue(pango_font_description_get_family(desc)); - size_pref->SetValue(size / PANGO_SCALE); - pango_font_description_free(desc); - // Reset the button font in px, since the chooser will have set it in points. - // Also, both sans and serif share the same size so we need to update them - // both. - NotifyPrefChanged(NULL); -} - -void FontsPageGtk::OnSerifFontSet(GtkWidget* font_button) { - SetFontsFromButton(&serif_name_, - &variable_width_size_, - font_button); -} - -void FontsPageGtk::OnSansFontSet(GtkWidget* font_button) { - SetFontsFromButton(&sans_serif_name_, - &variable_width_size_, - font_button); -} - -void FontsPageGtk::OnFixedFontSet(GtkWidget* font_button) { - SetFontsFromButton(&fixed_width_name_, - &fixed_width_size_, - font_button); -} - -void FontsPageGtk::OnDefaultEncodingChanged(GtkWidget* combo_box) { - int index = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_box)); - default_encoding_.SetValue(default_encoding_combobox_model_-> - GetEncodingCharsetByIndex(index)); -} diff --git a/chrome/browser/ui/gtk/options/fonts_page_gtk.h b/chrome/browser/ui/gtk/options/fonts_page_gtk.h deleted file mode 100644 index e61d225..0000000 --- a/chrome/browser/ui/gtk/options/fonts_page_gtk.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// The fonts page of the fonts & languages options dialog, which contains font -// family and size settings, as well as the default encoding option. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_FONTS_PAGE_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_FONTS_PAGE_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include "base/scoped_ptr.h" -#include "chrome/browser/character_encoding.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/options/options_page_base.h" -#include "ui/base/gtk/gtk_signal.h" - -class DefaultEncodingComboboxModel; - -class FontsPageGtk : public OptionsPageBase { - public: - explicit FontsPageGtk(Profile* profile); - virtual ~FontsPageGtk(); - - GtkWidget* get_page_widget() const { return page_; } - - private: - void Init(); - void InitDefaultEncodingComboBox(); - - // Overridden from OptionsPageBase. - virtual void NotifyPrefChanged(const std::string* pref_name); - - // Retrieve the font selection from the button and save it to the prefs. Also - // ensure the button(s) are displayed in the proper size, as the - // GtkFontSelector returns the value in points not pixels. - void SetFontsFromButton(StringPrefMember* name_pref, - IntegerPrefMember* size_pref, - GtkWidget* font_button); - - CHROMEGTK_CALLBACK_0(FontsPageGtk, void, OnSerifFontSet); - CHROMEGTK_CALLBACK_0(FontsPageGtk, void, OnSansFontSet); - CHROMEGTK_CALLBACK_0(FontsPageGtk, void, OnFixedFontSet); - CHROMEGTK_CALLBACK_0(FontsPageGtk, void, OnDefaultEncodingChanged); - - // The font chooser widgets - GtkWidget* serif_font_button_; - GtkWidget* sans_font_button_; - GtkWidget* fixed_font_button_; - - // The default encoding combobox widget. - GtkWidget* default_encoding_combobox_; - scoped_ptr<DefaultEncodingComboboxModel> default_encoding_combobox_model_; - - // The widget containing the options for this page. - GtkWidget* page_; - - // Font name preferences. - StringPrefMember serif_name_; - StringPrefMember sans_serif_name_; - StringPrefMember fixed_width_name_; - - // Font size preferences, in pixels. - IntegerPrefMember variable_width_size_; - IntegerPrefMember fixed_width_size_; - - // Default encoding preference. - StringPrefMember default_encoding_; - - DISALLOW_COPY_AND_ASSIGN(FontsPageGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_FONTS_PAGE_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/general_page_gtk.cc b/chrome/browser/ui/gtk/options/general_page_gtk.cc deleted file mode 100644 index 497319c..0000000 --- a/chrome/browser/ui/gtk/options/general_page_gtk.cc +++ /dev/null @@ -1,816 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/general_page_gtk.h" - -#include <set> -#include <vector> - -#include "base/callback.h" -#include "base/command_line.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/custom_home_pages_table_model.h" -#include "chrome/browser/instant/instant_confirm_dialog.h" -#include "chrome/browser/instant/instant_controller.h" -#include "chrome/browser/net/url_fixer_upper.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/prefs/session_startup_pref.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/search_engines/template_url.h" -#include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/keyword_editor_view.h" -#include "chrome/browser/ui/gtk/options/managed_prefs_banner_gtk.h" -#include "chrome/browser/ui/gtk/options/options_layout_gtk.h" -#include "chrome/browser/ui/gtk/options/url_picker_dialog_gtk.h" -#include "chrome/browser/ui/options/show_options_url.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/gtk_util.h" - -namespace { - -// Markup for the text showing the current state of the default browser -const char kDefaultBrowserLabelMarkup[] = "<span color='#%s'>%s</span>"; - -// Color of the default browser text when Chromium is the default browser -const char kDefaultBrowserLabelColor[] = "008700"; - -// Color of the default browser text when Chromium is not the default browser -const char kNotDefaultBrowserLabelColor[] = "870000"; - -// Column ids for |startup_custom_pages_store_|. -enum { - COL_FAVICON, - COL_URL, - COL_TOOLTIP, - COL_COUNT, -}; - -// Column ids for |default_search_engines_model_|. -enum { - SEARCH_ENGINES_COL_INDEX, - SEARCH_ENGINES_COL_TITLE, - SEARCH_ENGINES_COL_COUNT, -}; - -bool IsNewTabUIURLString(const GURL& url) { - return url == GURL(chrome::kChromeUINewTabURL); -} - -} // namespace - -/////////////////////////////////////////////////////////////////////////////// -// GeneralPageGtk, public: - -GeneralPageGtk::GeneralPageGtk(Profile* profile) - : OptionsPageBase(profile), - template_url_model_(NULL), - instant_checkbox_(NULL), - default_search_initializing_(true), - initializing_(true), - default_browser_worker_( - new ShellIntegration::DefaultBrowserWorker(this)), - managed_prefs_banner_(profile->GetPrefs(), OPTIONS_PAGE_GENERAL) { - scoped_ptr<OptionsLayoutBuilderGtk> - options_builder(OptionsLayoutBuilderGtk::CreateOptionallyCompactLayout()); - page_ = options_builder->get_page_widget(); - - options_builder->AddWidget(managed_prefs_banner_.banner_widget(), false); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_GROUP_NAME), - InitStartupGroup(), true); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_HOMEPAGE_GROUP_NAME), - InitHomepageGroup(), false); - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME), - InitDefaultSearchGroup(), false); -#if !defined(OS_CHROMEOS) - options_builder->AddOptionGroup( - l10n_util::GetStringUTF8(IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME), - InitDefaultBrowserGroup(), false); -#endif - - registrar_.Init(profile->GetPrefs()); - registrar_.Add(prefs::kRestoreOnStartup, this); - registrar_.Add(prefs::kURLsToRestoreOnStartup, this); - - new_tab_page_is_home_page_.Init(prefs::kHomePageIsNewTabPage, - profile->GetPrefs(), this); - homepage_.Init(prefs::kHomePage, profile->GetPrefs(), this); - show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); - - default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled, - g_browser_process->local_state(), - this); - - instant_.Init(prefs::kInstantEnabled, profile->GetPrefs(), this); - - // Load initial values - NotifyPrefChanged(NULL); -} - -GeneralPageGtk::~GeneralPageGtk() { - if (template_url_model_) - template_url_model_->RemoveObserver(this); - - default_browser_worker_->ObserverDestroyed(); -} - -GtkWindow* GeneralPageGtk::GetWindow() { - return GTK_WINDOW(gtk_widget_get_toplevel(page_)); -} - -/////////////////////////////////////////////////////////////////////////////// -// GeneralPageGtk, OptionsPageBase overrides: - -void GeneralPageGtk::NotifyPrefChanged(const std::string* pref_name) { - initializing_ = true; - PrefService* prefs = profile()->GetPrefs(); - if (!pref_name || - *pref_name == prefs::kRestoreOnStartup || - *pref_name == prefs::kURLsToRestoreOnStartup) { - const SessionStartupPref startup_pref = - SessionStartupPref::GetStartupPref(prefs); - bool radio_buttons_enabled = !SessionStartupPref::TypeIsManaged(prefs); - bool restore_urls_enabled = !SessionStartupPref::URLsAreManaged(prefs); - switch (startup_pref.type) { - case SessionStartupPref::DEFAULT: - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(startup_homepage_radio_), - TRUE); - restore_urls_enabled = false; - break; - - case SessionStartupPref::LAST: - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(startup_last_session_radio_), TRUE); - restore_urls_enabled = false; - break; - - case SessionStartupPref::URLS: - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(startup_custom_radio_), - TRUE); - break; - } - gtk_widget_set_sensitive(startup_homepage_radio_, radio_buttons_enabled); - gtk_widget_set_sensitive(startup_last_session_radio_, - radio_buttons_enabled); - gtk_widget_set_sensitive(startup_custom_radio_, radio_buttons_enabled); - EnableCustomHomepagesControls(restore_urls_enabled); - startup_custom_pages_table_model_->SetURLs(startup_pref.urls); - } - - if (!pref_name || - *pref_name == prefs::kHomePageIsNewTabPage || - *pref_name == prefs::kHomePage) { - bool new_tab_page_is_home_page_managed = - new_tab_page_is_home_page_.IsManaged(); - bool homepage_managed = homepage_.IsManaged(); - bool homepage_url_is_new_tab = - IsNewTabUIURLString(GURL(homepage_.GetValue())); - bool homepage_is_new_tab = homepage_url_is_new_tab || - new_tab_page_is_home_page_.GetValue(); - // If HomepageIsNewTab is managed or - // Homepage is 'chrome://newtab' and managed, disable the radios. - bool disable_homepage_choice_buttons = - new_tab_page_is_home_page_managed || - (homepage_managed && homepage_url_is_new_tab); - if (!homepage_url_is_new_tab) { - gtk_entry_set_text(GTK_ENTRY(homepage_use_url_entry_), - homepage_.GetValue().c_str()); - } - UpdateHomepageIsNewTabRadio( - homepage_is_new_tab, !disable_homepage_choice_buttons); - EnableHomepageURLField(!homepage_is_new_tab); - } - - if (!pref_name || *pref_name == prefs::kShowHomeButton) { - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(homepage_show_home_button_checkbox_), - show_home_button_.GetValue()); - gtk_widget_set_sensitive( - homepage_show_home_button_checkbox_, - !show_home_button_.IsManaged()); - } - - if ((!pref_name || *pref_name == prefs::kInstantEnabled) && - instant_checkbox_) { - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(instant_checkbox_), instant_.GetValue()); - } - - if (!pref_name || *pref_name == prefs::kDefaultBrowserSettingEnabled) { - // If the option is managed the UI is uncondionally disabled otherwise we - // restart the standard button enabling logic. - if (default_browser_policy_.IsManaged()) - gtk_widget_set_sensitive(default_browser_use_as_default_button_, false); - else - default_browser_worker_->StartCheckDefaultBrowser(); - } - - initializing_ = false; -} - -void GeneralPageGtk::HighlightGroup(OptionsGroup highlight_group) { - // TODO(mattm): implement group highlighting -} - -/////////////////////////////////////////////////////////////////////////////// -// GeneralPageGtk, private: - -GtkWidget* GeneralPageGtk::InitStartupGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - startup_homepage_radio_ = gtk_radio_button_new_with_label(NULL, - l10n_util::GetStringUTF8( - IDS_OPTIONS_STARTUP_SHOW_DEFAULT_AND_NEWTAB).c_str()); - g_signal_connect(startup_homepage_radio_, "toggled", - G_CALLBACK(OnStartupRadioToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), startup_homepage_radio_, FALSE, FALSE, 0); - - startup_last_session_radio_ = gtk_radio_button_new_with_label_from_widget( - GTK_RADIO_BUTTON(startup_homepage_radio_), - l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_SHOW_LAST_SESSION).c_str()); - g_signal_connect(startup_last_session_radio_, "toggled", - G_CALLBACK(OnStartupRadioToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), startup_last_session_radio_, - FALSE, FALSE, 0); - - startup_custom_radio_ = gtk_radio_button_new_with_label_from_widget( - GTK_RADIO_BUTTON(startup_homepage_radio_), - l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_SHOW_PAGES).c_str()); - g_signal_connect(startup_custom_radio_, "toggled", - G_CALLBACK(OnStartupRadioToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), startup_custom_radio_, FALSE, FALSE, 0); - - GtkWidget* url_list_container = gtk_hbox_new(FALSE, - gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(vbox), url_list_container, TRUE, TRUE, 0); - - GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), - GTK_SHADOW_ETCHED_IN); - gtk_container_add(GTK_CONTAINER(url_list_container), - scroll_window); - startup_custom_pages_store_ = gtk_list_store_new(COL_COUNT, - GDK_TYPE_PIXBUF, - G_TYPE_STRING, - G_TYPE_STRING); - startup_custom_pages_tree_ = gtk_tree_view_new_with_model( - GTK_TREE_MODEL(startup_custom_pages_store_)); - gtk_container_add(GTK_CONTAINER(scroll_window), startup_custom_pages_tree_); - - // Release |startup_custom_pages_store_| so that |startup_custom_pages_tree_| - // owns the model. - g_object_unref(startup_custom_pages_store_); - - gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(startup_custom_pages_tree_), - COL_TOOLTIP); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(startup_custom_pages_tree_), - FALSE); - GtkTreeViewColumn* column = gtk_tree_view_column_new(); - GtkCellRenderer* renderer = gtk_cell_renderer_pixbuf_new(); - gtk_tree_view_column_pack_start(column, renderer, FALSE); - gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", COL_FAVICON); - renderer = gtk_cell_renderer_text_new(); - gtk_tree_view_column_pack_start(column, renderer, TRUE); - gtk_tree_view_column_add_attribute(column, renderer, "text", COL_URL); - gtk_tree_view_append_column(GTK_TREE_VIEW(startup_custom_pages_tree_), - column); - startup_custom_pages_selection_ = gtk_tree_view_get_selection( - GTK_TREE_VIEW(startup_custom_pages_tree_)); - gtk_tree_selection_set_mode(startup_custom_pages_selection_, - GTK_SELECTION_MULTIPLE); - g_signal_connect(startup_custom_pages_selection_, "changed", - G_CALLBACK(OnStartupPagesSelectionChangedThunk), this); - - startup_custom_pages_table_model_.reset( - new CustomHomePagesTableModel(profile())); - startup_custom_pages_table_adapter_.reset( - new gtk_tree::TableAdapter(this, startup_custom_pages_store_, - startup_custom_pages_table_model_.get())); - - GtkWidget* url_list_buttons = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_end(GTK_BOX(url_list_container), url_list_buttons, - FALSE, FALSE, 0); - - startup_add_custom_page_button_ = gtk_button_new_with_mnemonic( - gfx::ConvertAcceleratorsFromWindowsStyle( - l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_ADD_BUTTON)).c_str()); - g_signal_connect(startup_add_custom_page_button_, "clicked", - G_CALLBACK(OnStartupAddCustomPageClickedThunk), this); - gtk_box_pack_start(GTK_BOX(url_list_buttons), startup_add_custom_page_button_, - FALSE, FALSE, 0); - startup_remove_custom_page_button_ = gtk_button_new_with_mnemonic( - gfx::ConvertAcceleratorsFromWindowsStyle( - l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_REMOVE_BUTTON)).c_str()); - g_signal_connect(startup_remove_custom_page_button_, "clicked", - G_CALLBACK(OnStartupRemoveCustomPageClickedThunk), this); - gtk_box_pack_start(GTK_BOX(url_list_buttons), - startup_remove_custom_page_button_, FALSE, FALSE, 0); - startup_use_current_page_button_ = gtk_button_new_with_mnemonic( - gfx::ConvertAcceleratorsFromWindowsStyle( - l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_USE_CURRENT)).c_str()); - g_signal_connect(startup_use_current_page_button_, "clicked", - G_CALLBACK(OnStartupUseCurrentPageClickedThunk), this); - gtk_box_pack_start(GTK_BOX(url_list_buttons), - startup_use_current_page_button_, FALSE, FALSE, 0); - - return vbox; -} - -GtkWidget* GeneralPageGtk::InitHomepageGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - homepage_use_newtab_radio_ = gtk_radio_button_new_with_label(NULL, - l10n_util::GetStringUTF8(IDS_OPTIONS_HOMEPAGE_USE_NEWTAB).c_str()); - g_signal_connect(homepage_use_newtab_radio_, "toggled", - G_CALLBACK(OnNewTabIsHomePageToggledThunk), this); - gtk_container_add(GTK_CONTAINER(vbox), homepage_use_newtab_radio_); - - GtkWidget* homepage_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); - gtk_container_add(GTK_CONTAINER(vbox), homepage_hbox); - - homepage_use_url_radio_ = gtk_radio_button_new_with_label_from_widget( - GTK_RADIO_BUTTON(homepage_use_newtab_radio_), - l10n_util::GetStringUTF8(IDS_OPTIONS_HOMEPAGE_USE_URL).c_str()); - g_signal_connect(homepage_use_url_radio_, "toggled", - G_CALLBACK(OnNewTabIsHomePageToggledThunk), this); - gtk_box_pack_start(GTK_BOX(homepage_hbox), homepage_use_url_radio_, - FALSE, FALSE, 0); - - homepage_use_url_entry_ = gtk_entry_new(); - g_signal_connect(homepage_use_url_entry_, "changed", - G_CALLBACK(OnHomepageUseUrlEntryChangedThunk), this); - gtk_box_pack_start(GTK_BOX(homepage_hbox), homepage_use_url_entry_, - TRUE, TRUE, 0); - - homepage_show_home_button_checkbox_ = gtk_check_button_new_with_label( - l10n_util::GetStringUTF8(IDS_OPTIONS_HOMEPAGE_SHOW_BUTTON).c_str()); - g_signal_connect(homepage_show_home_button_checkbox_, "toggled", - G_CALLBACK(OnShowHomeButtonToggledThunk), this); - gtk_container_add(GTK_CONTAINER(vbox), homepage_show_home_button_checkbox_); - - return vbox; -} - -GtkWidget* GeneralPageGtk::InitDefaultSearchGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - GtkWidget* search_hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(vbox), search_hbox, FALSE, FALSE, 0); - - default_search_engines_model_ = gtk_list_store_new(SEARCH_ENGINES_COL_COUNT, - G_TYPE_UINT, - G_TYPE_STRING); - default_search_engine_combobox_ = gtk_combo_box_new_with_model( - GTK_TREE_MODEL(default_search_engines_model_)); - g_object_unref(default_search_engines_model_); - g_signal_connect(default_search_engine_combobox_, "changed", - G_CALLBACK(OnDefaultSearchEngineChangedThunk), this); - gtk_container_add(GTK_CONTAINER(search_hbox), - default_search_engine_combobox_); - - GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(default_search_engine_combobox_), - renderer, TRUE); - gtk_cell_layout_set_attributes( - GTK_CELL_LAYOUT(default_search_engine_combobox_), renderer, - "text", SEARCH_ENGINES_COL_TITLE, - NULL); - - template_url_model_ = profile()->GetTemplateURLModel(); - if (template_url_model_) { - template_url_model_->Load(); - template_url_model_->AddObserver(this); - } - OnTemplateURLModelChanged(); - - default_search_manage_engines_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8( - IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK).c_str()); - g_signal_connect(default_search_manage_engines_button_, "clicked", - G_CALLBACK(OnDefaultSearchManageEnginesClickedThunk), this); - gtk_box_pack_start(GTK_BOX(search_hbox), - default_search_manage_engines_button_, FALSE, FALSE, 0); - - // When the instant lab is on, add some options for instant. We want the - // warning text and link to align with the pref's checkbox's label. - // Need a new vbox as we don't want any spacing between these labels. - GtkWidget* instant_vbox = gtk_vbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), instant_vbox, FALSE, FALSE, 0); - - instant_checkbox_ = gtk_check_button_new_with_label( - l10n_util::GetStringUTF8(IDS_INSTANT_PREF).c_str()); - g_signal_connect(instant_checkbox_, "toggled", - G_CALLBACK(OnInstantToggledThunk), this); - gtk_box_pack_start(GTK_BOX(instant_vbox), instant_checkbox_, FALSE, FALSE, 0); - - // Relies on knowledge of GTK+ internals to find the checkbox's label child - // and then make the indent below match its vertical spacing. - GtkWidget* instant_label = gtk_bin_get_child(GTK_BIN(instant_checkbox_)); - if (instant_label && GTK_IS_LABEL(instant_label)) { - g_signal_connect(instant_label, "size-allocate", - G_CALLBACK(OnInstantLabelSizeAllocateThunk), this); - } - - instant_indent_ = gtk_fixed_new(); - GtkWidget* explanation_box = gtk_hbox_new(FALSE, 0); - GtkWidget* explanation = gtk_label_new(( - l10n_util::GetStringUTF8(IDS_INSTANT_PREF_WARNING) + " ").c_str()); - GtkWidget* learn_more_link = gtk_chrome_link_button_new( - l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); - g_signal_connect(learn_more_link, "clicked", - G_CALLBACK(OnSearchLearnMoreClickedThunk), this); - gtk_box_pack_start(GTK_BOX(explanation_box), instant_indent_, - FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(explanation_box), explanation, - FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(explanation_box), learn_more_link, - FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(instant_vbox), explanation_box, FALSE, FALSE, 0); - - return vbox; -} - -GtkWidget* GeneralPageGtk::InitDefaultBrowserGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - // TODO(mattm): the label should be created with a text like "checking for - // default" to be displayed while we wait for the check to complete. - default_browser_status_label_ = gtk_label_new(NULL); - gtk_box_pack_start(GTK_BOX(vbox), default_browser_status_label_, - FALSE, FALSE, 0); - - default_browser_use_as_default_button_ = gtk_button_new_with_label( - l10n_util::GetStringFUTF8(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)).c_str()); - g_signal_connect(default_browser_use_as_default_button_, "clicked", - G_CALLBACK(OnBrowserUseAsDefaultClickedThunk), this); - - gtk_box_pack_start(GTK_BOX(vbox), default_browser_use_as_default_button_, - FALSE, FALSE, 0); - - GtkWidget* vbox_alignment = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); - gtk_container_add(GTK_CONTAINER(vbox_alignment), vbox); - - default_browser_worker_->StartCheckDefaultBrowser(); - - return vbox_alignment; -} - -void GeneralPageGtk::OnStartupRadioToggled(GtkWidget* toggle_button) { - if (initializing_) - return; - - if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button))) { - // When selecting a radio button, we get two signals (one for the old radio - // being toggled off, one for the new one being toggled on.) Ignore the - // signal for toggling off the old button. - return; - } - SaveStartupPref(); - if (toggle_button == startup_homepage_radio_) { - UserMetricsRecordAction(UserMetricsAction("Options_Startup_Homepage"), - profile()->GetPrefs()); - } else if (toggle_button == startup_last_session_radio_) { - UserMetricsRecordAction(UserMetricsAction("Options_Startup_LastSession"), - profile()->GetPrefs()); - } else if (toggle_button == startup_custom_radio_) { - UserMetricsRecordAction(UserMetricsAction("Options_Startup_Custom"), - profile()->GetPrefs()); - } -} - -void GeneralPageGtk::OnStartupAddCustomPageClicked(GtkWidget* button) { - new UrlPickerDialogGtk( - NewCallback(this, &GeneralPageGtk::OnAddCustomUrl), - profile(), - GetWindow()); -} - -void GeneralPageGtk::OnStartupRemoveCustomPageClicked(GtkWidget* button) { - RemoveSelectedCustomUrls(); -} - -void GeneralPageGtk::OnStartupUseCurrentPageClicked(GtkWidget* button) { - SetCustomUrlListFromCurrentPages(); -} - -void GeneralPageGtk::OnStartupPagesSelectionChanged( - GtkTreeSelection* selection) { - EnableCustomHomepagesControls(true); -} - -void GeneralPageGtk::OnNewTabIsHomePageToggled(GtkWidget* toggle_button) { - if (initializing_) - return; - if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button))) { - // Ignore the signal for toggling off the old button. - return; - } - if (toggle_button == homepage_use_newtab_radio_) { - UserMetricsRecordAction(UserMetricsAction("Options_Homepage_UseNewTab"), - profile()->GetPrefs()); - UpdateHomepagePrefs(); - EnableHomepageURLField(false); - } else if (toggle_button == homepage_use_url_radio_) { - UserMetricsRecordAction(UserMetricsAction("Options_Homepage_UseURL"), - profile()->GetPrefs()); - UpdateHomepagePrefs(); - EnableHomepageURLField(true); - } -} - -void GeneralPageGtk::OnHomepageUseUrlEntryChanged(GtkWidget* editable) { - if (initializing_) - return; - UpdateHomepagePrefs(); -} - -void GeneralPageGtk::OnShowHomeButtonToggled(GtkWidget* toggle_button) { - if (initializing_) - return; - bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button)); - show_home_button_.SetValue(enabled); - if (enabled) { - UserMetricsRecordAction( - UserMetricsAction("Options_Homepage_ShowHomeButton"), - profile()->GetPrefs()); - } else { - UserMetricsRecordAction( - UserMetricsAction("Options_Homepage_HideHomeButton"), - profile()->GetPrefs()); - } -} - -void GeneralPageGtk::OnInstantToggled(GtkWidget* toggle_button) { - if (initializing_) - return; - - bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button)); - - if (enabled) { - if (!instant_.GetValue()) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(instant_checkbox_), false); - browser::ShowInstantConfirmDialogIfNecessary(GetWindow(), profile()); - } else { - InstantController::Disable(profile()); - } - - // TODO(estade): UMA? -} - -void GeneralPageGtk::OnDefaultSearchEngineChanged(GtkWidget* combo_box) { - if (default_search_initializing_) - return; - SetDefaultSearchEngineFromComboBox(); -} - -void GeneralPageGtk::OnDefaultSearchManageEnginesClicked(GtkWidget* button) { - KeywordEditorView::Show(profile()); -} - -void GeneralPageGtk::OnBrowserUseAsDefaultClicked(GtkWidget* button) { - default_browser_worker_->StartSetAsDefaultBrowser(); - // If the user made Chrome the default browser, then he/she arguably wants - // to be notified when that changes. - profile()->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); - UserMetricsRecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"), - profile()->GetPrefs()); -} - -void GeneralPageGtk::SaveStartupPref() { - SessionStartupPref pref; - - if (gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(startup_last_session_radio_))) { - pref.type = SessionStartupPref::LAST; - } else if (gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(startup_custom_radio_))) { - pref.type = SessionStartupPref::URLS; - } - - pref.urls = startup_custom_pages_table_model_->GetURLs(); - - SessionStartupPref::SetStartupPref(profile()->GetPrefs(), pref); -} - -void GeneralPageGtk::SetColumnValues(int row, GtkTreeIter* iter) { - SkBitmap bitmap = startup_custom_pages_table_model_->GetIcon(row); - GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); - string16 text = startup_custom_pages_table_model_->GetText(row, 0); - std::string tooltip = - UTF16ToUTF8(startup_custom_pages_table_model_->GetTooltip(row)); - gchar* escaped_tooltip = g_markup_escape_text(tooltip.c_str(), - tooltip.size()); - gtk_list_store_set(startup_custom_pages_store_, iter, - COL_FAVICON, pixbuf, - COL_URL, UTF16ToUTF8(text).c_str(), - COL_TOOLTIP, escaped_tooltip, - -1); - g_object_unref(pixbuf); - g_free(escaped_tooltip); -} - -void GeneralPageGtk::SetCustomUrlListFromCurrentPages() { - startup_custom_pages_table_model_->SetToCurrentlyOpenPages(); - - SaveStartupPref(); -} - -void GeneralPageGtk::OnAddCustomUrl(const GURL& url) { - // The restore URLs policy might have become managed while the dialog is - // displayed. While the model makes sure that no changes are made in this - // condition, we should still avoid the rest of the method otherwise - // graphic elements will become enabled. - if (SessionStartupPref::URLsAreManaged(profile()->GetPrefs())) - return; - std::set<int> indices; - gtk_tree::GetSelectedIndices(startup_custom_pages_selection_, &indices); - int index; - if (indices.empty()) - index = startup_custom_pages_table_model_->RowCount(); - else - index = *indices.begin() + 1; - startup_custom_pages_table_model_->Add(index, url); - - SaveStartupPref(); - - gtk_tree::SelectAndFocusRowNum(index, - GTK_TREE_VIEW(startup_custom_pages_tree_)); -} - -void GeneralPageGtk::RemoveSelectedCustomUrls() { - std::set<int> indices; - gtk_tree::GetSelectedIndices(startup_custom_pages_selection_, &indices); - - int selected_row = 0; - for (std::set<int>::reverse_iterator i = indices.rbegin(); - i != indices.rend(); ++i) { - startup_custom_pages_table_model_->Remove(*i); - selected_row = *i; - } - - SaveStartupPref(); - - // Select the next row after the last row deleted, or the above item if the - // latest item was deleted or nothing when the table doesn't have any items. - int row_count = startup_custom_pages_table_model_->RowCount(); - if (selected_row >= row_count) - selected_row = row_count - 1; - if (selected_row >= 0) { - gtk_tree::SelectAndFocusRowNum(selected_row, - GTK_TREE_VIEW(startup_custom_pages_tree_)); - } -} - -void GeneralPageGtk::OnTemplateURLModelChanged() { - if (!template_url_model_ || !template_url_model_->loaded()) { - EnableDefaultSearchEngineComboBox(false); - return; - } - default_search_initializing_ = true; - gtk_list_store_clear(default_search_engines_model_); - const TemplateURL* default_search_provider = - template_url_model_->GetDefaultSearchProvider(); - std::vector<const TemplateURL*> model_urls = - template_url_model_->GetTemplateURLs(); - bool populated = false; - for (size_t i = 0; i < model_urls.size(); ++i) { - if (!model_urls[i]->ShowInDefaultList()) - continue; - populated = true; - GtkTreeIter iter; - gtk_list_store_append(default_search_engines_model_, &iter); - gtk_list_store_set( - default_search_engines_model_, &iter, - SEARCH_ENGINES_COL_INDEX, i, - SEARCH_ENGINES_COL_TITLE, - UTF16ToUTF8(model_urls[i]->short_name()).c_str(), - -1); - if (model_urls[i] == default_search_provider) { - gtk_combo_box_set_active_iter( - GTK_COMBO_BOX(default_search_engine_combobox_), &iter); - } - } - EnableDefaultSearchEngineComboBox(populated && - !template_url_model_->is_default_search_managed()); - default_search_initializing_ = false; -} - -void GeneralPageGtk::SetDefaultSearchEngineFromComboBox() { - GtkTreeIter iter; - if (!gtk_combo_box_get_active_iter( - GTK_COMBO_BOX(default_search_engine_combobox_), &iter)) { - return; - } - guint index; - gtk_tree_model_get(GTK_TREE_MODEL(default_search_engines_model_), &iter, - SEARCH_ENGINES_COL_INDEX, &index, - -1); - std::vector<const TemplateURL*> model_urls = - template_url_model_->GetTemplateURLs(); - if (index < model_urls.size()) - template_url_model_->SetDefaultSearchProvider(model_urls[index]); - else - NOTREACHED(); -} - -void GeneralPageGtk::EnableDefaultSearchEngineComboBox(bool enable) { - gtk_widget_set_sensitive(default_search_engine_combobox_, enable); -} - -void GeneralPageGtk::UpdateHomepagePrefs() { - const GURL& homepage = URLFixerUpper::FixupURL( - gtk_entry_get_text(GTK_ENTRY(homepage_use_url_entry_)), std::string()); - bool new_tab_page_is_home_page = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(homepage_use_newtab_radio_)); - if (IsNewTabUIURLString(homepage)) { - new_tab_page_is_home_page = true; - homepage_.SetValueIfNotManaged(std::string()); - } else if (!homepage.is_valid()) { - new_tab_page_is_home_page = true; - if (!homepage.has_host()) - homepage_.SetValueIfNotManaged(std::string()); - } else { - homepage_.SetValueIfNotManaged(homepage.spec()); - } - new_tab_page_is_home_page_.SetValueIfNotManaged(new_tab_page_is_home_page); -} - -void GeneralPageGtk::UpdateHomepageIsNewTabRadio(bool homepage_is_new_tab, - bool enabled) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(homepage_use_newtab_radio_), - homepage_is_new_tab); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(homepage_use_url_radio_), - !homepage_is_new_tab); - gtk_widget_set_sensitive(homepage_use_newtab_radio_, enabled); - gtk_widget_set_sensitive(homepage_use_url_radio_, enabled); -} - -void GeneralPageGtk::EnableHomepageURLField(bool enabled) { - if (homepage_.IsManaged()) - enabled = false; - gtk_widget_set_sensitive(homepage_use_url_entry_, enabled); -} - -void GeneralPageGtk::EnableCustomHomepagesControls(bool enable) { - gtk_widget_set_sensitive(startup_add_custom_page_button_, enable); - gtk_widget_set_sensitive(startup_remove_custom_page_button_, - enable && - gtk_tree_selection_count_selected_rows(startup_custom_pages_selection_)); - gtk_widget_set_sensitive(startup_use_current_page_button_, enable); - gtk_widget_set_sensitive(startup_custom_pages_tree_, enable); -} - -void GeneralPageGtk::SetDefaultBrowserUIState( - ShellIntegration::DefaultBrowserUIState state) { - const char* color = NULL; - std::string text; - if (state == ShellIntegration::STATE_IS_DEFAULT) { - color = kDefaultBrowserLabelColor; - text = l10n_util::GetStringFUTF8(IDS_OPTIONS_DEFAULTBROWSER_DEFAULT, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); - } else if (state == ShellIntegration::STATE_NOT_DEFAULT) { - color = kNotDefaultBrowserLabelColor; - text = l10n_util::GetStringFUTF8(IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); - } else if (state == ShellIntegration::STATE_UNKNOWN) { - color = kNotDefaultBrowserLabelColor; - text = l10n_util::GetStringFUTF8(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); - } - if (color) { - char* markup = g_markup_printf_escaped(kDefaultBrowserLabelMarkup, - color, text.c_str()); - gtk_label_set_markup(GTK_LABEL(default_browser_status_label_), markup); - g_free(markup); - } - - gtk_widget_set_sensitive(default_browser_use_as_default_button_, - state == ShellIntegration::STATE_NOT_DEFAULT && - !default_browser_policy_.IsManaged()); -} - -void GeneralPageGtk::OnInstantLabelSizeAllocate(GtkWidget* sender, - GtkAllocation* allocation) { - int desired_width = allocation->x - sender->parent->allocation.x; - GtkRequisition req; - gtk_widget_size_request(instant_indent_, &req); - if (req.width != desired_width) - gtk_widget_set_size_request(instant_indent_, desired_width, -1); -} - -void GeneralPageGtk::OnSearchLearnMoreClicked(GtkWidget* sender) { - browser::ShowOptionsURL(profile(), browser::InstantLearnMoreURL()); -} diff --git a/chrome/browser/ui/gtk/options/general_page_gtk.h b/chrome/browser/ui/gtk/options/general_page_gtk.h deleted file mode 100644 index 0ef4c14..0000000 --- a/chrome/browser/ui/gtk/options/general_page_gtk.h +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_GENERAL_PAGE_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_GENERAL_PAGE_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include <string> - -#include "chrome/browser/prefs/pref_change_registrar.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/search_engines/template_url_model_observer.h" -#include "chrome/browser/shell_integration.h" -#include "chrome/browser/ui/gtk/gtk_tree.h" -#include "chrome/browser/ui/gtk/options/managed_prefs_banner_gtk.h" -#include "chrome/browser/ui/options/options_page_base.h" -#include "googleurl/src/gurl.h" -#include "ui/base/gtk/gtk_signal.h" - -class CustomHomePagesTableModel; -class Profile; -class TemplateURLModel; - -class GeneralPageGtk : public OptionsPageBase, - public TemplateURLModelObserver, - public ShellIntegration::DefaultBrowserObserver, - public gtk_tree::TableAdapter::Delegate { - public: - explicit GeneralPageGtk(Profile* profile); - ~GeneralPageGtk(); - - GtkWidget* get_page_widget() const { return page_; } - - private: - GtkWindow* GetWindow(); - - // Overridden from OptionsPageBase - virtual void NotifyPrefChanged(const std::string* pref_name); - virtual void HighlightGroup(OptionsGroup highlight_group); - - // Initialize the option group widgets, return their container - GtkWidget* InitStartupGroup(); - GtkWidget* InitHomepageGroup(); - GtkWidget* InitDefaultSearchGroup(); - GtkWidget* InitDefaultBrowserGroup(); - - // Saves the startup preference from the values in the ui - void SaveStartupPref(); - - // Set the custom url list using the pages currently open - void SetCustomUrlListFromCurrentPages(); - - // Callback from UrlPickerDialogGtk, for adding custom urls manually. - // If a single row in the list is selected, the new url will be inserted - // before that row. Otherwise the new row will be added to the end. - void OnAddCustomUrl(const GURL& url); - - // Removes urls that are currently selected - void RemoveSelectedCustomUrls(); - - // Overridden from TemplateURLModelObserver. - // Populates the default search engine combobox from the model. - virtual void OnTemplateURLModelChanged(); - - // Set the default search engine pref to the combo box active item. - void SetDefaultSearchEngineFromComboBox(); - - // Set the default search engine combo box state. - void EnableDefaultSearchEngineComboBox(bool enable); - - // Copies the home page preferences from the gui controls to - // kNewTabPageIsHomePage and kHomePage. If an empty or null-host - // URL is specified, then we revert to using NewTab page as the Homepage. - void UpdateHomepagePrefs(); - - // Enables or disables the field for entering a custom homepage URL. - void EnableHomepageURLField(bool enabled); - - // Sets the state and enables/disables the radio buttons that control - // if the home page is the new tab page. - void UpdateHomepageIsNewTabRadio(bool homepage_is_new_tab, bool enabled); - - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnStartupRadioToggled); - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnStartupAddCustomPageClicked); - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnStartupRemoveCustomPageClicked); - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnStartupUseCurrentPageClicked); - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnNewTabIsHomePageToggled); - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnHomepageUseUrlEntryChanged); - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnShowHomeButtonToggled); - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnDefaultSearchEngineChanged); - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, - OnDefaultSearchManageEnginesClicked); - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnInstantToggled); - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnBrowserUseAsDefaultClicked); - CHROMEGTK_CALLBACK_1(GeneralPageGtk, void, OnInstantLabelSizeAllocate, - GtkAllocation*); - CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnSearchLearnMoreClicked); - - CHROMEG_CALLBACK_0(GeneralPageGtk, void, OnStartupPagesSelectionChanged, - GtkTreeSelection*); - - // Enables/Disables the controls associated with the custom start pages - // option if that preference is not selected. - void EnableCustomHomepagesControls(bool enable); - - // ShellIntegration::DefaultBrowserObserver implementation. - virtual void SetDefaultBrowserUIState( - ShellIntegration::DefaultBrowserUIState state); - - // gtk_tree::TableAdapter::Delegate implementation. - virtual void SetColumnValues(int row, GtkTreeIter* iter); - - // Widgets of the startup group - GtkWidget* startup_homepage_radio_; - GtkWidget* startup_last_session_radio_; - GtkWidget* startup_custom_radio_; - GtkWidget* startup_custom_pages_tree_; - GtkListStore* startup_custom_pages_store_; - GtkTreeSelection* startup_custom_pages_selection_; - GtkWidget* startup_add_custom_page_button_; - GtkWidget* startup_remove_custom_page_button_; - GtkWidget* startup_use_current_page_button_; - - // The model for |startup_custom_pages_store_|. - scoped_ptr<CustomHomePagesTableModel> startup_custom_pages_table_model_; - scoped_ptr<gtk_tree::TableAdapter> startup_custom_pages_table_adapter_; - - // Widgets and prefs of the homepage group - GtkWidget* homepage_use_newtab_radio_; - GtkWidget* homepage_use_url_radio_; - GtkWidget* homepage_use_url_entry_; - GtkWidget* homepage_show_home_button_checkbox_; - BooleanPrefMember new_tab_page_is_home_page_; - StringPrefMember homepage_; - BooleanPrefMember show_home_button_; - - // Widgets and data of the default search group - GtkWidget* default_search_engine_combobox_; - GtkListStore* default_search_engines_model_; - GtkWidget* default_search_manage_engines_button_; - TemplateURLModel* template_url_model_; - GtkWidget* instant_checkbox_; - // This widget acts as the indent for the instant warning label. - GtkWidget* instant_indent_; - BooleanPrefMember instant_; - - // Widgets of the default browser group - GtkWidget* default_browser_status_label_; - GtkWidget* default_browser_use_as_default_button_; - BooleanPrefMember default_browser_policy_; - - // The parent GtkTable widget - GtkWidget* page_; - - // Flag to ignore gtk callbacks while we are populating default search urls. - bool default_search_initializing_; - - // Flag to ignore gtk callbacks while we are loading prefs, to avoid - // then turning around and saving them again. - bool initializing_; - - // The helper object that performs default browser set/check tasks. - scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_; - - // Tracks managed preference warning banner state. - ManagedPrefsBannerGtk managed_prefs_banner_; - - PrefChangeRegistrar registrar_; - - DISALLOW_COPY_AND_ASSIGN(GeneralPageGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_GENERAL_PAGE_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/languages_page_gtk.cc b/chrome/browser/ui/gtk/options/languages_page_gtk.cc deleted file mode 100644 index 77c6929..0000000 --- a/chrome/browser/ui/gtk/options/languages_page_gtk.cc +++ /dev/null @@ -1,450 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/languages_page_gtk.h" - -#include <set> -#include <string> -#include <vector> - -#include "base/command_line.h" -#include "base/message_loop.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/language_combobox_model.h" -#include "chrome/browser/language_order_table_model.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/spellcheck_common.h" -#include "grit/generated_resources.h" -#include "ui/base/gtk/gtk_signal.h" -#include "ui/base/l10n/l10n_util.h" - -namespace { - -const int kWrapWidth = 475; - -GtkWidget* NewComboboxFromModel(ui::ComboboxModel* model) { - GtkWidget* combobox = gtk_combo_box_new_text(); - int count = model->GetItemCount(); - for (int i = 0; i < count; ++i) - gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), - UTF16ToUTF8(model->GetItemAt(i)).c_str()); - return combobox; -} - -//////////////////////////////////////////////////////////////////////////////// -// AddLanguageDialog - -class AddLanguageDialog { - public: - AddLanguageDialog(Profile* profile, LanguagesPageGtk* delegate); - virtual ~AddLanguageDialog() {} - - private: - // Callback for dialog buttons. - CHROMEGTK_CALLBACK_1(AddLanguageDialog, void, OnResponse, int); - - // Callback for window destruction. - CHROMEGTK_CALLBACK_0(AddLanguageDialog, void, OnWindowDestroy); - - // The dialog window. - GtkWidget* dialog_; - - // The language chooser combobox. - GtkWidget* combobox_; - scoped_ptr<LanguageComboboxModel> accept_language_combobox_model_; - - // Used for call back to LanguagePageGtk that language has been selected. - LanguagesPageGtk* language_delegate_; - - DISALLOW_COPY_AND_ASSIGN(AddLanguageDialog); -}; - -AddLanguageDialog::AddLanguageDialog(Profile* profile, - LanguagesPageGtk* delegate) - : language_delegate_(delegate) { - GtkWindow* parent = GTK_WINDOW( - gtk_widget_get_toplevel(delegate->get_page_widget())); - - dialog_ = gtk_dialog_new_with_buttons( - l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_TAB_TITLE).c_str(), - parent, - static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_ADD, - GTK_RESPONSE_OK, - NULL); - gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_OK); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), - gtk_util::kContentAreaSpacing); - - const std::string app_locale = g_browser_process->GetApplicationLocale(); - std::vector<std::string> locale_codes; - l10n_util::GetAcceptLanguagesForLocale(app_locale, &locale_codes); - accept_language_combobox_model_.reset( - new LanguageComboboxModel(profile, locale_codes)); - combobox_ = NewComboboxFromModel(accept_language_combobox_model_.get()); - gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_), 0); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), combobox_); - - g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); - g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); - - gtk_util::ShowDialog(dialog_); -} - -void AddLanguageDialog::OnResponse(GtkWidget* dialog, int response_id) { - if (response_id == GTK_RESPONSE_OK) { - int selected = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_)); - language_delegate_->OnAddLanguage( - accept_language_combobox_model_->GetLocaleFromIndex(selected)); - } - gtk_widget_destroy(dialog_); -} - -void AddLanguageDialog::OnWindowDestroy(GtkWidget* widget) { - MessageLoop::current()->DeleteSoon(FROM_HERE, this); -} - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// -// LanguagesPageGtk - -LanguagesPageGtk::LanguagesPageGtk(Profile* profile) - : OptionsPageBase(profile), - enable_autospellcorrect_checkbox_(NULL), - initializing_(true) { - Init(); -} - -LanguagesPageGtk::~LanguagesPageGtk() { -} - -void LanguagesPageGtk::Init() { - page_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing); - gtk_container_set_border_width(GTK_CONTAINER(page_), - gtk_util::kContentAreaBorder); - - // Languages order controls. - GtkWidget* languages_vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(page_), languages_vbox, - TRUE, TRUE, 0); - - GtkWidget* languages_instructions_label = gtk_label_new( - l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_INSTRUCTIONS).c_str()); - gtk_util::SetLabelWidth(languages_instructions_label, kWrapWidth); - gtk_box_pack_start(GTK_BOX(languages_vbox), languages_instructions_label, - FALSE, FALSE, 0); - - GtkWidget* languages_list_hbox = gtk_hbox_new(FALSE, - gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(languages_vbox), languages_list_hbox, - TRUE, TRUE, 0); - - // Languages order tree. - language_order_store_ = gtk_list_store_new(COL_COUNT, - G_TYPE_STRING); - language_order_tree_ = gtk_tree_view_new_with_model( - GTK_TREE_MODEL(language_order_store_)); - g_object_unref(language_order_store_); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(language_order_tree_), FALSE); - GtkTreeViewColumn* lang_column = gtk_tree_view_column_new_with_attributes( - "", - gtk_cell_renderer_text_new(), - "text", COL_LANG, - NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(language_order_tree_), lang_column); - language_order_selection_ = gtk_tree_view_get_selection( - GTK_TREE_VIEW(language_order_tree_)); - gtk_tree_selection_set_mode(language_order_selection_, - GTK_SELECTION_MULTIPLE); - g_signal_connect(language_order_selection_, "changed", - G_CALLBACK(OnSelectionChangedThunk), this); - GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), - GTK_SHADOW_ETCHED_IN); - gtk_container_add(GTK_CONTAINER(scroll_window), language_order_tree_); - gtk_box_pack_start(GTK_BOX(languages_list_hbox), scroll_window, - TRUE, TRUE, 0); - - language_order_table_model_.reset(new LanguageOrderTableModel); - language_order_table_adapter_.reset( - new gtk_tree::TableAdapter(this, language_order_store_, - language_order_table_model_.get())); - - // Languages order buttons. - GtkWidget* languages_buttons_vbox = gtk_vbox_new(FALSE, - gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(languages_list_hbox), languages_buttons_vbox, - FALSE, FALSE, 0); - - add_button_ = gtk_button_new_with_label(l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_SELECTOR_ADD_BUTTON_LABEL).c_str()); - g_signal_connect(add_button_, "clicked", - G_CALLBACK(OnAddButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(languages_buttons_vbox), add_button_, - FALSE, FALSE, 0); - - std::string remove_button_text = l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_SELECTOR_REMOVE_BUTTON_LABEL); - remove_button_ = gtk_button_new_with_label(remove_button_text.c_str()); - g_signal_connect(remove_button_, "clicked", - G_CALLBACK(OnRemoveButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(languages_buttons_vbox), remove_button_, - FALSE, FALSE, 0); - - std::string move_up_button_text = l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_SELECTOR_MOVEUP_BUTTON_LABEL); - move_up_button_ = gtk_button_new_with_label(move_up_button_text.c_str()); - g_signal_connect(move_up_button_, "clicked", - G_CALLBACK(OnMoveUpButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(languages_buttons_vbox), move_up_button_, - FALSE, FALSE, 0); - - std::string move_down_button_text = l10n_util::GetStringUTF8( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_SELECTOR_MOVEDOWN_BUTTON_LABEL); - move_down_button_ = gtk_button_new_with_label(move_down_button_text.c_str()); - g_signal_connect(move_down_button_, "clicked", - G_CALLBACK(OnMoveDownButtonClickedThunk), this); - gtk_box_pack_start(GTK_BOX(languages_buttons_vbox), move_down_button_, - FALSE, FALSE, 0); - - // Spell checker controls. - GtkWidget* spellchecker_vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(page_), spellchecker_vbox, - FALSE, FALSE, 0); - - enable_spellchecking_checkbox_ = gtk_check_button_new_with_label( - l10n_util::GetStringUTF8(IDS_OPTIONS_ENABLE_SPELLCHECK).c_str()); - g_signal_connect(enable_spellchecking_checkbox_, "toggled", - G_CALLBACK(OnEnableSpellCheckingToggledThunk), this); - gtk_box_pack_start(GTK_BOX(spellchecker_vbox), enable_spellchecking_checkbox_, - FALSE, FALSE, 0); - - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { - enable_autospellcorrect_checkbox_ = gtk_check_button_new_with_label( - l10n_util::GetStringUTF8( - IDS_OPTIONS_ENABLE_AUTO_SPELL_CORRECTION).c_str()); - g_signal_connect(enable_autospellcorrect_checkbox_, "toggled", - G_CALLBACK(OnEnableAutoSpellCheckingToggledThunk), this); - gtk_box_pack_start(GTK_BOX(spellchecker_vbox), - enable_autospellcorrect_checkbox_, FALSE, FALSE, 0); - } - - std::vector<std::string> spell_check_languages; - SpellCheckCommon::SpellCheckLanguages(&spell_check_languages); - dictionary_language_model_.reset(new LanguageComboboxModel(profile(), - spell_check_languages)); - dictionary_language_combobox_ = NewComboboxFromModel( - dictionary_language_model_.get()); - g_signal_connect(dictionary_language_combobox_, "changed", - G_CALLBACK(OnDictionaryLanguageChangedThunk), this); - GtkWidget* dictionary_language_control = - gtk_util::CreateLabeledControlsGroup(NULL, - l10n_util::GetStringUTF8( - IDS_OPTIONS_CHROME_DICTIONARY_LANGUAGE).c_str(), - dictionary_language_combobox_, - NULL); - gtk_box_pack_start(GTK_BOX(spellchecker_vbox), dictionary_language_control, - FALSE, FALSE, 0); - - // Initialize. - accept_languages_.Init(prefs::kAcceptLanguages, - profile()->GetPrefs(), this); - dictionary_language_.Init(prefs::kSpellCheckDictionary, - profile()->GetPrefs(), this); - enable_spellcheck_.Init(prefs::kEnableSpellCheck, - profile()->GetPrefs(), this); - enable_autospellcorrect_.Init(prefs::kEnableAutoSpellCorrect, - profile()->GetPrefs(), this); - NotifyPrefChanged(NULL); - EnableControls(); -} - -void LanguagesPageGtk::SetColumnValues(int row, GtkTreeIter* iter) { - string16 lang = language_order_table_model_->GetText(row, 0); - gtk_list_store_set(language_order_store_, iter, - COL_LANG, UTF16ToUTF8(lang).c_str(), - -1); -} - -void LanguagesPageGtk::OnAnyModelUpdate() { - if (!initializing_) - accept_languages_.SetValue(language_order_table_model_->GetLanguageList()); - EnableControls(); -} - -void LanguagesPageGtk::EnableControls() { - int num_selected = gtk_tree_selection_count_selected_rows( - language_order_selection_); - int row_count = gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(language_order_store_), NULL); - gtk_widget_set_sensitive(move_up_button_, - num_selected == 1 && FirstSelectedRowNum() > 0); - gtk_widget_set_sensitive(move_down_button_, - num_selected == 1 && - FirstSelectedRowNum() < row_count - 1); - gtk_widget_set_sensitive(remove_button_, num_selected > 0); -} - -int LanguagesPageGtk::FirstSelectedRowNum() { - int row_num = -1; - GList* list = gtk_tree_selection_get_selected_rows(language_order_selection_, - NULL); - if (list) { - row_num = gtk_tree::GetRowNumForPath(static_cast<GtkTreePath*>(list->data)); - g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); - g_list_free(list); - } - return row_num; -} - -void LanguagesPageGtk::NotifyPrefChanged(const std::string* pref_name) { - initializing_ = true; - if (!pref_name || *pref_name == prefs::kAcceptLanguages) { - language_order_table_model_->SetAcceptLanguagesString( - accept_languages_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kSpellCheckDictionary) { - int index = dictionary_language_model_->GetSelectedLanguageIndex( - prefs::kSpellCheckDictionary); - - // If not found, fall back from "language-region" to "language". - if (index < 0) { - const std::string& lang_region = dictionary_language_.GetValue(); - dictionary_language_.SetValue( - SpellCheckCommon::GetLanguageFromLanguageRegion(lang_region)); - index = dictionary_language_model_->GetSelectedLanguageIndex( - prefs::kSpellCheckDictionary); - } - - gtk_combo_box_set_active(GTK_COMBO_BOX(dictionary_language_combobox_), - index); - } - if (!pref_name || *pref_name == prefs::kEnableSpellCheck) { - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(enable_spellchecking_checkbox_), - enable_spellcheck_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kEnableAutoSpellCorrect) { - if (enable_autospellcorrect_checkbox_) { - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(enable_autospellcorrect_checkbox_), - enable_autospellcorrect_.GetValue()); - } - } - initializing_ = false; -} - -void LanguagesPageGtk::OnAddLanguage(const std::string& new_language) { - if (language_order_table_model_->Add(new_language)) - gtk_tree::SelectAndFocusRowNum(language_order_table_model_->RowCount() - 1, - GTK_TREE_VIEW(language_order_tree_)); -} - -void LanguagesPageGtk::OnSelectionChanged(GtkTreeSelection* selection) { - EnableControls(); -} - -void LanguagesPageGtk::OnAddButtonClicked(GtkWidget* button) { - new AddLanguageDialog(profile(), this); -} - -void LanguagesPageGtk::OnRemoveButtonClicked(GtkWidget* button) { - std::set<int> selected_rows; - gtk_tree::GetSelectedIndices(language_order_selection_, - &selected_rows); - - int selected_row = 0; - for (std::set<int>::reverse_iterator selected = selected_rows.rbegin(); - selected != selected_rows.rend(); ++selected) { - language_order_table_model_->Remove(*selected); - selected_row = *selected; - } - int row_count = language_order_table_model_->RowCount(); - if (row_count <= 0) - return; - if (selected_row >= row_count) - selected_row = row_count - 1; - gtk_tree::SelectAndFocusRowNum(selected_row, - GTK_TREE_VIEW(language_order_tree_)); -} - -void LanguagesPageGtk::OnMoveUpButtonClicked(GtkWidget* button) { - int item_selected = FirstSelectedRowNum(); - language_order_table_model_->MoveUp(item_selected); - gtk_tree::SelectAndFocusRowNum( - item_selected - 1, GTK_TREE_VIEW(language_order_tree_)); -} - -void LanguagesPageGtk::OnMoveDownButtonClicked(GtkWidget* button) { - int item_selected = FirstSelectedRowNum(); - language_order_table_model_->MoveDown(item_selected); - gtk_tree::SelectAndFocusRowNum( - item_selected + 1, GTK_TREE_VIEW(language_order_tree_)); -} - -void LanguagesPageGtk::OnEnableSpellCheckingToggled(GtkWidget* toggle_button) { - if (initializing_) - return; - enable_spellcheck_.SetValue( - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button))); -} - -void LanguagesPageGtk::OnEnableAutoSpellCheckingToggled( - GtkWidget* toggle_button) { - if (initializing_) - return; - enable_autospellcorrect_.SetValue( - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button))); -} - -void LanguagesPageGtk::OnDictionaryLanguageChanged(GtkWidget* widget) { - if (initializing_) - return; - int new_index = gtk_combo_box_get_active( - GTK_COMBO_BOX(dictionary_language_combobox_)); - - if (new_index < 0 || - new_index >= dictionary_language_model_->GetItemCount()) { - NOTREACHED(); - return; - } - - // Remove the previously added spell check language to the accept list. - if (!spellcheck_language_added_.empty()) { - int old_index = language_order_table_model_->GetIndex( - spellcheck_language_added_); - if (old_index > -1) - language_order_table_model_->Remove(old_index); - } - - // Add this new spell check language only if it is not already in the - // accept language list. - std::string language = - dictionary_language_model_->GetLocaleFromIndex(new_index); - int index = language_order_table_model_->GetIndex(language); - if (index == -1) { - // Add the new language. - OnAddLanguage(language); - spellcheck_language_added_ = language; - } else { - spellcheck_language_added_ = ""; - } - - UserMetricsRecordAction(UserMetricsAction("Options_DictionaryLanguage"), - profile()->GetPrefs()); - dictionary_language_.SetValue(language); -} diff --git a/chrome/browser/ui/gtk/options/languages_page_gtk.h b/chrome/browser/ui/gtk/options/languages_page_gtk.h deleted file mode 100644 index e3eaa27..0000000 --- a/chrome/browser/ui/gtk/options/languages_page_gtk.h +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// The languages page of the Languages & languages options dialog, which -// contains accept-languages and spellchecker language options. -// -// Note that we intentionally do not implement the application locale setting, -// as it does not make sense on Linux, where locale is set through the LANG and -// LC_* environment variables. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_LANGUAGES_PAGE_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_LANGUAGES_PAGE_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include <string> - -#include "base/gtest_prod_util.h" -#include "base/scoped_ptr.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/gtk/gtk_tree.h" -#include "chrome/browser/ui/options/options_page_base.h" -#include "ui/base/gtk/gtk_signal.h" - -class LanguageComboboxModel; -class LanguageOrderTableModel; - -class LanguagesPageGtk - : public OptionsPageBase, - public gtk_tree::TableAdapter::Delegate { - public: - explicit LanguagesPageGtk(Profile* profile); - virtual ~LanguagesPageGtk(); - - GtkWidget* get_page_widget() const { return page_; } - - // gtk_tree::TableAdapter::Delegate implementation. - virtual void OnAnyModelUpdate(); - virtual void SetColumnValues(int row, GtkTreeIter* iter); - - // Callback from AddLanguageDialog. - void OnAddLanguage(const std::string& new_language); - - private: - // Column ids for |language_order_store_|. - enum { - COL_LANG, - COL_COUNT, - }; - - void Init(); - - // Enable buttons based on selection state. - void EnableControls(); - - // Get the row number of the first selected row or -1 if no row is selected. - int FirstSelectedRowNum(); - - // Overridden from OptionsPageBase. - virtual void NotifyPrefChanged(const std::string* pref_name); - - // Callbacks for accept languages widgets. - CHROMEG_CALLBACK_0(LanguagesPageGtk, void, OnSelectionChanged, - GtkTreeSelection*); - CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnAddButtonClicked); - CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnRemoveButtonClicked); - CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnMoveUpButtonClicked); - CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnMoveDownButtonClicked); - - // Callbacks for spellchecker option widgets. - CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnEnableSpellCheckingToggled); - CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, - OnEnableAutoSpellCheckingToggled); - CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnDictionaryLanguageChanged); - - // The accept languages widgets. - GtkListStore* language_order_store_; - GtkWidget* language_order_tree_; - GtkTreeSelection* language_order_selection_; - GtkWidget* move_up_button_; - GtkWidget* move_down_button_; - GtkWidget* add_button_; - GtkWidget* remove_button_; - - // The spell checking widgets. - GtkWidget* dictionary_language_combobox_; - GtkWidget* enable_autospellcorrect_checkbox_; - GtkWidget* enable_spellchecking_checkbox_; - - // The widget containing the options for this page. - GtkWidget* page_; - - // The model for |language_order_store_|. - scoped_ptr<LanguageOrderTableModel> language_order_table_model_; - scoped_ptr<gtk_tree::TableAdapter> language_order_table_adapter_; - - // Accept languages pref. - StringPrefMember accept_languages_; - - // The spellchecker "dictionary language" pref and model. - StringPrefMember dictionary_language_; - scoped_ptr<LanguageComboboxModel> dictionary_language_model_; - - // If a language was auto-added to accept_languages_ due to being selected as - // the dictionary language, it is saved in this string, so that it can be - // removed if the dictionary language is changed again. - std::string spellcheck_language_added_; - - // SpellChecker enable pref. - BooleanPrefMember enable_spellcheck_; - - // Auto spell correction pref. - BooleanPrefMember enable_autospellcorrect_; - - // Flag to ignore gtk callbacks while we are loading prefs, to avoid - // then turning around and saving them again. - bool initializing_; - - friend class LanguagesPageGtkTest; - FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, RemoveAcceptLang); - FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, RemoveMultipleAcceptLang); - FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, MoveAcceptLang); - FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, AddAcceptLang); - FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, EnableSpellChecking); - FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, DictionaryLanguage); - - DISALLOW_COPY_AND_ASSIGN(LanguagesPageGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_LANGUAGES_PAGE_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/languages_page_gtk_unittest.cc b/chrome/browser/ui/gtk/options/languages_page_gtk_unittest.cc deleted file mode 100644 index 7df868f..0000000 --- a/chrome/browser/ui/gtk/options/languages_page_gtk_unittest.cc +++ /dev/null @@ -1,309 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/languages_page_gtk.h" - -#include <gtk/gtk.h> - -#include "base/message_loop.h" -#include "base/string_util.h" -#include "chrome/browser/language_combobox_model.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/common/pref_names.h" -#include "chrome/test/testing_profile.h" -#include "testing/gtest/include/gtest/gtest.h" - -class LanguagesPageGtkTest : public testing::Test { - public: - virtual void SetUp() { - profile_.reset(new TestingProfile()); - } - - // Get the accept languages displayed in the dialog in the order they are - // displayed, as a comma seperated string. - // Ex: EXPECT_STREQ("en,ja", GetDisplayedLangs(page).c_str()); - std::string GetDisplayedLangs(const LanguagesPageGtk& page) { - std::vector<std::string> parts; - GtkTreeModel* tree_model = GTK_TREE_MODEL(page.language_order_store_); - GtkTreeIter iter; - if (!gtk_tree_model_get_iter_first(tree_model, &iter)) - return std::string(); - while (true) { - gchar* name; - gtk_tree_model_get(tree_model, &iter, LanguagesPageGtk::COL_LANG, &name, - -1); - parts.push_back(name); - g_free(name); - if (!gtk_tree_model_iter_next(tree_model, &iter)) - break; - } - return JoinString(parts, ','); - } - - std::string GetDisplayedSpellCheckerLang(const LanguagesPageGtk& page) { - gchar* text = gtk_combo_box_get_active_text( - GTK_COMBO_BOX(page.dictionary_language_combobox_)); - std::string result = text; - g_free(text); - int space_pos = result.find(' '); - if (space_pos) - result = result.substr(0, space_pos); - return result; - } - - protected: - MessageLoopForUI message_loop_; - scoped_ptr<TestingProfile> profile_; -}; - -TEST_F(LanguagesPageGtkTest, RemoveAcceptLang) { - profile_->GetPrefs()->SetString(prefs::kAcceptLanguages, "en,ja,es"); - LanguagesPageGtk page(profile_.get()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.add_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - - GtkTreeIter iter; - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(page.language_order_store_), - &iter, NULL, 1); - gtk_tree_selection_select_iter(page.language_order_selection_, &iter); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.add_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(page.remove_button_)); - EXPECT_STREQ("English,Spanish", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("en,es", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.add_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_EQ(1, page.FirstSelectedRowNum()); - - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(page.language_order_store_), - &iter, NULL, 1); - gtk_tree_selection_select_iter(page.language_order_selection_, &iter); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.add_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(page.remove_button_)); - EXPECT_STREQ("English", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("en", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.add_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_EQ(0, page.FirstSelectedRowNum()); - - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(page.language_order_store_), - &iter, NULL, 0); - gtk_tree_selection_select_iter(page.language_order_selection_, &iter); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.add_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(page.remove_button_)); - EXPECT_STREQ("", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.add_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_EQ(-1, page.FirstSelectedRowNum()); -} - -TEST_F(LanguagesPageGtkTest, RemoveMultipleAcceptLang) { - profile_->GetPrefs()->SetString(prefs::kAcceptLanguages, "en,ja,es,fr,it"); - LanguagesPageGtk page(profile_.get()); - GtkTreeIter iter; - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(page.language_order_store_), - &iter, NULL, 1); - gtk_tree_selection_select_iter(page.language_order_selection_, &iter); - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(page.language_order_store_), - &iter, NULL, 3); - gtk_tree_selection_select_iter(page.language_order_selection_, &iter); - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(page.language_order_store_), - &iter, NULL, 4); - gtk_tree_selection_select_iter(page.language_order_selection_, &iter); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(page.remove_button_)); - EXPECT_STREQ("English,Spanish", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("en,es", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - EXPECT_EQ(1, page.FirstSelectedRowNum()); - - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(page.language_order_store_), - &iter, NULL, 1); - gtk_tree_selection_select_iter(page.language_order_selection_, &iter); - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(page.language_order_store_), - &iter, NULL, 0); - gtk_tree_selection_select_iter(page.language_order_selection_, &iter); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - - gtk_button_clicked(GTK_BUTTON(page.remove_button_)); - EXPECT_STREQ("", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - EXPECT_EQ(-1, page.FirstSelectedRowNum()); -} - -TEST_F(LanguagesPageGtkTest, MoveAcceptLang) { - profile_->GetPrefs()->SetString(prefs::kAcceptLanguages, "en,ja,es"); - LanguagesPageGtk page(profile_.get()); - EXPECT_STREQ("English,Japanese,Spanish", GetDisplayedLangs(page).c_str()); - GtkTreeIter iter; - - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(page.language_order_store_), - &iter, NULL, 0); - gtk_tree_selection_select_iter(page.language_order_selection_, &iter); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - - gtk_button_clicked(GTK_BUTTON(page.move_down_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_STREQ("Japanese,English,Spanish", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("ja,en,es", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - - gtk_button_clicked(GTK_BUTTON(page.move_down_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_STREQ("Japanese,Spanish,English", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("ja,es,en", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - - gtk_button_clicked(GTK_BUTTON(page.move_up_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_STREQ("Japanese,English,Spanish", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("ja,en,es", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - - gtk_button_clicked(GTK_BUTTON(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_STREQ("English,Japanese,Spanish", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("en,ja,es", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); -} - -TEST_F(LanguagesPageGtkTest, AddAcceptLang) { - profile_->GetPrefs()->SetString(prefs::kAcceptLanguages, ""); - LanguagesPageGtk page(profile_.get()); - EXPECT_STREQ("", GetDisplayedLangs(page).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.add_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - - page.OnAddLanguage("en"); - EXPECT_STREQ("English", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("en", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.add_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - EXPECT_EQ(0, page.FirstSelectedRowNum()); - - page.OnAddLanguage("es"); - EXPECT_STREQ("English,Spanish", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("en,es", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.add_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - EXPECT_EQ(1, page.FirstSelectedRowNum()); - - // Duplicates should be ignored and selection should not be changed. - gtk_tree_selection_unselect_all(page.language_order_selection_); - page.OnAddLanguage("en"); - EXPECT_STREQ("English,Spanish", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("en,es", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(page.add_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_up_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.move_down_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(page.remove_button_)); - EXPECT_EQ(0, gtk_tree_selection_count_selected_rows( - page.language_order_selection_)); -} - -TEST_F(LanguagesPageGtkTest, EnableSpellChecking) { - profile_->GetPrefs()->SetBoolean(prefs::kEnableSpellCheck, false); - LanguagesPageGtk page(profile_.get()); - EXPECT_EQ(FALSE, gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(page.enable_spellchecking_checkbox_))); - - profile_->GetPrefs()->SetBoolean(prefs::kEnableSpellCheck, true); - EXPECT_EQ(TRUE, gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(page.enable_spellchecking_checkbox_))); - - gtk_button_clicked(GTK_BUTTON(page.enable_spellchecking_checkbox_)); - EXPECT_EQ(FALSE, gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(page.enable_spellchecking_checkbox_))); - EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); - - gtk_button_clicked(GTK_BUTTON(page.enable_spellchecking_checkbox_)); - EXPECT_EQ(TRUE, gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(page.enable_spellchecking_checkbox_))); - EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); -} - -// TODO(mattm): add EnableAutoSpellChecking test - -TEST_F(LanguagesPageGtkTest, DictionaryLanguage) { - profile_->GetPrefs()->SetString(prefs::kAcceptLanguages, "it"); - profile_->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "es"); - LanguagesPageGtk page(profile_.get()); - EXPECT_STREQ("Italian", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("it", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_STREQ("Spanish", GetDisplayedSpellCheckerLang(page).c_str()); - int spanish_index = gtk_combo_box_get_active( - GTK_COMBO_BOX(page.dictionary_language_combobox_)); - - profile_->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "fr"); - EXPECT_STREQ("Italian", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("it", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_STREQ("French", GetDisplayedSpellCheckerLang(page).c_str()); - int french_index = gtk_combo_box_get_active( - GTK_COMBO_BOX(page.dictionary_language_combobox_)); - - gtk_combo_box_set_active( - GTK_COMBO_BOX(page.dictionary_language_combobox_), spanish_index); - EXPECT_STREQ("Italian,Spanish", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("it,es", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_STREQ("Spanish", GetDisplayedSpellCheckerLang(page).c_str()); - - gtk_combo_box_set_active( - GTK_COMBO_BOX(page.dictionary_language_combobox_), french_index); - EXPECT_STREQ("Italian,French", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("it,fr", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_STREQ("French", GetDisplayedSpellCheckerLang(page).c_str()); - - gtk_combo_box_set_active( - GTK_COMBO_BOX(page.dictionary_language_combobox_), - page.dictionary_language_model_->GetIndexFromLocale("it")); - EXPECT_STREQ("Italian", GetDisplayedLangs(page).c_str()); - EXPECT_STREQ("it", - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages).c_str()); - EXPECT_STREQ("Italian", GetDisplayedSpellCheckerLang(page).c_str()); -} diff --git a/chrome/browser/ui/gtk/options/managed_prefs_banner_gtk.cc b/chrome/browser/ui/gtk/options/managed_prefs_banner_gtk.cc deleted file mode 100644 index 53d8a61..0000000 --- a/chrome/browser/ui/gtk/options/managed_prefs_banner_gtk.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/managed_prefs_banner_gtk.h" - -#include "chrome/browser/ui/gtk/gtk_theme_provider.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - -namespace { - -// Padding within the banner box. -const int kBannerPadding = 3; - -} - -ManagedPrefsBannerGtk::ManagedPrefsBannerGtk(PrefService* prefs, - OptionsPage page) - : policy::ManagedPrefsBannerBase(prefs, page), - banner_widget_(NULL) { - InitWidget(); - OnUpdateVisibility(); -} - -void ManagedPrefsBannerGtk::InitWidget() { - banner_widget_ = gtk_frame_new(NULL); - GtkWidget* contents = gtk_hbox_new(FALSE, kBannerPadding); - gtk_container_set_border_width(GTK_CONTAINER(contents), kBannerPadding); - gtk_container_add(GTK_CONTAINER(banner_widget_), contents); - GtkWidget* warning_image = - gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING, - GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_box_pack_start(GTK_BOX(contents), warning_image, FALSE, FALSE, 0); - std::string info_text(l10n_util::GetStringUTF8(IDS_OPTIONS_MANAGED_PREFS)); - GtkWidget* info_label = gtk_label_new(info_text.c_str()); - gtk_box_pack_start(GTK_BOX(contents), info_label, FALSE, FALSE, 0); - gtk_widget_show_all(banner_widget_); - gtk_widget_set_no_show_all(GTK_WIDGET(banner_widget_), TRUE); -} - -void ManagedPrefsBannerGtk::OnUpdateVisibility() { - DCHECK(banner_widget_); - if (DetermineVisibility()) - gtk_widget_show(banner_widget_); - else - gtk_widget_hide(banner_widget_); -} diff --git a/chrome/browser/ui/gtk/options/managed_prefs_banner_gtk.h b/chrome/browser/ui/gtk/options/managed_prefs_banner_gtk.h deleted file mode 100644 index 8a1ec85..0000000 --- a/chrome/browser/ui/gtk/options/managed_prefs_banner_gtk.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_MANAGED_PREFS_BANNER_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_MANAGED_PREFS_BANNER_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include "chrome/browser/policy/managed_prefs_banner_base.h" - -// Constructs and maintains a GTK widget displaying a warning banner. The banner -// is displayed on the preferences dialog whenever there are options that are -// not settable by the user due to policy. -class ManagedPrefsBannerGtk : public policy::ManagedPrefsBannerBase { - public: - ManagedPrefsBannerGtk(PrefService* prefs, OptionsPage page); - virtual ~ManagedPrefsBannerGtk() { } - - GtkWidget* banner_widget() { return banner_widget_; } - - protected: - // Update widget visibility. - virtual void OnUpdateVisibility(); - - private: - // Construct the widget. - void InitWidget(); - - GtkWidget* banner_widget_; - - DISALLOW_COPY_AND_ASSIGN(ManagedPrefsBannerGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_MANAGED_PREFS_BANNER_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/options_layout_gtk.cc b/chrome/browser/ui/gtk/options/options_layout_gtk.cc deleted file mode 100644 index 33dbc86..0000000 --- a/chrome/browser/ui/gtk/options/options_layout_gtk.cc +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/options_layout_gtk.h" - -#include "chrome/browser/ui/gtk/gtk_util.h" - -// If the height of screen is equal or shorter than this, we will use -// a more compact option layout. -const int kCompactScreenHeight = 600; - -// Default option layout builder follows GNOME HIG, which uses header and -// spacing to group options. -class DefaultOptionsLayoutBuilderGtk : public OptionsLayoutBuilderGtk { - public: - explicit DefaultOptionsLayoutBuilderGtk(); - - void AddOptionGroup(const std::string& title, GtkWidget* content, - bool expandable); - void AddWidget(GtkWidget* content, bool expandable); - private: - DISALLOW_COPY_AND_ASSIGN(DefaultOptionsLayoutBuilderGtk); -}; - -DefaultOptionsLayoutBuilderGtk::DefaultOptionsLayoutBuilderGtk() { - page_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing); - gtk_container_set_border_width(GTK_CONTAINER(page_), - gtk_util::kContentAreaBorder); -} - -void DefaultOptionsLayoutBuilderGtk::AddOptionGroup(const std::string& title, - GtkWidget* content, - bool expandable) { - GtkWidget* title_label = gtk_util::CreateBoldLabel(title); - - GtkWidget* group = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(group), title_label, FALSE, FALSE, 0); - gtk_container_add(GTK_CONTAINER(group), gtk_util::IndentWidget(content)); - - AddWidget(group, expandable); -} - -void DefaultOptionsLayoutBuilderGtk::AddWidget(GtkWidget* content, - bool expandable) { - gtk_box_pack_start(GTK_BOX(page_), content, expandable, expandable, 0); -} - -// Compact layout builder uses table to layout label and content horizontally. -class CompactOptionsLayoutBuilderGtk : public OptionsLayoutBuilderGtk { - public: - explicit CompactOptionsLayoutBuilderGtk(); - - void AddOptionGroup(const std::string& title, GtkWidget* content, - bool expandable); - void AddWidget(GtkWidget* content, bool expandable); - private: - GtkWidget *table_; - guint row_; - - DISALLOW_COPY_AND_ASSIGN(CompactOptionsLayoutBuilderGtk); -}; - -CompactOptionsLayoutBuilderGtk::CompactOptionsLayoutBuilderGtk() { - row_ = 0; - table_ = NULL; - - page_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing); - gtk_container_set_border_width(GTK_CONTAINER(page_), - gtk_util::kContentAreaBorder); -} - -void CompactOptionsLayoutBuilderGtk::AddOptionGroup(const std::string& title, - GtkWidget* content, - bool expandable) { - if (!table_) { - // Create a new table to contain option groups - table_ = gtk_table_new(0, 2, FALSE); - gtk_table_set_col_spacing(GTK_TABLE(table_), 0, gtk_util::kLabelSpacing); - gtk_table_set_row_spacings(GTK_TABLE(table_), - gtk_util::kContentAreaSpacing); - - gtk_container_set_border_width(GTK_CONTAINER(table_), - gtk_util::kContentAreaBorder); - gtk_box_pack_start(GTK_BOX(page_), table_, TRUE, TRUE, 0); - } - - GtkWidget* title_label = gtk_util::CreateBoldLabel(title); - - gtk_table_resize(GTK_TABLE(table_), row_ + 1, 2); - gtk_misc_set_alignment(GTK_MISC(title_label), 1, 0); - - gtk_table_attach(GTK_TABLE(table_), title_label, - 0, 1, row_, row_ + 1, - GTK_FILL, GTK_FILL, - 0, 0); - gtk_table_attach(GTK_TABLE(table_), content, - 1, 2, row_, row_ + 1, - expandable ? - GTK_FILL : GtkAttachOptions(GTK_FILL | GTK_EXPAND), - GTK_FILL, - 0, 0); - row_++; -} - -void CompactOptionsLayoutBuilderGtk::AddWidget(GtkWidget* content, - bool expandable) { - gtk_box_pack_start(GTK_BOX(page_), content, expandable, expandable, 0); - - // Let AddOptionGroup create a new table and append after this widget - table_ = NULL; -} - -OptionsLayoutBuilderGtk* OptionsLayoutBuilderGtk::Create() { - return new DefaultOptionsLayoutBuilderGtk(); -} - -OptionsLayoutBuilderGtk* -OptionsLayoutBuilderGtk::CreateOptionallyCompactLayout() { - gint screen_height = gdk_screen_get_height(gdk_screen_get_default()); - if (screen_height <= kCompactScreenHeight) - return new CompactOptionsLayoutBuilderGtk(); - else - return new DefaultOptionsLayoutBuilderGtk(); -} diff --git a/chrome/browser/ui/gtk/options/options_layout_gtk.h b/chrome/browser/ui/gtk/options/options_layout_gtk.h deleted file mode 100644 index 5add467..0000000 --- a/chrome/browser/ui/gtk/options/options_layout_gtk.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_OPTIONS_LAYOUT_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_OPTIONS_LAYOUT_GTK_H_ -#pragma once - -#include <gtk/gtk.h> -#include <string> - -#include "base/basictypes.h" - -class OptionsLayoutBuilderGtk { - public: - virtual ~OptionsLayoutBuilderGtk() {} - - GtkWidget* get_page_widget() { - return page_; - } - - // Adds an option group to the table. Handles layout and the placing of - // separators between groups. If expandable is true, the content widget will - // be allowed to expand and fill any extra space when the dialog is resized. - virtual void AddOptionGroup(const std::string& title, GtkWidget* content, - bool expandable) = 0; - - // Adds a widget without title or special layout. If expandable is true, the - // content widget will be allowed to expand and fill any extra space when the - // dialog is resized. - virtual void AddWidget(GtkWidget* content, bool expandable) = 0; - - // Creates a default option layout builder. The default layout builder - // follows the GNOME HIG. - static OptionsLayoutBuilderGtk* Create(); - - // Creates a compact option layout builder, if the screen is compact. - // Otherwise, creates a default one. - static OptionsLayoutBuilderGtk* CreateOptionallyCompactLayout(); - - protected: - // The parent widget - GtkWidget* page_; -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_OPTIONS_LAYOUT_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/options_window_gtk.cc b/chrome/browser/ui/gtk/options/options_window_gtk.cc deleted file mode 100644 index 63da3ab..0000000 --- a/chrome/browser/ui/gtk/options/options_window_gtk.cc +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <gtk/gtk.h> - -#include "base/message_loop.h" -#include "base/scoped_ptr.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/options/advanced_page_gtk.h" -#include "chrome/browser/ui/gtk/options/content_page_gtk.h" -#include "chrome/browser/ui/gtk/options/general_page_gtk.h" -#include "chrome/browser/ui/options/options_window.h" -#include "chrome/browser/ui/window_sizer.h" -#include "chrome/common/pref_names.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - -/////////////////////////////////////////////////////////////////////////////// -// OptionsWindowGtk -// -// The contents of the Options dialog window. - -class OptionsWindowGtk { - public: - explicit OptionsWindowGtk(Profile* profile); - ~OptionsWindowGtk(); - - // Shows the Tab corresponding to the specified OptionsPage. - void ShowOptionsPage(OptionsPage page, OptionsGroup highlight_group); - - private: - static void OnSwitchPage(GtkNotebook* notebook, GtkNotebookPage* page, - guint page_num, OptionsWindowGtk* window); - - static void OnWindowDestroy(GtkWidget* widget, OptionsWindowGtk* window); - - // The options dialog. - GtkWidget* dialog_; - - // The container of the option pages. - GtkWidget* notebook_; - - // The Profile associated with these options. - Profile* profile_; - - // The general page. - GeneralPageGtk general_page_; - - // The content page. - ContentPageGtk content_page_; - - // The advanced (user data) page. - AdvancedPageGtk advanced_page_; - - // The last page the user was on when they opened the Options window. - IntegerPrefMember last_selected_page_; - - DISALLOW_COPY_AND_ASSIGN(OptionsWindowGtk); -}; - -// The singleton options window object. -static OptionsWindowGtk* options_window = NULL; - -/////////////////////////////////////////////////////////////////////////////// -// OptionsWindowGtk, public: - -OptionsWindowGtk::OptionsWindowGtk(Profile* profile) - // Always show preferences for the original profile. Most state when off - // the record comes from the original profile, but we explicitly use - // the original profile to avoid potential problems. - : profile_(profile->GetOriginalProfile()), - general_page_(profile_), - content_page_(profile_), - advanced_page_(profile_) { - - // We don't need to observe changes in this value. - last_selected_page_.Init(prefs::kOptionsWindowLastTabIndex, - g_browser_process->local_state(), NULL); - - std::string dialog_name = - l10n_util::GetStringFUTF8( - IDS_PREFERENCES_DIALOG_TITLE, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); - dialog_ = gtk_dialog_new_with_buttons( - dialog_name.c_str(), - // Prefs window is shared between all browser windows. - NULL, - // Non-modal. - GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE, - NULL); - - gtk_window_set_default_size(GTK_WINDOW(dialog_), 500, -1); - // Allow browser windows to go in front of the options dialog in metacity. - gtk_window_set_type_hint(GTK_WINDOW(dialog_), GDK_WINDOW_TYPE_HINT_NORMAL); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), - gtk_util::kContentAreaSpacing); - - notebook_ = gtk_notebook_new(); - - gtk_notebook_append_page( - GTK_NOTEBOOK(notebook_), - general_page_.get_page_widget(), - gtk_label_new( - l10n_util::GetStringUTF8(IDS_OPTIONS_GENERAL_TAB_LABEL).c_str())); - - gtk_notebook_append_page( - GTK_NOTEBOOK(notebook_), - content_page_.get_page_widget(), - gtk_label_new( - l10n_util::GetStringUTF8(IDS_OPTIONS_CONTENT_TAB_LABEL).c_str())); - - gtk_notebook_append_page( - GTK_NOTEBOOK(notebook_), - advanced_page_.get_page_widget(), - gtk_label_new( - l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_TAB_LABEL).c_str())); - - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), notebook_); - - DCHECK_EQ( - gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook_)), OPTIONS_PAGE_COUNT); - - // Show the content so that we can compute full dialog size, both - // for centering and because we want to show the notebook before - // connecting switch-page signal, otherwise we'll immediately get a - // signal switching to page 0 and overwrite our last_selected_page_ - // value. - gtk_widget_show_all(gtk_bin_get_child(GTK_BIN(dialog_))); - - if (Browser* b = BrowserList::GetLastActive()) { - gtk_util::CenterOverWindow(GTK_WINDOW(dialog_), - b->window()->GetNativeHandle()); - } - - // Now that we're centered over the browser, we add our dialog to its own - // window group. We don't do anything with the response and we don't want the - // options window's modal dialogs to be associated with the main browser - // window because gtk grabs work on a per window group basis. - gtk_window_group_add_window(gtk_window_group_new(), GTK_WINDOW(dialog_)); - g_object_unref(gtk_window_get_group(GTK_WINDOW(dialog_))); - - g_signal_connect(notebook_, "switch-page", G_CALLBACK(OnSwitchPage), this); - - // We only have one button and don't do any special handling, so just hook it - // directly to gtk_widget_destroy. - g_signal_connect(dialog_, "response", G_CALLBACK(gtk_widget_destroy), NULL); - - g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroy), this); - - gtk_widget_show(dialog_); -} - -OptionsWindowGtk::~OptionsWindowGtk() { -} - -void OptionsWindowGtk::ShowOptionsPage(OptionsPage page, - OptionsGroup highlight_group) { - if (Browser* b = BrowserList::GetLastActive()) { - gtk_util::CenterOverWindow(GTK_WINDOW(dialog_), - b->window()->GetNativeHandle()); - } - - // Bring options window to front if it already existed and isn't already - // in front - gtk_window_present_with_time(GTK_WINDOW(dialog_), - gtk_get_current_event_time()); - - if (page == OPTIONS_PAGE_DEFAULT) { - // Remember the last visited page from local state. - page = static_cast<OptionsPage>(last_selected_page_.GetValue()); - if (page == OPTIONS_PAGE_DEFAULT) - page = OPTIONS_PAGE_GENERAL; - } - // If the page number is out of bounds, reset to the first tab. - if (page < 0 || page >= gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook_))) - page = OPTIONS_PAGE_GENERAL; - - gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook_), page); - - // TODO(mattm): set highlight_group -} - -/////////////////////////////////////////////////////////////////////////////// -// OptionsWindowGtk, private: - -// static -void OptionsWindowGtk::OnSwitchPage(GtkNotebook* notebook, - GtkNotebookPage* page, - guint page_num, - OptionsWindowGtk* window) { - int index = page_num; - DCHECK(index > OPTIONS_PAGE_DEFAULT && index < OPTIONS_PAGE_COUNT); - window->last_selected_page_.SetValue(index); -} - -// static -void OptionsWindowGtk::OnWindowDestroy(GtkWidget* widget, - OptionsWindowGtk* window) { - options_window = NULL; - MessageLoop::current()->DeleteSoon(FROM_HERE, window); -} - -/////////////////////////////////////////////////////////////////////////////// -// Factory/finder method: - -void ShowOptionsWindow(OptionsPage page, - OptionsGroup highlight_group, - Profile* profile) { - DCHECK(profile); - - // If there's already an existing options window, activate it and switch to - // the specified page. - if (!options_window) { - // Create the options window. - options_window = new OptionsWindowGtk(profile); - } - options_window->ShowOptionsPage(page, highlight_group); -} diff --git a/chrome/browser/ui/gtk/options/passwords_exceptions_page_gtk.cc b/chrome/browser/ui/gtk/options/passwords_exceptions_page_gtk.cc deleted file mode 100644 index 13d77f2..0000000 --- a/chrome/browser/ui/gtk/options/passwords_exceptions_page_gtk.cc +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/passwords_exceptions_page_gtk.h" - -#include <string> - -#include "base/stl_util-inl.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/gtk/gtk_tree.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "grit/app_resources.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "net/base/net_util.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/gtk_util.h" - -namespace { - -// Column ids for |exception_list_store_|. -enum { - COL_SITE, - COL_COUNT, -}; - -} // anonymous namespace - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsExceptionsPageGtk, public: - -PasswordsExceptionsPageGtk::PasswordsExceptionsPageGtk(Profile* profile) - : populater(this), profile_(profile) { - - remove_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_PASSWORDS_PAGE_VIEW_REMOVE_BUTTON).c_str()); - gtk_widget_set_sensitive(remove_button_, FALSE); - g_signal_connect(remove_button_, "clicked", - G_CALLBACK(OnRemoveButtonClickedThunk), this); - remove_all_button_ = gtk_button_new_with_label(l10n_util::GetStringUTF8( - IDS_PASSWORDS_PAGE_VIEW_REMOVE_ALL_BUTTON).c_str()); - gtk_widget_set_sensitive(remove_all_button_, FALSE); - g_signal_connect(remove_all_button_, "clicked", - G_CALLBACK(OnRemoveAllButtonClickedThunk), this); - - GtkWidget* buttons = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(buttons), remove_button_, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(buttons), remove_all_button_, FALSE, FALSE, 0); - - GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), - GTK_SHADOW_ETCHED_IN); - - // Sets exception_tree_ among other things. - InitExceptionTree(); - gtk_container_add(GTK_CONTAINER(scroll_window), exception_tree_); - - page_ = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); - gtk_container_set_border_width(GTK_CONTAINER(page_), - gtk_util::kContentAreaBorder); - gtk_box_pack_end(GTK_BOX(page_), buttons, FALSE, FALSE, 0); - gtk_box_pack_end(GTK_BOX(page_), scroll_window, TRUE, TRUE, 0); -} - -PasswordsExceptionsPageGtk::~PasswordsExceptionsPageGtk() { - STLDeleteElements(&exception_list_); -} - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsExceptionsPageGtk, private: - -void PasswordsExceptionsPageGtk::InitExceptionTree() { - exception_list_store_ = gtk_list_store_new(COL_COUNT, G_TYPE_STRING); - exception_list_sort_ = gtk_tree_model_sort_new_with_model( - GTK_TREE_MODEL(exception_list_store_)); - gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(exception_list_sort_), - COL_SITE, CompareSite, this, NULL); - exception_tree_ = gtk_tree_view_new_with_model(exception_list_sort_); - g_object_unref(exception_list_store_); - g_object_unref(exception_list_sort_); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(exception_tree_), TRUE); - - exception_selection_ = gtk_tree_view_get_selection( - GTK_TREE_VIEW(exception_tree_)); - gtk_tree_selection_set_mode(exception_selection_, - GTK_SELECTION_SINGLE); - g_signal_connect(exception_selection_, "changed", - G_CALLBACK(OnExceptionSelectionChangedThunk), this); - - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( - l10n_util::GetStringUTF8(IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN).c_str(), - gtk_cell_renderer_text_new(), - "text", COL_SITE, - NULL); - gtk_tree_view_column_set_sort_column_id(column, COL_SITE); - gtk_tree_view_append_column(GTK_TREE_VIEW(exception_tree_), column); - - populater.populate(); -} - -PasswordStore* PasswordsExceptionsPageGtk::GetPasswordStore() { - return profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); -} - -void PasswordsExceptionsPageGtk::SetExceptionList( - const std::vector<webkit_glue::PasswordForm*>& result) { - std::string languages = - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); - gtk_list_store_clear(exception_list_store_); - STLDeleteElements(&exception_list_); - exception_list_ = result; - for (size_t i = 0; i < result.size(); ++i) { - GtkTreeIter iter; - gtk_list_store_insert_with_values(exception_list_store_, &iter, (gint) i, - COL_SITE, - UTF16ToUTF8(net::FormatUrl(result[i]->origin, languages)).c_str(), -1); - } - gtk_widget_set_sensitive(remove_all_button_, !result.empty()); -} - -void PasswordsExceptionsPageGtk::OnRemoveButtonClicked(GtkWidget* widget) { - GtkTreeIter iter; - if (!gtk_tree_selection_get_selected(exception_selection_, - NULL, &iter)) { - NOTREACHED(); - return; - } - - GtkTreePath* path = gtk_tree_model_get_path( - GTK_TREE_MODEL(exception_list_sort_), &iter); - gint index = gtk_tree::GetTreeSortChildRowNumForPath( - exception_list_sort_, path); - gtk_tree_path_free(path); - - GtkTreeIter child_iter; - gtk_tree_model_sort_convert_iter_to_child_iter( - GTK_TREE_MODEL_SORT(exception_list_sort_), &child_iter, &iter); - - // Remove from GTK list, DB, and vector. - gtk_list_store_remove(exception_list_store_, &child_iter); - GetPasswordStore()->RemoveLogin(*exception_list_[index]); - delete exception_list_[index]; - exception_list_.erase(exception_list_.begin() + index); - - gtk_widget_set_sensitive(remove_all_button_, !exception_list_.empty()); -} - -void PasswordsExceptionsPageGtk::OnRemoveAllButtonClicked(GtkWidget* widget) { - // Remove from GTK list, DB, and vector. - PasswordStore* store = GetPasswordStore(); - gtk_list_store_clear(exception_list_store_); - for (size_t i = 0; i < exception_list_.size(); ++i) - store->RemoveLogin(*exception_list_[i]); - STLDeleteElements(&exception_list_); - gtk_widget_set_sensitive(remove_all_button_, FALSE); -} - -void PasswordsExceptionsPageGtk::OnExceptionSelectionChanged( - GtkTreeSelection* selection) { - GtkTreeIter iter; - if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) { - gtk_widget_set_sensitive(remove_button_, FALSE); - return; - } - gtk_widget_set_sensitive(remove_button_, TRUE); -} - -// static -gint PasswordsExceptionsPageGtk::CompareSite(GtkTreeModel* model, - GtkTreeIter* a, GtkTreeIter* b, - gpointer window) { - int row1 = gtk_tree::GetRowNumForIter(model, a); - int row2 = gtk_tree::GetRowNumForIter(model, b); - PasswordsExceptionsPageGtk* page = - reinterpret_cast<PasswordsExceptionsPageGtk*>(window); - return page->exception_list_[row1]->origin.spec().compare( - page->exception_list_[row2]->origin.spec()); -} - -void PasswordsExceptionsPageGtk::ExceptionListPopulater::populate() { - DCHECK(!pending_login_query_); - PasswordStore* store = page_->GetPasswordStore(); - if (store != NULL) - pending_login_query_ = store->GetBlacklistLogins(this); - else - LOG(ERROR) << "No password store! Cannot display exceptions."; -} - -void -PasswordsExceptionsPageGtk::ExceptionListPopulater::OnPasswordStoreRequestDone( - int handle, const std::vector<webkit_glue::PasswordForm*>& result) { - DCHECK_EQ(pending_login_query_, handle); - pending_login_query_ = 0; - page_->SetExceptionList(result); -} diff --git a/chrome/browser/ui/gtk/options/passwords_exceptions_page_gtk.h b/chrome/browser/ui/gtk/options/passwords_exceptions_page_gtk.h deleted file mode 100644 index 8c0f145..0000000 --- a/chrome/browser/ui/gtk/options/passwords_exceptions_page_gtk.h +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_PASSWORDS_EXCEPTIONS_PAGE_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_PASSWORDS_EXCEPTIONS_PAGE_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include <vector> - -#include "chrome/browser/password_manager/password_store.h" -#include "ui/base/gtk/gtk_signal.h" - -class Profile; - -// A page in the show saved passwords dialog that lists what sites we never -// show passwords for, with controls for the user to add/remove sites from that -// list. -class PasswordsExceptionsPageGtk { - public: - explicit PasswordsExceptionsPageGtk(Profile* profile); - virtual ~PasswordsExceptionsPageGtk(); - - GtkWidget* get_page_widget() const { return page_; } - - private: - // Initialize the exception tree widget, setting the member variables. - void InitExceptionTree(); - - // The password store associated with the currently active profile. - PasswordStore* GetPasswordStore(); - - // Sets the exception list contents to the given data. We take ownership of - // the PasswordForms in the vector. - void SetExceptionList(const std::vector<webkit_glue::PasswordForm*>& result); - - CHROMEGTK_CALLBACK_0(PasswordsExceptionsPageGtk, void, OnRemoveButtonClicked); - CHROMEGTK_CALLBACK_0(PasswordsExceptionsPageGtk, void, - OnRemoveAllButtonClicked); - - CHROMEG_CALLBACK_0(PasswordsExceptionsPageGtk, void, - OnExceptionSelectionChanged, GtkTreeSelection*); - - // Sorting function. - static gint CompareSite(GtkTreeModel* model, - GtkTreeIter* a, GtkTreeIter* b, - gpointer window); - - // A short class to mediate requests to the password store. - class ExceptionListPopulater : public PasswordStoreConsumer { - public: - explicit ExceptionListPopulater(PasswordsExceptionsPageGtk* page) - : page_(page), - pending_login_query_(0) { - } - - // Send a query to the password store to populate an - // PasswordsExceptionsPageGtk. - void populate(); - - // PasswordStoreConsumer implementation. - // Send the password store's reply back to the PasswordsExceptionsPageGtk. - virtual void OnPasswordStoreRequestDone( - int handle, const std::vector<webkit_glue::PasswordForm*>& result); - - private: - PasswordsExceptionsPageGtk* page_; - int pending_login_query_; - }; - - // Password store consumer for populating the exception list. - ExceptionListPopulater populater; - - // Widgets for the buttons. - GtkWidget* remove_button_; - GtkWidget* remove_all_button_; - - // Widgets for the exception table. - GtkWidget* exception_tree_; - GtkListStore* exception_list_store_; - GtkTreeModel* exception_list_sort_; - GtkTreeSelection* exception_selection_; - - // The parent GtkHBox widget. - GtkWidget* page_; - - Profile* profile_; - std::vector<webkit_glue::PasswordForm*> exception_list_; - - DISALLOW_COPY_AND_ASSIGN(PasswordsExceptionsPageGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_PASSWORDS_EXCEPTIONS_PAGE_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/passwords_exceptions_window_gtk.cc b/chrome/browser/ui/gtk/options/passwords_exceptions_window_gtk.cc deleted file mode 100644 index 290430d..0000000 --- a/chrome/browser/ui/gtk/options/passwords_exceptions_window_gtk.cc +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/passwords_exceptions_window_gtk.h" - -#include <gtk/gtk.h> - -#include <string> - -#include "base/message_loop.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/options/passwords_exceptions_page_gtk.h" -#include "chrome/browser/ui/gtk/options/passwords_page_gtk.h" -#include "chrome/browser/ui/options/options_window.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsExceptionsWindowGtk -// -// The contents of the Passwords and Exceptions dialog window. - -class PasswordsExceptionsWindowGtk { - public: - explicit PasswordsExceptionsWindowGtk(Profile* profile); - ~PasswordsExceptionsWindowGtk(); - - void Show(); - - private: - static void OnWindowDestroy(GtkWidget* widget, - PasswordsExceptionsWindowGtk* window); - - // The passwords and exceptions dialog. - GtkWidget *dialog_; - - // The container of the password and exception pages. - GtkWidget *notebook_; - - // The Profile associated with these passwords and exceptions. - Profile* profile_; - - // The passwords page. - PasswordsPageGtk passwords_page_; - - // The exceptions page. - PasswordsExceptionsPageGtk exceptions_page_; - - DISALLOW_COPY_AND_ASSIGN(PasswordsExceptionsWindowGtk); -}; - -// The singleton passwords and exceptions window object. -static PasswordsExceptionsWindowGtk* passwords_exceptions_window = NULL; - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsExceptionsWindowGtk, public: - -PasswordsExceptionsWindowGtk::PasswordsExceptionsWindowGtk(Profile* profile) - : profile_(profile), - passwords_page_(profile_), - exceptions_page_(profile_) { - std::string dialog_name = l10n_util::GetStringUTF8( - IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); - dialog_ = gtk_dialog_new_with_buttons( - dialog_name.c_str(), - // Passwords and exceptions window is shared between all browser windows. - NULL, - // Non-modal. - GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE, - NULL); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), - gtk_util::kContentAreaSpacing); - - notebook_ = gtk_notebook_new(); - - gtk_notebook_append_page( - GTK_NOTEBOOK(notebook_), - passwords_page_.get_page_widget(), - gtk_label_new(l10n_util::GetStringUTF8( - IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE).c_str())); - - gtk_notebook_append_page( - GTK_NOTEBOOK(notebook_), - exceptions_page_.get_page_widget(), - gtk_label_new(l10n_util::GetStringUTF8( - IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE).c_str())); - - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), notebook_); - - // We only have one button and don't do any special handling, so just hook it - // directly to gtk_widget_destroy. - g_signal_connect(dialog_, "response", G_CALLBACK(gtk_widget_destroy), NULL); - - g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroy), this); - - gtk_util::ShowDialogWithLocalizedSize(dialog_, - IDS_PASSWORDS_DIALOG_WIDTH_CHARS, - IDS_PASSWORDS_DIALOG_HEIGHT_LINES, - true); -} - -PasswordsExceptionsWindowGtk::~PasswordsExceptionsWindowGtk() { -} - -void PasswordsExceptionsWindowGtk::Show() { - // Bring options window to front if it already existed and isn't already - // in front - gtk_util::PresentWindow(dialog_, 0); -} - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsExceptionsWindowGtk, private: - -// static -void PasswordsExceptionsWindowGtk::OnWindowDestroy(GtkWidget* widget, - PasswordsExceptionsWindowGtk* window) { - passwords_exceptions_window = NULL; - MessageLoop::current()->DeleteSoon(FROM_HERE, window); -} - -/////////////////////////////////////////////////////////////////////////////// -// Factory/finder method: - -void ShowPasswordsExceptionsWindow(Profile* profile) { - DCHECK(profile); - // If there's already an existing passwords and exceptions window, use it. - if (!passwords_exceptions_window) { - passwords_exceptions_window = new PasswordsExceptionsWindowGtk(profile); - } - passwords_exceptions_window->Show(); -} diff --git a/chrome/browser/ui/gtk/options/passwords_exceptions_window_gtk.h b/chrome/browser/ui/gtk/options/passwords_exceptions_window_gtk.h deleted file mode 100644 index b6c5c6c..0000000 --- a/chrome/browser/ui/gtk/options/passwords_exceptions_window_gtk.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_PASSWORDS_EXCEPTIONS_WINDOW_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_PASSWORDS_EXCEPTIONS_WINDOW_GTK_H_ -#pragma once - -class Profile; - -void ShowPasswordsExceptionsWindow(Profile* profile); - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_PASSWORDS_EXCEPTIONS_WINDOW_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/passwords_page_gtk.cc b/chrome/browser/ui/gtk/options/passwords_page_gtk.cc deleted file mode 100644 index c8d7d7c..0000000 --- a/chrome/browser/ui/gtk/options/passwords_page_gtk.cc +++ /dev/null @@ -1,367 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/passwords_page_gtk.h" - -#include <string> - -#include "base/stl_util-inl.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/gtk/gtk_tree.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "content/common/notification_details.h" -#include "content/common/notification_type.h" -#include "grit/app_resources.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "net/base/net_util.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/gtk_util.h" - -namespace { - -// Initial width of the first column. -const int kSiteColumnInitialSize = 265; - -// Column ids for |password_list_store_|. -enum { - COL_SITE, - COL_USERNAME, - COL_COUNT, -}; - -} // anonymous namespace - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsPageGtk, public: - -PasswordsPageGtk::PasswordsPageGtk(Profile* profile) - : populater(this), password_showing_(false), profile_(profile) { - allow_show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords, - profile->GetPrefs(), - this); - - remove_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_PASSWORDS_PAGE_VIEW_REMOVE_BUTTON).c_str()); - gtk_widget_set_sensitive(remove_button_, FALSE); - g_signal_connect(remove_button_, "clicked", - G_CALLBACK(OnRemoveButtonClickedThunk), this); - remove_all_button_ = gtk_button_new_with_label(l10n_util::GetStringUTF8( - IDS_PASSWORDS_PAGE_VIEW_REMOVE_ALL_BUTTON).c_str()); - gtk_widget_set_sensitive(remove_all_button_, FALSE); - g_signal_connect(remove_all_button_, "clicked", - G_CALLBACK(OnRemoveAllButtonClickedThunk), this); - - // We start with the "hide password" text but change it in the realize event. - show_password_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON).c_str()); - gtk_widget_set_no_show_all(show_password_button_, true); - gtk_widget_set_sensitive(show_password_button_, FALSE); - g_signal_connect(show_password_button_, "clicked", - G_CALLBACK(OnShowPasswordButtonClickedThunk), this); - g_signal_connect(show_password_button_, "realize", - G_CALLBACK(OnShowPasswordButtonRealizedThunk), this); - - password_ = gtk_label_new(""); - gtk_label_set_selectable(GTK_LABEL(password_), TRUE); - gtk_widget_set_no_show_all(password_, true); - - GtkWidget* buttons = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(buttons), remove_button_, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(buttons), remove_all_button_, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(buttons), show_password_button_, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(buttons), password_, FALSE, FALSE, 0); - - GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), - GTK_SHADOW_ETCHED_IN); - - // Sets password_tree_ among other things. - InitPasswordTree(); - gtk_container_add(GTK_CONTAINER(scroll_window), password_tree_); - - page_ = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); - gtk_container_set_border_width(GTK_CONTAINER(page_), - gtk_util::kContentAreaBorder); - gtk_box_pack_end(GTK_BOX(page_), buttons, FALSE, FALSE, 0); - gtk_box_pack_end(GTK_BOX(page_), scroll_window, TRUE, TRUE, 0); - - // Initialize UI state based on current preference values. - OnPrefChanged(prefs::kPasswordManagerAllowShowPasswords); -} - -PasswordsPageGtk::~PasswordsPageGtk() { - STLDeleteElements(&password_list_); -} - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsPageGtk, private: - -void PasswordsPageGtk::InitPasswordTree() { - password_list_store_ = gtk_list_store_new(COL_COUNT, - G_TYPE_STRING, - G_TYPE_STRING); - password_list_sort_ = gtk_tree_model_sort_new_with_model( - GTK_TREE_MODEL(password_list_store_)); - gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(password_list_sort_), - COL_SITE, CompareSite, this, NULL); - gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(password_list_sort_), - COL_USERNAME, CompareUsername, this, NULL); - password_tree_ = gtk_tree_view_new_with_model(password_list_sort_); - g_object_unref(password_list_store_); - g_object_unref(password_list_sort_); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(password_tree_), TRUE); - - password_selection_ = gtk_tree_view_get_selection( - GTK_TREE_VIEW(password_tree_)); - gtk_tree_selection_set_mode(password_selection_, - GTK_SELECTION_SINGLE); - g_signal_connect(password_selection_, "changed", - G_CALLBACK(OnPasswordSelectionChangedThunk), this); - - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( - l10n_util::GetStringUTF8(IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN).c_str(), - gtk_cell_renderer_text_new(), - "text", COL_SITE, - NULL); - gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); - gtk_tree_view_column_set_resizable(column, TRUE); - gtk_tree_view_column_set_fixed_width(column, kSiteColumnInitialSize); - gtk_tree_view_column_set_sort_column_id(column, COL_SITE); - gtk_tree_view_append_column(GTK_TREE_VIEW(password_tree_), column); - - column = gtk_tree_view_column_new_with_attributes( - l10n_util::GetStringUTF8(IDS_PASSWORDS_PAGE_VIEW_USERNAME_COLUMN).c_str(), - gtk_cell_renderer_text_new(), - "text", COL_USERNAME, - NULL); - gtk_tree_view_column_set_sort_column_id(column, COL_USERNAME); - gtk_tree_view_append_column(GTK_TREE_VIEW(password_tree_), column); - populater.populate(); -} - -PasswordStore* PasswordsPageGtk::GetPasswordStore() { - return profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); -} - -void PasswordsPageGtk::SetPasswordList( - const std::vector<webkit_glue::PasswordForm*>& result) { - std::string languages = - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); - gtk_list_store_clear(password_list_store_); - STLDeleteElements(&password_list_); - password_list_ = result; - for (size_t i = 0; i < result.size(); ++i) { - GtkTreeIter iter; - gtk_list_store_insert_with_values(password_list_store_, &iter, (gint) i, - COL_SITE, - UTF16ToUTF8(net::FormatUrl(result[i]->origin, languages)).c_str(), - COL_USERNAME, UTF16ToUTF8(result[i]->username_value).c_str(), -1); - } - gtk_widget_set_sensitive(remove_all_button_, !result.empty()); -} - -void PasswordsPageGtk::HidePassword() { - password_showing_ = false; - gtk_label_set_text(GTK_LABEL(password_), ""); - gtk_button_set_label(GTK_BUTTON(show_password_button_), - l10n_util::GetStringUTF8(IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON).c_str()); -} - -void PasswordsPageGtk::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); - const std::string* pref_name = Details<std::string>(details).ptr(); - OnPrefChanged(*pref_name); -} - -void PasswordsPageGtk::OnPrefChanged(const std::string& pref_name) { - if (pref_name == prefs::kPasswordManagerAllowShowPasswords) { - if (allow_show_passwords_.GetValue()) { - gtk_widget_show(show_password_button_); - gtk_widget_show(password_); - } else { - HidePassword(); - gtk_widget_hide(show_password_button_); - gtk_widget_hide(password_); - } - } else { - NOTREACHED(); - } -} - -void PasswordsPageGtk::OnRemoveButtonClicked(GtkWidget* widget) { - GtkTreeIter iter; - if (!gtk_tree_selection_get_selected(password_selection_, - NULL, &iter)) { - NOTREACHED(); - return; - } - - GtkTreePath* path = gtk_tree_model_get_path( - GTK_TREE_MODEL(password_list_sort_), &iter); - gint index = gtk_tree::GetTreeSortChildRowNumForPath( - password_list_sort_, path); - gtk_tree_path_free(path); - - GtkTreeIter child_iter; - gtk_tree_model_sort_convert_iter_to_child_iter( - GTK_TREE_MODEL_SORT(password_list_sort_), &child_iter, &iter); - - // Remove from GTK list, DB, and vector. - gtk_list_store_remove(password_list_store_, &child_iter); - GetPasswordStore()->RemoveLogin(*password_list_[index]); - delete password_list_[index]; - password_list_.erase(password_list_.begin() + index); - - gtk_widget_set_sensitive(remove_all_button_, !password_list_.empty()); -} - -void PasswordsPageGtk::OnRemoveAllButtonClicked(GtkWidget* widget) { - GtkWindow* window = GTK_WINDOW(gtk_widget_get_toplevel(page_)); - GtkWidget* confirm = gtk_message_dialog_new( - window, - static_cast<GtkDialogFlags>( - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - "%s", - l10n_util::GetStringUTF8( - IDS_PASSWORDS_PAGE_VIEW_TEXT_DELETE_ALL_PASSWORDS).c_str()); - gtk_util::ApplyMessageDialogQuirks(confirm); - gtk_window_set_title(GTK_WINDOW(confirm), l10n_util::GetStringUTF8( - IDS_PASSWORDS_PAGE_VIEW_CAPTION_DELETE_ALL_PASSWORDS).c_str()); - g_signal_connect(confirm, "response", - G_CALLBACK(OnRemoveAllConfirmResponseThunk), this); - gtk_widget_show_all(confirm); -} - -void PasswordsPageGtk::OnRemoveAllConfirmResponse(GtkWidget* dialog, - int response_id) { - bool confirmed = false; - switch (response_id) { - case GTK_RESPONSE_YES: - confirmed = true; - break; - default: - break; - } - gtk_widget_destroy(dialog); - if (!confirmed) - return; - - // Remove from GTK list, DB, and vector. - PasswordStore* store = GetPasswordStore(); - gtk_list_store_clear(password_list_store_); - for (size_t i = 0; i < password_list_.size(); ++i) - store->RemoveLogin(*password_list_[i]); - STLDeleteElements(&password_list_); - gtk_widget_set_sensitive(remove_all_button_, FALSE); -} - -void PasswordsPageGtk::OnShowPasswordButtonClicked(GtkWidget* widget) { - if (password_showing_ || !allow_show_passwords_.GetValue()) { - // Hide the password. - HidePassword(); - return; - } - // Show the password. - password_showing_ = true; - GtkTreeIter iter; - if (!gtk_tree_selection_get_selected(password_selection_, - NULL, &iter)) { - NOTREACHED(); - return; - } - GtkTreePath* path = gtk_tree_model_get_path( - GTK_TREE_MODEL(password_list_sort_), &iter); - gint index = gtk_tree::GetTreeSortChildRowNumForPath( - password_list_sort_, path); - gtk_tree_path_free(path); - std::string pass = UTF16ToUTF8(password_list_[index]->password_value); - gtk_label_set_text(GTK_LABEL(password_), pass.c_str()); - gtk_button_set_label(GTK_BUTTON(show_password_button_), - l10n_util::GetStringUTF8(IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON).c_str()); -} - -void PasswordsPageGtk::OnShowPasswordButtonRealized(GtkWidget* widget) { - // We have just realized the "show password" button, so we can now accurately - // find out how big it needs to be in order to accomodate both the "show" and - // "hide" labels. (This requires font information to work correctly.) The - // button starts with the "hide" label so we only have to change it once. - GtkRequisition hide_size, show_size; - // Get the size request of the button with the "hide password" text. - gtk_widget_size_request(show_password_button_, &hide_size); - gtk_button_set_label(GTK_BUTTON(show_password_button_), - l10n_util::GetStringUTF8(IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON).c_str()); - // Get the size request of the button with the "show password" text. - gtk_widget_size_request(show_password_button_, &show_size); - // Determine the maximum width and height. - if (hide_size.width > show_size.width) - show_size.width = hide_size.width; - if (hide_size.height > show_size.height) - show_size.height = hide_size.height; - // Force the button to be large enough for both labels. - gtk_widget_set_size_request(show_password_button_, show_size.width, - show_size.height); -} - -void PasswordsPageGtk::OnPasswordSelectionChanged(GtkTreeSelection* selection) { - // No matter how the selection changed, we want to hide the old password. - HidePassword(); - - GtkTreeIter iter; - if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) { - gtk_widget_set_sensitive(show_password_button_, FALSE); - gtk_widget_set_sensitive(remove_button_, FALSE); - return; - } - gtk_widget_set_sensitive(show_password_button_, TRUE); - gtk_widget_set_sensitive(remove_button_, TRUE); -} - -// static -gint PasswordsPageGtk::CompareSite(GtkTreeModel* model, - GtkTreeIter* a, GtkTreeIter* b, - gpointer window) { - int row1 = gtk_tree::GetRowNumForIter(model, a); - int row2 = gtk_tree::GetRowNumForIter(model, b); - PasswordsPageGtk* page = reinterpret_cast<PasswordsPageGtk*>(window); - return page->password_list_[row1]->origin.spec().compare( - page->password_list_[row2]->origin.spec()); -} - -// static -gint PasswordsPageGtk::CompareUsername(GtkTreeModel* model, - GtkTreeIter* a, GtkTreeIter* b, - gpointer window) { - int row1 = gtk_tree::GetRowNumForIter(model, a); - int row2 = gtk_tree::GetRowNumForIter(model, b); - PasswordsPageGtk* page = reinterpret_cast<PasswordsPageGtk*>(window); - return page->password_list_[row1]->username_value.compare( - page->password_list_[row2]->username_value); -} - -void PasswordsPageGtk::PasswordListPopulater::populate() { - DCHECK(!pending_login_query_); - PasswordStore* store = page_->GetPasswordStore(); - if (store != NULL) - pending_login_query_ = store->GetAutofillableLogins(this); - else - LOG(ERROR) << "No password store! Cannot display passwords."; -} - -void PasswordsPageGtk::PasswordListPopulater::OnPasswordStoreRequestDone( - int handle, const std::vector<webkit_glue::PasswordForm*>& result) { - DCHECK_EQ(pending_login_query_, handle); - pending_login_query_ = 0; - page_->SetPasswordList(result); -} diff --git a/chrome/browser/ui/gtk/options/passwords_page_gtk.h b/chrome/browser/ui/gtk/options/passwords_page_gtk.h deleted file mode 100644 index 6d4c727..0000000 --- a/chrome/browser/ui/gtk/options/passwords_page_gtk.h +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_PASSWORDS_PAGE_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_PASSWORDS_PAGE_GTK_H_ -#pragma once - -#include <gtk/gtk.h> - -#include <string> -#include <vector> - -#include "chrome/browser/password_manager/password_store.h" -#include "chrome/browser/prefs/pref_member.h" -#include "content/common/notification_observer.h" -#include "ui/base/gtk/gtk_signal.h" - -class Profile; - -class PasswordsPageGtk : public NotificationObserver { - public: - explicit PasswordsPageGtk(Profile* profile); - virtual ~PasswordsPageGtk(); - - GtkWidget* get_page_widget() const { return page_; } - - private: - // Initialize the password tree widget, setting the member variables. - void InitPasswordTree(); - - // The password store associated with the currently active profile. - PasswordStore* GetPasswordStore(); - - // Sets the password list contents to the given data. We take ownership of - // the PasswordForms in the vector. - void SetPasswordList(const std::vector<webkit_glue::PasswordForm*>& result); - - // Helper that hides the password. - void HidePassword(); - - // NotificationObserver implementation. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - // Handles changes to the observed preferences and updates the UI. - void OnPrefChanged(const std::string& pref_name); - - CHROMEGTK_CALLBACK_0(PasswordsPageGtk, void, OnRemoveButtonClicked); - CHROMEGTK_CALLBACK_0(PasswordsPageGtk, void, OnRemoveAllButtonClicked); - CHROMEGTK_CALLBACK_1(PasswordsPageGtk, void, OnRemoveAllConfirmResponse, int); - CHROMEGTK_CALLBACK_0(PasswordsPageGtk, void, OnShowPasswordButtonClicked); - CHROMEGTK_CALLBACK_0(PasswordsPageGtk, void, OnShowPasswordButtonRealized); - - CHROMEG_CALLBACK_0(PasswordsPageGtk, void, OnPasswordSelectionChanged, - GtkTreeSelection*); - - // Sorting functions. - static gint CompareSite(GtkTreeModel* model, - GtkTreeIter* a, GtkTreeIter* b, - gpointer window); - static gint CompareUsername(GtkTreeModel* model, - GtkTreeIter* a, GtkTreeIter* b, - gpointer window); - - // A short class to mediate requests to the password store. - class PasswordListPopulater : public PasswordStoreConsumer { - public: - explicit PasswordListPopulater(PasswordsPageGtk* page) - : page_(page), - pending_login_query_(0) { - } - - // Send a query to the password store to populate a PasswordsPageGtk. - void populate(); - - // Send the password store's reply back to the PasswordsPageGtk. - virtual void OnPasswordStoreRequestDone( - int handle, const std::vector<webkit_glue::PasswordForm*>& result); - - private: - PasswordsPageGtk* page_; - int pending_login_query_; - }; - - // Password store consumer for populating the password list. - PasswordListPopulater populater; - - // Widgets for the buttons. - GtkWidget* remove_button_; - GtkWidget* remove_all_button_; - GtkWidget* show_password_button_; - - // Widget for the shown password - GtkWidget* password_; - bool password_showing_; - - // Widgets for the password table. - GtkWidget* password_tree_; - GtkListStore* password_list_store_; - GtkTreeModel* password_list_sort_; - GtkTreeSelection* password_selection_; - - // The parent GtkHBox widget and GtkWindow window. - GtkWidget* page_; - - Profile* profile_; - BooleanPrefMember allow_show_passwords_; - std::vector<webkit_glue::PasswordForm*> password_list_; - - DISALLOW_COPY_AND_ASSIGN(PasswordsPageGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_PASSWORDS_PAGE_GTK_H_ diff --git a/chrome/browser/ui/gtk/options/simple_content_exceptions_window.cc b/chrome/browser/ui/gtk/options/simple_content_exceptions_window.cc deleted file mode 100644 index a8d9396..0000000 --- a/chrome/browser/ui/gtk/options/simple_content_exceptions_window.cc +++ /dev/null @@ -1,212 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/gtk/options/simple_content_exceptions_window.h" - -#include "base/message_loop.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/gtk_util.h" - -namespace { - -// Singleton for exception window. -SimpleContentExceptionsWindow* instance = NULL; - -enum { - COL_ACTION = gtk_tree::TableAdapter::COL_LAST_ID, - COL_COUNT -}; - -} // namespace - -// static -void SimpleContentExceptionsWindow::ShowExceptionsWindow( - GtkWindow* parent, RemoveRowsTableModel* model, int title_message_id) { - DCHECK(model); - scoped_ptr<RemoveRowsTableModel> owned_model(model); - - if (!instance) { - instance = new SimpleContentExceptionsWindow( - parent, owned_model.release(), title_message_id); - } else { - gtk_util::PresentWindow(instance->dialog_, 0); - } -} - -SimpleContentExceptionsWindow::SimpleContentExceptionsWindow( - GtkWindow* parent, - RemoveRowsTableModel* model, - int title_message_id) - : ignore_selection_changes_(false) { - // Build the model adapters that translate views and TableModels into - // something GTK can use. - list_store_ = gtk_list_store_new(COL_COUNT, - G_TYPE_STRING, - G_TYPE_BOOLEAN, - G_TYPE_BOOLEAN, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_BOOLEAN, - G_TYPE_STRING); - treeview_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store_)); - g_object_unref(list_store_); - - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview_), TRUE); - gtk_tree_view_set_row_separator_func( - GTK_TREE_VIEW(treeview_), - gtk_tree::TableAdapter::OnCheckRowIsSeparator, - NULL, - NULL); - - // Set up the properties of the treeview - GtkTreeViewColumn* hostname_column = gtk_tree_view_column_new_with_attributes( - l10n_util::GetStringUTF8(IDS_EXCEPTIONS_HOSTNAME_HEADER).c_str(), - gtk_cell_renderer_text_new(), - "text", gtk_tree::TableAdapter::COL_TITLE, - "weight", gtk_tree::TableAdapter::COL_WEIGHT, - "weight-set", gtk_tree::TableAdapter::COL_WEIGHT_SET, - NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_), hostname_column); - - GtkTreeViewColumn* action_column = gtk_tree_view_column_new_with_attributes( - l10n_util::GetStringUTF8(IDS_EXCEPTIONS_ACTION_HEADER).c_str(), - gtk_cell_renderer_text_new(), - "text", COL_ACTION, - NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_), action_column); - - treeview_selection_ = gtk_tree_view_get_selection( - GTK_TREE_VIEW(treeview_)); - gtk_tree_selection_set_mode(treeview_selection_, GTK_SELECTION_MULTIPLE); - gtk_tree_selection_set_select_function( - treeview_selection_, - gtk_tree::TableAdapter::OnSelectionFilter, - NULL, - NULL); - g_signal_connect(treeview_selection_, "changed", - G_CALLBACK(OnTreeSelectionChangedThunk), this); - - // Bind |list_store_| to our C++ model. - model_.reset(model); - model_adapter_.reset(new gtk_tree::TableAdapter(this, list_store_, - model_.get())); - // Force a reload of everything to copy data into |list_store_|. - model_adapter_->OnModelChanged(); - - dialog_ = gtk_dialog_new_with_buttons( - l10n_util::GetStringUTF8(title_message_id).c_str(), - parent, - static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE, - NULL); - gtk_window_set_default_size(GTK_WINDOW(dialog_), 500, 400); - // Allow browser windows to go in front of the options dialog in metacity. - gtk_window_set_type_hint(GTK_WINDOW(dialog_), GDK_WINDOW_TYPE_HINT_NORMAL); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), - gtk_util::kContentAreaSpacing); - - GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), hbox); - - // Create a scrolled window to wrap the treeview widget. - GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), - GTK_SHADOW_ETCHED_IN); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_container_add(GTK_CONTAINER(scrolled), treeview_); - gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); - - GtkWidget* button_box = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - remove_button_ = gtk_util::BuildDialogButton(dialog_, - IDS_EXCEPTIONS_REMOVE_BUTTON, - GTK_STOCK_REMOVE); - - g_signal_connect(remove_button_, "clicked", G_CALLBACK(RemoveThunk), this); - gtk_box_pack_start(GTK_BOX(button_box), remove_button_, FALSE, FALSE, 0); - - remove_all_button_ = gtk_util::BuildDialogButton( - dialog_, - IDS_EXCEPTIONS_REMOVEALL_BUTTON, - GTK_STOCK_CLEAR); - g_signal_connect(remove_all_button_, "clicked", G_CALLBACK(RemoveAllThunk), - this); - gtk_box_pack_start(GTK_BOX(button_box), remove_all_button_, FALSE, FALSE, 0); - - gtk_box_pack_start(GTK_BOX(hbox), button_box, FALSE, FALSE, 0); - - UpdateButtonState(); - - gtk_util::ShowDialogWithLocalizedSize(dialog_, - IDS_SIMPLE_CONTENT_EXCEPTION_DIALOG_WIDTH_CHARS, - IDS_SIMPLE_CONTENT_EXCEPTION_DIALOG_HEIGHT_LINES, - true); - - g_signal_connect(dialog_, "response", G_CALLBACK(gtk_widget_destroy), NULL); - g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); -} - -SimpleContentExceptionsWindow::~SimpleContentExceptionsWindow() {} - -void SimpleContentExceptionsWindow::SetColumnValues(int row, - GtkTreeIter* iter) { - string16 hostname = model_->GetText(row, IDS_EXCEPTIONS_HOSTNAME_HEADER); - gtk_list_store_set(list_store_, iter, gtk_tree::TableAdapter::COL_TITLE, - UTF16ToUTF8(hostname).c_str(), -1); - - string16 action = model_->GetText(row, IDS_EXCEPTIONS_ACTION_HEADER); - gtk_list_store_set(list_store_, iter, COL_ACTION, - UTF16ToUTF8(action).c_str(), -1); -} - -void SimpleContentExceptionsWindow::OnAnyModelUpdateStart() { - ignore_selection_changes_ = true; -} - -void SimpleContentExceptionsWindow::OnAnyModelUpdate() { - ignore_selection_changes_ = false; -} - -void SimpleContentExceptionsWindow::UpdateButtonState() { - int row_count = gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(list_store_), NULL); - - RemoveRowsTableModel::Rows rows; - std::set<int> indices; - gtk_tree::GetSelectedIndices(treeview_selection_, &indices); - model_adapter_->MapListStoreIndicesToModelRows(indices, &rows); - gtk_widget_set_sensitive(remove_button_, model_->CanRemoveRows(rows)); - gtk_widget_set_sensitive(remove_all_button_, row_count > 0); -} - -void SimpleContentExceptionsWindow::Remove(GtkWidget* widget) { - RemoveRowsTableModel::Rows rows; - std::set<int> indices; - gtk_tree::GetSelectedIndices(treeview_selection_, &indices); - model_adapter_->MapListStoreIndicesToModelRows(indices, &rows); - model_->RemoveRows(rows); - UpdateButtonState(); -} - -void SimpleContentExceptionsWindow::RemoveAll(GtkWidget* widget) { - model_->RemoveAll(); - UpdateButtonState(); -} - -void SimpleContentExceptionsWindow::OnWindowDestroy(GtkWidget* widget) { - instance = NULL; - MessageLoop::current()->DeleteSoon(FROM_HERE, this); -} - -void SimpleContentExceptionsWindow::OnTreeSelectionChanged( - GtkWidget* selection) { - if (!ignore_selection_changes_) - UpdateButtonState(); -} diff --git a/chrome/browser/ui/gtk/options/simple_content_exceptions_window.h b/chrome/browser/ui/gtk/options/simple_content_exceptions_window.h deleted file mode 100644 index c817c01..0000000 --- a/chrome/browser/ui/gtk/options/simple_content_exceptions_window.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_SIMPLE_CONTENT_EXCEPTIONS_WINDOW_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_SIMPLE_CONTENT_EXCEPTIONS_WINDOW_H_ -#pragma once - -#include <gtk/gtk.h> - -#include "base/scoped_ptr.h" -#include "chrome/browser/remove_rows_table_model.h" -#include "chrome/browser/ui/gtk/gtk_tree.h" -#include "chrome/common/content_settings.h" -#include "chrome/common/content_settings_types.h" -#include "ui/base/gtk/gtk_signal.h" - -class SimpleContentExceptionsWindow - : public gtk_tree::TableAdapter::Delegate { - public: - // Takes ownership of |model|. - static void ShowExceptionsWindow(GtkWindow* parent, - RemoveRowsTableModel* model, - int tile_message_id); - - virtual ~SimpleContentExceptionsWindow(); - - // gtk_tree::TableAdapter::Delegate implementation: - virtual void SetColumnValues(int row, GtkTreeIter* iter); - virtual void OnAnyModelUpdateStart(); - virtual void OnAnyModelUpdate(); - - private: - // Takes ownership of |model|. - SimpleContentExceptionsWindow(GtkWindow* parent, - RemoveRowsTableModel* model, - int title_message_id); - - // Updates which buttons are enabled. - void UpdateButtonState(); - - // Callbacks for the buttons. - CHROMEGTK_CALLBACK_0(SimpleContentExceptionsWindow, void, Remove); - CHROMEGTK_CALLBACK_0(SimpleContentExceptionsWindow, void, RemoveAll); - - CHROMEGTK_CALLBACK_0(SimpleContentExceptionsWindow, void, - OnWindowDestroy); - CHROMEGTK_CALLBACK_0(SimpleContentExceptionsWindow, void, - OnTreeSelectionChanged); - - // The list presented in |treeview_|; a gobject instead of a C++ object. - GtkListStore* list_store_; - - // The C++, views-ish, cross-platform model class that actually contains the - // gold standard data. - scoped_ptr<RemoveRowsTableModel> model_; - - // The adapter that ferries data back and forth between |model_| and - // |list_store_| whenever either of them change. - scoped_ptr<gtk_tree::TableAdapter> model_adapter_; - - // The exception window. - GtkWidget* dialog_; - - // The treeview that presents the site/action pairs. - GtkWidget* treeview_; - - // The current user selection from |treeview_|. - GtkTreeSelection* treeview_selection_; - - // Whether to ignore selection changes. This is set during model updates, - // when the list store may be inconsistent with the table model. - bool ignore_selection_changes_; - - // Buttons. - GtkWidget* remove_button_; - GtkWidget* remove_all_button_; -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_SIMPLE_CONTENT_EXCEPTIONS_WINDOW_H_ diff --git a/chrome/browser/ui/gtk/options/url_picker_dialog_gtk.cc b/chrome/browser/ui/gtk/options/url_picker_dialog_gtk.cc deleted file mode 100644 index e360553..0000000 --- a/chrome/browser/ui/gtk/options/url_picker_dialog_gtk.cc +++ /dev/null @@ -1,268 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <gtk/gtk.h> - -#include "base/message_loop.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/net/url_fixer_upper.h" -#include "chrome/browser/possible_url_model.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/gtk/gtk_tree.h" -#include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/gtk/options/url_picker_dialog_gtk.h" -#include "chrome/common/pref_names.h" -#include "googleurl/src/gurl.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "net/base/net_util.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/gtk_util.h" - -namespace { - -// Column ids for |history_list_store_|. -enum { - COL_FAVICON, - COL_TITLE, - COL_DISPLAY_URL, - COL_COUNT, -}; - -} // anonymous namespace - -UrlPickerDialogGtk::UrlPickerDialogGtk(UrlPickerCallback* callback, - Profile* profile, - GtkWindow* parent) - : profile_(profile), - callback_(callback) { - std::string dialog_name = l10n_util::GetStringUTF8(IDS_ASI_ADD_TITLE); - dialog_ = gtk_dialog_new_with_buttons( - dialog_name.c_str(), - parent, - static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - NULL); - add_button_ = gtk_dialog_add_button(GTK_DIALOG(dialog_), - GTK_STOCK_ADD, GTK_RESPONSE_OK); - gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_OK); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), - gtk_util::kContentAreaSpacing); - - // URL entry. - GtkWidget* url_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); - GtkWidget* url_label = gtk_label_new( - l10n_util::GetStringUTF8(IDS_ASI_URL).c_str()); - gtk_box_pack_start(GTK_BOX(url_hbox), url_label, - FALSE, FALSE, 0); - url_entry_ = gtk_entry_new(); - gtk_entry_set_activates_default(GTK_ENTRY(url_entry_), TRUE); - g_signal_connect(url_entry_, "changed", - G_CALLBACK(OnUrlEntryChangedThunk), this); - gtk_box_pack_start(GTK_BOX(url_hbox), url_entry_, - TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), url_hbox, - FALSE, FALSE, 0); - - // Recent history description label. - GtkWidget* history_vbox = gtk_vbox_new(FALSE, gtk_util::kLabelSpacing); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), history_vbox); - GtkWidget* history_label = gtk_util::CreateBoldLabel( - l10n_util::GetStringUTF8(IDS_ASI_DESCRIPTION)); - gtk_box_pack_start(GTK_BOX(history_vbox), history_label, FALSE, FALSE, 0); - - // Recent history list. - GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), - GTK_SHADOW_ETCHED_IN); - gtk_container_add(GTK_CONTAINER(history_vbox), scroll_window); - - history_list_store_ = gtk_list_store_new(COL_COUNT, - GDK_TYPE_PIXBUF, - G_TYPE_STRING, - G_TYPE_STRING); - history_list_sort_ = gtk_tree_model_sort_new_with_model( - GTK_TREE_MODEL(history_list_store_)); - gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(history_list_sort_), - COL_TITLE, CompareTitle, this, NULL); - gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(history_list_sort_), - COL_DISPLAY_URL, CompareURL, this, NULL); - history_tree_ = gtk_tree_view_new_with_model(history_list_sort_); - g_object_unref(history_list_store_); - g_object_unref(history_list_sort_); - gtk_container_add(GTK_CONTAINER(scroll_window), history_tree_); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(history_tree_), - TRUE); - g_signal_connect(history_tree_, "row-activated", - G_CALLBACK(OnHistoryRowActivatedThunk), this); - - history_selection_ = gtk_tree_view_get_selection( - GTK_TREE_VIEW(history_tree_)); - gtk_tree_selection_set_mode(history_selection_, - GTK_SELECTION_SINGLE); - g_signal_connect(history_selection_, "changed", - G_CALLBACK(OnHistorySelectionChangedThunk), this); - - // History list columns. - GtkTreeViewColumn* column = gtk_tree_view_column_new(); - GtkCellRenderer* renderer = gtk_cell_renderer_pixbuf_new(); - gtk_tree_view_column_pack_start(column, renderer, FALSE); - gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", COL_FAVICON); - renderer = gtk_cell_renderer_text_new(); - gtk_tree_view_column_pack_start(column, renderer, TRUE); - gtk_tree_view_column_add_attribute(column, renderer, "text", COL_TITLE); - gtk_tree_view_append_column(GTK_TREE_VIEW(history_tree_), - column); - gtk_tree_view_column_set_title( - column, l10n_util::GetStringUTF8(IDS_ASI_PAGE_COLUMN).c_str()); - gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); - gtk_tree_view_column_set_resizable(column, TRUE); - gtk_tree_view_column_set_sort_column_id(column, COL_TITLE); - - GtkTreeViewColumn* url_column = gtk_tree_view_column_new_with_attributes( - l10n_util::GetStringUTF8(IDS_ASI_URL_COLUMN).c_str(), - gtk_cell_renderer_text_new(), - "text", COL_DISPLAY_URL, - NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(history_tree_), url_column); - gtk_tree_view_column_set_sort_column_id(url_column, COL_DISPLAY_URL); - - // Loading data, showing dialog. - url_table_model_.reset(new PossibleURLModel()); - url_table_adapter_.reset(new gtk_tree::TableAdapter(this, history_list_store_, - url_table_model_.get())); - url_table_model_->Reload(profile_); - - EnableControls(); - - // Set the size of the dialog. - gtk_widget_realize(dialog_); - gtk_util::SetWindowSizeFromResources(GTK_WINDOW(dialog_), - IDS_URLPICKER_DIALOG_WIDTH_CHARS, - IDS_URLPICKER_DIALOG_HEIGHT_LINES, - true); - - // Set the width of the first column as well. - int width; - gtk_util::GetWidgetSizeFromResources( - dialog_, - IDS_URLPICKER_DIALOG_LEFT_COLUMN_WIDTH_CHARS, 0, - &width, NULL); - gtk_tree_view_column_set_fixed_width(column, width); - - gtk_util::ShowDialogWithLocalizedSize(dialog_, - IDS_URLPICKER_DIALOG_WIDTH_CHARS, - IDS_URLPICKER_DIALOG_HEIGHT_LINES, - false); - - g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); - g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); -} - -UrlPickerDialogGtk::~UrlPickerDialogGtk() { - delete callback_; -} - -void UrlPickerDialogGtk::AddURL() { - callback_->Run(URLFixerUpper::FixupURL( - gtk_entry_get_text(GTK_ENTRY(url_entry_)), std::string())); -} - -void UrlPickerDialogGtk::EnableControls() { - const gchar* text = gtk_entry_get_text(GTK_ENTRY(url_entry_)); - gtk_widget_set_sensitive(add_button_, text && *text); -} - -std::string UrlPickerDialogGtk::GetURLForPath(GtkTreePath* path) const { - gint row = gtk_tree::GetTreeSortChildRowNumForPath(history_list_sort_, path); - if (row < 0) { - NOTREACHED(); - return std::string(); - } - std::string languages = - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); - // Because this gets parsed by FixupURL(), it's safe to omit the scheme or - // trailing slash, and unescape most characters, but we need to not drop any - // username/password, or unescape anything that changes the meaning. - return UTF16ToUTF8(net::FormatUrl(url_table_model_->GetURL(row), - languages, net::kFormatUrlOmitAll & ~net::kFormatUrlOmitUsernamePassword, - UnescapeRule::SPACES, NULL, NULL, NULL)); -} - -void UrlPickerDialogGtk::SetColumnValues(int row, GtkTreeIter* iter) { - SkBitmap bitmap = url_table_model_->GetIcon(row); - GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); - string16 title = url_table_model_->GetText(row, IDS_ASI_PAGE_COLUMN); - string16 url = url_table_model_->GetText(row, IDS_ASI_URL_COLUMN); - gtk_list_store_set(history_list_store_, iter, - COL_FAVICON, pixbuf, - COL_TITLE, UTF16ToUTF8(title).c_str(), - COL_DISPLAY_URL, UTF16ToUTF8(url).c_str(), - -1); - g_object_unref(pixbuf); -} - -// static -gint UrlPickerDialogGtk::CompareTitle(GtkTreeModel* model, - GtkTreeIter* a, - GtkTreeIter* b, - gpointer window) { - int row1 = gtk_tree::GetRowNumForIter(model, a); - int row2 = gtk_tree::GetRowNumForIter(model, b); - return reinterpret_cast<UrlPickerDialogGtk*>(window)->url_table_model_-> - CompareValues(row1, row2, IDS_ASI_PAGE_COLUMN); -} - -// static -gint UrlPickerDialogGtk::CompareURL(GtkTreeModel* model, - GtkTreeIter* a, - GtkTreeIter* b, - gpointer window) { - int row1 = gtk_tree::GetRowNumForIter(model, a); - int row2 = gtk_tree::GetRowNumForIter(model, b); - return reinterpret_cast<UrlPickerDialogGtk*>(window)->url_table_model_-> - CompareValues(row1, row2, IDS_ASI_URL_COLUMN); -} - -void UrlPickerDialogGtk::OnUrlEntryChanged(GtkWidget* editable) { - EnableControls(); -} - -void UrlPickerDialogGtk::OnHistorySelectionChanged( - GtkTreeSelection* selection) { - GtkTreeIter iter; - if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) { - // The user has unselected the history element, nothing to do. - return; - } - GtkTreePath* path = gtk_tree_model_get_path( - GTK_TREE_MODEL(history_list_sort_), &iter); - gtk_entry_set_text(GTK_ENTRY(url_entry_), - GetURLForPath(path).c_str()); - gtk_tree_path_free(path); -} - -void UrlPickerDialogGtk::OnHistoryRowActivated(GtkWidget* tree_view, - GtkTreePath* path, - GtkTreeViewColumn* column) { - callback_->Run(URLFixerUpper::FixupURL(GetURLForPath(path), std::string())); - gtk_widget_destroy(dialog_); -} - -void UrlPickerDialogGtk::OnResponse(GtkWidget* dialog, int response_id) { - if (response_id == GTK_RESPONSE_OK) - AddURL(); - gtk_widget_destroy(dialog_); -} - -void UrlPickerDialogGtk::OnWindowDestroy(GtkWidget* widget) { - MessageLoop::current()->DeleteSoon(FROM_HERE, this); -} diff --git a/chrome/browser/ui/gtk/options/url_picker_dialog_gtk.h b/chrome/browser/ui/gtk/options/url_picker_dialog_gtk.h deleted file mode 100644 index f1b5640..0000000 --- a/chrome/browser/ui/gtk/options/url_picker_dialog_gtk.h +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_GTK_OPTIONS_URL_PICKER_DIALOG_GTK_H_ -#define CHROME_BROWSER_UI_GTK_OPTIONS_URL_PICKER_DIALOG_GTK_H_ -#pragma once - -#include <string> - -#include "base/basictypes.h" -#include "base/callback.h" -#include "chrome/browser/history/history.h" -#include "chrome/browser/ui/gtk/gtk_tree.h" -#include "ui/base/gtk/gtk_signal.h" - -class GURL; -class Profile; -class PossibleURLModel; - -class UrlPickerDialogGtk : public gtk_tree::TableAdapter::Delegate { - public: - typedef Callback1<const GURL&>::Type UrlPickerCallback; - - UrlPickerDialogGtk(UrlPickerCallback* callback, - Profile* profile, - GtkWindow* parent); - - ~UrlPickerDialogGtk(); - - // gtk_tree::TableAdapter::Delegate implementation. - virtual void SetColumnValues(int row, GtkTreeIter* iter); - - private: - // Call the callback based on url entry. - void AddURL(); - - // Set sensitivity of buttons based on url entry state. - void EnableControls(); - - // Return the entry-formatted url for path in the sorted model. - std::string GetURLForPath(GtkTreePath* path) const; - - // GTK sorting callbacks. - static gint CompareTitle(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, - gpointer window); - static gint CompareURL(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, - gpointer window); - - CHROMEGTK_CALLBACK_0(UrlPickerDialogGtk, void, OnUrlEntryChanged); - CHROMEGTK_CALLBACK_2(UrlPickerDialogGtk, void, OnHistoryRowActivated, - GtkTreePath*, GtkTreeViewColumn*); - CHROMEGTK_CALLBACK_1(UrlPickerDialogGtk, void, OnResponse, int); - CHROMEGTK_CALLBACK_0(UrlPickerDialogGtk, void, OnWindowDestroy); - - // Callback for user selecting rows in recent history list. - CHROMEG_CALLBACK_0(UrlPickerDialogGtk, void, OnHistorySelectionChanged, - GtkTreeSelection*) - - // The dialog window. - GtkWidget* dialog_; - - // The text entry for manually adding an URL. - GtkWidget* url_entry_; - - // The add button (we need a reference to it so we can de-activate it when the - // |url_entry_| is empty.) - GtkWidget* add_button_; - - // The recent history list. - GtkWidget* history_tree_; - GtkListStore* history_list_store_; - GtkTreeModel* history_list_sort_; - GtkTreeSelection* history_selection_; - - // Profile. - Profile* profile_; - - // The table model. - scoped_ptr<PossibleURLModel> url_table_model_; - scoped_ptr<gtk_tree::TableAdapter> url_table_adapter_; - - // Called if the user selects an url. - UrlPickerCallback* callback_; - - DISALLOW_COPY_AND_ASSIGN(UrlPickerDialogGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_OPTIONS_URL_PICKER_DIALOG_GTK_H_ diff --git a/chrome/browser/ui/views/browser_dialogs.h b/chrome/browser/ui/views/browser_dialogs.h index 7d28c73..d5be7e9 100644 --- a/chrome/browser/ui/views/browser_dialogs.h +++ b/chrome/browser/ui/views/browser_dialogs.h @@ -71,10 +71,6 @@ views::Window* ShowAboutChromeView(gfx::NativeWindow parent, // Creates and returns a find bar for the given browser window. See FindBarWin. FindBar* CreateFindBar(BrowserView* browser_view); -// Shows the "Save passwords and exceptions" dialog. -// See PasswordsExceptionsWindowView. -void ShowPasswordsExceptionsWindowView(Profile* profile); - // Shows the keyword editor. See KeywordEditorView. void ShowKeywordEditorView(Profile* profile); @@ -103,11 +99,6 @@ void EditSearchEngine(gfx::NativeWindow parent, void ShowRepostFormWarningDialog(gfx::NativeWindow parent_window, TabContents* tab_contents); -// Shows the content settings dialog box. -void ShowContentSettingsWindow(gfx::NativeWindow parent_window, - ContentSettingsType content_type, - Profile* profile); - // Shows the collected cookies dialog box. void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window, TabContents* tab_contents); diff --git a/chrome/browser/ui/views/dialog_stubs_gtk.cc b/chrome/browser/ui/views/dialog_stubs_gtk.cc index b5214ee..00cd889 100644 --- a/chrome/browser/ui/views/dialog_stubs_gtk.cc +++ b/chrome/browser/ui/views/dialog_stubs_gtk.cc @@ -14,8 +14,6 @@ #include "chrome/browser/ui/gtk/collected_cookies_gtk.h" #include "chrome/browser/ui/gtk/edit_search_engine_dialog.h" #include "chrome/browser/ui/gtk/keyword_editor_view.h" -#include "chrome/browser/ui/gtk/options/content_settings_window_gtk.h" -#include "chrome/browser/ui/gtk/options/passwords_exceptions_window_gtk.h" #include "chrome/browser/ui/gtk/repost_form_warning_gtk.h" #include "chrome/browser/ui/gtk/task_manager_gtk.h" #include "chrome/browser/ui/options/options_window.h" @@ -32,10 +30,6 @@ void ShowClearBrowsingDataView(views::Widget* parent, profile); } -void ShowPasswordsExceptionsWindowView(Profile* profile) { - ShowPasswordsExceptionsWindow(profile); -} - void ShowKeywordEditorView(Profile* profile) { KeywordEditorView::Show(profile); } @@ -60,12 +54,6 @@ void ShowRepostFormWarningDialog(gfx::NativeWindow parent_window, new RepostFormWarningGtk(GTK_WINDOW(parent_window), tab_contents); } -void ShowContentSettingsWindow(gfx::NativeWindow parent_window, - ContentSettingsType content_type, - Profile* profile) { - ContentSettingsWindowGtk::Show(parent_window, content_type, profile); -} - void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window, TabContents* tab_contents) { #if defined(OS_CHROMEOS) diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index ce088e1..63b2389 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -1102,11 +1102,6 @@ void BrowserView::ShowRepostFormWarningDialog(TabContents* tab_contents) { browser::ShowRepostFormWarningDialog(GetNativeHandle(), tab_contents); } -void BrowserView::ShowContentSettingsWindow(ContentSettingsType content_type, - Profile* profile) { - browser::ShowContentSettingsWindow(GetNativeHandle(), content_type, profile); -} - void BrowserView::ShowCollectedCookiesDialog(TabContents* tab_contents) { browser::ShowCollectedCookiesDialog(GetNativeHandle(), tab_contents); } diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index 602159c..aeda6b4 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -284,8 +284,6 @@ class BrowserView : public BrowserBubbleHost, virtual bool IsDownloadShelfVisible() const OVERRIDE; virtual DownloadShelf* GetDownloadShelf() OVERRIDE; virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) OVERRIDE; - virtual void ShowContentSettingsWindow(ContentSettingsType content_type, - Profile* profile) OVERRIDE; virtual void ShowCollectedCookiesDialog(TabContents* tab_contents) OVERRIDE; virtual void ShowProfileErrorDialog(int message_id) OVERRIDE; virtual void ShowThemeInstallBubble() OVERRIDE; diff --git a/chrome/browser/ui/views/options/advanced_contents_view.cc b/chrome/browser/ui/views/options/advanced_contents_view.cc deleted file mode 100644 index 96ced98..0000000 --- a/chrome/browser/ui/views/options/advanced_contents_view.cc +++ /dev/null @@ -1,1651 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/advanced_contents_view.h" - -#include <windows.h> - -#include <cryptuiapi.h> -#pragma comment(lib, "cryptui.lib") -#include <shellapi.h> -#include <vsstyle.h> -#include <vssym32.h> - -#include <string> - -#include "base/command_line.h" -#include "base/file_util.h" -#include "base/i18n/rtl.h" -#include "base/message_loop.h" -#include "base/path_service.h" -#include "base/scoped_callback_factory.h" -#include "base/threading/thread.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/browser_list.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/download/download_manager.h" -#include "chrome/browser/download/download_prefs.h" -#include "chrome/browser/google/google_util.h" -#include "chrome/browser/gears_integration.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/prefs/pref_set_observer.h" -#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" -#include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" -#include "chrome/browser/printing/cloud_print/cloud_print_url.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/safe_browsing/safe_browsing_service.h" -#include "chrome/browser/ui/options/options_util.h" -#include "chrome/browser/ui/options/show_options_url.h" -#include "chrome/browser/ui/shell_dialogs.h" -#include "chrome/browser/ui/views/browser_dialogs.h" -#include "chrome/browser/ui/views/clear_browsing_data_view.h" -#include "chrome/browser/ui/views/list_background.h" -#include "chrome/browser/ui/views/options/content_settings_window_view.h" -#include "chrome/browser/ui/views/options/fonts_languages_window_view.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "content/browser/renderer_host/resource_dispatcher_host.h" -#include "grit/app_resources.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "net/base/ssl_config_service_win.h" -#include "skia/ext/skia_utils_win.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas_skia.h" -#include "ui/gfx/native_theme_win.h" -#include "views/background.h" -#include "views/controls/button/checkbox.h" -#include "views/controls/combobox/combobox.h" -#include "views/controls/scroll_view.h" -#include "views/controls/textfield/textfield.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" -#include "views/widget/widget.h" -#include "views/window/window.h" - -using views::GridLayout; -using views::ColumnSet; - -namespace { - -const int kFileIconSize = 16; -const int kFileIconVerticalSpacing = 3; -const int kFileIconHorizontalSpacing = 3; -const int kFileIconTextFieldSpacing = 3; - -//////////////////////////////////////////////////////////////////////////////// -// FileDisplayArea - -class FileDisplayArea : public views::View { - public: - FileDisplayArea(); - virtual ~FileDisplayArea(); - - void SetFile(const FilePath& file_path); - - // views::View overrides: - virtual void OnPaint(gfx::Canvas* canvas); - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - protected: - // views::View overrides: - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - private: - void Init(); - - views::Textfield* text_field_; - SkColor text_field_background_color_; - - gfx::Rect icon_bounds_; - - bool initialized_; - - static void InitClass(); - static SkBitmap default_folder_icon_; - - DISALLOW_COPY_AND_ASSIGN(FileDisplayArea); -}; - -// static -SkBitmap FileDisplayArea::default_folder_icon_; - -FileDisplayArea::FileDisplayArea() - : text_field_(new views::Textfield), - text_field_background_color_(0), - initialized_(false) { - InitClass(); -} - -FileDisplayArea::~FileDisplayArea() { -} - -void FileDisplayArea::SetFile(const FilePath& file_path) { - // Force file path to have LTR directionality. - if (base::i18n::IsRTL()) { - string16 localized_file_path; - base::i18n::WrapPathWithLTRFormatting(file_path, &localized_file_path); - text_field_->SetText(UTF16ToWide(localized_file_path)); - } else { - text_field_->SetText(file_path.LossyDisplayName()); - } -} - -void FileDisplayArea::OnPaint(gfx::Canvas* canvas) { - HDC dc = canvas->BeginPlatformPaint(); - RECT rect = { 0, 0, width(), height() }; - gfx::NativeTheme::instance()->PaintTextField( - dc, EP_EDITTEXT, ETS_READONLY, 0, &rect, - skia::SkColorToCOLORREF(text_field_background_color_), true, true); - canvas->EndPlatformPaint(); - // Mirror left point for icon_bounds_ to draw icon in RTL locales correctly. - canvas->DrawBitmapInt(default_folder_icon_, GetMirroredXForRect(icon_bounds_), - icon_bounds_.y()); -} - -void FileDisplayArea::Layout() { - icon_bounds_.SetRect(kFileIconHorizontalSpacing, kFileIconVerticalSpacing, - kFileIconSize, kFileIconSize); - gfx::Size ps = text_field_->GetPreferredSize(); - text_field_->SetBounds(icon_bounds_.right() + kFileIconTextFieldSpacing, - (height() - ps.height()) / 2, - width() - icon_bounds_.right() - - kFileIconHorizontalSpacing - - kFileIconTextFieldSpacing, ps.height()); -} - -gfx::Size FileDisplayArea::GetPreferredSize() { - return gfx::Size(kFileIconSize + 2 * kFileIconVerticalSpacing, - kFileIconSize + 2 * kFileIconHorizontalSpacing); -} - -void FileDisplayArea::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (!initialized_ && is_add && GetWidget()) - Init(); -} - -void FileDisplayArea::Init() { - initialized_ = true; - AddChildView(text_field_); - text_field_background_color_ = - gfx::NativeTheme::instance()->GetThemeColorWithDefault( - gfx::NativeTheme::TEXTFIELD, EP_EDITTEXT, ETS_READONLY, - TMT_FILLCOLOR, COLOR_3DFACE); - text_field_->SetReadOnly(true); - text_field_->RemoveBorder(); - text_field_->SetBackgroundColor(text_field_background_color_); -} - -// static -void FileDisplayArea::InitClass() { - static bool initialized = false; - if (!initialized) { - // We'd prefer to use base::i18n::IsRTL() to perform the RTL - // environment check, but it's nonstatic, so, instead, we check whether the - // locale is RTL. - bool ui_is_rtl = base::i18n::IsRTL(); - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - default_folder_icon_ = *rb.GetBitmapNamed(ui_is_rtl ? - IDR_FOLDER_CLOSED_RTL : - IDR_FOLDER_CLOSED); - initialized = true; - } -} - -//////////////////////////////////////////////////////////////////////////////// -// AdvancedSection -// A convenience view for grouping advanced options together into related -// sections. -// -class AdvancedSection : public OptionsPageView { - public: - AdvancedSection(Profile* profile, const std::wstring& title); - virtual ~AdvancedSection() {} - - protected: - // Convenience helpers to add different kinds of ColumnSets for specific - // types of layout. - void AddWrappingColumnSet(views::GridLayout* layout, int id); - void AddDependentTwoColumnSet(views::GridLayout* layout, int id); - void AddTwoColumnSet(views::GridLayout* layout, int id); - void AddIndentedColumnSet(views::GridLayout* layout, int id); - - // Convenience helpers for adding controls to specific layouts in an - // aesthetically pleasing way. - void AddWrappingCheckboxRow(views::GridLayout* layout, - views::Checkbox* checkbox, - int id, - bool related_follows); - void AddWrappingLabelRow(views::GridLayout* layout, - views::Label* label, - int id, - bool related_follows); - void AddLabeledTwoColumnRow(views::GridLayout* layout, - views::Label* label, - views::View* control, - bool control_stretches, - int id, - bool related_follows); - void AddTwoColumnRow(views::GridLayout* layout, - views::View* first, - views::View* second, - bool control_stretches, // Whether or not the control - // expands to fill the width. - int id, - int trailing_space); - void AddLeadingControl(views::GridLayout* layout, - views::View* control, - int id, - bool related_follows); - void AddIndentedControl(views::GridLayout* layout, - views::View* control, - int id, - bool related_follows); - void AddSpacing(views::GridLayout* layout, bool related_follows); - - // OptionsPageView overrides: - virtual void InitControlLayout(); - - // The View that contains the contents of the section. - views::View* contents_; - - private: - // The section title. - views::Label* title_label_; - - DISALLOW_COPY_AND_ASSIGN(AdvancedSection); -}; - -//////////////////////////////////////////////////////////////////////////////// -// AdvancedSection, public: - -AdvancedSection::AdvancedSection(Profile* profile, - const std::wstring& title) - : contents_(NULL), - title_label_(new views::Label(title)), - OptionsPageView(profile) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - gfx::Font title_font = - rb.GetFont(ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD); - title_label_->SetFont(title_font); - - SkColor title_color = gfx::NativeTheme::instance()->GetThemeColorWithDefault( - gfx::NativeTheme::BUTTON, BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, - COLOR_WINDOWTEXT); - title_label_->SetColor(title_color); -} - -//////////////////////////////////////////////////////////////////////////////// -// AdvancedSection, protected: - -void AdvancedSection::AddWrappingColumnSet(views::GridLayout* layout, int id) { - ColumnSet* column_set = layout->AddColumnSet(id); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); -} - -void AdvancedSection::AddDependentTwoColumnSet(views::GridLayout* layout, - int id) { - ColumnSet* column_set = layout->AddColumnSet(id); - column_set->AddPaddingColumn(0, views::Checkbox::GetTextIndent()); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); -} - -void AdvancedSection::AddTwoColumnSet(views::GridLayout* layout, int id) { - ColumnSet* column_set = layout->AddColumnSet(id); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); -} - -void AdvancedSection::AddIndentedColumnSet(views::GridLayout* layout, int id) { - ColumnSet* column_set = layout->AddColumnSet(id); - column_set->AddPaddingColumn(0, views::Checkbox::GetTextIndent()); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); -} - -void AdvancedSection::AddWrappingCheckboxRow(views::GridLayout* layout, - views::Checkbox* checkbox, - int id, - bool related_follows) { - checkbox->SetMultiLine(true); - layout->StartRow(0, id); - layout->AddView(checkbox); - AddSpacing(layout, related_follows); -} - -void AdvancedSection::AddWrappingLabelRow(views::GridLayout* layout, - views::Label* label, - int id, - bool related_follows) { - label->SetMultiLine(true); - label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - layout->StartRow(0, id); - layout->AddView(label); - AddSpacing(layout, related_follows); -} - -void AdvancedSection::AddLabeledTwoColumnRow(views::GridLayout* layout, - views::Label* label, - views::View* control, - bool control_stretches, - int id, - bool related_follows) { - label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - AddTwoColumnRow(layout, label, control, control_stretches, id, - related_follows ? views::kRelatedControlVerticalSpacing - : views::kUnrelatedControlVerticalSpacing); -} - -void AdvancedSection::AddTwoColumnRow(views::GridLayout* layout, - views::View* first, - views::View* second, - bool control_stretches, - int id, - int trailing_space) { - layout->StartRow(0, id); - layout->AddView(first); - if (control_stretches) { - layout->AddView(second); - } else { - layout->AddView(second, 1, 1, views::GridLayout::LEADING, - views::GridLayout::CENTER); - } - layout->AddPaddingRow(0, trailing_space); -} - -void AdvancedSection::AddLeadingControl(views::GridLayout* layout, - views::View* control, - int id, - bool related_follows) { - layout->StartRow(0, id); - layout->AddView(control, 1, 1, GridLayout::LEADING, GridLayout::CENTER); - AddSpacing(layout, related_follows); -} - -void AdvancedSection::AddSpacing(views::GridLayout* layout, - bool related_follows) { - layout->AddPaddingRow( - 0, related_follows ? views::kRelatedControlVerticalSpacing - : views::kUnrelatedControlVerticalSpacing); -} - -//////////////////////////////////////////////////////////////////////////////// -// AdvancedSection, OptionsPageView overrides: - -void AdvancedSection::InitControlLayout() { - contents_ = new views::View; - - GridLayout* layout = new GridLayout(this); - SetLayoutManager(layout); - - const int single_column_layout_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, - GridLayout::USE_PREF, 0, 0); - const int inset_column_layout_id = 1; - column_set = layout->AddColumnSet(inset_column_layout_id); - column_set->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_layout_id); - layout->AddView(title_label_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, inset_column_layout_id); - layout->AddView(contents_); -} - -//////////////////////////////////////////////////////////////////////////////// -// PrivacySection - -class PrivacySection : public AdvancedSection, - public views::ButtonListener, - public views::LinkController { - public: - explicit PrivacySection(Profile* profile); - virtual ~PrivacySection() {} - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // Overridden from views::LinkController: - virtual void LinkActivated(views::Link* source, int event_flags); - - protected: - // OptionsPageView overrides: - virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::string* pref_name); - - private: - // Controls for this section: - views::NativeButton* content_settings_button_; - views::NativeButton* clear_data_button_; - views::Label* section_description_label_; - views::Checkbox* enable_link_doctor_checkbox_; - views::Checkbox* enable_suggest_checkbox_; - views::Checkbox* enable_dns_prefetching_checkbox_; - views::Checkbox* enable_safe_browsing_checkbox_; - views::Checkbox* reporting_enabled_checkbox_; - views::Link* learn_more_link_; - - // Preferences for this section: - BooleanPrefMember alternate_error_pages_; - BooleanPrefMember use_suggest_; - BooleanPrefMember dns_prefetch_enabled_; - BooleanPrefMember safe_browsing_; - BooleanPrefMember enable_metrics_recording_; - - void ResolveMetricsReportingEnabled(); - - DISALLOW_COPY_AND_ASSIGN(PrivacySection); -}; - -PrivacySection::PrivacySection(Profile* profile) - : content_settings_button_(NULL), - clear_data_button_(NULL), - section_description_label_(NULL), - enable_link_doctor_checkbox_(NULL), - enable_suggest_checkbox_(NULL), - enable_dns_prefetching_checkbox_(NULL), - enable_safe_browsing_checkbox_(NULL), - reporting_enabled_checkbox_(NULL), - learn_more_link_(NULL), - AdvancedSection(profile, UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY))) { -} - -void PrivacySection::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender == enable_link_doctor_checkbox_) { - bool enabled = enable_link_doctor_checkbox_->checked(); - UserMetricsRecordAction(UserMetricsAction(enabled ? - "Options_LinkDoctorCheckbox_Enable" : - "Options_LinkDoctorCheckbox_Disable"), - profile()->GetPrefs()); - alternate_error_pages_.SetValue(enabled); - } else if (sender == enable_suggest_checkbox_) { - bool enabled = enable_suggest_checkbox_->checked(); - UserMetricsRecordAction(UserMetricsAction(enabled ? - "Options_UseSuggestCheckbox_Enable" : - "Options_UseSuggestCheckbox_Disable"), - profile()->GetPrefs()); - use_suggest_.SetValue(enabled); - } else if (sender == enable_dns_prefetching_checkbox_) { - bool enabled = enable_dns_prefetching_checkbox_->checked(); - UserMetricsRecordAction(UserMetricsAction(enabled ? - "Options_DnsPrefetchCheckbox_Enable" : - "Options_DnsPrefetchCheckbox_Disable"), - profile()->GetPrefs()); - dns_prefetch_enabled_.SetValue(enabled); - } else if (sender == enable_safe_browsing_checkbox_) { - bool enabled = enable_safe_browsing_checkbox_->checked(); - UserMetricsRecordAction(UserMetricsAction(enabled ? - "Options_SafeBrowsingCheckbox_Enable" : - "Options_SafeBrowsingCheckbox_Disable"), - profile()->GetPrefs()); - safe_browsing_.SetValue(enabled); - SafeBrowsingService* safe_browsing_service = - g_browser_process->resource_dispatcher_host()->safe_browsing_service(); - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( - safe_browsing_service, &SafeBrowsingService::OnEnable, enabled)); - } else if (reporting_enabled_checkbox_ && - (sender == reporting_enabled_checkbox_)) { - bool enabled = reporting_enabled_checkbox_->checked(); - UserMetricsRecordAction(UserMetricsAction(enabled ? - "Options_MetricsReportingCheckbox_Enable" : - "Options_MetricsReportingCheckbox_Disable"), - profile()->GetPrefs()); - ResolveMetricsReportingEnabled(); - enable_metrics_recording_.SetValue(enabled); - } else if (sender == content_settings_button_) { - UserMetricsRecordAction(UserMetricsAction("Options_ContentSettings"), NULL); - browser::ShowContentSettingsWindow(GetWindow()->GetNativeWindow(), - CONTENT_SETTINGS_TYPE_DEFAULT, profile()); - } else if (sender == clear_data_button_) { - UserMetricsRecordAction(UserMetricsAction("Options_ClearData"), NULL); - views::Window::CreateChromeWindow( - GetWindow()->GetNativeWindow(), - gfx::Rect(), - new ClearBrowsingDataView(profile()))->Show(); - } -} - -void PrivacySection::LinkActivated(views::Link* source, int event_flags) { - DCHECK(source == learn_more_link_); - GURL url = google_util::AppendGoogleLocaleParam( - GURL(chrome::kPrivacyLearnMoreURL)); - browser::ShowOptionsURL(profile(), url); -} - -void PrivacySection::InitControlLayout() { - AdvancedSection::InitControlLayout(); - - content_settings_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON))); - clear_data_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON))); - section_description_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_DISABLE_SERVICES))); - enable_link_doctor_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_LINKDOCTOR_PREF))); - enable_link_doctor_checkbox_->set_listener(this); - enable_suggest_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_SUGGEST_PREF))); - enable_suggest_checkbox_->set_listener(this); - enable_dns_prefetching_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_NETWORK_DNS_PREFETCH_ENABLED_DESCRIPTION))); - enable_dns_prefetching_checkbox_->set_listener(this); - enable_safe_browsing_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION))); - enable_safe_browsing_checkbox_->set_listener(this); -#if defined(GOOGLE_CHROME_BUILD) - reporting_enabled_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_ENABLE_LOGGING))); - reporting_enabled_checkbox_->SetMultiLine(true); - reporting_enabled_checkbox_->set_listener(this); - reporting_enabled_checkbox_->SetVisible(true); -#endif - learn_more_link_ = new views::Link( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_LEARN_MORE))); - learn_more_link_->SetController(this); - - GridLayout* layout = new GridLayout(contents_); - contents_->SetLayoutManager(layout); - - const int leading_column_set_id = 0; - AddTwoColumnSet(layout, leading_column_set_id); - const int single_column_view_set_id = 1; - AddWrappingColumnSet(layout, single_column_view_set_id); - const int dependent_labeled_field_set_id = 2; - AddDependentTwoColumnSet(layout, dependent_labeled_field_set_id); - const int indented_view_set_id = 3; - AddIndentedColumnSet(layout, indented_view_set_id); - const int indented_column_set_id = 4; - AddIndentedColumnSet(layout, indented_column_set_id); - - AddTwoColumnRow(layout, content_settings_button_, clear_data_button_, false, - leading_column_set_id, - views::kUnrelatedControlLargeVerticalSpacing); - - // The description label at the top and label. - section_description_label_->SetMultiLine(true); - AddWrappingLabelRow(layout, section_description_label_, - single_column_view_set_id, true); - // Learn more link. - AddLeadingControl(layout, learn_more_link_, - single_column_view_set_id, true); - - // Link doctor. - AddWrappingCheckboxRow(layout, enable_link_doctor_checkbox_, - indented_view_set_id, true); - // Use Suggest service. - AddWrappingCheckboxRow(layout, enable_suggest_checkbox_, - indented_view_set_id, true); - // DNS pre-fetching. - AddWrappingCheckboxRow(layout, enable_dns_prefetching_checkbox_, - indented_view_set_id, true); - // Safe browsing controls. - AddWrappingCheckboxRow(layout, enable_safe_browsing_checkbox_, - indented_view_set_id, - reporting_enabled_checkbox_ != NULL); - // The "Help make Google Chrome better" checkbox. - if (reporting_enabled_checkbox_) { - AddWrappingCheckboxRow(layout, reporting_enabled_checkbox_, - indented_view_set_id, false); - } - - // Init member prefs so we can update the controls if prefs change. - alternate_error_pages_.Init(prefs::kAlternateErrorPagesEnabled, - profile()->GetPrefs(), this); - use_suggest_.Init(prefs::kSearchSuggestEnabled, - profile()->GetPrefs(), this); - dns_prefetch_enabled_.Init(prefs::kDnsPrefetchingEnabled, - profile()->GetPrefs(), this); - safe_browsing_.Init(prefs::kSafeBrowsingEnabled, profile()->GetPrefs(), this); - enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, - g_browser_process->local_state(), this); -} - -void PrivacySection::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || *pref_name == prefs::kAlternateErrorPagesEnabled) { - enable_link_doctor_checkbox_->SetEnabled( - !alternate_error_pages_.IsManaged()); - enable_link_doctor_checkbox_->SetChecked( - alternate_error_pages_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kSearchSuggestEnabled) { - enable_suggest_checkbox_->SetEnabled(!use_suggest_.IsManaged()); - enable_suggest_checkbox_->SetChecked(use_suggest_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kDnsPrefetchingEnabled) { - enable_dns_prefetching_checkbox_->SetEnabled( - !dns_prefetch_enabled_.IsManaged()); - bool enabled = dns_prefetch_enabled_.GetValue(); - enable_dns_prefetching_checkbox_->SetChecked(enabled); - } - if (!pref_name || *pref_name == prefs::kSafeBrowsingEnabled) { - enable_safe_browsing_checkbox_->SetEnabled(!safe_browsing_.IsManaged()); - enable_safe_browsing_checkbox_->SetChecked(safe_browsing_.GetValue()); - } - if (reporting_enabled_checkbox_ && - (!pref_name || *pref_name == prefs::kMetricsReportingEnabled)) { - reporting_enabled_checkbox_->SetEnabled( - !enable_metrics_recording_.IsManaged()); - reporting_enabled_checkbox_->SetChecked( - enable_metrics_recording_.GetValue()); - ResolveMetricsReportingEnabled(); - } -} - -void PrivacySection::ResolveMetricsReportingEnabled() { - DCHECK(reporting_enabled_checkbox_); - bool enabled = reporting_enabled_checkbox_->checked(); - - enabled = OptionsUtil::ResolveMetricsReportingEnabled(enabled); - - reporting_enabled_checkbox_->SetChecked(enabled); -} - -//////////////////////////////////////////////////////////////////////////////// -// WebContentSection - -class WebContentSection : public AdvancedSection, - public views::ButtonListener { - public: - explicit WebContentSection(Profile* profile); - virtual ~WebContentSection() {} - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - protected: - // OptionsPageView overrides: - virtual void InitControlLayout(); - - private: - // Controls for this section: - views::Label* fonts_and_languages_label_; - views::NativeButton* change_content_fonts_button_; - views::Label* gears_label_; - views::NativeButton* gears_settings_button_; - - DISALLOW_COPY_AND_ASSIGN(WebContentSection); -}; - -WebContentSection::WebContentSection(Profile* profile) - : fonts_and_languages_label_(NULL), - change_content_fonts_button_(NULL), - gears_label_(NULL), - gears_settings_button_(NULL), - AdvancedSection(profile, UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT))) { -} - -void WebContentSection::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender == gears_settings_button_) { - UserMetricsRecordAction(UserMetricsAction("Options_GearsSettings"), NULL); - GearsSettingsPressed(GetAncestor(GetWidget()->GetNativeView(), GA_ROOT)); - } else if (sender == change_content_fonts_button_) { - views::Window::CreateChromeWindow( - GetWindow()->GetNativeWindow(), - gfx::Rect(), - new FontsLanguagesWindowView(profile()))->Show(); - } -} - -void WebContentSection::InitControlLayout() { - AdvancedSection::InitControlLayout(); - - if (!base::i18n::IsRTL()) { - gears_label_ = new views::Label(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_GEARSSETTINGS_GROUP_NAME))); - } else { - // Add an RTL mark so that - // ":" in "Google Gears:" in Hebrew Chrome is displayed left-most. - std::wstring gearssetting_group_name = UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_GEARSSETTINGS_GROUP_NAME)); - gearssetting_group_name.push_back( - static_cast<wchar_t>(base::i18n::kRightToLeftMark)); - gears_label_ = new views::Label(gearssetting_group_name); - } - gears_settings_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_GEARSSETTINGS_CONFIGUREGEARS_BUTTON))); - fonts_and_languages_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_FONTSETTINGS_INFO))); - - change_content_fonts_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_FONTSETTINGS_CONFIGUREFONTS_BUTTON))); - - GridLayout* layout = new GridLayout(contents_); - contents_->SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - AddWrappingColumnSet(layout, single_column_view_set_id); - const int indented_column_set_id = 1; - AddIndentedColumnSet(layout, indented_column_set_id); - const int single_double_column_set = 2; - AddTwoColumnSet(layout, single_double_column_set); - - // Fonts and Languages. - AddWrappingLabelRow(layout, fonts_and_languages_label_, - single_column_view_set_id, - true); - AddLeadingControl(layout, change_content_fonts_button_, - indented_column_set_id, - false); - - // Gears. - AddLabeledTwoColumnRow(layout, gears_label_, gears_settings_button_, false, - single_double_column_set, false); -} - -//////////////////////////////////////////////////////////////////////////////// -// SecuritySection - -class SecuritySection : public AdvancedSection, - public views::ButtonListener { - public: - explicit SecuritySection(Profile* profile); - virtual ~SecuritySection() {} - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - protected: - // OptionsPageView overrides: - virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::string* pref_name); - - private: - // Controls for this section: - views::Label* ssl_info_label_; - views::Checkbox* enable_ssl3_checkbox_; - views::Checkbox* enable_tls1_checkbox_; - views::Checkbox* check_for_cert_revocation_checkbox_; - views::Label* manage_certificates_label_; - views::NativeButton* manage_certificates_button_; - - DISALLOW_COPY_AND_ASSIGN(SecuritySection); -}; - -SecuritySection::SecuritySection(Profile* profile) - : ssl_info_label_(NULL), - enable_ssl3_checkbox_(NULL), - enable_tls1_checkbox_(NULL), - check_for_cert_revocation_checkbox_(NULL), - manage_certificates_label_(NULL), - manage_certificates_button_(NULL), - AdvancedSection(profile, UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY))) { -} - -void SecuritySection::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender == enable_ssl3_checkbox_) { - bool enabled = enable_ssl3_checkbox_->checked(); - if (enabled) { - UserMetricsRecordAction(UserMetricsAction("Options_SSL3_Enable"), NULL); - } else { - UserMetricsRecordAction(UserMetricsAction("Options_SSL3_Disable"), NULL); - } - net::SSLConfigServiceWin::SetSSL3Enabled(enabled); - } else if (sender == enable_tls1_checkbox_) { - bool enabled = enable_tls1_checkbox_->checked(); - if (enabled) { - UserMetricsRecordAction(UserMetricsAction("Options_TLS1_Enable"), NULL); - } else { - UserMetricsRecordAction(UserMetricsAction("Options_TLS1_Disable"), NULL); - } - net::SSLConfigServiceWin::SetTLS1Enabled(enabled); - } else if (sender == check_for_cert_revocation_checkbox_) { - bool enabled = check_for_cert_revocation_checkbox_->checked(); - if (enabled) { - UserMetricsRecordAction( - UserMetricsAction("Options_CheckCertRevocation_Enable"), NULL); - } else { - UserMetricsRecordAction( - UserMetricsAction("Options_CheckCertRevocation_Disable"), NULL); - } - net::SSLConfigServiceWin::SetRevCheckingEnabled(enabled); - } else if (sender == manage_certificates_button_) { - UserMetricsRecordAction(UserMetricsAction("Options_ManagerCerts"), NULL); - CRYPTUI_CERT_MGR_STRUCT cert_mgr = { 0 }; - cert_mgr.dwSize = sizeof(CRYPTUI_CERT_MGR_STRUCT); - cert_mgr.hwndParent = GetWindow()->GetNativeWindow(); - ::CryptUIDlgCertMgr(&cert_mgr); - } -} - -void SecuritySection::InitControlLayout() { - AdvancedSection::InitControlLayout(); - - ssl_info_label_ = new views::Label(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_SSL_GROUP_DESCRIPTION))); - enable_ssl3_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_SSL_USESSL3))); - enable_ssl3_checkbox_->set_listener(this); - enable_tls1_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_SSL_USETLS1))); - enable_tls1_checkbox_->set_listener(this); - check_for_cert_revocation_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_SSL_CHECKREVOCATION))); - check_for_cert_revocation_checkbox_->set_listener(this); - manage_certificates_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_CERTIFICATES_LABEL))); - manage_certificates_button_ = new views::NativeButton( - this, - UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON))); - - GridLayout* layout = new GridLayout(contents_); - contents_->SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - AddWrappingColumnSet(layout, single_column_view_set_id); - const int dependent_labeled_field_set_id = 1; - AddDependentTwoColumnSet(layout, dependent_labeled_field_set_id); - const int double_column_view_set_id = 2; - AddTwoColumnSet(layout, double_column_view_set_id); - const int indented_column_set_id = 3; - AddIndentedColumnSet(layout, indented_column_set_id); - const int indented_view_set_id = 4; - AddIndentedColumnSet(layout, indented_view_set_id); - - // SSL connection controls and Certificates. - AddWrappingLabelRow(layout, manage_certificates_label_, - single_column_view_set_id, true); - AddLeadingControl(layout, manage_certificates_button_, - indented_column_set_id, false); - AddWrappingLabelRow(layout, ssl_info_label_, single_column_view_set_id, - true); - AddWrappingCheckboxRow(layout, enable_ssl3_checkbox_, - indented_column_set_id, true); - AddWrappingCheckboxRow(layout, enable_tls1_checkbox_, - indented_column_set_id, true); - AddWrappingCheckboxRow(layout, check_for_cert_revocation_checkbox_, - indented_column_set_id, false); -} - -// This method is called with a null pref_name when the dialog is initialized. -void SecuritySection::NotifyPrefChanged(const std::string* pref_name) { - // These SSL options are system settings and stored in the OS. - if (!pref_name) { - net::SSLConfig config; - if (net::SSLConfigServiceWin::GetSSLConfigNow(&config)) { - enable_ssl3_checkbox_->SetChecked(config.ssl3_enabled); - enable_tls1_checkbox_->SetChecked(config.tls1_enabled); - check_for_cert_revocation_checkbox_->SetChecked( - config.rev_checking_enabled); - } else { - enable_ssl3_checkbox_->SetEnabled(false); - enable_tls1_checkbox_->SetEnabled(false); - check_for_cert_revocation_checkbox_->SetEnabled(false); - } - } -} - -//////////////////////////////////////////////////////////////////////////////// -// NetworkSection - -// A helper method that opens the Internet Options control panel dialog with -// the Connections tab selected. -class OpenConnectionDialogTask : public Task { - public: - OpenConnectionDialogTask() {} - - virtual void Run() { - // Using rundll32 seems better than LaunchConnectionDialog which causes a - // new dialog to be made for each call. rundll32 uses the same global - // dialog and it seems to share with the shortcut in control panel. - FilePath rundll32; - PathService::Get(base::DIR_SYSTEM, &rundll32); - rundll32 = rundll32.AppendASCII("rundll32.exe"); - - FilePath shell32dll; - PathService::Get(base::DIR_SYSTEM, &shell32dll); - shell32dll = shell32dll.AppendASCII("shell32.dll"); - - FilePath inetcpl; - PathService::Get(base::DIR_SYSTEM, &inetcpl); - inetcpl = inetcpl.AppendASCII("inetcpl.cpl,,4"); - - std::wstring args(shell32dll.value()); - args.append(L",Control_RunDLL "); - args.append(inetcpl.value()); - - ShellExecute(NULL, L"open", rundll32.value().c_str(), args.c_str(), NULL, - SW_SHOWNORMAL); - } - - private: - DISALLOW_COPY_AND_ASSIGN(OpenConnectionDialogTask); -}; - -class NetworkSection : public AdvancedSection, - public views::ButtonListener { - public: - explicit NetworkSection(Profile* profile); - virtual ~NetworkSection() {} - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - protected: - // OptionsPageView overrides: - virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::string* pref_name); - - private: - // Controls for this section: - views::Label* change_proxies_label_; - views::NativeButton* change_proxies_button_; - - // Tracks the proxy preferences. - scoped_ptr<PrefSetObserver> proxy_prefs_; - - DISALLOW_COPY_AND_ASSIGN(NetworkSection); -}; - -NetworkSection::NetworkSection(Profile* profile) - : change_proxies_label_(NULL), - change_proxies_button_(NULL), - AdvancedSection(profile, UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK))) { -} - -void NetworkSection::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender == change_proxies_button_) { - UserMetricsRecordAction(UserMetricsAction("Options_ChangeProxies"), NULL); - base::Thread* thread = g_browser_process->file_thread(); - DCHECK(thread); - thread->message_loop()->PostTask(FROM_HERE, new OpenConnectionDialogTask); - } -} - -void NetworkSection::InitControlLayout() { - AdvancedSection::InitControlLayout(); - - change_proxies_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_LABEL))); - change_proxies_button_ = new views::NativeButton( - this, UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON))); - - GridLayout* layout = new GridLayout(contents_); - contents_->SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - AddWrappingColumnSet(layout, single_column_view_set_id); - const int indented_view_set_id = 1; - AddIndentedColumnSet(layout, indented_view_set_id); - const int dependent_labeled_field_set_id = 2; - AddDependentTwoColumnSet(layout, dependent_labeled_field_set_id); - const int dns_set_id = 3; - AddDependentTwoColumnSet(layout, dns_set_id); - - // Proxy settings. - AddWrappingLabelRow(layout, change_proxies_label_, single_column_view_set_id, - true); - AddLeadingControl(layout, change_proxies_button_, indented_view_set_id, - false); - - proxy_prefs_.reset(PrefSetObserver::CreateProxyPrefSetObserver( - profile()->GetPrefs(), this)); - NotifyPrefChanged(NULL); -} - -void NetworkSection::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || proxy_prefs_->IsObserved(*pref_name)) { - change_proxies_button_->SetEnabled(!proxy_prefs_->IsManaged()); - } -} - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// -// DownloadSection - -class DownloadSection : public AdvancedSection, - public views::ButtonListener, - public SelectFileDialog::Listener { - public: - explicit DownloadSection(Profile* profile); - virtual ~DownloadSection() { - select_file_dialog_->ListenerDestroyed(); - } - - // Overridden from views::ButtonListener. - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // SelectFileDialog::Listener implementation. - virtual void FileSelected(const FilePath& path, int index, void* params); - - // OptionsPageView implementation. - virtual bool CanClose() const; - - protected: - // OptionsPageView overrides. - virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::string* pref_name); - - private: - // Controls for this section. - views::Label* download_file_location_label_; - FileDisplayArea* download_default_download_location_display_; - views::NativeButton* download_browse_button_; - views::Checkbox* download_ask_for_save_location_checkbox_; - scoped_refptr<SelectFileDialog> select_file_dialog_; - views::Label* reset_file_handlers_label_; - views::NativeButton* reset_file_handlers_button_; - - // Pref members. - FilePathPrefMember default_download_location_; - BooleanPrefMember ask_for_save_location_; - - // Updates the directory displayed in the default download location view with - // the current value of the pref. - void UpdateDownloadDirectoryDisplay(); - - // Helper function for reacting to managed prefs. - void DownloadSection::UpdateWidgetsForManagedPrefs(); - - StringPrefMember auto_open_files_; - - DISALLOW_COPY_AND_ASSIGN(DownloadSection); -}; - -DownloadSection::DownloadSection(Profile* profile) - : download_file_location_label_(NULL), - download_default_download_location_display_(NULL), - download_browse_button_(NULL), - download_ask_for_save_location_checkbox_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST( - select_file_dialog_(SelectFileDialog::Create(this))), - reset_file_handlers_label_(NULL), - reset_file_handlers_button_(NULL), - AdvancedSection(profile, UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME))) { -} - -void DownloadSection::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender == download_browse_button_) { - const std::wstring dialog_title = UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE)); - select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER, - dialog_title, - profile()->GetPrefs()->GetFilePath( - prefs::kDownloadDefaultDirectory), - NULL, 0, std::wstring(), - GetWindow()->GetNativeWindow(), - NULL); - } else if (sender == download_ask_for_save_location_checkbox_) { - bool enabled = download_ask_for_save_location_checkbox_->checked(); - if (enabled) { - UserMetricsRecordAction( - UserMetricsAction("Options_AskForSaveLocation_Enable"), - profile()->GetPrefs()); - } else { - UserMetricsRecordAction( - UserMetricsAction("Options_AskForSaveLocation_Disable"), - profile()->GetPrefs()); - } - ask_for_save_location_.SetValue(enabled); - } else if (sender == reset_file_handlers_button_) { - profile()->GetDownloadManager()->download_prefs()->ResetAutoOpen(); - UserMetricsRecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"), - profile()->GetPrefs()); - } -} - -void DownloadSection::FileSelected(const FilePath& path, - int index, void* params) { - UserMetricsRecordAction(UserMetricsAction("Options_SetDownloadDirectory"), - profile()->GetPrefs()); - default_download_location_.SetValue(path); - // We need to call this manually here since because we're setting the value - // through the pref member which avoids notifying the listener that set the - // value. - UpdateDownloadDirectoryDisplay(); -} - -bool DownloadSection::CanClose() const { - return !select_file_dialog_->IsRunning(GetWindow()->GetNativeWindow()); -} - -void DownloadSection::InitControlLayout() { - AdvancedSection::InitControlLayout(); - - // Layout the download components. - download_file_location_label_ = new views::Label(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE))); - download_default_download_location_display_ = new FileDisplayArea; - download_browse_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_BUTTON))); - - download_ask_for_save_location_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION))); - download_ask_for_save_location_checkbox_->set_listener(this); - download_ask_for_save_location_checkbox_->SetMultiLine(true); - reset_file_handlers_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_AUTOOPENFILETYPES_INFO))); - reset_file_handlers_button_ = new views::NativeButton( - this, UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT))); - - GridLayout* layout = new GridLayout(contents_); - contents_->SetLayoutManager(layout); - - // Download location label. - const int single_column_view_set_id = 0; - AddWrappingColumnSet(layout, single_column_view_set_id); - AddWrappingLabelRow(layout, download_file_location_label_, - single_column_view_set_id, true); - - // Download location control. - const int double_column_view_set_id = 1; - ColumnSet* column_set = layout->AddColumnSet(double_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); - layout->StartRow(0, double_column_view_set_id); - layout->AddView(download_default_download_location_display_, 1, 1, - GridLayout::FILL, GridLayout::CENTER); - layout->AddView(download_browse_button_); - AddSpacing(layout, true); - - // Save location checkbox layout. - const int indented_view_set_id = 2; - AddIndentedColumnSet(layout, indented_view_set_id); - AddWrappingCheckboxRow(layout, download_ask_for_save_location_checkbox_, - indented_view_set_id, false); - - // Reset file handlers layout. - AddWrappingLabelRow(layout, reset_file_handlers_label_, - single_column_view_set_id, true); - AddLeadingControl(layout, reset_file_handlers_button_, - indented_view_set_id, - false); - - // Init member prefs so we can update the controls if prefs change. - default_download_location_.Init(prefs::kDownloadDefaultDirectory, - profile()->GetPrefs(), this); - ask_for_save_location_.Init(prefs::kPromptForDownload, - profile()->GetPrefs(), this); - auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, profile()->GetPrefs(), - this); -} - -void DownloadSection::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || *pref_name == prefs::kDownloadDefaultDirectory) - UpdateDownloadDirectoryDisplay(); - - if (!pref_name || *pref_name == prefs::kPromptForDownload) { - download_ask_for_save_location_checkbox_->SetChecked( - ask_for_save_location_.GetValue()); - } - - if (!pref_name || *pref_name == prefs::kDownloadExtensionsToOpen) { - bool enabled = - profile()->GetDownloadManager()->download_prefs()->IsAutoOpenUsed(); - reset_file_handlers_label_->SetEnabled(enabled); - reset_file_handlers_button_->SetEnabled(enabled); - } - UpdateWidgetsForManagedPrefs(); -} - -void DownloadSection::UpdateDownloadDirectoryDisplay() { - download_default_download_location_display_->SetFile( - default_download_location_.GetValue()); -} - -void DownloadSection::UpdateWidgetsForManagedPrefs() { - const bool enabled = !default_download_location_.IsManaged(); - download_default_download_location_display_->SetEnabled(enabled); - download_browse_button_->SetEnabled(enabled); - download_ask_for_save_location_checkbox_->SetEnabled(enabled); -} - -//////////////////////////////////////////////////////////////////////////////// -// TranslateSection - -class TranslateSection : public AdvancedSection, - public views::ButtonListener { - public: - explicit TranslateSection(Profile* profile); - virtual ~TranslateSection() {} - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - protected: - // OptionsPageView overrides: - virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::string* pref_name); - - private: - // Control for this section: - views::Checkbox* enable_translate_checkbox_; - - // Preferences for this section: - BooleanPrefMember enable_translate_; - - DISALLOW_COPY_AND_ASSIGN(TranslateSection); -}; - -TranslateSection::TranslateSection(Profile* profile) - : enable_translate_checkbox_(NULL), - AdvancedSection(profile, UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_ADVANCED_SECTION_TITLE_TRANSLATE))) { -} - -void TranslateSection::ButtonPressed( - views::Button* sender, const views::Event& event) { - DCHECK(sender == enable_translate_checkbox_); - bool enabled = enable_translate_checkbox_->checked(); - UserMetricsRecordAction(enabled ? - UserMetricsAction("Options_Translate_Enable") : - UserMetricsAction("Options_Translate_Disable"), - profile()->GetPrefs()); - enable_translate_.SetValue(enabled); -} - -void TranslateSection::InitControlLayout() { - AdvancedSection::InitControlLayout(); - - GridLayout* layout = new GridLayout(contents_); - contents_->SetLayoutManager(layout); - - AddIndentedColumnSet(layout, 0); - - enable_translate_checkbox_ = new views::Checkbox(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE))); - enable_translate_checkbox_->set_listener(this); - AddWrappingCheckboxRow(layout, enable_translate_checkbox_, 0, false); - - // Init member pref so we can update the controls if prefs change. - enable_translate_.Init(prefs::kEnableTranslate, profile()->GetPrefs(), this); -} - -void TranslateSection::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || *pref_name == prefs::kEnableTranslate) - enable_translate_checkbox_->SetChecked(enable_translate_.GetValue()); -} - -//////////////////////////////////////////////////////////////////////////////// -// CloudPrintProxySection - -class CloudPrintProxySection : public AdvancedSection, - public views::ButtonListener, - public CloudPrintSetupFlow::Delegate { - public: - explicit CloudPrintProxySection(Profile* profile); - virtual ~CloudPrintProxySection() {} - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // CloudPrintSetupFlow::Delegate implementation. - virtual void OnDialogClosed(); - - protected: - // OptionsPageView overrides: - virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::string* pref_name); - - private: - bool Enabled() const; - - // Controls for this section: - views::Label* section_description_label_; - views::NativeButton* enable_disable_button_; - views::NativeButton* manage_printer_button_; - - // Preferences we tie things to. - StringPrefMember cloud_print_proxy_email_; - BooleanPrefMember cloud_print_proxy_enabled_; - - base::ScopedCallbackFactory<CloudPrintProxySection> factory_; - - DISALLOW_COPY_AND_ASSIGN(CloudPrintProxySection); -}; - -CloudPrintProxySection::CloudPrintProxySection(Profile* profile) - : section_description_label_(NULL), - enable_disable_button_(NULL), - manage_printer_button_(NULL), - factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), - AdvancedSection(profile, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_ADVANCED_SECTION_TITLE_CLOUD_PRINT))) { -} - -void CloudPrintProxySection::ButtonPressed(views::Button* sender, - const views::Event& event) { - if (sender == enable_disable_button_) { - if (Enabled()) { - // Enabled, we must be the disable button. - UserMetricsRecordAction( - UserMetricsAction("Options_DisableCloudPrintProxy"), NULL); - profile()->GetCloudPrintProxyService()->DisableForUser(); - } else { - UserMetricsRecordAction( - UserMetricsAction("Options_EnableCloudPrintProxy"), NULL); - // We open a new browser window so the Options dialog doesn't - // get lost behind other windows. - enable_disable_button_->SetEnabled(false); - enable_disable_button_->SetLabel(UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLING_BUTTON))); - enable_disable_button_->InvalidateLayout(); - Layout(); - CloudPrintSetupFlow::OpenDialog(profile(), this, - GetWindow()->GetNativeWindow()); - } - } else if (sender == manage_printer_button_) { - UserMetricsRecordAction( - UserMetricsAction("Options_ManageCloudPrinters"), NULL); - browser::ShowOptionsURL( - profile(), - CloudPrintURL(profile()).GetCloudPrintServiceManageURL()); - } -} - -void CloudPrintProxySection::OnDialogClosed() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - enable_disable_button_->SetEnabled(true); - // If the dialog is canceled, the preference won't change, and so we - // have to revert the button text back to the disabled state. - if (!Enabled()) { - enable_disable_button_->SetLabel(UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_BUTTON))); - enable_disable_button_->InvalidateLayout(); - Layout(); - } -} - -void CloudPrintProxySection::InitControlLayout() { - AdvancedSection::InitControlLayout(); - - section_description_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL))); - enable_disable_button_ = new views::NativeButton(this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_BUTTON))); - manage_printer_button_ = new views::NativeButton(this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_MANAGE_BUTTON))); - - GridLayout* layout = new GridLayout(contents_); - contents_->SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - AddWrappingColumnSet(layout, single_column_view_set_id); - const int control_view_set_id = 1; - AddDependentTwoColumnSet(layout, control_view_set_id); - - // The description label at the top and label. - section_description_label_->SetMultiLine(true); - AddWrappingLabelRow(layout, section_description_label_, - single_column_view_set_id, true); - - // The enable / disable button and manage button. - AddTwoColumnRow(layout, enable_disable_button_, manage_printer_button_, false, - control_view_set_id, views::kRelatedControlVerticalSpacing); - - // Attach the preferences so we can flip things appropriately. - cloud_print_proxy_email_.Init(prefs::kCloudPrintEmail, - profile()->GetPrefs(), this); - cloud_print_proxy_enabled_.Init(prefs::kCloudPrintProxyEnabled, - profile()->GetPrefs(), this); - - // Start the UI off in the state we think it should be in. - std::string pref_string(prefs::kCloudPrintEmail); - NotifyPrefChanged(&pref_string); - - // Kick off a task to ask the background service what the real - // answer is. - profile()->GetCloudPrintProxyService()->RefreshStatusFromService(); -} - -void CloudPrintProxySection::NotifyPrefChanged(const std::string* pref_name) { - if (pref_name == NULL) - return; - - if (*pref_name == prefs::kCloudPrintEmail || - *pref_name == prefs::kCloudPrintProxyEnabled) { - bool cloud_print_proxy_allowed = - !cloud_print_proxy_enabled_.IsManaged() || - cloud_print_proxy_enabled_.GetValue(); - - if (Enabled() && cloud_print_proxy_allowed) { - std::string email; - if (profile()->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail)) - email = profile()->GetPrefs()->GetString(prefs::kCloudPrintEmail); - - section_description_label_->SetText(UTF16ToWide( - l10n_util::GetStringFUTF16( - IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_LABEL, - UTF8ToUTF16(email)))); - enable_disable_button_->SetLabel(UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_BUTTON))); - enable_disable_button_->InvalidateLayout(); - enable_disable_button_->SetEnabled(true); - manage_printer_button_->SetVisible(true); - manage_printer_button_->InvalidateLayout(); - } else { - section_description_label_->SetText(UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL))); - enable_disable_button_->SetLabel(UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_BUTTON))); - enable_disable_button_->InvalidateLayout(); - enable_disable_button_->SetEnabled(cloud_print_proxy_allowed); - manage_printer_button_->SetVisible(false); - } - - // Find the parent ScrollView, and ask it to re-layout since it's - // possible that the section_description_label_ has changed - // heights. And scroll us back to being visible in that case, to - // be nice to the user. - views::View* view = section_description_label_->parent(); - while (view && view->GetClassName() != views::ScrollView::kViewClassName) - view = view->parent(); - if (view) { - gfx::Rect visible_bounds = GetVisibleBounds(); - bool was_all_visible = (visible_bounds.size() == size()); - // Our bounds can change across this call, so we have to use the - // new bounds if we want to stay completely visible. - view->Layout(); - ScrollRectToVisible(was_all_visible ? bounds() : visible_bounds); - } else { - Layout(); - } - } -} - -bool CloudPrintProxySection::Enabled() const { - return profile()->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && - !profile()->GetPrefs()->GetString(prefs::kCloudPrintEmail).empty(); -} - -//////////////////////////////////////////////////////////////////////////////// -// AdvancedContentsView - -class AdvancedContentsView : public OptionsPageView { - public: - explicit AdvancedContentsView(Profile* profile); - virtual ~AdvancedContentsView(); - - // views::View overrides: - virtual int GetLineScrollIncrement(views::ScrollView* scroll_view, - bool is_horizontal, bool is_positive); - virtual void Layout(); - - protected: - // OptionsPageView implementation: - virtual void InitControlLayout(); - - private: - static void InitClass(); - - static int line_height_; - - DISALLOW_COPY_AND_ASSIGN(AdvancedContentsView); -}; - -// static -int AdvancedContentsView::line_height_ = 0; - -//////////////////////////////////////////////////////////////////////////////// -// AdvancedContentsView, public: - -AdvancedContentsView::AdvancedContentsView(Profile* profile) - : OptionsPageView(profile) { - InitClass(); -} - -AdvancedContentsView::~AdvancedContentsView() { -} - -//////////////////////////////////////////////////////////////////////////////// -// AdvancedContentsView, views::View overrides: - -int AdvancedContentsView::GetLineScrollIncrement( - views::ScrollView* scroll_view, - bool is_horizontal, - bool is_positive) { - - if (!is_horizontal) - return line_height_; - return View::GetPageScrollIncrement(scroll_view, is_horizontal, is_positive); -} - -void AdvancedContentsView::Layout() { - if (parent() && parent()->width()) { - const int width = parent()->width(); - const int height = GetHeightForWidth(width); - SetBounds(0, 0, width, height); - } else { - gfx::Size prefsize = GetPreferredSize(); - SetBounds(0, 0, prefsize.width(), prefsize.height()); - } - View::Layout(); -} - -//////////////////////////////////////////////////////////////////////////////// -// AdvancedContentsView, OptionsPageView implementation: - -void AdvancedContentsView::InitControlLayout() { - GridLayout* layout = GridLayout::CreatePanel(this); - SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_view_set_id); - layout->AddView(new PrivacySection(profile())); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(new NetworkSection(profile())); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(new TranslateSection(profile())); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(new DownloadSection(profile())); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(new WebContentSection(profile())); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(new SecuritySection(profile())); -#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) - // We want to enable the cloud print UI on Windows. Since the cloud - // print proxy on Windows needs the PDF plugin, we only enable it by - // default on Google Chrome Windows builds (which contain the PDF - // plugin). - bool cloud_print_available = true; -#else - bool cloud_print_available = CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCloudPrintProxy); -#endif - if (cloud_print_available && - profile()->GetCloudPrintProxyService()) { - layout->StartRow(0, single_column_view_set_id); - layout->AddView(new CloudPrintProxySection(profile())); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// AdvancedContentsView, private: - -void AdvancedContentsView::InitClass() { - static bool initialized = false; - if (!initialized) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - line_height_ = rb.GetFont(ResourceBundle::BaseFont).GetHeight(); - initialized = true; - } -} - -//////////////////////////////////////////////////////////////////////////////// -// AdvancedScrollViewContainer, public: - -AdvancedScrollViewContainer::AdvancedScrollViewContainer(Profile* profile) - : contents_view_(new AdvancedContentsView(profile)), - scroll_view_(new views::ScrollView) { - AddChildView(scroll_view_); - scroll_view_->SetContents(contents_view_); - set_background(new ListBackground()); -} - -AdvancedScrollViewContainer::~AdvancedScrollViewContainer() { -} - -//////////////////////////////////////////////////////////////////////////////// -// AdvancedScrollViewContainer, views::View overrides: - -void AdvancedScrollViewContainer::Layout() { - gfx::Rect lb = GetLocalBounds(); - - gfx::Size border = gfx::NativeTheme::instance()->GetThemeBorderSize( - gfx::NativeTheme::LIST); - lb.Inset(border.width(), border.height()); - scroll_view_->SetBoundsRect(lb); -} diff --git a/chrome/browser/ui/views/options/advanced_contents_view.h b/chrome/browser/ui/views/options/advanced_contents_view.h deleted file mode 100644 index 2e1b40e..0000000 --- a/chrome/browser/ui/views/options/advanced_contents_view.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_ADVANCED_CONTENTS_VIEW_H__ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_ADVANCED_CONTENTS_VIEW_H__ -#pragma once - -#include "chrome/browser/ui/views/options/options_page_view.h" - -class AdvancedContentsView; -namespace views { -class ScrollView; -} - -/////////////////////////////////////////////////////////////////////////////// -// AdvancedScrollViewContainer -// -// A View that contains a scroll view containing the Advanced options. - -class AdvancedScrollViewContainer : public views::View { - public: - explicit AdvancedScrollViewContainer(Profile* profile); - virtual ~AdvancedScrollViewContainer(); - - // views::View overrides: - virtual void Layout() OVERRIDE; - - private: - // The contents of the advanced scroll view. - AdvancedContentsView* contents_view_; - - // The scroll view that contains the advanced options. - views::ScrollView* scroll_view_; - - DISALLOW_COPY_AND_ASSIGN(AdvancedScrollViewContainer); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_ADVANCED_CONTENTS_VIEW_H__ diff --git a/chrome/browser/ui/views/options/advanced_page_view.cc b/chrome/browser/ui/views/options/advanced_page_view.cc deleted file mode 100644 index 907caa7..0000000 --- a/chrome/browser/ui/views/options/advanced_page_view.cc +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/advanced_page_view.h" - -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/options/options_util.h" -#include "chrome/browser/ui/views/options/advanced_contents_view.h" -#include "chrome/browser/ui/views/options/managed_prefs_banner_view.h" -#include "chrome/common/chrome_constants.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/message_box_flags.h" -#include "views/controls/message_box_view.h" -#include "views/controls/button/native_button.h" -#include "views/controls/scroll_view.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" -#include "views/window/dialog_delegate.h" -#include "views/window/window.h" - -namespace { - -// A dialog box that asks the user to confirm resetting settings. -class ResetDefaultsConfirmBox : public views::DialogDelegate { - public: - // This box is modal to |parent_hwnd|. - static void ShowConfirmBox(HWND parent_hwnd, AdvancedPageView* page_view) { - // When the window closes, it will delete itself. - new ResetDefaultsConfirmBox(parent_hwnd, page_view); - } - - protected: - // views::DialogDelegate - virtual std::wstring GetDialogButtonLabel( - ui::MessageBoxFlags::DialogButton button) const { - switch (button) { - case ui::MessageBoxFlags::DIALOGBUTTON_OK: - return UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_OKLABEL)); - case ui::MessageBoxFlags::DIALOGBUTTON_CANCEL: - return UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_CANCELLABEL)); - default: - break; - } - NOTREACHED(); - return std::wstring(); - } - virtual std::wstring GetWindowTitle() const { - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); - } - virtual bool Accept() { - advanced_page_view_->ResetToDefaults(); - return true; - } - // views::WindowDelegate - virtual void DeleteDelegate() { delete this; } - virtual bool IsModal() const { return true; } - virtual views::View* GetContentsView() { return message_box_view_; } - - private: - ResetDefaultsConfirmBox(HWND parent_hwnd, AdvancedPageView* page_view) - : advanced_page_view_(page_view) { - int dialog_width = views::Window::GetLocalizedContentsWidth( - IDS_OPTIONS_RESET_CONFIRM_BOX_WIDTH_CHARS); - // Also deleted when the window closes. - message_box_view_ = new MessageBoxView( - ui::MessageBoxFlags::kFlagHasMessage | - ui::MessageBoxFlags::kFlagHasOKButton, - UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_MESSAGE)).c_str(), - std::wstring(), - dialog_width); - views::Window::CreateChromeWindow(parent_hwnd, gfx::Rect(), this)->Show(); - } - virtual ~ResetDefaultsConfirmBox() { } - - MessageBoxView* message_box_view_; - AdvancedPageView* advanced_page_view_; - - DISALLOW_COPY_AND_ASSIGN(ResetDefaultsConfirmBox); -}; - -} // namespace - -/////////////////////////////////////////////////////////////////////////////// -// AdvancedPageView, public: - -AdvancedPageView::AdvancedPageView(Profile* profile) - : advanced_scroll_view_(NULL), - reset_to_default_button_(NULL), - OptionsPageView(profile) { -} - -AdvancedPageView::~AdvancedPageView() { -} - -void AdvancedPageView::ResetToDefaults() { - OptionsUtil::ResetToDefaults(profile()); -} - -/////////////////////////////////////////////////////////////////////////////// -// AdvancedPageView, views::ButtonListener implementation: - -void AdvancedPageView::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender == reset_to_default_button_) { - UserMetricsRecordAction(UserMetricsAction("Options_ResetToDefaults"), - NULL); - ResetDefaultsConfirmBox::ShowConfirmBox( - GetWindow()->GetNativeWindow(), this); - } -} - -/////////////////////////////////////////////////////////////////////////////// -// AdvancedPageView, OptionsPageView implementation: - -void AdvancedPageView::InitControlLayout() { - reset_to_default_button_ = new views::NativeButton( - this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_RESET))); - advanced_scroll_view_ = new AdvancedScrollViewContainer(profile()); - - using views::GridLayout; - using views::ColumnSet; - - GridLayout* layout = GridLayout::CreatePanel(this); - SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - layout->StartRow(0, single_column_view_set_id); - layout->AddView( - new ManagedPrefsBannerView(profile()->GetPrefs(), OPTIONS_PAGE_ADVANCED)); - - layout->StartRow(1, single_column_view_set_id); - layout->AddView(advanced_scroll_view_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - layout->StartRow(0, single_column_view_set_id); - layout->AddView(reset_to_default_button_, 1, 1, - GridLayout::TRAILING, GridLayout::CENTER); -} diff --git a/chrome/browser/ui/views/options/advanced_page_view.h b/chrome/browser/ui/views/options/advanced_page_view.h deleted file mode 100644 index 90ce325..0000000 --- a/chrome/browser/ui/views/options/advanced_page_view.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_ADVANCED_PAGE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_ADVANCED_PAGE_VIEW_H_ -#pragma once - -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "views/controls/button/button.h" - -class AdvancedOptionsListModel; -class AdvancedScrollViewContainer; -class PrefService; -namespace views { -class NativeButton; -} - -/////////////////////////////////////////////////////////////////////////////// -// AdvancedPageView - -class AdvancedPageView : public OptionsPageView, - public views::ButtonListener { - public: - explicit AdvancedPageView(Profile* profile); - virtual ~AdvancedPageView(); - - // Resets all prefs to their default values. - void ResetToDefaults(); - - // views::ButtonListener implementation: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - protected: - // OptionsPageView implementation: - virtual void InitControlLayout(); - - private: - // Controls for the Advanced page - AdvancedScrollViewContainer* advanced_scroll_view_; - views::NativeButton* reset_to_default_button_; - - DISALLOW_COPY_AND_ASSIGN(AdvancedPageView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_ADVANCED_PAGE_VIEW_H_ diff --git a/chrome/browser/ui/views/options/content_exceptions_table_view.cc b/chrome/browser/ui/views/options/content_exceptions_table_view.cc deleted file mode 100644 index 39c2478..0000000 --- a/chrome/browser/ui/views/options/content_exceptions_table_view.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/content_exceptions_table_view.h" - -#include "ui/gfx/font.h" - -ContentExceptionsTableView::ContentExceptionsTableView( - ContentExceptionsTableModel* model, - const std::vector<TableColumn>& columns) - : views::TableView(model, columns, views::TEXT_ONLY, false, true, false), - exceptions_(model) { - SetCustomColorsEnabled(true); -} - -bool ContentExceptionsTableView::GetCellColors(int model_row, - int column, - ItemColor* foreground, - ItemColor* background, - LOGFONT* logfont) { - if (!exceptions_->entry_is_off_the_record(model_row)) - return false; - - foreground->color_is_set = false; - background->color_is_set = false; - - gfx::Font font; - font = font.DeriveFont(0, gfx::Font::ITALIC); - HFONT hf = font.GetNativeFont(); - GetObject(hf, sizeof(LOGFONT), logfont); - return true; -} diff --git a/chrome/browser/ui/views/options/content_exceptions_table_view.h b/chrome/browser/ui/views/options/content_exceptions_table_view.h deleted file mode 100644 index 184fb9d..0000000 --- a/chrome/browser/ui/views/options/content_exceptions_table_view.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_EXCEPTIONS_TABLE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_EXCEPTIONS_TABLE_VIEW_H_ -#pragma once - -#include "chrome/browser/content_exceptions_table_model.h" -#include "views/controls/table/table_view.h" - -// A thin wrapper around TableView that displays incognito entries in -// italics. -class ContentExceptionsTableView : public views::TableView { - public: - ContentExceptionsTableView(ContentExceptionsTableModel* model, - const std::vector<TableColumn>& columns); - - virtual ~ContentExceptionsTableView() {} - - private: - virtual bool GetCellColors(int model_row, - int column, - ItemColor* foreground, - ItemColor* background, - LOGFONT* logfont); - - ContentExceptionsTableModel* exceptions_; -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_EXCEPTIONS_TABLE_VIEW_H_ diff --git a/chrome/browser/ui/views/options/content_filter_page_view.cc b/chrome/browser/ui/views/options/content_filter_page_view.cc deleted file mode 100644 index 32d842d..0000000 --- a/chrome/browser/ui/views/options/content_filter_page_view.cc +++ /dev/null @@ -1,297 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/content_filter_page_view.h" - -#include "base/command_line.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/content_settings/content_settings_details.h" -#include "chrome/browser/geolocation/geolocation_content_settings_map.h" -#include "chrome/browser/geolocation/geolocation_exceptions_table_model.h" -#include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/notification_exceptions_table_model.h" -#include "chrome/browser/plugin_exceptions_table_model.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/views/options/exceptions_view.h" -#include "chrome/browser/ui/views/options/simple_content_exceptions_view.h" -#include "chrome/common/chrome_switches.h" -#include "content/common/notification_details.h" -#include "content/common/notification_service.h" -#include "content/common/notification_type.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "views/controls/button/radio_button.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" -#include "views/window/window.h" - -ContentFilterPageView::ContentFilterPageView(Profile* profile, - ContentSettingsType content_type) - : OptionsPageView(profile), - content_type_(content_type), - allow_radio_(NULL), - ask_radio_(NULL), - block_radio_(NULL), - exceptions_button_(NULL) { -} - -ContentFilterPageView::~ContentFilterPageView() { -} - -//////////////////////////////////////////////////////////////////////////////// -// ContentFilterPageView, OptionsPageView implementation: - -void ContentFilterPageView::InitControlLayout() { - using views::GridLayout; - - GridLayout* layout = new GridLayout(this); - SetLayoutManager(layout); - - const int single_column_set_id = 0; - views::ColumnSet* column_set = layout->AddColumnSet(single_column_set_id); - column_set->AddPaddingColumn(0, views::kRelatedControlVerticalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - static const int kTitleIDs[] = { - IDS_MODIFY_COOKIE_STORING_LABEL, - IDS_IMAGES_SETTING_LABEL, - IDS_JS_SETTING_LABEL, - IDS_PLUGIN_SETTING_LABEL, - IDS_POPUP_SETTING_LABEL, - IDS_GEOLOCATION_SETTING_LABEL, - IDS_NOTIFICATIONS_SETTING_LABEL, - 0, - }; - COMPILE_ASSERT(arraysize(kTitleIDs) == CONTENT_SETTINGS_NUM_TYPES, - Need_a_setting_for_every_content_settings_type); - views::Label* title_label = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16(kTitleIDs[content_type_]))); - title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - title_label->SetMultiLine(true); - - layout->StartRow(0, single_column_set_id); - layout->AddView(title_label); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - static const int kAllowIDs[] = { - IDS_COOKIES_ALLOW_RADIO, - IDS_IMAGES_LOAD_RADIO, - IDS_JS_ALLOW_RADIO, - IDS_PLUGIN_LOAD_RADIO, - IDS_POPUP_ALLOW_RADIO, - IDS_GEOLOCATION_ALLOW_RADIO, - IDS_NOTIFICATIONS_ALLOW_RADIO, - 0, - }; - COMPILE_ASSERT(arraysize(kAllowIDs) == CONTENT_SETTINGS_NUM_TYPES, - Need_a_setting_for_every_content_settings_type); - const int radio_button_group = 0; - allow_radio_ = new views::RadioButton( - UTF16ToWide(l10n_util::GetStringUTF16(kAllowIDs[content_type_])), - radio_button_group); - allow_radio_->set_listener(this); - allow_radio_->SetMultiLine(true); - layout->StartRow(0, single_column_set_id); - layout->AddView(allow_radio_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - static const int kAskIDs[] = { - IDS_COOKIES_ASK_EVERY_TIME_RADIO, - 0, - 0, - IDS_PLUGIN_ASK_RADIO, - 0, - IDS_GEOLOCATION_ASK_RADIO, - IDS_NOTIFICATIONS_ASK_RADIO, - 0, - }; - COMPILE_ASSERT(arraysize(kAskIDs) == CONTENT_SETTINGS_NUM_TYPES, - Need_a_setting_for_every_content_settings_type); - if (content_type_ != CONTENT_SETTINGS_TYPE_COOKIES) { - int askID = kAskIDs[content_type_]; - if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS && - !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableClickToPlay)) { - askID = 0; - } - if (askID != 0) { - ask_radio_ = new views::RadioButton( - UTF16ToWide(l10n_util::GetStringUTF16(askID)), radio_button_group); - ask_radio_->set_listener(this); - ask_radio_->SetMultiLine(true); - layout->StartRow(0, single_column_set_id); - layout->AddView(ask_radio_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - } - } - - static const int kBlockIDs[] = { - IDS_COOKIES_BLOCK_RADIO, - IDS_IMAGES_NOLOAD_RADIO, - IDS_JS_DONOTALLOW_RADIO, - IDS_PLUGIN_NOLOAD_RADIO, - IDS_POPUP_BLOCK_RADIO, - IDS_GEOLOCATION_BLOCK_RADIO, - IDS_NOTIFICATIONS_BLOCK_RADIO, - 0, - }; - COMPILE_ASSERT(arraysize(kBlockIDs) == CONTENT_SETTINGS_NUM_TYPES, - Need_a_setting_for_every_content_settings_type); - block_radio_ = new views::RadioButton( - UTF16ToWide(l10n_util::GetStringUTF16(kBlockIDs[content_type_])), - radio_button_group); - block_radio_->set_listener(this); - block_radio_->SetMultiLine(true); - layout->StartRow(0, single_column_set_id); - layout->AddView(block_radio_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - exceptions_button_ = new views::NativeButton(this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_COOKIES_EXCEPTIONS_BUTTON))); - - layout->StartRow(0, single_column_set_id); - layout->AddView(exceptions_button_, 1, 1, GridLayout::LEADING, - GridLayout::FILL); - - UpdateView(); - - registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED, - NotificationService::AllSources()); - registrar_.Add(this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, - NotificationService::AllSources()); - registrar_.Add(this, NotificationType::GEOLOCATION_SETTINGS_CHANGED, - NotificationService::AllSources()); -} - -/////////////////////////////////////////////////////////////////////////////// -// ContentFilterPageView, -void ContentFilterPageView::UpdateView() { - ContentSetting default_setting; - bool is_content_type_managed = false; - if (content_type_ == CONTENT_SETTINGS_TYPE_GEOLOCATION) { - default_setting = profile()->GetGeolocationContentSettingsMap()-> - GetDefaultContentSetting(); - is_content_type_managed = profile()->GetGeolocationContentSettingsMap()-> - IsDefaultContentSettingManaged(); - } else if (content_type_ == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { - default_setting = profile()->GetDesktopNotificationService()-> - GetDefaultContentSetting(); - is_content_type_managed = profile()->GetDesktopNotificationService()-> - IsDefaultContentSettingManaged(); - } else { - default_setting = profile()->GetHostContentSettingsMap()-> - GetDefaultContentSetting(content_type_); - is_content_type_managed = profile()->GetHostContentSettingsMap()-> - IsDefaultContentSettingManaged(content_type_); - } - // Now that these have been added to the view hierarchy, it's safe to call - // SetChecked() on them. - if (default_setting == CONTENT_SETTING_ALLOW) { - allow_radio_->SetChecked(true); - } else if (default_setting == CONTENT_SETTING_ASK) { - DCHECK(ask_radio_ != NULL); - ask_radio_->SetChecked(true); - } else { - DCHECK(default_setting == CONTENT_SETTING_BLOCK); - block_radio_->SetChecked(true); - } - - // Set enable state of the buttons. - allow_radio_->SetEnabled(!is_content_type_managed); - if (ask_radio_) - ask_radio_->SetEnabled(!is_content_type_managed); - block_radio_->SetEnabled(!is_content_type_managed); - exceptions_button_->SetEnabled(!is_content_type_managed); -} - -/////////////////////////////////////////////////////////////////////////////// -// ContentFilterPageView, views::ButtonListener implementation: - -void ContentFilterPageView::ButtonPressed(views::Button* sender, - const views::Event& event) { - if (sender == exceptions_button_) { - if (content_type_ == CONTENT_SETTINGS_TYPE_GEOLOCATION) { - SimpleContentExceptionsView::ShowExceptionsWindow( - GetWindow()->GetNativeWindow(), - new GeolocationExceptionsTableModel( - profile()->GetGeolocationContentSettingsMap()), - IDS_GEOLOCATION_EXCEPTION_TITLE); - } else if (content_type_ == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { - SimpleContentExceptionsView::ShowExceptionsWindow( - GetWindow()->GetNativeWindow(), - new NotificationExceptionsTableModel( - profile()->GetDesktopNotificationService()), - IDS_NOTIFICATIONS_EXCEPTION_TITLE); - } else { - HostContentSettingsMap* settings = profile()->GetHostContentSettingsMap(); - HostContentSettingsMap* otr_settings = - profile()->HasOffTheRecordProfile() ? - profile()->GetOffTheRecordProfile()->GetHostContentSettingsMap() : - NULL; - if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS && - CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableResourceContentSettings)) { - PluginExceptionsTableModel* model = - new PluginExceptionsTableModel(settings, otr_settings); - model->LoadSettings(); - SimpleContentExceptionsView::ShowExceptionsWindow( - GetWindow()->GetNativeWindow(), - model, - IDS_PLUGINS_EXCEPTION_TITLE); - } else { - ExceptionsView::ShowExceptionsWindow(GetWindow()->GetNativeWindow(), - settings, - otr_settings, - content_type_); - } - } - return; - } - - DCHECK((sender == allow_radio_) || (sender == ask_radio_) || - (sender == block_radio_)); - ContentSetting default_setting = allow_radio_->checked() ? - CONTENT_SETTING_ALLOW : - (block_radio_->checked() ? CONTENT_SETTING_BLOCK : CONTENT_SETTING_ASK); - if (content_type_ == CONTENT_SETTINGS_TYPE_GEOLOCATION) { - profile()->GetGeolocationContentSettingsMap()->SetDefaultContentSetting( - default_setting); - } else if (content_type_ == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { - profile()->GetDesktopNotificationService()->SetDefaultContentSetting( - default_setting); - } else { - profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( - content_type_, default_setting); - } -} - -void ContentFilterPageView::NotifyContentSettingsChanged( - const ContentSettingsDetails* details) { - if (details->type() == CONTENT_SETTINGS_TYPE_DEFAULT || - details->type() == content_type_) { - UpdateView(); - } -} - -void ContentFilterPageView::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::CONTENT_SETTINGS_CHANGED) { - NotifyContentSettingsChanged( - Details<ContentSettingsDetails>(details).ptr()); - } else if (type == NotificationType::GEOLOCATION_SETTINGS_CHANGED) { - NotifyContentSettingsChanged( - Details<ContentSettingsDetails>(details).ptr()); - } else if (type == NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED) { - ContentSettingsDetails content_settings_details( - ContentSettingsPattern(), - CONTENT_SETTINGS_TYPE_NOTIFICATIONS, - ""); - NotifyContentSettingsChanged(&content_settings_details); - } else { - OptionsPageBase::Observe(type, source, details); - } -} diff --git a/chrome/browser/ui/views/options/content_filter_page_view.h b/chrome/browser/ui/views/options/content_filter_page_view.h deleted file mode 100644 index 57575cb..0000000 --- a/chrome/browser/ui/views/options/content_filter_page_view.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_FILTER_PAGE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_FILTER_PAGE_VIEW_H_ -#pragma once - -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "chrome/common/content_settings_types.h" -#include "content/common/notification_registrar.h" -#include "views/controls/button/button.h" - -namespace views { -class Label; -class NativeButton; -class RadioButton; -} -class PrefService; - -//////////////////////////////////////////////////////////////////////////////// -// The ContentFilterPageView class is used to render the Images, JavaScript, -// Pop-ups and Location pages in the Content Settings window. - -class ContentFilterPageView : public OptionsPageView, - public views::ButtonListener { - public: - ContentFilterPageView(Profile* profile, ContentSettingsType content_type); - virtual ~ContentFilterPageView(); - - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - protected: - // Updates the state of the UI. UpdateView is called when the content filter - // page is initialized and after the content setting changed (either the - // value or the is managed state). - virtual void UpdateView(); - - virtual void NotifyContentSettingsChanged( - const ContentSettingsDetails* details); - - // OptionsPageView implementation: - virtual void InitControlLayout(); - - // views::ButtonListener implementation: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - private: - ContentSettingsType content_type_; - - // Controls for the content filter tab page. - views::RadioButton* allow_radio_; - views::RadioButton* ask_radio_; - views::RadioButton* block_radio_; - views::NativeButton* exceptions_button_; - - NotificationRegistrar registrar_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(ContentFilterPageView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_FILTER_PAGE_VIEW_H_ diff --git a/chrome/browser/ui/views/options/content_page_view.cc b/chrome/browser/ui/views/options/content_page_view.cc deleted file mode 100644 index cc06acf..0000000 --- a/chrome/browser/ui/views/options/content_page_view.cc +++ /dev/null @@ -1,507 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/content_page_view.h" - -#include <shlobj.h> -#include <vsstyle.h> -#include <vssym32.h> -#include <windows.h> - -#include <string> - -#include "base/command_line.h" -#include "base/string_util.h" -#include "chrome/browser/autofill/autofill_dialog.h" -#include "chrome/browser/autofill/personal_data_manager.h" -#include "chrome/browser/browser_list.h" -#include "chrome/browser/browser_window.h" -#include "chrome/browser/importer/importer_data_types.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/sync_setup_wizard.h" -#include "chrome/browser/sync/sync_ui_util.h" -#include "chrome/browser/ui/views/importer/import_dialog_view.h" -#include "chrome/browser/ui/views/options/managed_prefs_banner_view.h" -#include "chrome/browser/ui/views/options/options_group_view.h" -#include "chrome/browser/ui/views/options/passwords_exceptions_window_view.h" -#include "chrome/common/pref_names.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/native_theme_win.h" -#include "views/controls/button/radio_button.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" -#include "views/widget/widget.h" -#include "views/window/window.h" - -namespace { - -// All the options pages are in the same view hierarchy. This means we need to -// make sure group identifiers don't collide across different pages. -const int kPasswordSavingRadioGroup = 201; -const int kFormAutofillRadioGroup = 202; - -// Background color for the status label when it's showing an error. -static const SkColor kSyncLabelErrorBgColor = SkColorSetRGB(0xff, 0x9a, 0x9a); - -static views::Background* CreateErrorBackground() { - return views::Background::CreateSolidBackground(kSyncLabelErrorBgColor); -} - -} // namespace - -ContentPageView::ContentPageView(Profile* profile) - : show_passwords_button_(NULL), - passwords_group_(NULL), - passwords_asktosave_radio_(NULL), - passwords_neversave_radio_(NULL), - change_autofill_settings_button_(NULL), - themes_group_(NULL), - themes_reset_button_(NULL), - themes_gallery_link_(NULL), - browsing_data_group_(NULL), - import_button_(NULL), - sync_group_(NULL), - sync_action_link_(NULL), - sync_status_label_(NULL), - sync_start_stop_button_(NULL), - sync_customize_button_(NULL), - privacy_dashboard_link_(NULL), - sync_service_(NULL), - OptionsPageView(profile) { - if (profile->GetProfileSyncService()) { - sync_service_ = profile->GetProfileSyncService(); - sync_service_->AddObserver(this); - } -} - -ContentPageView::~ContentPageView() { - if (sync_service_) - sync_service_->RemoveObserver(this); -} - -/////////////////////////////////////////////////////////////////////////////// -// ContentPageView, views::ButtonListener implementation: - -void ContentPageView::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender == passwords_asktosave_radio_ || - sender == passwords_neversave_radio_) { - bool enabled = passwords_asktosave_radio_->checked(); - if (enabled) { - UserMetricsRecordAction( - UserMetricsAction("Options_PasswordManager_Enable"), - profile()->GetPrefs()); - } else { - UserMetricsRecordAction( - UserMetricsAction("Options_PasswordManager_Disable"), - profile()->GetPrefs()); - } - ask_to_save_passwords_.SetValue(enabled); - } else if (sender == show_passwords_button_) { - UserMetricsRecordAction( - UserMetricsAction("Options_ShowPasswordsExceptions"), NULL); - PasswordsExceptionsWindowView::Show(profile()); - } else if (sender == change_autofill_settings_button_) { - // This button should be disabled if we lack PersonalDataManager. - DCHECK(profile()->GetPersonalDataManager()); - ShowAutoFillDialog(GetWindow()->GetNativeWindow(), - profile()->GetPersonalDataManager(), - profile()); - } else if (sender == themes_reset_button_) { - UserMetricsRecordAction(UserMetricsAction("Options_ThemesReset"), - profile()->GetPrefs()); - profile()->ClearTheme(); - } else if (sender == import_button_) { - views::Window::CreateChromeWindow( - GetWindow()->GetNativeWindow(), - gfx::Rect(), - new ImportDialogView(profile(), importer::ALL))->Show(); - } else if (sender == sync_start_stop_button_) { - DCHECK(sync_service_ && !sync_service_->IsManaged()); - - if (sync_service_->HasSyncSetupCompleted()) { - ConfirmMessageBoxDialog::RunWithCustomConfiguration( - GetWindow()->GetNativeWindow(), - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL)), - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_SYNC_STOP_SYNCING_DIALOG_TITLE)), - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL)), - UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL)), - gfx::Size(views::Window::GetLocalizedContentsSize( - IDS_CONFIRM_STOP_SYNCING_DIALOG_WIDTH_CHARS, - IDS_CONFIRM_STOP_SYNCING_DIALOG_HEIGHT_LINES))); - return; - } else { - sync_service_->ShowLoginDialog(GetWindow()->GetNativeWindow()); - ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_OPTIONS); - } - } else if (sender == sync_customize_button_) { - // sync_customize_button_ should be invisible if sync is not yet set up. - DCHECK(sync_service_->HasSyncSetupCompleted()); - sync_service_->ShowConfigure(GetWindow()->GetNativeWindow()); - } -} - -void ContentPageView::LinkActivated(views::Link* source, int event_flags) { - if (source == themes_gallery_link_) { - UserMetricsRecordAction(UserMetricsAction("Options_ThemesGallery"), - profile()->GetPrefs()); - BrowserList::GetLastActive()->OpenThemeGalleryTabAndActivate(); - return; - } - if (source == sync_action_link_) { - DCHECK(sync_service_ && !sync_service_->IsManaged()); - sync_service_->ShowErrorUI(GetWindow()->GetNativeWindow()); - return; - } - if (source == privacy_dashboard_link_) { - BrowserList::GetLastActive()->OpenPrivacyDashboardTabAndActivate(); - return; - } - NOTREACHED() << "Invalid link source."; -} - -//////////////////////////////////////////////////////////////////////////////// -// ContentPageView, OptionsPageView implementation: - -void ContentPageView::InitControlLayout() { - using views::GridLayout; - using views::ColumnSet; - - GridLayout* layout = new GridLayout(this); - layout->SetInsets(5, 5, 5, 5); - SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_view_set_id); - layout->AddView( - new ManagedPrefsBannerView(profile()->GetPrefs(), OPTIONS_PAGE_CONTENT)); - - if (sync_service_) { - layout->StartRow(0, single_column_view_set_id); - InitSyncGroup(); - layout->AddView(sync_group_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - } - - layout->StartRow(0, single_column_view_set_id); - InitPasswordSavingGroup(); - layout->AddView(passwords_group_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - layout->StartRow(0, single_column_view_set_id); - InitFormAutofillGroup(); - layout->AddView(form_autofill_group_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - layout->StartRow(0, single_column_view_set_id); - InitBrowsingDataGroup(); - layout->AddView(browsing_data_group_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - layout->StartRow(0, single_column_view_set_id); - InitThemesGroup(); - layout->AddView(themes_group_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - // Init member prefs so we can update the controls if prefs change. - ask_to_save_passwords_.Init(prefs::kPasswordManagerEnabled, - profile()->GetPrefs(), this); - form_autofill_enabled_.Init(prefs::kAutoFillEnabled, - profile()->GetPrefs(), this); - is_using_default_theme_.Init(prefs::kCurrentThemeID, - profile()->GetPrefs(), this); -} - -void ContentPageView::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || *pref_name == prefs::kPasswordManagerEnabled) { - if (ask_to_save_passwords_.GetValue()) { - passwords_asktosave_radio_->SetChecked(true); - } else { - passwords_neversave_radio_->SetChecked(true); - } - - // Disable UI elements that are managed via policy. - bool enablePasswordManagerElements = !ask_to_save_passwords_.IsManaged(); - passwords_asktosave_radio_->SetEnabled(enablePasswordManagerElements); - passwords_neversave_radio_->SetEnabled(enablePasswordManagerElements); - show_passwords_button_->SetEnabled(enablePasswordManagerElements || - ask_to_save_passwords_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kAutoFillEnabled) { - bool disabled_by_policy = form_autofill_enabled_.IsManaged() && - !form_autofill_enabled_.GetValue(); - change_autofill_settings_button_->SetEnabled( - !disabled_by_policy && profile()->GetPersonalDataManager()); - } - if (!pref_name || *pref_name == prefs::kCurrentThemeID) { - themes_reset_button_->SetEnabled( - is_using_default_theme_.GetValue().length() > 0); - } -} - -/////////////////////////////////////////////////////////////////////////////// -// ContentsPageView, views::View overrides: - -void ContentPageView::Layout() { - if (is_initialized()) - UpdateSyncControls(); - View::Layout(); -} - - -/////////////////////////////////////////////////////////////////////////////// -// ContentsPageView, ProfileSyncServiceObserver implementation: - -void ContentPageView::OnStateChanged() { - // If the UI controls are not yet initialized, then don't do anything. This - // can happen if the Options dialog is up, but the Content tab is not yet - // clicked. - if (is_initialized()) - Layout(); -} - -/////////////////////////////////////////////////////////////////////////////// -// ContentPageView, private: - -void ContentPageView::InitPasswordSavingGroup() { - passwords_asktosave_radio_ = new views::RadioButton( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_ASKTOSAVE)), - kPasswordSavingRadioGroup); - passwords_asktosave_radio_->set_listener(this); - passwords_asktosave_radio_->SetMultiLine(true); - passwords_neversave_radio_ = new views::RadioButton( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_NEVERSAVE)), - kPasswordSavingRadioGroup); - passwords_neversave_radio_->set_listener(this); - passwords_neversave_radio_->SetMultiLine(true); - show_passwords_button_ = new views::NativeButton( - this, UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_SHOWPASSWORDS))); - - using views::GridLayout; - using views::ColumnSet; - - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_view_set_id); - layout->AddView(passwords_asktosave_radio_, 1, 1, - GridLayout::FILL, GridLayout::LEADING); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(passwords_neversave_radio_, 1, 1, - GridLayout::FILL, GridLayout::LEADING); - layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(show_passwords_button_); - - passwords_group_ = new OptionsGroupView( - contents, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_GROUP_NAME)), - L"", - true); -} - -void ContentPageView::InitFormAutofillGroup() { - change_autofill_settings_button_ = new views::NativeButton( - this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS))); - - using views::GridLayout; - using views::ColumnSet; - - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - const int fill_column_view_set_id = 0; - const int leading_column_view_set_id = 1; - ColumnSet* column_set = layout->AddColumnSet(fill_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - column_set = layout->AddColumnSet(leading_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, leading_column_view_set_id); - layout->AddView(change_autofill_settings_button_); - - form_autofill_group_ = new OptionsGroupView( - contents, - UTF16ToWide( - l10n_util::GetStringUTF16(IDS_AUTOFILL_SETTING_WINDOWS_GROUP_NAME)), - L"", true); -} - -void ContentPageView::InitThemesGroup() { - themes_reset_button_ = new views::NativeButton(this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_THEMES_RESET_BUTTON))); - themes_gallery_link_ = new views::Link( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_THEMES_GALLERY_BUTTON))); - themes_gallery_link_->SetController(this); - - using views::GridLayout; - using views::ColumnSet; - - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - const int double_column_view_set_id = 1; - ColumnSet* double_col_set = layout->AddColumnSet(double_column_view_set_id); - double_col_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - double_col_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - double_col_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, double_column_view_set_id); - layout->AddView(themes_reset_button_); - layout->AddView(themes_gallery_link_); - - themes_group_ = new OptionsGroupView( - contents, UTF16ToWide(l10n_util::GetStringUTF16(IDS_THEMES_GROUP_NAME)), - L"", false); -} - -void ContentPageView::InitBrowsingDataGroup() { - import_button_ = new views::NativeButton(this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_IMPORT_DATA_BUTTON))); - - using views::GridLayout; - using views::ColumnSet; - - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - // Add the browsing data import button. - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(import_button_); - - browsing_data_group_ = new OptionsGroupView( - contents, - UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_BROWSING_DATA_GROUP_NAME)), - L"", true); -} - -void ContentPageView::OnConfirmMessageAccept() { - sync_service_->DisableForUser(); - ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); -} - -void ContentPageView::InitSyncGroup() { - sync_status_label_ = new views::Label; - sync_status_label_->SetMultiLine(true); - sync_status_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - - sync_action_link_ = new views::Link(); - sync_action_link_->set_collapse_when_hidden(true); - sync_action_link_->SetController(this); - - privacy_dashboard_link_ = new views::Link(); - privacy_dashboard_link_->set_collapse_when_hidden(true); - privacy_dashboard_link_->SetController(this); - privacy_dashboard_link_->SetText(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_SYNC_PRIVACY_DASHBOARD_LINK_LABEL))); - - sync_start_stop_button_ = new views::NativeButton(this, std::wstring()); - sync_customize_button_ = new views::NativeButton(this, std::wstring()); - - using views::GridLayout; - using views::ColumnSet; - - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_view_set_id); - layout->AddView(sync_status_label_, 3, 1, - GridLayout::FILL, GridLayout::LEADING); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(sync_action_link_, 3, 1); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(sync_start_stop_button_); - layout->AddView(sync_customize_button_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(privacy_dashboard_link_, 3, 1); - - sync_group_ = new OptionsGroupView( - contents, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_OPTIONS_GROUP_NAME)), - std::wstring(), true); -} - -void ContentPageView::UpdateSyncControls() { - DCHECK(sync_service_); - std::wstring status_label; - std::wstring link_label; - std::wstring customize_button_label; - string16 button_label; - bool managed = sync_service_->IsManaged(); - bool sync_setup_completed = sync_service_->HasSyncSetupCompleted(); - bool status_has_error = sync_ui_util::GetStatusLabels(sync_service_, - &status_label, &link_label) == sync_ui_util::SYNC_ERROR; - customize_button_label = - UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL)); - if (sync_setup_completed) { - button_label = - l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); - } else if (sync_service_->SetupInProgress()) { - button_label = l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS); - } else { - button_label = l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); - } - - sync_status_label_->SetText(status_label); - sync_start_stop_button_->SetEnabled( - !sync_service_->WizardIsVisible() && !managed); - sync_start_stop_button_->SetLabel(UTF16ToWide(button_label)); - sync_customize_button_->SetLabel(customize_button_label); - sync_customize_button_->SetVisible(sync_setup_completed && !status_has_error); - sync_customize_button_->SetEnabled(!managed); - sync_action_link_->SetText(link_label); - sync_action_link_->SetVisible(!link_label.empty()); - sync_action_link_->SetEnabled(!managed); - - if (status_has_error) { - sync_status_label_->set_background(CreateErrorBackground()); - sync_action_link_->set_background(CreateErrorBackground()); - } else { - sync_status_label_->set_background(NULL); - sync_action_link_->set_background(NULL); - } -} diff --git a/chrome/browser/ui/views/options/content_page_view.h b/chrome/browser/ui/views/options/content_page_view.h deleted file mode 100644 index 1f811c4..0000000 --- a/chrome/browser/ui/views/options/content_page_view.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_PAGE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_PAGE_VIEW_H_ -#pragma once - -#include "chrome/browser/autofill/personal_data_manager.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/ui/views/confirm_message_box_dialog.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "views/controls/button/button.h" -#include "views/controls/link.h" -#include "views/view.h" - -namespace views { -class Checkbox; -class Label; -class NativeButton; -class RadioButton; -} -class FileDisplayArea; -class OptionsGroupView; -class PrefService; - -//////////////////////////////////////////////////////////////////////////////// -// ContentPageView - -class ContentPageView : public OptionsPageView, - public views::LinkController, - public ProfileSyncServiceObserver, - public views::ButtonListener, - public ConfirmMessageBoxObserver { - public: - explicit ContentPageView(Profile* profile); - virtual ~ContentPageView(); - - // views::ButtonListener implementation: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // views::LinkController method. - virtual void LinkActivated(views::Link* source, int event_flags); - - // ConfirmMessageBoxObserver implementation. - virtual void OnConfirmMessageAccept(); - - // ProfileSyncServiceObserver method. - virtual void OnStateChanged(); - - protected: - // OptionsPageView implementation: - virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::string* pref_name); - - // views::View overrides: - virtual void Layout(); - - private: - // Updates various sync controls based on the current sync state. - void UpdateSyncControls(); - - // Returns whether initialization of controls is done or not. - bool is_initialized() const { - // If initialization is already done, all the UI controls data members - // should be non-NULL. So check for one of them to determine if controls - // are already initialized or not. - return sync_group_ != NULL; - } - - // Init all the dialog controls. - void InitPasswordSavingGroup(); - void InitFormAutofillGroup(); - void InitBrowsingDataGroup(); - void InitThemesGroup(); - void InitSyncGroup(); - - // Controls for the Password Saving group - views::NativeButton* show_passwords_button_; - OptionsGroupView* passwords_group_; - views::RadioButton* passwords_asktosave_radio_; - views::RadioButton* passwords_neversave_radio_; - - // Controls for the Form Autofill group - views::NativeButton* change_autofill_settings_button_; - OptionsGroupView* form_autofill_group_; - - // Controls for the Themes group - OptionsGroupView* themes_group_; - views::NativeButton* themes_reset_button_; - views::Link* themes_gallery_link_; - - // Controls for the browsing data group. - OptionsGroupView* browsing_data_group_; - views::NativeButton* import_button_; - - // Controls for the Sync group. - OptionsGroupView* sync_group_; - views::Label* sync_status_label_; - views::Link* sync_action_link_; - views::NativeButton* sync_start_stop_button_; - views::NativeButton* sync_customize_button_; - views::Link* privacy_dashboard_link_; - - BooleanPrefMember ask_to_save_passwords_; - BooleanPrefMember form_autofill_enabled_; - StringPrefMember is_using_default_theme_; - - // Cached pointer to ProfileSyncService, if it exists. Kept up to date - // and NULL-ed out on destruction. - ProfileSyncService* sync_service_; - - DISALLOW_COPY_AND_ASSIGN(ContentPageView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_PAGE_VIEW_H_ diff --git a/chrome/browser/ui/views/options/content_settings_window_view.cc b/chrome/browser/ui/views/options/content_settings_window_view.cc deleted file mode 100644 index 30916cf..0000000 --- a/chrome/browser/ui/views/options/content_settings_window_view.cc +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/content_settings_window_view.h" - -#include "base/stl_util-inl.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/views/options/advanced_page_view.h" -#include "chrome/browser/ui/views/options/content_filter_page_view.h" -#include "chrome/browser/ui/views/options/cookie_filter_page_view.h" -#include "chrome/browser/ui/views/options/general_page_view.h" -#include "chrome/browser/ui/views/options/plugin_filter_page_view.h" -#include "chrome/common/chrome_constants.h" -#include "chrome/common/pref_names.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "views/controls/label.h" -#include "views/widget/root_view.h" -#include "views/window/dialog_delegate.h" -#include "views/window/window.h" - -static ContentSettingsWindowView* instance_ = NULL; -// Content setting dialog bounds padding. -const int kDialogPadding = 7; - -namespace browser { - -// Declared in browser_dialogs.h so others don't have to depend on our header. -void ShowContentSettingsWindow(gfx::NativeWindow parent_window, - ContentSettingsType content_type, - Profile* profile) { - DCHECK(profile); - // If there's already an existing options window, activate it and switch to - // the specified page. - // TODO(beng): note this is not multi-simultaneous-profile-safe. When we care - // about this case this will have to be fixed. - if (!instance_) { - instance_ = new ContentSettingsWindowView(profile); - views::Window::CreateChromeWindow(parent_window, gfx::Rect(), instance_); - } - instance_->ShowContentSettingsTab(content_type); -} - -} // namespace browser - -ContentSettingsWindowView::ContentSettingsWindowView(Profile* profile) - // Always show preferences for the original profile. Most state when off - // the record comes from the original profile, but we explicitly use - // the original profile to avoid potential problems. - : profile_(profile->GetOriginalProfile()), - label_(NULL), - listbox_(NULL), - current_page_(0) { - // We don't need to observe changes in this value. - last_selected_page_.Init(prefs::kContentSettingsWindowLastTabIndex, - profile->GetPrefs(), NULL); -} - -ContentSettingsWindowView::~ContentSettingsWindowView() { - STLDeleteElements(&pages_); -} - -void ContentSettingsWindowView::ShowContentSettingsTab( - ContentSettingsType page) { - // This will show invisible windows and bring visible windows to the front. - window()->Show(); - - if (page == CONTENT_SETTINGS_TYPE_DEFAULT) { - // Remember the last visited page from local state. - page = static_cast<ContentSettingsType>(last_selected_page_.GetValue()); - if (page == CONTENT_SETTINGS_TYPE_DEFAULT) - page = CONTENT_SETTINGS_TYPE_COOKIES; - } - // If the page number is out of bounds, reset to the first tab. - if (page < 0 || page >= listbox_->GetRowCount()) - page = CONTENT_SETTINGS_TYPE_COOKIES; - - listbox_->SelectRow(static_cast<int>(page)); - ShowSettingsPage(listbox_->SelectedRow()); -} - -/////////////////////////////////////////////////////////////////////////////// -// ContentSettingsWindowView, views::DialogDelegate implementation: - -std::wstring ContentSettingsWindowView::GetWindowTitle() const { - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CONTENT_SETTINGS_TITLE)); -} - -void ContentSettingsWindowView::WindowClosing() { - instance_ = NULL; -} - -bool ContentSettingsWindowView::Cancel() { - return GetCurrentContentSettingsTabView()->CanClose(); -} - -views::View* ContentSettingsWindowView::GetContentsView() { - return this; -} - -/////////////////////////////////////////////////////////////////////////////// -// ContentSettingsWindowView, views::Listbox::Listener implementation: - -void ContentSettingsWindowView::ListboxSelectionChanged( - views::Listbox* sender) { - DCHECK_EQ(listbox_, sender); - ShowSettingsPage(listbox_->SelectedRow()); - last_selected_page_.SetValue(current_page_); -} - -/////////////////////////////////////////////////////////////////////////////// -// ContentSettingsWindowView, views::View overrides: - -void ContentSettingsWindowView::Layout() { - int listbox_width = views::Window::GetLocalizedContentsWidth( - IDS_CONTENT_SETTINGS_DIALOG_LISTBOX_WIDTH_CHARS); - label_->SetBounds(kDialogPadding, - kDialogPadding, - listbox_width, - label_->GetPreferredSize().height()); - - listbox_->SetBounds(kDialogPadding, - 2 * kDialogPadding + label_->height(), - listbox_width, - height() - (3 * kDialogPadding) - label_->height()); - - if (pages_[current_page_]->parent()) { - pages_[current_page_]->SetBounds( - 2 * kDialogPadding + listbox_width, - 2 * kDialogPadding + label_->height(), - width() - (3 * kDialogPadding) - listbox_width, - height() - (2 * kDialogPadding)); - } -} - -gfx::Size ContentSettingsWindowView::GetPreferredSize() { - return gfx::Size(views::Window::GetLocalizedContentsSize( - IDS_CONTENT_SETTINGS_DIALOG_WIDTH_CHARS, - IDS_CONTENT_SETTINGS_DIALOG_HEIGHT_LINES)); -} - -void ContentSettingsWindowView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - // Can't init before we're inserted into a Container, because we require a - // HWND to parent native child controls to. - if (is_add && child == this) - Init(); -} - -/////////////////////////////////////////////////////////////////////////////// -// ContentSettingsWindowView, private: - -void ContentSettingsWindowView::Init() { - // Make sure we don't leak memory by calling this twice. - DCHECK(!listbox_); - - label_ = new views::Label( - l10n_util::GetStringUTF16(IDS_CONTENT_SETTINGS_FEATURES_LABEL)); - label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - AddChildView(label_); - - pages_.push_back(new CookieFilterPageView(profile_)); - pages_.push_back( - new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_IMAGES)); - pages_.push_back( - new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_JAVASCRIPT)); - pages_.push_back(new PluginFilterPageView(profile_)); - pages_.push_back( - new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_POPUPS)); - pages_.push_back( - new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_GEOLOCATION)); - pages_.push_back( - new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); - for (size_t i = 0; i < pages_.size(); ++i) { - pages_[i]->set_parent_owned(false); - } - DCHECK_EQ(static_cast<int>(pages_.size()), CONTENT_SETTINGS_NUM_TYPES); - - std::vector<string16> strings; - strings.push_back(l10n_util::GetStringUTF16(IDS_COOKIES_TAB_LABEL)); - strings.push_back(l10n_util::GetStringUTF16(IDS_IMAGES_TAB_LABEL)); - strings.push_back(l10n_util::GetStringUTF16(IDS_JAVASCRIPT_TAB_LABEL)); - strings.push_back(l10n_util::GetStringUTF16(IDS_PLUGIN_TAB_LABEL)); - strings.push_back(l10n_util::GetStringUTF16(IDS_POPUP_TAB_LABEL)); - strings.push_back(l10n_util::GetStringUTF16(IDS_GEOLOCATION_TAB_LABEL)); - strings.push_back(l10n_util::GetStringUTF16(IDS_NOTIFICATIONS_TAB_LABEL)); - listbox_ = new views::Listbox(strings, this); - AddChildView(listbox_); - CHECK_EQ(strings.size(), pages_.size()); -} - -void ContentSettingsWindowView::ShowSettingsPage(int page) { - if (pages_[current_page_]->parent()) - RemoveChildView(pages_[current_page_]); - current_page_ = page; - AddChildView(pages_[current_page_]); - Layout(); - SchedulePaint(); -} - -const OptionsPageView* - ContentSettingsWindowView::GetCurrentContentSettingsTabView() const { - return static_cast<OptionsPageView*>(pages_[current_page_]); -} diff --git a/chrome/browser/ui/views/options/content_settings_window_view.h b/chrome/browser/ui/views/options/content_settings_window_view.h deleted file mode 100644 index 077aa50..0000000 --- a/chrome/browser/ui/views/options/content_settings_window_view.h +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_SETTINGS_WINDOW_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_SETTINGS_WINDOW_VIEW_H_ -#pragma once - -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/common/content_settings_types.h" -#include "views/controls/listbox/listbox.h" -#include "views/view.h" -#include "views/window/dialog_delegate.h" - -class Profile; -class MessageLoop; -class OptionsPageView; - -namespace views { -class Label; -} // namespace views - -/////////////////////////////////////////////////////////////////////////////// -// ContentSettingsWindowView -// -// The contents of the Options dialog window. -// -class ContentSettingsWindowView : public views::View, - public views::DialogDelegate, - public views::Listbox::Listener { - public: - explicit ContentSettingsWindowView(Profile* profile); - virtual ~ContentSettingsWindowView(); - - // Shows the Tab corresponding to the specified Content Settings page. - void ShowContentSettingsTab(ContentSettingsType page); - - protected: - // views::View overrides: - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - // views::DialogDelegate implementation: - virtual int GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_CANCEL; - } - virtual std::wstring GetWindowTitle() const; - virtual void WindowClosing(); - virtual bool Cancel(); - virtual views::View* GetContentsView(); - - // views::Listbox::Listener implementation: - virtual void ListboxSelectionChanged(views::Listbox* sender); - - private: - // Initializes the view. - void Init(); - - // Makes |pages_[page]| the currently visible page. - void ShowSettingsPage(int page); - - // Returns the currently selected OptionsPageView. - const OptionsPageView* GetCurrentContentSettingsTabView() const; - - // The Profile associated with these options. - Profile* profile_; - - // The label above the left box. - views::Label* label_; - - // The listbox used to select a page. - views::Listbox* listbox_; - - // The last page the user was on when they opened the Options window. - IntegerPrefMember last_selected_page_; - - // Stores the index of the currently visible page. - int current_page_; - - // Stores the possible content pages displayed on the right. - // |pages_[current_page_]| is the currently displayed page, and it's the only - // parented View in |pages_|. - std::vector<View*> pages_; - - DISALLOW_COPY_AND_ASSIGN(ContentSettingsWindowView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_CONTENT_SETTINGS_WINDOW_VIEW_H_ - diff --git a/chrome/browser/ui/views/options/cookie_filter_page_view.cc b/chrome/browser/ui/views/options/cookie_filter_page_view.cc deleted file mode 100644 index de29ea3..0000000 --- a/chrome/browser/ui/views/options/cookie_filter_page_view.cc +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/cookie_filter_page_view.h" - -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/options/show_options_url.h" -#include "chrome/browser/ui/views/options/cookies_view.h" -#include "chrome/common/pref_names.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "views/controls/button/checkbox.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" - -CookieFilterPageView::CookieFilterPageView(Profile* profile) - : ContentFilterPageView(profile, CONTENT_SETTINGS_TYPE_COOKIES), - block_3rdparty_check_(NULL), - clear_on_close_check_(NULL), - show_cookies_button_(NULL) { - clear_site_data_on_exit_.Init(prefs::kClearSiteDataOnExit, - profile->GetPrefs(), NULL); - block_third_party_cookies_.Init(prefs::kBlockThirdPartyCookies, - profile->GetPrefs(), this); -} - -CookieFilterPageView::~CookieFilterPageView() { -} - -/////////////////////////////////////////////////////////////////////////////// -// CookieFilterPageView, ContentFilterPageView override: - -void CookieFilterPageView::InitControlLayout() { - ContentFilterPageView::InitControlLayout(); - - using views::GridLayout; - - GridLayout* layout = static_cast<GridLayout*>(GetLayoutManager()); - const int single_column_set_id = 0; - layout->AddPaddingRow(0, views::kUnrelatedControlLargeVerticalSpacing); - - block_3rdparty_check_ = new views::Checkbox(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX))); - block_3rdparty_check_->set_listener(this); - - layout->StartRow(0, single_column_set_id); - layout->AddView(block_3rdparty_check_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - // Now that this has been added to the view hierarchy, it's safe to call - // SetChecked() on it. - block_3rdparty_check_->SetChecked( - profile()->GetHostContentSettingsMap()->BlockThirdPartyCookies()); - - clear_on_close_check_ = new views::Checkbox(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX))); - clear_on_close_check_->SetMultiLine(true); - clear_on_close_check_->set_listener(this); - - layout->StartRow(0, single_column_set_id); - layout->AddView(clear_on_close_check_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - show_cookies_button_ = new views::NativeButton(this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_COOKIES_SHOW_COOKIES_BUTTON))); - - layout->StartRow(0, single_column_set_id); - layout->AddView(show_cookies_button_, 1, 1, GridLayout::LEADING, - GridLayout::FILL); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - views::Link* flash_settings_link = new views::Link( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_FLASH_STORAGE_SETTINGS))); - flash_settings_link->SetController(this); - - layout->StartRow(0, single_column_set_id); - layout->AddView(flash_settings_link, 1, 1, GridLayout::LEADING, - GridLayout::FILL); -} - -/////////////////////////////////////////////////////////////////////////////// -// CookieFilterPageView, OptionsPageView implementation: - -void CookieFilterPageView::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || *pref_name == prefs::kClearSiteDataOnExit) { - clear_on_close_check_->SetChecked( - clear_site_data_on_exit_.GetValue()); - clear_on_close_check_->SetEnabled( - !clear_site_data_on_exit_.IsManaged()); - } - if (!pref_name || *pref_name == prefs::kBlockThirdPartyCookies) { - block_3rdparty_check_->SetChecked( - block_third_party_cookies_.GetValue()); - block_3rdparty_check_->SetEnabled( - !block_third_party_cookies_.IsManaged()); - } -} - -/////////////////////////////////////////////////////////////////////////////// -// CookieFilterPageView, views::ButtonListener implementation: - -void CookieFilterPageView::ButtonPressed(views::Button* sender, - const views::Event& event) { - HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); - if (sender == block_3rdparty_check_) { - settings_map->SetBlockThirdPartyCookies(block_3rdparty_check_->checked()); - } else if (sender == clear_on_close_check_) { - clear_site_data_on_exit_.SetValue(clear_on_close_check_->checked()); - } else if (sender == show_cookies_button_) { - UserMetricsRecordAction(UserMetricsAction("Options_ShowCookies"), NULL); - CookiesView::ShowCookiesWindow(profile()); - } else { - ContentFilterPageView::ButtonPressed(sender, event); - } -} - -/////////////////////////////////////////////////////////////////////////////// -// CookieFilterPageView, views::LinkController implementation: - -void CookieFilterPageView::LinkActivated(views::Link* source, int event_flags) { - browser::ShowOptionsURL( - profile(), - GURL(l10n_util::GetStringUTF8(IDS_FLASH_STORAGE_URL))); -} diff --git a/chrome/browser/ui/views/options/cookie_filter_page_view.h b/chrome/browser/ui/views/options/cookie_filter_page_view.h deleted file mode 100644 index c0d9445c..0000000 --- a/chrome/browser/ui/views/options/cookie_filter_page_view.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_COOKIE_FILTER_PAGE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_COOKIE_FILTER_PAGE_VIEW_H_ -#pragma once - -#include "chrome/browser/ui/views/options/content_filter_page_view.h" - -#include "chrome/browser/prefs/pref_member.h" - -namespace views { -class Checkbox; -} - -//////////////////////////////////////////////////////////////////////////////// -// CookieFilterPageView class is used to render the cookie content settings tab. - -class CookieFilterPageView : public ContentFilterPageView, - public views::LinkController { - public: - explicit CookieFilterPageView(Profile* profile); - virtual ~CookieFilterPageView(); - - private: - // Overridden from ContentFilterPageView: - virtual void InitControlLayout(); - - // OptionsPageView implementation: - virtual void NotifyPrefChanged(const std::string* pref_name); - - // views::ButtonListener implementation: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // Overridden from views::LinkController: - virtual void LinkActivated(views::Link* source, int event_flags); - - private: - // Controls for the cookie filter tab page view. - views::Checkbox* block_3rdparty_check_; - views::Checkbox* clear_on_close_check_; - views::NativeButton* show_cookies_button_; - - // Clear locally stored site data on exit pref. - BooleanPrefMember clear_site_data_on_exit_; - - // Block all third party cookies. - BooleanPrefMember block_third_party_cookies_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(CookieFilterPageView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_COOKIE_FILTER_PAGE_VIEW_H_ - diff --git a/chrome/browser/ui/views/options/cookies_view.cc b/chrome/browser/ui/views/options/cookies_view.cc deleted file mode 100644 index c29cf74..0000000 --- a/chrome/browser/ui/views/options/cookies_view.cc +++ /dev/null @@ -1,412 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/cookies_view.h" - -#include <algorithm> - -#include "base/message_loop.h" -#include "base/string_util.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/views/appcache_info_view.h" -#include "chrome/browser/ui/views/cookie_info_view.h" -#include "chrome/browser/ui/views/database_info_view.h" -#include "chrome/browser/ui/views/indexed_db_info_view.h" -#include "chrome/browser/ui/views/local_storage_info_view.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "net/base/cookie_monster.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/color_utils.h" -#include "views/border.h" -#include "views/controls/button/native_button.h" -#include "views/controls/label.h" -#include "views/controls/textfield/textfield.h" -#include "views/controls/tree/tree_view.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" - -// static -views::Window* CookiesView::instance_ = NULL; -static const int kSearchFilterDelayMs = 500; - -/////////////////////////////////////////////////////////////////////////////// -// CookiesTreeView -// Overridden to handle Delete key presses - -class CookiesTreeView : public views::TreeView { - public: - explicit CookiesTreeView(CookiesTreeModel* cookies_model); - virtual ~CookiesTreeView() {} - - // Removes the items associated with the selected node in the TreeView - void RemoveSelectedItems(); - - private: - DISALLOW_COPY_AND_ASSIGN(CookiesTreeView); -}; - -CookiesTreeView::CookiesTreeView(CookiesTreeModel* cookies_model) { - SetModel(cookies_model); - SetRootShown(false); - SetEditable(false); -} - -void CookiesTreeView::RemoveSelectedItems() { - ui::TreeModelNode* selected_node = GetSelectedNode(); - if (selected_node) { - static_cast<CookiesTreeModel*>(model())->DeleteCookieNode( - static_cast<CookieTreeNode*>(GetSelectedNode())); - } -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiesView::InfoPanelView -// Overridden to handle layout of the various info views. -// -// This view is a child of the CookiesView and participates -// in its GridLayout. The various info views are all children -// of this view. Only one child is expected to be visible at a time. - -class CookiesView::InfoPanelView : public views::View { - public: - virtual void Layout() { - for (int i = 0; i < child_count(); ++i) - GetChildViewAt(i)->SetBounds(0, 0, width(), height()); - } - - virtual gfx::Size GetPreferredSize() { - DCHECK(has_children()); - return GetChildViewAt(0)->GetPreferredSize(); - } -}; - -/////////////////////////////////////////////////////////////////////////////// -// CookiesView, public: - -// static -void CookiesView::ShowCookiesWindow(Profile* profile) { - if (!instance_) { - CookiesView* cookies_view = new CookiesView(profile); - instance_ = views::Window::CreateChromeWindow( - NULL, gfx::Rect(), cookies_view); - } - if (!instance_->IsVisible()) { - instance_->Show(); - } else { - instance_->Activate(); - } -} - -CookiesView::~CookiesView() { - cookies_tree_->SetModel(NULL); -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiesView, TreeModelObserver overrides: - -void CookiesView::TreeNodesAdded(ui::TreeModel* model, - ui::TreeModelNode* parent, - int start, - int count) { - UpdateRemoveButtonsState(); -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiesView, views::Buttonlistener implementation: - -void CookiesView::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender == remove_button_) { - cookies_tree_->RemoveSelectedItems(); - if (cookies_tree_model_->GetRoot()->child_count() == 0) - UpdateForEmptyState(); - } else if (sender == remove_all_button_) { - cookies_tree_model_->DeleteAllStoredObjects(); - UpdateForEmptyState(); - } else if (sender == clear_search_button_) { - ResetSearchQuery(); - } -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiesView, views::TextfieldController implementation: - -void CookiesView::ContentsChanged(views::Textfield* sender, - const std::wstring& new_contents) { - clear_search_button_->SetEnabled(!search_field_->text().empty()); - search_update_factory_.RevokeAll(); - MessageLoop::current()->PostDelayedTask(FROM_HERE, - search_update_factory_.NewRunnableMethod( - &CookiesView::UpdateSearchResults), kSearchFilterDelayMs); -} - -bool CookiesView::HandleKeyEvent(views::Textfield* sender, - const views::KeyEvent& key_event) { - if (key_event.key_code() == ui::VKEY_ESCAPE) { - ResetSearchQuery(); - } else if (key_event.key_code() == ui::VKEY_RETURN) { - search_update_factory_.RevokeAll(); - UpdateSearchResults(); - } - return false; -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiesView, views::DialogDelegate implementation: - -int CookiesView::GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_CANCEL; -} - -views::View* CookiesView::GetInitiallyFocusedView() { - return search_field_; -} - -bool CookiesView::CanResize() const { - return true; -} - -std::wstring CookiesView::GetWindowTitle() const { - return UTF16ToWide( - l10n_util::GetStringUTF16(IDS_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE)); -} - -void CookiesView::WindowClosing() { - instance_ = NULL; -} - -views::View* CookiesView::GetContentsView() { - return this; -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiesView, views::View overrides: - -void CookiesView::Layout() { - // Lay out the Remove/Remove All buttons in the parent view. - gfx::Size ps = remove_button_->GetPreferredSize(); - gfx::Rect parent_bounds = parent()->GetContentsBounds(); - int y_buttons = - parent_bounds.bottom() - ps.height() - views::kButtonVEdgeMargin; - - remove_button_->SetBounds(views::kPanelHorizMargin, y_buttons, ps.width(), - ps.height()); - - ps = remove_all_button_->GetPreferredSize(); - int remove_all_x = remove_button_->x() + remove_button_->width() + - views::kRelatedControlHorizontalSpacing; - remove_all_button_->SetBounds(remove_all_x, y_buttons, ps.width(), - ps.height()); - - // Lay out this View - View::Layout(); -} - -gfx::Size CookiesView::GetPreferredSize() { - return gfx::Size(views::Window::GetLocalizedContentsSize( - IDS_COOKIES_DIALOG_WIDTH_CHARS, - IDS_COOKIES_DIALOG_HEIGHT_LINES)); -} - -void CookiesView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (is_add && child == this) - Init(); -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiesView, views::TreeViewController overrides: - -void CookiesView::OnTreeViewSelectionChanged(views::TreeView* tree_view) { - UpdateRemoveButtonsState(); - CookieTreeNode::DetailedInfo detailed_info = - static_cast<CookieTreeNode*>(tree_view->GetSelectedNode())-> - GetDetailedInfo(); - if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { - UpdateVisibleDetailedInfo(cookie_info_view_); - cookie_info_view_->SetCookie(detailed_info.cookie->Domain(), - *detailed_info.cookie); - } else if (detailed_info.node_type == - CookieTreeNode::DetailedInfo::TYPE_DATABASE) { - UpdateVisibleDetailedInfo(database_info_view_); - database_info_view_->SetDatabaseInfo(*detailed_info.database_info); - } else if (detailed_info.node_type == - CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) { - UpdateVisibleDetailedInfo(local_storage_info_view_); - local_storage_info_view_->SetLocalStorageInfo( - *detailed_info.local_storage_info); - } else if (detailed_info.node_type == - CookieTreeNode::DetailedInfo::TYPE_APPCACHE) { - UpdateVisibleDetailedInfo(appcache_info_view_); - appcache_info_view_->SetAppCacheInfo(detailed_info.appcache_info); - } else if (detailed_info.node_type == - CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB) { - UpdateVisibleDetailedInfo(indexed_db_info_view_); - indexed_db_info_view_->SetIndexedDBInfo(*detailed_info.indexed_db_info); - } else { - UpdateVisibleDetailedInfo(cookie_info_view_); - cookie_info_view_->ClearCookieDisplay(); - } -} - -void CookiesView::OnTreeViewKeyDown(ui::KeyboardCode keycode) { - if (keycode == ui::VKEY_DELETE) - cookies_tree_->RemoveSelectedItems(); -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiesView, public: - -void CookiesView::UpdateSearchResults() { - cookies_tree_model_->UpdateSearchResults(search_field_->text()); - UpdateRemoveButtonsState(); -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiesView, private: - -CookiesView::CookiesView(Profile* profile) - : - search_label_(NULL), - search_field_(NULL), - clear_search_button_(NULL), - description_label_(NULL), - cookies_tree_(NULL), - info_panel_(NULL), - cookie_info_view_(NULL), - database_info_view_(NULL), - local_storage_info_view_(NULL), - appcache_info_view_(NULL), - indexed_db_info_view_(NULL), - remove_button_(NULL), - remove_all_button_(NULL), - profile_(profile), - ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) { -} - -void CookiesView::Init() { - search_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_COOKIES_SEARCH_LABEL))); - search_field_ = new views::Textfield; - search_field_->SetController(this); - clear_search_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_COOKIES_CLEAR_SEARCH_LABEL))); - clear_search_button_->SetEnabled(false); - description_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_COOKIES_INFO_LABEL))); - description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - cookies_tree_model_.reset(new CookiesTreeModel( - profile_->GetRequestContext()->GetCookieStore()->GetCookieMonster(), - new BrowsingDataDatabaseHelper(profile_), - new BrowsingDataLocalStorageHelper(profile_), - NULL, - new BrowsingDataAppCacheHelper(profile_), - BrowsingDataIndexedDBHelper::Create(profile_))); - cookies_tree_model_->AddCookiesTreeObserver(this); - - info_panel_ = new InfoPanelView; - cookie_info_view_ = new CookieInfoView(false); - database_info_view_ = new DatabaseInfoView; - local_storage_info_view_ = new LocalStorageInfoView; - appcache_info_view_ = new AppCacheInfoView; - indexed_db_info_view_ = new IndexedDBInfoView; - info_panel_->AddChildView(cookie_info_view_); - info_panel_->AddChildView(database_info_view_); - info_panel_->AddChildView(local_storage_info_view_); - info_panel_->AddChildView(appcache_info_view_); - info_panel_->AddChildView(indexed_db_info_view_); - - cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get()); - remove_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_COOKIES_REMOVE_LABEL))); - remove_all_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_COOKIES_REMOVE_ALL_LABEL))); - - using views::GridLayout; - using views::ColumnSet; - - GridLayout* layout = GridLayout::CreatePanel(this); - SetLayoutManager(layout); - - const int five_column_layout_id = 0; - ColumnSet* column_set = layout->AddColumnSet(five_column_layout_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, - GridLayout::USE_PREF, 0, 0); - - const int single_column_layout_id = 1; - column_set = layout->AddColumnSet(single_column_layout_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, five_column_layout_id); - layout->AddView(search_label_); - layout->AddView(search_field_); - layout->AddView(clear_search_button_); - layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); - - layout->StartRow(0, single_column_layout_id); - layout->AddView(description_label_); - - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(1, single_column_layout_id); - cookies_tree_->set_lines_at_root(true); - cookies_tree_->set_auto_expand_children(true); - layout->AddView(cookies_tree_); - - cookies_tree_->SetController(this); - - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_layout_id); - layout->AddView(info_panel_); - - // Add the Remove/Remove All buttons to the ClientView - parent()->AddChildView(remove_button_); - parent()->AddChildView(remove_all_button_); - if (!cookies_tree_model_.get()->GetRoot()->child_count()) { - UpdateForEmptyState(); - } else { - UpdateVisibleDetailedInfo(cookie_info_view_); - UpdateRemoveButtonsState(); - } -} - -void CookiesView::ResetSearchQuery() { - search_field_->SetText(std::wstring()); - clear_search_button_->SetEnabled(false); - UpdateSearchResults(); -} - -void CookiesView::UpdateForEmptyState() { - cookie_info_view_->ClearCookieDisplay(); - remove_button_->SetEnabled(false); - remove_all_button_->SetEnabled(false); - UpdateVisibleDetailedInfo(cookie_info_view_); -} - -void CookiesView::UpdateRemoveButtonsState() { - remove_button_->SetEnabled(cookies_tree_model_->GetRoot()-> - GetTotalNodeCount() > 1 && cookies_tree_->GetSelectedNode()); - remove_all_button_->SetEnabled(cookies_tree_model_->GetRoot()-> - GetTotalNodeCount() > 1); -} - -void CookiesView::UpdateVisibleDetailedInfo(views::View* view) { - cookie_info_view_->SetVisible(view == cookie_info_view_); - database_info_view_->SetVisible(view == database_info_view_); - local_storage_info_view_->SetVisible(view == local_storage_info_view_); - appcache_info_view_->SetVisible(view == appcache_info_view_); - indexed_db_info_view_->SetVisible(view == indexed_db_info_view_); -} diff --git a/chrome/browser/ui/views/options/cookies_view.h b/chrome/browser/ui/views/options/cookies_view.h deleted file mode 100644 index 52fca4e..0000000 --- a/chrome/browser/ui/views/options/cookies_view.h +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_COOKIES_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_COOKIES_VIEW_H_ -#pragma once - -#include <string> - -#include "base/task.h" -#include "chrome/browser/cookies_tree_model.h" -#include "net/base/cookie_monster.h" -#include "views/controls/button/button.h" -#include "views/controls/textfield/textfield_controller.h" -#include "views/controls/tree/tree_view.h" -#include "views/view.h" -#include "views/window/dialog_delegate.h" -#include "views/window/window.h" - -class AppCacheInfoView; -class CookieInfoView; -class CookiesTreeView; -class DatabaseInfoView; -class IndexedDBInfoView; -class LocalStorageInfoView; -class Profile; -class Timer; - -namespace ui { -class TreeModel; -class TreeModelNode; -} // namespace ui - -namespace views { -class Label; -class NativeButton; -} // namespace views - -class CookiesView : public CookiesTreeModel::Observer, - public views::View, - public views::DialogDelegate, - public views::ButtonListener, - public views::TreeViewController, - public views::TextfieldController { - public: - // Show the Cookies Window, creating one if necessary. - static void ShowCookiesWindow(Profile* profile); - - virtual ~CookiesView(); - - // Updates the display to show only the search results. - void UpdateSearchResults(); - - // Begin TreeModelObserver implementation. - virtual void TreeNodesAdded(ui::TreeModel* model, - ui::TreeModelNode* parent, - int start, - int count); - virtual void TreeNodesRemoved(ui::TreeModel* model, - ui::TreeModelNode* parent, - int start, - int count) {} - virtual void TreeNodeChanged(ui::TreeModel* model, ui::TreeModelNode* node) {} - // End TreeModelObserver implementation. - - // views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // views::TreeViewController: - virtual void OnTreeViewSelectionChanged(views::TreeView* tree_view); - virtual void OnTreeViewKeyDown(ui::KeyboardCode keycode); - - // views::TextfieldController: - virtual void ContentsChanged(views::Textfield* sender, - const std::wstring& new_contents); - virtual bool HandleKeyEvent(views::Textfield* sender, - const views::KeyEvent& key); - - // views::WindowDelegate: - virtual int GetDialogButtons() const; - virtual views::View* GetInitiallyFocusedView(); - virtual bool CanResize() const; - virtual std::wstring GetWindowTitle() const; - virtual void WindowClosing(); - virtual views::View* GetContentsView(); - - // views::View: - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - protected: - // views::View: - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - private: - class InfoPanelView; - - // Use the static factory method to show. - explicit CookiesView(Profile* profile); - - // Initialize the dialog contents and layout. - void Init(); - - // Resets the display to what it would be if there were no search query. - void ResetSearchQuery(); - - // Update the UI when there are no cookies. - void UpdateForEmptyState(); - - // Enable or disable the remove and remove all buttons. - void UpdateRemoveButtonsState(); - - // Updates view to be visible inside detailed_info_view_; - void UpdateVisibleDetailedInfo(views::View* view); - - // Assorted dialog controls - views::Label* search_label_; - views::Textfield* search_field_; - views::NativeButton* clear_search_button_; - views::Label* description_label_; - CookiesTreeView* cookies_tree_; - InfoPanelView* info_panel_; - CookieInfoView* cookie_info_view_; - DatabaseInfoView* database_info_view_; - LocalStorageInfoView* local_storage_info_view_; - AppCacheInfoView* appcache_info_view_; - IndexedDBInfoView* indexed_db_info_view_; - views::NativeButton* remove_button_; - views::NativeButton* remove_all_button_; - - // The Cookies Tree model - scoped_ptr<CookiesTreeModel> cookies_tree_model_; - - // The Profile for which Cookies are displayed - Profile* profile_; - - // A factory to construct Runnable Methods so that we can be called back to - // re-evaluate the model after the search query string changes. - ScopedRunnableMethodFactory<CookiesView> search_update_factory_; - - // Our containing window. If this is non-NULL there is a visible Cookies - // window somewhere. - static views::Window* instance_; - - DISALLOW_COPY_AND_ASSIGN(CookiesView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_COOKIES_VIEW_H_ diff --git a/chrome/browser/ui/views/options/exception_editor_view.cc b/chrome/browser/ui/views/options/exception_editor_view.cc deleted file mode 100644 index f027572..0000000 --- a/chrome/browser/ui/views/options/exception_editor_view.cc +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/exception_editor_view.h" - -#include "base/utf_string_conversions.h" -#include "chrome/browser/content_exceptions_table_model.h" -#include "googleurl/src/url_canon.h" -#include "googleurl/src/url_parse.h" -#include "grit/app_resources.h" -#include "grit/generated_resources.h" -#include "grit/theme_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/textfield/textfield.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" -#include "views/window/window.h" - -ExceptionEditorView::ExceptionEditorView( - Delegate* delegate, - ContentExceptionsTableModel* model, - bool allow_off_the_record, - int index, - const ContentSettingsPattern& pattern, - ContentSetting setting, - bool is_off_the_record) - : delegate_(delegate), - model_(model), - cb_model_(model->content_type()), - allow_off_the_record_(allow_off_the_record), - index_(index), - pattern_(pattern), - setting_(setting), - is_off_the_record_(is_off_the_record) { - // Geolocation exceptions are handled by SimpleContentExceptionsView. - DCHECK_NE(setting_, CONTENT_SETTINGS_TYPE_GEOLOCATION); - // Notification exceptions are handled by SimpleContentExceptionsView. - DCHECK_NE(setting_, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); - Init(); -} - -void ExceptionEditorView::Show(gfx::NativeWindow parent) { - views::Window* window = - views::Window::CreateChromeWindow(parent, gfx::Rect(), this); - window->Show(); - GetDialogClientView()->UpdateDialogButtons(); - pattern_tf_->SelectAll(); - pattern_tf_->RequestFocus(); -} - -bool ExceptionEditorView::IsModal() const { - return true; -} - -std::wstring ExceptionEditorView::GetWindowTitle() const { - if (is_new()) - return UTF16ToWide( - l10n_util::GetStringUTF16(IDS_EXCEPTION_EDITOR_NEW_TITLE)); - - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXCEPTION_EDITOR_TITLE)); -} - -bool ExceptionEditorView::IsDialogButtonEnabled( - MessageBoxFlags::DialogButton button) const { - if (button == MessageBoxFlags::DIALOGBUTTON_OK) { - return IsPatternValid(ContentSettingsPattern( - UTF16ToUTF8(pattern_tf_->text())), - incognito_cb_->checked()); - } - return true; -} - -bool ExceptionEditorView::Cancel() { - return true; -} - -bool ExceptionEditorView::Accept() { - ContentSettingsPattern new_pattern(UTF16ToUTF8(pattern_tf_->text())); - ContentSetting setting = - cb_model_.SettingForIndex(action_cb_->selected_item()); - bool is_off_the_record = incognito_cb_->checked(); - delegate_->AcceptExceptionEdit( - new_pattern, setting, is_off_the_record, index_, is_new()); - return true; -} - -views::View* ExceptionEditorView::GetContentsView() { - return this; -} - -void ExceptionEditorView::ContentsChanged(views::Textfield* sender, - const std::wstring& new_contents) { - GetDialogClientView()->UpdateDialogButtons(); - UpdateImageView(pattern_iv_, IsPatternValid(ContentSettingsPattern( - UTF16ToUTF8(pattern_tf_->text())), incognito_cb_->checked())); -} - -bool ExceptionEditorView::HandleKeyEvent(views::Textfield* sender, - const views::KeyEvent& key_event) { - return false; -} - -void ExceptionEditorView::Init() { - using views::GridLayout; - - pattern_tf_ = new views::Textfield(); - pattern_tf_->SetText(UTF8ToUTF16(pattern_.AsString())); - pattern_tf_->SetController(this); - - pattern_iv_ = new views::ImageView; - - UpdateImageView(pattern_iv_, IsPatternValid(ContentSettingsPattern( - UTF16ToUTF8(pattern_tf_->text())), is_off_the_record_)); - - action_cb_ = new views::Combobox(&cb_model_); - if (!is_new()) - action_cb_->SetSelectedItem(cb_model_.IndexForSetting(setting_)); - - incognito_cb_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXCEPTION_EDITOR_OTR_TITLE))); - incognito_cb_->SetChecked(is_off_the_record_); - - GridLayout* layout = GridLayout::CreatePanel(this); - SetLayoutManager(layout); - - // For the Textfields. - views::ColumnSet* column_set = layout->AddColumnSet(1); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - // Add the contents. - layout->StartRow(0, 1); - layout->AddView(CreateLabel(IDS_EXCEPTION_EDITOR_PATTERN_TITLE)); - layout->AddView(pattern_tf_); - layout->AddView(pattern_iv_); - - layout->StartRowWithPadding(0, 1, 0, views::kRelatedControlVerticalSpacing); - layout->AddView(CreateLabel(IDS_EXCEPTION_EDITOR_ACTION_TITLE)); - layout->AddView(action_cb_); - - if (allow_off_the_record_) { - layout->StartRowWithPadding(0, 1, 0, views::kRelatedControlVerticalSpacing); - layout->AddView(incognito_cb_, 3, 1, GridLayout::FILL, GridLayout::FILL); - } -} - -views::Label* ExceptionEditorView::CreateLabel(int message_id) { - views::Label* label = - new views::Label(UTF16ToWide(l10n_util::GetStringUTF16(message_id))); - label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - return label; -} - -bool ExceptionEditorView::IsPatternValid( - const ContentSettingsPattern& pattern, - bool is_off_the_record) const { - bool is_valid_pattern = pattern.IsValid() && - (model_->IndexOfExceptionByPattern(pattern, is_off_the_record) == -1); - - return is_new() ? is_valid_pattern : (!pattern.AsString().empty() && - ((pattern_ == pattern) || is_valid_pattern)); -} - -void ExceptionEditorView::UpdateImageView(views::ImageView* image_view, - bool is_valid) { - return image_view->SetImage( - ResourceBundle::GetSharedInstance().GetBitmapNamed( - is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT)); -} diff --git a/chrome/browser/ui/views/options/exception_editor_view.h b/chrome/browser/ui/views/options/exception_editor_view.h deleted file mode 100644 index af6d6f5..0000000 --- a/chrome/browser/ui/views/options/exception_editor_view.h +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_EXCEPTION_EDITOR_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_EXCEPTION_EDITOR_VIEW_H_ -#pragma once - -#include <string> - -#include "chrome/browser/content_setting_combo_model.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/common/content_settings.h" -#include "chrome/common/content_settings_types.h" -#include "views/controls/button/checkbox.h" -#include "views/controls/combobox/combobox.h" -#include "views/controls/textfield/textfield_controller.h" -#include "views/window/dialog_delegate.h" - -namespace views { -class ImageView; -class Label; -} - -class ContentExceptionsTableModel; - -// ExceptionEditorView is responsible for showing a dialog that allows the user -// to create or edit a single content exception. If the user clicks ok the -// delegate is notified and completes the edit. -// -// To use an ExceptionEditorView create one and invoke Show on it. -// ExceptionEditorView is deleted when the dialog closes. -class ExceptionEditorView : public views::View, - public views::TextfieldController, - public views::DialogDelegate { - public: - class Delegate { - public: - // Invoked when the user accepts the edit. - virtual void AcceptExceptionEdit( - const ContentSettingsPattern& pattern, - ContentSetting setting, - bool is_off_the_record, - int index, - bool is_new) = 0; - - protected: - virtual ~Delegate() {} - }; - - // Creates a new ExceptionEditorView with the supplied args. |index| is the - // index into the ContentExceptionsTableModel of the exception. This is not - // used by ExceptionEditorView but instead passed to the delegate. - ExceptionEditorView(Delegate* delegate, - ContentExceptionsTableModel* model, - bool allow_off_the_record, - int index, - const ContentSettingsPattern& pattern, - ContentSetting setting, - bool is_off_the_record); - virtual ~ExceptionEditorView() {} - - void Show(gfx::NativeWindow parent); - - // views::DialogDelegate overrides. - virtual bool IsModal() const; - virtual std::wstring GetWindowTitle() const; - virtual bool IsDialogButtonEnabled( - MessageBoxFlags::DialogButton button) const; - virtual bool Cancel(); - virtual bool Accept(); - virtual views::View* GetContentsView(); - - // views::TextfieldController: - // Updates whether the user can accept the dialog as well as updating image - // views showing whether value is valid. - virtual void ContentsChanged(views::Textfield* sender, - const std::wstring& new_contents); - virtual bool HandleKeyEvent(views::Textfield* sender, - const views::KeyEvent& key_event); - - private: - void Init(); - - views::Label* CreateLabel(int message_id); - - // Returns true if we're adding a new item. - bool is_new() const { return index_ == -1; } - - bool IsPatternValid(const ContentSettingsPattern& pattern, - bool is_off_the_record) const; - - void UpdateImageView(views::ImageView* image_view, bool is_valid); - - Delegate* delegate_; - ContentExceptionsTableModel* model_; - ContentSettingComboModel cb_model_; - - // Index of the item being edited. If -1, indices this is a new entry. - const bool allow_off_the_record_; - const int index_; - const ContentSettingsPattern pattern_; - const ContentSetting setting_; - const bool is_off_the_record_; - - views::Textfield* pattern_tf_; - views::ImageView* pattern_iv_; - views::Combobox* action_cb_; - views::Checkbox* incognito_cb_; - - DISALLOW_COPY_AND_ASSIGN(ExceptionEditorView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_EXCEPTION_EDITOR_VIEW_H_ diff --git a/chrome/browser/ui/views/options/exceptions_page_view.cc b/chrome/browser/ui/views/options/exceptions_page_view.cc deleted file mode 100644 index 363c3e8..0000000 --- a/chrome/browser/ui/views/options/exceptions_page_view.cc +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/exceptions_page_view.h" - -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/pref_names.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/text/text_elider.h" -#include "views/background.h" -#include "views/controls/button/native_button.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" - -using views::ColumnSet; -using views::GridLayout; -using webkit_glue::PasswordForm; - -/////////////////////////////////////////////////////////////////////////////// -// ExceptionsTableModel -ExceptionsTableModel::ExceptionsTableModel(Profile* profile) - : PasswordsTableModel(profile) { -} - -ExceptionsTableModel::~ExceptionsTableModel() { -} - -string16 ExceptionsTableModel::GetText(int row, int col_id) { - DCHECK_EQ(col_id, IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN); - return PasswordsTableModel::GetText(row, col_id); -} - -int ExceptionsTableModel::CompareValues(int row1, int row2, - int col_id) { - DCHECK_EQ(col_id, IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN); - return PasswordsTableModel::CompareValues(row1, row2, col_id); -} - -void ExceptionsTableModel::GetAllExceptionsForProfile() { - DCHECK(!pending_login_query_); - pending_login_query_ = password_store()->GetBlacklistLogins(this); -} - -void ExceptionsTableModel::OnPasswordStoreRequestDone( - int handle, const std::vector<webkit_glue::PasswordForm*>& result) { - DCHECK_EQ(pending_login_query_, handle); - pending_login_query_ = NULL; - - STLDeleteElements<PasswordRows>(&saved_signons_); - std::string languages = profile_->GetPrefs()->GetString( - prefs::kAcceptLanguages); - for (size_t i = 0; i < result.size(); ++i) { - saved_signons_.push_back(new PasswordRow( - ui::SortedDisplayURL(result[i]->origin, languages), result[i])); - } - if (observer_) - observer_->OnModelChanged(); - if (row_count_observer_) - row_count_observer_->OnRowCountChanged(RowCount()); -} - -/////////////////////////////////////////////////////////////////////////////// -// ExceptionsPageView, public -ExceptionsPageView::ExceptionsPageView(Profile* profile) - : OptionsPageView(profile), - ALLOW_THIS_IN_INITIALIZER_LIST(show_button_( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON)), - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON)))), - ALLOW_THIS_IN_INITIALIZER_LIST(remove_button_( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_PAGE_VIEW_REMOVE_BUTTON)))), - ALLOW_THIS_IN_INITIALIZER_LIST(remove_all_button_( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_PAGE_VIEW_REMOVE_ALL_BUTTON)))), - table_model_(profile), - table_view_(NULL) { -} - -ExceptionsPageView::~ExceptionsPageView() { - // The model is going away, prevent the table from accessing it. - if (table_view_) - table_view_->SetModel(NULL); -} - -void ExceptionsPageView::OnSelectionChanged() { - bool has_selection = table_view_->SelectedRowCount() > 0; - remove_button_.SetEnabled(has_selection); -} - -void ExceptionsPageView::ButtonPressed( - views::Button* sender, const views::Event& event) { - // Close will result in our destruction. - if (sender == &remove_all_button_) { - table_model_.ForgetAndRemoveAllSignons(); - return; - } - - // The following require a selection (and only one, since table is single- - // select only). - views::TableSelectionIterator iter = table_view_->SelectionBegin(); - int row = *iter; - DCHECK(++iter == table_view_->SelectionEnd()); - - if (sender == &remove_button_) { - table_model_.ForgetAndRemoveSignon(row); - } else { - NOTREACHED() << "Invalid button."; - } -} - -void ExceptionsPageView::OnRowCountChanged(size_t rows) { - remove_all_button_.SetEnabled(rows > 0); -} - -/////////////////////////////////////////////////////////////////////////////// -// ExceptionsPageView, protected -void ExceptionsPageView::InitControlLayout() { - SetupButtons(); - SetupTable(); - - // Do the layout thing. - GridLayout* layout = GridLayout::CreatePanel(this); - SetLayoutManager(layout); - - const int top_column_set_id = 0; - - // Design the grid. - ColumnSet* column_set = layout->AddColumnSet(top_column_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - // Fill the grid. - layout->StartRow(0, top_column_set_id); - layout->AddView(table_view_, 1, 6, GridLayout::FILL, - GridLayout::FILL); - layout->AddView(&remove_button_); - layout->StartRowWithPadding(0, top_column_set_id, 0, - views::kRelatedControlVerticalSpacing); - layout->SkipColumns(1); - layout->AddView(&remove_all_button_); - layout->StartRowWithPadding(0, top_column_set_id, 0, - views::kRelatedControlVerticalSpacing); - - layout->SkipColumns(1); - layout->AddView(&show_button_); - layout->AddPaddingRow(1, 0); - - // Ask the database for exception data. - table_model_.GetAllExceptionsForProfile(); -} - -/////////////////////////////////////////////////////////////////////////////// -// ExceptionsPageView, private -void ExceptionsPageView::SetupButtons() { - // Disable all buttons in the first place. - remove_button_.set_parent_owned(false); - remove_button_.SetEnabled(false); - - remove_all_button_.set_parent_owned(false); - remove_all_button_.SetEnabled(false); - - show_button_.set_parent_owned(false); - show_button_.SetEnabled(false); - show_button_.SetVisible(false); -} - -void ExceptionsPageView::SetupTable() { - // Tell the table model we are concerned about how many rows it has. - table_model_.set_row_count_observer(this); - - // Creates the different columns for the table. - // The float resize values are the result of much tinkering. - std::vector<ui::TableColumn> columns; - columns.push_back(ui::TableColumn(IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN, - ui::TableColumn::LEFT, -1, 0.55f)); - columns.back().sortable = true; - table_view_ = new views::TableView(&table_model_, columns, views::TEXT_ONLY, - true, true, true); - // Make the table initially sorted by host. - views::TableView::SortDescriptors sort; - sort.push_back(views::TableView::SortDescriptor( - IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN, true)); - table_view_->SetSortDescriptors(sort); - table_view_->SetObserver(this); -} diff --git a/chrome/browser/ui/views/options/exceptions_page_view.h b/chrome/browser/ui/views/options/exceptions_page_view.h deleted file mode 100644 index ee34869..0000000 --- a/chrome/browser/ui/views/options/exceptions_page_view.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_EXCEPTIONS_PAGE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_EXCEPTIONS_PAGE_VIEW_H_ -#pragma once - -#include <vector> - -#include "base/compiler_specific.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "chrome/browser/ui/views/options/passwords_page_view.h" -#include "views/controls/table/table_view_observer.h" - -class Profile; - -/////////////////////////////////////////////////////////////////////////////// -// ExceptionsTableModel -class ExceptionsTableModel : public PasswordsTableModel { - public: - explicit ExceptionsTableModel(Profile* profile); - virtual ~ExceptionsTableModel(); - - // TableModel methods. - virtual string16 GetText(int row, int column) OVERRIDE; - virtual int CompareValues(int row1, int row2, int col_id) OVERRIDE; - - // PasswordStoreConsumer implementation. - virtual void OnPasswordStoreRequestDone( - int handle, const std::vector<webkit_glue::PasswordForm*>& result); - // Request all logins data. - void GetAllExceptionsForProfile(); -}; - -/////////////////////////////////////////////////////////////////////////////// -// ExceptionsPageView -class ExceptionsPageView : public OptionsPageView, - public views::TableViewObserver, - public views::ButtonListener, - public PasswordsTableModelObserver { - public: - explicit ExceptionsPageView(Profile* profile); - virtual ~ExceptionsPageView(); - - // views::TableViewObserverImplementation. - virtual void OnSelectionChanged(); - - // views::ButtonListener implementation. - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // PasswordsTableModelObserver implementation. - virtual void OnRowCountChanged(size_t rows); - - protected: - virtual void InitControlLayout(); - - private: - // Helper to configure our buttons and labels. - void SetupButtons(); - - // Helper to configure our table view. - void SetupTable(); - - ExceptionsTableModel table_model_; - views::TableView* table_view_; - - // The buttons and labels. - views::NativeButton remove_button_; - views::NativeButton remove_all_button_; - MultiLabelButtons show_button_; - - DISALLOW_COPY_AND_ASSIGN(ExceptionsPageView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_EXCEPTIONS_PAGE_VIEW_H_ diff --git a/chrome/browser/ui/views/options/exceptions_view.cc b/chrome/browser/ui/views/options/exceptions_view.cc deleted file mode 100644 index 0ab6aaf..0000000 --- a/chrome/browser/ui/views/options/exceptions_view.cc +++ /dev/null @@ -1,281 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/exceptions_view.h" - -#include <algorithm> -#include <vector> - -#include "base/utf_string_conversions.h" -#include "chrome/browser/ui/views/options/content_exceptions_table_view.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/rect.h" -#include "views/controls/button/native_button.h" -#include "views/controls/label.h" -#include "views/controls/table/table_view.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" -#include "views/window/window.h" - -static const int kExceptionsViewInsetSize = 5; -static ExceptionsView* instances[CONTENT_SETTINGS_NUM_TYPES] = { NULL }; - -// static -void ExceptionsView::ShowExceptionsWindow( - gfx::NativeWindow parent, - HostContentSettingsMap* map, - HostContentSettingsMap* off_the_record_map, - ContentSettingsType content_type) { - if (!instances[content_type]) { - instances[content_type] = - new ExceptionsView(map, off_the_record_map, content_type); - views::Window::CreateChromeWindow(parent, gfx::Rect(), - instances[content_type]); - } - - // This will show invisible windows and bring visible windows to the front. - instances[content_type]->window()->Show(); -} - -ExceptionsView::~ExceptionsView() { - instances[model_.content_type()] = NULL; - table_->SetModel(NULL); -} - -void ExceptionsView::OnSelectionChanged() { - UpdateButtonState(); -} - -void ExceptionsView::OnDoubleClick() { - if (table_->SelectedRowCount() == 1) - Edit(); -} - -void ExceptionsView::OnTableViewDelete(views::TableView* table_view) { - Remove(); -} - -void ExceptionsView::ButtonPressed(views::Button* sender, - const views::Event& event) { - switch (sender->tag()) { - case IDS_EXCEPTIONS_ADD_BUTTON: - Add(); - break; - case IDS_EXCEPTIONS_EDIT_BUTTON: - Edit(); - break; - case IDS_EXCEPTIONS_REMOVEALL_BUTTON: - RemoveAll(); - break; - case IDS_EXCEPTIONS_REMOVE_BUTTON: - Remove(); - break; - default: - NOTREACHED(); - } -} - -void ExceptionsView::Layout() { - views::NativeButton* buttons[] = { add_button_, edit_button_, - remove_button_, remove_all_button_ }; - - // The buttons are placed in the parent, but we need to lay them out. - int max_y = - parent()->GetContentsBounds().bottom() - views::kButtonVEdgeMargin; - int x = views::kPanelHorizMargin; - - for (size_t i = 0; i < arraysize(buttons); ++i) { - gfx::Size pref = buttons[i]->GetPreferredSize(); - buttons[i]->SetBounds(x, max_y - pref.height(), pref.width(), - pref.height()); - x += pref.width() + views::kRelatedControlHorizontalSpacing; - } - - // Lay out the rest of this view. - View::Layout(); -} - -gfx::Size ExceptionsView::GetPreferredSize() { - return gfx::Size(views::Window::GetLocalizedContentsSize( - IDS_CONTENT_EXCEPTION_DIALOG_WIDTH_CHARS, - IDS_CONTENT_EXCEPTION_DIALOG_HEIGHT_LINES)); -} - -void ExceptionsView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (is_add && child == this) - Init(); -} - -std::wstring ExceptionsView::GetWindowTitle() const { - switch (model_.content_type()) { - case CONTENT_SETTINGS_TYPE_COOKIES: - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_COOKIE_EXCEPTION_TITLE)); - case CONTENT_SETTINGS_TYPE_IMAGES: - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_IMAGES_EXCEPTION_TITLE)); - case CONTENT_SETTINGS_TYPE_JAVASCRIPT: - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_JS_EXCEPTION_TITLE)); - case CONTENT_SETTINGS_TYPE_PLUGINS: - return UTF16ToWide( - l10n_util::GetStringUTF16(IDS_PLUGINS_EXCEPTION_TITLE)); - case CONTENT_SETTINGS_TYPE_POPUPS: - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_POPUP_EXCEPTION_TITLE)); - default: - NOTREACHED(); - } - return std::wstring(); -} - -void ExceptionsView::AcceptExceptionEdit( - const ContentSettingsPattern& pattern, - ContentSetting setting, - bool is_off_the_record, - int index, - bool is_new) { - DCHECK(!is_off_the_record || allow_off_the_record_); - - if (!is_new) - model_.RemoveException(index); - model_.AddException(pattern, setting, is_off_the_record); - - int new_index = model_.IndexOfExceptionByPattern(pattern, is_off_the_record); - DCHECK(new_index != -1); - table_->Select(new_index); -} - -ExceptionsView::ExceptionsView(HostContentSettingsMap* map, - HostContentSettingsMap* off_the_record_map, - ContentSettingsType type) - : model_(map, off_the_record_map, type), - allow_off_the_record_(off_the_record_map != NULL), - table_(NULL), - add_button_(NULL), - edit_button_(NULL), - remove_button_(NULL), - remove_all_button_(NULL) { -} - -void ExceptionsView::Init() { - if (table_) - return; // We've already Init'd. - - using views::GridLayout; - - std::vector<ui::TableColumn> columns; - columns.push_back( - ui::TableColumn(IDS_EXCEPTIONS_PATTERN_HEADER, ui::TableColumn::LEFT, -1, - .75)); - columns.back().sortable = true; - columns.push_back( - ui::TableColumn(IDS_EXCEPTIONS_ACTION_HEADER, ui::TableColumn::LEFT, -1, - .25)); - columns.back().sortable = true; - table_ = new ContentExceptionsTableView(&model_, columns); - views::TableView::SortDescriptors sort; - sort.push_back( - views::TableView::SortDescriptor(IDS_EXCEPTIONS_PATTERN_HEADER, true)); - table_->SetSortDescriptors(sort); - table_->SetObserver(this); - - add_button_ = new views::NativeButton( - this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ADD_BUTTON))); - add_button_->set_tag(IDS_EXCEPTIONS_ADD_BUTTON); - edit_button_ = new views::NativeButton( - this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_EDIT_BUTTON))); - edit_button_->set_tag(IDS_EXCEPTIONS_EDIT_BUTTON); - remove_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_REMOVE_BUTTON))); - remove_button_->set_tag(IDS_EXCEPTIONS_REMOVE_BUTTON); - remove_all_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_REMOVEALL_BUTTON))); - remove_all_button_->set_tag(IDS_EXCEPTIONS_REMOVEALL_BUTTON); - - parent()->AddChildView(add_button_); - parent()->AddChildView(edit_button_); - parent()->AddChildView(remove_button_); - parent()->AddChildView(remove_all_button_); - - GridLayout* layout = new GridLayout(this); - layout->SetInsets(kExceptionsViewInsetSize, kExceptionsViewInsetSize, - kExceptionsViewInsetSize, kExceptionsViewInsetSize); - SetLayoutManager(layout); - - const int single_column_layout_id = 0; - views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - layout->StartRow(1, single_column_layout_id); - layout->AddView(table_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - if (allow_off_the_record_) { - views::Label* label = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_OTR_IN_ITALICS))); - label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - layout->StartRow(0, single_column_layout_id); - layout->AddView(label, 1, 1, GridLayout::LEADING, GridLayout::CENTER); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - } - - UpdateButtonState(); -} - -void ExceptionsView::UpdateButtonState() { - int selected_row_count = table_->SelectedRowCount(); - // TODO: 34177, support editing of more than one entry at a time. - edit_button_->SetEnabled(selected_row_count == 1); - remove_button_->SetEnabled(selected_row_count >= 1); - remove_all_button_->SetEnabled(model_.RowCount() > 0); -} - -void ExceptionsView::Add() { - ExceptionEditorView* view = - new ExceptionEditorView(this, &model_, allow_off_the_record_, -1, - ContentSettingsPattern(), - CONTENT_SETTING_BLOCK, false); - view->Show(window()->GetNativeWindow()); - - UpdateButtonState(); -} - -void ExceptionsView::Edit() { - DCHECK(table_->FirstSelectedRow() != -1); - int index = table_->FirstSelectedRow(); - const HostContentSettingsMap::PatternSettingPair& entry = - model_.entry_at(index); - ExceptionEditorView* view = - new ExceptionEditorView(this, &model_, allow_off_the_record_, index, - entry.first, entry.second, - model_.entry_is_off_the_record(index)); - view->Show(window()->GetNativeWindow()); -} - -void ExceptionsView::Remove() { - std::vector<int> indices; - for (views::TableView::iterator i = table_->SelectionBegin(); - i != table_->SelectionEnd(); ++i) { - indices.push_back(*i); - } - std::sort(indices.begin(), indices.end()); - for (std::vector<int>::reverse_iterator i = indices.rbegin(); - i != indices.rend(); ++i) { - model_.RemoveException(*i); - } - - UpdateButtonState(); -} - -void ExceptionsView::RemoveAll() { - model_.RemoveAll(); - - UpdateButtonState(); -} diff --git a/chrome/browser/ui/views/options/exceptions_view.h b/chrome/browser/ui/views/options/exceptions_view.h deleted file mode 100644 index 4e920ca..0000000 --- a/chrome/browser/ui/views/options/exceptions_view.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_EXCEPTIONS_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_EXCEPTIONS_VIEW_H_ -#pragma once - -#include <string> - -#include "chrome/browser/content_exceptions_table_model.h" -#include "chrome/browser/ui/views/options/exception_editor_view.h" -#include "chrome/common/content_settings.h" -#include "chrome/common/content_settings_types.h" -#include "views/controls/button/button.h" -#include "views/controls/table/table_view_observer.h" -#include "views/window/dialog_delegate.h" - -class HostContentSettingsMap; - -namespace views { -class NativeButton; -class TableView; -} - -// ExceptionsView is responsible for showing the user the set of content -// exceptions for a specific type. The exceptions are shown in a table view -// by way of a ContentExceptionsTableModel. The user can add/edit/remove -// exceptions. Editing and creating new exceptions is done way of the -// ExceptionEditorView. -// Use the ShowExceptionsWindow method to create and show an ExceptionsView -// for a specific type. ExceptionsView is deleted when the window closes. -class ExceptionsView : public ExceptionEditorView::Delegate, - public views::View, - public views::ButtonListener, - public views::DialogDelegate, - public views::TableViewObserver { - public: - // Shows the Exceptions window. - static void ShowExceptionsWindow(gfx::NativeWindow parent, - HostContentSettingsMap* map, - HostContentSettingsMap* off_the_record_map, - ContentSettingsType content_type); - - virtual ~ExceptionsView(); - - // TableViewObserver overrides: - virtual void OnSelectionChanged(); - virtual void OnDoubleClick(); - virtual void OnTableViewDelete(views::TableView* table_view); - - // views::ButtonListener implementation. - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // views::View overrides: - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - // views::WindowDelegate implementation. - virtual int GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_CANCEL; - } - virtual bool CanResize() const { return true; } - virtual std::wstring GetWindowTitle() const; - virtual views::View* GetContentsView() { return this; } - - // ExceptionEditorView::Delegate implementation. - virtual void AcceptExceptionEdit( - const ContentSettingsPattern& pattern, - ContentSetting setting, - bool is_off_the_record, - int index, - bool is_new); - - private: - ExceptionsView(HostContentSettingsMap* map, - HostContentSettingsMap* off_the_record_map, - ContentSettingsType type); - - void Init(); - - // Resets the enabled state of the buttons from the model. - void UpdateButtonState(); - - // Adds a new item. - void Add(); - - // Edits the selected item. - void Edit(); - - // Removes the selected item. - void Remove(); - - // Removes all. - void RemoveAll(); - - // The model displayed in the table. - ContentExceptionsTableModel model_; - - // True if the user can also add incognito entries. - bool allow_off_the_record_; - - views::TableView* table_; - - views::NativeButton* add_button_; - views::NativeButton* edit_button_; - views::NativeButton* remove_button_; - views::NativeButton* remove_all_button_; - - DISALLOW_COPY_AND_ASSIGN(ExceptionsView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_EXCEPTIONS_VIEW_H_ - diff --git a/chrome/browser/ui/views/options/fonts_languages_window_view.cc b/chrome/browser/ui/views/options/fonts_languages_window_view.cc deleted file mode 100644 index 70b0492..0000000 --- a/chrome/browser/ui/views/options/fonts_languages_window_view.cc +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/fonts_languages_window_view.h" - -#include "base/utf_string_conversions.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/views/options/fonts_page_view.h" -#include "chrome/browser/ui/views/options/languages_page_view.h" -#include "chrome/common/chrome_constants.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "views/controls/tabbed_pane/tabbed_pane.h" -#include "views/window/window.h" - -// static -static FontsLanguagesWindowView* instance_ = NULL; -static const int kDialogPadding = 7; - -/////////////////////////////////////////////////////////////////////////////// -// FontsLanguagesWindowView, public: - -FontsLanguagesWindowView::FontsLanguagesWindowView(Profile* profile) - // Always show preferences for the original profile. Most state when off - // the record comes from the original profile, but we explicitly use - // the original profile to avoid potential problems. - : profile_(profile->GetOriginalProfile()), - fonts_page_(NULL), - languages_page_(NULL) { -} - -FontsLanguagesWindowView::~FontsLanguagesWindowView() { -} - -/////////////////////////////////////////////////////////////////////////////// -// FontsLanguagesWindowView, views::DialogDelegate implementation: - -bool FontsLanguagesWindowView::Accept() { - fonts_page_->SaveChanges(); - languages_page_->SaveChanges(); - return true; -} - -/////////////////////////////////////////////////////////////////////////////// -// FontsLanguagesWindowView, views::WindowDelegate implementation: - -std::wstring FontsLanguagesWindowView::GetWindowTitle() const { - return UTF16ToWide( - l10n_util::GetStringUTF16(IDS_FONT_LANGUAGE_SETTING_WINDOWS_TITLE)); -} - -void FontsLanguagesWindowView::WindowClosing() { - // Clear the static instance so that the next time ShowOptionsWindow() is - // called a new window is opened. - instance_ = NULL; -} - -views::View* FontsLanguagesWindowView::GetContentsView() { - return this; -} - -/////////////////////////////////////////////////////////////////////////////// -// FontsLanguagesWindowView, views::View overrides: - -void FontsLanguagesWindowView::Layout() { - tabs_->SetBounds(kDialogPadding, kDialogPadding, - width() - (2 * kDialogPadding), - height() - (2 * kDialogPadding)); -} - -gfx::Size FontsLanguagesWindowView::GetPreferredSize() { - return gfx::Size(views::Window::GetLocalizedContentsSize( - IDS_FONTSLANG_DIALOG_WIDTH_CHARS, - IDS_FONTSLANG_DIALOG_HEIGHT_LINES)); -} - -void FontsLanguagesWindowView::ShowTabPage(FontsLanguagesPage page) { - // If the window is not yet visible, we need to show it (it will become - // active), otherwise just bring it to the front. - if (!window()->IsVisible()) { - window()->Show(); - } else { - window()->Activate(); - } - - // If the page is out of bounds, reset to the first tab. - if (page < 0 || page >= tabs_->GetTabCount()) - page = FONTS_ENCODING_PAGE; - - tabs_->SelectTabAt(page); -} - -void FontsLanguagesWindowView::ViewHierarchyChanged( - bool is_add, views::View* parent, views::View* child) { - // Can't init before we're inserted into a Container, because we require - // a HWND to parent native child controls to. - if (is_add && child == this) - Init(); -} - -/////////////////////////////////////////////////////////////////////////////// -// FontsLanguagesWindowView, private: - -void FontsLanguagesWindowView::Init() { - tabs_ = new views::TabbedPane; - AddChildView(tabs_); - - fonts_page_ = new FontsPageView(profile_); - tabs_->AddTab(UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_FONT_TAB_TITLE)), fonts_page_); - - languages_page_ = new LanguagesPageView(profile_); - tabs_->AddTab(UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_TAB_TITLE)), languages_page_); -} - -void ShowFontsLanguagesWindow(gfx::NativeWindow window, - FontsLanguagesPage page, - Profile* profile) { - DCHECK(profile); - - // If there's already an existing fonts and language window, activate it and - // switch to the specified page. - // TODO(beng): note this is not multi-simultaneous-profile-safe. When we care - // about this case this will have to be fixed. - if (!instance_) { - instance_ = new FontsLanguagesWindowView(profile); - views::Window::CreateChromeWindow(window, gfx::Rect(), instance_); - } - instance_->ShowTabPage(page); -} diff --git a/chrome/browser/ui/views/options/fonts_languages_window_view.h b/chrome/browser/ui/views/options/fonts_languages_window_view.h deleted file mode 100644 index 65afe52..0000000 --- a/chrome/browser/ui/views/options/fonts_languages_window_view.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_FONTS_LANGUAGES_WINDOW_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_FONTS_LANGUAGES_WINDOW_VIEW_H_ -#pragma once - -#include "chrome/browser/fonts_languages_window.h" -#include "views/view.h" -#include "views/window/dialog_delegate.h" - -class Profile; -class FontsPageView; -class LanguagesPageView; - -namespace views { -class TabbedPane; -} - -/////////////////////////////////////////////////////////////////////////////// -// FontsLanguagesWindowView -// -// The contents of the "Fonts and Languages Preferences" dialog window. -// -class FontsLanguagesWindowView : public views::View, - public views::DialogDelegate { - public: - explicit FontsLanguagesWindowView(Profile* profile); - virtual ~FontsLanguagesWindowView(); - - // views::DialogDelegate implementation: - virtual bool Accept(); - - // views::WindowDelegate Methods: - virtual bool IsModal() const { return true; } - virtual std::wstring GetWindowTitle() const; - virtual views::View* GetContentsView(); - virtual void WindowClosing(); - - // views::View overrides: - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - // Shows the tab corresponding to the specified |page|. - void ShowTabPage(FontsLanguagesPage page); - - protected: - // views::View overrides: - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - private: - // Init the assorted Tabbed pages - void Init(); - - // The Tab view that contains all of the options pages. - views::TabbedPane* tabs_; - - // Fonts Page View handle remembered so that prefs is updated only when - // OK is pressed. - FontsPageView* fonts_page_; - - // Languages Page View handle remembered so that prefs is updated only when - // OK is pressed. - LanguagesPageView* languages_page_; - - // The Profile associated with these options. - Profile* profile_; - - DISALLOW_COPY_AND_ASSIGN(FontsLanguagesWindowView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_FONTS_LANGUAGES_WINDOW_VIEW_H_ diff --git a/chrome/browser/ui/views/options/fonts_page_view.cc b/chrome/browser/ui/views/options/fonts_page_view.cc deleted file mode 100644 index 44d6b5c..0000000 --- a/chrome/browser/ui/views/options/fonts_page_view.cc +++ /dev/null @@ -1,434 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/fonts_page_view.h" - -#include <windows.h> -#include <shlobj.h> -#include <vsstyle.h> -#include <vssym32.h> - -#include <vector> - -#include "base/file_util.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/default_encoding_combo_model.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/pref_names.h" -#include "grit/generated_resources.h" -#include "grit/theme_resources.h" -#include "grit/locale_settings.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas_skia.h" -#include "ui/gfx/font.h" -#include "ui/gfx/native_theme_win.h" -#include "views/controls/button/native_button.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" -#include "views/widget/widget.h" - -//////////////////////////////////////////////////////////////////////////////// -// FontDisplayView - -class FontDisplayView : public views::View { - public: - FontDisplayView(); - virtual ~FontDisplayView(); - - // This method takes in font size in pixel units, instead of the normal point - // unit because users expect the font size number to represent pixels and not - // points. - void SetFontType(const std::wstring& font_name, - int font_size); - - std::wstring font_name() { return font_name_; } - int font_size() { return font_size_; } - - // views::View overrides: - virtual void OnPaint(gfx::Canvas* canvas); - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - private: - views::Label* font_text_label_; - std::wstring font_name_; - int font_size_; - std::wstring font_text_label_string_; - - static const int kFontDisplayMaxWidthChars = 50; - static const int kFontDisplayMaxHeightChars = 1; - static const int kFontDisplayLabelPadding = 5; - - DISALLOW_COPY_AND_ASSIGN(FontDisplayView); -}; - -FontDisplayView::FontDisplayView() - : font_text_label_(new views::Label) { - AddChildView(font_text_label_); -} - -FontDisplayView::~FontDisplayView() { -} - -void FontDisplayView::SetFontType(const std::wstring& font_name, - int font_size) { - if (font_name.empty()) - return; - - font_name_ = font_name; - font_size_ = font_size; - std::wstring displayed_text = font_name_; - - // Append the font type and size. - displayed_text += L", "; - displayed_text += UTF8ToWide(::StringPrintf("%d", font_size_)); - HDC hdc = GetDC(NULL); - int font_size_point = MulDiv(font_size, 72, GetDeviceCaps(hdc, LOGPIXELSY)); - gfx::Font font = gfx::Font(font_name, font_size_point); - font_text_label_->SetFont(font); - font_text_label_->SetText(displayed_text); -} - -void FontDisplayView::OnPaint(gfx::Canvas* canvas) { - HDC dc = canvas->BeginPlatformPaint(); - RECT rect = { 0, 0, width(), height() }; - gfx::NativeTheme::instance()->PaintTextField( - dc, EP_BACKGROUND, EBS_NORMAL, 0, &rect, ::GetSysColor(COLOR_3DFACE), - true, true); - canvas->EndPlatformPaint(); -} - -void FontDisplayView::Layout() { - font_text_label_->SetBounds(0, 0, width(), height()); -} - -gfx::Size FontDisplayView::GetPreferredSize() { - gfx::Size size = font_text_label_->GetPreferredSize(); - size.set_width(size.width() + 2 * kFontDisplayLabelPadding); - size.set_height(size.height() + 2 * kFontDisplayLabelPadding); - return size; -} - -void EmbellishTitle(views::Label* title_label) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - gfx::Font title_font = - rb.GetFont(ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD); - title_label->SetFont(title_font); - SkColor title_color = - gfx::NativeTheme::instance()->GetThemeColorWithDefault( - gfx::NativeTheme::BUTTON, BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, - COLOR_WINDOWTEXT); - title_label->SetColor(title_color); -} - -FontsPageView::FontsPageView(Profile* profile) - : ALLOW_THIS_IN_INITIALIZER_LIST( - select_font_dialog_(SelectFontDialog::Create(this))), - fonts_group_title_(NULL), - encoding_group_title_(NULL), - fixed_width_font_change_page_button_(NULL), - serif_font_change_page_button_(NULL), - sans_serif_font_change_page_button_(NULL), - fixed_width_font_label_(NULL), - serif_font_label_(NULL), - sans_serif_font_label_(NULL), - default_encoding_combobox_(NULL), - serif_button_pressed_(false), - sans_serif_button_pressed_(false), - fixed_width_button_pressed_(false), - encoding_dropdown_clicked_(false), - font_type_being_changed_(NONE), - OptionsPageView(profile), - font_changed_(false), - default_encoding_changed_(false), - serif_font_size_pixel_(0), - sans_serif_font_size_pixel_(0), - fixed_width_font_size_pixel_(0) { - serif_name_.Init(prefs::kWebKitSerifFontFamily, profile->GetPrefs(), NULL); - serif_size_.Init(prefs::kWebKitDefaultFontSize, profile->GetPrefs(), NULL); - - sans_serif_name_.Init(prefs::kWebKitSansSerifFontFamily, profile->GetPrefs(), - NULL); - sans_serif_size_.Init(prefs::kWebKitDefaultFontSize, profile->GetPrefs(), - NULL); - - fixed_width_name_.Init(prefs::kWebKitFixedFontFamily, profile->GetPrefs(), - NULL); - fixed_width_size_.Init(prefs::kWebKitDefaultFixedFontSize, - profile->GetPrefs(), NULL); - - default_encoding_.Init(prefs::kDefaultCharset, profile->GetPrefs(), NULL); -} - -FontsPageView::~FontsPageView() { -} - -void FontsPageView::ButtonPressed( - views::Button* sender, const views::Event& event) { - HWND owning_hwnd = GetAncestor(GetWidget()->GetNativeView(), GA_ROOT); - std::wstring font_name; - int font_size = 0; - if (sender == serif_font_change_page_button_) { - font_type_being_changed_ = SERIF; - font_name = serif_font_display_view_->font_name(); - font_size = serif_font_size_pixel_; - } else if (sender == sans_serif_font_change_page_button_) { - font_type_being_changed_ = SANS_SERIF; - font_name = sans_serif_font_display_view_->font_name(); - font_size = sans_serif_font_size_pixel_; - } else if (sender == fixed_width_font_change_page_button_) { - font_type_being_changed_ = FIXED_WIDTH; - font_name = fixed_width_font_display_view_->font_name(); - font_size = fixed_width_font_size_pixel_; - } else { - NOTREACHED(); - return; - } - - select_font_dialog_->SelectFont(owning_hwnd, NULL, font_name, font_size); -} - -void FontsPageView::ItemChanged(views::Combobox* combo_box, - int prev_index, int new_index) { - if (combo_box == default_encoding_combobox_) { - if (prev_index != new_index) { // Default-Encoding has been changed. - encoding_dropdown_clicked_ = true; - default_encoding_selected_ = default_encoding_combobox_model_-> - GetEncodingCharsetByIndex(new_index); - default_encoding_changed_ = true; - } - } -} - -void FontsPageView::FontSelected(const gfx::Font& font, void* params) { - if (font.GetFontName().empty()) - return; - int font_size = font.GetFontSize(); - // Currently we do not have separate font sizes for Serif and Sans Serif. - // Therefore, when Serif font size is changed, Sans-Serif font size changes, - // and vice versa. - if (font_type_being_changed_ == SERIF) { - sans_serif_font_size_pixel_ = serif_font_size_pixel_ = font_size; - serif_font_display_view_->SetFontType( - font.GetFontName(), - serif_font_size_pixel_); - sans_serif_font_display_view_->SetFontType( - sans_serif_font_display_view_->font_name(), - sans_serif_font_size_pixel_); - } else if (font_type_being_changed_ == SANS_SERIF) { - sans_serif_font_size_pixel_ = serif_font_size_pixel_ = font_size; - sans_serif_font_display_view_->SetFontType( - font.GetFontName(), - sans_serif_font_size_pixel_); - serif_font_display_view_->SetFontType( - serif_font_display_view_->font_name(), - sans_serif_font_size_pixel_); - } else if (font_type_being_changed_ == FIXED_WIDTH) { - fixed_width_font_size_pixel_ = font_size; - fixed_width_font_display_view_->SetFontType(font.GetFontName(), font_size); - } - font_changed_ = true; -} - -void FontsPageView::SaveChanges() { - // Set Fonts. - if (font_changed_) { - serif_name_.SetValue(WideToUTF8(serif_font_display_view_->font_name())); - serif_size_.SetValue(serif_font_size_pixel_); - sans_serif_name_.SetValue( - WideToUTF8(sans_serif_font_display_view_->font_name())); - sans_serif_size_.SetValue(sans_serif_font_size_pixel_); - fixed_width_name_.SetValue(WideToUTF8( - fixed_width_font_display_view_->font_name())); - fixed_width_size_.SetValue(fixed_width_font_size_pixel_); - } - // Set Encoding. - if (default_encoding_changed_) - default_encoding_.SetValue(default_encoding_selected_); -} - -void FontsPageView::InitControlLayout() { - using views::GridLayout; - using views::ColumnSet; - - GridLayout* layout = GridLayout::CreatePanel(this); - SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - - // Fonts group. - column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1, - GridLayout::USE_PREF, 0, 0); - fonts_group_title_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_FONT_SUB_DIALOG_FONT_TITLE))); - EmbellishTitle(fonts_group_title_); - fonts_group_title_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(fonts_group_title_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - InitFontLayout(); - layout->AddView(fonts_contents_); - layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); - - // Encoding group. - encoding_group_title_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_FONT_SUB_DIALOG_ENCODING_TITLE))); - EmbellishTitle(encoding_group_title_); - encoding_group_title_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(encoding_group_title_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - InitEncodingLayout(); - layout->AddView(encoding_contents_); -} - -void FontsPageView::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || *pref_name == prefs::kWebKitFixedFontFamily) { - fixed_width_font_size_pixel_ = fixed_width_size_.GetValue(); - fixed_width_font_display_view_->SetFontType( - UTF8ToWide(fixed_width_name_.GetValue()), - fixed_width_font_size_pixel_); - } - if (!pref_name || *pref_name == prefs::kWebKitSerifFontFamily) { - serif_font_size_pixel_ = serif_size_.GetValue(); - serif_font_display_view_->SetFontType( - UTF8ToWide(serif_name_.GetValue()), - serif_font_size_pixel_); - } - if (!pref_name || *pref_name == prefs::kWebKitSansSerifFontFamily) { - sans_serif_font_size_pixel_ = sans_serif_size_.GetValue(); - sans_serif_font_display_view_->SetFontType( - UTF8ToWide(sans_serif_name_.GetValue()), - sans_serif_font_size_pixel_); - } -} - -void FontsPageView::InitFontLayout() { - // Fixed width. - fixed_width_font_display_view_ = new FontDisplayView; - fixed_width_font_change_page_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_BUTTON_LABEL))); - - fixed_width_font_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_FIXED_WIDTH_LABEL))); - fixed_width_font_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - - // Serif font. - serif_font_display_view_ = new FontDisplayView; - serif_font_change_page_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_BUTTON_LABEL))); - - serif_font_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SERIF_LABEL))); - serif_font_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - - // Sans Serif font. - sans_serif_font_display_view_ = new FontDisplayView; - sans_serif_font_change_page_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_BUTTON_LABEL))); - - sans_serif_font_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SANS_SERIF_LABEL))); - sans_serif_font_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - - // Now add the views. - using views::GridLayout; - using views::ColumnSet; - - fonts_contents_ = new views::View; - GridLayout* layout = new GridLayout(fonts_contents_); - fonts_contents_->SetLayoutManager(layout); - - const int triple_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(triple_column_view_set_id); - - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - // Serif font controls. - layout->StartRow(0, triple_column_view_set_id); - layout->AddView(serif_font_label_); - layout->AddView(serif_font_display_view_, 1, 1, - GridLayout::FILL, GridLayout::CENTER); - layout->AddView(serif_font_change_page_button_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - // Sans serif font controls. - layout->StartRow(0, triple_column_view_set_id); - layout->AddView(sans_serif_font_label_); - layout->AddView(sans_serif_font_display_view_, 1, 1, - GridLayout::FILL, GridLayout::CENTER); - layout->AddView(sans_serif_font_change_page_button_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - // Fixed-width font controls. - layout->StartRow(0, triple_column_view_set_id); - layout->AddView(fixed_width_font_label_); - layout->AddView(fixed_width_font_display_view_, 1, 1, - GridLayout::FILL, GridLayout::CENTER); - layout->AddView(fixed_width_font_change_page_button_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); -} - -void FontsPageView::InitEncodingLayout() { - default_encoding_combobox_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_FONT_DEFAULT_ENCODING_SELECTOR_LABEL))); - default_encoding_combobox_model_.reset(new DefaultEncodingComboboxModel); - default_encoding_combobox_ = new views::Combobox( - default_encoding_combobox_model_.get()); - int selected_encoding_index = default_encoding_combobox_model_-> - GetSelectedEncodingIndex(profile()); - default_encoding_combobox_->SetSelectedItem(selected_encoding_index); - default_encoding_selected_ = default_encoding_combobox_model_-> - GetEncodingCharsetByIndex(selected_encoding_index); - default_encoding_combobox_->set_listener(this); - - // Now add the views. - using views::GridLayout; - using views::ColumnSet; - - encoding_contents_ = new views::View; - GridLayout* layout = new GridLayout(encoding_contents_); - encoding_contents_->SetLayoutManager(layout); - - // Double column. - const int double_column_view_set_id = 2; - ColumnSet* column_set = layout->AddColumnSet(double_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - - // Add Encoding Combobox. - layout->StartRow(0, double_column_view_set_id); - layout->AddView(default_encoding_combobox_label_); - layout->AddView(default_encoding_combobox_, 1, 1, GridLayout::FILL, - GridLayout::CENTER); -} diff --git a/chrome/browser/ui/views/options/fonts_page_view.h b/chrome/browser/ui/views/options/fonts_page_view.h deleted file mode 100644 index 6891fda..0000000 --- a/chrome/browser/ui/views/options/fonts_page_view.h +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_FONTS_PAGE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_FONTS_PAGE_VIEW_H_ -#pragma once - -#include <string> - -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/shell_dialogs.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "views/controls/combobox/combobox.h" -#include "views/controls/button/button.h" -#include "views/view.h" - -class DefaultEncodingComboboxModel; -class FontDisplayView; - -namespace views { -class GroupboxView; -class Label; -class NativeButton; -class TableView; -} - -/////////////////////////////////////////////////////////////////////////////// -// FontsPageView - -class FontsPageView : public OptionsPageView, - public views::Combobox::Listener, - public SelectFontDialog::Listener, - public views::ButtonListener { - public: - explicit FontsPageView(Profile* profile); - - // views::ButtonListener implementation: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // views::Combobox::Listener implementation: - virtual void ItemChanged(views::Combobox* combo_box, - int prev_index, - int new_index); - - // SelectFontDialog::Listener implementation: - virtual void FontSelected(const gfx::Font& font, void* params); - - // Save Changes made to relevent pref members associated with this tab. - // This is public since it is called by FontsLanguageWindowView in its - // Dialog Delegate Accept() method. - void SaveChanges(); - - protected: - // OptionsPageView implementation: - virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::string* pref_name); - - private: - enum FontTypeBeingChanged { - NONE, - SERIF, - SANS_SERIF, - FIXED_WIDTH - }; - - virtual ~FontsPageView(); - - // Init Dialog controls. - void InitFontLayout(); - void InitEncodingLayout(); - - bool serif_button_pressed_; - bool sans_serif_button_pressed_; - bool fixed_width_button_pressed_; - bool encoding_dropdown_clicked_; - - views::Label* fonts_group_title_; - views::Label* encoding_group_title_; - - views::View* fonts_contents_; - views::View* encoding_contents_; - - // Fonts settings. - // Select Font dialogs. - scoped_refptr<SelectFontDialog> select_font_dialog_; - - // Buttons. - views::NativeButton* fixed_width_font_change_page_button_; - views::NativeButton* serif_font_change_page_button_; - views::NativeButton* sans_serif_font_change_page_button_; - - // FontDisplayView objects to display selected font. - FontDisplayView* fixed_width_font_display_view_; - FontDisplayView* serif_font_display_view_; - FontDisplayView* sans_serif_font_display_view_; - - // Labels to describe what is to be changed. - views::Label* fixed_width_font_label_; - views::Label* serif_font_label_; - views::Label* sans_serif_font_label_; - - // Advanced Font names and sizes as PrefMembers. - StringPrefMember serif_name_; - StringPrefMember sans_serif_name_; - StringPrefMember fixed_width_name_; - IntegerPrefMember serif_size_; - IntegerPrefMember sans_serif_size_; - IntegerPrefMember fixed_width_size_; - int serif_font_size_pixel_; - int sans_serif_font_size_pixel_; - int fixed_width_font_size_pixel_; - StringPrefMember default_encoding_; - bool font_changed_; - - // Windows font picker flag; - FontTypeBeingChanged font_type_being_changed_; - - // Default Encoding. - scoped_ptr<DefaultEncodingComboboxModel> default_encoding_combobox_model_; - views::Label* default_encoding_combobox_label_; - views::Combobox* default_encoding_combobox_; - std::string default_encoding_selected_; - bool default_encoding_changed_; - - DISALLOW_COPY_AND_ASSIGN(FontsPageView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_FONTS_PAGE_VIEW_H_ diff --git a/chrome/browser/ui/views/options/general_page_view.cc b/chrome/browser/ui/views/options/general_page_view.cc deleted file mode 100644 index 9b618be..0000000 --- a/chrome/browser/ui/views/options/general_page_view.cc +++ /dev/null @@ -1,913 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/general_page_view.h" - -#include <string> -#include <vector> - -#include "base/callback.h" -#include "base/message_loop.h" -#include "base/string16.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/browser_window.h" -#include "chrome/browser/custom_home_pages_table_model.h" -#include "chrome/browser/instant/instant_confirm_dialog.h" -#include "chrome/browser/instant/instant_controller.h" -#include "chrome/browser/net/url_fixer_upper.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/prefs/session_startup_pref.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/search_engines/template_url.h" -#include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/browser/search_engines/template_url_model_observer.h" -#include "chrome/browser/ui/options/show_options_url.h" -#include "chrome/browser/ui/views/keyword_editor_view.h" -#include "chrome/browser/ui/views/options/managed_prefs_banner_view.h" -#include "chrome/browser/ui/views/options/options_group_view.h" -#include "chrome/browser/ui/webui/new_tab_ui.h" -#include "chrome/common/chrome_constants.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "chrome/installer/util/browser_distribution.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/models/combobox_model.h" -#include "views/controls/button/radio_button.h" -#include "views/controls/label.h" -#include "views/controls/table/table_view.h" -#include "views/controls/textfield/textfield.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" - -namespace { - -// All the options pages are in the same view hierarchy. This means we need to -// make sure group identifiers don't collide across different pages. -const int kStartupRadioGroup = 101; -const int kHomePageRadioGroup = 102; -const SkColor kDefaultBrowserLabelColor = SkColorSetRGB(0, 135, 0); -const SkColor kNotDefaultBrowserLabelColor = SkColorSetRGB(135, 0, 0); -const int kHomePageTextfieldWidthChars = 40; - -bool IsNewTabUIURLString(const GURL& url) { - return url == GURL(chrome::kChromeUINewTabURL); -} -} // namespace - -/////////////////////////////////////////////////////////////////////////////// -// OptionsGroupContents -class OptionsGroupContents : public views::View { - public: - OptionsGroupContents() { } - - // views::View overrides: - virtual AccessibilityTypes::Role GetAccessibleRole() { - return AccessibilityTypes::ROLE_GROUPING; - } - - private: - DISALLOW_COPY_AND_ASSIGN(OptionsGroupContents); -}; - -/////////////////////////////////////////////////////////////////////////////// -// SearchEngineListModel - -class SearchEngineListModel : public ui::ComboboxModel, - public TemplateURLModelObserver { - public: - explicit SearchEngineListModel(Profile* profile); - virtual ~SearchEngineListModel(); - - // Sets the Combobox. SearchEngineListModel needs a handle to the Combobox - // so that when the TemplateURLModel changes the combobox can be updated. - void SetCombobox(views::Combobox* combobox); - - // ui::ComboboxModel overrides: - virtual int GetItemCount(); - virtual string16 GetItemAt(int index); - - // Returns the TemplateURL at the specified index. - const TemplateURL* GetTemplateURLAt(int index); - - TemplateURLModel* model() { return template_url_model_; } - - private: - // TemplateURLModelObserver methods. - virtual void OnTemplateURLModelChanged(); - - // Recalculates the TemplateURLs to display and notifies the combobox. - void ResetContents(); - - // Resets the selection of the combobox based on the users selected search - // engine. - void ChangeComboboxSelection(); - - TemplateURLModel* template_url_model_; - - // The combobox hosting us. - views::Combobox* combobox_; - - // The TemplateURLs we're showing. - typedef std::vector<const TemplateURL*> TemplateURLs; - TemplateURLs template_urls_; - - DISALLOW_COPY_AND_ASSIGN(SearchEngineListModel); -}; - -SearchEngineListModel::SearchEngineListModel(Profile* profile) - : template_url_model_(profile->GetTemplateURLModel()), - combobox_(NULL) { - if (template_url_model_) { - template_url_model_->Load(); - template_url_model_->AddObserver(this); - } - ResetContents(); -} - -SearchEngineListModel::~SearchEngineListModel() { - if (template_url_model_) - template_url_model_->RemoveObserver(this); -} - -void SearchEngineListModel::SetCombobox(views::Combobox* combobox) { - combobox_ = combobox; - if (template_url_model_ && template_url_model_->loaded()) - ChangeComboboxSelection(); - else - combobox_->SetEnabled(false); -} - -int SearchEngineListModel::GetItemCount() { - return static_cast<int>(template_urls_.size()); -} - -string16 SearchEngineListModel::GetItemAt(int index) { - DCHECK(index < GetItemCount()); - return WideToUTF16Hack(template_urls_[index]->short_name()); -} - -const TemplateURL* SearchEngineListModel::GetTemplateURLAt(int index) { - DCHECK(index >= 0 && index < static_cast<int>(template_urls_.size())); - return template_urls_[static_cast<int>(index)]; -} - -void SearchEngineListModel::OnTemplateURLModelChanged() { - ResetContents(); -} - -void SearchEngineListModel::ResetContents() { - if (!template_url_model_ || !template_url_model_->loaded()) - return; - template_urls_.clear(); - TemplateURLs model_urls = template_url_model_->GetTemplateURLs(); - for (size_t i = 0; i < model_urls.size(); ++i) { - if (model_urls[i]->ShowInDefaultList()) - template_urls_.push_back(model_urls[i]); - } - - if (combobox_) { - combobox_->ModelChanged(); - ChangeComboboxSelection(); - } -} - -void SearchEngineListModel::ChangeComboboxSelection() { - if (template_urls_.size()) { - const TemplateURL* default_search_provider = - template_url_model_->GetDefaultSearchProvider(); - if (default_search_provider) { - TemplateURLs::iterator i = - find(template_urls_.begin(), template_urls_.end(), - default_search_provider); - if (i != template_urls_.end()) { - combobox_->SetSelectedItem( - static_cast<int>(i - template_urls_.begin())); - } - } else { - combobox_->SetSelectedItem(-1); - } - } - // If the default search is managed or there are no URLs, disable the control. - combobox_->SetEnabled(!template_urls_.empty() && - !template_url_model_->is_default_search_managed()); -} - -/////////////////////////////////////////////////////////////////////////////// -// GeneralPageView, public: - -GeneralPageView::GeneralPageView(Profile* profile) - : startup_group_(NULL), - startup_homepage_radio_(NULL), - startup_last_session_radio_(NULL), - startup_custom_radio_(NULL), - startup_add_custom_page_button_(NULL), - startup_remove_custom_page_button_(NULL), - startup_use_current_page_button_(NULL), - startup_custom_pages_table_(NULL), - homepage_group_(NULL), - homepage_use_newtab_radio_(NULL), - homepage_use_url_radio_(NULL), - homepage_use_url_textfield_(NULL), - homepage_show_home_button_checkbox_(NULL), - default_search_group_(NULL), - default_search_manage_engines_button_(NULL), - instant_checkbox_(NULL), - instant_link_(NULL), - default_browser_group_(NULL), - default_browser_status_label_(NULL), - default_browser_use_as_default_button_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST( - default_browser_worker_( - new ShellIntegration::DefaultBrowserWorker(this))), - OptionsPageView(profile) { -} - -GeneralPageView::~GeneralPageView() { - if (startup_custom_pages_table_) - startup_custom_pages_table_->SetModel(NULL); - default_browser_worker_->ObserverDestroyed(); -} - -/////////////////////////////////////////////////////////////////////////////// -// GeneralPageView, views::ButtonListener implementation: - -void GeneralPageView::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender == startup_homepage_radio_ || - sender == startup_last_session_radio_ || - sender == startup_custom_radio_) { - SaveStartupPref(); - if (sender == startup_homepage_radio_) { - UserMetricsRecordAction(UserMetricsAction("Options_Startup_Homepage"), - profile()->GetPrefs()); - } else if (sender == startup_last_session_radio_) { - UserMetricsRecordAction(UserMetricsAction("Options_Startup_LastSession"), - profile()->GetPrefs()); - } else if (sender == startup_custom_radio_) { - UserMetricsRecordAction(UserMetricsAction("Options_Startup_Custom"), - profile()->GetPrefs()); - } - } else if (sender == startup_add_custom_page_button_) { - AddURLToStartupURLs(); - } else if (sender == startup_remove_custom_page_button_) { - RemoveURLsFromStartupURLs(); - } else if (sender == startup_use_current_page_button_) { - SetStartupURLToCurrentPage(); - } else if (sender == homepage_use_newtab_radio_) { - UserMetricsRecordAction(UserMetricsAction("Options_Homepage_UseNewTab"), - profile()->GetPrefs()); - UpdateHomepagePrefs(); - EnableHomepageURLField(false); - } else if (sender == homepage_use_url_radio_) { - UserMetricsRecordAction(UserMetricsAction("Options_Homepage_UseURL"), - profile()->GetPrefs()); - UpdateHomepagePrefs(); - EnableHomepageURLField(true); - } else if (sender == homepage_show_home_button_checkbox_) { - bool show_button = homepage_show_home_button_checkbox_->checked(); - if (show_button) { - UserMetricsRecordAction( - UserMetricsAction("Options_Homepage_ShowHomeButton"), - profile()->GetPrefs()); - } else { - UserMetricsRecordAction( - UserMetricsAction("Options_Homepage_HideHomeButton"), - profile()->GetPrefs()); - } - show_home_button_.SetValue(show_button); - } else if (sender == default_browser_use_as_default_button_) { - default_browser_worker_->StartSetAsDefaultBrowser(); - UserMetricsRecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"), - NULL); - // If the user made Chrome the default browser, then he/she arguably wants - // to be notified when that changes. - profile()->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); - } else if (sender == default_search_manage_engines_button_) { - UserMetricsRecordAction(UserMetricsAction("Options_ManageSearchEngines"), - NULL); - KeywordEditorView::Show(profile()); - } else if (sender == instant_checkbox_) { - if (instant_checkbox_->checked()) { - // Don't toggle immediately, instead let - // ShowInstantConfirmDialogIfNecessary do it. - instant_checkbox_->SetChecked(false); - browser::ShowInstantConfirmDialogIfNecessary( - GetWindow()->GetNativeWindow(), profile()); - } else { - InstantController::Disable(profile()); - } - } -} - -/////////////////////////////////////////////////////////////////////////////// -// GeneralPageView, views::Combobox::Listener implementation: - -void GeneralPageView::ItemChanged(views::Combobox* combobox, - int prev_index, int new_index) { - if (combobox == default_search_engine_combobox_) { - SetDefaultSearchProvider(); - UserMetricsRecordAction(UserMetricsAction("Options_SearchEngineChanged"), - NULL); - } -} - -/////////////////////////////////////////////////////////////////////////////// -// GeneralPageView, views::Textfield:Controller implementation: - -void GeneralPageView::ContentsChanged(views::Textfield* sender, - const std::wstring& new_contents) { - if (sender == homepage_use_url_textfield_) { - UpdateHomepagePrefs(); - } -} - -bool GeneralPageView::HandleKeyEvent(views::Textfield* sender, - const views::KeyEvent& key_event) { - return false; -} - -/////////////////////////////////////////////////////////////////////////////// -// GeneralPageView, OptionsPageView implementation: - -void GeneralPageView::InitControlLayout() { - using views::GridLayout; - using views::ColumnSet; - - GridLayout* layout = new GridLayout(this); - layout->SetInsets(5, 5, 5, 5); - SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_view_set_id); - layout->AddView( - new ManagedPrefsBannerView(profile()->GetPrefs(), OPTIONS_PAGE_GENERAL)); - - layout->StartRow(0, single_column_view_set_id); - InitStartupGroup(); - layout->AddView(startup_group_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - layout->StartRow(0, single_column_view_set_id); - InitHomepageGroup(); - layout->AddView(homepage_group_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - layout->StartRow(0, single_column_view_set_id); - InitDefaultSearchGroup(); - layout->AddView(default_search_group_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - -#if !defined(OS_CHROMEOS) - layout->StartRow(0, single_column_view_set_id); - InitDefaultBrowserGroup(); - layout->AddView(default_browser_group_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); -#endif - - // Register pref observers that update the controls when a pref changes. - registrar_.Init(profile()->GetPrefs()); - registrar_.Add(prefs::kRestoreOnStartup, this); - registrar_.Add(prefs::kURLsToRestoreOnStartup, this); - registrar_.Add(prefs::kInstantEnabled, this); - - new_tab_page_is_home_page_.Init(prefs::kHomePageIsNewTabPage, - profile()->GetPrefs(), this); - homepage_.Init(prefs::kHomePage, profile()->GetPrefs(), this); - show_home_button_.Init(prefs::kShowHomeButton, profile()->GetPrefs(), this); - default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled, - g_browser_process->local_state(), - this); -} - -void GeneralPageView::NotifyPrefChanged(const std::string* pref_name) { - PrefService* prefs = profile()->GetPrefs(); - if (!pref_name || - *pref_name == prefs::kRestoreOnStartup || - *pref_name == prefs::kURLsToRestoreOnStartup) { - const SessionStartupPref startup_pref = - SessionStartupPref::GetStartupPref(prefs); - bool radio_buttons_enabled = !SessionStartupPref::TypeIsManaged(prefs); - bool restore_urls_enabled = !SessionStartupPref::URLsAreManaged(prefs); - switch (startup_pref.type) { - case SessionStartupPref::DEFAULT: - startup_homepage_radio_->SetChecked(true); - restore_urls_enabled = false; - break; - - case SessionStartupPref::LAST: - startup_last_session_radio_->SetChecked(true); - restore_urls_enabled = false; - break; - - case SessionStartupPref::URLS: - startup_custom_radio_->SetChecked(true); - break; - } - startup_homepage_radio_->SetEnabled(radio_buttons_enabled); - startup_last_session_radio_->SetEnabled(radio_buttons_enabled); - startup_custom_radio_->SetEnabled(radio_buttons_enabled); - EnableCustomHomepagesControls(restore_urls_enabled); - startup_custom_pages_table_model_->SetURLs(startup_pref.urls); - } - - if (!pref_name || - *pref_name == prefs::kHomePageIsNewTabPage || - *pref_name == prefs::kHomePage) { - bool new_tab_page_is_home_page_managed = - new_tab_page_is_home_page_.IsManaged(); - bool homepage_managed = homepage_.IsManaged(); - bool homepage_url_is_new_tab = - IsNewTabUIURLString(GURL(homepage_.GetValue())); - bool homepage_is_new_tab = homepage_url_is_new_tab || - new_tab_page_is_home_page_.GetValue(); - // If HomepageIsNewTab is managed or - // Homepage is 'chrome://newtab' and managed, disable the radios. - bool disable_homepage_choice_buttons = - new_tab_page_is_home_page_managed || - homepage_managed && homepage_url_is_new_tab; - if (!homepage_url_is_new_tab) - homepage_use_url_textfield_->SetText(UTF8ToWide(homepage_.GetValue())); - UpdateHomepageIsNewTabRadio( - homepage_is_new_tab, !disable_homepage_choice_buttons); - EnableHomepageURLField(!homepage_is_new_tab); - } - - if (!pref_name || *pref_name == prefs::kShowHomeButton) { - homepage_show_home_button_checkbox_->SetChecked( - show_home_button_.GetValue()); - homepage_show_home_button_checkbox_->SetEnabled( - !show_home_button_.IsManaged()); - } - - if (!pref_name || *pref_name == prefs::kInstantEnabled) - instant_checkbox_->SetChecked(prefs->GetBoolean(prefs::kInstantEnabled)); - - if (!pref_name || *pref_name == prefs::kDefaultBrowserSettingEnabled) { - // If the option is managed the UI is uncondionally disabled otherwise we - // restart the standard button enabling logic. - if (default_browser_policy_.IsManaged()) - default_browser_use_as_default_button_->SetEnabled(false); - else - default_browser_worker_->StartCheckDefaultBrowser(); - } -} - -void GeneralPageView::HighlightGroup(OptionsGroup highlight_group) { - if (highlight_group == OPTIONS_GROUP_DEFAULT_SEARCH) - default_search_group_->SetHighlighted(true); -} - -void GeneralPageView::LinkActivated(views::Link* source, int event_flags) { - DCHECK(source == instant_link_); - browser::ShowOptionsURL(profile(), browser::InstantLearnMoreURL()); -} - -/////////////////////////////////////////////////////////////////////////////// -// GeneralPageView, private: - -void GeneralPageView::SetDefaultBrowserUIState( - ShellIntegration::DefaultBrowserUIState state) { - bool button_enabled = - (state == ShellIntegration::STATE_NOT_DEFAULT) && - !default_browser_policy_.IsManaged(); - default_browser_use_as_default_button_->SetEnabled(button_enabled); - default_browser_use_as_default_button_->SetNeedElevation(true); - if (state == ShellIntegration::STATE_IS_DEFAULT) { - default_browser_status_label_->SetText(UTF16ToWide( - l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_DEFAULT, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)))); - default_browser_status_label_->SetColor(kDefaultBrowserLabelColor); - Layout(); - } else if (state == ShellIntegration::STATE_NOT_DEFAULT) { - default_browser_status_label_->SetText(UTF16ToWide( - l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)))); - default_browser_status_label_->SetColor(kNotDefaultBrowserLabelColor); - Layout(); - } else if (state == ShellIntegration::STATE_UNKNOWN) { - default_browser_status_label_->SetText(UTF16ToWide( - l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)))); - default_browser_status_label_->SetColor(kNotDefaultBrowserLabelColor); - Layout(); - } -} - -void GeneralPageView::SetDefaultBrowserUIStateForSxS() { - default_browser_use_as_default_button_->SetEnabled(false); - default_browser_status_label_->SetText(UTF16ToWide( - l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_SXS, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)))); - default_browser_status_label_->SetColor(kNotDefaultBrowserLabelColor); - Layout(); -} - -void GeneralPageView::InitStartupGroup() { - startup_homepage_radio_ = new views::RadioButton(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_STARTUP_SHOW_DEFAULT_AND_NEWTAB)), - kStartupRadioGroup); - startup_homepage_radio_->set_listener(this); - startup_last_session_radio_ = new views::RadioButton(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_STARTUP_SHOW_LAST_SESSION)), - kStartupRadioGroup); - startup_last_session_radio_->set_listener(this); - startup_last_session_radio_->SetMultiLine(true); - startup_custom_radio_ = new views::RadioButton( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_STARTUP_SHOW_PAGES)), - kStartupRadioGroup); - startup_custom_radio_->set_listener(this); - startup_add_custom_page_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_STARTUP_ADD_BUTTON))); - startup_remove_custom_page_button_ = new views::NativeButton( - this, - UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_STARTUP_REMOVE_BUTTON))); - startup_remove_custom_page_button_->SetEnabled(false); - startup_use_current_page_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_STARTUP_USE_CURRENT))); - - startup_custom_pages_table_model_.reset( - new CustomHomePagesTableModel(profile())); - std::vector<TableColumn> columns; - columns.push_back(TableColumn()); - startup_custom_pages_table_ = new views::TableView( - startup_custom_pages_table_model_.get(), columns, - views::ICON_AND_TEXT, false, false, true); - startup_custom_pages_table_->SetObserver(this); - - using views::GridLayout; - using views::ColumnSet; - - views::View* contents = new OptionsGroupContents; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - - const int double_column_view_set_id = 1; - column_set = layout->AddColumnSet(double_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_view_set_id); - layout->AddView(startup_homepage_radio_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(startup_last_session_radio_, 1, 1, - GridLayout::FILL, GridLayout::LEADING); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(startup_custom_radio_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - layout->StartRow(0, double_column_view_set_id); - layout->AddView(startup_custom_pages_table_, 1, 1, - GridLayout::FILL, GridLayout::FILL); - - views::View* button_stack = new views::View; - GridLayout* button_stack_layout = new GridLayout(button_stack); - button_stack->SetLayoutManager(button_stack_layout); - - column_set = button_stack_layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - button_stack_layout->StartRow(0, single_column_view_set_id); - button_stack_layout->AddView(startup_add_custom_page_button_, - 1, 1, GridLayout::FILL, GridLayout::CENTER); - button_stack_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - button_stack_layout->StartRow(0, single_column_view_set_id); - button_stack_layout->AddView(startup_remove_custom_page_button_, - 1, 1, GridLayout::FILL, GridLayout::CENTER); - button_stack_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - button_stack_layout->StartRow(0, single_column_view_set_id); - button_stack_layout->AddView(startup_use_current_page_button_, - 1, 1, GridLayout::FILL, GridLayout::CENTER); - layout->AddView(button_stack); - - startup_group_ = new OptionsGroupView( - contents, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_STARTUP_GROUP_NAME)), - std::wstring(), true); -} - -void GeneralPageView::InitHomepageGroup() { - homepage_use_newtab_radio_ = new views::RadioButton( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_HOMEPAGE_USE_NEWTAB)), - kHomePageRadioGroup); - homepage_use_newtab_radio_->set_listener(this); - homepage_use_newtab_radio_->SetMultiLine(true); - homepage_use_url_radio_ = new views::RadioButton( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_HOMEPAGE_USE_URL)), - kHomePageRadioGroup); - homepage_use_url_radio_->set_listener(this); - homepage_use_url_textfield_ = new views::Textfield; - homepage_use_url_textfield_->SetController(this); - homepage_use_url_textfield_->set_default_width_in_chars( - kHomePageTextfieldWidthChars); - homepage_show_home_button_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_HOMEPAGE_SHOW_BUTTON))); - homepage_show_home_button_checkbox_->set_listener(this); - homepage_show_home_button_checkbox_->SetMultiLine(true); - - using views::GridLayout; - using views::ColumnSet; - - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - - const int double_column_view_set_id = 1; - column_set = layout->AddColumnSet(double_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_view_set_id); - layout->AddView(homepage_use_newtab_radio_, 1, 1, - GridLayout::FILL, GridLayout::LEADING); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, double_column_view_set_id); - layout->AddView(homepage_use_url_radio_); - layout->AddView(homepage_use_url_textfield_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(homepage_show_home_button_checkbox_, 1, 1, - GridLayout::FILL, GridLayout::LEADING); - - homepage_group_ = new OptionsGroupView( - contents, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_HOMEPAGE_GROUP_NAME)), - std::wstring(), true); -} - - -void GeneralPageView::InitDefaultSearchGroup() { - default_search_engines_model_.reset(new SearchEngineListModel(profile())); - default_search_engine_combobox_ = - new views::Combobox(default_search_engines_model_.get()); - default_search_engines_model_->SetCombobox(default_search_engine_combobox_); - default_search_engine_combobox_->set_listener(this); - - default_search_manage_engines_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK))); - - instant_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_INSTANT_PREF))); - instant_checkbox_->SetMultiLine(false); - instant_checkbox_->set_listener(this); - - instant_link_ = new views::Link(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_LEARN_MORE))); - instant_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - instant_link_->SetController(this); - - using views::GridLayout; - using views::ColumnSet; - - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - const int double_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(double_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - const int checkbox_column_view_set_id = 1; - column_set = layout->AddColumnSet(checkbox_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - const int link_column_set_id = 2; - column_set = layout->AddColumnSet(link_column_set_id); - // TODO(sky): this isn't right, we need a method to determine real indent. - column_set->AddPaddingColumn(0, views::Checkbox::GetTextIndent() + 3); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, double_column_view_set_id); - layout->AddView(default_search_engine_combobox_); - layout->AddView(default_search_manage_engines_button_); - layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); - - layout->StartRow(0, checkbox_column_view_set_id); - layout->AddView(instant_checkbox_); - layout->AddPaddingRow(0, 0); - - layout->StartRow(0, link_column_set_id); - layout->AddView(new views::Label(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_INSTANT_PREF_WARNING)))); - layout->AddView(instant_link_); - - default_search_group_ = new OptionsGroupView( - contents, - UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME)), - std::wstring(), true); -} - -void GeneralPageView::InitDefaultBrowserGroup() { - default_browser_status_label_ = new views::Label; - default_browser_status_label_->SetMultiLine(true); - default_browser_status_label_->SetHorizontalAlignment( - views::Label::ALIGN_LEFT); - default_browser_use_as_default_button_ = new views::NativeButton( - this, - UTF16ToWide( - l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)))); - - using views::GridLayout; - using views::ColumnSet; - - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_view_set_id); - layout->AddView(default_browser_status_label_, 1, 1, - GridLayout::FILL, GridLayout::LEADING); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(default_browser_use_as_default_button_); - - default_browser_group_ = new OptionsGroupView( - contents, - UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME)), - std::wstring(), false); - - if (BrowserDistribution::GetDistribution()->CanSetAsDefault()) - default_browser_worker_->StartCheckDefaultBrowser(); - else - SetDefaultBrowserUIStateForSxS(); -} - -void GeneralPageView::SaveStartupPref() { - SessionStartupPref pref; - - if (startup_last_session_radio_->checked()) { - pref.type = SessionStartupPref::LAST; - } else if (startup_custom_radio_->checked()) { - pref.type = SessionStartupPref::URLS; - } - - pref.urls = startup_custom_pages_table_model_->GetURLs(); - - SessionStartupPref::SetStartupPref(profile()->GetPrefs(), pref); -} - -void GeneralPageView::AddURLToStartupURLs() { - UrlPicker* dialog = new UrlPicker(this, profile()); - dialog->Show(GetWindow()->GetNativeWindow()); -} - -void GeneralPageView::RemoveURLsFromStartupURLs() { - int selected_row = 0; - for (views::TableView::iterator i = - startup_custom_pages_table_->SelectionBegin(); - i != startup_custom_pages_table_->SelectionEnd(); ++i) { - startup_custom_pages_table_model_->Remove(*i); - selected_row = *i; - } - int row_count = startup_custom_pages_table_->RowCount(); - if (selected_row >= row_count) - selected_row = row_count - 1; - if (selected_row >= 0) { - // Select the next row after the last row deleted, or the above item if the - // latest item was deleted or nothing when the table doesn't have any items. - startup_custom_pages_table_->Select(selected_row); - } - SaveStartupPref(); -} - -void GeneralPageView::SetStartupURLToCurrentPage() { - startup_custom_pages_table_model_->SetToCurrentlyOpenPages(); - - SaveStartupPref(); -} - -void GeneralPageView::EnableCustomHomepagesControls(bool enable) { - startup_add_custom_page_button_->SetEnabled(enable); - bool has_selected_rows = startup_custom_pages_table_->SelectedRowCount() > 0; - startup_remove_custom_page_button_->SetEnabled(enable && has_selected_rows); - startup_use_current_page_button_->SetEnabled(enable); - startup_custom_pages_table_->SetEnabled(enable); -} - -void GeneralPageView::AddBookmark(UrlPicker* dialog, - const std::wstring& title, - const GURL& url) { - // The restore URLs policy might have become managed while the dialog is - // displayed. While the model makes sure that no changes are made in this - // condition, we should still avoid changing the graphic elements. - if (SessionStartupPref::URLsAreManaged(profile()->GetPrefs())) - return; - int index = startup_custom_pages_table_->FirstSelectedRow(); - if (index == -1) - index = startup_custom_pages_table_model_->RowCount(); - else - index++; - startup_custom_pages_table_model_->Add(index, url); - startup_custom_pages_table_->Select(index); - - SaveStartupPref(); -} - -void GeneralPageView::UpdateHomepagePrefs() { - // If the text field contains a valid URL, sync it to prefs. We run it - // through the fixer upper to allow input like "google.com" to be converted - // to something valid ("http://google.com"). If the field contains an - // empty or null-host URL, a blank homepage is synced to prefs. - const GURL& homepage = - URLFixerUpper::FixupURL( - UTF16ToUTF8(homepage_use_url_textfield_->text()), std::string()); - bool new_tab_page_is_home_page = homepage_use_newtab_radio_->checked(); - if (IsNewTabUIURLString(homepage)) { // 'chrome://newtab/' - // This should be handled differently than invalid URLs. - // When the control arrives here, then |homepage| contains - // 'chrome://newtab/', and the homepage preference contains the previous - // valid content of the textfield (fixed up), most likely - // 'chrome://newta/'. This has to be cleared, because keeping it makes no - // sense to the user. - new_tab_page_is_home_page = true; - homepage_.SetValueIfNotManaged(std::string()); - } else if (!homepage.is_valid()) { - new_tab_page_is_home_page = true; - // The URL is invalid either with a host (e.g. http://chr%mium.org) - // or without a host (e.g. http://). In case there is a host, then - // the URL is not cleared, saving a fragment of the URL to the - // preferences (e.g. http://chr in case the characters of the above example - // were typed by the user one by one). - // See bug 40996. - if (!homepage.has_host()) - homepage_.SetValueIfNotManaged(std::string()); - } else { - homepage_.SetValueIfNotManaged(homepage.spec()); - } - new_tab_page_is_home_page_.SetValueIfNotManaged(new_tab_page_is_home_page); -} - -void GeneralPageView::UpdateHomepageIsNewTabRadio(bool homepage_is_new_tab, - bool enabled) { - homepage_use_newtab_radio_->SetChecked(homepage_is_new_tab); - homepage_use_url_radio_->SetChecked(!homepage_is_new_tab); - homepage_use_newtab_radio_->SetEnabled(enabled); - homepage_use_url_radio_->SetEnabled(enabled); -} - -void GeneralPageView::OnSelectionChanged() { - startup_remove_custom_page_button_->SetEnabled( - startup_custom_pages_table_->SelectedRowCount() > 0); -} - -void GeneralPageView::EnableHomepageURLField(bool enabled) { - if (homepage_.IsManaged()) { - enabled = false; - } - homepage_use_url_textfield_->SetEnabled(enabled); - homepage_use_url_textfield_->SetReadOnly(!enabled); -} - -void GeneralPageView::SetDefaultSearchProvider() { - const int index = default_search_engine_combobox_->selected_item(); - default_search_engines_model_->model()->SetDefaultSearchProvider( - default_search_engines_model_->GetTemplateURLAt(index)); -} diff --git a/chrome/browser/ui/views/options/general_page_view.h b/chrome/browser/ui/views/options/general_page_view.h deleted file mode 100644 index 56e4396..0000000 --- a/chrome/browser/ui/views/options/general_page_view.h +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_GENERAL_PAGE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_GENERAL_PAGE_VIEW_H_ -#pragma once - -#include "chrome/browser/prefs/pref_change_registrar.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/shell_integration.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "chrome/browser/ui/views/url_picker.h" -#include "views/controls/button/button.h" -#include "views/controls/combobox/combobox.h" -#include "views/controls/link.h" -#include "views/controls/table/table_view_observer.h" -#include "views/controls/textfield/textfield_controller.h" -#include "views/view.h" - -class CustomHomePagesTableModel; -class OptionsGroupView; -class SearchEngineListModel; - -namespace views { -class Checkbox; -class GroupboxView; -class Label; -class NativeButton; -class RadioButton; -class TableView; -class Textfield; -} - -/////////////////////////////////////////////////////////////////////////////// -// GeneralPageView - -class GeneralPageView : public OptionsPageView, - public views::Combobox::Listener, - public views::ButtonListener, - public views::TextfieldController, - public UrlPickerDelegate, - public views::TableViewObserver, - public ShellIntegration::DefaultBrowserObserver, - public views::LinkController { - public: - explicit GeneralPageView(Profile* profile); - virtual ~GeneralPageView(); - - protected: - // views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // views::Combobox::Listener: - virtual void ItemChanged(views::Combobox* combobox, - int prev_index, - int new_index); - - // views::TextfieldController: - virtual void ContentsChanged(views::Textfield* sender, - const std::wstring& new_contents); - virtual bool HandleKeyEvent(views::Textfield* sender, - const views::KeyEvent& key_event); - - // OptionsPageView: - virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::string* pref_name); - virtual void HighlightGroup(OptionsGroup highlight_group); - - // views::LinkController: - virtual void LinkActivated(views::Link* source, int event_flags); - - private: - // ShellIntegration::DefaultBrowserObserver implementation: - // Updates the UI state to reflect the current default browser state. - virtual void SetDefaultBrowserUIState( - ShellIntegration::DefaultBrowserUIState state); - - // For Side by Side installs, this will disable the Default Browser setting - // and display an explanitory message. - void SetDefaultBrowserUIStateForSxS(); - - // Init all the dialog controls - void InitStartupGroup(); - void InitHomepageGroup(); - void InitDefaultSearchGroup(); - void InitDefaultBrowserGroup(); - - // Saves the startup preference from that of the ui. - void SaveStartupPref(); - - // Shows a dialog allowing the user to add a new URL to the set of URLs - // launched on startup. - void AddURLToStartupURLs(); - - // Removes the selected URL from the list of startup urls. - void RemoveURLsFromStartupURLs(); - - // Resets the list of urls to launch on startup from the list of open - // browsers. - void SetStartupURLToCurrentPage(); - - // Enables/Disables the controls associated with the custom start pages - // option if that preference is not selected. - void EnableCustomHomepagesControls(bool enable); - - // UrlPickerDelegate. Adds the URL to the list of startup urls. - virtual void AddBookmark(UrlPicker* dialog, - const std::wstring& title, - const GURL& url); - - // Copies the home page preferences from the gui controls to - // kNewTabPageIsHomePage and kHomePage. If an empty or null-host - // URL is specified, then we revert to using NewTab page as the Homepage. - void UpdateHomepagePrefs(); - - // Invoked when the selection of the table view changes. Updates the enabled - // property of the remove button. - virtual void OnSelectionChanged(); - - // Enables or disables the field for entering a custom homepage URL. - void EnableHomepageURLField(bool enabled); - - // Sets the state and enables/disables the radio buttons that control - // if the home page is the new tab page. - void UpdateHomepageIsNewTabRadio(bool homepage_is_new_tab, bool enabled); - - // Sets the default search provider for the selected item in the combobox. - void SetDefaultSearchProvider(); - - // Controls for the Startup group - OptionsGroupView* startup_group_; - views::RadioButton* startup_homepage_radio_; - views::RadioButton* startup_last_session_radio_; - views::RadioButton* startup_custom_radio_; - views::NativeButton* startup_add_custom_page_button_; - views::NativeButton* startup_remove_custom_page_button_; - views::NativeButton* startup_use_current_page_button_; - views::TableView* startup_custom_pages_table_; - scoped_ptr<CustomHomePagesTableModel> startup_custom_pages_table_model_; - - // Controls for the Home Page group - OptionsGroupView* homepage_group_; - views::RadioButton* homepage_use_newtab_radio_; - views::RadioButton* homepage_use_url_radio_; - views::Textfield* homepage_use_url_textfield_; - views::Checkbox* homepage_show_home_button_checkbox_; - BooleanPrefMember new_tab_page_is_home_page_; - StringPrefMember homepage_; - BooleanPrefMember show_home_button_; - - // Controls for the Search group - OptionsGroupView* default_search_group_; - views::Combobox* default_search_engine_combobox_; - views::NativeButton* default_search_manage_engines_button_; - scoped_ptr<SearchEngineListModel> default_search_engines_model_; - views::Checkbox* instant_checkbox_; - views::Link* instant_link_; - - // Controls for the Default Browser group - OptionsGroupView* default_browser_group_; - views::Label* default_browser_status_label_; - views::NativeButton* default_browser_use_as_default_button_; - BooleanPrefMember default_browser_policy_; - - // The helper object that performs default browser set/check tasks. - scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_; - - PrefChangeRegistrar registrar_; - - DISALLOW_COPY_AND_ASSIGN(GeneralPageView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_GENERAL_PAGE_VIEW_H_ diff --git a/chrome/browser/ui/views/options/languages_page_view.cc b/chrome/browser/ui/views/options/languages_page_view.cc deleted file mode 100644 index f260202..0000000 --- a/chrome/browser/ui/views/options/languages_page_view.cc +++ /dev/null @@ -1,588 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <windows.h> -#include <shlobj.h> -#include <vsstyle.h> -#include <vssym32.h> - -#include "chrome/browser/ui/views/options/languages_page_view.h" - -#include "base/command_line.h" -#include "base/file_util.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/language_combobox_model.h" -#include "chrome/browser/language_order_table_model.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/shell_dialogs.h" -#include "chrome/browser/ui/views/restart_message_box.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/spellcheck_common.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/theme_resources.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/font.h" -#include "ui/gfx/native_theme_win.h" -#include "unicode/uloc.h" -#include "views/controls/button/radio_button.h" -#include "views/controls/tabbed_pane/tabbed_pane.h" -#include "views/controls/table/table_view.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" -#include "views/widget/widget.h" -#include "views/window/window.h" - -/////////////////////////////////////////////////////////////////////////////// -// AddLanguageWindowView -// -// This opens another window from where a new accept language can be selected. -// -class AddLanguageWindowView : public views::View, - public views::Combobox::Listener, - public views::DialogDelegate { - public: - AddLanguageWindowView(LanguagesPageView* language_delegate, Profile* profile); - views::Window* container() const { return container_; } - void set_container(views::Window* container) { - container_ = container; - } - - // views::DialogDelegate methods. - virtual bool Accept(); - virtual std::wstring GetWindowTitle() const; - - // views::WindowDelegate method. - virtual bool IsModal() const { return true; } - virtual views::View* GetContentsView() { return this; } - - // views::Combobox::Listener implementation: - virtual void ItemChanged(views::Combobox* combobox, - int prev_index, - int new_index); - - // views::View overrides. - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - protected: - virtual void ViewHierarchyChanged(bool is_add, views::View* parent, - views::View* child); - - private: - void Init(); - - // The Options dialog window. - views::Window* container_; - - // Used for Call back to LanguagePageView that language has been selected. - LanguagesPageView* language_delegate_; - std::string accept_language_selected_; - - // Combobox and its corresponding model. - scoped_ptr<LanguageComboboxModel> accept_language_combobox_model_; - views::Combobox* accept_language_combobox_; - - // The Profile associated with this window. - Profile* profile_; - - DISALLOW_COPY_AND_ASSIGN(AddLanguageWindowView); -}; - -static const int kDialogPadding = 7; -static int kDefaultWindowWidthChars = 60; -static int kDefaultWindowHeightLines = 3; - -AddLanguageWindowView::AddLanguageWindowView( - LanguagesPageView* language_delegate, - Profile* profile) - : profile_(profile->GetOriginalProfile()), - language_delegate_(language_delegate), - accept_language_combobox_(NULL) { - Init(); - - // Initialize accept_language_selected_ to the first index in drop down. - accept_language_selected_ = accept_language_combobox_model_-> - GetLocaleFromIndex(0); -} - -std::wstring AddLanguageWindowView::GetWindowTitle() const { - return UTF16ToWide( - l10n_util::GetStringUTF16(IDS_FONT_LANGUAGE_SETTING_LANGUAGES_TAB_TITLE)); -} - -bool AddLanguageWindowView::Accept() { - if (language_delegate_) { - language_delegate_->OnAddLanguage(accept_language_selected_); - } - return true; -} - -void AddLanguageWindowView::ItemChanged(views::Combobox* combobox, - int prev_index, - int new_index) { - accept_language_selected_ = accept_language_combobox_model_-> - GetLocaleFromIndex(new_index); -} - -void AddLanguageWindowView::Layout() { - gfx::Size sz = accept_language_combobox_->GetPreferredSize(); - accept_language_combobox_->SetBounds(kDialogPadding, kDialogPadding, - width() - 2*kDialogPadding, - sz.height()); -} - -gfx::Size AddLanguageWindowView::GetPreferredSize() { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - const gfx::Font& font = rb.GetFont(ResourceBundle::BaseFont); - return gfx::Size(font.GetAverageCharacterWidth() * kDefaultWindowWidthChars, - font.GetHeight() * kDefaultWindowHeightLines); -} - -void AddLanguageWindowView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - // Can't init before we're inserted into a Widget, because we require - // a HWND to parent native child controls to. - if (is_add && child == this) - Init(); -} - -void AddLanguageWindowView::Init() { - // Determine Locale Codes. - const std::string app_locale = g_browser_process->GetApplicationLocale(); - std::vector<std::string> locale_codes; - l10n_util::GetAcceptLanguagesForLocale(app_locale, &locale_codes); - - accept_language_combobox_model_.reset(new LanguageComboboxModel( - profile_, locale_codes)); - accept_language_combobox_ = new views::Combobox( - accept_language_combobox_model_.get()); - accept_language_combobox_->SetSelectedItem(0); - accept_language_combobox_->set_listener(this); - AddChildView(accept_language_combobox_); -} - -LanguagesPageView::LanguagesPageView(Profile* profile) - : languages_instructions_(NULL), - languages_contents_(NULL), - language_order_table_(NULL), - add_button_(NULL), - remove_button_(NULL), - move_up_button_(NULL), - move_down_button_(NULL), - button_stack_(NULL), - language_info_label_(NULL), - ui_language_label_(NULL), - change_ui_language_combobox_(NULL), - change_dictionary_language_combobox_(NULL), - enable_spellchecking_checkbox_(NULL), - enable_autospellcorrect_checkbox_(NULL), - dictionary_language_label_(NULL), - OptionsPageView(profile), - language_table_edited_(false), - language_warning_shown_(false), - enable_spellcheck_checkbox_clicked_(false), - enable_autospellcorrect_checkbox_clicked_(false), - spellcheck_language_index_selected_(-1), - ui_language_index_selected_(-1), - starting_ui_language_index_(-1) { - accept_languages_.Init(prefs::kAcceptLanguages, - profile->GetPrefs(), NULL); - enable_spellcheck_.Init(prefs::kEnableSpellCheck, - profile->GetPrefs(), NULL); - enable_autospellcorrect_.Init(prefs::kEnableAutoSpellCorrect, - profile->GetPrefs(), NULL); -} - -LanguagesPageView::~LanguagesPageView() { - if (language_order_table_) - language_order_table_->SetModel(NULL); -} - -void LanguagesPageView::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender == move_up_button_) { - OnMoveUpLanguage(); - language_table_edited_ = true; - } else if (sender == move_down_button_) { - OnMoveDownLanguage(); - language_table_edited_ = true; - } else if (sender == remove_button_) { - OnRemoveLanguage(); - language_table_edited_ = true; - } else if (sender == add_button_) { - views::Window::CreateChromeWindow( - GetWindow()->GetNativeWindow(), - gfx::Rect(), - new AddLanguageWindowView(this, profile()))->Show(); - language_table_edited_ = true; - } else if (sender == enable_spellchecking_checkbox_) { - enable_spellcheck_checkbox_clicked_ = true; - } else if (sender == enable_autospellcorrect_checkbox_) { - enable_autospellcorrect_checkbox_clicked_ = true; - } -} - -void LanguagesPageView::OnAddLanguage(const std::string& new_language) { - if (language_order_table_model_->Add(new_language)) { - language_order_table_->Select(language_order_table_model_->RowCount() - 1); - OnSelectionChanged(); - } -} - -void LanguagesPageView::InitControlLayout() { - // Define the buttons. - add_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_SELECTOR_ADD_BUTTON_LABEL))); - remove_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_SELECTOR_REMOVE_BUTTON_LABEL))); - remove_button_->SetEnabled(false); - move_up_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_SELECTOR_MOVEUP_BUTTON_LABEL))); - move_up_button_->SetEnabled(false); - move_down_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_SELECTOR_MOVEDOWN_BUTTON_LABEL))); - move_down_button_->SetEnabled(false); - - languages_contents_ = new views::View; - using views::GridLayout; - using views::ColumnSet; - - GridLayout* layout = GridLayout::CreatePanel(this); - SetLayoutManager(layout); - - const int single_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - - // Add the instructions label. - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - languages_instructions_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_FONT_LANGUAGE_SETTING_LANGUAGES_INSTRUCTIONS))); - languages_instructions_->SetMultiLine(true); - languages_instructions_->SetHorizontalAlignment( - views::Label::ALIGN_LEFT); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(languages_instructions_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - // Add two columns - for table, and for button stack. - std::vector<TableColumn> columns; - columns.push_back(TableColumn()); - language_order_table_model_.reset(new LanguageOrderTableModel); - language_order_table_ = new views::TableView( - language_order_table_model_.get(), columns, - views::TEXT_ONLY, false, true, true); - language_order_table_->SetObserver(this); - - const int double_column_view_set_id = 1; - column_set = layout->AddColumnSet(double_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, double_column_view_set_id); - - // Add the table to the the first column. - layout->AddView(language_order_table_); - - // Now add the four buttons to the second column. - button_stack_ = new views::View; - GridLayout* button_stack_layout = new GridLayout(button_stack_); - button_stack_->SetLayoutManager(button_stack_layout); - - column_set = button_stack_layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - button_stack_layout->StartRow(0, single_column_view_set_id); - button_stack_layout->AddView(add_button_, 1, 1, GridLayout::FILL, - GridLayout::CENTER); - button_stack_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - button_stack_layout->StartRow(0, single_column_view_set_id); - button_stack_layout->AddView(remove_button_, 1, 1, GridLayout::FILL, - GridLayout::CENTER); - button_stack_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - button_stack_layout->StartRow(0, single_column_view_set_id); - button_stack_layout->AddView(move_up_button_, 1, 1, GridLayout::FILL, - GridLayout::CENTER); - button_stack_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - button_stack_layout->StartRow(0, single_column_view_set_id); - button_stack_layout->AddView(move_down_button_, 1, 1, GridLayout::FILL, - GridLayout::CENTER); - - layout->AddView(button_stack_); - - layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); - - language_info_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_CHROME_LANGUAGE_INFO))); - language_info_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - ui_language_label_ = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_CHROME_UI_LANGUAGE))); - ui_language_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - ui_language_model_.reset(new LanguageComboboxModel); - change_ui_language_combobox_ = - new views::Combobox(ui_language_model_.get()); - change_ui_language_combobox_->set_listener(this); - dictionary_language_label_ = new views::Label(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_CHROME_DICTIONARY_LANGUAGE))); - dictionary_language_label_->SetHorizontalAlignment( - views::Label::ALIGN_LEFT); - enable_spellchecking_checkbox_ = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_ENABLE_SPELLCHECK))); - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { - enable_autospellcorrect_checkbox_ = new views::Checkbox(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_ENABLE_AUTO_SPELL_CORRECTION))); - enable_autospellcorrect_checkbox_->set_listener(this); - } - enable_spellchecking_checkbox_->set_listener(this); - enable_spellchecking_checkbox_->SetMultiLine(true); - - // Determine Locale Codes. - std::vector<std::string> spell_check_languages; - SpellCheckCommon::SpellCheckLanguages(&spell_check_languages); - dictionary_language_model_.reset(new LanguageComboboxModel(profile(), - spell_check_languages)); - change_dictionary_language_combobox_ = - new views::Combobox(dictionary_language_model_.get()); - change_dictionary_language_combobox_->set_listener(this); - - // SpellCheck language settings. - layout->StartRow(0, single_column_view_set_id); - layout->AddView(enable_spellchecking_checkbox_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { - layout->StartRow(0, single_column_view_set_id); - layout->AddView(enable_autospellcorrect_checkbox_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - } - const int double_column_view_set_2_id = 2; - column_set = layout->AddColumnSet(double_column_view_set_2_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, double_column_view_set_2_id); - layout->AddView(dictionary_language_label_); - layout->AddView(change_dictionary_language_combobox_); - - // UI language settings. - layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(language_info_label_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - layout->StartRow(0, double_column_view_set_2_id); - layout->AddView(ui_language_label_); - layout->AddView(change_ui_language_combobox_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - // Init member prefs so we can update the controls if prefs change. - app_locale_.Init(prefs::kApplicationLocale, - g_browser_process->local_state(), this); - dictionary_language_.Init(prefs::kSpellCheckDictionary, - profile()->GetPrefs(), this); -} - -void LanguagesPageView::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || *pref_name == prefs::kAcceptLanguages) { - language_order_table_model_->SetAcceptLanguagesString( - accept_languages_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kApplicationLocale) { - int index = ui_language_model_->GetSelectedLanguageIndex( - prefs::kApplicationLocale); - if (-1 == index) { - // The pref value for locale isn't valid. Use the current app locale - // (which is what we're currently using). - index = ui_language_model_->GetIndexFromLocale( - g_browser_process->GetApplicationLocale()); - } - DCHECK(-1 != index); - change_ui_language_combobox_->SetSelectedItem(index); - starting_ui_language_index_ = index; - } - if (!pref_name || *pref_name == prefs::kSpellCheckDictionary) { - int index = dictionary_language_model_->GetSelectedLanguageIndex( - prefs::kSpellCheckDictionary); - - // If the index for the current language cannot be found, it is due to - // the fact that the pref-member value for the last dictionary language - // set by the user still uses the old format; i.e. language-region, even - // when region is not necessary. For example, if the user sets the - // dictionary language to be French, the pref-member value in the user - // profile is "fr-FR", whereas we now use only "fr". To resolve this issue, - // if "fr-FR" is read from the pref, the language code ("fr" here) is - // extracted, and re-written in the pref, so that the pref-member value for - // dictionary language in the user profile now correctly stores "fr" - // instead of "fr-FR". - if (index < 0) { - const std::string& lang_region = dictionary_language_.GetValue(); - dictionary_language_.SetValue( - SpellCheckCommon::GetLanguageFromLanguageRegion(lang_region)); - index = dictionary_language_model_->GetSelectedLanguageIndex( - prefs::kSpellCheckDictionary); - } - - change_dictionary_language_combobox_->SetSelectedItem(index); - spellcheck_language_index_selected_ = -1; - } - if (!pref_name || *pref_name == prefs::kEnableSpellCheck) { - enable_spellchecking_checkbox_->SetChecked( - enable_spellcheck_.GetValue()); - } - if (!pref_name || *pref_name == prefs::kEnableAutoSpellCorrect) { - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { - enable_autospellcorrect_checkbox_->SetChecked( - enable_autospellcorrect_.GetValue()); - } - } -} - -void LanguagesPageView::ItemChanged(views::Combobox* sender, - int prev_index, - int new_index) { - if (prev_index == new_index) - return; - - if (sender == change_ui_language_combobox_) { - if (new_index == starting_ui_language_index_) - ui_language_index_selected_ = -1; - else - ui_language_index_selected_ = new_index; - - if (!language_warning_shown_) { - RestartMessageBox::ShowMessageBox(GetWindow()->GetNativeWindow()); - language_warning_shown_ = true; - } - } else if (sender == change_dictionary_language_combobox_) { - // Set the spellcheck language selected. - spellcheck_language_index_selected_ = new_index; - - // Remove the previously added spell check language to the accept list. - if (!spellcheck_language_added_.empty()) { - int old_index = language_order_table_model_->GetIndex( - spellcheck_language_added_); - if (old_index > -1) - language_order_table_model_->Remove(old_index); - } - - // Add this new spell check language only if it is not already in the - // accept language list. - std::string language = - dictionary_language_model_->GetLocaleFromIndex(new_index); - int index = language_order_table_model_->GetIndex(language); - if (index == -1) { - // Add the new language. - OnAddLanguage(language); - language_table_edited_ = true; - spellcheck_language_added_ = language; - } else { - spellcheck_language_added_ = ""; - } - } -} - -void LanguagesPageView::OnSelectionChanged() { - move_up_button_->SetEnabled(language_order_table_->FirstSelectedRow() > 0 && - language_order_table_->SelectedRowCount() == 1); - move_down_button_->SetEnabled(language_order_table_->FirstSelectedRow() < - language_order_table_->RowCount() - 1 && - language_order_table_->SelectedRowCount() == - 1); - remove_button_->SetEnabled(language_order_table_->SelectedRowCount() > 0); -} - -void LanguagesPageView::OnRemoveLanguage() { - int item_selected = 0; - for (views::TableView::iterator i = - language_order_table_->SelectionBegin(); - i != language_order_table_->SelectionEnd(); ++i) { - language_order_table_model_->Remove(*i); - item_selected = *i; - } - - move_up_button_->SetEnabled(false); - move_down_button_->SetEnabled(false); - remove_button_->SetEnabled(false); - int items_left = language_order_table_model_->RowCount(); - if (items_left <= 0) - return; - if (item_selected > items_left - 1) - item_selected = items_left - 1; - language_order_table_->Select(item_selected); - OnSelectionChanged(); -} - -void LanguagesPageView::OnMoveDownLanguage() { - int item_selected = language_order_table_->FirstSelectedRow(); - language_order_table_model_->MoveDown(item_selected); - language_order_table_->Select(item_selected + 1); - OnSelectionChanged(); -} - -void LanguagesPageView::OnMoveUpLanguage() { - int item_selected = language_order_table_->FirstSelectedRow(); - language_order_table_model_->MoveUp(item_selected); - language_order_table_->Select(item_selected - 1); - - OnSelectionChanged(); -} - -void LanguagesPageView::SaveChanges() { - if (language_order_table_model_.get() && language_table_edited_) { - accept_languages_.SetValue( - language_order_table_model_->GetLanguageList()); - } - - if (ui_language_index_selected_ != -1) { - UserMetricsRecordAction(UserMetricsAction("Options_AppLanguage"), - g_browser_process->local_state()); - app_locale_.SetValue(ui_language_model_-> - GetLocaleFromIndex(ui_language_index_selected_)); - - // Remove pref values for spellcheck dictionaries forcefully. - PrefService* prefs = profile()->GetPrefs(); - if (prefs) - prefs->ClearPref(prefs::kSpellCheckDictionary); - } - - if (spellcheck_language_index_selected_ != -1) { - UserMetricsRecordAction(UserMetricsAction("Options_DictionaryLanguage"), - profile()->GetPrefs()); - dictionary_language_.SetValue(dictionary_language_model_-> - GetLocaleFromIndex(spellcheck_language_index_selected_)); - } - - if (enable_spellcheck_checkbox_clicked_) - enable_spellcheck_.SetValue(enable_spellchecking_checkbox_->checked()); - - if (enable_autospellcorrect_checkbox_clicked_) { - enable_autospellcorrect_.SetValue( - enable_autospellcorrect_checkbox_->checked()); - } -} diff --git a/chrome/browser/ui/views/options/languages_page_view.h b/chrome/browser/ui/views/options/languages_page_view.h deleted file mode 100644 index 1babef7..0000000 --- a/chrome/browser/ui/views/options/languages_page_view.h +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_LANGUAGES_PAGE_VIEW_H__ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_LANGUAGES_PAGE_VIEW_H__ -#pragma once - -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "views/controls/combobox/combobox.h" -#include "views/controls/button/button.h" -#include "views/controls/table/table_view_observer.h" -#include "views/view.h" - -class AddLanguageView; -class LanguageComboboxModel; -class LanguageOrderTableModel; - -namespace views { -class Checkbox; -class Label; -class NativeButton; -class TableView; -} - -/////////////////////////////////////////////////////////////////////////////// -// LanguagesPageView - -class LanguagesPageView : public OptionsPageView, - public views::ButtonListener, - public views::TableViewObserver, - public views::Combobox::Listener { - public: - explicit LanguagesPageView(Profile* profile); - virtual ~LanguagesPageView(); - - // views::ButtonListener implementation: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // Save Changes made to relevant pref members associated with this tab. - // This is public since it is called by FontsLanguageWindowView in its - // Dialog Delegate Accept() method. - void SaveChanges(); - - // This is public because when user clicks OK in AddLanguageView dialog, - // this is called back in the LanguagePageView delegate in order to add - // this language to the table model in this tab. - void OnAddLanguage(const std::string& new_language); - - protected: - // OptionsPageView implementation: - virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::string* pref_name); - - // views::Combobox::Listener implementation: - virtual void ItemChanged(views::Combobox* sender, - int prev_index, - int new_index); - - private: - // Invoked when the selection of the table view changes. Updates the enabled - // property of the remove button. - virtual void OnSelectionChanged(); - void OnRemoveLanguage(); - void OnMoveDownLanguage(); - void OnMoveUpLanguage(); - - views::Label* languages_instructions_; - views::View* languages_contents_; - views::View* button_stack_; - views::TableView* language_order_table_; - views::NativeButton* move_up_button_; - views::NativeButton* move_down_button_; - views::NativeButton* add_button_; - views::NativeButton* remove_button_; - views::Label* language_info_label_; - views::Label* ui_language_label_; - views::Combobox* change_ui_language_combobox_; - views::Combobox* change_dictionary_language_combobox_; - views::Checkbox* enable_autospellcorrect_checkbox_; - views::Checkbox* enable_spellchecking_checkbox_; - views::Label* dictionary_language_label_; - - scoped_ptr<LanguageOrderTableModel> language_order_table_model_; - AddLanguageView* add_language_instance_; - StringPrefMember accept_languages_; - - // The contents of the "user interface language" combobox. - scoped_ptr<LanguageComboboxModel> ui_language_model_; - StringPrefMember app_locale_; - int ui_language_index_selected_; - int starting_ui_language_index_; - - // The contents of the "dictionary language" combobox. - scoped_ptr<LanguageComboboxModel> dictionary_language_model_; - StringPrefMember dictionary_language_; - - // SpellChecker enable pref. - BooleanPrefMember enable_spellcheck_; - - // Auto spell correction pref. - BooleanPrefMember enable_autospellcorrect_; - - // This is assigned the new index of spellcheck language if the language - // is changed. Otherwise, it remains -1, and pref members are not updated. - int spellcheck_language_index_selected_; - std::string spellcheck_language_added_; - - bool language_table_edited_; - bool language_warning_shown_; - bool enable_spellcheck_checkbox_clicked_; - bool enable_autospellcorrect_checkbox_clicked_; - - DISALLOW_COPY_AND_ASSIGN(LanguagesPageView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_LANGUAGES_PAGE_VIEW_H__ diff --git a/chrome/browser/ui/views/options/managed_prefs_banner_view.cc b/chrome/browser/ui/views/options/managed_prefs_banner_view.cc deleted file mode 100644 index 02ef429..0000000 --- a/chrome/browser/ui/views/options/managed_prefs_banner_view.cc +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/managed_prefs_banner_view.h" - -#include "grit/generated_resources.h" -#include "grit/theme_resources.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/color_utils.h" -#include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/layout/box_layout.h" -#include "views/layout/layout_constants.h" - -// Spacing between the banner frame and its contents. -static const int kPrefsBannerPadding = 3; -// Width of the banner frame. -static const int kPrefsBannerBorderSize = 1; - -ManagedPrefsBannerView::ManagedPrefsBannerView(PrefService* prefs, - OptionsPage page) - : policy::ManagedPrefsBannerBase(prefs, page) { - content_ = new views::View; - SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); - views::Border* border = views::Border::CreateSolidBorder( - kPrefsBannerBorderSize, border_color); - content_->set_border(border); - - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - warning_image_ = new views::ImageView(); - warning_image_->SetImage(rb.GetBitmapNamed(IDR_WARNING)); - label_ = new views::Label(rb.GetLocalizedString(IDS_OPTIONS_MANAGED_PREFS)); -} - -void ManagedPrefsBannerView::Init() { - AddChildView(content_); - content_->SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kHorizontal, - kPrefsBannerPadding, - kPrefsBannerPadding, - views::kRelatedControlSmallHorizontalSpacing)); - content_->AddChildView(warning_image_); - content_->AddChildView(label_); - OnUpdateVisibility(); -} - -gfx::Size ManagedPrefsBannerView::GetPreferredSize() { - if (!IsVisible()) - return gfx::Size(); - - // Add space below the banner. - gfx::Size size(content_->GetPreferredSize()); - size.Enlarge(0, views::kRelatedControlVerticalSpacing); - return size; -} - -void ManagedPrefsBannerView::Layout() { - content_->SetBounds( - 0, 0, width(), height() - views::kRelatedControlVerticalSpacing); -} - -void ManagedPrefsBannerView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (is_add && child == this) - Init(); -} - -void ManagedPrefsBannerView::OnUpdateVisibility() { - SetVisible(DetermineVisibility()); -} diff --git a/chrome/browser/ui/views/options/managed_prefs_banner_view.h b/chrome/browser/ui/views/options/managed_prefs_banner_view.h deleted file mode 100644 index 71396d8..0000000 --- a/chrome/browser/ui/views/options/managed_prefs_banner_view.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_MANAGED_PREFS_BANNER_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_MANAGED_PREFS_BANNER_VIEW_H_ -#pragma once - -#include "chrome/browser/policy/managed_prefs_banner_base.h" -#include "views/view.h" - -namespace views { -class ImageView; -class Label; -} - -// Displays a banner showing a warning message that tells the user some options -// cannot be changed because the relevant preferences are managed by their -// system administrator. -class ManagedPrefsBannerView : public policy::ManagedPrefsBannerBase, - public views::View { - public: - // Initialize the banner. |page| is used to determine the names of the - // preferences that control the banner visibility through their managed flag. - ManagedPrefsBannerView(PrefService* pref_service, OptionsPage page); - virtual ~ManagedPrefsBannerView() {} - - private: - // Initialize contents and layout. - void Init(); - - // views::View overrides. - virtual gfx::Size GetPreferredSize(); - virtual void Layout(); - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - // ManagedPrefsBannerBase override. - virtual void OnUpdateVisibility(); - - // Holds the warning icon image and text label and renders the border. - views::View* content_; - // Warning icon image. - views::ImageView* warning_image_; - // The label responsible for rendering the warning text. - views::Label* label_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(ManagedPrefsBannerView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_MANAGED_PREFS_BANNER_VIEW_H_ diff --git a/chrome/browser/ui/views/options/options_group_view.cc b/chrome/browser/ui/views/options/options_group_view.cc deleted file mode 100644 index f4a9670..0000000 --- a/chrome/browser/ui/views/options/options_group_view.cc +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <vsstyle.h> -#include <vssym32.h> - -#include "chrome/browser/ui/views/options/options_group_view.h" - -#include "base/string_number_conversions.h" -#include "base/utf_string_conversions.h" -#include "grit/locale_settings.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/font.h" -#include "ui/gfx/native_theme_win.h" -#include "views/controls/label.h" -#include "views/controls/separator.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" - -static const int kLeftColumnWidthChars = 20; -static const int kOptionsGroupViewColumnSpacing = 30; - -/////////////////////////////////////////////////////////////////////////////// -// OptionsGroupView, public: - -OptionsGroupView::OptionsGroupView(views::View* contents, - const std::wstring& title, - const std::wstring& description, - bool show_separator) - : contents_(contents), - title_label_(new views::Label(title)), - description_label_(new views::Label(description)), - separator_(NULL), - show_separator_(show_separator), - highlighted_(false) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - const gfx::Font& title_font = - rb.GetFont(ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD); - title_label_->SetFont(title_font); - SkColor title_color = gfx::NativeTheme::instance()->GetThemeColorWithDefault( - gfx::NativeTheme::BUTTON, BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, - COLOR_WINDOWTEXT); - title_label_->SetColor(title_color); - title_label_->SetMultiLine(true); - title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - - description_label_->SetMultiLine(true); - description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - - SetAccessibleName(WideToUTF16Hack(title)); - contents->SetAccessibleName(WideToUTF16Hack(title)); -} - -OptionsGroupView::~OptionsGroupView() { -} - -void OptionsGroupView::SetHighlighted(bool highlighted) { - highlighted_ = highlighted; - SchedulePaint(); -} - -int OptionsGroupView::GetContentsWidth() const { - return contents_->width(); -} - -/////////////////////////////////////////////////////////////////////////////// -// OptionsGroupView, views::View overrides: - -AccessibilityTypes::Role OptionsGroupView::GetAccessibleRole() { - return AccessibilityTypes::ROLE_GROUPING; -} - -void OptionsGroupView::OnPaint(gfx::Canvas* canvas) { - if (highlighted_) { - COLORREF infocolor = GetSysColor(COLOR_INFOBK); - SkColor background_color = SkColorSetRGB(GetRValue(infocolor), - GetGValue(infocolor), - GetBValue(infocolor)); - int y_offset = views::kUnrelatedControlVerticalSpacing / 2; - canvas->FillRectInt(background_color, 0, 0, width(), - height() - y_offset); - } -} - -void OptionsGroupView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (is_add && child == this) - Init(); -} - -/////////////////////////////////////////////////////////////////////////////// -// OptionsGroupView, private: - -void OptionsGroupView::Init() { - using views::GridLayout; - using views::ColumnSet; - - GridLayout* layout = new GridLayout(this); - SetLayoutManager(layout); - - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - const gfx::Font& font = rb.GetFont(ResourceBundle::BaseFont); - int left_column_chars = 0; - base::StringToInt( - l10n_util::GetStringUTF16(IDS_OPTIONS_DIALOG_LEFT_COLUMN_WIDTH_CHARS), - &left_column_chars); - int left_column_width = font.GetExpectedTextWidth(left_column_chars); - - const int two_column_layout_id = 0; - ColumnSet* column_set = layout->AddColumnSet(two_column_layout_id); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, - GridLayout::FIXED, left_column_width, 0); - column_set->AddPaddingColumn(0, kOptionsGroupViewColumnSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 1, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(0, two_column_layout_id); - layout->AddView(title_label_, 1, 1, GridLayout::FILL, GridLayout::LEADING); - layout->AddView(contents_, 1, 3, GridLayout::FILL, GridLayout::FILL); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - layout->StartRow(1, two_column_layout_id); - layout->AddView(description_label_, 1, 1, - GridLayout::FILL, GridLayout::LEADING); - layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); - - if (show_separator_) { - const int single_column_layout_id = 1; - column_set = layout->AddColumnSet(single_column_layout_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - - separator_ = new views::Separator; - layout->StartRow(0, single_column_layout_id); - layout->AddView(separator_); - } -} diff --git a/chrome/browser/ui/views/options/options_group_view.h b/chrome/browser/ui/views/options/options_group_view.h deleted file mode 100644 index 1d32c0a..0000000 --- a/chrome/browser/ui/views/options/options_group_view.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_OPTIONS_GROUP_VIEW_H__ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_OPTIONS_GROUP_VIEW_H__ -#pragma once - -#include "views/view.h" - -namespace views { -class Label; -class Separator; -}; - -/////////////////////////////////////////////////////////////////////////////// -// OptionsGroupView -// -// A helper View that gathers related options into groups with a title and -// optional description. -// -class OptionsGroupView : public views::View { - public: - OptionsGroupView(views::View* contents, - const std::wstring& title, - const std::wstring& description, - bool show_separator); - virtual ~OptionsGroupView(); - - // Sets the group as being highlighted to attract attention. - void SetHighlighted(bool highlighted); - - // Retrieves the width of the ContentsView. Used to help size wrapping items. - int GetContentsWidth() const; - - protected: - // views::View overrides: - virtual AccessibilityTypes::Role GetAccessibleRole(); - virtual void OnPaint(gfx::Canvas* canvas); - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - private: - void Init(); - - views::View* contents_; - views::Label* title_label_; - views::Label* description_label_; - views::Separator* separator_; - - // True if we should show a separator line below the contents of this - // section. - bool show_separator_; - - // True if this section should have a highlighted treatment to draw the - // user's attention. - bool highlighted_; - - DISALLOW_COPY_AND_ASSIGN(OptionsGroupView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_OPTIONS_GROUP_VIEW_H__ diff --git a/chrome/browser/ui/views/options/options_page_view.cc b/chrome/browser/ui/views/options/options_page_view.cc deleted file mode 100644 index ec0c109..0000000 --- a/chrome/browser/ui/views/options/options_page_view.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/options_page_view.h" - -#include "chrome/browser/metrics/user_metrics.h" -#include "views/widget/widget.h" - -/////////////////////////////////////////////////////////////////////////////// -// OptionsPageView - -OptionsPageView::OptionsPageView(Profile* profile) - : OptionsPageBase(profile), - initialized_(false) { -} - -OptionsPageView::~OptionsPageView() { -} - -/////////////////////////////////////////////////////////////////////////////// -// OptionsPageView, views::View overrides: - -bool OptionsPageView::CanClose() const { - return true; -} - -void OptionsPageView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (!initialized_ && is_add && GetWidget()) { - // It is important that this only get done _once_ otherwise we end up - // duplicating the view hierarchy when tabs are switched. - initialized_ = true; - InitControlLayout(); - NotifyPrefChanged(NULL); - } -} - -AccessibilityTypes::Role OptionsPageView::GetAccessibleRole() { - return AccessibilityTypes::ROLE_PAGETAB; -} diff --git a/chrome/browser/ui/views/options/options_page_view.h b/chrome/browser/ui/views/options/options_page_view.h deleted file mode 100644 index c26cc9f..0000000 --- a/chrome/browser/ui/views/options/options_page_view.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_OPTIONS_PAGE_VIEW_H__ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_OPTIONS_PAGE_VIEW_H__ -#pragma once - -#include "chrome/browser/ui/options/options_page_base.h" -#include "views/controls/link.h" -#include "views/controls/button/native_button.h" - -class PrefService; - -/////////////////////////////////////////////////////////////////////////////// -// OptionsPageView -// -// A base class for Options dialog pages that handles ensuring control -// initialization is done just once. -// -class OptionsPageView : public views::View, - public OptionsPageBase { - public: - virtual ~OptionsPageView(); - - // Returns true if the window containing this view can be closed, given the - // current state of this view. This can be used to prevent the window from - // being closed when a modal dialog box is showing, for example. - virtual bool CanClose() const; - - protected: - // This class cannot be instantiated directly, but its constructor must be - // called by derived classes. - explicit OptionsPageView(Profile* profile); - - // Initializes the layout of the controls within the panel. - virtual void InitControlLayout() = 0; - - // views::View overrides: - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - virtual AccessibilityTypes::Role GetAccessibleRole(); - - private: - // Whether or not the control layout has been initialized for this page. - bool initialized_; - - DISALLOW_COPY_AND_ASSIGN(OptionsPageView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_OPTIONS_PAGE_VIEW_H__ diff --git a/chrome/browser/ui/views/options/options_window_view.cc b/chrome/browser/ui/views/options/options_window_view.cc deleted file mode 100644 index aef8719..0000000 --- a/chrome/browser/ui/views/options/options_window_view.cc +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/options/options_window.h" -#include "chrome/browser/ui/views/options/advanced_page_view.h" -#include "chrome/browser/ui/views/options/content_page_view.h" -#include "chrome/browser/ui/views/options/general_page_view.h" -#include "chrome/browser/ui/window_sizer.h" -#include "chrome/common/chrome_constants.h" -#include "chrome/common/pref_names.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "views/controls/tabbed_pane/tabbed_pane.h" -#include "views/widget/root_view.h" -#include "views/widget/widget.h" -#include "views/widget/native_widget.h" -#include "views/window/dialog_delegate.h" -#include "views/window/window.h" - -/////////////////////////////////////////////////////////////////////////////// -// OptionsWindowView -// -// The contents of the Options dialog window. -// -class OptionsWindowView : public views::View, - public views::DialogDelegate, - public views::TabbedPane::Listener { - public: - explicit OptionsWindowView(Profile* profile); - virtual ~OptionsWindowView(); - - // Shows the Tab corresponding to the specified OptionsPage. - void ShowOptionsPage(OptionsPage page, OptionsGroup highlight_group); - - // views::DialogDelegate implementation: - virtual int GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_CANCEL; - } - virtual std::wstring GetWindowTitle() const; - virtual std::wstring GetWindowName() const; - virtual void WindowClosing(); - virtual bool Cancel(); - virtual views::View* GetContentsView(); - virtual bool ShouldRestoreWindowSize() const; - - // views::TabbedPane::Listener implementation: - virtual void TabSelectedAt(int index); - - // views::View overrides: - virtual AccessibilityTypes::Role GetAccessibleRole(); - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - protected: - // views::View overrides: - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - private: - // Init the assorted Tabbed pages - void Init(); - - // Returns the currently selected OptionsPageView. - OptionsPageView* GetCurrentOptionsPageView() const; - - // The Tab view that contains all of the options pages. - views::TabbedPane* tabs_; - - // The Profile associated with these options. - Profile* profile_; - - // The last page the user was on when they opened the Options window. - IntegerPrefMember last_selected_page_; - - DISALLOW_COPY_AND_ASSIGN(OptionsWindowView); -}; - -// static -static OptionsWindowView* instance_ = NULL; -static const int kDialogPadding = 7; - -/////////////////////////////////////////////////////////////////////////////// -// OptionsWindowView, public: - -OptionsWindowView::OptionsWindowView(Profile* profile) - // Always show preferences for the original profile. Most state when off - // the record comes from the original profile, but we explicitly use - // the original profile to avoid potential problems. - : profile_(profile->GetOriginalProfile()) { - // We don't need to observe changes in this value. - last_selected_page_.Init(prefs::kOptionsWindowLastTabIndex, - g_browser_process->local_state(), NULL); -} - -OptionsWindowView::~OptionsWindowView() { -} - -void OptionsWindowView::ShowOptionsPage(OptionsPage page, - OptionsGroup highlight_group) { - // Positioning is handled by window_delegate. we just need to show the window. - // This will show invisible windows and bring visible windows to the front. - window()->Show(); - - if (page == OPTIONS_PAGE_DEFAULT) { - // Remember the last visited page from local state. - page = static_cast<OptionsPage>(last_selected_page_.GetValue()); - if (page == OPTIONS_PAGE_DEFAULT) - page = OPTIONS_PAGE_GENERAL; - } - // If the page number is out of bounds, reset to the first tab. - if (page < 0 || page >= tabs_->GetTabCount()) - page = OPTIONS_PAGE_GENERAL; - - tabs_->SelectTabAt(static_cast<int>(page)); - - GetCurrentOptionsPageView()->HighlightGroup(highlight_group); -} - -/////////////////////////////////////////////////////////////////////////////// -// OptionsWindowView, views::DialogDelegate implementation: - -std::wstring OptionsWindowView::GetWindowTitle() const { - return UTF16ToWide( - l10n_util::GetStringFUTF16(IDS_OPTIONS_DIALOG_TITLE, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); -} - -std::wstring OptionsWindowView::GetWindowName() const { - return UTF8ToWide(prefs::kPreferencesWindowPlacement); -} - -void OptionsWindowView::WindowClosing() { - // Clear the static instance so that the next time ShowOptionsWindow() is - // called a new window is opened. - instance_ = NULL; -} - -bool OptionsWindowView::Cancel() { - return GetCurrentOptionsPageView()->CanClose(); -} - -views::View* OptionsWindowView::GetContentsView() { - return this; -} - -bool OptionsWindowView::ShouldRestoreWindowSize() const { - // By returning false the options window is always sized to its preferred - // size. - return false; -} - -/////////////////////////////////////////////////////////////////////////////// -// OptionsWindowView, views::TabbedPane::Listener implementation: - -void OptionsWindowView::TabSelectedAt(int index) { - DCHECK(index > OPTIONS_PAGE_DEFAULT && index < OPTIONS_PAGE_COUNT); - last_selected_page_.SetValue(index); -} - -/////////////////////////////////////////////////////////////////////////////// -// OptionsWindowView, views::View overrides: - -AccessibilityTypes::Role OptionsWindowView::GetAccessibleRole() { - return AccessibilityTypes::ROLE_CLIENT; -} - -void OptionsWindowView::Layout() { - tabs_->SetBounds(kDialogPadding, kDialogPadding, - width() - (2 * kDialogPadding), - height() - (2 * kDialogPadding)); -} - -gfx::Size OptionsWindowView::GetPreferredSize() { - gfx::Size size(tabs_->GetPreferredSize()); - size.Enlarge(2 * kDialogPadding, 2 * kDialogPadding); - return size; -} - -void OptionsWindowView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - // Can't init before we're inserted into a Container, because we require a - // HWND to parent native child controls to. - if (is_add && child == this) - Init(); -} - -/////////////////////////////////////////////////////////////////////////////// -// OptionsWindowView, private: - -void OptionsWindowView::Init() { - tabs_ = new views::TabbedPane; - tabs_->SetAccessibleName(l10n_util::GetStringFUTF16( - IDS_OPTIONS_DIALOG_TITLE, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); - tabs_->SetListener(this); - AddChildView(tabs_); - - int tab_index = 0; - GeneralPageView* general_page = new GeneralPageView(profile_); - tabs_->AddTabAtIndex( - tab_index++, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_GENERAL_TAB_LABEL)), - general_page, false); - - ContentPageView* content_page = new ContentPageView(profile_); - tabs_->AddTabAtIndex( - tab_index++, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_CONTENT_TAB_LABEL)), - content_page, false); - - AdvancedPageView* advanced_page = new AdvancedPageView(profile_); - tabs_->AddTabAtIndex( - tab_index++, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_ADVANCED_TAB_LABEL)), - advanced_page, false); - - // Bind the profile to the window so that the ChromeViewsDelegate can find - // the user preferences to store and retrieve window placement settings. - window()->AsWidget()->native_widget()->SetNativeWindowProperty( - Profile::kProfileKey, profile_); - - DCHECK(tabs_->GetTabCount() == OPTIONS_PAGE_COUNT); -} - -OptionsPageView* OptionsWindowView::GetCurrentOptionsPageView() const { - return static_cast<OptionsPageView*>(tabs_->GetSelectedTab()); -} - -/////////////////////////////////////////////////////////////////////////////// -// Factory/finder method: - -void ShowOptionsWindow(OptionsPage page, - OptionsGroup highlight_group, - Profile* profile) { - DCHECK(profile); - // If there's already an existing options window, activate it and switch to - // the specified page. - // TODO(beng): note this is not multi-simultaneous-profile-safe. When we care - // about this case this will have to be fixed. - if (!instance_) { - instance_ = new OptionsWindowView(profile); - views::Window::CreateChromeWindow(NULL, gfx::Rect(), instance_); - } - instance_->ShowOptionsPage(page, highlight_group); -} diff --git a/chrome/browser/ui/views/options/passwords_exceptions_window_view.cc b/chrome/browser/ui/views/options/passwords_exceptions_window_view.cc deleted file mode 100644 index ed9c70d..0000000 --- a/chrome/browser/ui/views/options/passwords_exceptions_window_view.cc +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/passwords_exceptions_window_view.h" - -#include "base/utf_string_conversions.h" -#include "chrome/browser/ui/views/options/exceptions_page_view.h" -#include "chrome/browser/ui/views/options/passwords_page_view.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "views/controls/tabbed_pane/tabbed_pane.h" -#include "views/window/window.h" - -// static -PasswordsExceptionsWindowView* PasswordsExceptionsWindowView::instance_ = NULL; - -static const int kDialogPadding = 7; - -namespace browser { - -// Declared in browser_dialogs.h so others don't have to depend on our header. -void ShowPasswordsExceptionsWindowView(Profile* profile) { - PasswordsExceptionsWindowView::Show(profile); -} - -} // namespace browser - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsExceptionsWindowView, public - -PasswordsExceptionsWindowView::PasswordsExceptionsWindowView(Profile* profile) - : tabs_(NULL), - passwords_page_view_(NULL), - exceptions_page_view_(NULL), - profile_(profile) { -} - -// static -void PasswordsExceptionsWindowView::Show(Profile* profile) { - DCHECK(profile); - if (!instance_) { - instance_ = new PasswordsExceptionsWindowView(profile); - - // |instance_| will get deleted once Close() is called. - views::Window::CreateChromeWindow(NULL, gfx::Rect(), instance_); - } - if (!instance_->window()->IsVisible()) { - instance_->window()->Show(); - } else { - instance_->window()->Activate(); - } -} - -///////////////////////////////////////////////////////////////////////////// -// PasswordsExceptionsWindowView, views::View implementations - -void PasswordsExceptionsWindowView::Layout() { - tabs_->SetBounds(kDialogPadding, kDialogPadding, - width() - (2 * kDialogPadding), - height() - (2 * kDialogPadding)); -} - -gfx::Size PasswordsExceptionsWindowView::GetPreferredSize() { - return gfx::Size(views::Window::GetLocalizedContentsSize( - IDS_PASSWORDS_DIALOG_WIDTH_CHARS, - IDS_PASSWORDS_DIALOG_HEIGHT_LINES)); -} - -void PasswordsExceptionsWindowView::ViewHierarchyChanged( - bool is_add, views::View* parent, views::View* child) { - if (is_add && child == this) - Init(); -} - -///////////////////////////////////////////////////////////////////////////// -// PasswordsExceptionsWindowView, views::DisloagDelegate implementations - -int PasswordsExceptionsWindowView::GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_CANCEL; -} - -std::wstring PasswordsExceptionsWindowView::GetWindowTitle() const { - return UTF16ToWide( - l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE)); -} - -void PasswordsExceptionsWindowView::WindowClosing() { - // |instance_| is deleted once the window is closed, so we just have to set - // it to NULL. - instance_ = NULL; -} - -views::View* PasswordsExceptionsWindowView::GetContentsView() { - return this; -} - -///////////////////////////////////////////////////////////////////////////// -// PasswordsExceptionsWindowView, private - -void PasswordsExceptionsWindowView::Init() { - tabs_ = new views::TabbedPane(); - AddChildView(tabs_); - - passwords_page_view_ = new PasswordsPageView(profile_); - tabs_->AddTab(UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE)), passwords_page_view_); - - exceptions_page_view_ = new ExceptionsPageView(profile_); - tabs_->AddTab(UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE)), exceptions_page_view_); -} diff --git a/chrome/browser/ui/views/options/passwords_exceptions_window_view.h b/chrome/browser/ui/views/options/passwords_exceptions_window_view.h deleted file mode 100644 index 24ef781..0000000 --- a/chrome/browser/ui/views/options/passwords_exceptions_window_view.h +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_PASSWORDS_EXCEPTIONS_WINDOW_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_PASSWORDS_EXCEPTIONS_WINDOW_VIEW_H_ -#pragma once - -#include "views/view.h" -#include "views/window/dialog_delegate.h" - -class Profile; -class PasswordsPageView; -class ExceptionsPageView; - -namespace views { -class TabbedPane; -} - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsExceptionsWindowView -// -// The contents of the "Save passwords and exceptions" dialog window. -// -class PasswordsExceptionsWindowView : public views::View, - public views::DialogDelegate { - public: - explicit PasswordsExceptionsWindowView(Profile* profile); - virtual ~PasswordsExceptionsWindowView() {} - - // Show the PasswordManagerExceptionsView for the given profile. - static void Show(Profile* profile); - - // views::View methods. - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - virtual void ViewHierarchyChanged(bool is_add, views::View* parent, - views::View* child); - - // views::DialogDelegate methods: - virtual int GetDialogButtons() const; - virtual bool CanResize() const { return true; } - virtual bool CanMaximize() const { return false; } - virtual bool IsAlwaysOnTop() const { return false; } - virtual bool HasAlwaysOnTopMenu() const { return false; } - virtual std::wstring GetWindowTitle() const; - virtual void WindowClosing(); - virtual views::View* GetContentsView(); - - private: - void Init(); - - // The Tab view that contains all of the options pages. - views::TabbedPane* tabs_; - - PasswordsPageView* passwords_page_view_; - - ExceptionsPageView* exceptions_page_view_; - - Profile* profile_; - - static PasswordsExceptionsWindowView* instance_; - - DISALLOW_COPY_AND_ASSIGN(PasswordsExceptionsWindowView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_PASSWORDS_EXCEPTIONS_WINDOW_VIEW_H_ diff --git a/chrome/browser/ui/views/options/passwords_page_view.cc b/chrome/browser/ui/views/options/passwords_page_view.cc deleted file mode 100644 index 9b714e0..0000000 --- a/chrome/browser/ui/views/options/passwords_page_view.cc +++ /dev/null @@ -1,371 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/passwords_page_view.h" - -#include "base/i18n/rtl.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/password_manager/password_store.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/pref_names.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "views/background.h" -#include "views/controls/button/native_button.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" - -using views::ColumnSet; -using views::GridLayout; -using webkit_glue::PasswordForm; - -/////////////////////////////////////////////////////////////////////////////// -// MultiLabelButtons -MultiLabelButtons::MultiLabelButtons(views::ButtonListener* listener, - const std::wstring& label, - const std::wstring& alt_label) - : NativeButton(listener, label), - label_(label), - alt_label_(alt_label) { -} - -gfx::Size MultiLabelButtons::GetPreferredSize() { - if (!IsVisible()) - return gfx::Size(); - - if (pref_size_.IsEmpty()) { - // Let's compute our preferred size. - std::wstring current_label = label(); - SetLabel(label_); - pref_size_ = NativeButton::GetPreferredSize(); - SetLabel(alt_label_); - gfx::Size alt_pref_size = NativeButton::GetPreferredSize(); - // Revert to the original label. - SetLabel(current_label); - pref_size_.SetSize(std::max(pref_size_.width(), alt_pref_size.width()), - std::max(pref_size_.height(), alt_pref_size.height())); - } - return gfx::Size(pref_size_.width(), pref_size_.height()); -} - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsTableModel, public -PasswordsTableModel::PasswordsTableModel(Profile* profile) - : observer_(NULL), - row_count_observer_(NULL), - pending_login_query_(NULL), - saved_signons_cleanup_(&saved_signons_), - profile_(profile) { - DCHECK(profile && profile->GetPasswordStore(Profile::EXPLICIT_ACCESS)); -} - -PasswordsTableModel::~PasswordsTableModel() { - CancelLoginsQuery(); -} - -int PasswordsTableModel::RowCount() { - return static_cast<int>(saved_signons_.size()); -} - -string16 PasswordsTableModel::GetText(int row, - int col_id) { - switch (col_id) { - case IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN: { // Site. - // Force URL to have LTR directionality. - std::wstring url(saved_signons_[row]->display_url.display_url()); - return base::i18n::GetDisplayStringInLTRDirectionality( - WideToUTF16Hack(url)); - } - case IDS_PASSWORDS_PAGE_VIEW_USERNAME_COLUMN: { // Username. - std::wstring username = GetPasswordFormAt(row)->username_value; - base::i18n::AdjustStringForLocaleDirection(&username); - return WideToUTF16Hack(username); - } - default: - NOTREACHED() << "Invalid column."; - return string16(); - } -} - -int PasswordsTableModel::CompareValues(int row1, int row2, - int column_id) { - if (column_id == IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN) { - return saved_signons_[row1]->display_url.Compare( - saved_signons_[row2]->display_url, GetCollator()); - } - return TableModel::CompareValues(row1, row2, column_id); -} - -void PasswordsTableModel::SetObserver(ui::TableModelObserver* observer) { - observer_ = observer; -} - -void PasswordsTableModel::GetAllSavedLoginsForProfile() { - DCHECK(!pending_login_query_); - pending_login_query_ = password_store()->GetAutofillableLogins(this); -} - -void PasswordsTableModel::OnPasswordStoreRequestDone( - int handle, const std::vector<PasswordForm*>& result) { - DCHECK_EQ(pending_login_query_, handle); - pending_login_query_ = NULL; - - STLDeleteElements<PasswordRows>(&saved_signons_); - saved_signons_.resize(result.size(), NULL); - std::string languages = profile_->GetPrefs()->GetString( - prefs::kAcceptLanguages); - for (size_t i = 0; i < result.size(); ++i) { - saved_signons_[i] = new PasswordRow( - ui::SortedDisplayURL(result[i]->origin, languages), result[i]); - } - if (observer_) - observer_->OnModelChanged(); - if (row_count_observer_) - row_count_observer_->OnRowCountChanged(RowCount()); -} - -PasswordForm* PasswordsTableModel::GetPasswordFormAt(int row) { - DCHECK(row >= 0 && row < RowCount()); - return saved_signons_[row]->form.get(); -} - -void PasswordsTableModel::ForgetAndRemoveSignon(int row) { - DCHECK(row >= 0 && row < RowCount()); - PasswordRows::iterator target_iter = saved_signons_.begin() + row; - // Remove from DB, memory, and vector. - PasswordRow* password_row = *target_iter; - password_store()->RemoveLogin(*(password_row->form.get())); - delete password_row; - saved_signons_.erase(target_iter); - if (observer_) - observer_->OnItemsRemoved(row, 1); - if (row_count_observer_) - row_count_observer_->OnRowCountChanged(RowCount()); -} - -void PasswordsTableModel::ForgetAndRemoveAllSignons() { - PasswordRows::iterator iter = saved_signons_.begin(); - while (iter != saved_signons_.end()) { - // Remove from DB, memory, and vector. - PasswordRow* row = *iter; - password_store()->RemoveLogin(*(row->form.get())); - delete row; - iter = saved_signons_.erase(iter); - } - if (observer_) - observer_->OnModelChanged(); - if (row_count_observer_) - row_count_observer_->OnRowCountChanged(RowCount()); -} - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsTableModel, private -void PasswordsTableModel::CancelLoginsQuery() { - if (pending_login_query_) { - password_store()->CancelLoginsQuery(pending_login_query_); - pending_login_query_ = NULL; - } -} - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsPageView, public -PasswordsPageView::PasswordsPageView(Profile* profile) - : OptionsPageView(profile), - ALLOW_THIS_IN_INITIALIZER_LIST(show_button_( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON)), - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON)))), - ALLOW_THIS_IN_INITIALIZER_LIST(remove_button_( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_PAGE_VIEW_REMOVE_BUTTON)))), - ALLOW_THIS_IN_INITIALIZER_LIST(remove_all_button_( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_PAGE_VIEW_REMOVE_ALL_BUTTON)))), - table_model_(profile), - table_view_(NULL), - current_selected_password_(NULL) { - allow_show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords, - profile->GetPrefs(), - this); -} - -PasswordsPageView::~PasswordsPageView() { - // The model is going away, prevent the table from accessing it. - if (table_view_) - table_view_->SetModel(NULL); -} - -void PasswordsPageView::OnSelectionChanged() { - bool has_selection = table_view_->SelectedRowCount() > 0; - remove_button_.SetEnabled(has_selection); - - PasswordForm* selected = NULL; - if (has_selection) { - views::TableSelectionIterator iter = table_view_->SelectionBegin(); - selected = table_model_.GetPasswordFormAt(*iter); - DCHECK(++iter == table_view_->SelectionEnd()); - } - - if (selected != current_selected_password_) { - // Reset the password related views. - show_button_.SetLabel(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON))); - show_button_.SetEnabled(has_selection); - password_label_.SetText(std::wstring()); - - current_selected_password_ = selected; - } -} - -void PasswordsPageView::ButtonPressed( - views::Button* sender, const views::Event& event) { - // Close will result in our destruction. - if (sender == &remove_all_button_) { - ConfirmMessageBoxDialog::Run( - GetWindow()->GetNativeWindow(), - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_PAGE_VIEW_TEXT_DELETE_ALL_PASSWORDS)), - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_PASSWORDS_PAGE_VIEW_CAPTION_DELETE_ALL_PASSWORDS))); - return; - } - - // The following require a selection (and only one, since table is single- - // select only). - views::TableSelectionIterator iter = table_view_->SelectionBegin(); - int row = *iter; - PasswordForm* selected = table_model_.GetPasswordFormAt(row); - DCHECK(++iter == table_view_->SelectionEnd()); - - if (sender == &remove_button_) { - table_model_.ForgetAndRemoveSignon(row); - } else if (sender == &show_button_) { - if (password_label_.GetText().length() == 0 && - allow_show_passwords_.GetValue()) { - password_label_.SetText(selected->password_value); - show_button_.SetLabel(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON))); - } else { - HidePassword(); - } - } else { - NOTREACHED() << "Invalid button."; - } -} - -void PasswordsPageView::OnRowCountChanged(size_t rows) { - remove_all_button_.SetEnabled(rows > 0); -} - -void PasswordsPageView::OnConfirmMessageAccept() { - table_model_.ForgetAndRemoveAllSignons(); -} - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsPageView, protected -void PasswordsPageView::InitControlLayout() { - SetupButtonsAndLabels(); - SetupTable(); - - // Do the layout thing. - const int top_column_set_id = 0; - GridLayout* layout = GridLayout::CreatePanel(this); - SetLayoutManager(layout); - - // Design the grid. - ColumnSet* column_set = layout->AddColumnSet(top_column_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - // Fill the grid. - layout->StartRow(0, top_column_set_id); - layout->AddView(table_view_, 1, 8, GridLayout::FILL, - GridLayout::FILL); - layout->AddView(&remove_button_); - layout->StartRowWithPadding(0, top_column_set_id, 0, - views::kRelatedControlVerticalSpacing); - layout->SkipColumns(1); - layout->AddView(&remove_all_button_); - layout->StartRowWithPadding(0, top_column_set_id, 0, - views::kRelatedControlVerticalSpacing); - layout->SkipColumns(1); - layout->AddView(&show_button_); - layout->StartRowWithPadding(0, top_column_set_id, 0, - views::kRelatedControlVerticalSpacing); - layout->SkipColumns(1); - layout->AddView(&password_label_); - layout->AddPaddingRow(1, 0); - - // Ask the database for saved password data. - table_model_.GetAllSavedLoginsForProfile(); -} - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsPageView, private -void PasswordsPageView::SetupButtonsAndLabels() { - // Disable all buttons in the first place. - show_button_.set_parent_owned(false); - show_button_.SetEnabled(false); - - remove_button_.set_parent_owned(false); - remove_button_.SetEnabled(false); - - remove_all_button_.set_parent_owned(false); - remove_all_button_.SetEnabled(false); - - password_label_.set_parent_owned(false); -} - -void PasswordsPageView::SetupTable() { - // Tell the table model we are concern about how many rows it has. - table_model_.set_row_count_observer(this); - - // Creates the different columns for the table. - // The float resize values are the result of much tinkering. - std::vector<ui::TableColumn> columns; - columns.push_back(ui::TableColumn(IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN, - ui::TableColumn::LEFT, -1, 0.55f)); - columns.back().sortable = true; - columns.push_back(ui::TableColumn( - IDS_PASSWORDS_PAGE_VIEW_USERNAME_COLUMN, ui::TableColumn::LEFT, - -1, 0.37f)); - columns.back().sortable = true; - table_view_ = new views::TableView(&table_model_, columns, views::TEXT_ONLY, - true, true, true); - // Make the table initially sorted by host. - views::TableView::SortDescriptors sort; - sort.push_back(views::TableView::SortDescriptor( - IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN, true)); - table_view_->SetSortDescriptors(sort); - table_view_->SetObserver(this); -} - -void PasswordsPageView::HidePassword() { - password_label_.SetText(L""); - show_button_.SetLabel(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON))); -} - -void PasswordsPageView::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || *pref_name == prefs::kPasswordManagerAllowShowPasswords) { - bool show = allow_show_passwords_.GetValue(); - if (!show) - HidePassword(); - show_button_.SetVisible(show); - password_label_.SetVisible(show); - // Update the layout (it may depend on the button size). - show_button_.InvalidateLayout(); - Layout(); - } -} diff --git a/chrome/browser/ui/views/options/passwords_page_view.h b/chrome/browser/ui/views/options/passwords_page_view.h deleted file mode 100644 index 76eed4e..0000000 --- a/chrome/browser/ui/views/options/passwords_page_view.h +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_PASSWORDS_PAGE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_PASSWORDS_PAGE_VIEW_H_ -#pragma once - -#include <vector> - -#include "base/compiler_specific.h" -#include "base/scoped_ptr.h" -#include "base/stl_util-inl.h" -#include "chrome/browser/password_manager/password_store.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/views/confirm_message_box_dialog.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "ui/base/models/table_model.h" -#include "ui/base/text/text_elider.h" -#include "views/controls/button/native_button.h" -#include "views/controls/label.h" -#include "views/controls/table/table_view.h" -#include "views/controls/table/table_view_observer.h" -#include "views/window/dialog_delegate.h" -#include "views/window/window.h" -#include "webkit/glue/password_form.h" - -/////////////////////////////////////////////////////////////////////////////// -// PasswordTableModelObserver -// An observer interface to notify change of row count in a table model. This -// allow the container view of TableView(i.e. PasswordsPageView and -// ExceptionsPageView), to be notified of row count changes directly -// from the TableModel. We have two different observers in -// PasswordsTableModel, namely TableModelObserver and -// PasswordsTableModelObserver, rather than adding this event to -// TableModelObserver because only container view of -// PasswordsTableModel cares about this event. -class PasswordsTableModelObserver { - public: - virtual void OnRowCountChanged(size_t rows) = 0; -}; - -/////////////////////////////////////////////////////////////////////////////// -// MultiLabelButtons -// A button that can have 2 different labels set on it and for which the -// preferred size is the size of the widest string. -class MultiLabelButtons : public views::NativeButton { - public: - MultiLabelButtons(views::ButtonListener* listener, - const std::wstring& label, - const std::wstring& alt_label); - - virtual gfx::Size GetPreferredSize(); - - private: - std::wstring label_; - std::wstring alt_label_; - gfx::Size pref_size_; - - DISALLOW_COPY_AND_ASSIGN(MultiLabelButtons); -}; - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsTableModel -class PasswordsTableModel : public TableModel, - public PasswordStoreConsumer { - public: - explicit PasswordsTableModel(Profile* profile); - virtual ~PasswordsTableModel(); - - // TableModel methods. - virtual int RowCount() OVERRIDE; - virtual string16 GetText(int row, int column) OVERRIDE; - virtual int CompareValues(int row1, int row2, int column_id) OVERRIDE; - virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE; - - // Delete the PasswordForm at specified row from the database (and remove - // from view). - void ForgetAndRemoveSignon(int row); - - // Delete all saved signons for the active profile (via web data service), - // and clear the view. - void ForgetAndRemoveAllSignons(); - - // PasswordStoreConsumer implementation. - virtual void OnPasswordStoreRequestDone( - int handle, const std::vector<webkit_glue::PasswordForm*>& result); - - // Request saved logins data. - void GetAllSavedLoginsForProfile(); - - // Return the PasswordForm at the specified index. - webkit_glue::PasswordForm* GetPasswordFormAt(int row); - - // Set the observer who concerns about how many rows are in the table. - void set_row_count_observer(PasswordsTableModelObserver* observer) { - row_count_observer_ = observer; - } - - protected: - // Wraps the PasswordForm from the database and caches the display URL for - // quick sorting. - struct PasswordRow { - PasswordRow(const ui::SortedDisplayURL& url, - webkit_glue::PasswordForm* password_form) - : display_url(url), form(password_form) { - } - - // Contains the URL that is displayed along with the - ui::SortedDisplayURL display_url; - - // The underlying PasswordForm. We own this. - scoped_ptr<webkit_glue::PasswordForm> form; - }; - - // The password store associated with the currently active profile. - PasswordStore* password_store() { - return profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); - } - - // The TableView observing this model. - ui::TableModelObserver* observer_; - - // Dispatching row count events specific to this password manager table model - // to this observer. - PasswordsTableModelObserver* row_count_observer_; - - // Handle to any pending PasswordStore login lookup query. - int pending_login_query_; - - // The set of passwords we're showing. - typedef std::vector<PasswordRow*> PasswordRows; - PasswordRows saved_signons_; - STLElementDeleter<PasswordRows> saved_signons_cleanup_; - - Profile* profile_; - - private: - // Cancel any pending login query involving a callback. - void CancelLoginsQuery(); - - DISALLOW_COPY_AND_ASSIGN(PasswordsTableModel); -}; - -/////////////////////////////////////////////////////////////////////////////// -// PasswordsPageView -class PasswordsPageView : public OptionsPageView, - public views::TableViewObserver, - public views::ButtonListener, - public PasswordsTableModelObserver, - public ConfirmMessageBoxObserver { - public: - explicit PasswordsPageView(Profile* profile); - virtual ~PasswordsPageView(); - - // views::TableViewObserverImplementation. - virtual void OnSelectionChanged(); - - // views::ButtonListener implementation. - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // PasswordsTableModelObserver implementation. - virtual void OnRowCountChanged(size_t rows); - - // ConfirmMessageBoxObserver implementation. - virtual void OnConfirmMessageAccept(); - - protected: - virtual void InitControlLayout(); - - private: - // Helper to configure our buttons and labels. - void SetupButtonsAndLabels(); - - // Helper to configure our table view. - void SetupTable(); - - // Helper that hides the password. - void HidePassword(); - - // Handles changes to the observed preferences and updates the UI. - void NotifyPrefChanged(const std::string* pref_name); - - PasswordsTableModel table_model_; - views::TableView* table_view_; - - // The buttons and labels. - MultiLabelButtons show_button_; - views::NativeButton remove_button_; - views::NativeButton remove_all_button_; - views::Label password_label_; - webkit_glue::PasswordForm* current_selected_password_; - - // Tracks the preference that controls whether showing passwords is allowed. - BooleanPrefMember allow_show_passwords_; - - DISALLOW_COPY_AND_ASSIGN(PasswordsPageView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_PASSWORDS_PAGE_VIEW_H_ diff --git a/chrome/browser/ui/views/options/plugin_filter_page_view.cc b/chrome/browser/ui/views/options/plugin_filter_page_view.cc deleted file mode 100644 index 7d37ef3..0000000 --- a/chrome/browser/ui/views/options/plugin_filter_page_view.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/plugin_filter_page_view.h" - -#include "base/utf_string_conversions.h" -#include "chrome/browser/ui/options/show_options_url.h" -#include "chrome/common/url_constants.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" - -PluginFilterPageView::PluginFilterPageView(Profile* profile) - : ContentFilterPageView(profile, CONTENT_SETTINGS_TYPE_PLUGINS) { -} - -PluginFilterPageView::~PluginFilterPageView() { -} - -/////////////////////////////////////////////////////////////////////////////// -// PluginFilterPageView, ContentFilterPageView override: - -void PluginFilterPageView::InitControlLayout() { - ContentFilterPageView::InitControlLayout(); - - using views::GridLayout; - - GridLayout* layout = static_cast<GridLayout*>(GetLayoutManager()); - const int single_column_set_id = 0; - layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); - - views::Link* plugins_page_link = new views::Link( - UTF16ToWide(l10n_util::GetStringUTF16(IDS_PLUGIN_SELECTIVE_DISABLE))); - plugins_page_link->SetController(this); - - layout->StartRow(0, single_column_set_id); - layout->AddView(plugins_page_link, 1, 1, GridLayout::LEADING, - GridLayout::FILL); -} - -/////////////////////////////////////////////////////////////////////////////// -// PluginFilterPageView, views::LinkController implementation: - -void PluginFilterPageView::LinkActivated(views::Link* source, - int event_flags) { - browser::ShowOptionsURL(profile(), GURL(chrome::kChromeUIPluginsURL)); -} diff --git a/chrome/browser/ui/views/options/plugin_filter_page_view.h b/chrome/browser/ui/views/options/plugin_filter_page_view.h deleted file mode 100644 index 6a1d441..0000000 --- a/chrome/browser/ui/views/options/plugin_filter_page_view.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_PLUGIN_FILTER_PAGE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_PLUGIN_FILTER_PAGE_VIEW_H_ -#pragma once - -#include "chrome/browser/ui/views/options/content_filter_page_view.h" - -//////////////////////////////////////////////////////////////////////////////// -// PluginFilterPageView class is used to render the plugin content settings tab. - -class PluginFilterPageView : public ContentFilterPageView, - public views::LinkController { - public: - explicit PluginFilterPageView(Profile* profile); - virtual ~PluginFilterPageView(); - - private: - // Overridden from ContentFilterPageView: - virtual void InitControlLayout(); - - // Overridden from views::LinkController: - virtual void LinkActivated(views::Link* source, int event_flags); - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(PluginFilterPageView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_PLUGIN_FILTER_PAGE_VIEW_H_ - diff --git a/chrome/browser/ui/views/options/simple_content_exceptions_view.cc b/chrome/browser/ui/views/options/simple_content_exceptions_view.cc deleted file mode 100644 index 0c3e0fe..0000000 --- a/chrome/browser/ui/views/options/simple_content_exceptions_view.cc +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/options/simple_content_exceptions_view.h" - -#include <algorithm> -#include <vector> - -#include "base/utf_string_conversions.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/rect.h" -#include "views/controls/button/native_button.h" -#include "views/controls/table/table_view.h" -#include "views/layout/grid_layout.h" -#include "views/layout/layout_constants.h" -#include "views/window/window.h" - -static const int kExceptionsViewInsetSize = 5; -static SimpleContentExceptionsView* instance = NULL; - -// static -void SimpleContentExceptionsView::ShowExceptionsWindow( - gfx::NativeWindow parent, - RemoveRowsTableModel* model, - int title_message_id) { - scoped_ptr<RemoveRowsTableModel> owned_model(model); - if (!instance) { - instance = new SimpleContentExceptionsView(owned_model.release(), - title_message_id); - views::Window::CreateChromeWindow(parent, gfx::Rect(), instance); - } - - // This will show invisible windows and bring visible windows to the front. - instance->window()->Show(); -} - -SimpleContentExceptionsView::~SimpleContentExceptionsView() { - instance = NULL; - table_->SetModel(NULL); -} - -void SimpleContentExceptionsView::OnSelectionChanged() { - UpdateButtonState(); -} - -void SimpleContentExceptionsView::OnTableViewDelete( - views::TableView* table_view) { - Remove(); -} - -void SimpleContentExceptionsView::ButtonPressed(views::Button* sender, - const views::Event& event) { - switch (sender->tag()) { - case IDS_EXCEPTIONS_REMOVEALL_BUTTON: - RemoveAll(); - break; - case IDS_EXCEPTIONS_REMOVE_BUTTON: - Remove(); - break; - default: - NOTREACHED(); - } -} - -void SimpleContentExceptionsView::Layout() { - views::NativeButton* buttons[] = { remove_button_, remove_all_button_ }; - - // The buttons are placed in the parent, but we need to lay them out. - int max_y = - parent()->GetContentsBounds().bottom() - views::kButtonVEdgeMargin; - int x = views::kPanelHorizMargin; - - for (size_t i = 0; i < arraysize(buttons); ++i) { - gfx::Size pref = buttons[i]->GetPreferredSize(); - buttons[i]->SetBounds(x, max_y - pref.height(), pref.width(), - pref.height()); - x += pref.width() + views::kRelatedControlHorizontalSpacing; - } - - // Lay out the rest of this view. - View::Layout(); -} - -gfx::Size SimpleContentExceptionsView::GetPreferredSize() { - return gfx::Size(views::Window::GetLocalizedContentsSize( - IDS_SIMPLE_CONTENT_EXCEPTION_DIALOG_WIDTH_CHARS, - IDS_SIMPLE_CONTENT_EXCEPTION_DIALOG_HEIGHT_LINES)); -} - -void SimpleContentExceptionsView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (is_add && child == this) - Init(); -} - -std::wstring SimpleContentExceptionsView::GetWindowTitle() const { - return UTF16ToWide(l10n_util::GetStringUTF16(title_message_id_)); -} - -SimpleContentExceptionsView::SimpleContentExceptionsView( - RemoveRowsTableModel* model, - int title_message_id) - : model_(model), - table_(NULL), - remove_button_(NULL), - remove_all_button_(NULL), - title_message_id_(title_message_id) { -} - -void SimpleContentExceptionsView::Init() { - if (table_) - return; // We've already Init'd. - - using views::GridLayout; - - std::vector<ui::TableColumn> columns; - columns.push_back( - ui::TableColumn(IDS_EXCEPTIONS_HOSTNAME_HEADER, ui::TableColumn::LEFT, -1, - .75)); - columns.back().sortable = true; - columns.push_back( - ui::TableColumn(IDS_EXCEPTIONS_ACTION_HEADER, ui::TableColumn::LEFT, -1, - .25)); - columns.back().sortable = true; - table_ = new views::TableView(model_.get(), columns, views::TEXT_ONLY, - false, true, false); - views::TableView::SortDescriptors sort; - sort.push_back( - views::TableView::SortDescriptor(IDS_EXCEPTIONS_HOSTNAME_HEADER, true)); - table_->SetSortDescriptors(sort); - table_->SetObserver(this); - - remove_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_REMOVE_BUTTON))); - remove_button_->set_tag(IDS_EXCEPTIONS_REMOVE_BUTTON); - remove_all_button_ = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_REMOVEALL_BUTTON))); - remove_all_button_->set_tag(IDS_EXCEPTIONS_REMOVEALL_BUTTON); - - parent()->AddChildView(remove_button_); - parent()->AddChildView(remove_all_button_); - - GridLayout* layout = new GridLayout(this); - layout->SetInsets(kExceptionsViewInsetSize, kExceptionsViewInsetSize, - kExceptionsViewInsetSize, kExceptionsViewInsetSize); - SetLayoutManager(layout); - - const int single_column_layout_id = 0; - views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); - column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - layout->StartRow(1, single_column_layout_id); - layout->AddView(table_); - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - - UpdateButtonState(); -} - -RemoveRowsTableModel::Rows - SimpleContentExceptionsView::GetSelectedRows() const { - RemoveRowsTableModel::Rows rows; - for (views::TableView::iterator i(table_->SelectionBegin()); - i != table_->SelectionEnd(); ++i) - rows.insert(*i); - return rows; -} - -void SimpleContentExceptionsView::UpdateButtonState() { - remove_button_->SetEnabled(model_->CanRemoveRows(GetSelectedRows())); - remove_all_button_->SetEnabled(model_->RowCount() > 0); -} - -void SimpleContentExceptionsView::Remove() { - model_->RemoveRows(GetSelectedRows()); - UpdateButtonState(); -} - -void SimpleContentExceptionsView::RemoveAll() { - model_->RemoveAll(); - UpdateButtonState(); -} diff --git a/chrome/browser/ui/views/options/simple_content_exceptions_view.h b/chrome/browser/ui/views/options/simple_content_exceptions_view.h deleted file mode 100644 index 4e6a075..0000000 --- a/chrome/browser/ui/views/options/simple_content_exceptions_view.h +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_OPTIONS_SIMPLE_CONTENT_EXCEPTIONS_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_OPTIONS_SIMPLE_CONTENT_EXCEPTIONS_VIEW_H_ -#pragma once - -#include <string> - -#include "chrome/browser/remove_rows_table_model.h" -#include "chrome/common/content_settings.h" -#include "views/controls/button/button.h" -#include "views/controls/table/table_view_observer.h" -#include "views/window/dialog_delegate.h" - -namespace views { -class NativeButton; -class TableView; -} - -// SimpleContentExceptionsView is responsible for showing the user the set of -// site-specific permissions. The exceptions are shown in a table view by way -// of a RemoveRowsTableModel. The user can remove exceptions. -// Use the ShowExceptionsWindow method to create and show a -// SimpleContentExceptionsView, which is deleted when the window closes. -class SimpleContentExceptionsView : public views::View, - public views::ButtonListener, - public views::DialogDelegate, - public views::TableViewObserver { - public: - // Shows the Exceptions window. Takes ownership of |model|. - static void ShowExceptionsWindow(gfx::NativeWindow parent, - RemoveRowsTableModel* model, - int title_message_id); - - virtual ~SimpleContentExceptionsView(); - - // TableViewObserver overrides: - virtual void OnSelectionChanged(); - virtual void OnTableViewDelete(views::TableView* table_view); - - // views::ButtonListener implementation. - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // views::View overrides: - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - // views::WindowDelegate implementation. - virtual int GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_CANCEL; - } - virtual bool CanResize() const { return true; } - virtual std::wstring GetWindowTitle() const; - virtual views::View* GetContentsView() { return this; } - - private: - // Takes ownership of |model|. - explicit SimpleContentExceptionsView(RemoveRowsTableModel* model, - int title_message_id); - - void Init(); - - // Resets the enabled state of the buttons from the model. - void UpdateButtonState(); - - // Returns the set of selected rows. - RemoveRowsTableModel::Rows GetSelectedRows() const; - - // Removes the selected item. - void Remove(); - - // Removes all. - void RemoveAll(); - - // The model displayed in the table. - scoped_ptr<RemoveRowsTableModel> model_; - - views::TableView* table_; - - views::NativeButton* remove_button_; - views::NativeButton* remove_all_button_; - - // The message id of the window title. - int title_message_id_; - - DISALLOW_COPY_AND_ASSIGN(SimpleContentExceptionsView); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_SIMPLE_CONTENT_EXCEPTIONS_VIEW_H_ - diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 93bf4d77..0f1c70c 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2646,46 +2646,6 @@ 'browser/ui/gtk/notifications/balloon_view_gtk.h', 'browser/ui/gtk/notifications/balloon_view_host_gtk.cc', 'browser/ui/gtk/notifications/balloon_view_host_gtk.h', - 'browser/ui/gtk/options/advanced_contents_gtk.cc', - 'browser/ui/gtk/options/advanced_contents_gtk.h', - 'browser/ui/gtk/options/advanced_page_gtk.cc', - 'browser/ui/gtk/options/advanced_page_gtk.h', - 'browser/ui/gtk/options/content_exception_editor.cc', - 'browser/ui/gtk/options/content_exception_editor.h', - 'browser/ui/gtk/options/content_exceptions_window_gtk.cc', - 'browser/ui/gtk/options/content_exceptions_window_gtk.h', - 'browser/ui/gtk/options/content_filter_page_gtk.cc', - 'browser/ui/gtk/options/content_filter_page_gtk.h', - 'browser/ui/gtk/options/content_page_gtk.cc', - 'browser/ui/gtk/options/content_page_gtk.h', - 'browser/ui/gtk/options/content_settings_window_gtk.cc', - 'browser/ui/gtk/options/content_settings_window_gtk.h', - 'browser/ui/gtk/options/cookie_filter_page_gtk.cc', - 'browser/ui/gtk/options/cookie_filter_page_gtk.h', - 'browser/ui/gtk/options/cookies_view.cc', - 'browser/ui/gtk/options/cookies_view.h', - 'browser/ui/gtk/options/fonts_languages_window_gtk.cc', - 'browser/ui/gtk/options/fonts_page_gtk.cc', - 'browser/ui/gtk/options/fonts_page_gtk.h', - 'browser/ui/gtk/options/general_page_gtk.cc', - 'browser/ui/gtk/options/general_page_gtk.h', - 'browser/ui/gtk/options/languages_page_gtk.cc', - 'browser/ui/gtk/options/languages_page_gtk.h', - 'browser/ui/gtk/options/managed_prefs_banner_gtk.cc', - 'browser/ui/gtk/options/managed_prefs_banner_gtk.h', - 'browser/ui/gtk/options/options_layout_gtk.cc', - 'browser/ui/gtk/options/options_layout_gtk.h', - 'browser/ui/gtk/options/options_window_gtk.cc', - 'browser/ui/gtk/options/passwords_exceptions_page_gtk.cc', - 'browser/ui/gtk/options/passwords_exceptions_page_gtk.h', - 'browser/ui/gtk/options/passwords_exceptions_window_gtk.cc', - 'browser/ui/gtk/options/passwords_exceptions_window_gtk.h', - 'browser/ui/gtk/options/passwords_page_gtk.cc', - 'browser/ui/gtk/options/passwords_page_gtk.h', - 'browser/ui/gtk/options/simple_content_exceptions_window.cc', - 'browser/ui/gtk/options/simple_content_exceptions_window.h', - 'browser/ui/gtk/options/url_picker_dialog_gtk.cc', - 'browser/ui/gtk/options/url_picker_dialog_gtk.h', 'browser/ui/gtk/overflow_button.cc', 'browser/ui/gtk/overflow_button.h', 'browser/ui/gtk/owned_widget_gtk.cc', @@ -3039,51 +2999,6 @@ 'browser/ui/views/notifications/balloon_view.h', 'browser/ui/views/notifications/balloon_view_host.cc', 'browser/ui/views/notifications/balloon_view_host.h', - 'browser/ui/views/options/advanced_contents_view.cc', - 'browser/ui/views/options/advanced_contents_view.h', - 'browser/ui/views/options/advanced_page_view.cc', - 'browser/ui/views/options/advanced_page_view.h', - 'browser/ui/views/options/content_exceptions_table_view.cc', - 'browser/ui/views/options/content_exceptions_table_view.h', - 'browser/ui/views/options/content_filter_page_view.cc', - 'browser/ui/views/options/content_filter_page_view.h', - 'browser/ui/views/options/content_page_view.cc', - 'browser/ui/views/options/content_page_view.h', - 'browser/ui/views/options/content_settings_window_view.cc', - 'browser/ui/views/options/content_settings_window_view.h', - 'browser/ui/views/options/cookie_filter_page_view.cc', - 'browser/ui/views/options/cookie_filter_page_view.h', - 'browser/ui/views/options/cookies_view.cc', - 'browser/ui/views/options/cookies_view.h', - 'browser/ui/views/options/exception_editor_view.cc', - 'browser/ui/views/options/exception_editor_view.h', - 'browser/ui/views/options/exceptions_page_view.cc', - 'browser/ui/views/options/exceptions_page_view.h', - 'browser/ui/views/options/exceptions_view.cc', - 'browser/ui/views/options/exceptions_view.h', - 'browser/ui/views/options/fonts_languages_window_view.cc', - 'browser/ui/views/options/fonts_languages_window_view.h', - 'browser/ui/views/options/fonts_page_view.cc', - 'browser/ui/views/options/fonts_page_view.h', - 'browser/ui/views/options/general_page_view.cc', - 'browser/ui/views/options/general_page_view.h', - 'browser/ui/views/options/languages_page_view.cc', - 'browser/ui/views/options/languages_page_view.h', - 'browser/ui/views/options/managed_prefs_banner_view.cc', - 'browser/ui/views/options/managed_prefs_banner_view.h', - 'browser/ui/views/options/options_group_view.cc', - 'browser/ui/views/options/options_group_view.h', - 'browser/ui/views/options/options_page_view.cc', - 'browser/ui/views/options/options_page_view.h', - 'browser/ui/views/options/options_window_view.cc', - 'browser/ui/views/options/passwords_exceptions_window_view.cc', - 'browser/ui/views/options/passwords_exceptions_window_view.h', - 'browser/ui/views/options/passwords_page_view.cc', - 'browser/ui/views/options/passwords_page_view.h', - 'browser/ui/views/options/plugin_filter_page_view.cc', - 'browser/ui/views/options/plugin_filter_page_view.h', - 'browser/ui/views/options/simple_content_exceptions_view.cc', - 'browser/ui/views/options/simple_content_exceptions_view.h', 'browser/ui/views/page_info_bubble_view.cc', 'browser/ui/views/page_info_bubble_view.h', 'browser/ui/views/pinned_contents_info_bubble.cc', @@ -3831,7 +3746,6 @@ ['include', '^browser/ui/gtk/keyword_editor_view.h'], ['include', '^browser/ui/gtk/nine_box.cc'], ['include', '^browser/ui/gtk/nine_box.h'], - ['include', '^browser/ui/gtk/options/'], ['include', '^browser/ui/gtk/owned_widget_gtk.cc'], ['include', '^browser/ui/gtk/owned_widget_gtk.h'], ['include', '^browser/ui/gtk/popup_blocked_animation_gtk.cc'], @@ -3985,8 +3899,6 @@ ['include', '^browser/ui/views/location_bar_view.h'], ['include', '^browser/ui/views/notifications/balloon_view_host.cc'], ['include', '^browser/ui/views/notifications/balloon_view_host.h'], - ['include', '^browser/ui/views/options/options_page_view.cc'], - ['include', '^browser/ui/views/options/options_page_view.h'], ['include', '^browser/ui/views/page_info_bubble_view.cc'], ['include', '^browser/ui/views/panel_controller.cc'], ['include', '^browser/ui/views/panel_controller.h'], diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 7a4bea3..790953f 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1303,9 +1303,6 @@ 'browser/ui/gtk/gtk_expanded_container_unittest.cc', 'browser/ui/gtk/gtk_theme_provider_unittest.cc', 'browser/ui/gtk/keyword_editor_view_unittest.cc', - 'browser/ui/gtk/options/content_exceptions_window_gtk_unittest.cc', - 'browser/ui/gtk/options/cookies_view_unittest.cc', - 'browser/ui/gtk/options/languages_page_gtk_unittest.cc', 'browser/ui/gtk/reload_button_gtk_unittest.cc', 'browser/ui/gtk/status_icons/status_tray_gtk_unittest.cc', 'browser/ui/gtk/tabs/tab_renderer_gtk_unittest.cc', diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index 1387d51..18fdc80 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -195,12 +195,12 @@ const char kContentSettingsExceptionsSubPage[] = "contentExceptions"; const char kDefaultOptionsSubPage[] = ""; const char kImportDataSubPage[] = "importData"; const char kInstantConfirmPage[] = "instantConfirm"; +const char kLanguageOptionsSubPage[] = "language"; const char kPersonalOptionsSubPage[] = "personal"; const char kPasswordManagerSubPage[] = "passwords"; const char kSearchEnginesSubPage[] = "searchEngines"; #if defined(OS_CHROMEOS) const char kInternetOptionsSubPage[] = "internet"; -const char kLanguageOptionsSubPage[] = "languages"; const char kSystemOptionsSubPage[] = "system"; #endif diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index 971a4df..c4c8d4f 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -192,12 +192,12 @@ extern const char kContentSettingsSubPage[]; extern const char kContentSettingsExceptionsSubPage[]; extern const char kImportDataSubPage[]; extern const char kInstantConfirmPage[]; +extern const char kLanguageOptionsSubPage[]; extern const char kPersonalOptionsSubPage[]; extern const char kPasswordManagerSubPage[]; extern const char kSearchEnginesSubPage[]; #if defined(OS_CHROMEOS) extern const char kInternetOptionsSubPage[]; -extern const char kLanguageOptionsSubPage[]; extern const char kSystemOptionsSubPage[]; #endif diff --git a/chrome/test/test_browser_window.h b/chrome/test/test_browser_window.h index cf768de..a384d7e 100644 --- a/chrome/test/test_browser_window.h +++ b/chrome/test/test_browser_window.h @@ -78,8 +78,6 @@ class TestBrowserWindow : public BrowserWindow { virtual DownloadShelf* GetDownloadShelf(); virtual void ShowReportBugDialog() {} virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) {} - virtual void ShowContentSettingsWindow(ContentSettingsType content_type, - Profile* profile) {} virtual void ShowCollectedCookiesDialog(TabContents* tab_contents) {} virtual void ShowProfileErrorDialog(int message_id) {} virtual void ShowThemeInstallBubble() {} diff --git a/content/browser/tab_contents/tab_contents_delegate.cc b/content/browser/tab_contents/tab_contents_delegate.cc index 0d099cb..dc316fb 100644 --- a/content/browser/tab_contents/tab_contents_delegate.cc +++ b/content/browser/tab_contents/tab_contents_delegate.cc @@ -171,7 +171,7 @@ void TabContentsDelegate::ShowRepostFormWarningDialog( TabContents* tab_contents) { } -void TabContentsDelegate::ShowContentSettingsWindow( +void TabContentsDelegate::ShowContentSettingsPage( ContentSettingsType content_type) { } diff --git a/content/browser/tab_contents/tab_contents_delegate.h b/content/browser/tab_contents/tab_contents_delegate.h index 6264575..a079198 100644 --- a/content/browser/tab_contents/tab_contents_delegate.h +++ b/content/browser/tab_contents/tab_contents_delegate.h @@ -269,8 +269,8 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { // Shows the repost form confirmation dialog box. virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); - // Shows the Content Settings dialog for a given content type. - virtual void ShowContentSettingsWindow(ContentSettingsType content_type); + // Shows the Content Settings page for a given content type. + virtual void ShowContentSettingsPage(ContentSettingsType content_type); // Shows the cookies collected in the tab contents. virtual void ShowCollectedCookiesDialog(TabContents* tab_contents); |