Commit faa6203e authored by jungkee.song's avatar jungkee.song Committed by Commit bot

Deprecate ServiceWorkerMessageEvent in favor of MessageEvent

This extends MessageEvent to allow ServiceWorker as a type of source
attribute according to the changes in HTML and replaces the existing
ServiceWorkerMessageEvent code usage with this extended MessageEvent.

Related spec issue: https://github.com/w3c/ServiceWorker/issues/989
Related spec change:
 - HTML: https://github.com/whatwg/html/pull/1944
 - SW: https://github.com/w3c/ServiceWorker/commit/6c68bd87bdfd153186a5b9904e31676c56730e2f
Related WPT: https://github.com/w3c/web-platform-tests/pull/4186

Intent to Deprecate and Remove: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/Xp9hmKyuOrI

BUG=659074

Review-Url: https://codereview.chromium.org/2466513002
Cr-Commit-Position: refs/heads/master@{#438545}
parent 45369974
...@@ -4436,13 +4436,6 @@ interface ServiceWorkerContainer : EventTarget ...@@ -4436,13 +4436,6 @@ interface ServiceWorkerContainer : EventTarget
method register method register
setter oncontrollerchange setter oncontrollerchange
setter onmessage setter onmessage
interface ServiceWorkerMessageEvent : Event
getter data
getter lastEventId
getter origin
getter ports
getter source
method constructor
interface ServiceWorkerRegistration : EventTarget interface ServiceWorkerRegistration : EventTarget
getter onupdatefound getter onupdatefound
getter scope getter scope
......
...@@ -25,16 +25,26 @@ promise_test(t => { ...@@ -25,16 +25,26 @@ promise_test(t => {
}) })
.then(e => { .then(e => {
var message = e.data; var message = e.data;
assert_equals(e.origin, location.origin, assert_equals(e.constructor, w.MessageEvent,
'origin of message should be origin of Service Worker'); 'message events should use MessageEvent interface.');
assert_equals(e.type, 'message', 'type should be "message".');
assert_equals(
e.origin, location.origin,
'origin of message should be origin of Service Worker.');
assert_equals(e.lastEventId, '', assert_equals(e.lastEventId, '',
'lastEventId should be an empty string'); 'lastEventId should be an empty string.');
assert_equals(e.source.constructor, w.ServiceWorker,
'source should use ServiceWorker interface.');
assert_equals(
e.source, w.navigator.serviceWorker.controller,
'source should be the service worker that sent the message.');
assert_equals(e.ports.length, 0, 'ports should be an empty array.');
assert_equals(message, 'Sending message via clients'); assert_equals(message, 'Sending message via clients');
return new Promise(resolve => { return new Promise(resolve => {
w.navigator.serviceWorker.onmessage = resolve; w.navigator.serviceWorker.onmessage = resolve;
}); });
}) })
.then(e => { assert_equals(e.data, 'quit'); }); .then(e => { assert_equals(e.data, 'quit'); });
}, 'postMessage from ServiceWorker to Client'); }, 'postMessage from ServiceWorker to Client.');
</script> </script>
<!DOCTYPE html>
<title>Service Worker: ServiceWorkerMessageEvent</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<script>
promise_test(function(t) {
var scope = 'resources/blank.html';
var url = 'resources/postmessage-to-client-worker.js';
return service_worker_unregister_and_register(t, url, scope)
.then(function(r) {
return wait_for_state(t, r.installing, 'activated');
})
.then(function() {
return with_iframe(scope);
})
.then(function(frame) {
var w = frame.contentWindow;
var worker = w.navigator.serviceWorker.controller;
// Test constructor with ServiceWorker object as source.
var e = new ServiceWorkerMessageEvent('eventType', {source: worker});
assert_equals(e.source, worker,
'Source should equal to the passing service worker');
return new Promise(function(resolve) {
w.navigator.serviceWorker.onmessage = t.step_func(function(e) {
assert_true(e instanceof w.ServiceWorkerMessageEvent);
assert_true(e.source instanceof w.ServiceWorker);
assert_equals(e.type, 'message');
assert_equals(e.source, worker,
'Source worker should equal to the controller');
assert_equals(e.ports.length, 0);
resolve();
});
worker.postMessage('PING');
});
})
.then(function() {
return service_worker_unregister_and_done(t, scope);
});
}, 'Test ServiceWorkerMessageEvent type.');
</script>
...@@ -10,7 +10,7 @@ FAIL [[GetOwnProperty]] - Property descriptors for cross-origin properties shoul ...@@ -10,7 +10,7 @@ FAIL [[GetOwnProperty]] - Property descriptors for cross-origin properties shoul
FAIL [[Delete]] Should throw on cross-origin objects assert_throws: Can't delete cross-origin indexed property function "function () { delete C[0]; }" did not throw FAIL [[Delete]] Should throw on cross-origin objects assert_throws: Can't delete cross-origin indexed property function "function () { delete C[0]; }" did not throw
FAIL [[DefineOwnProperty]] Should throw for cross-origin objects assert_throws: Can't define cross-origin value property length function "function () { Object.defineProperty(obj, prop, valueDesc); }" did not throw FAIL [[DefineOwnProperty]] Should throw for cross-origin objects assert_throws: Can't define cross-origin value property length function "function () { Object.defineProperty(obj, prop, valueDesc); }" did not throw
FAIL [[Enumerate]] should return an empty iterator assert_unreached: Shouldn't have been able to enumerate stop on cross-origin Window Reached unreachable code FAIL [[Enumerate]] should return an empty iterator assert_unreached: Shouldn't have been able to enumerate stop on cross-origin Window Reached unreachable code
FAIL [[OwnPropertyKeys]] should return all properties from cross-origin objects assert_array_equals: Object.getOwnPropertyNames() gives the right answer for cross-origin Window lengths differ, expected 862 got 13 FAIL [[OwnPropertyKeys]] should return all properties from cross-origin objects assert_array_equals: Object.getOwnPropertyNames() gives the right answer for cross-origin Window lengths differ, expected 861 got 13
PASS A and B jointly observe the same identity for cross-origin Window and Location PASS A and B jointly observe the same identity for cross-origin Window and Location
PASS Cross-origin functions get local Function.prototype PASS Cross-origin functions get local Function.prototype
FAIL Cross-origin Window accessors get local Function.prototype Cannot read property 'name' of undefined FAIL Cross-origin Window accessors get local Function.prototype Cannot read property 'name' of undefined
......
...@@ -5307,14 +5307,6 @@ interface ServiceWorkerContainer : EventTarget ...@@ -5307,14 +5307,6 @@ interface ServiceWorkerContainer : EventTarget
method register method register
setter oncontrollerchange setter oncontrollerchange
setter onmessage setter onmessage
interface ServiceWorkerMessageEvent : Event
attribute @@toStringTag
getter data
getter lastEventId
getter origin
getter ports
getter source
method constructor
interface ServiceWorkerRegistration : EventTarget interface ServiceWorkerRegistration : EventTarget
attribute @@toStringTag attribute @@toStringTag
getter active getter active
......
...@@ -5365,14 +5365,6 @@ interface ServiceWorkerContainer : EventTarget ...@@ -5365,14 +5365,6 @@ interface ServiceWorkerContainer : EventTarget
method register method register
setter oncontrollerchange setter oncontrollerchange
setter onmessage setter onmessage
interface ServiceWorkerMessageEvent : Event
attribute @@toStringTag
getter data
getter lastEventId
getter origin
getter ports
getter source
method constructor
interface ServiceWorkerRegistration : EventTarget interface ServiceWorkerRegistration : EventTarget
attribute @@toStringTag attribute @@toStringTag
getter active getter active
......
...@@ -6258,14 +6258,6 @@ interface ServiceWorkerContainer : EventTarget ...@@ -6258,14 +6258,6 @@ interface ServiceWorkerContainer : EventTarget
method register method register
setter oncontrollerchange setter oncontrollerchange
setter onmessage setter onmessage
interface ServiceWorkerMessageEvent : Event
attribute @@toStringTag
getter data
getter lastEventId
getter origin
getter ports
getter source
method constructor
interface ServiceWorkerRegistration : EventTarget interface ServiceWorkerRegistration : EventTarget
attribute @@toStringTag attribute @@toStringTag
getter active getter active
......
...@@ -110,7 +110,7 @@ void V8MessageEvent::initMessageEventMethodCustom( ...@@ -110,7 +110,7 @@ void V8MessageEvent::initMessageEventMethodCustom(
v8::Local<v8::Value> dataArg = info[3]; v8::Local<v8::Value> dataArg = info[3];
TOSTRING_VOID(V8StringResource<>, originArg, info[4]); TOSTRING_VOID(V8StringResource<>, originArg, info[4]);
TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]); TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]);
DOMWindow* sourceArg = toDOMWindow(info.GetIsolate(), info[6]); EventTarget* sourceArg = toEventTarget(info.GetIsolate(), info[6]);
MessagePortArray* portArray = nullptr; MessagePortArray* portArray = nullptr;
const int portArrayIndex = 7; const int portArrayIndex = 7;
if (!isUndefinedOrNull(info[portArrayIndex])) { if (!isUndefinedOrNull(info[portArrayIndex])) {
......
...@@ -45,7 +45,6 @@ generate_event_interfaces("modules_bindings_generated_event_interfaces") { ...@@ -45,7 +45,6 @@ generate_event_interfaces("modules_bindings_generated_event_interfaces") {
"//third_party/WebKit/Source/modules/serviceworkers/FetchEvent.idl", "//third_party/WebKit/Source/modules/serviceworkers/FetchEvent.idl",
"//third_party/WebKit/Source/modules/serviceworkers/ForeignFetchEvent.idl", "//third_party/WebKit/Source/modules/serviceworkers/ForeignFetchEvent.idl",
"//third_party/WebKit/Source/modules/serviceworkers/InstallEvent.idl", "//third_party/WebKit/Source/modules/serviceworkers/InstallEvent.idl",
"//third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerMessageEvent.idl",
"//third_party/WebKit/Source/modules/speech/SpeechRecognitionError.idl", "//third_party/WebKit/Source/modules/speech/SpeechRecognitionError.idl",
"//third_party/WebKit/Source/modules/speech/SpeechRecognitionEvent.idl", "//third_party/WebKit/Source/modules/speech/SpeechRecognitionEvent.idl",
"//third_party/WebKit/Source/modules/speech/SpeechSynthesisEvent.idl", "//third_party/WebKit/Source/modules/speech/SpeechSynthesisEvent.idl",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "bindings/modules/v8/V8ServiceWorkerMessageEvent.h"
#include "bindings/modules/v8/V8ServiceWorkerMessageEventInit.h"
#include "bindings/modules/v8/V8ServiceWorkerMessageEventInternal.h"
namespace blink {
void V8ServiceWorkerMessageEvent::constructorCustom(
const v8::FunctionCallbackInfo<v8::Value>& info) {
V8ServiceWorkerMessageEventInternal::constructorCustom<
ServiceWorkerMessageEvent, ServiceWorkerMessageEventInit>(info);
}
void V8ServiceWorkerMessageEvent::dataAttributeGetterCustom(
const v8::FunctionCallbackInfo<v8::Value>& info) {
V8ServiceWorkerMessageEventInternal::dataAttributeGetterCustom<
ServiceWorkerMessageEvent>(info);
}
} // namespace blink
...@@ -10,7 +10,6 @@ bindings_modules_v8_custom_files = ...@@ -10,7 +10,6 @@ bindings_modules_v8_custom_files =
"V8ExtendableMessageEventCustom.cpp", "V8ExtendableMessageEventCustom.cpp",
"V8IDBObserverCustom.cpp", "V8IDBObserverCustom.cpp",
"V8RemotePlaybackCustom.cpp", "V8RemotePlaybackCustom.cpp",
"V8ServiceWorkerMessageEventCustom.cpp",
"V8WebGLRenderingContextCustom.cpp", "V8WebGLRenderingContextCustom.cpp",
"V8WebGL2RenderingContextCustom.cpp", "V8WebGL2RenderingContextCustom.cpp",
], ],
......
...@@ -46,8 +46,6 @@ bindings_modules_generated_union_type_files = [ ...@@ -46,8 +46,6 @@ bindings_modules_generated_union_type_files = [
"$bindings_modules_v8_output_dir/RenderingContext.h", "$bindings_modules_v8_output_dir/RenderingContext.h",
"$bindings_modules_v8_output_dir/RequestOrUSVString.cpp", "$bindings_modules_v8_output_dir/RequestOrUSVString.cpp",
"$bindings_modules_v8_output_dir/RequestOrUSVString.h", "$bindings_modules_v8_output_dir/RequestOrUSVString.h",
"$bindings_modules_v8_output_dir/ServiceWorkerOrMessagePort.cpp",
"$bindings_modules_v8_output_dir/ServiceWorkerOrMessagePort.h",
"$bindings_modules_v8_output_dir/StringOrArrayBufferOrNFCMessage.cpp", "$bindings_modules_v8_output_dir/StringOrArrayBufferOrNFCMessage.cpp",
"$bindings_modules_v8_output_dir/StringOrArrayBufferOrNFCMessage.h", "$bindings_modules_v8_output_dir/StringOrArrayBufferOrNFCMessage.h",
"$bindings_modules_v8_output_dir/StringOrCanvasGradientOrCanvasPattern.cpp", "$bindings_modules_v8_output_dir/StringOrCanvasGradientOrCanvasPattern.cpp",
......
...@@ -173,6 +173,10 @@ MessagePort* EventTarget::toMessagePort() { ...@@ -173,6 +173,10 @@ MessagePort* EventTarget::toMessagePort() {
return nullptr; return nullptr;
} }
ServiceWorker* EventTarget::toServiceWorker() {
return nullptr;
}
inline LocalDOMWindow* EventTarget::executingWindow() { inline LocalDOMWindow* EventTarget::executingWindow() {
if (ExecutionContext* context = getExecutionContext()) if (ExecutionContext* context = getExecutionContext())
return context->executingWindow(); return context->executingWindow();
......
...@@ -56,6 +56,7 @@ class LocalDOMWindow; ...@@ -56,6 +56,7 @@ class LocalDOMWindow;
class ExceptionState; class ExceptionState;
class MessagePort; class MessagePort;
class Node; class Node;
class ServiceWorker;
struct FiringEventIterator { struct FiringEventIterator {
DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
...@@ -119,6 +120,7 @@ class CORE_EXPORT EventTarget : public GarbageCollectedFinalized<EventTarget>, ...@@ -119,6 +120,7 @@ class CORE_EXPORT EventTarget : public GarbageCollectedFinalized<EventTarget>,
virtual const LocalDOMWindow* toLocalDOMWindow() const; virtual const LocalDOMWindow* toLocalDOMWindow() const;
virtual LocalDOMWindow* toLocalDOMWindow(); virtual LocalDOMWindow* toLocalDOMWindow();
virtual MessagePort* toMessagePort(); virtual MessagePort* toMessagePort();
virtual ServiceWorker* toServiceWorker();
bool addEventListener(const AtomicString& eventType, bool addEventListener(const AtomicString& eventType,
EventListener*, EventListener*,
......
...@@ -36,7 +36,8 @@ ...@@ -36,7 +36,8 @@
namespace blink { namespace blink {
static inline bool isValidSource(EventTarget* source) { static inline bool isValidSource(EventTarget* source) {
return !source || source->toLocalDOMWindow() || source->toMessagePort(); return !source || source->toLocalDOMWindow() || source->toMessagePort() ||
source->toServiceWorker();
} }
MessageEvent::MessageEvent() : m_dataType(DataTypeScriptValue) {} MessageEvent::MessageEvent() : m_dataType(DataTypeScriptValue) {}
...@@ -155,7 +156,7 @@ void MessageEvent::initMessageEvent(const AtomicString& type, ...@@ -155,7 +156,7 @@ void MessageEvent::initMessageEvent(const AtomicString& type,
ScriptValue data, ScriptValue data,
const String& origin, const String& origin,
const String& lastEventId, const String& lastEventId,
DOMWindow* source, EventTarget* source,
MessagePortArray* ports) { MessagePortArray* ports) {
if (isBeingDispatched()) if (isBeingDispatched())
return; return;
...@@ -177,7 +178,7 @@ void MessageEvent::initMessageEvent(const AtomicString& type, ...@@ -177,7 +178,7 @@ void MessageEvent::initMessageEvent(const AtomicString& type,
PassRefPtr<SerializedScriptValue> data, PassRefPtr<SerializedScriptValue> data,
const String& origin, const String& origin,
const String& lastEventId, const String& lastEventId,
DOMWindow* source, EventTarget* source,
MessagePortArray* ports) { MessagePortArray* ports) {
if (isBeingDispatched()) if (isBeingDispatched())
return; return;
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "core/events/EventTarget.h" #include "core/events/EventTarget.h"
#include "core/events/MessageEventInit.h" #include "core/events/MessageEventInit.h"
#include "core/fileapi/Blob.h" #include "core/fileapi/Blob.h"
#include "core/frame/DOMWindow.h"
#include "wtf/Compiler.h" #include "wtf/Compiler.h"
#include <memory> #include <memory>
...@@ -99,7 +98,7 @@ class CORE_EXPORT MessageEvent final : public Event { ...@@ -99,7 +98,7 @@ class CORE_EXPORT MessageEvent final : public Event {
ScriptValue data, ScriptValue data,
const String& origin, const String& origin,
const String& lastEventId, const String& lastEventId,
DOMWindow* source, EventTarget* source,
MessagePortArray*); MessagePortArray*);
void initMessageEvent(const AtomicString& type, void initMessageEvent(const AtomicString& type,
bool canBubble, bool canBubble,
...@@ -107,7 +106,7 @@ class CORE_EXPORT MessageEvent final : public Event { ...@@ -107,7 +106,7 @@ class CORE_EXPORT MessageEvent final : public Event {
PassRefPtr<SerializedScriptValue> data, PassRefPtr<SerializedScriptValue> data,
const String& origin, const String& origin,
const String& lastEventId, const String& lastEventId,
DOMWindow* source, EventTarget* source,
MessagePortArray*); MessagePortArray*);
const String& origin() const { return m_origin; } const String& origin() const { return m_origin; }
......
...@@ -49,6 +49,6 @@ ...@@ -49,6 +49,6 @@
[Default=Undefined] optional any dataArg, [Default=Undefined] optional any dataArg,
[Default=Undefined] optional DOMString originArg, [Default=Undefined] optional DOMString originArg,
[Default=Undefined] optional DOMString lastEventIdArg, [Default=Undefined] optional DOMString lastEventIdArg,
[Default=Undefined] optional Window sourceArg, [Default=Undefined] optional EventTarget sourceArg,
[Default=Undefined] optional sequence<MessagePort> portsArg); [Default=Undefined] optional sequence<MessagePort> portsArg);
}; };
...@@ -242,7 +242,6 @@ modules_idl_files = ...@@ -242,7 +242,6 @@ modules_idl_files =
"serviceworkers/ServiceWorker.idl", "serviceworkers/ServiceWorker.idl",
"serviceworkers/ServiceWorkerContainer.idl", "serviceworkers/ServiceWorkerContainer.idl",
"serviceworkers/ServiceWorkerGlobalScope.idl", "serviceworkers/ServiceWorkerGlobalScope.idl",
"serviceworkers/ServiceWorkerMessageEvent.idl",
"serviceworkers/ServiceWorkerRegistration.idl", "serviceworkers/ServiceWorkerRegistration.idl",
"serviceworkers/WindowClient.idl", "serviceworkers/WindowClient.idl",
"shapedetection/BarcodeDetector.idl", "shapedetection/BarcodeDetector.idl",
...@@ -493,7 +492,6 @@ modules_dictionary_idl_files = ...@@ -493,7 +492,6 @@ modules_dictionary_idl_files =
"serviceworkers/ForeignFetchResponse.idl", "serviceworkers/ForeignFetchResponse.idl",
"serviceworkers/NavigationPreloadState.idl", "serviceworkers/NavigationPreloadState.idl",
"serviceworkers/RegistrationOptions.idl", "serviceworkers/RegistrationOptions.idl",
"serviceworkers/ServiceWorkerMessageEventInit.idl",
"shapedetection/FaceDetectorOptions.idl", "shapedetection/FaceDetectorOptions.idl",
"speech/SpeechRecognitionErrorInit.idl", "speech/SpeechRecognitionErrorInit.idl",
"speech/SpeechRecognitionEventInit.idl", "speech/SpeechRecognitionEventInit.idl",
...@@ -870,8 +868,6 @@ generated_modules_dictionary_files = [ ...@@ -870,8 +868,6 @@ generated_modules_dictionary_files = [
"$blink_modules_output_dir/serviceworkers/NavigationPreloadState.h", "$blink_modules_output_dir/serviceworkers/NavigationPreloadState.h",
"$blink_modules_output_dir/serviceworkers/RegistrationOptions.cpp", "$blink_modules_output_dir/serviceworkers/RegistrationOptions.cpp",
"$blink_modules_output_dir/serviceworkers/RegistrationOptions.h", "$blink_modules_output_dir/serviceworkers/RegistrationOptions.h",
"$blink_modules_output_dir/serviceworkers/ServiceWorkerMessageEventInit.cpp",
"$blink_modules_output_dir/serviceworkers/ServiceWorkerMessageEventInit.h",
"$blink_modules_output_dir/shapedetection/FaceDetectorOptions.cpp", "$blink_modules_output_dir/shapedetection/FaceDetectorOptions.cpp",
"$blink_modules_output_dir/shapedetection/FaceDetectorOptions.h", "$blink_modules_output_dir/shapedetection/FaceDetectorOptions.h",
"$blink_modules_output_dir/speech/SpeechRecognitionErrorInit.cpp", "$blink_modules_output_dir/speech/SpeechRecognitionErrorInit.cpp",
......
...@@ -44,8 +44,6 @@ blink_modules_sources("serviceworkers") { ...@@ -44,8 +44,6 @@ blink_modules_sources("serviceworkers") {
"ServiceWorkerGlobalScopeClient.h", "ServiceWorkerGlobalScopeClient.h",
"ServiceWorkerLinkResource.cpp", "ServiceWorkerLinkResource.cpp",
"ServiceWorkerLinkResource.h", "ServiceWorkerLinkResource.h",
"ServiceWorkerMessageEvent.cpp",
"ServiceWorkerMessageEvent.h",
"ServiceWorkerRegistration.cpp", "ServiceWorkerRegistration.cpp",
"ServiceWorkerRegistration.h", "ServiceWorkerRegistration.h",
"ServiceWorkerScriptCachedMetadataHandler.cpp", "ServiceWorkerScriptCachedMetadataHandler.cpp",
......
...@@ -69,6 +69,8 @@ class MODULES_EXPORT ServiceWorker final : public AbstractWorker, ...@@ -69,6 +69,8 @@ class MODULES_EXPORT ServiceWorker final : public AbstractWorker,
String state() const; String state() const;
DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange);
ServiceWorker* toServiceWorker() override { return this; }
// ScriptWrappable overrides. // ScriptWrappable overrides.
bool hasPendingActivity() const final; bool hasPendingActivity() const final;
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "core/dom/ExceptionCode.h" #include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h" #include "core/dom/ExecutionContext.h"
#include "core/dom/MessagePort.h" #include "core/dom/MessagePort.h"
#include "core/events/MessageEvent.h"
#include "core/frame/LocalDOMWindow.h" #include "core/frame/LocalDOMWindow.h"
#include "core/frame/UseCounter.h" #include "core/frame/UseCounter.h"
#include "core/frame/csp/ContentSecurityPolicy.h" #include "core/frame/csp/ContentSecurityPolicy.h"
...@@ -49,7 +50,6 @@ ...@@ -49,7 +50,6 @@
#include "modules/serviceworkers/ServiceWorker.h" #include "modules/serviceworkers/ServiceWorker.h"
#include "modules/serviceworkers/ServiceWorkerContainerClient.h" #include "modules/serviceworkers/ServiceWorkerContainerClient.h"
#include "modules/serviceworkers/ServiceWorkerError.h" #include "modules/serviceworkers/ServiceWorkerError.h"
#include "modules/serviceworkers/ServiceWorkerMessageEvent.h"
#include "modules/serviceworkers/ServiceWorkerRegistration.h" #include "modules/serviceworkers/ServiceWorkerRegistration.h"
#include "platform/RuntimeEnabledFeatures.h" #include "platform/RuntimeEnabledFeatures.h"
#include "platform/weborigin/SchemeRegistry.h" #include "platform/weborigin/SchemeRegistry.h"
...@@ -454,9 +454,9 @@ void ServiceWorkerContainer::dispatchMessageEvent( ...@@ -454,9 +454,9 @@ void ServiceWorkerContainer::dispatchMessageEvent(
RefPtr<SerializedScriptValue> value = SerializedScriptValue::create(message); RefPtr<SerializedScriptValue> value = SerializedScriptValue::create(message);
ServiceWorker* source = ServiceWorker::from( ServiceWorker* source = ServiceWorker::from(
getExecutionContext(), WTF::wrapUnique(handle.release())); getExecutionContext(), WTF::wrapUnique(handle.release()));
dispatchEvent(ServiceWorkerMessageEvent::create( dispatchEvent(MessageEvent::create(
ports, value, source, ports, value, getExecutionContext()->getSecurityOrigin()->toString(),
getExecutionContext()->getSecurityOrigin()->toString())); String() /* lastEventId */, source, String() /* suborigin */));
} }
const AtomicString& ServiceWorkerContainer::interfaceName() const { const AtomicString& ServiceWorkerContainer::interfaceName() const {
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "modules/serviceworkers/ServiceWorkerMessageEvent.h"
namespace blink {
ServiceWorkerMessageEvent::ServiceWorkerMessageEvent(
const AtomicString& type,
const ServiceWorkerMessageEventInit& initializer)
: Event(type, initializer) {
if (initializer.hasOrigin())
m_origin = initializer.origin();
if (initializer.hasLastEventId())
m_lastEventId = initializer.lastEventId();
if (initializer.hasSource()) {
if (initializer.source().isServiceWorker())
m_sourceAsServiceWorker = initializer.source().getAsServiceWorker();
else if (initializer.source().isMessagePort())
m_sourceAsMessagePort = initializer.source().getAsMessagePort();
}
if (initializer.hasPorts())
m_ports = new MessagePortArray(initializer.ports());
}
ServiceWorkerMessageEvent::ServiceWorkerMessageEvent(
PassRefPtr<SerializedScriptValue> data,
const String& origin,
const String& lastEventId,
ServiceWorker* source,
MessagePortArray* ports)
: Event(EventTypeNames::message, false, false),
m_serializedData(data),
m_origin(origin),
m_lastEventId(lastEventId),
m_sourceAsServiceWorker(source),
m_ports(ports) {
if (m_serializedData)
m_serializedData->registerMemoryAllocatedWithCurrentScriptContext();
}
ServiceWorkerMessageEvent::~ServiceWorkerMessageEvent() {}
MessagePortArray ServiceWorkerMessageEvent::ports(bool& isNull) const {
// TODO(bashi): Currently we return a copied array because the binding
// layer could modify the content of the array while executing JS callbacks.
// Avoid copying once we can make sure that the binding layer won't
// modify the content.
if (m_ports) {
isNull = false;
return *m_ports;
}
isNull = true;
return MessagePortArray();
}
MessagePortArray ServiceWorkerMessageEvent::ports() const {
bool unused;
return ports(unused);
}
void ServiceWorkerMessageEvent::source(
ServiceWorkerOrMessagePort& result) const {
if (m_sourceAsServiceWorker)
result =
ServiceWorkerOrMessagePort::fromServiceWorker(m_sourceAsServiceWorker);
else if (m_sourceAsMessagePort)
result = ServiceWorkerOrMessagePort::fromMessagePort(m_sourceAsMessagePort);
}
const AtomicString& ServiceWorkerMessageEvent::interfaceName() const {
return EventNames::ServiceWorkerMessageEvent;
}
DEFINE_TRACE(ServiceWorkerMessageEvent) {
visitor->trace(m_sourceAsServiceWorker);
visitor->trace(m_sourceAsMessagePort);
visitor->trace(m_ports);
Event::trace(visitor);
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ServiceWorkerMessageEvent_h
#define ServiceWorkerMessageEvent_h
#include "core/dom/DOMArrayBuffer.h"
#include "core/dom/MessagePort.h"
#include "modules/EventModules.h"
#include "modules/ModulesExport.h"
#include "modules/serviceworkers/ServiceWorkerMessageEventInit.h"
namespace blink {
class MODULES_EXPORT ServiceWorkerMessageEvent final : public Event {
DEFINE_WRAPPERTYPEINFO();
public:
static ServiceWorkerMessageEvent* create(
const AtomicString& type,
const ServiceWorkerMessageEventInit& initializer) {
return new ServiceWorkerMessageEvent(type, initializer);
}
static ServiceWorkerMessageEvent* create(
MessagePortArray* ports,
PassRefPtr<SerializedScriptValue> data,
ServiceWorker* source,
const String& origin) {
return new ServiceWorkerMessageEvent(std::move(data), origin, String(),
source, ports);
}
~ServiceWorkerMessageEvent() override;
SerializedScriptValue* serializedData() const {
return m_serializedData.get();
}
void setSerializedData(PassRefPtr<SerializedScriptValue> serializedData) {
m_serializedData = serializedData;
}
const String& origin() const { return m_origin; }
const String& lastEventId() const { return m_lastEventId; }
MessagePortArray ports(bool& isNull) const;
MessagePortArray ports() const;
void source(ServiceWorkerOrMessagePort& result) const;
const AtomicString& interfaceName() const override;
DECLARE_VIRTUAL_TRACE();
private:
ServiceWorkerMessageEvent(const AtomicString& type,
const ServiceWorkerMessageEventInit& initializer);
ServiceWorkerMessageEvent(PassRefPtr<SerializedScriptValue> data,
const String& origin,
const String& lastEventId,
ServiceWorker* source,
MessagePortArray* ports);
RefPtr<SerializedScriptValue> m_serializedData;
String m_origin;
String m_lastEventId;
Member<ServiceWorker> m_sourceAsServiceWorker;
Member<MessagePort> m_sourceAsMessagePort;
Member<MessagePortArray> m_ports;
};
} // namespace blink
#endif // ServiceWorkerMessageEvent_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment