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