Skip to content

Commit

Permalink
Bug 1667393 - Also send version number when serializing SessionHistor…
Browse files Browse the repository at this point in the history
…yInfo. r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D91434
  • Loading branch information
farre committed Sep 28, 2020
1 parent fdc2959 commit 4b00ad3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
20 changes: 14 additions & 6 deletions docshell/shistory/SessionHistoryEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "nsStructuredCloneContainer.h"
#include "nsXULAppAPI.h"
#include "mozilla/PresState.h"
#include "mozilla/Tuple.h"
#include "mozilla/dom/nsCSPContext.h"
#include "mozilla/ipc/IPDLParamTraits.h"

Expand Down Expand Up @@ -1259,13 +1260,17 @@ namespace ipc {
void IPDLParamTraits<dom::SessionHistoryInfo>::Write(
IPC::Message* aMsg, IProtocol* aActor,
const dom::SessionHistoryInfo& aParam) {
Maybe<dom::ClonedMessageData> stateData;
Maybe<Tuple<uint32_t, dom::ClonedMessageData>> stateData;
if (aParam.mStateData) {
stateData.emplace();
uint32_t version;
NS_ENSURE_SUCCESS_VOID(aParam.mStateData->GetFormatVersion(&version));
Get<0>(*stateData) = version;

JSStructuredCloneData& data = aParam.mStateData->Data();
auto iter = data.Start();
bool success;
stateData->data().data = data.Borrow(iter, data.Size(), &success);
Get<1>(*stateData).data().data = data.Borrow(iter, data.Size(), &success);
if (NS_WARN_IF(!success)) {
return;
}
Expand Down Expand Up @@ -1307,7 +1312,7 @@ void IPDLParamTraits<dom::SessionHistoryInfo>::Write(
bool IPDLParamTraits<dom::SessionHistoryInfo>::Read(
const IPC::Message* aMsg, PickleIterator* aIter, IProtocol* aActor,
dom::SessionHistoryInfo* aResult) {
Maybe<dom::ClonedMessageData> stateData;
Maybe<Tuple<uint32_t, dom::ClonedMessageData>> stateData;
uint64_t sharedId;
if (!ReadIPDLParam(aMsg, aIter, aActor, &aResult->mURI) ||
!ReadIPDLParam(aMsg, aIter, aActor, &aResult->mOriginalURI) ||
Expand Down Expand Up @@ -1400,11 +1405,14 @@ bool IPDLParamTraits<dom::SessionHistoryInfo>::Read(
}

if (stateData.isSome()) {
aResult->mStateData = new nsStructuredCloneContainer();
uint32_t version = Get<0>(*stateData);
aResult->mStateData = new nsStructuredCloneContainer(version);
if (aActor->GetSide() == ChildSide) {
aResult->mStateData->StealFromClonedMessageDataForChild(stateData.ref());
aResult->mStateData->StealFromClonedMessageDataForChild(
Get<1>(*stateData));
} else {
aResult->mStateData->StealFromClonedMessageDataForParent(stateData.ref());
aResult->mStateData->StealFromClonedMessageDataForParent(
Get<1>(*stateData));
}
}
MOZ_ASSERT_IF(stateData.isNothing(), !aResult->mStateData);
Expand Down
2 changes: 2 additions & 0 deletions dom/base/nsStructuredCloneContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ NS_INTERFACE_MAP_BEGIN(nsStructuredCloneContainer)
NS_INTERFACE_MAP_END

nsStructuredCloneContainer::nsStructuredCloneContainer() : mVersion(0) {}
nsStructuredCloneContainer::nsStructuredCloneContainer(uint32_t aVersion)
: mVersion(aVersion) {}

nsStructuredCloneContainer::~nsStructuredCloneContainer() = default;

Expand Down
1 change: 1 addition & 0 deletions dom/base/nsStructuredCloneContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class nsStructuredCloneContainer final
public mozilla::dom::ipc::StructuredCloneData {
public:
nsStructuredCloneContainer();
explicit nsStructuredCloneContainer(uint32_t aVersion);

NS_DECL_ISUPPORTS
NS_DECL_NSISTRUCTUREDCLONECONTAINER
Expand Down

0 comments on commit 4b00ad3

Please sign in to comment.