Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1212842 - part 1 - BroadcastChannel should not remove the documen…
Browse files Browse the repository at this point in the history
…t from bfcache when not used, r=smaug
  • Loading branch information
bakulf committed Oct 13, 2015
1 parent 4548f88 commit dbd7074
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
2 changes: 2 additions & 0 deletions dom/base/nsIDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ class nsIDocument : public nsINode
return GetBFCacheEntry() ? nullptr : mPresShell;
}

// Instead using this method, what you probably want is
// RemoveFromBFCacheSync() as we do in MessagePort and BroadcastChannel.
void DisallowBFCaching()
{
NS_ASSERTION(!mBFCacheEntry, "We're already in the bfcache!");
Expand Down
34 changes: 28 additions & 6 deletions dom/broadcastchannel/BroadcastChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "WorkerPrivate.h"
#include "WorkerRunnable.h"

#include "nsIBFCacheEntry.h"
#include "nsIDocument.h"
#include "nsISupportsPrimitives.h"

Expand Down Expand Up @@ -127,9 +128,6 @@ class InitializeRunnable final : public WorkerMainThreadRunnable
nsIDocument* doc = window->GetExtantDoc();
if (doc) {
mPrivateBrowsing = nsContentUtils::IsInPrivateBrowsing(doc);

// No bfcache when BroadcastChannel is used.
doc->DisallowBFCaching();
}

return true;
Expand Down Expand Up @@ -381,9 +379,6 @@ BroadcastChannel::Constructor(const GlobalObject& aGlobal,
nsIDocument* doc = window->GetExtantDoc();
if (doc) {
privateBrowsing = nsContentUtils::IsInPrivateBrowsing(doc);

// No bfcache when BroadcastChannel is used.
doc->DisallowBFCaching();
}
} else {
JSContext* cx = aGlobal.Context();
Expand Down Expand Up @@ -466,6 +461,8 @@ BroadcastChannel::PostMessageInternal(JSContext* aCx,
void
BroadcastChannel::PostMessageData(BroadcastChannelMessage* aData)
{
RemoveDocFromBFCache();

if (mActor) {
nsRefPtr<BCPostMessageRunnable> runnable =
new BCPostMessageRunnable(mActor, aData);
Expand Down Expand Up @@ -666,6 +663,31 @@ BroadcastChannel::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}

void
BroadcastChannel::RemoveDocFromBFCache()
{
if (!NS_IsMainThread()) {
return;
}

nsPIDOMWindow* window = GetOwner();
if (!window) {
return;
}

nsIDocument* doc = window->GetExtantDoc();
if (!doc) {
return;
}

nsCOMPtr<nsIBFCacheEntry> bfCacheEntry = doc->GetBFCacheEntry();
if (!bfCacheEntry) {
return;
}

bfCacheEntry->RemoveFromBFCacheSync();
}

NS_IMPL_CYCLE_COLLECTION_CLASS(BroadcastChannel)

NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BroadcastChannel,
Expand Down
14 changes: 9 additions & 5 deletions dom/broadcastchannel/BroadcastChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class BroadcastChannel final
, public nsIIPCBackgroundChildCreateCallback
, public nsIObserver
{
friend class BroadcastChannelChild;

NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
NS_DECL_NSIOBSERVER

Expand Down Expand Up @@ -82,11 +84,6 @@ class BroadcastChannel final

void Shutdown();

bool IsClosed() const
{
return mState != StateActive;
}

private:
BroadcastChannel(nsPIDOMWindow* aWindow,
const PrincipalInfo& aPrincipalInfo,
Expand All @@ -108,6 +105,13 @@ class BroadcastChannel final
return mIsKeptAlive;
}

bool IsClosed() const
{
return mState != StateActive;
}

void RemoveDocFromBFCache();

nsRefPtr<BroadcastChannelChild> mActor;
nsTArray<nsRefPtr<BroadcastChannelMessage>> mPendingMessages;

Expand Down
2 changes: 2 additions & 0 deletions dom/broadcastchannel/BroadcastChannelChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ BroadcastChannelChild::RecvNotify(const ClonedMessageData& aData)
return true;
}

mBC->RemoveDocFromBFCache();

AutoJSAPI jsapi;
nsCOMPtr<nsIGlobalObject> globalObject;

Expand Down

0 comments on commit dbd7074

Please sign in to comment.