| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 namespace blink { | 75 namespace blink { |
| 76 | 76 |
| 77 RawPtr<ServiceWorkerGlobalScopeProxy> ServiceWorkerGlobalScopeProxy::create(WebE
mbeddedWorkerImpl& embeddedWorker, Document& document, WebServiceWorkerContextCl
ient& client) | 77 RawPtr<ServiceWorkerGlobalScopeProxy> ServiceWorkerGlobalScopeProxy::create(WebE
mbeddedWorkerImpl& embeddedWorker, Document& document, WebServiceWorkerContextCl
ient& client) |
| 78 { | 78 { |
| 79 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client); | 79 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client); |
| 80 } | 80 } |
| 81 | 81 |
| 82 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() | 82 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() |
| 83 { | 83 { |
| 84 // Verify that the proxy has been detached. | 84 // Verify that the proxy has been detached. |
| 85 ASSERT(!m_embeddedWorker); | 85 DCHECK(!m_embeddedWorker); |
| 86 } | 86 } |
| 87 | 87 |
| 88 DEFINE_TRACE(ServiceWorkerGlobalScopeProxy) | 88 DEFINE_TRACE(ServiceWorkerGlobalScopeProxy) |
| 89 { | 89 { |
| 90 visitor->trace(m_document); | 90 visitor->trace(m_document); |
| 91 visitor->trace(m_workerGlobalScope); | 91 visitor->trace(m_workerGlobalScope); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void ServiceWorkerGlobalScopeProxy::setRegistration(WebPassOwnPtr<WebServiceWork
erRegistration::Handle> handle) | 94 void ServiceWorkerGlobalScopeProxy::setRegistration(WebPassOwnPtr<WebServiceWork
erRegistration::Handle> handle) |
| 95 { | 95 { |
| 96 workerGlobalScope()->setRegistration(handle); | 96 workerGlobalScope()->setRegistration(handle); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) | 99 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) |
| 100 { | 100 { |
| 101 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Activate, eventID); | 101 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Activate, eventID); |
| 102 RawPtr<Event> event(ExtendableEvent::create(EventTypeNames::activate, Extend
ableEventInit(), observer)); | 102 RawPtr<Event> event(ExtendableEvent::create(EventTypeNames::activate, Extend
ableEventInit(), observer)); |
| 103 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); | 103 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void ServiceWorkerGlobalScopeProxy::dispatchExtendableMessageEvent(int eventID,
const WebString& message, const WebSecurityOrigin& sourceOrigin, const WebMessag
ePortChannelArray& webChannels, const WebServiceWorkerClientInfo& client) | 106 void ServiceWorkerGlobalScopeProxy::dispatchExtendableMessageEvent(int eventID,
const WebString& message, const WebSecurityOrigin& sourceOrigin, const WebMessag
ePortChannelArray& webChannels, const WebServiceWorkerClientInfo& client) |
| 107 { | 107 { |
| 108 ASSERT(RuntimeEnabledFeatures::serviceWorkerExtendableMessageEventEnabled())
; | 108 DCHECK(RuntimeEnabledFeatures::serviceWorkerExtendableMessageEventEnabled())
; |
| 109 | 109 |
| 110 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); | 110 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); |
| 111 MessagePortArray* ports = MessagePort::toMessagePortArray(m_workerGlobalScop
e, webChannels); | 111 MessagePortArray* ports = MessagePort::toMessagePortArray(m_workerGlobalScop
e, webChannels); |
| 112 String origin; | 112 String origin; |
| 113 if (!sourceOrigin.isUnique()) | 113 if (!sourceOrigin.isUnique()) |
| 114 origin = sourceOrigin.toString(); | 114 origin = sourceOrigin.toString(); |
| 115 ServiceWorkerClient* source = nullptr; | 115 ServiceWorkerClient* source = nullptr; |
| 116 if (client.clientType == WebServiceWorkerClientTypeWindow) | 116 if (client.clientType == WebServiceWorkerClientTypeWindow) |
| 117 source = ServiceWorkerWindowClient::create(client); | 117 source = ServiceWorkerWindowClient::create(client); |
| 118 else | 118 else |
| 119 source = ServiceWorkerClient::create(client); | 119 source = ServiceWorkerClient::create(client); |
| 120 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Message, eventID); | 120 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Message, eventID); |
| 121 | 121 |
| 122 RawPtr<Event> event(ExtendableMessageEvent::create(value, origin, ports, sou
rce, observer)); | 122 RawPtr<Event> event(ExtendableMessageEvent::create(value, origin, ports, sou
rce, observer)); |
| 123 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); | 123 workerGlobalScope()->dispatchExtendableEvent(event.release(), observer); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void ServiceWorkerGlobalScopeProxy::dispatchExtendableMessageEvent(int eventID,
const WebString& message, const WebSecurityOrigin& sourceOrigin, const WebMessag
ePortChannelArray& webChannels, WebPassOwnPtr<WebServiceWorker::Handle> handle) | 126 void ServiceWorkerGlobalScopeProxy::dispatchExtendableMessageEvent(int eventID,
const WebString& message, const WebSecurityOrigin& sourceOrigin, const WebMessag
ePortChannelArray& webChannels, WebPassOwnPtr<WebServiceWorker::Handle> handle) |
| 127 { | 127 { |
| 128 ASSERT(RuntimeEnabledFeatures::serviceWorkerExtendableMessageEventEnabled())
; | 128 DCHECK(RuntimeEnabledFeatures::serviceWorkerExtendableMessageEventEnabled())
; |
| 129 | 129 |
| 130 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); | 130 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); |
| 131 MessagePortArray* ports = MessagePort::toMessagePortArray(m_workerGlobalScop
e, webChannels); | 131 MessagePortArray* ports = MessagePort::toMessagePortArray(m_workerGlobalScop
e, webChannels); |
| 132 String origin; | 132 String origin; |
| 133 if (!sourceOrigin.isUnique()) | 133 if (!sourceOrigin.isUnique()) |
| 134 origin = sourceOrigin.toString(); | 134 origin = sourceOrigin.toString(); |
| 135 ServiceWorker* source = ServiceWorker::from(m_workerGlobalScope->getExecutio
nContext(), handle.release()); | 135 ServiceWorker* source = ServiceWorker::from(m_workerGlobalScope->getExecutio
nContext(), handle.release()); |
| 136 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Message, eventID); | 136 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Message, eventID); |
| 137 | 137 |
| 138 RawPtr<Event> event(ExtendableMessageEvent::create(value, origin, ports, sou
rce, observer)); | 138 RawPtr<Event> event(ExtendableMessageEvent::create(value, origin, ports, sou
rce, observer)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 client().reportException(errorMessage, lineNumber, columnNumber, sourceURL); | 234 client().reportException(errorMessage, lineNumber, columnNumber, sourceURL); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void ServiceWorkerGlobalScopeProxy::reportConsoleMessage(RawPtr<ConsoleMessage>
consoleMessage) | 237 void ServiceWorkerGlobalScopeProxy::reportConsoleMessage(RawPtr<ConsoleMessage>
consoleMessage) |
| 238 { | 238 { |
| 239 client().reportConsoleMessage(consoleMessage->source(), consoleMessage->leve
l(), consoleMessage->message(), consoleMessage->lineNumber(), consoleMessage->ur
l()); | 239 client().reportConsoleMessage(consoleMessage->source(), consoleMessage->leve
l(), consoleMessage->message(), consoleMessage->lineNumber(), consoleMessage->ur
l()); |
| 240 } | 240 } |
| 241 | 241 |
| 242 void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector(const String& mes
sage) | 242 void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector(const String& mes
sage) |
| 243 { | 243 { |
| 244 ASSERT(m_embeddedWorker); | 244 DCHECK(m_embeddedWorker); |
| 245 document().postInspectorTask(BLINK_FROM_HERE, createCrossThreadTask(&WebEmbe
ddedWorkerImpl::postMessageToPageInspector, m_embeddedWorker, message)); | 245 document().postInspectorTask(BLINK_FROM_HERE, createCrossThreadTask(&WebEmbe
ddedWorkerImpl::postMessageToPageInspector, m_embeddedWorker, message)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void ServiceWorkerGlobalScopeProxy::didEvaluateWorkerScript(bool success) | 248 void ServiceWorkerGlobalScopeProxy::didEvaluateWorkerScript(bool success) |
| 249 { | 249 { |
| 250 client().didEvaluateWorkerScript(success); | 250 client().didEvaluateWorkerScript(success); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void ServiceWorkerGlobalScopeProxy::didInitializeWorkerContext() | 253 void ServiceWorkerGlobalScopeProxy::didInitializeWorkerContext() |
| 254 { | 254 { |
| 255 ScriptState::Scope scope(workerGlobalScope()->scriptController()->getScriptS
tate()); | 255 ScriptState::Scope scope(workerGlobalScope()->scriptController()->getScriptS
tate()); |
| 256 client().didInitializeWorkerContext(workerGlobalScope()->scriptController()-
>context()); | 256 client().didInitializeWorkerContext(workerGlobalScope()->scriptController()-
>context()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void ServiceWorkerGlobalScopeProxy::workerGlobalScopeStarted(WorkerGlobalScope*
workerGlobalScope) | 259 void ServiceWorkerGlobalScopeProxy::workerGlobalScopeStarted(WorkerGlobalScope*
workerGlobalScope) |
| 260 { | 260 { |
| 261 ASSERT(!m_workerGlobalScope); | 261 DCHECK(!m_workerGlobalScope); |
| 262 m_workerGlobalScope = static_cast<ServiceWorkerGlobalScope*>(workerGlobalSco
pe); | 262 m_workerGlobalScope = static_cast<ServiceWorkerGlobalScope*>(workerGlobalSco
pe); |
| 263 client().workerContextStarted(this); | 263 client().workerContextStarted(this); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void ServiceWorkerGlobalScopeProxy::workerGlobalScopeClosed() | 266 void ServiceWorkerGlobalScopeProxy::workerGlobalScopeClosed() |
| 267 { | 267 { |
| 268 ASSERT(m_embeddedWorker); | 268 DCHECK(m_embeddedWorker); |
| 269 document().postTask(BLINK_FROM_HERE, createCrossThreadTask(&WebEmbeddedWorke
rImpl::terminateWorkerContext, m_embeddedWorker)); | 269 document().postTask(BLINK_FROM_HERE, createCrossThreadTask(&WebEmbeddedWorke
rImpl::terminateWorkerContext, m_embeddedWorker)); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void ServiceWorkerGlobalScopeProxy::willDestroyWorkerGlobalScope() | 272 void ServiceWorkerGlobalScopeProxy::willDestroyWorkerGlobalScope() |
| 273 { | 273 { |
| 274 v8::HandleScope handleScope(workerGlobalScope()->thread()->isolate()); | 274 v8::HandleScope handleScope(workerGlobalScope()->thread()->isolate()); |
| 275 client().willDestroyWorkerContext(workerGlobalScope()->scriptController()->c
ontext()); | 275 client().willDestroyWorkerContext(workerGlobalScope()->scriptController()->c
ontext()); |
| 276 m_workerGlobalScope = nullptr; | 276 m_workerGlobalScope = nullptr; |
| 277 } | 277 } |
| 278 | 278 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 292 void ServiceWorkerGlobalScopeProxy::detach() | 292 void ServiceWorkerGlobalScopeProxy::detach() |
| 293 { | 293 { |
| 294 m_embeddedWorker = nullptr; | 294 m_embeddedWorker = nullptr; |
| 295 m_document = nullptr; | 295 m_document = nullptr; |
| 296 m_client = nullptr; | 296 m_client = nullptr; |
| 297 m_workerGlobalScope = nullptr; | 297 m_workerGlobalScope = nullptr; |
| 298 } | 298 } |
| 299 | 299 |
| 300 WebServiceWorkerContextClient& ServiceWorkerGlobalScopeProxy::client() const | 300 WebServiceWorkerContextClient& ServiceWorkerGlobalScopeProxy::client() const |
| 301 { | 301 { |
| 302 ASSERT(m_client); | 302 DCHECK(m_client); |
| 303 return *m_client; | 303 return *m_client; |
| 304 } | 304 } |
| 305 | 305 |
| 306 Document& ServiceWorkerGlobalScopeProxy::document() const | 306 Document& ServiceWorkerGlobalScopeProxy::document() const |
| 307 { | 307 { |
| 308 ASSERT(m_document); | 308 DCHECK(m_document); |
| 309 return *m_document; | 309 return *m_document; |
| 310 } | 310 } |
| 311 | 311 |
| 312 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() con
st | 312 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() con
st |
| 313 { | 313 { |
| 314 ASSERT(m_workerGlobalScope); | 314 DCHECK(m_workerGlobalScope); |
| 315 return m_workerGlobalScope; | 315 return m_workerGlobalScope; |
| 316 } | 316 } |
| 317 | 317 |
| 318 void ServiceWorkerGlobalScopeProxy::dispatchFetchEventImpl(int eventID, const We
bServiceWorkerRequest& webRequest, const AtomicString& eventTypeName) | 318 void ServiceWorkerGlobalScopeProxy::dispatchFetchEventImpl(int eventID, const We
bServiceWorkerRequest& webRequest, const AtomicString& eventTypeName) |
| 319 { | 319 { |
| 320 RespondWithObserver* observer = RespondWithObserver::create(workerGlobalScop
e(), eventID, webRequest.url(), webRequest.mode(), webRequest.frameType(), webRe
quest.requestContext()); | 320 RespondWithObserver* observer = RespondWithObserver::create(workerGlobalScop
e(), eventID, webRequest.url(), webRequest.mode(), webRequest.frameType(), webRe
quest.requestContext()); |
| 321 Request* request = Request::create(workerGlobalScope(), webRequest); | 321 Request* request = Request::create(workerGlobalScope(), webRequest); |
| 322 request->getHeaders()->setGuard(Headers::ImmutableGuard); | 322 request->getHeaders()->setGuard(Headers::ImmutableGuard); |
| 323 FetchEventInit eventInit; | 323 FetchEventInit eventInit; |
| 324 eventInit.setCancelable(true); | 324 eventInit.setCancelable(true); |
| 325 eventInit.setRequest(request); | 325 eventInit.setRequest(request); |
| 326 eventInit.setClientId(webRequest.isMainResourceLoad() ? WebString() : webReq
uest.clientId()); | 326 eventInit.setClientId(webRequest.isMainResourceLoad() ? WebString() : webReq
uest.clientId()); |
| 327 eventInit.setIsReload(webRequest.isReload()); | 327 eventInit.setIsReload(webRequest.isReload()); |
| 328 RawPtr<FetchEvent> fetchEvent(FetchEvent::create(eventTypeName, eventInit, o
bserver)); | 328 RawPtr<FetchEvent> fetchEvent(FetchEvent::create(eventTypeName, eventInit, o
bserver)); |
| 329 DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetc
hEvent.release()); | 329 DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetc
hEvent.release()); |
| 330 observer->didDispatchEvent(dispatchResult); | 330 observer->didDispatchEvent(dispatchResult); |
| 331 } | 331 } |
| 332 | 332 |
| 333 } // namespace blink | 333 } // namespace blink |
| OLD | NEW |