mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 966439 - BroadcastChannel API - patch 5 - bfcache supported, r=smaug
This commit is contained in:
parent
9dc7e00134
commit
d358897d78
@ -125,6 +125,24 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
// Walk up to our containing page
|
||||
WorkerPrivate* wp = mWorkerPrivate;
|
||||
while (wp->GetParent()) {
|
||||
wp = wp->GetParent();
|
||||
}
|
||||
|
||||
// Window doesn't exist for some kind of workers (eg: SharedWorkers)
|
||||
nsPIDOMWindow* window = wp->GetWindow();
|
||||
if (!window) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsIDocument* doc = window->GetExtantDoc();
|
||||
// No bfcache when BroadcastChannel is used.
|
||||
if (doc) {
|
||||
doc->DisallowBFCaching();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -400,6 +418,11 @@ BroadcastChannel::Constructor(const GlobalObject& aGlobal,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsIDocument* doc = window->GetExtantDoc();
|
||||
// No bfcache when BroadcastChannel is used.
|
||||
if (doc) {
|
||||
doc->DisallowBFCaching();
|
||||
}
|
||||
} else {
|
||||
JSContext* cx = aGlobal.Context();
|
||||
workerPrivate = GetWorkerPrivateFromContext(cx);
|
||||
@ -506,7 +529,7 @@ BroadcastChannel::ActorCreated(ipc::PBackgroundChild* aActor)
|
||||
mActor = static_cast<BroadcastChannelChild*>(actor);
|
||||
MOZ_ASSERT(mActor);
|
||||
|
||||
mActor->SetEventTarget(this);
|
||||
mActor->SetParent(this);
|
||||
|
||||
// Flush pending messages.
|
||||
for (uint32_t i = 0; i < mPendingMessages.Length(); ++i) {
|
||||
@ -539,7 +562,7 @@ BroadcastChannel::Shutdown()
|
||||
}
|
||||
|
||||
if (mActor) {
|
||||
mActor->SetEventTarget(nullptr);
|
||||
mActor->SetParent(nullptr);
|
||||
|
||||
nsRefPtr<TeardownRunnable> runnable = new TeardownRunnable(mActor);
|
||||
NS_DispatchToCurrentThread(runnable);
|
||||
|
@ -30,24 +30,29 @@ BroadcastChannelChild::BroadcastChannelChild(const nsAString& aOrigin,
|
||||
|
||||
BroadcastChannelChild::~BroadcastChannelChild()
|
||||
{
|
||||
MOZ_ASSERT(!mEventTarget);
|
||||
MOZ_ASSERT(!mBC);
|
||||
}
|
||||
|
||||
bool
|
||||
BroadcastChannelChild::RecvNotify(const nsString& aMessage)
|
||||
{
|
||||
nsCOMPtr<DOMEventTargetHelper> helper = mBC;
|
||||
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(helper);
|
||||
|
||||
// This object is going to be deleted soon. No notify is required.
|
||||
if (!mEventTarget) {
|
||||
if (!eventTarget) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// CheckInnerWindowCorrectness can be used also without a window when
|
||||
// BroadcastChannel is running in a worker. In this case, it's a NOP.
|
||||
if (NS_FAILED(mBC->CheckInnerWindowCorrectness())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (NS_IsMainThread()) {
|
||||
DOMEventTargetHelper* deth =
|
||||
DOMEventTargetHelper::FromSupports(mEventTarget);
|
||||
MOZ_ASSERT(deth);
|
||||
|
||||
AutoJSAPI autoJS;
|
||||
if (!autoJS.Init(deth->GetParentObject())) {
|
||||
if (!autoJS.Init(mBC->GetParentObject())) {
|
||||
NS_WARNING("Dropping message");
|
||||
return true;
|
||||
}
|
||||
@ -85,8 +90,7 @@ BroadcastChannelChild::Notify(JSContext* aCx, const nsString& aMessage)
|
||||
|
||||
ErrorResult rv;
|
||||
nsRefPtr<MessageEvent> event =
|
||||
MessageEvent::Constructor(mEventTarget, NS_LITERAL_STRING("message"),
|
||||
init, rv);
|
||||
MessageEvent::Constructor(mBC, NS_LITERAL_STRING("message"), init, rv);
|
||||
if (rv.Failed()) {
|
||||
NS_WARNING("Failed to create a MessageEvent object.");
|
||||
return;
|
||||
@ -95,7 +99,7 @@ BroadcastChannelChild::Notify(JSContext* aCx, const nsString& aMessage)
|
||||
event->SetTrusted(true);
|
||||
|
||||
bool status;
|
||||
mEventTarget->DispatchEvent(static_cast<Event*>(event.get()), &status);
|
||||
mBC->DispatchEvent(static_cast<Event*>(event.get()), &status);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -5,7 +5,6 @@
|
||||
#ifndef mozilla_dom_BroadcastChannelChild_h
|
||||
#define mozilla_dom_BroadcastChannelChild_h
|
||||
|
||||
#include "mozilla/dom/EventTarget.h"
|
||||
#include "mozilla/dom/PBroadcastChannelChild.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -16,7 +15,7 @@ class BackgroundChildImpl;
|
||||
|
||||
namespace dom {
|
||||
|
||||
class EventTarget;
|
||||
class BroadcastChannel;
|
||||
|
||||
class BroadcastChannelChild MOZ_FINAL : public PBroadcastChannelChild
|
||||
{
|
||||
@ -25,9 +24,9 @@ class BroadcastChannelChild MOZ_FINAL : public PBroadcastChannelChild
|
||||
public:
|
||||
NS_INLINE_DECL_REFCOUNTING(BroadcastChannelChild)
|
||||
|
||||
void SetEventTarget(EventTarget* aEventTarget)
|
||||
void SetParent(BroadcastChannel* aBC)
|
||||
{
|
||||
mEventTarget = aEventTarget;
|
||||
mBC = aBC;
|
||||
}
|
||||
|
||||
virtual bool RecvNotify(const nsString& aMessage) MOZ_OVERRIDE;
|
||||
@ -49,7 +48,7 @@ private:
|
||||
|
||||
// This raw pointer is actually the parent object.
|
||||
// It's set to null when the parent object is deleted.
|
||||
EventTarget* mEventTarget;
|
||||
BroadcastChannel* mBC;
|
||||
|
||||
nsString mOrigin;
|
||||
nsString mChannel;
|
||||
|
Loading…
Reference in New Issue
Block a user