Configuring interaction with the Content Blocking API

How data is exchanged between the browser and the extension

  1. Yandex.Browser scans the manifests of all applications installed on the device. If your extension's manifest meets the requirements, the browser adds it to the list of extensions for blocking content.
  2. Your extension can open the content blocking settings in the user's browser by sending the corresponding Intent.
  3. After the user has chosen your extension in the settings, the browser caches the content blocking filters from the extension. Since filters are cached, the extension must promptly inform the browser of any changes to filters.
  4. The browser begins blocking content on web pages according to the filtering rules.

Configuring the extension's manifest

In order for Yandex.Browser to get filters from your extension:

  1. The content provider section in the AndroidManifest.xml file should look like this:

    <provider
       android:name="<package_name>.sampleContentProvider"       
       android:authorities="<package_name>.contentBlocker.contentProvider"       
       android:exported="true">       
    </provider>
    

    Attribute descriptions (all attributes are required):

    • android:name — Name of the data provider class in any format.

      Example:

      android:name="my.content.blocker.FiltersContentProvider"

    • android:authorities — The URI for the browser to access your ContentProvider. It must conform strictly to the pattern: <package_name>.contentBlocker.contentProvider.

      Example:

      android:authorities="my.content.blocker.contentBlocker.contentProvider"

    • android:exported — Defines whether your data is available to other applications. Set the value to true, implying that the filters are available to other applications.

      Example:

      android-exported="true"

  2. The AndroidManifest.xml file must include information about the version of the Content Blocker API:

    <meta-data android:name="com.samsung.android.sbrowser.contentBlocker.interfaceVersion" android:value="API_1.0" />
    

    Attribute descriptions (all attributes are required):

    • android:name — Metatag name. Must exactly match the name in the example (this is necessary for compatibility with Samsung Internet for Android).

      Example:

      android:name="com.samsung.android.sbrowser.contentBlocker.interfaceVersion"

    • android:value — Version number of the Content Blocker API for mobile browsers that the extension should work with.

      Example:

      android:value="API_1.0"

      Note

      The current version of the Content Blocker API is 1.0.

Updating filters

Yandex.Browser checks extension versions on each launch. If the extension version changed, the browser repeats the request for filters from the extension.

In order for filters in the browser cache to be updated without delay, the extension can notify the browser of updated filters immediately after they are changed.

To do this, send a Broadcast message with the Intent object in the format:

Intent intent = new Intent();       
       intent.setAction("com.samsung.android.sbrowser.contentBlocker.ACTION_UPDATE");       
       intent.setData(Uri.parse("package:<package_name>"));       
       sendBroadcast(intent);

Example:

Intent intent = new Intent();
       intent.setAction("com.samsung.android.sbrowser.contentBlocker.ACTION_UPDATE");
       intent.setData(Uri.parse("package:my.content.blocker"));
       sendBroadcast(intent);

More detailed about attributes:

Opening browser settings after installing the extension

Immediately after installation, your extension can open Yandex.Browser settings on the device and ask the user to select the extension for blocking content. To do this:

  1. Create an Intent and set the following string as the activity:

    intent.setAction("com.samsung.android.sbrowser.contentBlocker.ACTION_SETTING").

  2. Call the startActivity method for the Context class.

 Intent intent = new Intent();
       intent.setAction("com.samsung.android.sbrowser.contentBlocker.ACTION_SETTING");
       startActivity(intent);

More detailed about attributes: