OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" | 65 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" |
66 #include "web/WebEmbeddedWorkerImpl.h" | 66 #include "web/WebEmbeddedWorkerImpl.h" |
67 #include "wtf/Assertions.h" | 67 #include "wtf/Assertions.h" |
68 #include "wtf/Functional.h" | 68 #include "wtf/Functional.h" |
69 #include "wtf/PassOwnPtr.h" | 69 #include "wtf/PassOwnPtr.h" |
70 | 70 |
71 #include <utility> | 71 #include <utility> |
72 | 72 |
73 namespace blink { | 73 namespace blink { |
74 | 74 |
75 RawPtr<ServiceWorkerGlobalScopeProxy> ServiceWorkerGlobalScopeProxy::create(WebE
mbeddedWorkerImpl& embeddedWorker, Document& document, WebServiceWorkerContextCl
ient& client) | 75 ServiceWorkerGlobalScopeProxy* ServiceWorkerGlobalScopeProxy::create(WebEmbedded
WorkerImpl& embeddedWorker, Document& document, WebServiceWorkerContextClient& c
lient) |
76 { | 76 { |
77 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client); | 77 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client); |
78 } | 78 } |
79 | 79 |
80 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() | 80 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() |
81 { | 81 { |
82 // Verify that the proxy has been detached. | 82 // Verify that the proxy has been detached. |
83 DCHECK(!m_embeddedWorker); | 83 DCHECK(!m_embeddedWorker); |
84 } | 84 } |
85 | 85 |
86 DEFINE_TRACE(ServiceWorkerGlobalScopeProxy) | 86 DEFINE_TRACE(ServiceWorkerGlobalScopeProxy) |
87 { | 87 { |
88 visitor->trace(m_document); | 88 visitor->trace(m_document); |
89 visitor->trace(m_workerGlobalScope); | 89 visitor->trace(m_workerGlobalScope); |
90 } | 90 } |
91 | 91 |
92 void ServiceWorkerGlobalScopeProxy::setRegistration(std::unique_ptr<WebServiceWo
rkerRegistration::Handle> handle) | 92 void ServiceWorkerGlobalScopeProxy::setRegistration(std::unique_ptr<WebServiceWo
rkerRegistration::Handle> handle) |
93 { | 93 { |
94 workerGlobalScope()->setRegistration(std::move(handle)); | 94 workerGlobalScope()->setRegistration(std::move(handle)); |
95 } | 95 } |
96 | 96 |
97 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) | 97 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) |
98 { | 98 { |
99 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Activate, eventID); | 99 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Activate, eventID); |
100 RawPtr<Event> event(ExtendableEvent::create(EventTypeNames::activate, Extend
ableEventInit(), observer)); | 100 Event* event = ExtendableEvent::create(EventTypeNames::activate, ExtendableE
ventInit(), observer); |
101 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); | 101 workerGlobalScope()->dispatchExtendableEvent(event, observer); |
102 } | 102 } |
103 | 103 |
104 void ServiceWorkerGlobalScopeProxy::dispatchExtendableMessageEvent(int eventID,
const WebString& message, const WebSecurityOrigin& sourceOrigin, const WebMessag
ePortChannelArray& webChannels, const WebServiceWorkerClientInfo& client) | 104 void ServiceWorkerGlobalScopeProxy::dispatchExtendableMessageEvent(int eventID,
const WebString& message, const WebSecurityOrigin& sourceOrigin, const WebMessag
ePortChannelArray& webChannels, const WebServiceWorkerClientInfo& client) |
105 { | 105 { |
106 DCHECK(RuntimeEnabledFeatures::serviceWorkerExtendableMessageEventEnabled())
; | 106 DCHECK(RuntimeEnabledFeatures::serviceWorkerExtendableMessageEventEnabled())
; |
107 | 107 |
108 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); | 108 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); |
109 MessagePortArray* ports = MessagePort::toMessagePortArray(m_workerGlobalScop
e, webChannels); | 109 MessagePortArray* ports = MessagePort::toMessagePortArray(m_workerGlobalScop
e, webChannels); |
110 String origin; | 110 String origin; |
111 if (!sourceOrigin.isUnique()) | 111 if (!sourceOrigin.isUnique()) |
112 origin = sourceOrigin.toString(); | 112 origin = sourceOrigin.toString(); |
113 ServiceWorkerClient* source = nullptr; | 113 ServiceWorkerClient* source = nullptr; |
114 if (client.clientType == WebServiceWorkerClientTypeWindow) | 114 if (client.clientType == WebServiceWorkerClientTypeWindow) |
115 source = ServiceWorkerWindowClient::create(client); | 115 source = ServiceWorkerWindowClient::create(client); |
116 else | 116 else |
117 source = ServiceWorkerClient::create(client); | 117 source = ServiceWorkerClient::create(client); |
118 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Message, eventID); | 118 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Message, eventID); |
119 | 119 |
120 RawPtr<Event> event(ExtendableMessageEvent::create(value, origin, ports, sou
rce, observer)); | 120 Event* event = ExtendableMessageEvent::create(value, origin, ports, source,
observer); |
121 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); | 121 workerGlobalScope()->dispatchExtendableEvent(event, observer); |
122 } | 122 } |
123 | 123 |
124 void ServiceWorkerGlobalScopeProxy::dispatchExtendableMessageEvent(int eventID,
const WebString& message, const WebSecurityOrigin& sourceOrigin, const WebMessag
ePortChannelArray& webChannels, std::unique_ptr<WebServiceWorker::Handle> handle
) | 124 void ServiceWorkerGlobalScopeProxy::dispatchExtendableMessageEvent(int eventID,
const WebString& message, const WebSecurityOrigin& sourceOrigin, const WebMessag
ePortChannelArray& webChannels, std::unique_ptr<WebServiceWorker::Handle> handle
) |
125 { | 125 { |
126 DCHECK(RuntimeEnabledFeatures::serviceWorkerExtendableMessageEventEnabled())
; | 126 DCHECK(RuntimeEnabledFeatures::serviceWorkerExtendableMessageEventEnabled())
; |
127 | 127 |
128 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); | 128 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); |
129 MessagePortArray* ports = MessagePort::toMessagePortArray(m_workerGlobalScop
e, webChannels); | 129 MessagePortArray* ports = MessagePort::toMessagePortArray(m_workerGlobalScop
e, webChannels); |
130 String origin; | 130 String origin; |
131 if (!sourceOrigin.isUnique()) | 131 if (!sourceOrigin.isUnique()) |
132 origin = sourceOrigin.toString(); | 132 origin = sourceOrigin.toString(); |
133 ServiceWorker* source = ServiceWorker::from(m_workerGlobalScope->getExecutio
nContext(), adoptPtr(handle.release())); | 133 ServiceWorker* source = ServiceWorker::from(m_workerGlobalScope->getExecutio
nContext(), adoptPtr(handle.release())); |
134 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Message, eventID); | 134 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Message, eventID); |
135 | 135 |
136 RawPtr<Event> event(ExtendableMessageEvent::create(value, origin, ports, sou
rce, observer)); | 136 Event* event = ExtendableMessageEvent::create(value, origin, ports, source,
observer); |
137 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); | 137 workerGlobalScope()->dispatchExtendableEvent(event, observer); |
138 } | 138 } |
139 | 139 |
140 void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int eventID, const WebSer
viceWorkerRequest& webRequest) | 140 void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int eventID, const WebSer
viceWorkerRequest& webRequest) |
141 { | 141 { |
142 RespondWithObserver* observer = RespondWithObserver::create(workerGlobalScop
e(), eventID, webRequest.url(), webRequest.mode(), webRequest.frameType(), webRe
quest.requestContext()); | 142 RespondWithObserver* observer = RespondWithObserver::create(workerGlobalScop
e(), eventID, webRequest.url(), webRequest.mode(), webRequest.frameType(), webRe
quest.requestContext()); |
143 Request* request = Request::create(workerGlobalScope(), webRequest); | 143 Request* request = Request::create(workerGlobalScope(), webRequest); |
144 request->getHeaders()->setGuard(Headers::ImmutableGuard); | 144 request->getHeaders()->setGuard(Headers::ImmutableGuard); |
145 FetchEventInit eventInit; | 145 FetchEventInit eventInit; |
146 eventInit.setCancelable(true); | 146 eventInit.setCancelable(true); |
147 eventInit.setRequest(request); | 147 eventInit.setRequest(request); |
(...skipping 19 matching lines...) Expand all Loading... |
167 | 167 |
168 void ServiceWorkerGlobalScopeProxy::dispatchGeofencingEvent(int eventID, WebGeof
encingEventType eventType, const WebString& regionID, const WebCircularGeofencin
gRegion& region) | 168 void ServiceWorkerGlobalScopeProxy::dispatchGeofencingEvent(int eventID, WebGeof
encingEventType eventType, const WebString& regionID, const WebCircularGeofencin
gRegion& region) |
169 { | 169 { |
170 const AtomicString& type = eventType == WebGeofencingEventTypeEnter ? EventT
ypeNames::geofenceenter : EventTypeNames::geofenceleave; | 170 const AtomicString& type = eventType == WebGeofencingEventTypeEnter ? EventT
ypeNames::geofenceenter : EventTypeNames::geofenceleave; |
171 workerGlobalScope()->dispatchEvent(GeofencingEvent::create(type, regionID, C
ircularGeofencingRegion::create(regionID, region))); | 171 workerGlobalScope()->dispatchEvent(GeofencingEvent::create(type, regionID, C
ircularGeofencingRegion::create(regionID, region))); |
172 } | 172 } |
173 | 173 |
174 void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID) | 174 void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID) |
175 { | 175 { |
176 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Install, eventID); | 176 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Install, eventID); |
177 RawPtr<Event> event; | 177 Event* event; |
178 if (RuntimeEnabledFeatures::foreignFetchEnabled()) | 178 if (RuntimeEnabledFeatures::foreignFetchEnabled()) |
179 event = InstallEvent::create(EventTypeNames::install, ExtendableEventIni
t(), observer); | 179 event = InstallEvent::create(EventTypeNames::install, ExtendableEventIni
t(), observer); |
180 else | 180 else |
181 event = ExtendableEvent::create(EventTypeNames::install, ExtendableEvent
Init(), observer); | 181 event = ExtendableEvent::create(EventTypeNames::install, ExtendableEvent
Init(), observer); |
182 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); | 182 workerGlobalScope()->dispatchExtendableEvent(event, observer); |
183 } | 183 } |
184 | 184 |
185 void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& messag
e, const WebMessagePortChannelArray& webChannels) | 185 void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& messag
e, const WebMessagePortChannelArray& webChannels) |
186 { | 186 { |
187 MessagePortArray* ports = MessagePort::toMessagePortArray(workerGlobalScope(
), webChannels); | 187 MessagePortArray* ports = MessagePort::toMessagePortArray(workerGlobalScope(
), webChannels); |
188 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); | 188 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); |
189 workerGlobalScope()->dispatchEvent(MessageEvent::create(ports, value)); | 189 workerGlobalScope()->dispatchEvent(MessageEvent::create(ports, value)); |
190 } | 190 } |
191 | 191 |
192 void ServiceWorkerGlobalScopeProxy::dispatchNotificationClickEvent(int eventID,
int64_t notificationID, const WebNotificationData& data, int actionIndex) | 192 void ServiceWorkerGlobalScopeProxy::dispatchNotificationClickEvent(int eventID,
int64_t notificationID, const WebNotificationData& data, int actionIndex) |
193 { | 193 { |
194 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::NotificationClick, eventID); | 194 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::NotificationClick, eventID); |
195 NotificationEventInit eventInit; | 195 NotificationEventInit eventInit; |
196 eventInit.setNotification(Notification::create(workerGlobalScope(), notifica
tionID, data, true /* showing */)); | 196 eventInit.setNotification(Notification::create(workerGlobalScope(), notifica
tionID, data, true /* showing */)); |
197 if (0 <= actionIndex && actionIndex < static_cast<int>(data.actions.size())) | 197 if (0 <= actionIndex && actionIndex < static_cast<int>(data.actions.size())) |
198 eventInit.setAction(data.actions[actionIndex].action); | 198 eventInit.setAction(data.actions[actionIndex].action); |
199 RawPtr<Event> event(NotificationEvent::create(EventTypeNames::notificationcl
ick, eventInit, observer)); | 199 Event* event = NotificationEvent::create(EventTypeNames::notificationclick,
eventInit, observer); |
200 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); | 200 workerGlobalScope()->dispatchExtendableEvent(event, observer); |
201 } | 201 } |
202 | 202 |
203 void ServiceWorkerGlobalScopeProxy::dispatchNotificationCloseEvent(int eventID,
int64_t notificationID, const WebNotificationData& data) | 203 void ServiceWorkerGlobalScopeProxy::dispatchNotificationCloseEvent(int eventID,
int64_t notificationID, const WebNotificationData& data) |
204 { | 204 { |
205 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::NotificationClose, eventID); | 205 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::NotificationClose, eventID); |
206 NotificationEventInit eventInit; | 206 NotificationEventInit eventInit; |
207 eventInit.setAction(WTF::String()); // initialize as null. | 207 eventInit.setAction(WTF::String()); // initialize as null. |
208 eventInit.setNotification(Notification::create(workerGlobalScope(), notifica
tionID, data, false /* showing */)); | 208 eventInit.setNotification(Notification::create(workerGlobalScope(), notifica
tionID, data, false /* showing */)); |
209 RawPtr<Event> event(NotificationEvent::create(EventTypeNames::notificationcl
ose, eventInit, observer)); | 209 Event* event = NotificationEvent::create(EventTypeNames::notificationclose,
eventInit, observer); |
210 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); | 210 workerGlobalScope()->dispatchExtendableEvent(event, observer); |
211 } | 211 } |
212 | 212 |
213 void ServiceWorkerGlobalScopeProxy::dispatchPushEvent(int eventID, const WebStri
ng& data) | 213 void ServiceWorkerGlobalScopeProxy::dispatchPushEvent(int eventID, const WebStri
ng& data) |
214 { | 214 { |
215 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Push, eventID); | 215 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Push, eventID); |
216 RawPtr<Event> event(PushEvent::create(EventTypeNames::push, PushMessageData:
:create(data), observer)); | 216 Event* event = PushEvent::create(EventTypeNames::push, PushMessageData::crea
te(data), observer); |
217 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); | 217 workerGlobalScope()->dispatchExtendableEvent(event, observer); |
218 } | 218 } |
219 | 219 |
220 void ServiceWorkerGlobalScopeProxy::dispatchSyncEvent(int eventID, const WebStri
ng& tag, LastChanceOption lastChance) | 220 void ServiceWorkerGlobalScopeProxy::dispatchSyncEvent(int eventID, const WebStri
ng& tag, LastChanceOption lastChance) |
221 { | 221 { |
222 if (!RuntimeEnabledFeatures::backgroundSyncEnabled()) { | 222 if (!RuntimeEnabledFeatures::backgroundSyncEnabled()) { |
223 ServiceWorkerGlobalScopeClient::from(workerGlobalScope())->didHandleSync
Event(eventID, WebServiceWorkerEventResultCompleted); | 223 ServiceWorkerGlobalScopeClient::from(workerGlobalScope())->didHandleSync
Event(eventID, WebServiceWorkerEventResultCompleted); |
224 return; | 224 return; |
225 } | 225 } |
226 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Sync, eventID); | 226 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Sync, eventID); |
227 RawPtr<Event> event(SyncEvent::create(EventTypeNames::sync, tag, lastChance
== IsLastChance, observer)); | 227 Event* event = SyncEvent::create(EventTypeNames::sync, tag, lastChance == Is
LastChance, observer); |
228 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); | 228 workerGlobalScope()->dispatchExtendableEvent(event, observer); |
229 } | 229 } |
230 | 230 |
231 void ServiceWorkerGlobalScopeProxy::reportException(const String& errorMessage,
int lineNumber, int columnNumber, const String& sourceURL, int) | 231 void ServiceWorkerGlobalScopeProxy::reportException(const String& errorMessage,
int lineNumber, int columnNumber, const String& sourceURL, int) |
232 { | 232 { |
233 client().reportException(errorMessage, lineNumber, columnNumber, sourceURL); | 233 client().reportException(errorMessage, lineNumber, columnNumber, sourceURL); |
234 } | 234 } |
235 | 235 |
236 void ServiceWorkerGlobalScopeProxy::reportConsoleMessage(RawPtr<ConsoleMessage>
consoleMessage) | 236 void ServiceWorkerGlobalScopeProxy::reportConsoleMessage(ConsoleMessage* console
Message) |
237 { | 237 { |
238 client().reportConsoleMessage(consoleMessage->source(), consoleMessage->leve
l(), consoleMessage->message(), consoleMessage->lineNumber(), consoleMessage->ur
l()); | 238 client().reportConsoleMessage(consoleMessage->source(), consoleMessage->leve
l(), consoleMessage->message(), consoleMessage->lineNumber(), consoleMessage->ur
l()); |
239 } | 239 } |
240 | 240 |
241 void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector(const String& mes
sage) | 241 void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector(const String& mes
sage) |
242 { | 242 { |
243 DCHECK(m_embeddedWorker); | 243 DCHECK(m_embeddedWorker); |
244 document().postInspectorTask(BLINK_FROM_HERE, createCrossThreadTask(&WebEmbe
ddedWorkerImpl::postMessageToPageInspector, m_embeddedWorker, message)); | 244 document().postInspectorTask(BLINK_FROM_HERE, createCrossThreadTask(&WebEmbe
ddedWorkerImpl::postMessageToPageInspector, m_embeddedWorker, message)); |
245 } | 245 } |
246 | 246 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 return *m_document; | 308 return *m_document; |
309 } | 309 } |
310 | 310 |
311 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() con
st | 311 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() con
st |
312 { | 312 { |
313 DCHECK(m_workerGlobalScope); | 313 DCHECK(m_workerGlobalScope); |
314 return m_workerGlobalScope; | 314 return m_workerGlobalScope; |
315 } | 315 } |
316 | 316 |
317 } // namespace blink | 317 } // namespace blink |
OLD | NEW |