Skip to content

Commit

Permalink
Merge pull request mozilla#11 from mozilla-b2g/revert-10-bug1234128
Browse files Browse the repository at this point in the history
Revert "Bug1234128"
  • Loading branch information
xeonchen committed Jun 1, 2016
2 parents 6b1d94f + 38aff5b commit a13bc21
Show file tree
Hide file tree
Showing 24 changed files with 254 additions and 237 deletions.
36 changes: 19 additions & 17 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2424,38 +2424,40 @@ Navigator::HasPresentationSupport(JSContext* aCx, JSObject* aGlobal)

// Grant access to browser receiving pages and their same-origin iframes. (App
// pages should be controlled by "presentation" permission in app manifests.)
nsCOMPtr<nsIDocShell> docshell = inner->GetDocShell();
if (!docshell) {
mozilla::dom::ContentChild* cc =
mozilla::dom::ContentChild::GetSingleton();
if (!cc || !cc->IsForBrowser()) {
return false;
}

if (!docshell->GetIsInMozBrowserOrApp()) {
nsCOMPtr<nsPIDOMWindowOuter> win = inner->GetOuterWindow();
nsCOMPtr<nsPIDOMWindowOuter> top = win->GetTop();
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(win);
nsCOMPtr<nsIScriptObjectPrincipal> topSop = do_QueryInterface(top);
if (!sop || !topSop) {
return false;
}

nsAutoString presentationURL;
nsContentUtils::GetPresentationURL(docshell, presentationURL);

if (presentationURL.IsEmpty()) {
nsIPrincipal* principal = sop->GetPrincipal();
nsIPrincipal* topPrincipal = topSop->GetPrincipal();
if (!principal || !topPrincipal || !principal->Subsumes(topPrincipal)) {
return false;
}

nsCOMPtr<nsIScriptSecurityManager> securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
if (!securityManager) {
nsCOMPtr<nsPIDOMWindowInner> topInner;
if (!(topInner = top->GetCurrentInnerWindow())) {
return false;
}

nsCOMPtr<nsIURI> presentationURI;
nsresult rv = NS_NewURI(getter_AddRefs(presentationURI), presentationURL);
if (NS_FAILED(rv)) {
nsCOMPtr<nsIPresentationService> presentationService =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!presentationService)) {
return false;
}

nsCOMPtr<nsIURI> docURI = inner->GetDocumentURI();
return NS_SUCCEEDED(securityManager->CheckSameOriginURI(presentationURI,
docURI,
false));
nsAutoString sessionId;
presentationService->GetExistentSessionIdAtLaunch(topInner->WindowID(), sessionId);
return !sessionId.IsEmpty();
}

/* static */
Expand Down
30 changes: 0 additions & 30 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMEvent.h"
#include "nsIDOMElement.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMHTMLInputElement.h"
Expand Down Expand Up @@ -204,7 +203,6 @@
#include "mozilla/EnumSet.h"
#include "mozilla/BloomFilter.h"
#include "SourceSurfaceRawData.h"
#include "TabChild.h"

#include "nsIBidiKeyboard.h"

Expand Down Expand Up @@ -8848,31 +8846,3 @@ 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);
}
6 changes: 0 additions & 6 deletions dom/base/nsContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2556,12 +2556,6 @@ class nsContentUtils

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();

Expand Down
8 changes: 1 addition & 7 deletions dom/base/nsFrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3234,18 +3234,12 @@ 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,
presentationURLStr);
signedPkgOrigin);
NS_ENSURE_STATE(tabContextUpdated);

return NS_OK;
Expand Down
1 change: 0 additions & 1 deletion dom/base/nsGkAtomList.h
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,6 @@ 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")
Expand Down
5 changes: 0 additions & 5 deletions dom/ipc/PTabContext.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ 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.
Expand Down
18 changes: 3 additions & 15 deletions dom/ipc/TabContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,12 @@ 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 nsAString& aPresentationURL)
const nsACString& aSignedPkgOriginNoSuffix)
{
NS_ENSURE_FALSE(mInitialized, false);

Expand Down Expand Up @@ -215,7 +208,6 @@ TabContext::SetTabContext(bool aIsMozBrowserElement,
mOwnApp = aOwnApp;
mContainingApp = aAppFrameOwnerApp;
mSignedPkgOriginNoSuffix = aSignedPkgOriginNoSuffix;
mPresentationURL = aPresentationURL;
return true;
}

Expand All @@ -227,8 +219,7 @@ TabContext::AsIPCTabContext() const
return IPCTabContext(FrameIPCTabContext(originSuffix,
mContainingAppId,
mSignedPkgOriginNoSuffix,
mIsMozBrowserElement,
mPresentationURL));
mIsMozBrowserElement));
}

static already_AddRefed<mozIApplication>
Expand All @@ -251,7 +242,6 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
DocShellOriginAttributes originAttributes;
nsAutoCString originSuffix;
nsAutoCString signedPkgOriginNoSuffix;
nsAutoString presentationURL;

switch(aParams.type()) {
case IPCTabContext::TPopupIPCTabContext: {
Expand Down Expand Up @@ -312,7 +302,6 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
isMozBrowserElement = ipcContext.isMozBrowserElement();
containingAppId = ipcContext.frameOwnerAppId();
signedPkgOriginNoSuffix = ipcContext.signedPkgOriginNoSuffix();
presentationURL = ipcContext.presentationURL();
originSuffix = ipcContext.originSuffix();
originAttributes.PopulateFromSuffix(originSuffix);
break;
Expand Down Expand Up @@ -361,8 +350,7 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
ownApp,
containingApp,
originAttributes,
signedPkgOriginNoSuffix,
presentationURL);
signedPkgOriginNoSuffix);
if (!rv) {
mInvalidReason = "Couldn't initialize TabContext.";
}
Expand Down
20 changes: 3 additions & 17 deletions dom/ipc/TabContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ class TabContext
*/
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;

Expand Down Expand Up @@ -164,8 +158,7 @@ class TabContext
mozIApplication* aOwnApp,
mozIApplication* aAppFrameOwnerApp,
const DocShellOriginAttributes& aOriginAttributes,
const nsACString& aSignedPkgOriginNoSuffix,
const nsAString& aPresentationURL);
const nsACString& aSignedPkgOriginNoSuffix);

private:
/**
Expand Down Expand Up @@ -211,11 +204,6 @@ class TabContext
* doesn't own a signed package, this value would be empty.
*/
nsCString mSignedPkgOriginNoSuffix;

/**
* The requested presentation URL.
*/
nsString mPresentationURL;
};

/**
Expand All @@ -236,15 +224,13 @@ class MutableTabContext : public TabContext
mozIApplication* aOwnApp,
mozIApplication* aAppFrameOwnerApp,
const DocShellOriginAttributes& aOriginAttributes,
const nsACString& aSignedPkgOriginNoSuffix = EmptyCString(),
const nsAString& aPresentationURL = EmptyString())
const nsACString& aSignedPkgOriginNoSuffix = EmptyCString())
{
return TabContext::SetTabContext(aIsMozBrowserElement,
aOwnApp,
aAppFrameOwnerApp,
aOriginAttributes,
aSignedPkgOriginNoSuffix,
aPresentationURL);
aSignedPkgOriginNoSuffix);
}
};

Expand Down
65 changes: 33 additions & 32 deletions dom/presentation/Presentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

#include "mozilla/dom/PresentationBinding.h"
#include "mozilla/dom/Promise.h"
#include "nsContentUtils.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIDocShell.h"
#include "nsIPresentationService.h"
#include "nsServiceManagerUtils.h"
#include "Presentation.h"
Expand All @@ -30,7 +28,7 @@ NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
Presentation::Create(nsPIDOMWindowInner* aWindow)
{
RefPtr<Presentation> presentation = new Presentation(aWindow);
return presentation.forget();
return NS_WARN_IF(!presentation->Init()) ? nullptr : presentation.forget();
}

Presentation::Presentation(nsPIDOMWindowInner* aWindow)
Expand All @@ -42,6 +40,37 @@ Presentation::~Presentation()
{
}

bool
Presentation::Init()
{
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
return false;
}

if (NS_WARN_IF(!GetOwner())) {
return false;
}

// Check if a receiver instance is required now. A session may already be
// connecting before the web content gets loaded in a receiving browsing
// context.
nsAutoString sessionId;
nsresult rv = service->GetExistentSessionIdAtLaunch(GetOwner()->WindowID(), sessionId);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
if (!sessionId.IsEmpty()) {
mReceiver = PresentationReceiver::Create(GetOwner(), sessionId);
if (NS_WARN_IF(!mReceiver)) {
return false;
}
}

return true;
}

/* virtual */ JSObject*
Presentation::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto)
Expand All @@ -63,36 +92,8 @@ Presentation::GetDefaultRequest() const
}

already_AddRefed<PresentationReceiver>
Presentation::GetReceiver()
Presentation::GetReceiver() const
{
// return the same receiver if already created
if (mReceiver) {
RefPtr<PresentationReceiver> receiver = mReceiver;
return receiver.forget();
}

if (!IsInPresentedContent()) {
return nullptr;
}

mReceiver = PresentationReceiver::Create(GetOwner());
if (NS_WARN_IF(!mReceiver)) {
MOZ_ASSERT(mReceiver);
return nullptr;
}

RefPtr<PresentationReceiver> receiver = mReceiver;
return receiver.forget();
}

bool
Presentation::IsInPresentedContent() const
{
nsCOMPtr<nsIDocShell> docShell = GetOwner()->GetDocShell();
MOZ_ASSERT(docShell);

nsAutoString presentationURL;
nsContentUtils::GetPresentationURL(docShell, presentationURL);

return !presentationURL.IsEmpty();
}
4 changes: 2 additions & 2 deletions dom/presentation/Presentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class Presentation final : public DOMEventTargetHelper

already_AddRefed<PresentationRequest> GetDefaultRequest() const;

already_AddRefed<PresentationReceiver> GetReceiver();
already_AddRefed<PresentationReceiver> GetReceiver() const;

private:
explicit Presentation(nsPIDOMWindowInner* aWindow);

~Presentation();

bool IsInPresentedContent() const;
bool Init();

RefPtr<PresentationRequest> mDefaultRequest;
RefPtr<PresentationReceiver> mReceiver;
Expand Down
Loading

0 comments on commit a13bc21

Please sign in to comment.