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

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

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

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

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

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

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

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

@ -4409,7 +4409,6 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
nsIURI* aURIToLoad, nsIURI* aURIToLoad,
const nsCString& aFeatures, const nsCString& aFeatures,
const nsCString& aBaseURI, const nsCString& aBaseURI,
const OriginAttributes& aOpenerOriginAttributes,
const float& aFullZoom, const float& aFullZoom,
uint64_t aNextTabParentId, uint64_t aNextTabParentId,
const nsString& aName, const nsString& aName,
@ -4475,22 +4474,24 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
MOZ_ASSERT(openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB || MOZ_ASSERT(openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB ||
openLocation == nsIBrowserDOMWindow::OPEN_NEWWINDOW); 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 (openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB) {
if (NS_WARN_IF(!browserDOMWin)) { if (NS_WARN_IF(!browserDOMWin)) {
aResult = NS_ERROR_ABORT; aResult = NS_ERROR_ABORT;
return IPC_OK(); return IPC_OK();
} }
bool isPrivate = false;
if (thisTabParent) {
nsCOMPtr<nsILoadContext> loadContext = thisTabParent->GetLoadContext();
loadContext->GetUsePrivateBrowsing(&isPrivate);
}
nsCOMPtr<nsIOpenURIInFrameParams> params = nsCOMPtr<nsIOpenURIInFrameParams> params =
new nsOpenURIInFrameParams(aOpenerOriginAttributes); new nsOpenURIInFrameParams(openerOriginAttributes);
params->SetReferrer(NS_ConvertUTF8toUTF16(aBaseURI)); params->SetReferrer(NS_ConvertUTF8toUTF16(aBaseURI));
params->SetIsPrivate(isPrivate);
nsCOMPtr<nsIFrameLoaderOwner> frameLoaderOwner; nsCOMPtr<nsIFrameLoaderOwner> frameLoaderOwner;
aResult = browserDOMWin->OpenURIInFrame(aURIToLoad, params, openLocation, aResult = browserDOMWin->OpenURIInFrame(aURIToLoad, params, openLocation,
@ -4515,9 +4516,10 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
return IPC_OK(); return IPC_OK();
} }
aResult = pwwatch->OpenWindowWithTabParent(aSetOpener ? thisTabParent : nullptr, aResult = pwwatch->OpenWindowWithTabParent(thisTabParent,
aFeatures, aCalledFromJS, aFullZoom, aFeatures, aCalledFromJS, aFullZoom,
aNextTabParentId, aNextTabParentId,
!aSetOpener,
getter_AddRefs(aNewTabParent)); getter_AddRefs(aNewTabParent));
if (NS_WARN_IF(NS_FAILED(aResult))) { if (NS_WARN_IF(NS_FAILED(aResult))) {
return IPC_OK(); return IPC_OK();
@ -4530,6 +4532,16 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
Unused << TabParent::GetFrom(aNewTabParent)->SendSetWindowName(aName); 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) { if (aURIToLoad) {
nsCOMPtr<mozIDOMWindowProxy> openerWindow; nsCOMPtr<mozIDOMWindowProxy> openerWindow;
if (aSetOpener && thisTabParent) { if (aSetOpener && thisTabParent) {
@ -4561,7 +4573,6 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
const bool& aSizeSpecified, const bool& aSizeSpecified,
const nsCString& aFeatures, const nsCString& aFeatures,
const nsCString& aBaseURI, const nsCString& aBaseURI,
const OriginAttributes& aOpenerOriginAttributes,
const float& aFullZoom, const float& aFullZoom,
nsresult* aResult, nsresult* aResult,
bool* aWindowIsNew, bool* aWindowIsNew,
@ -4599,8 +4610,8 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
mozilla::ipc::IPCResult ipcResult = mozilla::ipc::IPCResult ipcResult =
CommonCreateWindow(aThisTab, /* aSetOpener = */ true, aChromeFlags, CommonCreateWindow(aThisTab, /* aSetOpener = */ true, aChromeFlags,
aCalledFromJS, aPositionSpecified, aSizeSpecified, aCalledFromJS, aPositionSpecified, aSizeSpecified,
nullptr, aFeatures, aBaseURI, aOpenerOriginAttributes, nullptr, aFeatures, aBaseURI, aFullZoom,
aFullZoom, nextTabParentId, NullString(), *aResult, nextTabParentId, NullString(), *aResult,
newRemoteTab, aWindowIsNew); newRemoteTab, aWindowIsNew);
if (!ipcResult) { if (!ipcResult) {
return ipcResult; return ipcResult;
@ -4640,7 +4651,6 @@ ContentParent::RecvCreateWindowInDifferentProcess(
const URIParams& aURIToLoad, const URIParams& aURIToLoad,
const nsCString& aFeatures, const nsCString& aFeatures,
const nsCString& aBaseURI, const nsCString& aBaseURI,
const OriginAttributes& aOpenerOriginAttributes,
const float& aFullZoom, const float& aFullZoom,
const nsString& aName) const nsString& aName)
{ {
@ -4651,8 +4661,8 @@ ContentParent::RecvCreateWindowInDifferentProcess(
mozilla::ipc::IPCResult ipcResult = mozilla::ipc::IPCResult ipcResult =
CommonCreateWindow(aThisTab, /* aSetOpener = */ false, aChromeFlags, CommonCreateWindow(aThisTab, /* aSetOpener = */ false, aChromeFlags,
aCalledFromJS, aPositionSpecified, aSizeSpecified, aCalledFromJS, aPositionSpecified, aSizeSpecified,
uriToLoad, aFeatures, aBaseURI, aOpenerOriginAttributes, uriToLoad, aFeatures, aBaseURI, aFullZoom,
aFullZoom, /* aNextTabParentId = */ 0, aName, rv, /* aNextTabParentId = */ 0, aName, rv,
newRemoteTab, &windowIsNew); newRemoteTab, &windowIsNew);
if (!ipcResult) { if (!ipcResult) {
return ipcResult; return ipcResult;

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

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

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

@ -83,6 +83,7 @@ using mozilla::widget::CandidateWindowPosition from "ipc/nsGUIEventIPC.h";
using class mozilla::NativeEventData from "ipc/nsGUIEventIPC.h"; using class mozilla::NativeEventData from "ipc/nsGUIEventIPC.h";
using mozilla::FontRange from "ipc/nsGUIEventIPC.h"; using mozilla::FontRange from "ipc/nsGUIEventIPC.h";
using mozilla::a11y::IAccessibleHolder from "mozilla/a11y/IPCTypes.h"; using mozilla::a11y::IAccessibleHolder from "mozilla/a11y/IPCTypes.h";
using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -895,6 +896,12 @@ child:
*/ */
async SetWindowName(nsString aName); 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! * FIXME: write protocol!

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

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

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

@ -3168,6 +3168,15 @@ TabChild::RecvSetWindowName(const nsString& aName)
return IPC_OK(); 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* mozilla::plugins::PPluginWidgetChild*
TabChild::AllocPPluginWidgetChild() TabChild::AllocPPluginWidgetChild()
{ {

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

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

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

@ -105,6 +105,9 @@ interface nsPIWindowWatcher : nsISupports
* @param aNextTabParentId * @param aNextTabParentId
* The integer ID for the next tab parent actor. * The integer ID for the next tab parent actor.
* 0 means there is no next tab parent actor to use. * 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 * @return the nsITabParent of the initial browser for the newly opened
* window. * window.
@ -113,7 +116,8 @@ interface nsPIWindowWatcher : nsISupports
in ACString aFeatures, in ACString aFeatures,
in boolean aCalledFromJS, in boolean aCalledFromJS,
in float aOpenerFullZoom, 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 * Find a named docshell tree item amongst all windows registered

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

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