OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/tools/test_shell/notification_presenter.h" |
| 6 |
| 7 #include "googleurl/src/gurl.h" |
| 8 #include "third_party/WebKit/WebKit/chromium/public/WebNotification.h" |
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebNotificationPermissionCal
lback.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 13 |
| 14 using WebKit::WebNotification; |
| 15 using WebKit::WebNotificationPresenter; |
| 16 using WebKit::WebNotificationPermissionCallback; |
| 17 using WebKit::WebSecurityOrigin; |
| 18 using WebKit::WebString; |
| 19 using WebKit::WebURL; |
| 20 |
| 21 void TestNotificationPresenter::grantPermission(const std::string& origin) { |
| 22 // Make sure it's in the form of an origin. |
| 23 GURL url(origin); |
| 24 allowed_origins_.insert(url.GetOrigin().spec()); |
| 25 } |
| 26 |
| 27 // The output from all these methods matches what DumpRenderTree produces. |
| 28 bool TestNotificationPresenter::show(const WebNotification& notification) { |
| 29 if (notification.isHTML()) { |
| 30 printf("DESKTOP NOTIFICATION: contents at %s\n", |
| 31 notification.url().spec().data()); |
| 32 } else { |
| 33 printf("DESKTOP NOTIFICATION: icon %s, title %s, text %s\n", |
| 34 notification.icon().utf8().data(), |
| 35 notification.title().utf8().data(), |
| 36 notification.body().utf8().data()); |
| 37 } |
| 38 |
| 39 WebNotification event_target(notification); |
| 40 event_target.dispatchDisplayEvent(); |
| 41 return true; |
| 42 } |
| 43 |
| 44 void TestNotificationPresenter::cancel(const WebNotification& notification) { |
| 45 WebString identifier; |
| 46 if (notification.isHTML()) |
| 47 identifier = notification.url().spec().utf16(); |
| 48 else |
| 49 identifier = notification.title(); |
| 50 |
| 51 printf("DESKTOP NOTIFICATION CLOSED: %s\n", identifier.utf8().data()); |
| 52 WebNotification event_target(notification); |
| 53 event_target.dispatchCloseEvent(false); |
| 54 } |
| 55 |
| 56 void TestNotificationPresenter::objectDestroyed( |
| 57 const WebKit::WebNotification& notification) { |
| 58 // Nothing to do. Not storing the objects. |
| 59 } |
| 60 |
| 61 WebNotificationPresenter::Permission TestNotificationPresenter::checkPermission( |
| 62 const WebURL& url) { |
| 63 // Check with the layout test controller |
| 64 std::string origin = static_cast<GURL>(url).GetOrigin().spec(); |
| 65 bool allowed = allowed_origins_.find(origin) != allowed_origins_.end(); |
| 66 return allowed ? WebNotificationPresenter::PermissionAllowed |
| 67 : WebNotificationPresenter::PermissionDenied; |
| 68 } |
| 69 |
| 70 void TestNotificationPresenter::requestPermission( |
| 71 const WebSecurityOrigin& origin, |
| 72 WebNotificationPermissionCallback* callback) { |
| 73 printf("DESKTOP NOTIFICATION PERMISSION REQUESTED: %s\n", |
| 74 origin.toString().utf8().data()); |
| 75 callback->permissionRequestComplete(); |
| 76 } |
OLD | NEW |