Bug 1368046 - Part 2: Propagate OriginAttributes across processes for RecvCreateWindowInDifferentProcess, r=smaug

MozReview-Commit-ID: 8ok4DI9zgfR
This commit is contained in:
Michael Layzell 2017-06-06 14:22:17 -04:00
Родитель ac7ba92fd5
Коммит e9a9541ee7
12 изменённых файлов: 61 добавлений и 48 удалений

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

@ -12,7 +12,6 @@ NS_IMPL_ISUPPORTS(nsOpenURIInFrameParams, nsIOpenURIInFrameParams)
nsOpenURIInFrameParams::nsOpenURIInFrameParams(const mozilla::OriginAttributes& aOriginAttributes)
: mOpenerOriginAttributes(aOriginAttributes)
, mIsPrivate(false)
{
}
@ -37,14 +36,7 @@ NS_IMETHODIMP
nsOpenURIInFrameParams::GetIsPrivate(bool* aIsPrivate)
{
NS_ENSURE_ARG_POINTER(aIsPrivate);
*aIsPrivate = mIsPrivate;
return NS_OK;
}
NS_IMETHODIMP
nsOpenURIInFrameParams::SetIsPrivate(bool aIsPrivate)
{
mIsPrivate = aIsPrivate;
*aIsPrivate = mOpenerOriginAttributes.mPrivateBrowsingId > 0;
return NS_OK;
}

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

@ -25,5 +25,4 @@ private:
mozilla::OriginAttributes mOpenerOriginAttributes;
nsString mReferrer;
bool mIsPrivate;
};

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

@ -14,7 +14,7 @@ interface nsIFrameLoaderOwner;
interface nsIOpenURIInFrameParams : nsISupports
{
attribute DOMString referrer;
attribute boolean isPrivate;
readonly attribute boolean isPrivate;
[implicit_jscontext]
readonly attribute jsval openerOriginAttributes;

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

@ -684,8 +684,7 @@ ContentChild::ProvideWindow(mozIDOMWindowProxy* aParent,
static nsresult
GetWindowParamsFromParent(mozIDOMWindowProxy* aParent,
nsACString& aBaseURIString, float* aFullZoom,
OriginAttributes& aOriginAttributes)
nsACString& aBaseURIString, float* aFullZoom)
{
*aFullZoom = 1.0f;
auto* opener = nsPIDOMWindowOuter::From(aParent);
@ -708,8 +707,6 @@ GetWindowParamsFromParent(mozIDOMWindowProxy* aParent,
return NS_OK;
}
aOriginAttributes = openerDocShell->GetOriginAttributes();
nsCOMPtr<nsIContentViewer> cv;
nsresult rv = openerDocShell->GetContentViewer(getter_AddRefs(cv));
if (NS_SUCCEEDED(rv) && cv) {
@ -752,22 +749,22 @@ ContentChild::ProvideWindowCommon(TabChild* aTabOpener,
if (NS_SUCCEEDED(rv) && !shouldLoad) {
nsAutoCString baseURIString;
float fullZoom;
OriginAttributes originAttributes;
rv = GetWindowParamsFromParent(aParent, baseURIString, &fullZoom,
originAttributes);
rv = GetWindowParamsFromParent(aParent, baseURIString, &fullZoom);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
URIParams uriToLoad;
SerializeURI(aURI, uriToLoad);
Unused << SendCreateWindowInDifferentProcess(aTabOpener, aChromeFlags,
Unused << SendCreateWindowInDifferentProcess(aTabOpener,
aChromeFlags,
aCalledFromJS,
aPositionSpecified,
aSizeSpecified,
uriToLoad, features,
uriToLoad,
features,
baseURIString,
originAttributes, fullZoom);
fullZoom);
// We return NS_ERROR_ABORT, so that the caller knows that we've abandoned
// the window open as far as it is concerned.
@ -851,9 +848,7 @@ ContentChild::ProvideWindowCommon(TabChild* aTabOpener,
} else {
nsAutoCString baseURIString;
float fullZoom;
OriginAttributes originAttributes;
rv = GetWindowParamsFromParent(aParent, baseURIString, &fullZoom,
originAttributes);
rv = GetWindowParamsFromParent(aParent, baseURIString, &fullZoom);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -863,7 +858,6 @@ ContentChild::ProvideWindowCommon(TabChild* aTabOpener,
aSizeSpecified,
features,
baseURIString,
originAttributes,
fullZoom,
&rv,
aWindowIsNew,

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

@ -4409,7 +4409,6 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
nsIURI* aURIToLoad,
const nsCString& aFeatures,
const nsCString& aBaseURI,
const OriginAttributes& aOpenerOriginAttributes,
const float& aFullZoom,
uint64_t aNextTabParentId,
const nsString& aName,
@ -4475,22 +4474,24 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
MOZ_ASSERT(openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB ||
openLocation == nsIBrowserDOMWindow::OPEN_NEWWINDOW);
// Read the origin attributes for the tab from the opener tabParent.
OriginAttributes openerOriginAttributes;
if (thisTabParent) {
nsCOMPtr<nsILoadContext> loadContext = thisTabParent->GetLoadContext();
loadContext->GetOriginAttributes(openerOriginAttributes);
} else if (Preferences::GetBool("browser.privatebrowsing.autostart")) {
openerOriginAttributes.mPrivateBrowsingId = 1;
}
if (openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB) {
if (NS_WARN_IF(!browserDOMWin)) {
aResult = NS_ERROR_ABORT;
return IPC_OK();
}
bool isPrivate = false;
if (thisTabParent) {
nsCOMPtr<nsILoadContext> loadContext = thisTabParent->GetLoadContext();
loadContext->GetUsePrivateBrowsing(&isPrivate);
}
nsCOMPtr<nsIOpenURIInFrameParams> params =
new nsOpenURIInFrameParams(aOpenerOriginAttributes);
new nsOpenURIInFrameParams(openerOriginAttributes);
params->SetReferrer(NS_ConvertUTF8toUTF16(aBaseURI));
params->SetIsPrivate(isPrivate);
nsCOMPtr<nsIFrameLoaderOwner> frameLoaderOwner;
aResult = browserDOMWin->OpenURIInFrame(aURIToLoad, params, openLocation,
@ -4515,9 +4516,10 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
return IPC_OK();
}
aResult = pwwatch->OpenWindowWithTabParent(aSetOpener ? thisTabParent : nullptr,
aResult = pwwatch->OpenWindowWithTabParent(thisTabParent,
aFeatures, aCalledFromJS, aFullZoom,
aNextTabParentId,
!aSetOpener,
getter_AddRefs(aNewTabParent));
if (NS_WARN_IF(NS_FAILED(aResult))) {
return IPC_OK();
@ -4530,6 +4532,16 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
Unused << TabParent::GetFrom(aNewTabParent)->SendSetWindowName(aName);
}
// Don't send down the OriginAttributes if the content process is handling
// setting up the window for us. We only want to send them in the async case.
//
// If we send it down in the non-async case, then we might set the
// OriginAttributes after the document has already navigated.
if (!aSetOpener) {
Unused << TabParent::GetFrom(aNewTabParent)
->SendSetOriginAttributes(openerOriginAttributes);
}
if (aURIToLoad) {
nsCOMPtr<mozIDOMWindowProxy> openerWindow;
if (aSetOpener && thisTabParent) {
@ -4561,7 +4573,6 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
const bool& aSizeSpecified,
const nsCString& aFeatures,
const nsCString& aBaseURI,
const OriginAttributes& aOpenerOriginAttributes,
const float& aFullZoom,
nsresult* aResult,
bool* aWindowIsNew,
@ -4599,8 +4610,8 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
mozilla::ipc::IPCResult ipcResult =
CommonCreateWindow(aThisTab, /* aSetOpener = */ true, aChromeFlags,
aCalledFromJS, aPositionSpecified, aSizeSpecified,
nullptr, aFeatures, aBaseURI, aOpenerOriginAttributes,
aFullZoom, nextTabParentId, NullString(), *aResult,
nullptr, aFeatures, aBaseURI, aFullZoom,
nextTabParentId, NullString(), *aResult,
newRemoteTab, aWindowIsNew);
if (!ipcResult) {
return ipcResult;
@ -4640,7 +4651,6 @@ ContentParent::RecvCreateWindowInDifferentProcess(
const URIParams& aURIToLoad,
const nsCString& aFeatures,
const nsCString& aBaseURI,
const OriginAttributes& aOpenerOriginAttributes,
const float& aFullZoom,
const nsString& aName)
{
@ -4651,8 +4661,8 @@ ContentParent::RecvCreateWindowInDifferentProcess(
mozilla::ipc::IPCResult ipcResult =
CommonCreateWindow(aThisTab, /* aSetOpener = */ false, aChromeFlags,
aCalledFromJS, aPositionSpecified, aSizeSpecified,
uriToLoad, aFeatures, aBaseURI, aOpenerOriginAttributes,
aFullZoom, /* aNextTabParentId = */ 0, aName, rv,
uriToLoad, aFeatures, aBaseURI, aFullZoom,
/* aNextTabParentId = */ 0, aName, rv,
newRemoteTab, &windowIsNew);
if (!ipcResult) {
return ipcResult;

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

@ -535,7 +535,6 @@ public:
const bool& aSizeSpecified,
const nsCString& aFeatures,
const nsCString& aBaseURI,
const OriginAttributes& aOpenerOriginAttributes,
const float& aFullZoom,
nsresult* aResult,
bool* aWindowIsNew,
@ -555,7 +554,6 @@ public:
const URIParams& aURIToLoad,
const nsCString& aFeatures,
const nsCString& aBaseURI,
const OriginAttributes& aOpenerOriginAttributes,
const float& aFullZoom,
const nsString& aName) override;
@ -713,7 +711,6 @@ private:
nsIURI* aURIToLoad,
const nsCString& aFeatures,
const nsCString& aBaseURI,
const OriginAttributes& aOpenerOriginAttributes,
const float& aFullZoom,
uint64_t aNextTabParentId,
const nsString& aName,

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

@ -83,6 +83,7 @@ using mozilla::widget::CandidateWindowPosition from "ipc/nsGUIEventIPC.h";
using class mozilla::NativeEventData from "ipc/nsGUIEventIPC.h";
using mozilla::FontRange from "ipc/nsGUIEventIPC.h";
using mozilla::a11y::IAccessibleHolder from "mozilla/a11y/IPCTypes.h";
using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";
namespace mozilla {
namespace dom {
@ -895,6 +896,12 @@ child:
*/
async SetWindowName(nsString aName);
/**
* Tell the TabChild what OriginAttributes it should inherit from. This must
* be called before the first non-blank document is loaded in the TabChild.
*/
async SetOriginAttributes(OriginAttributes aOriginAttributes);
/*
* FIXME: write protocol!

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

@ -988,7 +988,6 @@ parent:
bool aSizeSpecified,
nsCString aFeatures,
nsCString aBaseURI,
OriginAttributes aOpenerOriginAttributes,
float aFullZoom)
returns (nsresult rv,
bool windowOpened,
@ -1008,7 +1007,6 @@ parent:
URIParams aURIToLoad,
nsCString aFeatures,
nsCString aBaseURI,
OriginAttributes aOpenerOriginAttributes,
float aFullZoom,
nsString aName);

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

@ -3168,6 +3168,15 @@ TabChild::RecvSetWindowName(const nsString& aName)
return IPC_OK();
}
mozilla::ipc::IPCResult
TabChild::RecvSetOriginAttributes(const OriginAttributes& aOriginAttributes)
{
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(WebNavigation());
nsDocShell::Cast(docShell)->SetOriginAttributes(aOriginAttributes);
return IPC_OK();
}
mozilla::plugins::PPluginWidgetChild*
TabChild::AllocPPluginWidgetChild()
{

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

@ -737,6 +737,8 @@ protected:
virtual mozilla::ipc::IPCResult RecvSetWindowName(const nsString& aName) override;
virtual mozilla::ipc::IPCResult RecvSetOriginAttributes(const OriginAttributes& aOriginAttributes) override;
private:
void HandleDoubleTap(const CSSPoint& aPoint, const Modifiers& aModifiers,
const ScrollableLayerGuid& aGuid);

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

@ -105,6 +105,9 @@ interface nsPIWindowWatcher : nsISupports
* @param aNextTabParentId
* The integer ID for the next tab parent actor.
* 0 means there is no next tab parent actor to use.
* @param aForceNoOpener
* If true, then aOpeningTab will not be used to set the opener
* for the newly created window.
*
* @return the nsITabParent of the initial browser for the newly opened
* window.
@ -113,7 +116,8 @@ interface nsPIWindowWatcher : nsISupports
in ACString aFeatures,
in boolean aCalledFromJS,
in float aOpenerFullZoom,
in unsigned long long aNextTabParentId);
in unsigned long long aNextTabParentId,
in boolean aForceNoOpener);
/**
* Find a named docshell tree item amongst all windows registered

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

@ -550,6 +550,7 @@ nsWindowWatcher::OpenWindowWithTabParent(nsITabParent* aOpeningTabParent,
bool aCalledFromJS,
float aOpenerFullZoom,
uint64_t aNextTabParentId,
bool aForceNoOpener,
nsITabParent** aResult)
{
MOZ_ASSERT(XRE_IsParentProcess());
@ -617,7 +618,7 @@ nsWindowWatcher::OpenWindowWithTabParent(nsITabParent* aOpeningTabParent,
nsCOMPtr<nsIWebBrowserChrome> newWindowChrome;
CreateChromeWindow(aFeatures, parentChrome, chromeFlags,
aOpeningTabParent, nullptr,
aForceNoOpener ? nullptr : aOpeningTabParent, nullptr,
aNextTabParentId,
getter_AddRefs(newWindowChrome));