Skip to content

Commit

Permalink
Bug 1567268 - [1.0] Report all ETP-related blocking and non-blocking.…
Browse files Browse the repository at this point in the history
… r=geckoview-reviewers,snorp,rbarker

Differential Revision: https://phabricator.services.mozilla.com/D40694
  • Loading branch information
Dylan Roeh committed Aug 9, 2019
1 parent 9ca10cd commit a7f5f26
Show file tree
Hide file tree
Showing 9 changed files with 490 additions and 322 deletions.
60 changes: 60 additions & 0 deletions mobile/android/chrome/geckoview/GeckoViewContentBlockingChild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const { GeckoViewChildModule } = ChromeUtils.import(
"resource://gre/modules/GeckoViewChildModule.jsm"
);

class GeckoViewContentBlockingChild extends GeckoViewChildModule {
onEnable() {
debug`onEnable`;

const flags = Ci.nsIWebProgress.NOTIFY_CONTENT_BLOCKING;
this.progressFilter = Cc[
"@mozilla.org/appshell/component/browser-status-filter;1"
].createInstance(Ci.nsIWebProgress);
this.progressFilter.addProgressListener(this, flags);
const webProgress = docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebProgress);
webProgress.addProgressListener(this.progressFilter, flags);
}

onContentBlockingEvent(aWebProgress, aRequest, aEvent) {
debug`onContentBlockingEvent ${aEvent.toString(16)}`;

if (!aRequest || !(aRequest instanceof Ci.nsIClassifiedChannel)) {
return;
}

const channel = aRequest.QueryInterface(Ci.nsIChannel);
const uri = channel.URI && channel.URI.spec;
const classChannel = aRequest.QueryInterface(Ci.nsIClassifiedChannel);

if (!uri) {
return;
}

debug`onContentBlockingEvent matchedList: ${classChannel.matchedList}`;
debug`onContentBlockingEvent matchedTrackingLists: ${
classChannel.matchedTrackingLists
}`;

const message = {
type: "GeckoView:ContentBlockingEvent",
uri: uri,
category: aEvent,
blockedList: classChannel.matchedList || null,
loadedLists: classChannel.matchedTrackingLists,
};

this.eventDispatcher.sendRequest(message);
}
}

const { debug, warn } = GeckoViewContentBlockingChild.initLogging(
"GeckoViewContentBlocking"
); // eslint-disable-line no-unused-vars
const module = GeckoViewContentBlockingChild.create(this);
3 changes: 2 additions & 1 deletion mobile/android/chrome/geckoview/geckoview.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ function startup() {
{
name: "GeckoViewContentBlocking",
onEnable: {
resource: "resource://gre/modules/GeckoViewContentBlocking.jsm",
frameScript:
"chrome://geckoview/content/GeckoViewContentBlockingChild.js",
},
},
{
Expand Down
1 change: 1 addition & 0 deletions mobile/android/chrome/geckoview/jar.mn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ geckoview.jar:
content/ErrorPageEventHandler.js
content/geckoview.xul
content/geckoview.js
content/GeckoViewContentBlockingChild.js
content/GeckoViewContentChild.js
content/GeckoViewMediaChild.js
content/GeckoViewNavigationChild.js
Expand Down
80 changes: 51 additions & 29 deletions mobile/android/geckoview/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,58 +130,80 @@ package org.mozilla.geckoview {

@AnyThread public class ContentBlocking {
ctor public ContentBlocking();
field public static final int AT_AD = 2;
field public static final int AT_ANALYTIC = 4;
field public static final int AT_CONTENT = 16;
field public static final int AT_CRYPTOMINING = 64;
field public static final int AT_DEFAULT = 46;
field public static final int AT_FINGERPRINTING = 128;
field public static final int AT_SOCIAL = 8;
field public static final int AT_STRICT = 254;
field public static final int AT_TEST = 32;
field public static final int CB_DEFAULT = 15406;
field public static final int CB_STRICT = 15614;
field public static final int COOKIE_ACCEPT_ALL = 0;
field public static final int COOKIE_ACCEPT_FIRST_PARTY = 1;
field public static final int COOKIE_ACCEPT_NONE = 2;
field public static final int COOKIE_ACCEPT_NON_TRACKERS = 4;
field public static final int COOKIE_ACCEPT_VISITED = 3;
field public static final int COOKIE_LIFETIME_DAYS = 3;
field public static final int COOKIE_LIFETIME_NORMAL = 0;
field public static final int COOKIE_LIFETIME_RUNTIME = 2;
}

public static class ContentBlocking.AntiTracking {
ctor protected AntiTracking();
field public static final int AD = 2;
field public static final int ANALYTIC = 4;
field public static final int CONTENT = 16;
field public static final int CRYPTOMINING = 64;
field public static final int DEFAULT = 46;
field public static final int FINGERPRINTING = 128;
field public static final int NONE = 0;
field public static final int SB_ALL = 15360;
field public static final int SB_HARMFUL = 4096;
field public static final int SB_MALWARE = 1024;
field public static final int SB_PHISHING = 8192;
field public static final int SB_UNWANTED = 2048;
field public static final int SOCIAL = 8;
field public static final int STRICT = 254;
field public static final int TEST = 32;
}

public static class ContentBlocking.BlockEvent {
ctor public BlockEvent(@NonNull String, int);
field public final int categories;
ctor public BlockEvent(@NonNull String, int, int, int, boolean);
method @UiThread public int getAntiTrackingCategory();
method @UiThread public int getCookieBehaviorCategory();
method @UiThread public int getSafeBrowsingCategory();
method @UiThread public boolean isBlocking();
field @NonNull public final String uri;
}

public static class ContentBlocking.CookieBehavior {
ctor protected CookieBehavior();
field public static final int ACCEPT_ALL = 0;
field public static final int ACCEPT_FIRST_PARTY = 1;
field public static final int ACCEPT_NONE = 2;
field public static final int ACCEPT_NON_TRACKERS = 4;
field public static final int ACCEPT_VISITED = 3;
}

public static class ContentBlocking.CookieLifetime {
ctor protected CookieLifetime();
field public static final int DAYS = 3;
field public static final int NORMAL = 0;
field public static final int RUNTIME = 2;
}

public static interface ContentBlocking.Delegate {
method @UiThread default public void onContentBlocked(@NonNull GeckoSession, @NonNull ContentBlocking.BlockEvent);
method @UiThread default public void onContentLoaded(@NonNull GeckoSession, @NonNull ContentBlocking.BlockEvent);
}

public static class ContentBlocking.SafeBrowsing {
ctor protected SafeBrowsing();
field public static final int DEFAULT = 15360;
field public static final int HARMFUL = 4096;
field public static final int MALWARE = 1024;
field public static final int NONE = 0;
field public static final int PHISHING = 8192;
field public static final int UNWANTED = 2048;
}

@AnyThread public static class ContentBlocking.Settings extends RuntimeSettings {
method public int getCategories();
method public int getAntiTrackingCategories();
method public int getCookieBehavior();
method public int getCookieLifetime();
method @NonNull public ContentBlocking.Settings setCategories(int);
method public int getSafeBrowsingCategories();
method @NonNull public ContentBlocking.Settings setAntiTracking(int);
method @NonNull public ContentBlocking.Settings setCookieBehavior(int);
method @NonNull public ContentBlocking.Settings setCookieLifetime(int);
method @NonNull public ContentBlocking.Settings setSafeBrowsing(int);
field public static final Parcelable.Creator<ContentBlocking.Settings> CREATOR;
}

@AnyThread public static class ContentBlocking.Settings.Builder extends RuntimeSettings.Builder {
ctor public Builder();
method @NonNull public ContentBlocking.Settings.Builder categories(int);
method @NonNull public ContentBlocking.Settings.Builder antiTracking(int);
method @NonNull public ContentBlocking.Settings.Builder cookieBehavior(int);
method @NonNull public ContentBlocking.Settings.Builder cookieLifetime(int);
method @NonNull public ContentBlocking.Settings.Builder safeBrowsing(int);
method @NonNull protected ContentBlocking.Settings newSettings(@Nullable ContentBlocking.Settings);
}

Expand Down
Loading

0 comments on commit a7f5f26

Please sign in to comment.