OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/notifications/notification_exceptions_table_model.h" | 5 #include "chrome/browser/notifications/notification_exceptions_table_model.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 #include <string> |
| 9 |
7 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/content_settings/content_settings_pattern.h" |
| 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
8 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
9 #include "chrome/common/content_settings.h" | 15 #include "chrome/common/content_settings.h" |
10 #include "chrome/common/content_settings_helper.h" | |
11 #include "chrome/common/content_settings_types.h" | 16 #include "chrome/common/content_settings_types.h" |
12 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
13 #include "content/common/notification_service.h" | 18 #include "content/common/notification_service.h" |
14 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
15 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/base/models/table_model_observer.h" | 21 #include "ui/base/models/table_model_observer.h" |
17 | 22 |
18 struct NotificationExceptionsTableModel::Entry { | 23 struct NotificationExceptionsTableModel::Entry { |
19 Entry(const GURL& origin, ContentSetting setting); | 24 Entry(const ContentSettingsPattern& origin, ContentSetting setting); |
20 bool operator<(const Entry& b) const; | 25 bool operator<(const Entry& b) const; |
21 | 26 |
22 GURL origin; | 27 ContentSettingsPattern origin; |
23 ContentSetting setting; | 28 ContentSetting setting; |
24 }; | 29 }; |
25 | 30 |
26 NotificationExceptionsTableModel::NotificationExceptionsTableModel( | 31 NotificationExceptionsTableModel::NotificationExceptionsTableModel( |
27 DesktopNotificationService* service) | 32 DesktopNotificationService* service) |
28 : service_(service), | 33 : service_(service), |
29 updates_disabled_(false), | 34 updates_disabled_(false), |
30 observer_(NULL) { | 35 observer_(NULL) { |
31 registrar_.Add(this, | 36 registrar_.Add(this, |
32 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 37 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 73 } |
69 | 74 |
70 int NotificationExceptionsTableModel::RowCount() { | 75 int NotificationExceptionsTableModel::RowCount() { |
71 return static_cast<int>(entries_.size()); | 76 return static_cast<int>(entries_.size()); |
72 } | 77 } |
73 | 78 |
74 string16 NotificationExceptionsTableModel::GetText(int row, | 79 string16 NotificationExceptionsTableModel::GetText(int row, |
75 int column_id) { | 80 int column_id) { |
76 const Entry& entry = entries_[row]; | 81 const Entry& entry = entries_[row]; |
77 if (column_id == IDS_EXCEPTIONS_HOSTNAME_HEADER) { | 82 if (column_id == IDS_EXCEPTIONS_HOSTNAME_HEADER) { |
78 return content_settings_helper::OriginToString16(entry.origin); | 83 return UTF8ToUTF16(entry.origin.ToString()); |
79 } | 84 } |
80 | 85 |
81 if (column_id == IDS_EXCEPTIONS_ACTION_HEADER) { | 86 if (column_id == IDS_EXCEPTIONS_ACTION_HEADER) { |
82 switch (entry.setting) { | 87 switch (entry.setting) { |
83 case CONTENT_SETTING_ALLOW: | 88 case CONTENT_SETTING_ALLOW: |
84 return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON); | 89 return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON); |
85 case CONTENT_SETTING_BLOCK: | 90 case CONTENT_SETTING_BLOCK: |
86 return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON); | 91 return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON); |
87 default: | 92 default: |
88 break; | 93 break; |
(...skipping 18 matching lines...) Expand all Loading... |
107 DCHECK_EQ(Source<DesktopNotificationService>(source).ptr(), service_); | 112 DCHECK_EQ(Source<DesktopNotificationService>(source).ptr(), service_); |
108 entries_.clear(); | 113 entries_.clear(); |
109 LoadEntries(); | 114 LoadEntries(); |
110 | 115 |
111 if (observer_) | 116 if (observer_) |
112 observer_->OnModelChanged(); | 117 observer_->OnModelChanged(); |
113 } | 118 } |
114 } | 119 } |
115 | 120 |
116 void NotificationExceptionsTableModel::LoadEntries() { | 121 void NotificationExceptionsTableModel::LoadEntries() { |
117 std::vector<GURL> allowed(service_->GetAllowedOrigins()); | 122 HostContentSettingsMap::SettingsForOneType settings; |
118 std::vector<GURL> blocked(service_->GetBlockedOrigins()); | 123 service_->GetNotificationsSettings(&settings); |
119 entries_.reserve(allowed.size() + blocked.size()); | 124 |
120 for (size_t i = 0; i < allowed.size(); ++i) | 125 entries_.reserve(settings.size()); |
121 entries_.push_back(Entry(allowed[i], CONTENT_SETTING_ALLOW)); | 126 for (HostContentSettingsMap::SettingsForOneType::const_iterator i = |
122 for (size_t i = 0; i < blocked.size(); ++i) | 127 settings.begin(); |
123 entries_.push_back(Entry(blocked[i], CONTENT_SETTING_BLOCK)); | 128 i != settings.end(); |
| 129 ++i) { |
| 130 const HostContentSettingsMap::PatternSettingSourceTuple& tuple(*i); |
| 131 entries_.push_back(Entry(tuple.a, tuple.c)); |
| 132 } |
124 std::sort(entries_.begin(), entries_.end()); | 133 std::sort(entries_.begin(), entries_.end()); |
125 } | 134 } |
126 | 135 |
127 NotificationExceptionsTableModel::Entry::Entry( | 136 NotificationExceptionsTableModel::Entry::Entry( |
128 const GURL& in_origin, | 137 const ContentSettingsPattern& in_origin, |
129 ContentSetting in_setting) | 138 ContentSetting in_setting) |
130 : origin(in_origin), | 139 : origin(in_origin), |
131 setting(in_setting) { | 140 setting(in_setting) { |
132 } | 141 } |
133 | 142 |
134 bool NotificationExceptionsTableModel::Entry::operator<( | 143 bool NotificationExceptionsTableModel::Entry::operator<( |
135 const NotificationExceptionsTableModel::Entry& b) const { | 144 const NotificationExceptionsTableModel::Entry& b) const { |
136 DCHECK_NE(origin, b.origin); | 145 DCHECK_NE(origin, b.origin); |
137 return origin < b.origin; | 146 return origin.ToString() < b.origin.ToString(); |
138 } | 147 } |
OLD | NEW |