Backed out changeset 7b45c1aebf7f (bug 1359017)

This commit is contained in:
Sebastian Hengst 2017-09-13 08:56:13 +02:00
Родитель 38b304e15b
Коммит 66969c6b7b
5 изменённых файлов: 15 добавлений и 54 удалений

Просмотреть файл

@ -143,18 +143,19 @@ PostMessageEvent::Run()
}
}
IgnoredErrorResult rv;
ErrorResult rv;
JS::Rooted<JS::Value> messageData(cx);
nsCOMPtr<mozilla::dom::EventTarget> eventTarget = do_QueryObject(targetWindow);
nsCOMPtr<nsPIDOMWindowInner> window = targetWindow->AsInner();
Read(targetWindow->AsInner(), cx, &messageData, rv);
Read(window, cx, &messageData, rv);
if (NS_WARN_IF(rv.Failed())) {
DispatchError(cx, targetWindow, eventTarget);
return NS_OK;
return rv.StealNSResult();
}
// Create the event
RefPtr<MessageEvent> event = new MessageEvent(eventTarget, nullptr, nullptr);
nsCOMPtr<mozilla::dom::EventTarget> eventTarget = do_QueryObject(targetWindow);
RefPtr<MessageEvent> event =
new MessageEvent(eventTarget, nullptr, nullptr);
Nullable<WindowProxyOrMessagePortOrServiceWorker> source;
@ -162,8 +163,7 @@ PostMessageEvent::Run()
Sequence<OwningNonNull<MessagePort>> ports;
if (!TakeTransferredPortsAsSequence(ports)) {
DispatchError(cx, targetWindow, eventTarget);
return NS_OK;
return NS_ERROR_OUT_OF_MEMORY;
}
event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"),
@ -171,52 +171,26 @@ PostMessageEvent::Run()
messageData, mCallerOrigin,
EmptyString(), source, ports);
Dispatch(targetWindow, event);
return NS_OK;
}
void
PostMessageEvent::DispatchError(JSContext* aCx, nsGlobalWindow* aTargetWindow,
mozilla::dom::EventTarget* aEventTarget)
{
RootedDictionary<MessageEventInit> init(aCx);
init.mBubbles = false;
init.mCancelable = false;
init.mOrigin = mCallerOrigin;
if (mSource) {
init.mSource.SetValue().SetAsWindowProxy() = mSource->AsOuter();
}
RefPtr<Event> event =
MessageEvent::Constructor(aEventTarget, NS_LITERAL_STRING("messageerror"),
init);
Dispatch(aTargetWindow, event);
}
void
PostMessageEvent::Dispatch(nsGlobalWindow* aTargetWindow, Event* aEvent)
{
// We can't simply call dispatchEvent on the window because doing so ends
// up flipping the trusted bit on the event, and we don't want that to
// happen because then untrusted content can call postMessage on a chrome
// window if it can get a reference to it.
nsIPresShell *shell = aTargetWindow->GetExtantDoc()->GetShell();
nsIPresShell *shell = targetWindow->GetExtantDoc()->GetShell();
RefPtr<nsPresContext> presContext;
if (shell) {
if (shell)
presContext = shell->GetPresContext();
}
aEvent->SetTrusted(mTrustedCaller);
WidgetEvent* internalEvent = aEvent->WidgetEventPtr();
event->SetTrusted(mTrustedCaller);
WidgetEvent* internalEvent = event->WidgetEventPtr();
nsEventStatus status = nsEventStatus_eIgnore;
EventDispatcher::Dispatch(aTargetWindow->AsInner(),
EventDispatcher::Dispatch(window,
presContext,
internalEvent,
aEvent,
static_cast<dom::Event*>(event.get()),
&status);
return NS_OK;
}
} // namespace dom

Просмотреть файл

@ -40,13 +40,6 @@ public:
private:
~PostMessageEvent();
void
Dispatch(nsGlobalWindow* aTargetWindow, Event* aEvent);
void
DispatchError(JSContext* aCx, nsGlobalWindow* aTargetWindow,
mozilla::dom::EventTarget* aEventTarget);
RefPtr<nsGlobalWindow> mSource;
nsString mCallerOrigin;
RefPtr<nsGlobalWindow> mTargetWindow;

Просмотреть файл

@ -551,10 +551,6 @@ WINDOW_EVENT(message,
eMessage,
EventNameType_None,
eBasicEventClass)
WINDOW_EVENT(messageerror,
eMessageError,
EventNameType_HTMLBodyOrFramesetOnly,
eBasicEventClass)
WINDOW_EVENT(offline,
eOffline,
EventNameType_XUL | EventNameType_HTMLBodyOrFramesetOnly,

Просмотреть файл

@ -147,7 +147,6 @@ interface WindowEventHandlers {
attribute EventHandler onhashchange;
attribute EventHandler onlanguagechange;
attribute EventHandler onmessage;
attribute EventHandler onmessageerror;
attribute EventHandler onoffline;
attribute EventHandler ononline;
attribute EventHandler onpagehide;

Просмотреть файл

@ -374,7 +374,6 @@ NS_EVENT_MESSAGE(eBeforePrint)
NS_EVENT_MESSAGE(eAfterPrint)
NS_EVENT_MESSAGE(eMessage)
NS_EVENT_MESSAGE(eMessageError)
// Menu open event
NS_EVENT_MESSAGE(eOpen)