summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/notification_exceptions_table_model.cc
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-06 16:45:22 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-06 16:45:22 +0000
commitf4192f2d3de41612744b932b9f9cabdd32db7416 (patch)
tree1c481baaf1ebf329c8b2d966e40d0f2f58ab201c /chrome/browser/notifications/notification_exceptions_table_model.cc
parent75d2456a90b4cffed0a0c99bd0444087e8c7c252 (diff)
downloadchromium_src-f4192f2d3de41612744b932b9f9cabdd32db7416.zip
chromium_src-f4192f2d3de41612744b932b9f9cabdd32db7416.tar.gz
chromium_src-f4192f2d3de41612744b932b9f9cabdd32db7416.tar.bz2
Backend changes for notifications content settings.
NotificationExceptionsTableModel is now functional, and DesktopNotificationService::GetContentSetting contains the new permission behavior. Both aren't used anywhere yet, so still no functionality change (but this is the last CL without functionality changes). Also add a ton of tests. BUG=45547 TEST=unit tests Review URL: http://codereview.chromium.org/2868042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications/notification_exceptions_table_model.cc')
-rw-r--r--chrome/browser/notifications/notification_exceptions_table_model.cc59
1 files changed, 54 insertions, 5 deletions
diff --git a/chrome/browser/notifications/notification_exceptions_table_model.cc b/chrome/browser/notifications/notification_exceptions_table_model.cc
index e8e3c08..f4e8d68 100644
--- a/chrome/browser/notifications/notification_exceptions_table_model.cc
+++ b/chrome/browser/notifications/notification_exceptions_table_model.cc
@@ -8,6 +8,7 @@
#include "app/l10n_util_collator.h"
#include "app/table_model_observer.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/common/url_constants.h"
#include "grit/generated_resources.h"
@@ -15,20 +16,44 @@ NotificationExceptionsTableModel::NotificationExceptionsTableModel(
DesktopNotificationService* service)
: service_(service),
observer_(NULL) {
+ std::vector<GURL> allowed(service_->GetAllowedOrigins());
+ std::vector<GURL> blocked(service_->GetBlockedOrigins());
+ entries_.reserve(allowed.size() + blocked.size());
+ for (size_t i = 0; i < allowed.size(); ++i)
+ entries_.push_back(Entry(allowed[i], CONTENT_SETTING_ALLOW));
+ for (size_t i = 0; i < blocked.size(); ++i)
+ entries_.push_back(Entry(blocked[i], CONTENT_SETTING_BLOCK));
+ sort(entries_.begin(), entries_.end());
}
bool NotificationExceptionsTableModel::CanRemoveRows(
const Rows& rows) const {
- NOTIMPLEMENTED();
- return false;
+ return !rows.empty();
}
void NotificationExceptionsTableModel::RemoveRows(const Rows& rows) {
- NOTIMPLEMENTED();
+ // This is O(n^2) in rows.size(). Since n is small, that's ok.
+ for (Rows::const_reverse_iterator i(rows.rbegin()); i != rows.rend(); ++i) {
+ size_t row = *i;
+ Entry* entry = &entries_[row];
+ if (entry->setting == CONTENT_SETTING_ALLOW) {
+ service_->ResetAllowedOrigin(entry->origin);
+ } else {
+ DCHECK_EQ(entry->setting, CONTENT_SETTING_BLOCK);
+ service_->ResetBlockedOrigin(entry->origin);
+ }
+ entries_.erase(entries_.begin() + row); // Note: |entry| is now garbage.
+ if (observer_)
+ observer_->OnItemsRemoved(row, 1);
+ }
}
void NotificationExceptionsTableModel::RemoveAll() {
- NOTIMPLEMENTED();
+ int old_row_count = RowCount();
+ entries_.clear();
+ service_->ResetAllOrigins();
+ if (observer_)
+ observer_->OnItemsRemoved(0, old_row_count);
}
int NotificationExceptionsTableModel::RowCount() {
@@ -37,7 +62,26 @@ int NotificationExceptionsTableModel::RowCount() {
std::wstring NotificationExceptionsTableModel::GetText(int row,
int column_id) {
- NOTIMPLEMENTED();
+ const Entry& entry = entries_[row];
+ if (column_id == IDS_EXCEPTIONS_HOSTNAME_HEADER) {
+ // TODO(bulach): factor out in a common function so that Notifications won't
+ // depend on Geolocation.
+ return UTF8ToWide(GeolocationContentSettingsMap::OriginToString(
+ entry.origin));
+ }
+
+ if (column_id == IDS_EXCEPTIONS_ACTION_HEADER) {
+ switch (entry.setting) {
+ case CONTENT_SETTING_ALLOW:
+ return l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON);
+ case CONTENT_SETTING_BLOCK:
+ return l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON);
+ default:
+ break;
+ }
+ }
+
+ NOTREACHED();
return std::wstring();
}
@@ -53,3 +97,8 @@ NotificationExceptionsTableModel::Entry::Entry(
setting(in_setting) {
}
+bool NotificationExceptionsTableModel::Entry::operator<(
+ const NotificationExceptionsTableModel::Entry& b) const {
+ DCHECK_NE(origin, b.origin);
+ return origin < b.origin;
+}