| 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" |
| 11 #include "chrome/browser/browser_process.h" | |
| 12 #include "chrome/browser/chrome_thread.h" | 11 #include "chrome/browser/chrome_thread.h" |
| 13 #include "chrome/browser/notifications/notification.h" | 12 #include "chrome/browser/notifications/notification.h" |
| 14 #include "chrome/browser/notifications/notification_object_proxy.h" | 13 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 15 #include "chrome/browser/notifications/notifications_prefs_cache.h" | 14 #include "chrome/browser/notifications/notifications_prefs_cache.h" |
| 16 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
| 17 #include "chrome/browser/renderer_host/render_process_host.h" | 16 #include "chrome/browser/renderer_host/render_process_host.h" |
| 18 #include "chrome/browser/renderer_host/render_view_host.h" | 17 #include "chrome/browser/renderer_host/render_view_host.h" |
| 19 #include "chrome/browser/renderer_host/site_instance.h" | 18 #include "chrome/browser/renderer_host/site_instance.h" |
| 20 #include "chrome/browser/tab_contents/infobar_delegate.h" | 19 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 21 #include "chrome/browser/tab_contents/tab_contents.h" | 20 #include "chrome/browser/tab_contents/tab_contents.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 route_id_(contents->render_view_host()->routing_id()), | 68 route_id_(contents->render_view_host()->routing_id()), |
| 70 callback_context_(callback_context), | 69 callback_context_(callback_context), |
| 71 action_taken_(false) { | 70 action_taken_(false) { |
| 72 } | 71 } |
| 73 | 72 |
| 74 // Overridden from ConfirmInfoBarDelegate: | 73 // Overridden from ConfirmInfoBarDelegate: |
| 75 virtual void InfoBarClosed() { | 74 virtual void InfoBarClosed() { |
| 76 if (!action_taken_) | 75 if (!action_taken_) |
| 77 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1); | 76 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1); |
| 78 | 77 |
| 79 base::Thread* io_thread = g_browser_process->io_thread(); | 78 ChromeThread::PostTask( |
| 80 if (io_thread && io_thread->message_loop()) { | 79 ChromeThread::IO, FROM_HERE, |
| 81 io_thread->message_loop()->PostTask(FROM_HERE, | 80 new NotificationPermissionCallbackTask( |
| 82 new NotificationPermissionCallbackTask(process_id_, route_id_, | 81 process_id_, route_id_, callback_context_)); |
| 83 callback_context_)); | |
| 84 } | |
| 85 | 82 |
| 86 delete this; | 83 delete this; |
| 87 } | 84 } |
| 88 | 85 |
| 89 virtual std::wstring GetMessageText() const { | 86 virtual std::wstring GetMessageText() const { |
| 90 return l10n_util::GetStringF(IDS_NOTIFICATION_PERMISSIONS, | 87 return l10n_util::GetStringF(IDS_NOTIFICATION_PERMISSIONS, |
| 91 UTF8ToWide(origin_.spec())); | 88 UTF8ToWide(origin_.spec())); |
| 92 } | 89 } |
| 93 | 90 |
| 94 virtual SkBitmap* GetIcon() const { | 91 virtual SkBitmap* GetIcon() const { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); | 171 prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); |
| 175 ListValue* denied_sites = | 172 ListValue* denied_sites = |
| 176 prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins); | 173 prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins); |
| 177 // Remove from the black-list and add to the white-list. | 174 // Remove from the black-list and add to the white-list. |
| 178 StringValue* value = new StringValue(origin.spec()); | 175 StringValue* value = new StringValue(origin.spec()); |
| 179 denied_sites->Remove(*value); | 176 denied_sites->Remove(*value); |
| 180 allowed_sites->Append(value); | 177 allowed_sites->Append(value); |
| 181 prefs->ScheduleSavePersistentPrefs(); | 178 prefs->ScheduleSavePersistentPrefs(); |
| 182 | 179 |
| 183 // Schedule a cache update on the IO thread. | 180 // Schedule a cache update on the IO thread. |
| 184 base::Thread* io_thread = g_browser_process->io_thread(); | 181 ChromeThread::PostTask( |
| 185 if (io_thread && io_thread->message_loop()) { | 182 ChromeThread::IO, FROM_HERE, |
| 186 io_thread->message_loop()->PostTask(FROM_HERE, | 183 NewRunnableMethod( |
| 187 NewRunnableMethod(prefs_cache_.get(), | 184 prefs_cache_.get(), &NotificationsPrefsCache::CacheAllowedOrigin, |
| 188 &NotificationsPrefsCache::CacheAllowedOrigin, | 185 origin)); |
| 189 origin)); | |
| 190 } | |
| 191 } | 186 } |
| 192 | 187 |
| 193 void DesktopNotificationService::DenyPermission(const GURL& origin) { | 188 void DesktopNotificationService::DenyPermission(const GURL& origin) { |
| 194 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 189 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 195 PrefService* prefs = profile_->GetPrefs(); | 190 PrefService* prefs = profile_->GetPrefs(); |
| 196 ListValue* allowed_sites = | 191 ListValue* allowed_sites = |
| 197 prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); | 192 prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); |
| 198 ListValue* denied_sites = | 193 ListValue* denied_sites = |
| 199 prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins); | 194 prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins); |
| 200 StringValue* value = new StringValue(origin.spec()); | 195 StringValue* value = new StringValue(origin.spec()); |
| 201 // Remove from the white-list and add to the black-list. | 196 // Remove from the white-list and add to the black-list. |
| 202 allowed_sites->Remove(*value); | 197 allowed_sites->Remove(*value); |
| 203 denied_sites->Append(value); | 198 denied_sites->Append(value); |
| 204 prefs->ScheduleSavePersistentPrefs(); | 199 prefs->ScheduleSavePersistentPrefs(); |
| 205 | 200 |
| 206 // Schedule a cache update on the IO thread. | 201 // Schedule a cache update on the IO thread. |
| 207 base::Thread* io_thread = g_browser_process->io_thread(); | 202 ChromeThread::PostTask( |
| 208 if (io_thread && io_thread->message_loop()) { | 203 ChromeThread::IO, FROM_HERE, |
| 209 io_thread->message_loop()->PostTask(FROM_HERE, | 204 NewRunnableMethod( |
| 210 NewRunnableMethod(prefs_cache_.get(), | 205 prefs_cache_.get(), &NotificationsPrefsCache::CacheDeniedOrigin, |
| 211 &NotificationsPrefsCache::CacheDeniedOrigin, | 206 origin)); |
| 212 origin)); | |
| 213 } | |
| 214 } | 207 } |
| 215 | 208 |
| 216 void DesktopNotificationService::RequestPermission( | 209 void DesktopNotificationService::RequestPermission( |
| 217 const GURL& origin, int callback_context) { | 210 const GURL& origin, int callback_context) { |
| 218 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 211 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 219 // Show an info bar requesting permission. | 212 // Show an info bar requesting permission. |
| 220 Browser* browser = BrowserList::GetLastActive(); | 213 Browser* browser = BrowserList::GetLastActive(); |
| 221 if (!browser) { | 214 if (!browser) { |
| 222 // Reached during ui tests. | 215 // Reached during ui tests. |
| 223 return; | 216 return; |
| 224 } | 217 } |
| 225 TabContents* tab = browser->GetSelectedTabContents(); | 218 TabContents* tab = browser->GetSelectedTabContents(); |
| 226 if (!tab) | 219 if (!tab) |
| 227 return; | 220 return; |
| 228 tab->AddInfoBar(new NotificationPermissionInfoBarDelegate(tab, origin, | 221 tab->AddInfoBar(new NotificationPermissionInfoBarDelegate(tab, origin, |
| 229 callback_context)); | 222 callback_context)); |
| 230 } | 223 } |
| OLD | NEW |