| Index: chrome/browser/notifications/notification_exceptions_table_model.cc
|
| diff --git a/chrome/browser/notifications/notification_exceptions_table_model.cc b/chrome/browser/notifications/notification_exceptions_table_model.cc
|
| index e8e3c084c8efb042730f93c531911f677b77c284..f4e8d687f8c5e25b924db4de7620f644ff7448d1 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;
|
| +}
|
|
|