Bug 832700 - Add private browsing to b2g, API implementation r=ehsan,smaug

This commit is contained in:
Fabrice Desré 2014-10-10 14:28:04 -07:00
parent 012100ceed
commit 5788a6960b
7 changed files with 41 additions and 2 deletions

View File

@ -609,6 +609,7 @@ GK_ATOM(mozfullscreenerror, "mozfullscreenerror")
GK_ATOM(mozpasspointerevents, "mozpasspointerevents")
GK_ATOM(mozpointerlockchange, "mozpointerlockchange")
GK_ATOM(mozpointerlockerror, "mozpointerlockerror")
GK_ATOM(mozprivatebrowsing, "mozprivatebrowsing")
GK_ATOM(moz_opaque, "moz-opaque")
GK_ATOM(moz_action_hint, "mozactionhint")
GK_ATOM(x_moz_errormessage, "x-moz-errormessage")

View File

@ -851,6 +851,7 @@ nsDocShell::nsDocShell():
#endif
mAffectPrivateSessionLifetime(true),
mInvisible(false),
mHasLoadedNonBlankURI(false),
mDefaultLoadFlags(nsIRequest::LOAD_NORMAL),
mFrameType(eFrameTypeRegular),
mOwnOrContainingAppId(nsIScriptSecurityManager::UNKNOWN_APP_ID),
@ -1928,6 +1929,10 @@ nsDocShell::SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest,
mCurrentURI = NS_TryToMakeImmutable(aURI);
if (!NS_IsAboutBlank(mCurrentURI)) {
mHasLoadedNonBlankURI = true;
}
bool isRoot = false; // Is this the root docshell
bool isSubFrame = false; // Is this a subframe navigation?
@ -2277,6 +2282,15 @@ nsDocShell::SetPrivateBrowsing(bool aUsePrivateBrowsing)
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetHasLoadedNonBlankURI(bool* aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mHasLoadedNonBlankURI;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetUseRemoteTabs(bool* aUseRemoteTabs)
{

View File

@ -915,6 +915,7 @@ protected:
#endif
bool mAffectPrivateSessionLifetime;
bool mInvisible;
bool mHasLoadedNonBlankURI;
uint64_t mHistoryID;
uint32_t mDefaultLoadFlags;

View File

@ -54,7 +54,7 @@ interface nsITabParent;
typedef unsigned long nsLoadFlags;
[scriptable, builtinclass, uuid(2b8e4a50-7744-454d-a05b-debead8070fe)]
[scriptable, builtinclass, uuid(23157a63-26fd-44a0-a0f9-fdc64dcc004c)]
interface nsIDocShell : nsIDocShellTreeItem
{
/**
@ -1017,4 +1017,11 @@ interface nsIDocShell : nsIDocShellTreeItem
// URLSearchParams for the window.location is owned by the docShell.
[noscript,notxpcom] URLSearchParams getURLSearchParams();
/**
* This attribute determines whether a document which is not about:blank has
* already be loaded by this docShell.
*/
[infallible] readonly attribute boolean hasLoadedNonBlankURI;
};

View File

@ -56,3 +56,10 @@ let infos = sendSyncMessage('browser-element-api:call',
{ 'msg_name': 'hello' })[0];
docShell.QueryInterface(Ci.nsIDocShellTreeItem).name = infos.name;
docShell.setFullscreenAllowed(infos.fullscreenAllowed);
if (infos.isPrivate) {
if (docShell.hasLoadedNonBlankURI) {
Cu.reportError("We should not switch to Private Browsing after loading a document.");
} else {
docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = true;
}
}

View File

@ -76,6 +76,14 @@ CreateIframe(Element* aOpenerFrameElement, const nsAString& aName, bool aRemote)
NS_LITERAL_STRING("false"),
/* aNotify = */ false);
// Copy the opener frame's mozprivatebrowsing attribute to the popup frame.
nsAutoString mozprivatebrowsing;
if (aOpenerFrameElement->GetAttr(kNameSpaceID_None, nsGkAtoms::mozprivatebrowsing,
mozprivatebrowsing)) {
popupFrameElement->SetAttr(kNameSpaceID_None, nsGkAtoms::mozprivatebrowsing,
mozprivatebrowsing, /* aNotify = */ false);
}
return popupFrameElement.forget();
}

View File

@ -389,7 +389,8 @@ BrowserElementParent.prototype = {
name: this._frameElement.getAttribute('name'),
fullscreenAllowed:
this._frameElement.hasAttribute('allowfullscreen') ||
this._frameElement.hasAttribute('mozallowfullscreen')
this._frameElement.hasAttribute('mozallowfullscreen'),
isPrivate: this._frameElement.hasAttribute('mozprivatebrowsing')
};
},