mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1136467 - ServiceWorker: client.postMessage should land in navigator.serviceWorker.onmessage. r=baku
This commit is contained in:
parent
a58e64d193
commit
553cdbd8f5
@ -32,6 +32,7 @@ interface ServiceWorkerContainer : EventTarget {
|
||||
attribute EventHandler oncontrollerchange;
|
||||
attribute EventHandler onreloadpage;
|
||||
attribute EventHandler onerror;
|
||||
attribute EventHandler onmessage;
|
||||
};
|
||||
|
||||
// Testing only.
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "ServiceWorkerClient.h"
|
||||
#include "ServiceWorkerContainer.h"
|
||||
|
||||
#include "mozilla/dom/MessageEvent.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
@ -59,16 +60,23 @@ public:
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
ErrorResult result;
|
||||
dom::Navigator* navigator = window->GetNavigator(result);
|
||||
if (NS_WARN_IF(result.Failed())) {
|
||||
return result.ErrorCode();
|
||||
}
|
||||
|
||||
nsRefPtr<ServiceWorkerContainer> container = navigator->ServiceWorker();
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init(window);
|
||||
JSContext* cx = jsapi.cx();
|
||||
|
||||
return DispatchDOMEvent(cx, window);
|
||||
return DispatchDOMEvent(cx, container);
|
||||
}
|
||||
|
||||
private:
|
||||
NS_IMETHOD
|
||||
DispatchDOMEvent(JSContext* aCx, nsGlobalWindow* aTargetWindow)
|
||||
DispatchDOMEvent(JSContext* aCx, ServiceWorkerContainer* aTargetContainer)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
@ -84,7 +92,7 @@ private:
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMMessageEvent> event = new MessageEvent(aTargetWindow,
|
||||
nsCOMPtr<nsIDOMMessageEvent> event = new MessageEvent(aTargetContainer,
|
||||
nullptr, nullptr);
|
||||
nsresult rv =
|
||||
event->InitMessageEvent(NS_LITERAL_STRING("message"),
|
||||
@ -101,7 +109,7 @@ private:
|
||||
|
||||
event->SetTrusted(true);
|
||||
bool status = false;
|
||||
aTargetWindow->DispatchEvent(event, &status);
|
||||
aTargetContainer->DispatchEvent(event, &status);
|
||||
|
||||
if (!status) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
IMPL_EVENT_HANDLER(controllerchange)
|
||||
IMPL_EVENT_HANDLER(reloadpage)
|
||||
IMPL_EVENT_HANDLER(error)
|
||||
IMPL_EVENT_HANDLER(message)
|
||||
|
||||
explicit ServiceWorkerContainer(nsPIDOMWindow* aWindow);
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
window.onmessage = function(msg) {
|
||||
navigator.serviceWorker.onmessage = function(msg) {
|
||||
// forward message to the test page.
|
||||
parent.postMessage(msg.data, "*");
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user