| OLD | NEW |
| 1 // Copyright (c) 2010 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/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 "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 int route_id_; | 110 int route_id_; |
| 111 int request_id_; | 111 int request_id_; |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 // The delegate for the infobar shown when an origin requests notification | 114 // The delegate for the infobar shown when an origin requests notification |
| 115 // permissions. | 115 // permissions. |
| 116 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | 116 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 117 public: | 117 public: |
| 118 NotificationPermissionInfoBarDelegate(TabContents* contents, | 118 NotificationPermissionInfoBarDelegate(TabContents* contents, |
| 119 const GURL& origin, | 119 const GURL& origin, |
| 120 const std::wstring& display_name, | 120 const string16& display_name, |
| 121 int process_id, | 121 int process_id, |
| 122 int route_id, | 122 int route_id, |
| 123 int callback_context) | 123 int callback_context) |
| 124 : ConfirmInfoBarDelegate(contents), | 124 : ConfirmInfoBarDelegate(contents), |
| 125 origin_(origin), | 125 origin_(origin), |
| 126 display_name_(display_name), | 126 display_name_(display_name), |
| 127 profile_(contents->profile()), | 127 profile_(contents->profile()), |
| 128 process_id_(process_id), | 128 process_id_(process_id), |
| 129 route_id_(route_id), | 129 route_id_(route_id), |
| 130 callback_context_(callback_context), | 130 callback_context_(callback_context), |
| 131 action_taken_(false) { | 131 action_taken_(false) { |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Overridden from ConfirmInfoBarDelegate: | 134 // Overridden from ConfirmInfoBarDelegate: |
| 135 virtual void InfoBarClosed() { | 135 virtual void InfoBarClosed() { |
| 136 if (!action_taken_) | 136 if (!action_taken_) |
| 137 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1); | 137 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1); |
| 138 | 138 |
| 139 ChromeThread::PostTask( | 139 ChromeThread::PostTask( |
| 140 ChromeThread::IO, FROM_HERE, | 140 ChromeThread::IO, FROM_HERE, |
| 141 new NotificationPermissionCallbackTask( | 141 new NotificationPermissionCallbackTask( |
| 142 process_id_, route_id_, callback_context_)); | 142 process_id_, route_id_, callback_context_)); |
| 143 | 143 |
| 144 delete this; | 144 delete this; |
| 145 } | 145 } |
| 146 | 146 |
| 147 virtual std::wstring GetMessageText() const { | 147 virtual string16 GetMessageText() const { |
| 148 return l10n_util::GetStringF(IDS_NOTIFICATION_PERMISSIONS, display_name_); | 148 return l10n_util::GetStringFUTF16(IDS_NOTIFICATION_PERMISSIONS, |
| 149 display_name_); |
| 149 } | 150 } |
| 150 | 151 |
| 151 virtual SkBitmap* GetIcon() const { | 152 virtual SkBitmap* GetIcon() const { |
| 152 return ResourceBundle::GetSharedInstance().GetBitmapNamed( | 153 return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 153 IDR_PRODUCT_ICON_32); | 154 IDR_PRODUCT_ICON_32); |
| 154 } | 155 } |
| 155 | 156 |
| 156 virtual int GetButtons() const { | 157 virtual int GetButtons() const { |
| 157 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT; | 158 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT; |
| 158 } | 159 } |
| 159 | 160 |
| 160 virtual std::wstring GetButtonLabel(InfoBarButton button) const { | 161 virtual string16 GetButtonLabel(InfoBarButton button) const { |
| 161 return button == BUTTON_OK ? | 162 return button == BUTTON_OK ? |
| 162 l10n_util::GetString(IDS_NOTIFICATION_PERMISSION_YES) : | 163 l10n_util::GetStringUTF16(IDS_NOTIFICATION_PERMISSION_YES) : |
| 163 l10n_util::GetString(IDS_NOTIFICATION_PERMISSION_NO); | 164 l10n_util::GetStringUTF16(IDS_NOTIFICATION_PERMISSION_NO); |
| 164 } | 165 } |
| 165 | 166 |
| 166 virtual bool Accept() { | 167 virtual bool Accept() { |
| 167 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Allowed", 1); | 168 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Allowed", 1); |
| 168 profile_->GetDesktopNotificationService()->GrantPermission(origin_); | 169 profile_->GetDesktopNotificationService()->GrantPermission(origin_); |
| 169 action_taken_ = true; | 170 action_taken_ = true; |
| 170 return true; | 171 return true; |
| 171 } | 172 } |
| 172 | 173 |
| 173 virtual bool Cancel() { | 174 virtual bool Cancel() { |
| 174 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Denied", 1); | 175 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Denied", 1); |
| 175 profile_->GetDesktopNotificationService()->DenyPermission(origin_); | 176 profile_->GetDesktopNotificationService()->DenyPermission(origin_); |
| 176 action_taken_ = true; | 177 action_taken_ = true; |
| 177 return true; | 178 return true; |
| 178 } | 179 } |
| 179 | 180 |
| 180 // Overridden from InfoBarDelegate: | 181 // Overridden from InfoBarDelegate: |
| 181 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; } | 182 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; } |
| 182 | 183 |
| 183 private: | 184 private: |
| 184 // The origin we are asking for permissions on. | 185 // The origin we are asking for permissions on. |
| 185 GURL origin_; | 186 GURL origin_; |
| 186 | 187 |
| 187 // The display name for the origin to be displayed. Will be different from | 188 // The display name for the origin to be displayed. Will be different from |
| 188 // origin_ for extensions. | 189 // origin_ for extensions. |
| 189 std::wstring display_name_; | 190 string16 display_name_; |
| 190 | 191 |
| 191 // The Profile that we restore sessions from. | 192 // The Profile that we restore sessions from. |
| 192 Profile* profile_; | 193 Profile* profile_; |
| 193 | 194 |
| 194 // The callback information that tells us how to respond to javascript via | 195 // The callback information that tells us how to respond to javascript via |
| 195 // the correct RenderView. | 196 // the correct RenderView. |
| 196 int process_id_; | 197 int process_id_; |
| 197 int route_id_; | 198 int route_id_; |
| 198 int callback_context_; | 199 int callback_context_; |
| 199 | 200 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 if (!tab) | 511 if (!tab) |
| 511 return; | 512 return; |
| 512 | 513 |
| 513 // If |origin| hasn't been seen before and the default content setting for | 514 // If |origin| hasn't been seen before and the default content setting for |
| 514 // notifications is "ask", show an infobar. | 515 // notifications is "ask", show an infobar. |
| 515 // The cache can only answer queries on the IO thread once it's initialized, | 516 // The cache can only answer queries on the IO thread once it's initialized, |
| 516 // so don't ask the cache. | 517 // so don't ask the cache. |
| 517 ContentSetting setting = GetContentSetting(origin); | 518 ContentSetting setting = GetContentSetting(origin); |
| 518 if (setting == CONTENT_SETTING_ASK) { | 519 if (setting == CONTENT_SETTING_ASK) { |
| 519 // Show an info bar requesting permission. | 520 // Show an info bar requesting permission. |
| 520 std::wstring display_name = UTF16ToWide(DisplayNameForOrigin(origin)); | |
| 521 | |
| 522 tab->AddInfoBar(new NotificationPermissionInfoBarDelegate( | 521 tab->AddInfoBar(new NotificationPermissionInfoBarDelegate( |
| 523 tab, origin, display_name, process_id, route_id, callback_context)); | 522 tab, origin, DisplayNameForOrigin(origin), process_id, |
| 523 route_id, callback_context)); |
| 524 } else { | 524 } else { |
| 525 // Notify renderer immediately. | 525 // Notify renderer immediately. |
| 526 ChromeThread::PostTask( | 526 ChromeThread::PostTask( |
| 527 ChromeThread::IO, FROM_HERE, | 527 ChromeThread::IO, FROM_HERE, |
| 528 new NotificationPermissionCallbackTask( | 528 new NotificationPermissionCallbackTask( |
| 529 process_id, route_id, callback_context)); | 529 process_id, route_id, callback_context)); |
| 530 } | 530 } |
| 531 } | 531 } |
| 532 | 532 |
| 533 void DesktopNotificationService::ShowNotification( | 533 void DesktopNotificationService::ShowNotification( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 if (origin.SchemeIs(chrome::kExtensionScheme)) { | 577 if (origin.SchemeIs(chrome::kExtensionScheme)) { |
| 578 ExtensionsService* ext_service = profile_->GetExtensionsService(); | 578 ExtensionsService* ext_service = profile_->GetExtensionsService(); |
| 579 if (ext_service) { | 579 if (ext_service) { |
| 580 Extension* extension = ext_service->GetExtensionByURL(origin); | 580 Extension* extension = ext_service->GetExtensionByURL(origin); |
| 581 if (extension) | 581 if (extension) |
| 582 return UTF8ToUTF16(extension->name()); | 582 return UTF8ToUTF16(extension->name()); |
| 583 } | 583 } |
| 584 } | 584 } |
| 585 return UTF8ToUTF16(origin.host()); | 585 return UTF8ToUTF16(origin.host()); |
| 586 } | 586 } |
| OLD | NEW |