2012-08-06 21:47:48 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-02-13 11:36:47 -08:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-08-06 21:47:48 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-12-12 08:05:00 -08:00
|
|
|
#include "mozilla/Assertions.h"
|
2015-09-23 01:10:21 -07:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2012-08-06 21:47:48 -07:00
|
|
|
#include "mozilla/LoadContext.h"
|
2015-10-26 13:05:13 -07:00
|
|
|
#include "mozilla/dom/ScriptSettings.h" // for AutoJSAPI
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "xpcpublic.h"
|
2012-08-06 21:47:48 -07:00
|
|
|
|
2015-10-26 13:05:13 -07:00
|
|
|
bool
|
|
|
|
nsILoadContext::GetOriginAttributes(mozilla::DocShellOriginAttributes& aAttrs)
|
|
|
|
{
|
|
|
|
mozilla::dom::AutoJSAPI jsapi;
|
|
|
|
bool ok = jsapi.Init(xpc::PrivilegedJunkScope());
|
|
|
|
NS_ENSURE_TRUE(ok, false);
|
|
|
|
JS::Rooted<JS::Value> v(jsapi.cx());
|
|
|
|
nsresult rv = GetOriginAttributes(&v);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
NS_ENSURE_TRUE(v.isObject(), false);
|
|
|
|
JS::Rooted<JSObject*> obj(jsapi.cx(), &v.toObject());
|
|
|
|
|
|
|
|
// If we're JS-implemented, the object will be left in a different (System-Principaled)
|
|
|
|
// scope, so we may need to enter its compartment.
|
|
|
|
MOZ_ASSERT(nsContentUtils::IsSystemPrincipal(nsContentUtils::ObjectPrincipal(obj)));
|
|
|
|
JSAutoCompartment ac(jsapi.cx(), obj);
|
|
|
|
|
|
|
|
mozilla::DocShellOriginAttributes attrs;
|
|
|
|
ok = attrs.Init(jsapi.cx(), v);
|
|
|
|
NS_ENSURE_TRUE(ok, false);
|
|
|
|
aAttrs = attrs;
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-17 18:55:57 -08:00
|
|
|
|
2012-08-06 21:47:48 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(LoadContext, nsILoadContext, nsIInterfaceRequestor)
|
2012-08-06 21:47:48 -07:00
|
|
|
|
2015-05-06 10:57:23 -07:00
|
|
|
LoadContext::LoadContext(nsIPrincipal* aPrincipal,
|
|
|
|
nsILoadContext* aOptionalBase)
|
2014-12-12 08:05:00 -08:00
|
|
|
: mTopFrameElement(nullptr)
|
|
|
|
, mNestedFrameId(0)
|
|
|
|
, mIsContent(true)
|
|
|
|
, mUsePrivateBrowsing(false)
|
|
|
|
, mUseRemoteTabs(false)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mIsNotNull(true)
|
|
|
|
#endif
|
|
|
|
{
|
2015-11-02 17:50:54 -08:00
|
|
|
PrincipalOriginAttributes poa = BasePrincipal::Cast(aPrincipal)->OriginAttributesRef();
|
2015-12-04 00:18:57 -08:00
|
|
|
mOriginAttributes.InheritFromDocToChildDocShell(poa);
|
2015-02-21 07:09:17 -08:00
|
|
|
|
|
|
|
if (!aOptionalBase) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(aOptionalBase->GetIsContent(&mIsContent)));
|
2015-05-06 10:57:23 -07:00
|
|
|
MOZ_ALWAYS_TRUE(
|
|
|
|
NS_SUCCEEDED(aOptionalBase->GetUsePrivateBrowsing(&mUsePrivateBrowsing)));
|
|
|
|
MOZ_ALWAYS_TRUE(
|
|
|
|
NS_SUCCEEDED(aOptionalBase->GetUseRemoteTabs(&mUseRemoteTabs)));
|
2014-12-12 08:05:00 -08:00
|
|
|
}
|
|
|
|
|
2012-08-06 21:47:48 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// LoadContext::nsILoadContext
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-01-30 09:05:36 -08:00
|
|
|
LoadContext::GetAssociatedWindow(mozIDOMWindowProxy**)
|
2012-08-06 21:47:48 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsNotNull);
|
|
|
|
|
|
|
|
// can't support this in the parent process
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-01-30 09:05:36 -08:00
|
|
|
LoadContext::GetTopWindow(mozIDOMWindowProxy**)
|
2012-08-06 21:47:48 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsNotNull);
|
|
|
|
|
|
|
|
// can't support this in the parent process
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2012-08-21 23:47:23 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
LoadContext::GetTopFrameElement(nsIDOMElement** aElement)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryReferent(mTopFrameElement);
|
|
|
|
element.forget(aElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-06-10 22:44:36 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
LoadContext::GetNestedFrameId(uint64_t* aId)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aId);
|
|
|
|
*aId = mNestedFrameId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-06 21:47:48 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
LoadContext::IsAppOfType(uint32_t, bool*)
|
2012-08-06 21:47:48 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsNotNull);
|
|
|
|
|
|
|
|
// don't expect we need this in parent (Thunderbird/SeaMonkey specific?)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
LoadContext::GetIsContent(bool* aIsContent)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsNotNull);
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsContent);
|
|
|
|
|
|
|
|
*aIsContent = mIsContent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
LoadContext::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsNotNull);
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aUsePrivateBrowsing);
|
|
|
|
|
|
|
|
*aUsePrivateBrowsing = mUsePrivateBrowsing;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
LoadContext::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsNotNull);
|
|
|
|
|
|
|
|
// We shouldn't need this on parent...
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2012-10-30 21:15:24 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
LoadContext::SetPrivateBrowsing(bool aUsePrivateBrowsing)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsNotNull);
|
|
|
|
|
|
|
|
// We shouldn't need this on parent...
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-02-11 09:00:54 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
LoadContext::GetUseRemoteTabs(bool* aUseRemoteTabs)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsNotNull);
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aUseRemoteTabs);
|
|
|
|
|
|
|
|
*aUseRemoteTabs = mUseRemoteTabs;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
LoadContext::SetRemoteTabs(bool aUseRemoteTabs)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsNotNull);
|
|
|
|
|
|
|
|
// We shouldn't need this on parent...
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2012-08-06 21:47:48 -07:00
|
|
|
NS_IMETHODIMP
|
2016-02-17 18:55:57 -08:00
|
|
|
LoadContext::GetIsInIsolatedMozBrowserElement(bool* aIsInIsolatedMozBrowserElement)
|
2012-08-06 21:47:48 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsNotNull);
|
|
|
|
|
2016-02-17 18:55:57 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsInIsolatedMozBrowserElement);
|
2012-08-06 21:47:48 -07:00
|
|
|
|
2016-02-17 18:55:57 -08:00
|
|
|
*aIsInIsolatedMozBrowserElement = mOriginAttributes.mInIsolatedMozBrowser;
|
2012-08-06 21:47:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
LoadContext::GetAppId(uint32_t* aAppId)
|
2012-08-06 21:47:48 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsNotNull);
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aAppId);
|
|
|
|
|
2015-09-23 01:10:21 -07:00
|
|
|
*aAppId = mOriginAttributes.mAppId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
LoadContext::GetOriginAttributes(JS::MutableHandleValue aAttrs)
|
|
|
|
{
|
|
|
|
JSContext* cx = nsContentUtils::GetCurrentJSContext();
|
|
|
|
MOZ_ASSERT(cx);
|
|
|
|
|
|
|
|
bool ok = ToJSValue(cx, mOriginAttributes, aAttrs);
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
|
2012-08-06 21:47:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-19 12:31:24 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// LoadContext::nsIInterfaceRequestor
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2015-02-13 11:36:37 -08:00
|
|
|
LoadContext::GetInterface(const nsIID& aIID, void** aResult)
|
2013-08-19 12:31:24 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = nullptr;
|
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsILoadContext))) {
|
|
|
|
*aResult = static_cast<nsILoadContext*>(this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2012-08-06 21:47:48 -07:00
|
|
|
} // namespace mozilla
|