Backed out 2 changesets (bug 1561079, bug 1561913) for apilint and checkstyle failures CLOSED TREE

Backed out changeset c21bf3dfa6e5 (bug 1561913)
Backed out changeset 77ef4f2e0a8d (bug 1561079)
This commit is contained in:
Bogdan Tara 2019-07-24 18:34:06 +03:00
Родитель c230c12dae
Коммит 6d06c40c7c
3 изменённых файлов: 28 добавлений и 127 удалений

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

@ -1174,40 +1174,6 @@ class NavigationDelegateTest : BaseSessionTest() {
equalTo(referrer))
}
@Test fun loadUriReferrerSession() {
val uri = "https://example.com/bar"
val referrer = "https://example.org/foo"
sessionRule.session.loadUri(referrer)
sessionRule.session.waitForPageStop()
val newSession = sessionRule.createOpenSession()
newSession.loadUri(uri, sessionRule.session, GeckoSession.LOAD_FLAGS_NONE)
newSession.waitForPageStop()
assertThat("Referrer should match",
newSession.evaluateJS("document.referrer") as String,
equalTo(referrer))
}
@Test fun loadUriReferrerSessionFileUrl() {
val uri = "file:///system/etc/fonts.xml"
val referrer = "https://example.org"
sessionRule.session.loadUri(referrer)
sessionRule.session.waitForPageStop()
val newSession = sessionRule.createOpenSession()
newSession.loadUri(uri, sessionRule.session, GeckoSession.LOAD_FLAGS_NONE)
newSession.waitUntilCalled(object : Callbacks.NavigationDelegate {
@AssertCalled
override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult<String>? {
return null
}
})
}
@Test(expected = GeckoResult.UncaughtException::class)
fun onNewSession_doesNotAllowOpened() {
// Disable popup blocker.

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

@ -1534,7 +1534,7 @@ public class GeckoSession implements Parcelable {
*/
@AnyThread
public void loadUri(final @NonNull String uri) {
loadUri(uri, (GeckoSession)null, LOAD_FLAGS_NONE);
loadUri(uri, null, LOAD_FLAGS_NONE);
}
/**
@ -1545,7 +1545,7 @@ public class GeckoSession implements Parcelable {
*/
@AnyThread
public void loadUri(final @NonNull String uri, final @LoadFlags int flags) {
loadUri(uri, (GeckoSession)null, flags);
loadUri(uri, null, flags);
}
/**
@ -1563,29 +1563,7 @@ public class GeckoSession implements Parcelable {
msg.putInt("flags", flags);
if (referrer != null) {
msg.putString("referrerUri", referrer);
}
mEventDispatcher.dispatch("GeckoView:LoadUri", msg);
}
/**
* Load the given URI with the specified referrer and load type. This method will also do any
* applicable checks to ensure that the specified URI is both safe and allowable
* according to the referring GeckoSession.
*
* @param uri the URI to load
* @param referrer the referring GeckoSession, may be null
* @param flags the load flags to use, an OR-ed value of {@link #LOAD_FLAGS_NONE LOAD_FLAGS_*}
*/
@AnyThread
public void loadUri(final @NonNull String uri, final @Nullable GeckoSession referrer,
final @LoadFlags int flags) {
final GeckoBundle msg = new GeckoBundle();
msg.putString("uri", uri);
msg.putInt("flags", flags);
if (referrer != null) {
msg.putString("referrerSessionId", referrer.mId);
msg.putString("referrer", referrer);
}
mEventDispatcher.dispatch("GeckoView:LoadUri", msg);
}
@ -1606,7 +1584,7 @@ public class GeckoSession implements Parcelable {
*/
@AnyThread
public void loadUri(final @NonNull Uri uri, final @LoadFlags int flags) {
loadUri(uri.toString(), (GeckoSession)null, flags);
loadUri(uri.toString(), null, flags);
}
/**
@ -1635,7 +1613,7 @@ public class GeckoSession implements Parcelable {
throw new IllegalArgumentException("data cannot be null");
}
loadUri(createDataUri(data, mimeType), (GeckoSession)null, LOAD_FLAGS_NONE);
loadUri(createDataUri(data, mimeType), null, LOAD_FLAGS_NONE);
}
/**
@ -1650,8 +1628,8 @@ public class GeckoSession implements Parcelable {
if (bytes == null) {
throw new IllegalArgumentException("data cannot be null");
}
loadUri(createDataUri(bytes, mimeType), (GeckoSession)null, LOAD_FLAGS_FORCE_ALLOW_DATA_URI);
loadUri(createDataUri(bytes, mimeType), null, LOAD_FLAGS_FORCE_ALLOW_DATA_URI);
}
/**

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

@ -105,7 +105,7 @@ class GeckoViewNavigation extends GeckoViewModule {
this.browser.gotoIndex(aData.index);
break;
case "GeckoView:LoadUri":
const { uri, referrerUri, referrerSessionId, flags } = aData;
const { uri, referrer, flags } = aData;
let navFlags = 0;
@ -138,72 +138,34 @@ class GeckoViewNavigation extends GeckoViewModule {
this.moduleManager.updateRemoteTypeForURI(uri);
}
let triggeringPrincipal, referrerInfo, csp;
if (referrerSessionId) {
const referrerWindow = Services.ww.getWindowByName(
referrerSessionId,
this.window
);
triggeringPrincipal = referrerWindow.browser.contentPrincipal;
csp = referrerWindow.browser.csp;
const referrerPolicy = referrerWindow.browser.referrerInfo
? referrerWindow.browser.referrerInfo.referrerPolicy
: Ci.nsIHttpChannel.REFERRER_POLICY_UNSET;
referrerInfo = new ReferrerInfo(
referrerPolicy,
true,
referrerWindow.browser.documentURI
);
} else {
try {
const parsedUri = Services.io.newURI(uri);
if (
parsedUri.schemeIs("about") ||
parsedUri.schemeIs("data") ||
parsedUri.schemeIs("file") ||
parsedUri.schemeIs("resource") ||
parsedUri.schemeIs("moz-extension")
) {
// Only allow privileged loading for certain URIs.
triggeringPrincipal = Services.scriptSecurityManager.createContentPrincipal(
parsedUri,
{}
);
}
} catch (ignored) {}
referrerInfo = createReferrerInfo(referrerUri);
}
let parsedUri;
let triggeringPrincipal;
try {
parsedUri = Services.io.newURI(uri);
if (
parsedUri.schemeIs("about") ||
parsedUri.schemeIs("data") ||
parsedUri.schemeIs("file") ||
parsedUri.schemeIs("resource") ||
parsedUri.schemeIs("moz-extension")
) {
// Only allow privileged loading for certain URIs.
triggeringPrincipal = Services.scriptSecurityManager.createContentPrincipal(
parsedUri,
{}
);
}
} catch (ignored) {}
if (!triggeringPrincipal) {
triggeringPrincipal = Services.scriptSecurityManager.createNullPrincipal(
{}
);
}
// For any navigation here, we should have an appropriate triggeringPrincipal:
//
// 1) If we have a referring session, triggeringPrincipal is the contentPrincipal from the
// referring document.
// 2) For certain URI schemes listed above, we will have a codebase principal.
// 3) In all other cases, we create a NullPrincipal.
//
// The navigation flags are driven by the app. We purposely do not propagate these from
// the referring document, but expect that the app will in most cases.
//
// The referrerInfo is derived from the referring document, if present, by propagating any
// referrer policy. If we only have the referrerUri from the app, we create a referrerInfo
// with the specified URI and no policy set. If no referrerUri is present and we have no
// referring session, the referrerInfo is null.
//
// csp is only present if we have a referring document, null otherwise.
this.browser.loadURI(uri, {
this.browser.loadURI(parsedUri ? parsedUri.spec : uri, {
flags: navFlags,
referrerInfo,
referrerInfo: createReferrerInfo(referrer),
triggeringPrincipal,
csp,
});
break;
case "GeckoView:Reload":
@ -413,7 +375,6 @@ class GeckoViewNavigation extends GeckoViewModule {
aFlags,
aTriggeringPrincipal,
aCsp,
aReferrerInfo,
aNextRemoteTabId
) {
debug`handleOpenUri: uri=${aUri && aUri.spec}
@ -453,11 +414,9 @@ class GeckoViewNavigation extends GeckoViewModule {
return null;
}
// 3) We have a new session and a browser element, load the requested URI.
browser.loadURI(aUri.spec, {
triggeringPrincipal: aTriggeringPrincipal,
csp: aCsp,
referrerInfo: aReferrerInfo,
});
return browser;
}
@ -471,7 +430,6 @@ class GeckoViewNavigation extends GeckoViewModule {
aFlags,
aTriggeringPrincipal,
aCsp,
null,
null
);
return browser && browser.contentWindow;
@ -486,7 +444,6 @@ class GeckoViewNavigation extends GeckoViewModule {
aFlags,
aParams.triggeringPrincipal,
aParams.csp,
aParams.referrerInfo,
aNextRemoteTabId
);
return browser;