| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "web/ServiceWorkerGlobalScopeProxy.h" | 31 #include "web/ServiceWorkerGlobalScopeProxy.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/SourceLocation.h" | 33 #include "bindings/core/v8/SourceLocation.h" |
| 34 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 34 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 35 #include "core/dom/CrossThreadTask.h" | 35 #include "core/dom/CrossThreadTask.h" |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/dom/ExecutionContext.h" | 37 #include "core/dom/ExecutionContext.h" |
| 38 #include "core/dom/MessagePort.h" | 38 #include "core/dom/MessagePort.h" |
| 39 #include "core/inspector/ConsoleMessage.h" | 39 #include "core/inspector/ConsoleMessage.h" |
| 40 #include "core/origin_trials/OriginTrials.h" |
| 40 #include "core/workers/WorkerGlobalScope.h" | 41 #include "core/workers/WorkerGlobalScope.h" |
| 41 #include "core/workers/WorkerThread.h" | 42 #include "core/workers/WorkerThread.h" |
| 42 #include "modules/background_sync/SyncEvent.h" | 43 #include "modules/background_sync/SyncEvent.h" |
| 43 #include "modules/fetch/Headers.h" | 44 #include "modules/fetch/Headers.h" |
| 44 #include "modules/notifications/Notification.h" | 45 #include "modules/notifications/Notification.h" |
| 45 #include "modules/notifications/NotificationEvent.h" | 46 #include "modules/notifications/NotificationEvent.h" |
| 46 #include "modules/notifications/NotificationEventInit.h" | 47 #include "modules/notifications/NotificationEventInit.h" |
| 47 #include "modules/push_messaging/PushEvent.h" | 48 #include "modules/push_messaging/PushEvent.h" |
| 48 #include "modules/push_messaging/PushMessageData.h" | 49 #include "modules/push_messaging/PushMessageData.h" |
| 49 #include "modules/serviceworkers/ExtendableEvent.h" | 50 #include "modules/serviceworkers/ExtendableEvent.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 waitUntilObserver->willDispatchEvent(); | 148 waitUntilObserver->willDispatchEvent(); |
| 148 DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetc
hEvent); | 149 DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetc
hEvent); |
| 149 respondWithObserver->didDispatchEvent(dispatchResult); | 150 respondWithObserver->didDispatchEvent(dispatchResult); |
| 150 // false is okay because waitUntil for fetch event doesn't care about the | 151 // false is okay because waitUntil for fetch event doesn't care about the |
| 151 // promise rejection or an uncaught runtime script error. | 152 // promise rejection or an uncaught runtime script error. |
| 152 waitUntilObserver->didDispatchEvent(false /* errorOccurred */); | 153 waitUntilObserver->didDispatchEvent(false /* errorOccurred */); |
| 153 } | 154 } |
| 154 | 155 |
| 155 void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent(int responseID, in
t eventFinishID, const WebServiceWorkerRequest& webRequest) | 156 void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent(int responseID, in
t eventFinishID, const WebServiceWorkerRequest& webRequest) |
| 156 { | 157 { |
| 158 if (!OriginTrials::foreignFetchEnabled(workerGlobalScope())) { |
| 159 // If origin trial tokens have expired, or are otherwise no longer valid |
| 160 // no events should be dispatched. |
| 161 // TODO(mek): Ideally the browser wouldn't even start the service worker |
| 162 // if its tokens have expired. |
| 163 ServiceWorkerGlobalScopeClient::from(workerGlobalScope())->respondToFetc
hEvent(responseID); |
| 164 ServiceWorkerGlobalScopeClient::from(workerGlobalScope())->didHandleFetc
hEvent(eventFinishID, WebServiceWorkerEventResultCompleted); |
| 165 return; |
| 166 } |
| 167 |
| 157 ScriptState::Scope scope(workerGlobalScope()->scriptController()->getScriptS
tate()); | 168 ScriptState::Scope scope(workerGlobalScope()->scriptController()->getScriptS
tate()); |
| 158 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(webRequest.referrerUr
l()); | 169 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(webRequest.referrerUr
l()); |
| 159 WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create(workerGloba
lScope(), WaitUntilObserver::Fetch, eventFinishID); | 170 WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create(workerGloba
lScope(), WaitUntilObserver::Fetch, eventFinishID); |
| 160 ForeignFetchRespondWithObserver* respondWithObserver = ForeignFetchRespondWi
thObserver::create(workerGlobalScope(), responseID, webRequest.url(), webRequest
.mode(), webRequest.frameType(), webRequest.requestContext(), origin, waitUntilO
bserver); | 171 ForeignFetchRespondWithObserver* respondWithObserver = ForeignFetchRespondWi
thObserver::create(workerGlobalScope(), responseID, webRequest.url(), webRequest
.mode(), webRequest.frameType(), webRequest.requestContext(), origin, waitUntilO
bserver); |
| 161 Request* request = Request::create(workerGlobalScope()->scriptController()->
getScriptState(), webRequest); | 172 Request* request = Request::create(workerGlobalScope()->scriptController()->
getScriptState(), webRequest); |
| 162 request->getHeaders()->setGuard(Headers::ImmutableGuard); | 173 request->getHeaders()->setGuard(Headers::ImmutableGuard); |
| 163 ForeignFetchEventInit eventInit; | 174 ForeignFetchEventInit eventInit; |
| 164 eventInit.setCancelable(true); | 175 eventInit.setCancelable(true); |
| 165 eventInit.setRequest(request); | 176 eventInit.setRequest(request); |
| 166 eventInit.setOrigin(origin->toString()); | 177 eventInit.setOrigin(origin->toString()); |
| 167 ForeignFetchEvent* fetchEvent = ForeignFetchEvent::create(workerGlobalScope(
)->scriptController()->getScriptState(), EventTypeNames::foreignfetch, eventInit
, respondWithObserver, waitUntilObserver); | 178 ForeignFetchEvent* fetchEvent = ForeignFetchEvent::create(workerGlobalScope(
)->scriptController()->getScriptState(), EventTypeNames::foreignfetch, eventInit
, respondWithObserver, waitUntilObserver); |
| 168 waitUntilObserver->willDispatchEvent(); | 179 waitUntilObserver->willDispatchEvent(); |
| 169 DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetc
hEvent); | 180 DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetc
hEvent); |
| 170 respondWithObserver->didDispatchEvent(dispatchResult); | 181 respondWithObserver->didDispatchEvent(dispatchResult); |
| 171 // false is okay because waitUntil for foreign fetch event doesn't care | 182 // false is okay because waitUntil for foreign fetch event doesn't care |
| 172 // about the promise rejection or an uncaught runtime script error. | 183 // about the promise rejection or an uncaught runtime script error. |
| 173 waitUntilObserver->didDispatchEvent(false /* errorOccurred */); | 184 waitUntilObserver->didDispatchEvent(false /* errorOccurred */); |
| 174 } | 185 } |
| 175 | 186 |
| 176 void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID) | 187 void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID) |
| 177 { | 188 { |
| 178 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Install, eventID); | 189 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::Install, eventID); |
| 179 Event* event; | 190 Event* event; |
| 180 if (RuntimeEnabledFeatures::foreignFetchEnabled()) | 191 if (OriginTrials::foreignFetchEnabled(workerGlobalScope())) |
| 181 event = InstallEvent::create(EventTypeNames::install, ExtendableEventIni
t(), observer); | 192 event = InstallEvent::create(EventTypeNames::install, ExtendableEventIni
t(), observer); |
| 182 else | 193 else |
| 183 event = ExtendableEvent::create(EventTypeNames::install, ExtendableEvent
Init(), observer); | 194 event = ExtendableEvent::create(EventTypeNames::install, ExtendableEvent
Init(), observer); |
| 184 workerGlobalScope()->dispatchExtendableEvent(event, observer); | 195 workerGlobalScope()->dispatchExtendableEvent(event, observer); |
| 185 } | 196 } |
| 186 | 197 |
| 187 void ServiceWorkerGlobalScopeProxy::dispatchNotificationClickEvent(int eventID,
int64_t notificationID, const WebNotificationData& data, int actionIndex) | 198 void ServiceWorkerGlobalScopeProxy::dispatchNotificationClickEvent(int eventID,
int64_t notificationID, const WebNotificationData& data, int actionIndex) |
| 188 { | 199 { |
| 189 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::NotificationClick, eventID); | 200 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(),
WaitUntilObserver::NotificationClick, eventID); |
| 190 NotificationEventInit eventInit; | 201 NotificationEventInit eventInit; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 return *m_document; | 321 return *m_document; |
| 311 } | 322 } |
| 312 | 323 |
| 313 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() con
st | 324 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() con
st |
| 314 { | 325 { |
| 315 DCHECK(m_workerGlobalScope); | 326 DCHECK(m_workerGlobalScope); |
| 316 return m_workerGlobalScope; | 327 return m_workerGlobalScope; |
| 317 } | 328 } |
| 318 | 329 |
| 319 } // namespace blink | 330 } // namespace blink |
| OLD | NEW |