summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/dom_ui/content_settings_handler.cc78
-rw-r--r--chrome/browser/dom_ui/content_settings_handler.h4
-rw-r--r--chrome/browser/dom_ui/dom_ui.cc45
-rw-r--r--chrome/browser/dom_ui/dom_ui.h6
-rw-r--r--chrome/browser/first_run/first_run_gtk.cc5
-rw-r--r--chrome/browser/resources/options/content_settings.html26
-rw-r--r--chrome/browser/resources/options/content_settings.js26
-rw-r--r--chrome/browser/resources/options/content_settings_exceptions_area.js57
-rw-r--r--chrome/browser/resources/options/options_page.css4
9 files changed, 176 insertions, 75 deletions
diff --git a/chrome/browser/dom_ui/content_settings_handler.cc b/chrome/browser/dom_ui/content_settings_handler.cc
index dfa5d9c..a6cb452 100644
--- a/chrome/browser/dom_ui/content_settings_handler.cc
+++ b/chrome/browser/dom_ui/content_settings_handler.cc
@@ -231,14 +231,12 @@ void ContentSettingsHandler::Initialize() {
dom_ui_->CallJavascriptFunction(
L"ContentSettings.setBlockThirdPartyCookies", *bool_value.get());
- UpdateImagesExceptionsViewFromModel();
+ UpdateAllExceptionsViewsFromModel();
notification_registrar_.Add(
this, NotificationType::CONTENT_SETTINGS_CHANGED,
Source<const HostContentSettingsMap>(settings_map));
}
-// TODO(estade): generalize this function to work on all content settings types
-// rather than just images.
void ContentSettingsHandler::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -248,21 +246,26 @@ void ContentSettingsHandler::Observe(NotificationType type,
const ContentSettingsDetails* settings_details =
static_cast<Details<const ContentSettingsDetails> >(details).ptr();
- if (settings_details->type() == CONTENT_SETTINGS_TYPE_IMAGES ||
- settings_details->update_all_types()) {
- // TODO(estade): we pretend update_all() is always true.
- UpdateImagesExceptionsViewFromModel();
+ // TODO(estade): we pretend update_all() is always true.
+ if (settings_details->update_all_types())
+ UpdateAllExceptionsViewsFromModel();
+ else
+ UpdateExceptionsViewFromModel(settings_details->type());
+}
+
+void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() {
+ for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1;
+ type < CONTENT_SETTINGS_NUM_TYPES; ++type) {
+ UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type));
}
}
-// TODO(estade): generalize this function to work on all content settings types
-// rather than just images.
-void ContentSettingsHandler::UpdateImagesExceptionsViewFromModel() {
+void ContentSettingsHandler::UpdateExceptionsViewFromModel(
+ ContentSettingsType type) {
HostContentSettingsMap::SettingsForOneType entries;
const HostContentSettingsMap* settings_map =
dom_ui_->GetProfile()->GetHostContentSettingsMap();
- settings_map->GetSettingsForOneType(
- CONTENT_SETTINGS_TYPE_IMAGES, "", &entries);
+ settings_map->GetSettingsForOneType(type, "", &entries);
ListValue exceptions;
for (size_t i = 0; i < entries.size(); ++i) {
@@ -273,8 +276,9 @@ void ContentSettingsHandler::UpdateImagesExceptionsViewFromModel() {
exceptions.Append(exception);
}
+ StringValue type_string(ContentSettingsTypeToGroupName(type));
dom_ui_->CallJavascriptFunction(
- L"ContentSettings.setImagesExceptions", exceptions);
+ L"ContentSettings.setExceptions", type_string, exceptions);
}
void ContentSettingsHandler::RegisterMessages() {
@@ -284,10 +288,10 @@ void ContentSettingsHandler::RegisterMessages() {
dom_ui_->RegisterMessageCallback("setAllowThirdPartyCookies",
NewCallback(this,
&ContentSettingsHandler::SetAllowThirdPartyCookies));
- dom_ui_->RegisterMessageCallback("removeImageExceptions",
+ dom_ui_->RegisterMessageCallback("removeExceptions",
NewCallback(this,
&ContentSettingsHandler::RemoveExceptions));
- dom_ui_->RegisterMessageCallback("setImageException",
+ dom_ui_->RegisterMessageCallback("setException",
NewCallback(this,
&ContentSettingsHandler::SetException));
dom_ui_->RegisterMessageCallback("checkExceptionPatternValidity",
@@ -317,47 +321,52 @@ void ContentSettingsHandler::SetAllowThirdPartyCookies(const Value* value) {
allow == L"true");
}
-// TODO(estade): generalize this function to work on all content settings types
-// rather than just images.
void ContentSettingsHandler::RemoveExceptions(const Value* value) {
const ListValue* list_value = static_cast<const ListValue*>(value);
+ size_t arg_i = 0;
+ std::string type_string;
+ CHECK(list_value->GetString(arg_i++, &type_string));
HostContentSettingsMap* settings_map =
dom_ui_->GetProfile()->GetHostContentSettingsMap();
- for (size_t i = 0; i < list_value->GetSize(); ++i) {
+ while (arg_i < list_value->GetSize()) {
std::string pattern;
- bool rv = list_value->GetString(i, &pattern);
+ bool rv = list_value->GetString(arg_i++, &pattern);
DCHECK(rv);
- settings_map->SetContentSetting(HostContentSettingsMap::Pattern(pattern),
- CONTENT_SETTINGS_TYPE_IMAGES,
- "",
- CONTENT_SETTING_DEFAULT);
+ settings_map->SetContentSetting(
+ HostContentSettingsMap::Pattern(pattern),
+ ContentSettingsTypeFromGroupName(type_string),
+ "",
+ CONTENT_SETTING_DEFAULT);
}
}
-// TODO(estade): generalize this function to work on all content settings types
-// rather than just images.
void ContentSettingsHandler::SetException(const Value* value) {
const ListValue* list_value = static_cast<const ListValue*>(value);
+ size_t arg_i = 0;
+ std::string type_string;
+ CHECK(list_value->GetString(arg_i++, &type_string));
std::string pattern;
- bool rv = list_value->GetString(0, &pattern);
- DCHECK(rv);
+ CHECK(list_value->GetString(arg_i++, &pattern));
std::string setting;
- rv = list_value->GetString(1, &setting);
- DCHECK(rv);
+ CHECK(list_value->GetString(arg_i++, &setting));
HostContentSettingsMap* settings_map =
dom_ui_->GetProfile()->GetHostContentSettingsMap();
settings_map->SetContentSetting(HostContentSettingsMap::Pattern(pattern),
- CONTENT_SETTINGS_TYPE_IMAGES,
+ ContentSettingsTypeFromGroupName(type_string),
"",
ContentSettingFromString(setting));
}
-// TODO(estade): generalize this function to work on all content settings types
-// rather than just images.
void ContentSettingsHandler::CheckExceptionPatternValidity(const Value* value) {
- std::string pattern_string = WideToUTF8(ExtractStringValue(value));
+ const ListValue* list_value = static_cast<const ListValue*>(value);
+ size_t arg_i = 0;
+ Value* type;
+ CHECK(list_value->Get(arg_i++, &type));
+ std::string pattern_string;
+ CHECK(list_value->GetString(arg_i++, &pattern_string));
+
HostContentSettingsMap::Pattern pattern(pattern_string);
scoped_ptr<Value> pattern_value(Value::CreateStringValue(
@@ -366,6 +375,7 @@ void ContentSettingsHandler::CheckExceptionPatternValidity(const Value* value) {
pattern.IsValid()));
dom_ui_->CallJavascriptFunction(
- L"ContentSettings.patternValidityCheckComplete", *pattern_value.get(),
+ L"ContentSettings.patternValidityCheckComplete", *type,
+ *pattern_value.get(),
*valid_value.get());
}
diff --git a/chrome/browser/dom_ui/content_settings_handler.h b/chrome/browser/dom_ui/content_settings_handler.h
index 1858dc5..3e72aab 100644
--- a/chrome/browser/dom_ui/content_settings_handler.h
+++ b/chrome/browser/dom_ui/content_settings_handler.h
@@ -7,6 +7,7 @@
#pragma once
#include "chrome/browser/dom_ui/options_ui.h"
+#include "chrome/common/content_settings_types.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
@@ -28,7 +29,8 @@ class ContentSettingsHandler : public OptionsPageUIHandler {
const NotificationDetails& details);
private:
- void UpdateImagesExceptionsViewFromModel();
+ void UpdateAllExceptionsViewsFromModel();
+ void UpdateExceptionsViewFromModel(ContentSettingsType type);
void SetContentFilter(const Value* value);
void SetAllowThirdPartyCookies(const Value* value);
void RemoveExceptions(const Value* value);
diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc
index f3000f3..a4f3583 100644
--- a/chrome/browser/dom_ui/dom_ui.cc
+++ b/chrome/browser/dom_ui/dom_ui.cc
@@ -17,6 +17,24 @@
#include "chrome/browser/tab_contents/tab_contents_view.h"
#include "chrome/common/bindings_policy.h"
+namespace {
+
+std::wstring GetJavascript(const std::wstring& function_name,
+ const std::vector<const Value*>& arg_list) {
+ std::wstring parameters;
+ std::string json;
+ for (size_t i = 0; i < arg_list.size(); ++i) {
+ if (i > 0)
+ parameters += L",";
+
+ base::JSONWriter::Write(arg_list[i], false, &json);
+ parameters += UTF8ToWide(json);
+ }
+ return function_name + L"(" + parameters + L");";
+}
+
+} // namespace
+
DOMUI::DOMUI(TabContents* contents)
: hide_favicon_(false),
force_bookmark_bar_visible_(false),
@@ -58,23 +76,28 @@ void DOMUI::CallJavascriptFunction(const std::wstring& function_name) {
void DOMUI::CallJavascriptFunction(const std::wstring& function_name,
const Value& arg) {
- std::string json;
- base::JSONWriter::Write(&arg, false, &json);
- std::wstring javascript = function_name + L"(" + UTF8ToWide(json) + L");";
-
- ExecuteJavascript(javascript);
+ std::vector<const Value*> args;
+ args.push_back(&arg);
+ ExecuteJavascript(GetJavascript(function_name, args));
}
void DOMUI::CallJavascriptFunction(
const std::wstring& function_name,
const Value& arg1, const Value& arg2) {
- std::string json;
- base::JSONWriter::Write(&arg1, false, &json);
- std::wstring javascript = function_name + L"(" + UTF8ToWide(json);
- base::JSONWriter::Write(&arg2, false, &json);
- javascript += L"," + UTF8ToWide(json) + L");";
+ std::vector<const Value*> args;
+ args.push_back(&arg1);
+ args.push_back(&arg2);
+ ExecuteJavascript(GetJavascript(function_name, args));
+}
- ExecuteJavascript(javascript);
+void DOMUI::CallJavascriptFunction(
+ const std::wstring& function_name,
+ const Value& arg1, const Value& arg2, const Value& arg3) {
+ std::vector<const Value*> args;
+ args.push_back(&arg1);
+ args.push_back(&arg2);
+ args.push_back(&arg3);
+ ExecuteJavascript(GetJavascript(function_name, args));
}
ThemeProvider* DOMUI::GetThemeProvider() const {
diff --git a/chrome/browser/dom_ui/dom_ui.h b/chrome/browser/dom_ui/dom_ui.h
index 1b333a8..4d35723 100644
--- a/chrome/browser/dom_ui/dom_ui.h
+++ b/chrome/browser/dom_ui/dom_ui.h
@@ -104,13 +104,17 @@ class DOMUI {
// the renderer. This is asynchronous; there's no way to get the result
// of the call, and should be thought of more like sending a message to
// the page.
- // There are two function variants for one-arg and two-arg calls.
+ // There are variants for calls with more arguments.
void CallJavascriptFunction(const std::wstring& function_name);
void CallJavascriptFunction(const std::wstring& function_name,
const Value& arg);
void CallJavascriptFunction(const std::wstring& function_name,
const Value& arg1,
const Value& arg2);
+ void CallJavascriptFunction(const std::wstring& function_name,
+ const Value& arg1,
+ const Value& arg2,
+ const Value& arg3);
ThemeProvider* GetThemeProvider() const;
diff --git a/chrome/browser/first_run/first_run_gtk.cc b/chrome/browser/first_run/first_run_gtk.cc
index cd32cec..725cdd0 100644
--- a/chrome/browser/first_run/first_run_gtk.cc
+++ b/chrome/browser/first_run/first_run_gtk.cc
@@ -22,7 +22,10 @@
#include "chrome/installer/util/util_constants.h"
#include "googleurl/src/gurl.h"
-bool OpenFirstRunDialog(Profile* profile, bool homepage_defined,
+// TODO(estade): pay attention to the args between |profile| and
+// |process_singleton|.
+bool OpenFirstRunDialog(Profile* profile,
+ bool homepage_defined,
int import_items,
int dont_import_items,
bool search_engine_experiment,
diff --git a/chrome/browser/resources/options/content_settings.html b/chrome/browser/resources/options/content_settings.html
index e3a550c..9f2f451 100644
--- a/chrome/browser/resources/options/content_settings.html
+++ b/chrome/browser/resources/options/content_settings.html
@@ -47,6 +47,10 @@
</tr>
</table>
+ <div id="cookiesExceptionsArea" contentType="cookies">
+ <list id="cookiesExceptionsList"></list>
+ </div>
+
<table class="option-control-table">
<tr>
<td class="option-name"><label>
@@ -97,7 +101,7 @@
</tr>
</table>
- <div id="imagesExceptionsArea">
+ <div id="imagesExceptionsArea" contentType="images">
<list id="imagesExceptionsList"></list>
</div>
</div>
@@ -124,6 +128,10 @@
</td>
</tr>
</table>
+
+ <div id="javascriptExceptionsArea" contentType="javascript">
+ <list id="javascriptExceptionsList"></list>
+ </div>
</div>
<!-- Plug-ins filter tab contents -->
@@ -153,6 +161,10 @@
</td>
</tr>
</table>
+
+ <div id="pluginsExceptionsArea" contentType="plugins">
+ <list id="pluginsExceptionsList"></list>
+ </div>
</div>
<!-- Pop-ups filter tab contents -->
@@ -177,6 +189,10 @@
</td>
</tr>
</table>
+
+ <div id="popupsExceptionsArea" contentType="popups">
+ <list id="popupsExceptionsList"></list>
+ </div>
</div>
<!-- Location filter tab contents -->
@@ -207,6 +223,10 @@
</td>
</tr>
</table>
+
+ <div id="locationExceptionsArea" contentType="location">
+ <list id="locationExceptionsList"></list>
+ </div>
</div>
<!-- Notifications filter tab contents -->
@@ -237,5 +257,9 @@
</td>
</tr>
</table>
+
+ <div id="notificationsExceptionsArea" contentType="notifications">
+ <list id="notificationsExceptionsList"></list>
+ </div>
</div>
</div>
diff --git a/chrome/browser/resources/options/content_settings.js b/chrome/browser/resources/options/content_settings.js
index ddb59d1..bc78304 100644
--- a/chrome/browser/resources/options/content_settings.js
+++ b/chrome/browser/resources/options/content_settings.js
@@ -50,8 +50,10 @@ cr.define('options', function() {
imagesExceptionsList.redraw();
};
- options.contentSettings.ExceptionsArea.decorate(
- $('imagesExceptionsArea'));
+ var exceptionsAreas = document.querySelectorAll('div[contentType]');
+ for (var i = 0; i < exceptionsAreas.length; i++) {
+ options.contentSettings.ExceptionsArea.decorate(exceptionsAreas[i]);
+ }
},
};
@@ -68,14 +70,17 @@ cr.define('options', function() {
};
/**
- * Initializes the image exceptions list.
+ * Initializes an exceptions list.
+ * @param {string} type The content type that we are setting exceptions for.
* @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) {
- imagesExceptionsList.clear();
- for (var i = 0; i < list.length; ++i) {
- imagesExceptionsList.addException(list[i]);
+ ContentSettings.setExceptions = function(type, list) {
+ var exceptionsList =
+ document.querySelector('div[contentType=' + type + '] list');
+ exceptionsList.clear();
+ for (var i = 0; i < list.length; i++) {
+ exceptionsList.addException(list[i]);
}
};
@@ -94,8 +99,11 @@ cr.define('options', function() {
* @param {bool} valid Whether said pattern is valid in the context of
* a content exception setting.
*/
- ContentSettings.patternValidityCheckComplete = function(pattern, valid) {
- imagesExceptionsList.patternValidityCheckComplete(pattern, valid);
+ ContentSettings.patternValidityCheckComplete =
+ function(type, pattern, valid) {
+ var exceptionsList =
+ document.querySelector('div[contentType=' + type + '] list');
+ exceptionsList.patternValidityCheckComplete(pattern, valid);
};
// Export
diff --git a/chrome/browser/resources/options/content_settings_exceptions_area.js b/chrome/browser/resources/options/content_settings_exceptions_area.js
index 96ac54d..c037906 100644
--- a/chrome/browser/resources/options/content_settings_exceptions_area.js
+++ b/chrome/browser/resources/options/content_settings_exceptions_area.js
@@ -78,11 +78,14 @@ cr.define('options.contentSettings', function() {
this.updateEditables();
- var self = this;
+ var listItem = this;
// Handle events on the editable nodes.
input.oninput = function(event) {
- self.inputValidityKnown = false;
- chrome.send('checkExceptionPatternValidity', [input.value]);
+ listItem.inputValidityKnown = false;
+ if (listItem.parentNode) {
+ chrome.send('checkExceptionPatternValidity',
+ [listItem.parentNode.contentType, input.value]);
+ }
};
var eventsToStop =
@@ -94,7 +97,6 @@ cr.define('options.contentSettings', function() {
}
);
- var listItem = this;
// Handles enter and escape which trigger reset and commit respectively.
function handleKeydown(e) {
// Make sure that the tree does not handle the key.
@@ -256,10 +258,12 @@ cr.define('options.contentSettings', function() {
this.removeAttribute('editing');
+ var contentType = this.parentNode.contentType;
+
if (pattern != this.pattern)
- chrome.send('removeImageExceptions', [pattern]);
+ chrome.send('removeExceptions', [contentType, pattern]);
- chrome.send('setImageException', [this.pattern, this.setting]);
+ chrome.send('setException', [contentType, this.pattern, this.setting]);
}
}
};
@@ -317,7 +321,7 @@ cr.define('options.contentSettings', function() {
* a content exception setting.
*/
patternValidityCheckComplete: function(pattern, valid) {
- for (var i = 0; i < this.dataModel.length; ++i) {
+ for (var i = 0; i < this.dataModel.length; i++) {
var listItem = this.getListItemByIndex(i);
if (listItem)
listItem.maybeSetPatternValid(pattern, valid);
@@ -335,13 +339,15 @@ cr.define('options.contentSettings', function() {
* Removes all selected rows from browser's model.
*/
removeSelectedRows: function() {
- var removePatterns = [];
+ // The first member is the content type; the rest of the values are
+ // the patterns we are removing.
+ var args = [this.contentType];
var selectedItems = this.selectedItems;
- for (var i = 0; i < selectedItems.length; ++i) {
- removePatterns.push(selectedItems[i][0]);
+ for (var i = 0; i < selectedItems.length; i++) {
+ args.push(selectedItems[i][0]);
}
- chrome.send('removeImageExceptions', removePatterns);
+ chrome.send('removeExceptions', args);
},
/**
@@ -360,8 +366,13 @@ cr.define('options.contentSettings', function() {
__proto__: HTMLDivElement.prototype,
decorate: function() {
- ExceptionsList.decorate($('imagesExceptionsList'));
- imagesExceptionsList.selectionModel.addEventListener(
+ // TODO(estade): need some sort of visual indication when the list is
+ // empty.
+ this.exceptionsList = this.querySelector('list');
+ this.exceptionsList.contentType = this.contentType;
+
+ ExceptionsList.decorate(this.exceptionsList);
+ this.exceptionsList.selectionModel.addEventListener(
'change', cr.bind(this.handleOnSelectionChange_, this));
var addRow = cr.doc.createElement('button');
@@ -378,27 +389,39 @@ cr.define('options.contentSettings', function() {
this.appendChild(removeRow);
this.removeRow = removeRow;
+ var self = this;
addRow.onclick = function(event) {
- imagesExceptionsList.addException(['', '']);
+ self.exceptionsList.addException(['', '']);
};
editRow.onclick = function(event) {
- imagesExceptionsList.editSelectedRow();
+ self.exceptionsList.editSelectedRow();
};
removeRow.onclick = function(event) {
- imagesExceptionsList.removeSelectedRows();
+ self.exceptionsList.removeSelectedRows();
};
this.updateButtonSensitivity();
},
/**
+ * The content type for this exceptions area, such as 'images'.
+ * @type {string}
+ */
+ get contentType() {
+ return this.getAttribute('contentType');
+ },
+ set contentType(type) {
+ return this.setAttribute('contentType', type);
+ },
+
+ /**
* Update the enabled/disabled state of the editing buttons based on which
* rows are selected.
*/
updateButtonSensitivity: function() {
- var selectionSize = imagesExceptionsList.selectedItems.length;
+ var selectionSize = this.exceptionsList.selectedItems.length;
this.editRow.disabled = selectionSize != 1;
this.removeRow.disabled = selectionSize == 0;
},
diff --git a/chrome/browser/resources/options/options_page.css b/chrome/browser/resources/options/options_page.css
index db9291f..e5357d9 100644
--- a/chrome/browser/resources/options/options_page.css
+++ b/chrome/browser/resources/options/options_page.css
@@ -220,3 +220,7 @@ input[type="checkbox"] {
background-color: transparent;
border-color: transparent;
}
+
+#contentSettingsPage :invalid {
+ background-color: pink;
+}