| 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" |
| 8 #include "content/common/desktop_notification_messages.h" |
| 7 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | 9 #include "content/shell/renderer/test_runner/WebTestDelegate.h" |
| 8 #include "third_party/WebKit/public/platform/Platform.h" | 10 #include "third_party/WebKit/public/platform/Platform.h" |
| 9 #include "third_party/WebKit/public/platform/WebString.h" | 11 #include "third_party/WebKit/public/platform/WebString.h" |
| 10 #include "third_party/WebKit/public/platform/WebURL.h" | 12 #include "third_party/WebKit/public/platform/WebURL.h" |
| 11 #include "third_party/WebKit/public/web/WebKit.h" | 13 #include "third_party/WebKit/public/web/WebKit.h" |
| 12 #include "third_party/WebKit/public/web/WebNotificationPermissionCallback.h" | 14 #include "third_party/WebKit/public/web/WebNotificationPermissionCallback.h" |
| 13 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 15 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 14 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 15 | 17 |
| 16 using blink::Platform; | 18 using blink::Platform; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 30 | 32 |
| 31 delete notification; | 33 delete notification; |
| 32 } | 34 } |
| 33 | 35 |
| 34 } // namespace | 36 } // namespace |
| 35 | 37 |
| 36 NotificationPresenter::NotificationPresenter() : delegate_(0) {} | 38 NotificationPresenter::NotificationPresenter() : delegate_(0) {} |
| 37 | 39 |
| 38 NotificationPresenter::~NotificationPresenter() {} | 40 NotificationPresenter::~NotificationPresenter() {} |
| 39 | 41 |
| 40 void NotificationPresenter::GrantPermission(const std::string& origin, | |
| 41 bool permission_granted) { | |
| 42 known_origins_[origin] = permission_granted; | |
| 43 } | |
| 44 | |
| 45 bool NotificationPresenter::SimulateClick(const std::string& title) { | 42 bool NotificationPresenter::SimulateClick(const std::string& title) { |
| 46 ActiveNotificationMap::iterator iter = active_notifications_.find(title); | 43 ActiveNotificationMap::iterator iter = active_notifications_.find(title); |
| 47 if (iter == active_notifications_.end()) | 44 if (iter == active_notifications_.end()) |
| 48 return false; | 45 return false; |
| 49 | 46 |
| 50 const WebNotification& notification = iter->second; | 47 const WebNotification& notification = iter->second; |
| 51 | 48 |
| 52 WebNotification event_target(notification); | 49 WebNotification event_target(notification); |
| 53 event_target.dispatchClickEvent(); | 50 event_target.dispatchClickEvent(); |
| 54 | 51 |
| 55 return true; | 52 return true; |
| 56 } | 53 } |
| 57 | 54 |
| 58 void NotificationPresenter::Reset() { | 55 void NotificationPresenter::Reset() { |
| 59 while (!active_notifications_.empty()) { | 56 while (!active_notifications_.empty()) { |
| 60 const WebNotification& notification = active_notifications_.begin()->second; | 57 const WebNotification& notification = active_notifications_.begin()->second; |
| 61 cancel(notification); | 58 cancel(notification); |
| 62 } | 59 } |
| 63 | 60 |
| 64 known_origins_.clear(); | |
| 65 replacements_.clear(); | 61 replacements_.clear(); |
| 66 } | 62 } |
| 67 | 63 |
| 68 bool NotificationPresenter::show(const WebNotification& notification) { | 64 bool NotificationPresenter::show(const WebNotification& notification) { |
| 69 if (!notification.replaceId().isEmpty()) { | 65 if (!notification.replaceId().isEmpty()) { |
| 70 std::string replaceId(notification.replaceId().utf8()); | 66 std::string replaceId(notification.replaceId().utf8()); |
| 71 if (replacements_.find(replaceId) != replacements_.end()) { | 67 if (replacements_.find(replaceId) != replacements_.end()) { |
| 72 delegate_->printMessage(std::string("REPLACING NOTIFICATION ") + | 68 delegate_->printMessage(std::string("REPLACING NOTIFICATION ") + |
| 73 replacements_.find(replaceId)->second + "\n"); | 69 replacements_.find(replaceId)->second + "\n"); |
| 74 } | 70 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 119 } |
| 124 | 120 |
| 125 void NotificationPresenter::objectDestroyed( | 121 void NotificationPresenter::objectDestroyed( |
| 126 const WebNotification& notification) { | 122 const WebNotification& notification) { |
| 127 std::string title = notification.title().utf8(); | 123 std::string title = notification.title().utf8(); |
| 128 active_notifications_.erase(title); | 124 active_notifications_.erase(title); |
| 129 } | 125 } |
| 130 | 126 |
| 131 WebNotificationPresenter::Permission NotificationPresenter::checkPermission( | 127 WebNotificationPresenter::Permission NotificationPresenter::checkPermission( |
| 132 const WebSecurityOrigin& security_origin) { | 128 const WebSecurityOrigin& security_origin) { |
| 133 const std::string origin = security_origin.toString().utf8(); | 129 return delegate_->checkWebNotificationPermission( |
| 134 const KnownOriginMap::iterator it = known_origins_.find(origin); | 130 GURL(security_origin.toString())); |
| 135 if (it == known_origins_.end()) | |
| 136 return WebNotificationPresenter::PermissionNotAllowed; | |
| 137 | |
| 138 // Values in |known_origins_| indicate whether permission has been granted. | |
| 139 if (it->second) | |
| 140 return WebNotificationPresenter::PermissionAllowed; | |
| 141 | |
| 142 return WebNotificationPresenter::PermissionDenied; | |
| 143 } | 131 } |
| 144 | 132 |
| 145 void NotificationPresenter::requestPermission( | 133 void NotificationPresenter::requestPermission( |
| 146 const WebSecurityOrigin& security_origin, | 134 const WebSecurityOrigin& security_origin, |
| 147 WebNotificationPermissionCallback* callback) { | 135 WebNotificationPermissionCallback* callback) { |
| 148 std::string origin = security_origin.toString().utf8(); | 136 NOTREACHED(); |
| 149 delegate_->printMessage("DESKTOP NOTIFICATION PERMISSION REQUESTED: " + | |
| 150 origin + "\n"); | |
| 151 callback->permissionRequestComplete(); | |
| 152 } | 137 } |
| 153 | 138 |
| 154 } // namespace content | 139 } // namespace content |
| OLD | NEW |