OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/desktop_notification_service.h" | 5 #include "chrome/browser/notifications/desktop_notification_service.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/thread.h" | 9 #include "base/thread.h" |
10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 InitPrefs(); | 146 InitPrefs(); |
147 } | 147 } |
148 | 148 |
149 DesktopNotificationService::~DesktopNotificationService() { | 149 DesktopNotificationService::~DesktopNotificationService() { |
150 } | 150 } |
151 | 151 |
152 // Initialize the cache with the allowed and denied origins, or | 152 // Initialize the cache with the allowed and denied origins, or |
153 // create the preferences if they don't exist yet. | 153 // create the preferences if they don't exist yet. |
154 void DesktopNotificationService::InitPrefs() { | 154 void DesktopNotificationService::InitPrefs() { |
155 PrefService* prefs = profile_->GetPrefs(); | 155 PrefService* prefs = profile_->GetPrefs(); |
156 ListValue* allowed_sites = NULL; | 156 const ListValue* allowed_sites; |
157 ListValue* denied_sites = NULL; | 157 const ListValue* denied_sites; |
158 | 158 |
159 if (prefs->FindPreference(prefs::kDesktopNotificationAllowedOrigins)) | 159 if (!prefs->FindPreference(prefs::kDesktopNotificationAllowedOrigins)) |
160 allowed_sites = | |
161 prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); | |
162 else | |
163 prefs->RegisterListPref(prefs::kDesktopNotificationAllowedOrigins); | 160 prefs->RegisterListPref(prefs::kDesktopNotificationAllowedOrigins); |
| 161 allowed_sites = prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); |
164 | 162 |
165 if (prefs->FindPreference(prefs::kDesktopNotificationDeniedOrigins)) | 163 if (!prefs->FindPreference(prefs::kDesktopNotificationDeniedOrigins)) |
166 denied_sites = | |
167 prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins); | |
168 else | |
169 prefs->RegisterListPref(prefs::kDesktopNotificationDeniedOrigins); | 164 prefs->RegisterListPref(prefs::kDesktopNotificationDeniedOrigins); |
| 165 denied_sites = prefs->GetList(prefs::kDesktopNotificationDeniedOrigins); |
170 | 166 |
171 prefs_cache_ = new NotificationsPrefsCache(allowed_sites, denied_sites); | 167 prefs_cache_ = new NotificationsPrefsCache(allowed_sites, denied_sites); |
172 } | 168 } |
173 | 169 |
174 void DesktopNotificationService::GrantPermission(const GURL& origin) { | 170 void DesktopNotificationService::GrantPermission(const GURL& origin) { |
175 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 171 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
176 PrefService* prefs = profile_->GetPrefs(); | 172 PrefService* prefs = profile_->GetPrefs(); |
177 ListValue* allowed_sites = | 173 ListValue* allowed_sites = |
178 prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); | 174 prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); |
179 ListValue* denied_sites = | 175 ListValue* denied_sites = |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 if (!browser) { | 221 if (!browser) { |
226 // Reached during ui tests. | 222 // Reached during ui tests. |
227 return; | 223 return; |
228 } | 224 } |
229 TabContents* tab = browser->GetSelectedTabContents(); | 225 TabContents* tab = browser->GetSelectedTabContents(); |
230 if (!tab) | 226 if (!tab) |
231 return; | 227 return; |
232 tab->AddInfoBar(new NotificationPermissionInfoBarDelegate(tab, origin, | 228 tab->AddInfoBar(new NotificationPermissionInfoBarDelegate(tab, origin, |
233 callback_context)); | 229 callback_context)); |
234 } | 230 } |
OLD | NEW |