Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: chrome/browser/notifications/desktop_notification_service.cc

Issue 455004: Keep incognito notification preferences separate from regular ones, and don't... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/notifications/desktop_notification_service.h ('k') | chrome/browser/profile.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string_piece.h" 9 #include "base/string_piece.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 Source<Profile>(profile_)); 198 Source<Profile>(profile_));
199 } 199 }
200 200
201 DesktopNotificationService::~DesktopNotificationService() { 201 DesktopNotificationService::~DesktopNotificationService() {
202 } 202 }
203 203
204 // Initialize the cache with the allowed and denied origins, or 204 // Initialize the cache with the allowed and denied origins, or
205 // create the preferences if they don't exist yet. 205 // create the preferences if they don't exist yet.
206 void DesktopNotificationService::InitPrefs() { 206 void DesktopNotificationService::InitPrefs() {
207 PrefService* prefs = profile_->GetPrefs(); 207 PrefService* prefs = profile_->GetPrefs();
208 const ListValue* allowed_sites; 208 const ListValue* allowed_sites = NULL;
209 const ListValue* denied_sites; 209 const ListValue* denied_sites = NULL;
210 210
211 if (!prefs->FindPreference(prefs::kDesktopNotificationAllowedOrigins)) 211 if (!profile_->IsOffTheRecord()) {
212 prefs->RegisterListPref(prefs::kDesktopNotificationAllowedOrigins); 212 if (!prefs->FindPreference(prefs::kDesktopNotificationAllowedOrigins))
213 allowed_sites = prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); 213 prefs->RegisterListPref(prefs::kDesktopNotificationAllowedOrigins);
214 allowed_sites = prefs->GetList(prefs::kDesktopNotificationAllowedOrigins);
214 215
215 if (!prefs->FindPreference(prefs::kDesktopNotificationDeniedOrigins)) 216 if (!prefs->FindPreference(prefs::kDesktopNotificationDeniedOrigins))
216 prefs->RegisterListPref(prefs::kDesktopNotificationDeniedOrigins); 217 prefs->RegisterListPref(prefs::kDesktopNotificationDeniedOrigins);
217 denied_sites = prefs->GetList(prefs::kDesktopNotificationDeniedOrigins); 218 denied_sites = prefs->GetList(prefs::kDesktopNotificationDeniedOrigins);
219 }
218 220
219 prefs_cache_ = new NotificationsPrefsCache(allowed_sites, denied_sites); 221 prefs_cache_ = new NotificationsPrefsCache(allowed_sites, denied_sites);
220 222
221 ExtensionsService* ext_service = profile_->GetExtensionsService(); 223 ExtensionsService* ext_service = profile_->GetExtensionsService();
222 if (ext_service) { 224 if (ext_service) {
223 const ExtensionList* extensions = ext_service->extensions(); 225 const ExtensionList* extensions = ext_service->extensions();
224 for (ExtensionList::const_iterator iter = extensions->begin(); 226 for (ExtensionList::const_iterator iter = extensions->begin();
225 iter != extensions->end(); ++iter) { 227 iter != extensions->end(); ++iter) {
226 if ((*iter)->HasApiPermission(Extension::kNotificationPermission)) { 228 if ((*iter)->HasApiPermission(Extension::kNotificationPermission)) {
227 prefs_cache_->CacheAllowedOrigin((*iter)->url()); 229 prefs_cache_->CacheAllowedOrigin((*iter)->url());
(...skipping 11 matching lines...) Expand all
239 } 241 }
240 242
241 Details<Extension> extension = static_cast<Details<Extension> >(details); 243 Details<Extension> extension = static_cast<Details<Extension> >(details);
242 if (extension->HasApiPermission(Extension::kNotificationPermission)) { 244 if (extension->HasApiPermission(Extension::kNotificationPermission)) {
243 GrantPermission(extension->url()); 245 GrantPermission(extension->url());
244 } 246 }
245 } 247 }
246 248
247 void DesktopNotificationService::GrantPermission(const GURL& origin) { 249 void DesktopNotificationService::GrantPermission(const GURL& origin) {
248 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 250 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
249 PrefService* prefs = profile_->GetPrefs();
250 ListValue* allowed_sites =
251 prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins);
252 ListValue* denied_sites =
253 prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins);
254 // Remove from the black-list and add to the white-list.
255 StringValue* value = new StringValue(origin.spec());
256 denied_sites->Remove(*value);
257 allowed_sites->Append(value);
258 prefs->ScheduleSavePersistentPrefs();
259 251
260 // Schedule a cache update on the IO thread. 252 if (!profile_->IsOffTheRecord())
253 PersistPermissionChange(origin, true);
254
261 ChromeThread::PostTask( 255 ChromeThread::PostTask(
262 ChromeThread::IO, FROM_HERE, 256 ChromeThread::IO, FROM_HERE,
263 NewRunnableMethod( 257 NewRunnableMethod(
264 prefs_cache_.get(), &NotificationsPrefsCache::CacheAllowedOrigin, 258 prefs_cache_.get(), &NotificationsPrefsCache::CacheAllowedOrigin,
265 origin)); 259 origin));
266 } 260 }
267 261
268 void DesktopNotificationService::DenyPermission(const GURL& origin) { 262 void DesktopNotificationService::DenyPermission(const GURL& origin) {
269 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 263 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
270 PrefService* prefs = profile_->GetPrefs(); 264
271 ListValue* allowed_sites = 265 if (!profile_->IsOffTheRecord())
272 prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); 266 PersistPermissionChange(origin, false);
273 ListValue* denied_sites =
274 prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins);
275 StringValue* value = new StringValue(origin.spec());
276 // Remove from the white-list and add to the black-list.
277 allowed_sites->Remove(*value);
278 denied_sites->Append(value);
279 prefs->ScheduleSavePersistentPrefs();
280 267
281 // Schedule a cache update on the IO thread. 268 // Schedule a cache update on the IO thread.
282 ChromeThread::PostTask( 269 ChromeThread::PostTask(
283 ChromeThread::IO, FROM_HERE, 270 ChromeThread::IO, FROM_HERE,
284 NewRunnableMethod( 271 NewRunnableMethod(
285 prefs_cache_.get(), &NotificationsPrefsCache::CacheDeniedOrigin, 272 prefs_cache_.get(), &NotificationsPrefsCache::CacheDeniedOrigin,
286 origin)); 273 origin));
287 } 274 }
288 275
276 void DesktopNotificationService::PersistPermissionChange(
277 const GURL& origin, bool is_allowed) {
michaeln 2009/12/01 00:00:07 maybe DCHECK(!profile_->IsOffTheRecord()), or push
278 PrefService* prefs = profile_->GetPrefs();
279 ListValue* allowed_sites =
280 prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins);
281 ListValue* denied_sites =
282 prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins);
283 StringValue* value = new StringValue(origin.spec());
284 // Remove from one list and add to the other.
285 if (is_allowed) {
286 allowed_sites->Append(value);
287 denied_sites->Remove(*value);
288 } else {
289 allowed_sites->Remove(*value);
290 denied_sites->Append(value);
291 }
292 prefs->ScheduleSavePersistentPrefs();
293 }
294
289 void DesktopNotificationService::RequestPermission( 295 void DesktopNotificationService::RequestPermission(
290 const GURL& origin, int process_id, int route_id, int callback_context) { 296 const GURL& origin, int process_id, int route_id, int callback_context) {
291 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 297 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
292 // Show an info bar requesting permission. 298 // Show an info bar requesting permission.
293 Browser* browser = BrowserList::GetLastActive(); 299 Browser* browser = BrowserList::GetLastActive();
294 if (!browser) { 300 if (!browser) {
295 // Reached during ui tests. 301 // Reached during ui tests.
296 return; 302 return;
297 } 303 }
298 TabContents* tab = browser->GetSelectedTabContents(); 304 TabContents* tab = browser->GetSelectedTabContents();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 if (origin.SchemeIs(chrome::kExtensionScheme)) { 362 if (origin.SchemeIs(chrome::kExtensionScheme)) {
357 ExtensionsService* ext_service = profile_->GetExtensionsService(); 363 ExtensionsService* ext_service = profile_->GetExtensionsService();
358 if (ext_service) { 364 if (ext_service) {
359 Extension* extension = ext_service->GetExtensionByURL(origin); 365 Extension* extension = ext_service->GetExtensionByURL(origin);
360 if (extension) 366 if (extension)
361 return ASCIIToWide(extension->name()); 367 return ASCIIToWide(extension->name());
362 } 368 }
363 } 369 }
364 return UTF8ToWide(origin.spec()); 370 return UTF8ToWide(origin.spec());
365 } 371 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/desktop_notification_service.h ('k') | chrome/browser/profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698