Index: chrome/browser/views/options/geolocation_filter_page_view.cc |
diff --git a/chrome/browser/views/options/geolocation_filter_page_view.cc b/chrome/browser/views/options/geolocation_filter_page_view.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b69f58fd6f6cd055307e7f552b84ee3e4a63f2ab |
--- /dev/null |
+++ b/chrome/browser/views/options/geolocation_filter_page_view.cc |
@@ -0,0 +1,133 @@ |
+// 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 "chrome/browser/views/options/geolocation_filter_page_view.h" |
+ |
+#include "app/gfx/canvas.h" |
+#include "app/gfx/native_theme_win.h" |
+#include "app/l10n_util.h" |
+#include "app/resource_bundle.h" |
+#include "chrome/browser/host_content_settings_map.h" |
+#include "chrome/browser/profile.h" |
+#include "chrome/browser/views/options/exceptions_view.h" |
+#include "chrome/common/pref_names.h" |
+#include "grit/generated_resources.h" |
+#include "grit/locale_settings.h" |
+#include "views/controls/button/radio_button.h" |
+#include "views/grid_layout.h" |
+#include "views/standard_layout.h" |
+#include "views/widget/widget.h" |
+#include "views/window/window.h" |
+ |
+GeolocationFilterPageView::GeolocationFilterPageView(Profile* profile) |
+ : OptionsPageView(profile), |
+ ask_radio_(NULL), |
+ block_radio_(NULL), |
+ allow_radio_(NULL), |
+ exceptions_button_(NULL) { |
+} |
+ |
+GeolocationFilterPageView::~GeolocationFilterPageView() { |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// GeolocationFilterPageView, OptionsPageView implementation: |
+void GeolocationFilterPageView::InitControlLayout() { |
+ // Make sure we don't leak memory by calling this more than once. |
+ DCHECK(!exceptions_button_); |
+ using views::GridLayout; |
+ |
+ GridLayout* layout = new GridLayout(this); |
+ layout->SetInsets(5, 5, 5, 5); |
+ SetLayoutManager(layout); |
+ |
+ const int single_column_set_id = 0; |
+ views::ColumnSet* column_set = layout->AddColumnSet(single_column_set_id); |
+ column_set->AddPaddingColumn(0, kRelatedControlVerticalSpacing); |
+ column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
+ GridLayout::USE_PREF, 0, 0); |
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
+ |
+ views::Label* title_label = new views::Label( |
+ l10n_util::GetString(IDS_GEOLOCATION_SETTING_LABEL)); |
+ 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, kRelatedControlVerticalSpacing); |
+ |
+ const int radio_button_group = 0; |
+ ask_radio_ = new views::RadioButton( |
+ l10n_util::GetString(IDS_GEOLOCATION_ASK_ALL_RADIO), radio_button_group); |
+ ask_radio_->set_listener(this); |
+ ask_radio_->SetMultiLine(true); |
+ |
+ block_radio_ = new views::RadioButton( |
+ l10n_util::GetString(IDS_GEOLOCATION_BLOCK_ALL_RADIO), |
+ radio_button_group); |
+ block_radio_->set_listener(this); |
+ block_radio_->SetMultiLine(true); |
+ |
+ allow_radio_ = new views::RadioButton( |
+ l10n_util::GetString(IDS_GEOLOCATION_ALLOW_ALL_RADIO), |
+ radio_button_group); |
+ allow_radio_->set_listener(this); |
+ allow_radio_->SetMultiLine(true); |
+ |
+ layout->StartRow(0, single_column_set_id); |
+ layout->AddView(ask_radio_); |
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
+ layout->StartRow(0, single_column_set_id); |
+ layout->AddView(block_radio_); |
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
+ layout->StartRow(0, single_column_set_id); |
+ layout->AddView(allow_radio_); |
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
+ |
+ ContentSetting default_setting = profile()->GetHostContentSettingsMap()-> |
+ GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
+ // Now that these have been added to the view hierarchy, it's safe to call |
+ // SetChecked() on them. |
+ if (default_setting == CONTENT_SETTING_ASK) { |
+ ask_radio_->SetChecked(true); |
+ } else if (default_setting == CONTENT_SETTING_BLOCK) { |
+ block_radio_->SetChecked(true); |
+ } else if (default_setting == CONTENT_SETTING_ALLOW) { |
+ DCHECK(default_setting == CONTENT_SETTING_ALLOW); |
+ allow_radio_->SetChecked(true); |
+ } |
+ |
+ exceptions_button_ = new views::NativeButton(this, |
+ l10n_util::GetString(IDS_COOKIES_EXCEPTIONS_BUTTON)); |
+ |
+ layout->StartRow(0, single_column_set_id); |
+ layout->AddView(exceptions_button_, 1, 1, GridLayout::LEADING, |
+ GridLayout::FILL); |
+} |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
+// GeolocationFilterPageView, views::ButtonListener implementation: |
+ |
+void GeolocationFilterPageView::ButtonPressed(views::Button* sender, |
+ const views::Event& event) { |
+ if (sender == exceptions_button_) { |
+ ExceptionsView::ShowExceptionsWindow(GetWindow()->GetNativeWindow(), |
+ profile()->GetHostContentSettingsMap(), |
+ CONTENT_SETTINGS_TYPE_GEOLOCATION); |
+ return; |
+ } |
+ |
+ ContentSetting setting = CONTENT_SETTING_ASK; |
+ if (sender == ask_radio_) |
+ setting = CONTENT_SETTING_ASK; |
+ else if (sender == block_radio_) |
+ setting = CONTENT_SETTING_BLOCK; |
+ else if (sender == allow_radio_) |
+ setting = CONTENT_SETTING_ALLOW; |
+ else |
+ NOTREACHED() << "unknown sender"; |
+ profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, setting); |
+} |