diff options
author | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-12 05:44:26 +0000 |
---|---|---|
committer | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-12 05:44:26 +0000 |
commit | 4bb33630869981809c47c36c3c18813d6b005d34 (patch) | |
tree | 505252dfeac2de2d02a89d1f7e69ffcdf4affcf5 /chrome/browser/notifications/notifications_prefs_cache.cc | |
parent | a93244407e205a8619d620ce91bafbdf88eab195 (diff) | |
download | chromium_src-4bb33630869981809c47c36c3c18813d6b005d34.zip chromium_src-4bb33630869981809c47c36c3c18813d6b005d34.tar.gz chromium_src-4bb33630869981809c47c36c3c18813d6b005d34.tar.bz2 |
Browser side support (sans UI) for desktop notifications.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/194108
Review URL: http://codereview.chromium.org/271052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications/notifications_prefs_cache.cc')
-rw-r--r-- | chrome/browser/notifications/notifications_prefs_cache.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/chrome/browser/notifications/notifications_prefs_cache.cc b/chrome/browser/notifications/notifications_prefs_cache.cc new file mode 100644 index 0000000..c5663e4 --- /dev/null +++ b/chrome/browser/notifications/notifications_prefs_cache.cc @@ -0,0 +1,67 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/notifications/notifications_prefs_cache.h" + +#include "base/string_util.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/common/pref_service.h" +#include "webkit/api/public/WebNotificationPresenter.h" + +NotificationsPrefsCache::NotificationsPrefsCache( + ListValue* allowed, ListValue* denied) { + ListValue::const_iterator i; + std::wstring origin; + if (allowed) { + for (i = allowed->begin(); i != allowed->end(); ++i) { + (*i)->GetAsString(&origin); + allowed_origins_.insert(GURL(WideToUTF8(origin))); + } + } + if (denied) { + for (i = denied->begin(); i != denied->end(); ++i) { + (*i)->GetAsString(&origin); + denied_origins_.insert(GURL(WideToUTF8(origin))); + } + } +} + +void NotificationsPrefsCache::CacheAllowedOrigin( + const GURL& origin) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + std::set<GURL>::iterator iter; + allowed_origins_.insert(origin); + if ((iter = denied_origins_.find(origin)) != denied_origins_.end()) + denied_origins_.erase(iter); +} + +void NotificationsPrefsCache::CacheDeniedOrigin( + const GURL& origin) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + std::set<GURL>::iterator iter; + denied_origins_.insert(origin); + if ((iter = allowed_origins_.find(origin)) != allowed_origins_.end()) + allowed_origins_.erase(iter); +} + +int NotificationsPrefsCache::HasPermission(const GURL& origin) { + if (IsOriginAllowed(origin)) + return WebKit::WebNotificationPresenter::PermissionAllowed; + if (IsOriginDenied(origin)) + return WebKit::WebNotificationPresenter::PermissionDenied; + return WebKit::WebNotificationPresenter::PermissionNotAllowed; +} + +bool NotificationsPrefsCache::IsOriginAllowed( + const GURL& origin) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + return (allowed_origins_.find(origin) != allowed_origins_.end()); +} + +bool NotificationsPrefsCache::IsOriginDenied( + const GURL& origin) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + return (denied_origins_.find(origin) != denied_origins_.end()); +} |