| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/shell/renderer/test_runner/notification_presenter.h" | 5 #include "content/shell/renderer/test_runner/notification_presenter.h" |
| 6 | 6 |
| 7 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | 7 #include "content/shell/renderer/test_runner/WebTestDelegate.h" |
| 8 #include "third_party/WebKit/public/platform/Platform.h" | 8 #include "third_party/WebKit/public/platform/Platform.h" |
| 9 #include "third_party/WebKit/public/platform/WebString.h" | 9 #include "third_party/WebKit/public/platform/WebString.h" |
| 10 #include "third_party/WebKit/public/platform/WebURL.h" | 10 #include "third_party/WebKit/public/platform/WebURL.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 void NotificationPresenter::CancelAllActiveNotifications() { | 58 void NotificationPresenter::CancelAllActiveNotifications() { |
| 59 while (!active_notifications_.empty()) { | 59 while (!active_notifications_.empty()) { |
| 60 const WebNotification& notification = active_notifications_.begin()->second; | 60 const WebNotification& notification = active_notifications_.begin()->second; |
| 61 cancel(notification); | 61 cancel(notification); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 void NotificationPresenter::Reset() { | 65 void NotificationPresenter::Reset() { |
| 66 // TODO(peter): Ensure that |active_notifications_| is empty as well. | 66 CancelAllActiveNotifications(); |
| 67 known_origins_.clear(); | 67 known_origins_.clear(); |
| 68 replacements_.clear(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 bool NotificationPresenter::show(const WebNotification& notification) { | 71 bool NotificationPresenter::show(const WebNotification& notification) { |
| 71 if (!notification.replaceId().isEmpty()) { | 72 if (!notification.replaceId().isEmpty()) { |
| 72 std::string replaceId(notification.replaceId().utf8()); | 73 std::string replaceId(notification.replaceId().utf8()); |
| 73 if (replacements_.find(replaceId) != replacements_.end()) { | 74 if (replacements_.find(replaceId) != replacements_.end()) { |
| 74 delegate_->printMessage(std::string("REPLACING NOTIFICATION ") + | 75 delegate_->printMessage(std::string("REPLACING NOTIFICATION ") + |
| 75 replacements_.find(replaceId)->second + "\n"); | 76 replacements_.find(replaceId)->second + "\n"); |
| 76 } | 77 } |
| 77 replacements_[replaceId] = notification.title().utf8(); | 78 replacements_[replaceId] = notification.title().utf8(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 delegate_->printMessage("DESKTOP NOTIFICATION:"); | 81 delegate_->printMessage("DESKTOP NOTIFICATION SHOWN: "); |
| 81 delegate_->printMessage( | 82 if (!notification.title().isEmpty()) |
| 82 notification.direction() == WebTextDirectionRightToLeft ? "(RTL)" : ""); | 83 delegate_->printMessage(notification.title().utf8().data()); |
| 83 delegate_->printMessage(" icon "); | 84 |
| 84 delegate_->printMessage(notification.iconURL().isEmpty() | 85 if (notification.direction() == WebTextDirectionRightToLeft) |
| 85 ? "" | 86 delegate_->printMessage(", RTL"); |
| 86 : notification.iconURL().spec().data()); | 87 |
| 87 delegate_->printMessage(", title "); | 88 // TODO(beverloo): WebNotification should expose the "lang" attribute's value. |
| 88 delegate_->printMessage( | 89 |
| 89 notification.title().isEmpty() ? "" : notification.title().utf8().data()); | 90 if (!notification.body().isEmpty()) { |
| 90 delegate_->printMessage(", text "); | 91 delegate_->printMessage(std::string(", body: ") + |
| 91 delegate_->printMessage( | 92 notification.body().utf8().data()); |
| 92 notification.body().isEmpty() ? "" : notification.body().utf8().data()); | 93 } |
| 94 |
| 95 if (!notification.replaceId().isEmpty()) { |
| 96 delegate_->printMessage(std::string(", tag: ") + |
| 97 notification.replaceId().utf8().data()); |
| 98 } |
| 99 |
| 100 if (!notification.iconURL().isEmpty()) { |
| 101 delegate_->printMessage(std::string(", icon: ") + |
| 102 notification.iconURL().spec().data()); |
| 103 } |
| 104 |
| 93 delegate_->printMessage("\n"); | 105 delegate_->printMessage("\n"); |
| 94 | 106 |
| 95 std::string title = notification.title().utf8(); | 107 std::string title = notification.title().utf8(); |
| 96 active_notifications_[title] = notification; | 108 active_notifications_[title] = notification; |
| 97 | 109 |
| 98 Platform::current()->callOnMainThread(DeferredDisplayDispatch, | 110 Platform::current()->callOnMainThread(DeferredDisplayDispatch, |
| 99 new WebNotification(notification)); | 111 new WebNotification(notification)); |
| 100 | 112 |
| 101 return true; | 113 return true; |
| 102 } | 114 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 void NotificationPresenter::requestPermission( | 148 void NotificationPresenter::requestPermission( |
| 137 const WebSecurityOrigin& security_origin, | 149 const WebSecurityOrigin& security_origin, |
| 138 WebNotificationPermissionCallback* callback) { | 150 WebNotificationPermissionCallback* callback) { |
| 139 std::string origin = security_origin.toString().utf8(); | 151 std::string origin = security_origin.toString().utf8(); |
| 140 delegate_->printMessage("DESKTOP NOTIFICATION PERMISSION REQUESTED: " + | 152 delegate_->printMessage("DESKTOP NOTIFICATION PERMISSION REQUESTED: " + |
| 141 origin + "\n"); | 153 origin + "\n"); |
| 142 callback->permissionRequestComplete(); | 154 callback->permissionRequestComplete(); |
| 143 } | 155 } |
| 144 | 156 |
| 145 } // namespace content | 157 } // namespace content |
| OLD | NEW |