OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "WebNotificationPermissionCallback.h" | 42 #include "WebNotificationPermissionCallback.h" |
43 #include "WebNotificationPresenter.h" | 43 #include "WebNotificationPresenter.h" |
44 #include <public/WebURL.h> | 44 #include <public/WebURL.h> |
45 | 45 |
46 #include <wtf/PassRefPtr.h> | 46 #include <wtf/PassRefPtr.h> |
47 | 47 |
48 using namespace WebCore; | 48 using namespace WebCore; |
49 | 49 |
50 namespace WebKit { | 50 namespace WebKit { |
51 | 51 |
| 52 #if ENABLE(LEGACY_NOTIFICATIONS) |
52 class VoidCallbackClient : public WebNotificationPermissionCallback { | 53 class VoidCallbackClient : public WebNotificationPermissionCallback { |
53 public: | 54 public: |
54 VoidCallbackClient(PassRefPtr<VoidCallback> callback) | 55 explicit VoidCallbackClient(PassRefPtr<VoidCallback> callback) |
55 : m_callback(callback) | 56 : m_callback(callback) |
56 { | 57 { |
57 } | 58 } |
58 | 59 |
59 virtual void permissionRequestComplete() | 60 virtual void permissionRequestComplete() |
60 { | 61 { |
61 if (m_callback) | 62 if (m_callback) |
62 m_callback->handleEvent(); | 63 m_callback->handleEvent(); |
63 delete this; | 64 delete this; |
64 } | 65 } |
65 | 66 |
66 private: | 67 private: |
67 virtual ~VoidCallbackClient() { } | 68 virtual ~VoidCallbackClient() { } |
68 | 69 |
69 RefPtr<VoidCallback> m_callback; | 70 RefPtr<VoidCallback> m_callback; |
70 }; | 71 }; |
| 72 #endif // ENABLE(LEGACY_NOTIFICATIONS) |
| 73 |
| 74 #if ENABLE(NOTIFICATIONS) |
| 75 class NotificationPermissionCallbackClient : public WebNotificationPermissionCal
lback { |
| 76 public: |
| 77 NotificationPermissionCallbackClient(WebNotificationPresenter* presenter, Pa
ssRefPtr<SecurityOrigin> securityOrigin, PassRefPtr<NotificationPermissionCallba
ck> callback) |
| 78 : m_presenter(presenter) |
| 79 , m_securityOrigin(securityOrigin) |
| 80 , m_callback(callback) |
| 81 { |
| 82 } |
| 83 |
| 84 virtual void permissionRequestComplete() |
| 85 { |
| 86 if (m_callback) |
| 87 m_callback->handleEvent(Notification::permissionString(static_cast<N
otificationClient::Permission>(m_presenter->checkPermission(WebSecurityOrigin(m_
securityOrigin))))); |
| 88 delete this; |
| 89 } |
| 90 |
| 91 private: |
| 92 virtual ~NotificationPermissionCallbackClient() { } |
| 93 |
| 94 WebNotificationPresenter* m_presenter; |
| 95 RefPtr<SecurityOrigin> m_securityOrigin; |
| 96 RefPtr<NotificationPermissionCallback> m_callback; |
| 97 }; |
| 98 #endif // ENABLE(NOTIFICATIONS) |
71 | 99 |
72 void NotificationPresenterImpl::initialize(WebNotificationPresenter* presenter) | 100 void NotificationPresenterImpl::initialize(WebNotificationPresenter* presenter) |
73 { | 101 { |
74 m_presenter = presenter; | 102 m_presenter = presenter; |
75 } | 103 } |
76 | 104 |
77 bool NotificationPresenterImpl::isInitialized() | 105 bool NotificationPresenterImpl::isInitialized() |
78 { | 106 { |
79 return !!m_presenter; | 107 return !!m_presenter; |
80 } | 108 } |
(...skipping 16 matching lines...) Expand all Loading... |
97 void NotificationPresenterImpl::notificationControllerDestroyed() | 125 void NotificationPresenterImpl::notificationControllerDestroyed() |
98 { | 126 { |
99 } | 127 } |
100 | 128 |
101 NotificationClient::Permission NotificationPresenterImpl::checkPermission(Script
ExecutionContext* context) | 129 NotificationClient::Permission NotificationPresenterImpl::checkPermission(Script
ExecutionContext* context) |
102 { | 130 { |
103 int result = m_presenter->checkPermission(WebSecurityOrigin(context->securit
yOrigin())); | 131 int result = m_presenter->checkPermission(WebSecurityOrigin(context->securit
yOrigin())); |
104 return static_cast<NotificationClient::Permission>(result); | 132 return static_cast<NotificationClient::Permission>(result); |
105 } | 133 } |
106 | 134 |
| 135 #if ENABLE(LEGACY_NOTIFICATIONS) |
107 void NotificationPresenterImpl::requestPermission(ScriptExecutionContext* contex
t, PassRefPtr<VoidCallback> callback) | 136 void NotificationPresenterImpl::requestPermission(ScriptExecutionContext* contex
t, PassRefPtr<VoidCallback> callback) |
108 { | 137 { |
109 m_presenter->requestPermission(WebSecurityOrigin(context->securityOrigin()),
new VoidCallbackClient(callback)); | 138 m_presenter->requestPermission(WebSecurityOrigin(context->securityOrigin()),
new VoidCallbackClient(callback)); |
110 } | 139 } |
| 140 #endif // ENABLE(LEGACY_NOTIFICATIONS) |
| 141 |
| 142 #if ENABLE(NOTIFICATIONS) |
| 143 void NotificationPresenterImpl::requestPermission(ScriptExecutionContext* contex
t, WTF::PassRefPtr<NotificationPermissionCallback> callback) |
| 144 { |
| 145 m_presenter->requestPermission(WebSecurityOrigin(context->securityOrigin()),
new NotificationPermissionCallbackClient(m_presenter, context->securityOrigin()
, callback)); |
| 146 } |
| 147 #endif // ENABLE(NOTIFICATIONS) |
111 | 148 |
112 } // namespace WebKit | 149 } // namespace WebKit |
113 | 150 |
114 #endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) | 151 #endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) |
OLD | NEW |