OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 "base/bind.h" | |
8 #include "base/message_loop.h" | |
9 #include "googleurl/src/gurl.h" | |
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | |
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotification.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPermis
sionCallback.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h" | |
16 | |
17 using WebKit::WebNotification; | |
18 using WebKit::WebNotificationPresenter; | |
19 using WebKit::WebNotificationPermissionCallback; | |
20 using WebKit::WebSecurityOrigin; | |
21 using WebKit::WebString; | |
22 using WebKit::WebTextDirectionRightToLeft; | |
23 using WebKit::WebURL; | |
24 | |
25 namespace { | |
26 void DeferredDisplayDispatch(WebNotification notification) { | |
27 notification.dispatchDisplayEvent(); | |
28 } | |
29 } | |
30 | |
31 TestNotificationPresenter::TestNotificationPresenter(TestShell* shell) { | |
32 } | |
33 | |
34 TestNotificationPresenter::~TestNotificationPresenter() {} | |
35 | |
36 void TestNotificationPresenter::Reset() { | |
37 allowed_origins_.clear(); | |
38 } | |
39 | |
40 void TestNotificationPresenter::grantPermission(const std::string& origin) { | |
41 allowed_origins_.insert(origin); | |
42 } | |
43 | |
44 // The output from all these methods matches what DumpRenderTree produces. | |
45 bool TestNotificationPresenter::show(const WebNotification& notification) { | |
46 if (!notification.replaceId().isEmpty()) { | |
47 std::string replace_id(notification.replaceId().utf8()); | |
48 if (replacements_.find(replace_id) != replacements_.end()) | |
49 printf("REPLACING NOTIFICATION %s\n", | |
50 replacements_.find(replace_id)->second.c_str()); | |
51 | |
52 WebString identifier = notification.isHTML() ? | |
53 notification.url().spec().utf16() : notification.title(); | |
54 replacements_[replace_id] = identifier.utf8(); | |
55 } | |
56 | |
57 if (notification.isHTML()) { | |
58 printf("DESKTOP NOTIFICATION: contents at %s\n", | |
59 notification.url().spec().data()); | |
60 } else { | |
61 printf("DESKTOP NOTIFICATION:%s icon %s, title %s, text %s\n", | |
62 notification.direction() == WebTextDirectionRightToLeft ? "(RTL)" : | |
63 "", | |
64 notification.iconURL().isEmpty() ? "" : | |
65 notification.iconURL().spec().data(), | |
66 notification.title().isEmpty() ? "" : | |
67 notification.title().utf8().data(), | |
68 notification.body().isEmpty() ? "" : | |
69 notification.body().utf8().data()); | |
70 } | |
71 | |
72 | |
73 WebNotification event_target(notification); | |
74 MessageLoop::current()->PostTask( | |
75 FROM_HERE, base::Bind(&DeferredDisplayDispatch, event_target)); | |
76 return true; | |
77 } | |
78 | |
79 void TestNotificationPresenter::cancel(const WebNotification& notification) { | |
80 WebString identifier; | |
81 if (notification.isHTML()) | |
82 identifier = notification.url().spec().utf16(); | |
83 else | |
84 identifier = notification.title(); | |
85 | |
86 printf("DESKTOP NOTIFICATION CLOSED: %s\n", identifier.utf8().data()); | |
87 WebNotification event_target(notification); | |
88 event_target.dispatchCloseEvent(false); | |
89 } | |
90 | |
91 void TestNotificationPresenter::objectDestroyed( | |
92 const WebKit::WebNotification& notification) { | |
93 // Nothing to do. Not storing the objects. | |
94 } | |
95 | |
96 WebNotificationPresenter::Permission TestNotificationPresenter::checkPermission( | |
97 const WebSecurityOrigin& origin) { | |
98 // Check with the layout test controller | |
99 bool allowed = allowed_origins_.find(origin.toString().utf8().data()) | |
100 != allowed_origins_.end(); | |
101 return allowed ? WebNotificationPresenter::PermissionAllowed | |
102 : WebNotificationPresenter::PermissionDenied; | |
103 } | |
104 | |
105 void TestNotificationPresenter::requestPermission( | |
106 const WebSecurityOrigin& origin, | |
107 WebNotificationPermissionCallback* callback) { | |
108 printf("DESKTOP NOTIFICATION PERMISSION REQUESTED: %s\n", | |
109 origin.toString().utf8().data()); | |
110 callback->permissionRequestComplete(); | |
111 } | |
OLD | NEW |