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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/desktop_notification_messages.h" | 8 #include "content/common/desktop_notification_messages.h" |
9 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | 9 #include "content/shell/renderer/test_runner/web_test_delegate.h" |
10 #include "third_party/WebKit/public/platform/Platform.h" | 10 #include "third_party/WebKit/public/platform/Platform.h" |
11 #include "third_party/WebKit/public/platform/WebString.h" | 11 #include "third_party/WebKit/public/platform/WebString.h" |
12 #include "third_party/WebKit/public/platform/WebURL.h" | 12 #include "third_party/WebKit/public/platform/WebURL.h" |
13 #include "third_party/WebKit/public/web/WebKit.h" | 13 #include "third_party/WebKit/public/web/WebKit.h" |
14 #include "third_party/WebKit/public/web/WebNotificationPermissionCallback.h" | 14 #include "third_party/WebKit/public/web/WebNotificationPermissionCallback.h" |
15 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 15 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 using blink::Platform; | 18 using blink::Platform; |
19 using blink::WebNotification; | 19 using blink::WebNotification; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 cancel(notification); | 58 cancel(notification); |
59 } | 59 } |
60 | 60 |
61 replacements_.clear(); | 61 replacements_.clear(); |
62 } | 62 } |
63 | 63 |
64 bool NotificationPresenter::show(const WebNotification& notification) { | 64 bool NotificationPresenter::show(const WebNotification& notification) { |
65 if (!notification.replaceId().isEmpty()) { | 65 if (!notification.replaceId().isEmpty()) { |
66 std::string replaceId(notification.replaceId().utf8()); | 66 std::string replaceId(notification.replaceId().utf8()); |
67 if (replacements_.find(replaceId) != replacements_.end()) { | 67 if (replacements_.find(replaceId) != replacements_.end()) { |
68 delegate_->printMessage(std::string("REPLACING NOTIFICATION ") + | 68 delegate_->PrintMessage(std::string("REPLACING NOTIFICATION ") + |
69 replacements_.find(replaceId)->second + "\n"); | 69 replacements_.find(replaceId)->second + "\n"); |
70 } | 70 } |
71 replacements_[replaceId] = notification.title().utf8(); | 71 replacements_[replaceId] = notification.title().utf8(); |
72 } | 72 } |
73 | 73 |
74 delegate_->printMessage("DESKTOP NOTIFICATION SHOWN: "); | 74 delegate_->PrintMessage("DESKTOP NOTIFICATION SHOWN: "); |
75 if (!notification.title().isEmpty()) | 75 if (!notification.title().isEmpty()) |
76 delegate_->printMessage(notification.title().utf8().data()); | 76 delegate_->PrintMessage(notification.title().utf8().data()); |
77 | 77 |
78 if (notification.direction() == WebTextDirectionRightToLeft) | 78 if (notification.direction() == WebTextDirectionRightToLeft) |
79 delegate_->printMessage(", RTL"); | 79 delegate_->PrintMessage(", RTL"); |
80 | 80 |
81 // TODO(beverloo): WebNotification should expose the "lang" attribute's value. | 81 // TODO(beverloo): WebNotification should expose the "lang" attribute's value. |
82 | 82 |
83 if (!notification.body().isEmpty()) { | 83 if (!notification.body().isEmpty()) { |
84 delegate_->printMessage(std::string(", body: ") + | 84 delegate_->PrintMessage(std::string(", body: ") + |
85 notification.body().utf8().data()); | 85 notification.body().utf8().data()); |
86 } | 86 } |
87 | 87 |
88 if (!notification.replaceId().isEmpty()) { | 88 if (!notification.replaceId().isEmpty()) { |
89 delegate_->printMessage(std::string(", tag: ") + | 89 delegate_->PrintMessage(std::string(", tag: ") + |
90 notification.replaceId().utf8().data()); | 90 notification.replaceId().utf8().data()); |
91 } | 91 } |
92 | 92 |
93 if (!notification.iconURL().isEmpty()) { | 93 if (!notification.iconURL().isEmpty()) { |
94 delegate_->printMessage(std::string(", icon: ") + | 94 delegate_->PrintMessage(std::string(", icon: ") + |
95 notification.iconURL().spec().data()); | 95 notification.iconURL().spec().data()); |
96 } | 96 } |
97 | 97 |
98 delegate_->printMessage("\n"); | 98 delegate_->PrintMessage("\n"); |
99 | 99 |
100 std::string title = notification.title().utf8(); | 100 std::string title = notification.title().utf8(); |
101 active_notifications_[title] = notification; | 101 active_notifications_[title] = notification; |
102 | 102 |
103 Platform::current()->callOnMainThread(DeferredDisplayDispatch, | 103 Platform::current()->callOnMainThread(DeferredDisplayDispatch, |
104 new WebNotification(notification)); | 104 new WebNotification(notification)); |
105 | 105 |
106 return true; | 106 return true; |
107 } | 107 } |
108 | 108 |
109 void NotificationPresenter::cancel(const WebNotification& notification) { | 109 void NotificationPresenter::cancel(const WebNotification& notification) { |
110 std::string title = notification.title().utf8(); | 110 std::string title = notification.title().utf8(); |
111 | 111 |
112 delegate_->printMessage(std::string("DESKTOP NOTIFICATION CLOSED: ") + title + | 112 delegate_->PrintMessage(std::string("DESKTOP NOTIFICATION CLOSED: ") + title + |
113 "\n"); | 113 "\n"); |
114 | 114 |
115 WebNotification event_target(notification); | 115 WebNotification event_target(notification); |
116 event_target.dispatchCloseEvent(false); | 116 event_target.dispatchCloseEvent(false); |
117 | 117 |
118 active_notifications_.erase(title); | 118 active_notifications_.erase(title); |
119 } | 119 } |
120 | 120 |
121 void NotificationPresenter::objectDestroyed( | 121 void NotificationPresenter::objectDestroyed( |
122 const WebNotification& notification) { | 122 const WebNotification& notification) { |
123 std::string title = notification.title().utf8(); | 123 std::string title = notification.title().utf8(); |
124 active_notifications_.erase(title); | 124 active_notifications_.erase(title); |
125 } | 125 } |
126 | 126 |
127 WebNotificationPresenter::Permission NotificationPresenter::checkPermission( | 127 WebNotificationPresenter::Permission NotificationPresenter::checkPermission( |
128 const WebSecurityOrigin& security_origin) { | 128 const WebSecurityOrigin& security_origin) { |
129 return delegate_->checkWebNotificationPermission( | 129 return delegate_->CheckWebNotificationPermission( |
130 GURL(security_origin.toString())); | 130 GURL(security_origin.toString())); |
131 } | 131 } |
132 | 132 |
133 } // namespace content | 133 } // namespace content |
OLD | NEW |