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

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

Issue 2842043: Add a default content setting to the notifications service. (Closed)
Patch Set: '' Created 10 years, 5 months 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/notifications_prefs_cache.h" 5 #include "chrome/browser/notifications/notifications_prefs_cache.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/chrome_thread.h" 9 #include "chrome/browser/chrome_thread.h"
10 #include "chrome/browser/pref_service.h" 10 #include "chrome/browser/pref_service.h"
11 #include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h" 11 #include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h"
12 12
13 NotificationsPrefsCache::NotificationsPrefsCache() 13 NotificationsPrefsCache::NotificationsPrefsCache()
14 : is_initialized_(false) { 14 : default_content_setting_(CONTENT_SETTING_DEFAULT),
15 is_initialized_(false) {
15 } 16 }
16 17
17 void NotificationsPrefsCache::CacheAllowedOrigin( 18 void NotificationsPrefsCache::CacheAllowedOrigin(
18 const GURL& origin) { 19 const GURL& origin) {
19 CheckThreadAccess(); 20 CheckThreadAccess();
20 std::set<GURL>::iterator iter; 21 std::set<GURL>::iterator iter;
21 allowed_origins_.insert(origin); 22 allowed_origins_.insert(origin);
22 if ((iter = denied_origins_.find(origin)) != denied_origins_.end()) 23 if ((iter = denied_origins_.find(origin)) != denied_origins_.end())
23 denied_origins_.erase(iter); 24 denied_origins_.erase(iter);
24 } 25 }
(...skipping 12 matching lines...) Expand all
37 allowed_origins_.clear(); 38 allowed_origins_.clear();
38 allowed_origins_.insert(allowed.begin(), allowed.end()); 39 allowed_origins_.insert(allowed.begin(), allowed.end());
39 } 40 }
40 41
41 void NotificationsPrefsCache::SetCacheDeniedOrigins( 42 void NotificationsPrefsCache::SetCacheDeniedOrigins(
42 const std::vector<GURL>& denied) { 43 const std::vector<GURL>& denied) {
43 denied_origins_.clear(); 44 denied_origins_.clear();
44 denied_origins_.insert(denied.begin(), denied.end()); 45 denied_origins_.insert(denied.begin(), denied.end());
45 } 46 }
46 47
48 void NotificationsPrefsCache::SetCacheDefaultContentSetting(
49 ContentSetting setting) {
50 default_content_setting_ = setting;
51 }
52
47 // static 53 // static
48 void NotificationsPrefsCache::ListValueToGurlVector( 54 void NotificationsPrefsCache::ListValueToGurlVector(
49 const ListValue& origin_list, 55 const ListValue& origin_list,
50 std::vector<GURL>* origin_vector) { 56 std::vector<GURL>* origin_vector) {
51 ListValue::const_iterator i; 57 ListValue::const_iterator i;
52 std::wstring origin; 58 std::wstring origin;
53 for (i = origin_list.begin(); i != origin_list.end(); ++i) { 59 for (i = origin_list.begin(); i != origin_list.end(); ++i) {
54 (*i)->GetAsString(&origin); 60 (*i)->GetAsString(&origin);
55 origin_vector->push_back(GURL(WideToUTF8(origin))); 61 origin_vector->push_back(GURL(WideToUTF8(origin)));
56 } 62 }
57 } 63 }
58 64
59 int NotificationsPrefsCache::HasPermission(const GURL& origin) { 65 int NotificationsPrefsCache::HasPermission(const GURL& origin) {
60 if (IsOriginAllowed(origin)) 66 if (IsOriginAllowed(origin))
61 return WebKit::WebNotificationPresenter::PermissionAllowed; 67 return WebKit::WebNotificationPresenter::PermissionAllowed;
62 if (IsOriginDenied(origin)) 68 if (IsOriginDenied(origin))
63 return WebKit::WebNotificationPresenter::PermissionDenied; 69 return WebKit::WebNotificationPresenter::PermissionDenied;
64 return WebKit::WebNotificationPresenter::PermissionNotAllowed; 70 switch (default_content_setting_) {
71 case CONTENT_SETTING_ALLOW:
72 return WebKit::WebNotificationPresenter::PermissionAllowed;
73 case CONTENT_SETTING_BLOCK:
74 return WebKit::WebNotificationPresenter::PermissionDenied;
75 case CONTENT_SETTING_ASK:
76 case CONTENT_SETTING_DEFAULT:
77 default: // Make gcc happy.
78 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
79 }
65 } 80 }
66 81
67 bool NotificationsPrefsCache::IsOriginAllowed( 82 bool NotificationsPrefsCache::IsOriginAllowed(
68 const GURL& origin) { 83 const GURL& origin) {
69 CheckThreadAccess(); 84 CheckThreadAccess();
70 return (allowed_origins_.find(origin) != allowed_origins_.end()); 85 return allowed_origins_.find(origin) != allowed_origins_.end();
71 } 86 }
72 87
73 bool NotificationsPrefsCache::IsOriginDenied( 88 bool NotificationsPrefsCache::IsOriginDenied(
74 const GURL& origin) { 89 const GURL& origin) {
75 CheckThreadAccess(); 90 CheckThreadAccess();
76 return (denied_origins_.find(origin) != denied_origins_.end()); 91 return denied_origins_.find(origin) != denied_origins_.end();
77 } 92 }
78 93
79 void NotificationsPrefsCache::CheckThreadAccess() { 94 void NotificationsPrefsCache::CheckThreadAccess() {
80 if (is_initialized_) { 95 if (is_initialized_) {
81 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 96 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
82 } else { 97 } else {
83 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 98 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
84 } 99 }
85 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698