OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 using WebKit::WebSecurityOrigin; | 52 using WebKit::WebSecurityOrigin; |
53 | 53 |
54 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; | 54 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; |
55 | 55 |
56 // NotificationPermissionInfoBarDelegate -------------------------------------- | 56 // NotificationPermissionInfoBarDelegate -------------------------------------- |
57 | 57 |
58 // The delegate for the infobar shown when an origin requests notification | 58 // The delegate for the infobar shown when an origin requests notification |
59 // permissions. | 59 // permissions. |
60 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | 60 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { |
61 public: | 61 public: |
| 62 // Creates a notification permission delegate and adds it to |
| 63 // |infobar_service|. |
| 64 static void Create(InfoBarService* infobar_service, |
| 65 DesktopNotificationService* notification_service, |
| 66 const GURL& origin, |
| 67 const string16& display_name, |
| 68 int process_id, |
| 69 int route_id, |
| 70 int callback_context); |
| 71 |
| 72 private: |
62 NotificationPermissionInfoBarDelegate( | 73 NotificationPermissionInfoBarDelegate( |
63 InfoBarService* infobar_service, | 74 InfoBarService* infobar_service, |
64 DesktopNotificationService* notification_service, | 75 DesktopNotificationService* notification_service, |
65 const GURL& origin, | 76 const GURL& origin, |
66 const string16& display_name, | 77 const string16& display_name, |
67 int process_id, | 78 int process_id, |
68 int route_id, | 79 int route_id, |
69 int callback_context); | 80 int callback_context); |
70 | |
71 private: | |
72 virtual ~NotificationPermissionInfoBarDelegate(); | 81 virtual ~NotificationPermissionInfoBarDelegate(); |
73 | 82 |
74 // ConfirmInfoBarDelegate: | 83 // ConfirmInfoBarDelegate: |
75 virtual gfx::Image* GetIcon() const OVERRIDE; | 84 virtual gfx::Image* GetIcon() const OVERRIDE; |
76 virtual Type GetInfoBarType() const OVERRIDE; | 85 virtual Type GetInfoBarType() const OVERRIDE; |
77 virtual string16 GetMessageText() const OVERRIDE; | 86 virtual string16 GetMessageText() const OVERRIDE; |
78 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 87 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
79 virtual bool Accept() OVERRIDE; | 88 virtual bool Accept() OVERRIDE; |
80 virtual bool Cancel() OVERRIDE; | 89 virtual bool Cancel() OVERRIDE; |
81 | 90 |
(...skipping 12 matching lines...) Expand all Loading... |
94 int process_id_; | 103 int process_id_; |
95 int route_id_; | 104 int route_id_; |
96 int callback_context_; | 105 int callback_context_; |
97 | 106 |
98 // Whether the user clicked one of the buttons. | 107 // Whether the user clicked one of the buttons. |
99 bool action_taken_; | 108 bool action_taken_; |
100 | 109 |
101 DISALLOW_COPY_AND_ASSIGN(NotificationPermissionInfoBarDelegate); | 110 DISALLOW_COPY_AND_ASSIGN(NotificationPermissionInfoBarDelegate); |
102 }; | 111 }; |
103 | 112 |
| 113 // static |
| 114 void NotificationPermissionInfoBarDelegate::Create( |
| 115 InfoBarService* infobar_service, |
| 116 DesktopNotificationService* notification_service, |
| 117 const GURL& origin, |
| 118 const string16& display_name, |
| 119 int process_id, |
| 120 int route_id, |
| 121 int callback_context) { |
| 122 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 123 new NotificationPermissionInfoBarDelegate( |
| 124 infobar_service, notification_service, origin, display_name, |
| 125 process_id, route_id, callback_context))); |
| 126 } |
| 127 |
104 NotificationPermissionInfoBarDelegate::NotificationPermissionInfoBarDelegate( | 128 NotificationPermissionInfoBarDelegate::NotificationPermissionInfoBarDelegate( |
105 InfoBarService* infobar_service, | 129 InfoBarService* infobar_service, |
106 DesktopNotificationService* notification_service, | 130 DesktopNotificationService* notification_service, |
107 const GURL& origin, | 131 const GURL& origin, |
108 const string16& display_name, | 132 const string16& display_name, |
109 int process_id, | 133 int process_id, |
110 int route_id, | 134 int route_id, |
111 int callback_context) | 135 int callback_context) |
112 : ConfirmInfoBarDelegate(infobar_service), | 136 : ConfirmInfoBarDelegate(infobar_service), |
113 origin_(origin), | 137 origin_(origin), |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 // so don't ask the cache. | 433 // so don't ask the cache. |
410 ContentSetting setting = GetContentSetting(origin); | 434 ContentSetting setting = GetContentSetting(origin); |
411 if (setting == CONTENT_SETTING_ASK) { | 435 if (setting == CONTENT_SETTING_ASK) { |
412 // Show an info bar requesting permission. | 436 // Show an info bar requesting permission. |
413 InfoBarService* infobar_service = | 437 InfoBarService* infobar_service = |
414 InfoBarService::FromWebContents(contents); | 438 InfoBarService::FromWebContents(contents); |
415 // |infobar_service| may be NULL, e.g., if this request originated in a | 439 // |infobar_service| may be NULL, e.g., if this request originated in a |
416 // browser action popup, extension background page, or any HTML that runs | 440 // browser action popup, extension background page, or any HTML that runs |
417 // outside of a tab. | 441 // outside of a tab. |
418 if (infobar_service) { | 442 if (infobar_service) { |
419 infobar_service->AddInfoBar(new NotificationPermissionInfoBarDelegate( | 443 NotificationPermissionInfoBarDelegate::Create( |
420 infobar_service, | 444 infobar_service, |
421 DesktopNotificationServiceFactory::GetForProfile( | 445 DesktopNotificationServiceFactory::GetForProfile( |
422 Profile::FromBrowserContext(contents->GetBrowserContext())), | 446 Profile::FromBrowserContext(contents->GetBrowserContext())), |
423 origin, | 447 origin, |
424 DisplayNameForOrigin(origin), | 448 DisplayNameForOrigin(origin), |
425 process_id, | 449 process_id, |
426 route_id, | 450 route_id, |
427 callback_context)); | 451 callback_context); |
428 return; | 452 return; |
429 } | 453 } |
430 } | 454 } |
431 | 455 |
432 // Notify renderer immediately. | 456 // Notify renderer immediately. |
433 RenderViewHost* host = RenderViewHost::FromID(process_id, route_id); | 457 RenderViewHost* host = RenderViewHost::FromID(process_id, route_id); |
434 if (host) | 458 if (host) |
435 host->DesktopNotificationPermissionRequestDone(callback_context); | 459 host->DesktopNotificationPermissionRequestDone(callback_context); |
436 } | 460 } |
437 | 461 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 | 544 |
521 if (setting == CONTENT_SETTING_ALLOW) | 545 if (setting == CONTENT_SETTING_ALLOW) |
522 return WebKit::WebNotificationPresenter::PermissionAllowed; | 546 return WebKit::WebNotificationPresenter::PermissionAllowed; |
523 if (setting == CONTENT_SETTING_BLOCK) | 547 if (setting == CONTENT_SETTING_BLOCK) |
524 return WebKit::WebNotificationPresenter::PermissionDenied; | 548 return WebKit::WebNotificationPresenter::PermissionDenied; |
525 if (setting == CONTENT_SETTING_ASK) | 549 if (setting == CONTENT_SETTING_ASK) |
526 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 550 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
527 NOTREACHED() << "Invalid notifications settings value: " << setting; | 551 NOTREACHED() << "Invalid notifications settings value: " << setting; |
528 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 552 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
529 } | 553 } |
OLD | NEW |