Commit e5cb284f authored by Anny Gakhokidze's avatar Anny Gakhokidze
Browse files

Bug 1539238 - Modify nsSHEntry::Create to consolidate setter calls on...

Bug 1539238 - Modify nsSHEntry::Create to consolidate setter calls on nsSHEntry in nsDocShell::AddToSessionHistory, r=peterv

nsDocShell is the only consumer of nsISHEntry::Create, and
in AddToSessionHistory method, after calling nsISHEntry::Create,
it calls 8 setter methods on nsISHEntry, which results in a
total of 9 sync IPC calls.

With the proposed solution of setting everything via
nsISHEntry::Create, we get a total of 1 sync IPC call.

Differential Revision: https://phabricator.services.mozilla.com/D24979

--HG--
extra : rebase_source : af9c75043260a6333d789d3ca882173703f7bc29
extra : amend_source : 334281153e24f9e9f0abac3983d32fb99dae6995
extra : source : a8eed7c5d12c49366ad8acd706fa0e8464ed8549
extra : histedit_source : 653daabf83d43571803a1e33c95a4804e4275e7d
parent b0a8f8d7
......@@ -11412,7 +11412,7 @@ nsresult nsDocShell::AddToSessionHistory(
nsCOMPtr<nsIPrincipal> principalToInherit = aPrincipalToInherit;
nsCOMPtr<nsIPrincipal> storagePrincipalToInherit = aStoragePrincipalToInherit;
nsCOMPtr<nsIContentSecurityPolicy> csp = aCsp;
bool expired = false;
bool expired = false; // by default the page is not expired
bool discardLayoutState = false;
nsCOMPtr<nsICacheInfoChannel> cacheChannel;
if (aChannel) {
......@@ -11481,40 +11481,28 @@ nsresult nsDocShell::AddToSessionHistory(
}
}
// Title is set in nsDocShell::SetTitle()
entry->Create(aURI, // uri
EmptyString(), // Title
inputStream, // Post data stream
cacheKey, // CacheKey
mContentTypeHint, // Content-type
triggeringPrincipal, // Channel or provided principal
principalToInherit, storagePrincipalToInherit, csp, HistoryID(),
mDynamicallyCreated);
nsAutoString srcdoc;
bool srcdocEntry = false;
nsCOMPtr<nsIURI> baseURI;
entry->SetOriginalURI(originalURI);
entry->SetResultPrincipalURI(resultPrincipalURI);
entry->SetLoadReplace(loadReplace);
entry->SetReferrerInfo(referrerInfo);
nsCOMPtr<nsIInputStreamChannel> inStrmChan = do_QueryInterface(aChannel);
if (inStrmChan) {
bool isSrcdocChannel;
inStrmChan->GetIsSrcdocChannel(&isSrcdocChannel);
if (isSrcdocChannel) {
nsAutoString srcdoc;
inStrmChan->GetSrcdocData(srcdoc);
entry->SetSrcdocData(srcdoc);
nsCOMPtr<nsIURI> baseURI;
srcdocEntry = true;
inStrmChan->GetBaseURI(getter_AddRefs(baseURI));
entry->SetBaseURI(baseURI);
} else {
srcdoc.SetIsVoid(true);
}
}
/* If cache got a 'no-store', ask SH not to store
* HistoryLayoutState. By default, SH will set this
* flag to true and save HistoryLayoutState.
*/
if (discardLayoutState) {
entry->SetSaveLayoutStateFlag(false);
}
bool saveLayoutState = !discardLayoutState;
if (cacheChannel) {
// Check if the page has expired from cache
uint32_t expTime = 0;
......@@ -11524,9 +11512,18 @@ nsresult nsDocShell::AddToSessionHistory(
expired = true;
}
}
if (expired) {
entry->SetExpirationStatus(true);
}
// Title is set in nsDocShell::SetTitle()
entry->Create(aURI, // uri
EmptyString(), // Title
inputStream, // Post data stream
cacheKey, // CacheKey
mContentTypeHint, // Content-type
triggeringPrincipal, // Channel or provided principal
principalToInherit, storagePrincipalToInherit, csp, HistoryID(),
mDynamicallyCreated, originalURI, resultPrincipalURI,
loadReplace, referrerInfo, srcdoc, srcdocEntry, baseURI,
saveLayoutState, expired);
if (root == static_cast<nsIDocShellTreeItem*>(this) && mSessionHistory) {
// If we need to clone our children onto the new session
......
......@@ -85,8 +85,12 @@ parent:
sync Create(nsIURI URI, nsString title, nsIInputStream inputStream,
uint32_t cacheKey, nsCString contentType,
nsIPrincipal triggeringPrincipal, nsIPrincipal principalToInherit,
nsIPrincipal storagePrincipalToInherit,
nsIContentSecurityPolicy csp, nsID docshellID,
bool dynamicCreation);
bool dynamicCreation, nsIURI originalUri, nsIURI resultPrincipalURI,
bool loadReplace, nsIReferrerInfo referrerInfo,
nsString srcdoc, bool srcdocEntry, nsIURI baseURI,
bool saveLayoutState, bool expired);
sync HasDetachedEditor() returns (bool hasDetachedEditor);
sync IsDynamicallyAdded() returns (bool isDynamicallyAdded);
sync HasDynamicallyAddedChild() returns (bool hasDynamicallyAddedChild);
......
......@@ -531,21 +531,25 @@ SHEntryChild::SetContentType(const nsACString& aContentType) {
}
NS_IMETHODIMP
SHEntryChild::Create(nsIURI* aURI, const nsAString& aTitle,
nsIInputStream* aInputStream, uint32_t aCacheKey,
const nsACString& aContentType,
nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit,
nsIContentSecurityPolicy* aCsp, const nsID& aDocShellID,
bool aDynamicCreation) {
SHEntryChild::Create(
nsIURI* aURI, const nsAString& aTitle, nsIInputStream* aInputStream,
uint32_t aCacheKey, const nsACString& aContentType,
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aStoragePrincipalToInherit, nsIContentSecurityPolicy* aCsp,
const nsID& aDocShellID, bool aDynamicCreation, nsIURI* aOriginalURI,
nsIURI* aResultPrincipalURI, bool aLoadReplace,
nsIReferrerInfo* aReferrerInfo, const nsAString& srcdoc, bool srcdocEntry,
nsIURI* aBaseURI, bool aSaveLayoutState, bool aExpired) {
mShared->mLayoutHistoryState = nullptr;
// By default we save LayoutHistoryState
mShared->mSaveLayoutState = true;
mShared->mSaveLayoutState = aSaveLayoutState;
return SendCreate(aURI, nsString(aTitle), aInputStream, aCacheKey,
nsCString(aContentType), aTriggeringPrincipal,
aPrincipalToInherit, aCsp, aDocShellID, aDynamicCreation)
aPrincipalToInherit, aStoragePrincipalToInherit, aCsp,
aDocShellID, aDynamicCreation, aOriginalURI,
aResultPrincipalURI, aLoadReplace, aReferrerInfo,
nsString(srcdoc), srcdocEntry, aBaseURI, aSaveLayoutState,
aExpired)
? NS_OK
: NS_ERROR_FAILURE;
}
......
......@@ -428,11 +428,17 @@ bool SHEntryParent::RecvCreate(
nsIURI* aURI, const nsString& aTitle, nsIInputStream* aInputStream,
const uint32_t& aCacheKey, const nsCString& aContentType,
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit,
nsIContentSecurityPolicy* aCsp, const nsID& aDocshellID,
const bool& aDynamicCreation) {
nsIPrincipal* aStoragePrincipalToInherit, nsIContentSecurityPolicy* aCsp,
const nsID& aDocshellID, const bool& aDynamicCreation, nsIURI* aOriginalURI,
nsIURI* aResultPrincipalURI, const bool& aLoadReplace,
nsIReferrerInfo* aReferrerInfo, const nsAString& srcdoc,
const bool& srcdocEntry, nsIURI* aBaseURI, const bool& aSaveLayoutState,
const bool& aExpired) {
DebugOnly<nsresult> rv = mEntry->Create(
aURI, aTitle, aInputStream, aCacheKey, aContentType, aTriggeringPrincipal,
aPrincipalToInherit, aCsp, aDocshellID, aDynamicCreation);
aPrincipalToInherit, aStoragePrincipalToInherit, aCsp, aDocshellID,
aDynamicCreation, aOriginalURI, aResultPrincipalURI, aLoadReplace,
aReferrerInfo, srcdoc, srcdocEntry, aBaseURI, aSaveLayoutState, aExpired);
MOZ_ASSERT(NS_SUCCEEDED(rv), "Didn't expect this to fail.");
return true;
}
......
......@@ -156,8 +156,14 @@ class SHEntryParent final : public PSHEntryParent {
const nsCString& aContentType,
nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aStoragePrincipalToInherit,
nsIContentSecurityPolicy* aCsp, const nsID& aDocshellID,
const bool& aDynamicCreation);
const bool& aDynamicCreation, nsIURI* aOriginalURI,
nsIURI* aResultPrincipalURI, const bool& aLoadReplace,
nsIReferrerInfo* aReferrerInfo, const nsAString& srcdoc,
const bool& srcdocEntry, nsIURI* aBaseURI,
const bool& aSaveLayoutState, const bool& aExpired);
bool RecvClone(PSHEntryParent** aCloneEntry);
bool RecvHasDetachedEditor(bool* aHasDetachedEditor);
bool RecvIsDynamicallyAdded(bool* aIsDynamicallyAdded);
bool RecvHasDynamicallyAddedChild(bool* aHasDynamicallyAddedChild);
......
......@@ -300,7 +300,16 @@ interface nsISHEntry : nsISupports
in nsIPrincipal storagePrincipalToInherit,
in nsIContentSecurityPolicy aCsp,
in nsIDRef docshellID,
in boolean dynamicCreation);
in boolean dynamicCreation,
in nsIURI originalURI,
in nsIURI resultPrincipalURI,
in bool loadReplace,
in nsIReferrerInfo referrerInfo,
in AString srcdoc,
in bool srcdocEntry,
in nsIURI baseURI,
in bool saveLayoutState,
in bool expired);
nsISHEntry clone();
......
......@@ -345,14 +345,15 @@ nsSHEntry::SetContentType(const nsACString& aContentType) {
}
NS_IMETHODIMP
nsSHEntry::Create(nsIURI* aURI, const nsAString& aTitle,
nsIInputStream* aInputStream, uint32_t aCacheKey,
const nsACString& aContentType,
nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aStoragePrincipalToInherit,
nsIContentSecurityPolicy* aCsp, const nsID& aDocShellID,
bool aDynamicCreation) {
nsSHEntry::Create(
nsIURI* aURI, const nsAString& aTitle, nsIInputStream* aInputStream,
uint32_t aCacheKey, const nsACString& aContentType,
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aStoragePrincipalToInherit, nsIContentSecurityPolicy* aCsp,
const nsID& aDocShellID, bool aDynamicCreation, nsIURI* aOriginalURI,
nsIURI* aResultPrincipalURI, bool aLoadReplace,
nsIReferrerInfo* aReferrerInfo, const nsAString& aSrcdocData,
bool aSrcdocEntry, nsIURI* aBaseURI, bool aSaveLayoutState, bool aExpired) {
MOZ_ASSERT(
aTriggeringPrincipal,
"need a valid triggeringPrincipal to create a session history entry");
......@@ -378,14 +379,19 @@ nsSHEntry::Create(nsIURI* aURI, const nsAString& aTitle,
// all subframe navigations, sets the flag to true.
mShared->mIsFrameNavigation = false;
// By default the page is not expired
mShared->mExpired = false;
mShared->mExpired = aExpired;
mIsSrcdocEntry = false;
mSrcdocData = VoidString();
mIsSrcdocEntry = aSrcdocEntry;
mSrcdocData = aSrcdocData;
mBaseURI = aBaseURI;
mLoadedInThisProcess = true;
mOriginalURI = aOriginalURI;
mResultPrincipalURI = aResultPrincipalURI;
mLoadReplace = aLoadReplace;
mReferrerInfo = aReferrerInfo;
return NS_OK;
}
......@@ -977,21 +983,25 @@ nsLegacySHEntry::InitLayoutHistoryState(nsILayoutHistoryState** aState) {
}
NS_IMETHODIMP
nsLegacySHEntry::Create(nsIURI* aURI, const nsAString& aTitle,
nsIInputStream* aInputStream, uint32_t aCacheKey,
const nsACString& aContentType,
nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit,
nsIContentSecurityPolicy* aCsp, const nsID& aDocShellID,
bool aDynamicCreation) {
nsLegacySHEntry::Create(
nsIURI* aURI, const nsAString& aTitle, nsIInputStream* aInputStream,
uint32_t aCacheKey, const nsACString& aContentType,
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aStoragePrincipalToInherit, nsIContentSecurityPolicy* aCsp,
const nsID& aDocShellID, bool aDynamicCreation, nsIURI* aOriginalURI,
nsIURI* aResultPrincipalURI, bool aLoadReplace,
nsIReferrerInfo* aReferrerInfo, const nsAString& aSrcdocData,
bool aSrcdocEntry, nsIURI* aBaseURI, bool aSaveLayoutState, bool aExpired) {
GetState()->mLayoutHistoryState = nullptr;
// By default we save LayoutHistoryState
GetState()->mSaveLayoutState = true;
GetState()->mSaveLayoutState = aSaveLayoutState;
return nsSHEntry::Create(aURI, aTitle, aInputStream, aCacheKey, aContentType,
aTriggeringPrincipal, aPrincipalToInherit, aCsp,
aDocShellID, aDynamicCreation);
aTriggeringPrincipal, aPrincipalToInherit,
aStoragePrincipalToInherit, aCsp, aDocShellID,
aDynamicCreation, aOriginalURI, aResultPrincipalURI,
aLoadReplace, aReferrerInfo, aSrcdocData,
aSrcdocEntry, aBaseURI, aSaveLayoutState, aExpired);
}
NS_IMETHODIMP
......
......@@ -102,13 +102,16 @@ class nsLegacySHEntry final : public nsSHEntry {
NS_IMETHOD_(void) ClearChildShells() override;
NS_IMETHOD_(void) SyncPresentationState() override;
NS_IMETHOD InitLayoutHistoryState(nsILayoutHistoryState** aState) override;
NS_IMETHOD Create(nsIURI* aURI, const nsAString& aTitle,
nsIInputStream* aInputStream, uint32_t aCacheKey,
const nsACString& aContentType,
nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit,
nsIContentSecurityPolicy* aCsp, const nsID& aDocshellID,
bool aDynamicCreation) override;
NS_IMETHOD Create(
nsIURI* aURI, const nsAString& aTitle, nsIInputStream* aInputStream,
uint32_t aCacheKey, const nsACString& aContentType,
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aStoragePrincipalToInherit, nsIContentSecurityPolicy* aCsp,
const nsID& aDocshellID, bool aDynamicCreation, nsIURI* aOriginalURI,
nsIURI* aResultPrincipalURI, bool aLoadReplace,
nsIReferrerInfo* aReferrerInfo, const nsAString& aSrcdocData,
bool aSrcdocEntry, nsIURI* aBaseURI, bool aSaveLayoutState,
bool aExpired) override;
NS_IMETHOD Clone(nsISHEntry** aResult) override;
NS_IMETHOD_(nsDocShellEditorData*) ForgetEditorData(void) override;
NS_IMETHOD_(void) SetEditorData(nsDocShellEditorData* aData) override;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment