fune/netwerk/url-classifier/nsIChannelClassifierService.idl
Dimi Lee 86d87ef93e Bug 1639718 - P1. Add ChannelClassifierService to support notifying/unblocking channel. r=baku
ChannelClassifierService notifies "urlclassifier-before-block-channel"
event when a channel is going to be blocked by protection features.

It also provides an API for receivers to "unblock" the channel.

Sample usage:
this.service = Cc["@mozilla.org/url-classifier/channel-classifier-service;1"].getService(
  Ci.nsIChannelClassifierService
);
if (this.service) {
  this.service.addListener({
    observe(aSubject, aTopic, aData) {
      switch (aTopic) {
        case "urlclassifier-before-block-channel":
          let channel = aSubject.QueryInterface(Ci.nsIUrlClassifierBlockedChannel);
          channel.unblock();
          break;
      }
    },
  })
}

Differential Revision: https://phabricator.services.mozilla.com/D76836
2020-05-28 09:51:15 +00:00

50 lines
1.5 KiB
Text

/* 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/. */
#include "nsIContentPolicy.idl"
#include "nsISupports.idl"
interface nsIChannel;
interface nsIURI;
interface nsIObserver;
[scriptable, uuid(9b0353a7-ab46-4914-9178-2215ee221e4e)]
interface nsIUrlClassifierBlockedChannel: nsISupports
{
// blocked reason
const unsigned long TRACKING_PROTECTION = 0;
const unsigned long SOCIAL_TRACKING_PROTECTION = 1;
const unsigned long FINGERPRINTING_PROTECTION = 2;
const unsigned long CRYPTOMINING_PROTECTION = 3;
// Feature that blocks this channel.
readonly attribute uint8_t reason;
// Comma separated list of tables that find a match for the channel's url.
readonly attribute ACString tables;
readonly attribute AString url;
readonly attribute uint64_t tabId;
readonly attribute uint64_t channelId;
readonly attribute boolean isPrivateBrowsing;
readonly attribute AString topLevelUrl;
// Ask UrlClassifier to unblock the load.
void unblock();
};
[scriptable, uuid(9411409c-5dac-40b9-ba36-2738a7237a4c)]
interface nsIChannelClassifierService : nsISupports
{
// when a channel is blocked, the observer should receive
// "urlclassifier-before-block-channel" callback an alternative way is to
// use a custom callback instead of using nsIObserver
void addListener(in nsIObserver aObserver);
void removeListener(in nsIObserver aObserver);
};