summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-26 20:34:01 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-26 20:34:01 +0000
commit2e0d5f8bb1720c36a197d3b2b8ca305fb4f7c26b (patch)
tree3e82128d4b0f0401a7121bb65b893d47a3f0c57e
parentfd1011217ef2440ac2f21ced2ad7660838dc003f (diff)
downloadchromium_src-2e0d5f8bb1720c36a197d3b2b8ca305fb4f7c26b.zip
chromium_src-2e0d5f8bb1720c36a197d3b2b8ca305fb4f7c26b.tar.gz
chromium_src-2e0d5f8bb1720c36a197d3b2b8ca305fb4f7c26b.tar.bz2
First cut at content settings exceptions lists.
This only shows the existing exceptions (doesn't allow you to add or remove them). It also only works for image exceptions. It always shows the exceptions, instead of hiding/showing them when you press the exceptions button. BUG=48862 TEST=manual Review URL: http://codereview.chromium.org/2856058 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53672 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/dom_ui/content_settings_handler.cc60
-rw-r--r--chrome/browser/dom_ui/content_settings_handler.h4
-rw-r--r--chrome/browser/resources/options.html1
-rw-r--r--chrome/browser/resources/options/chromeos_accounts_user_list.js4
-rw-r--r--chrome/browser/resources/options/content_settings.html2
-rw-r--r--chrome/browser/resources/options/content_settings.js15
-rw-r--r--chrome/browser/resources/options/content_settings_exceptions_list.js101
-rw-r--r--chrome/browser/resources/shared/css/list.css1
8 files changed, 167 insertions, 21 deletions
diff --git a/chrome/browser/dom_ui/content_settings_handler.cc b/chrome/browser/dom_ui/content_settings_handler.cc
index 9a006b8..897291e 100644
--- a/chrome/browser/dom_ui/content_settings_handler.cc
+++ b/chrome/browser/dom_ui/content_settings_handler.cc
@@ -102,6 +102,10 @@ void ContentSettingsHandler::GetLocalizedValues(
l10n_util::GetString(IDS_COOKIES_EXCEPTIONS_BUTTON));
localized_strings->SetString(L"contentSettingsPage",
l10n_util::GetString(IDS_CONTENT_SETTINGS_TITLE));
+ localized_strings->SetString(L"allowException",
+ l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON));
+ localized_strings->SetString(L"blockException",
+ l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON));
// Cookies filter.
localized_strings->SetString(L"cookies_tab_label",
@@ -192,21 +196,9 @@ void ContentSettingsHandler::GetLocalizedValues(
l10n_util::GetString(IDS_NOTIFICATIONS_BLOCK_RADIO));
}
-void ContentSettingsHandler::RegisterMessages() {
- dom_ui_->RegisterMessageCallback("getContentFilterSettings",
- NewCallback(this,
- &ContentSettingsHandler::GetContentFilterSettings));
- dom_ui_->RegisterMessageCallback("setContentFilter",
- NewCallback(this,
- &ContentSettingsHandler::SetContentFilter));
- dom_ui_->RegisterMessageCallback("setAllowThirdPartyCookies",
- NewCallback(this,
- &ContentSettingsHandler::SetAllowThirdPartyCookies));
-}
-
-void ContentSettingsHandler::GetContentFilterSettings(const Value* value) {
+void ContentSettingsHandler::Initialize() {
// We send a list of the <input> IDs that should be checked.
- DictionaryValue dict_value;
+ DictionaryValue filter_settings;
const HostContentSettingsMap* settings_map =
dom_ui_->GetProfile()->GetHostContentSettingsMap();
@@ -216,17 +208,51 @@ void ContentSettingsHandler::GetContentFilterSettings(const Value* value) {
ContentSetting default_setting = settings_map->
GetDefaultContentSetting(type);
- dict_value.SetString(ContentSettingsTypeToGroupName(type),
- ContentSettingToString(default_setting));
+ filter_settings.SetString(ContentSettingsTypeToGroupName(type),
+ ContentSettingToString(default_setting));
}
dom_ui_->CallJavascriptFunction(
- L"ContentSettings.setInitialContentFilterSettingsValue", dict_value);
+ L"ContentSettings.setInitialContentFilterSettingsValue", filter_settings);
scoped_ptr<Value> bool_value(Value::CreateBooleanValue(
settings_map->BlockThirdPartyCookies()));
dom_ui_->CallJavascriptFunction(
L"ContentSettings.setBlockThirdPartyCookies", *bool_value.get());
+
+ UpdateImagesExceptionsViewFromModel();
+}
+
+// TODO(estade): generalize this function to work on all content settings types
+// rather than just images.
+// TODO(estade): call this in response to content exceptions change
+// notifications.
+void ContentSettingsHandler::UpdateImagesExceptionsViewFromModel() {
+ HostContentSettingsMap::SettingsForOneType entries;
+ const HostContentSettingsMap* settings_map =
+ dom_ui_->GetProfile()->GetHostContentSettingsMap();
+ settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, &entries);
+
+ ListValue exceptions;
+ for (size_t i = 0; i < entries.size(); ++i) {
+ ListValue* exception = new ListValue();
+ exception->Append(new StringValue(entries[i].first.AsString()));
+ exception->Append(
+ new StringValue(ContentSettingToString(entries[i].second)));
+ exceptions.Append(exception);
+ }
+
+ dom_ui_->CallJavascriptFunction(
+ L"ContentSettings.setImagesExceptions", exceptions);
+}
+
+void ContentSettingsHandler::RegisterMessages() {
+ dom_ui_->RegisterMessageCallback("setContentFilter",
+ NewCallback(this,
+ &ContentSettingsHandler::SetContentFilter));
+ dom_ui_->RegisterMessageCallback("setAllowThirdPartyCookies",
+ NewCallback(this,
+ &ContentSettingsHandler::SetAllowThirdPartyCookies));
}
void ContentSettingsHandler::SetContentFilter(const Value* value) {
diff --git a/chrome/browser/dom_ui/content_settings_handler.h b/chrome/browser/dom_ui/content_settings_handler.h
index b20651a..a9fac0c 100644
--- a/chrome/browser/dom_ui/content_settings_handler.h
+++ b/chrome/browser/dom_ui/content_settings_handler.h
@@ -15,10 +15,12 @@ class ContentSettingsHandler : public OptionsPageUIHandler {
// OptionsUIHandler implementation.
virtual void GetLocalizedValues(DictionaryValue* localized_strings);
+ virtual void Initialize();
+
virtual void RegisterMessages();
private:
- void GetContentFilterSettings(const Value* value);
+ void UpdateImagesExceptionsViewFromModel();
void SetContentFilter(const Value* value);
void SetAllowThirdPartyCookies(const Value* value);
diff --git a/chrome/browser/resources/options.html b/chrome/browser/resources/options.html
index 4a76423..66370bf 100644
--- a/chrome/browser/resources/options.html
+++ b/chrome/browser/resources/options.html
@@ -31,6 +31,7 @@
<script src="options/advanced_options.js"></script>
<script src="options/browser_options.js"></script>
<script src="options/personal_options.js"></script>
+<script src="options/content_settings_exceptions_list.js"></script>
<script src="options/content_settings_ui.js"></script>
<script src="options/content_settings.js"></script>
<script src="options/add_startup_page_overlay.js"></script>
diff --git a/chrome/browser/resources/options/chromeos_accounts_user_list.js b/chrome/browser/resources/options/chromeos_accounts_user_list.js
index 2f654cc..f641a51 100644
--- a/chrome/browser/resources/options/chromeos_accounts_user_list.js
+++ b/chrome/browser/resources/options/chromeos_accounts_user_list.js
@@ -52,9 +52,7 @@ cr.define('options.accounts', function() {
* @param {Object} user A user to be added to user list.
*/
addUser: function(user) {
- var dataModel = this.dataModel;
- dataModel.splice(dataModel.length, 0, user);
-
+ this.dataModel.push(user);
this.updateBackend_();
},
diff --git a/chrome/browser/resources/options/content_settings.html b/chrome/browser/resources/options/content_settings.html
index 2e667cb..83071e1 100644
--- a/chrome/browser/resources/options/content_settings.html
+++ b/chrome/browser/resources/options/content_settings.html
@@ -96,6 +96,8 @@
</td>
</tr>
</table>
+
+ <list id="imagesExceptionsList"></list>
</div>
<!-- JavaScript filter tab contents -->
diff --git a/chrome/browser/resources/options/content_settings.js b/chrome/browser/resources/options/content_settings.js
index c17a84e..0c8eff8 100644
--- a/chrome/browser/resources/options/content_settings.js
+++ b/chrome/browser/resources/options/content_settings.js
@@ -48,7 +48,11 @@ ContentSettings.prototype = {
// Images filter page ------------------------------------------------------
$('images-exceptions-button').onclick = function(event) {
// TODO(estade): show a dialog.
+ // TODO(estade): remove this hack.
+ imagesExceptionsList.redraw();
};
+
+ options.contentSettings.ExceptionsList.decorate($('imagesExceptionsList'));
},
/**
@@ -84,6 +88,17 @@ ContentSettings.setInitialContentFilterSettingsValue = function(dict) {
};
/**
+ * Initializes the image exceptions list.
+ * @param {Array} list An array of pairs, where the first element of each pair
+ * is the filter string, and the second is the setting (allow/block).
+ */
+ContentSettings.setImagesExceptions = function(list) {
+ for (var i = 0; i < list.length; ++i) {
+ imagesExceptionsList.addException(list[i]);
+ }
+};
+
+/**
* Sets the initial value for the Third Party Cookies checkbox.
* @param {boolean=} block True if we are blocking third party cookies.
*/
diff --git a/chrome/browser/resources/options/content_settings_exceptions_list.js b/chrome/browser/resources/options/content_settings_exceptions_list.js
new file mode 100644
index 0000000..e2b14f6
--- /dev/null
+++ b/chrome/browser/resources/options/content_settings_exceptions_list.js
@@ -0,0 +1,101 @@
+// 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.
+
+cr.define('options.contentSettings', function() {
+ const List = cr.ui.List;
+ const ListItem = cr.ui.ListItem;
+ const ArrayDataModel = cr.ui.ArrayDataModel;
+
+ /**
+ * Creates a new exceptions list item.
+ * @param {Array} exception A pair of the form [filter, setting].
+ * @constructor
+ * @extends {cr.ui.ListItem}
+ */
+ function ExceptionsListItem(exception) {
+ var el = cr.doc.createElement('li');
+ el.exceptionsPattern = exception[0];
+ el.__proto__ = ExceptionsListItem.prototype;
+ el.decorate();
+
+ if (exception[1] == 'allow')
+ el.option_allow.selected = 'selected';
+ else if (exception[1] == 'block')
+ el.option_block.selected = 'selected';
+
+ return el;
+ }
+
+ ExceptionsListItem.prototype = {
+ __proto__: ListItem.prototype,
+
+ /**
+ * Called when an element is decorated as a list item.
+ */
+ decorate: function() {
+ ListItem.prototype.decorate.call(this);
+
+ var input = cr.doc.createElement('input');
+ input.type = 'text';
+ input.value = this.exceptionsPattern;
+ this.appendChild(input);
+
+ var select = cr.doc.createElement('select');
+ var option_allow = cr.doc.createElement('option');
+ option_allow.textContent = templateData.allowException;
+ var option_block = cr.doc.createElement('option');
+ option_block.textContent = templateData.blockException;
+
+ select.appendChild(option_allow);
+ select.appendChild(option_block);
+ this.appendChild(select);
+
+ this.input = input;
+ this.select = select;
+ this.option_allow = option_allow;
+ this.option_block = option_block
+ }
+ };
+
+ /**
+ * Creates a new exceptions list.
+ * @constructor
+ * @extends {cr.ui.List}
+ */
+ var ExceptionsList = cr.ui.define('list');
+
+ ExceptionsList.prototype = {
+ __proto__: List.prototype,
+
+ /**
+ * Called when an element is decorated as a list.
+ */
+ decorate: function() {
+ List.prototype.decorate.call(this);
+
+ this.dataModel = new ArrayDataModel([]);
+ },
+
+ /**
+ * Creates an item to go in the list.
+ * @param {Object} entry The element from the data model for this row.
+ */
+ createItem: function(entry) {
+ return new ExceptionsListItem(entry);
+ },
+
+ /**
+ * Adds an exception to the model.
+ * @param {Array} entry A pair of the form [filter, setting].
+ */
+ addException: function(entry) {
+ this.dataModel.push(entry);
+ }
+ };
+
+ return {
+ ExceptionsListItem: ExceptionsListItem,
+ ExceptionsList: ExceptionsList
+ };
+});
diff --git a/chrome/browser/resources/shared/css/list.css b/chrome/browser/resources/shared/css/list.css
index 60cad42..65b16e6 100644
--- a/chrome/browser/resources/shared/css/list.css
+++ b/chrome/browser/resources/shared/css/list.css
@@ -5,6 +5,7 @@ list {
overflow: auto;
position: relative; /* Make sure that item offsets are relative to the
list. */
+ height: 200px;
}
list > * {