1 /* |
|
2 * Copyright (C) 2010 Google Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions are |
|
6 * met: |
|
7 * |
|
8 * * Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * * Redistributions in binary form must reproduce the above |
|
11 * copyright notice, this list of conditions and the following disclaimer |
|
12 * in the documentation and/or other materials provided with the |
|
13 * distribution. |
|
14 * * Neither the name of Google Inc. nor the names of its |
|
15 * contributors may be used to endorse or promote products derived from |
|
16 * this software without specific prior written permission. |
|
17 * |
|
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 */ |
|
30 |
|
31 #include "config.h" |
|
32 #include "NotificationPresenter.h" |
|
33 |
|
34 #include "googleurl/src/gurl.h" |
|
35 #include "public/WebNotification.h" |
|
36 #include "public/WebNotificationPermissionCallback.h" |
|
37 #include "public/WebSecurityOrigin.h" |
|
38 #include "public/WebString.h" |
|
39 #include "public/WebURL.h" |
|
40 #include <wtf/text/CString.h> |
|
41 |
|
42 using namespace WebCore; |
|
43 using namespace WebKit; |
|
44 |
|
45 void NotificationPresenter::grantPermission(const WebString& origin) |
|
46 { |
|
47 // Make sure it's in the form of an origin. |
|
48 GURL url(origin); |
|
49 m_allowedOrigins.add(String(url.GetOrigin().spec().c_str())); |
|
50 } |
|
51 |
|
52 // The output from all these methods matches what DumpRenderTree produces. |
|
53 bool NotificationPresenter::show(const WebNotification& notification) |
|
54 { |
|
55 if (!notification.replaceId().isEmpty()) { |
|
56 String replaceId(notification.replaceId().data(), notification.replaceId().length()); |
|
57 if (m_replacements.find(replaceId) != m_replacements.end()) |
|
58 printf("REPLACING NOTIFICATION %s\n", |
|
59 m_replacements.find(replaceId)->second.utf8().data()); |
|
60 |
|
61 WebString identifier = notification.isHTML() ? |
|
62 notification.url().spec().utf16() : notification.title(); |
|
63 m_replacements.set(replaceId, String(identifier.data(), identifier.length())); |
|
64 } |
|
65 |
|
66 if (notification.isHTML()) { |
|
67 printf("DESKTOP NOTIFICATION: contents at %s\n", |
|
68 notification.url().spec().data()); |
|
69 } else { |
|
70 printf("DESKTOP NOTIFICATION:%s icon %s, title %s, text %s\n", |
|
71 notification.dir() == "rtl" ? "(RTL)" : "", |
|
72 notification.iconURL().isEmpty() ? "" : |
|
73 notification.iconURL().spec().data(), |
|
74 notification.title().isEmpty() ? "" : |
|
75 notification.title().utf8().data(), |
|
76 notification.body().isEmpty() ? "" : |
|
77 notification.body().utf8().data()); |
|
78 } |
|
79 |
|
80 WebNotification eventTarget(notification); |
|
81 eventTarget.dispatchDisplayEvent(); |
|
82 return true; |
|
83 } |
|
84 |
|
85 void NotificationPresenter::cancel(const WebNotification& notification) |
|
86 { |
|
87 WebString identifier; |
|
88 if (notification.isHTML()) |
|
89 identifier = notification.url().spec().utf16(); |
|
90 else |
|
91 identifier = notification.title(); |
|
92 |
|
93 printf("DESKTOP NOTIFICATION CLOSED: %s\n", identifier.utf8().data()); |
|
94 WebNotification eventTarget(notification); |
|
95 eventTarget.dispatchCloseEvent(false); |
|
96 } |
|
97 |
|
98 void NotificationPresenter::objectDestroyed(const WebKit::WebNotification& notification) |
|
99 { |
|
100 // Nothing to do. Not storing the objects. |
|
101 } |
|
102 |
|
103 WebNotificationPresenter::Permission NotificationPresenter::checkPermission(const WebURL& url) |
|
104 { |
|
105 // Check with the layout test controller |
|
106 String origin = String(static_cast<GURL>(url).GetOrigin().spec().c_str()); |
|
107 bool allowed = m_allowedOrigins.find(origin) != m_allowedOrigins.end(); |
|
108 return allowed ? WebNotificationPresenter::PermissionAllowed |
|
109 : WebNotificationPresenter::PermissionDenied; |
|
110 } |
|
111 |
|
112 void NotificationPresenter::requestPermission( |
|
113 const WebSecurityOrigin& origin, |
|
114 WebNotificationPermissionCallback* callback) |
|
115 { |
|
116 printf("DESKTOP NOTIFICATION PERMISSION REQUESTED: %s\n", |
|
117 origin.toString().utf8().data()); |
|
118 callback->permissionRequestComplete(); |
|
119 } |
|