Bug 1234128 - Part 1: Add mozpresentation attribute in browser element. r=smaug

--HG--
extra : rebase_source : ba957a216d873638a61eb2b80be3cf2f0fe661ff
This commit is contained in:
Shih-Chiang Chien 2016-05-17 11:10:59 +08:00
Родитель 30c9aa43b3
Коммит 79fd83ae47
7 изменённых файлов: 81 добавлений и 7 удалений

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

@ -115,6 +115,7 @@
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMEvent.h"
#include "nsIDOMElement.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMHTMLInputElement.h"
@ -203,6 +204,7 @@
#include "nsICookieService.h"
#include "mozilla/EnumSet.h"
#include "mozilla/BloomFilter.h"
#include "TabChild.h"
#include "nsIBidiKeyboard.h"
@ -8839,3 +8841,31 @@ nsContentUtils::SetScrollbarsVisibility(nsIDocShell* aDocShell, bool aVisible)
nsIScrollable::ScrollOrientation_X, prefValue);
}
}
/* static */ void
nsContentUtils::GetPresentationURL(nsIDocShell* aDocShell, nsAString& aPresentationUrl)
{
MOZ_ASSERT(aDocShell);
if (XRE_IsContentProcess()) {
nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
aDocShell->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
nsCOMPtr<nsIDocShellTreeItem> root;
aDocShell->GetRootTreeItem(getter_AddRefs(root));
if (sameTypeRoot.get() == root.get()) {
// presentation URL is stored in TabChild for the top most
// <iframe mozbrowser> in content process.
TabChild* tabChild = TabChild::GetFrom(aDocShell);
if (tabChild) {
aPresentationUrl = tabChild->PresentationURL();
}
return;
}
}
nsCOMPtr<nsILoadContext> loadContext(do_QueryInterface(aDocShell));
nsCOMPtr<nsIDOMElement> topFrameElement;
loadContext->GetTopFrameElement(getter_AddRefs(topFrameElement));
topFrameElement->GetAttribute(NS_LITERAL_STRING("mozpresentation"), aPresentationUrl);
}

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

@ -2553,6 +2553,12 @@ public:
static void SetScrollbarsVisibility(nsIDocShell* aDocShell, bool aVisible);
/*
* Return the associated presentation URL of the presented content.
* Will return empty string if the docshell is not in a presented content.
*/
static void GetPresentationURL(nsIDocShell* aDocShell, nsAString& aPresentationUrl);
private:
static bool InitializeEventTable();

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

@ -3340,12 +3340,18 @@ nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
attrs.mUserContextId = userContextId;
}
nsAutoString presentationURLStr;
mOwnerContent->GetAttr(kNameSpaceID_None,
nsGkAtoms::mozpresentation,
presentationURLStr);
bool tabContextUpdated =
aTabContext->SetTabContext(OwnerIsMozBrowserFrame(),
ownApp,
containingApp,
attrs,
signedPkgOrigin);
signedPkgOrigin,
presentationURLStr);
NS_ENSURE_STATE(tabContextUpdated);
return NS_OK;

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

@ -1014,6 +1014,7 @@ GK_ATOM(predicate, "predicate")
GK_ATOM(prefix, "prefix")
GK_ATOM(preload, "preload")
GK_ATOM(prerendered, "prerendered")
GK_ATOM(mozpresentation, "mozpresentation")
GK_ATOM(preserve, "preserve")
GK_ATOM(preserveSpace, "preserve-space")
GK_ATOM(preventdefault, "preventdefault")

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

@ -47,6 +47,11 @@ struct FrameIPCTabContext
// Whether this is a mozbrowser frame. <iframe mozbrowser mozapp> and
// <xul:browser> are not considered to be mozbrowser frames.
bool isMozBrowserElement;
// The requested presentation URL.
// This value would be empty if the TabContext isn't created for
// presented content.
nsString presentationURL;
};
// XXXcatalinb: This is only used by ServiceWorkerClients::OpenWindow.

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

@ -190,12 +190,19 @@ TabContext::SignedPkgOriginNoSuffix() const
return mSignedPkgOriginNoSuffix;
}
const nsAString&
TabContext::PresentationURL() const
{
return mPresentationURL;
}
bool
TabContext::SetTabContext(bool aIsMozBrowserElement,
mozIApplication* aOwnApp,
mozIApplication* aAppFrameOwnerApp,
const DocShellOriginAttributes& aOriginAttributes,
const nsACString& aSignedPkgOriginNoSuffix)
const nsACString& aSignedPkgOriginNoSuffix,
const nsAString& aPresentationURL)
{
NS_ENSURE_FALSE(mInitialized, false);
@ -227,6 +234,7 @@ TabContext::SetTabContext(bool aIsMozBrowserElement,
mOwnApp = aOwnApp;
mContainingApp = aAppFrameOwnerApp;
mSignedPkgOriginNoSuffix = aSignedPkgOriginNoSuffix;
mPresentationURL = aPresentationURL;
return true;
}
@ -238,7 +246,8 @@ TabContext::AsIPCTabContext() const
return IPCTabContext(FrameIPCTabContext(originSuffix,
mContainingAppId,
mSignedPkgOriginNoSuffix,
mIsMozBrowserElement));
mIsMozBrowserElement,
mPresentationURL));
}
static already_AddRefed<mozIApplication>
@ -261,6 +270,7 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
DocShellOriginAttributes originAttributes;
nsAutoCString originSuffix;
nsAutoCString signedPkgOriginNoSuffix;
nsAutoString presentationURL;
switch(aParams.type()) {
case IPCTabContext::TPopupIPCTabContext: {
@ -321,6 +331,7 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
isMozBrowserElement = ipcContext.isMozBrowserElement();
containingAppId = ipcContext.frameOwnerAppId();
signedPkgOriginNoSuffix = ipcContext.signedPkgOriginNoSuffix();
presentationURL = ipcContext.presentationURL();
originSuffix = ipcContext.originSuffix();
originAttributes.PopulateFromSuffix(originSuffix);
break;
@ -369,7 +380,8 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
ownApp,
containingApp,
originAttributes,
signedPkgOriginNoSuffix);
signedPkgOriginNoSuffix,
presentationURL);
if (!rv) {
mInvalidReason = "Couldn't initialize TabContext.";
}

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

@ -130,6 +130,12 @@ public:
*/
const nsACString& SignedPkgOriginNoSuffix() const;
/**
* Returns the presentation URL associated with the tab if this tab is
* created for presented content
*/
const nsAString& PresentationURL() const;
protected:
friend class MaybeInvalidTabContext;
@ -158,7 +164,8 @@ protected:
mozIApplication* aOwnApp,
mozIApplication* aAppFrameOwnerApp,
const DocShellOriginAttributes& aOriginAttributes,
const nsACString& aSignedPkgOriginNoSuffix);
const nsACString& aSignedPkgOriginNoSuffix,
const nsAString& aPresentationURL);
/**
* Modify this TabContext to match the given TabContext. This is a special
@ -215,6 +222,11 @@ private:
* doesn't own a signed package, this value would be empty.
*/
nsCString mSignedPkgOriginNoSuffix;
/**
* The requested presentation URL.
*/
nsString mPresentationURL;
};
/**
@ -235,13 +247,15 @@ public:
mozIApplication* aOwnApp,
mozIApplication* aAppFrameOwnerApp,
const DocShellOriginAttributes& aOriginAttributes,
const nsACString& aSignedPkgOriginNoSuffix = EmptyCString())
const nsACString& aSignedPkgOriginNoSuffix = EmptyCString(),
const nsAString& aPresentationURL = EmptyString())
{
return TabContext::SetTabContext(aIsMozBrowserElement,
aOwnApp,
aAppFrameOwnerApp,
aOriginAttributes,
aSignedPkgOriginNoSuffix);
aSignedPkgOriginNoSuffix,
aPresentationURL);
}
};