Bug 1806740 - Add API to expose hasRuleForBrowsingContext r=geckoview-reviewers,amejiamarmol,calu

Differential Revision: https://phabricator.services.mozilla.com/D167890
This commit is contained in:
owlishDeveloper 2023-02-27 17:25:10 +00:00
Родитель a12e5bfb99
Коммит 3bb59795be
5 изменённых файлов: 82 добавлений и 1 удалений

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

@ -919,6 +919,7 @@ package org.mozilla.geckoview {
method @AnyThread public void goForward();
method @AnyThread public void goForward(boolean);
method @AnyThread public void gotoHistoryIndex(int);
method @AnyThread @NonNull public GeckoResult<Boolean> hasCookieBannerRuleForBrowsingContextTree();
method @UiThread public boolean isOpen();
method @AnyThread @NonNull public GeckoResult<Boolean> isPdfJs();
method @AnyThread public void load(@NonNull GeckoSession.Loader);

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

@ -14,6 +14,7 @@ import org.json.JSONObject
import org.junit.Assume.assumeThat
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.geckoview.ContentBlocking.CookieBannerMode
import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.GeckoSession.ContentDelegate
@ -2062,4 +2063,58 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) {
sessionRule.waitForResult(result)
}
@Test fun checkCookieBannerRuleForSession() {
// set preferences. We have a cookie rule for example.com
val testRules = "[{\"id\":\"87815b2d-a840-4155-8713-f8a26d1f483a\",\"click\":{\"optOut\":\"#optOutBtn\",\"presence\": \"#cookieBanner\"},\"cookies\":{\"optOut\":[{\"name\":\"foo\", \"value\":\"bar\"}]}, \"domains\":[\"example.com\"]}]"
sessionRule.setPrefsUntilTestEnd(
mapOf(
"cookiebanners.service.mode" to CookieBannerMode.COOKIE_BANNER_MODE_REJECT,
"cookiebanners.listService.testSkipRemoteSettings" to true,
"cookiebanners.listService.testRules" to testRules,
"cookiebanners.service.detectOnly" to false
)
)
var prefs = sessionRule.getPrefs(
"cookiebanners.service.mode",
"cookiebanners.listService.testSkipRemoteSettings",
"cookiebanners.listService.testRules",
"cookiebanners.service.detectOnly"
)
assertThat("Cookie banner service mode should be correct", prefs[0] as Int, equalTo(1))
assertThat("Cookie banner remote settings should be skipped", prefs[1] as Boolean, equalTo(true))
assertThat("Cookie banner rule should be set", prefs[2] as String, equalTo(testRules))
assertThat("Cookie banner service should not be in detect only mode", prefs[3] as Boolean, equalTo(false))
// session 1 - load url for which there is no rule
mainSession.loadUri(HELLO_HTML_PATH)
sessionRule.waitForPageStop()
val response1 = mainSession.hasCookieBannerRuleForBrowsingContextTree()
sessionRule.waitForResult(response1).let {
assertThat("There should be no rule", it, equalTo(false))
}
// session 1 - load url for which there is a rule
mainSession.loadUri("http://example.com/")
sessionRule.waitForPageStop()
val response2 = mainSession.hasCookieBannerRuleForBrowsingContextTree()
sessionRule.waitForResult(response2).let {
assertThat("There should be a rule", it, equalTo(true))
}
// session 2 load url for which there is no rule
val session2 = sessionRule.createOpenSession()
session2.loadUri(HELLO_HTML_PATH)
sessionRule.waitForPageStop()
val response3 = session2.hasCookieBannerRuleForBrowsingContextTree()
sessionRule.waitForResult(response3).let {
assertThat("There should be no rule", it, equalTo(false))
}
// API shoul return the correct result for the page we have loaded in session 1
val response4 = mainSession.hasCookieBannerRuleForBrowsingContextTree()
sessionRule.waitForResult(response4).let {
assertThat("There should be a rule the second time", it, equalTo(true))
}
}
}

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

@ -2333,6 +2333,17 @@ public class GeckoSession {
return mFinder;
}
/**
* Checks whether we have a rule for this session. Uses the browsing context or any of its
* children, calls nsICookieBannerService.hasRuleForBrowsingContextTree
*
* @return {@link GeckoResult} with boolean
*/
@AnyThread
public @NonNull GeckoResult<Boolean> hasCookieBannerRuleForBrowsingContextTree() {
return mEventDispatcher.queryBoolean("GeckoView:HasCookieBannerRuleForBrowsingContextTree");
}
/**
* Get the SessionPdfFileSaver instance for this session, to save a pdf document.
*

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

@ -15,6 +15,9 @@ exclude: true
## v112
- Added `GeckoSession.LOAD_FLAGS_BYPASS_LOAD_URI_DELEGATE`, see ([bug 1809269]({{bugzilla}}1809269)).
- Added [`GeckoSession.hasCookieBannerRuleForBrowsingContextTree`][112.1] to expose Gecko API nsICookieBannerService::hasRuleForBrowsingContextTree see ([bug 1806740]({{bugzilla}}1806740))
[112.1]: {{javadoc_uri}}/GeckoSession.html#hasCookieBannerRuleForBrowsingContextTree()
## v111
@ -1321,4 +1324,4 @@ to allow adding gecko profiler markers.
[65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport(android.content.Context,android.os.Bundle,java.lang.String)
[65.25]: {{javadoc_uri}}/GeckoResult.html
[api-version]: e6608eb2026e3779678c2ae2b72b4abf403f73ca
[api-version]: 2eda8f8745bff92ab7b9462d550c91ca5f1dfa85

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

@ -17,6 +17,7 @@ class GeckoViewContent extends GeckoViewModule {
"GeckoView:ClearMatches",
"GeckoView:DisplayMatches",
"GeckoView:FindInPage",
"GeckoView:HasCookieBannerRuleForBrowsingContextTree",
"GeckoView:RestoreState",
"GeckoView:ContainsFormData",
"GeckoView:ScrollBy",
@ -193,6 +194,9 @@ class GeckoViewContent extends GeckoViewModule {
case "GeckoView:IsPdfJs":
aCallback.onSuccess(this.isPdfJs);
break;
case "GeckoView:HasCookieBannerRuleForBrowsingContextTree":
this._hasCookieBannerRuleForBrowsingContextTree(aCallback);
break;
}
}
@ -303,6 +307,13 @@ class GeckoViewContent extends GeckoViewModule {
aCallback.onSuccess(await this.actor.containsFormData());
}
async _hasCookieBannerRuleForBrowsingContextTree(aCallback) {
const { browsingContext } = this.actor;
aCallback.onSuccess(
Services.cookieBanners.hasRuleForBrowsingContextTree(browsingContext)
);
}
_findInPage(aData, aCallback) {
debug`findInPage: data=${aData} callback=${aCallback && "non-null"}`;