Class ContentBlocking.SafeBrowsingProvider

Object
org.mozilla.geckoview.RuntimeSettings
org.mozilla.geckoview.ContentBlocking.SafeBrowsingProvider
All Implemented Interfaces:
Parcelable
Enclosing class:
ContentBlocking

@AnyThread public static class ContentBlocking.SafeBrowsingProvider extends RuntimeSettings
Holds configuration for a SafeBrowsing provider.

This class can be used to modify existing configuration for SafeBrowsing providers or to add a custom SafeBrowsing provider to the app.

Default configuration for Google's SafeBrowsing servers can be found at ContentBlocking.GOOGLE_SAFE_BROWSING_PROVIDER and ContentBlocking.GOOGLE_LEGACY_SAFE_BROWSING_PROVIDER.

This class is immutable, once constructed its values cannot be changed.

You can, however, use the from(org.mozilla.geckoview.ContentBlocking.SafeBrowsingProvider) method to build upon an existing configuration. For example to override the Google's server configuration, you can do the following:

     SafeBrowsingProvider override = SafeBrowsingProvider
         .from(ContentBlocking.GOOGLE_SAFE_BROWSING_PROVIDER)
         .getHashUrl("http://my-custom-server.com/...")
         .updateUrl("http://my-custom-server.com/...")
         .build();

     runtime.getContentBlocking().setSafeBrowsingProviders(override);
 
This will override the configuration.

You can also add a custom SafeBrowsing provider using the withName(java.lang.String) method. For example, to add a custom provider that provides the list testprovider-phish-digest256 do the following:

     SafeBrowsingProvider custom = SafeBrowsingProvider
         .withName("custom-provider")
         .version("2.2")
         .lists("testprovider-phish-digest256")
         .updateUrl("http://my-custom-server2.com/...")
         .getHashUrl("http://my-custom-server2.com/...")
         .build();
 
And then add the custom provider (adding optionally existing providers):

     runtime.getContentBlocking().setSafeBrowsingProviders(
         custom,
         // Add this if you want to keep the existing configuration too.
         ContentBlocking.GOOGLE_SAFE_BROWSING_PROVIDER,
         ContentBlocking.GOOGLE_LEGACY_SAFE_BROWSING_PROVIDER);
 
And set the list in the phishing configuration

     runtime.getContentBlocking().setSafeBrowsingPhishingTable(
          "testprovider-phish-digest256",
          // Existing configuration
          "goog-phish-proto");
 
Note that any list present in the phishing or malware tables need to appear in one safe browsing provider's getLists() property.

See also safe-browsing/v4.

  • Field Details

  • Method Details

    • withName

      @NonNull public static ContentBlocking.SafeBrowsingProvider.Builder withName(@NonNull String name)
      Creates a ContentBlocking.SafeBrowsingProvider.Builder for a provider with the given name.

      Note: the mozilla name is reserved for internal use, and this method will throw if you attempt to build a provider with that name.

      Parameters:
      name - The name of the provider.
      Returns:
      a ContentBlocking.SafeBrowsingProvider.Builder instance that can be used to build a provider.
      Throws:
      IllegalArgumentException - if this method is called with name="mozilla"
    • from

      Creates a ContentBlocking.SafeBrowsingProvider.Builder based on the given provider.

      All properties not otherwise specified will be copied from the provider given in input.

      Parameters:
      provider - The source provider for this builder.
      Returns:
      a ContentBlocking.SafeBrowsingProvider.Builder instance that can be used to create a configuration based on the builder in input.
    • getName

      @NonNull public String getName()
      Get the name of this provider.
      Returns:
      a string containing the name.
    • getVersion

      @Nullable public String getVersion()
      Get the version for this provider.
      Returns:
      a string representing the version, e.g. "2.2" or "4".
    • getLists

      @NonNull public String[] getLists()
      Get the lists provided by this provider.
      Returns:
      an array of string identifiers for the lists
    • getUpdateUrl

      @Nullable public String getUpdateUrl()
      Get the url that will be used to update the threat list for this provider.

      See also v4/threadListUpdates/fetch .

      Returns:
      a string containing the URL.
    • getGetHashUrl

      @Nullable public String getGetHashUrl()
      Get the url that will be used to get the full hashes that match a partial hash.

      See also v4/fullHashes/find .

      Returns:
      a string containing the URL.
    • getReportUrl

      @Nullable public String getReportUrl()
      Get the url that will be used to report a url to the SafeBrowsing provider.
      Returns:
      a string containing the URL.
    • getReportPhishingMistakeUrl

      @Nullable public String getReportPhishingMistakeUrl()
      Get the url that will be used to report a url mistakenly reported as Phishing to the SafeBrowsing provider.
      Returns:
      a string containing the URL.
    • getReportMalwareMistakeUrl

      @Nullable public String getReportMalwareMistakeUrl()
      Get the url that will be used to report a url mistakenly reported as Malware to the SafeBrowsing provider.
      Returns:
      a string containing the URL.
    • getAdvisoryUrl

      @Nullable public String getAdvisoryUrl()
      Get the url that will be used to give a general advisory about this SafeBrowsing provider.
      Returns:
      a string containing the URL.
    • getAdvisoryName

      @Nullable public String getAdvisoryName()
      Get the advisory name for this provider.
      Returns:
      a string containing the URL.
    • getDataSharingUrl

      @Nullable public String getDataSharingUrl()
      Get the url to share threat data to the provider, if enabled by getDataSharingEnabled().
      Returns:
      this ContentBlocking.SafeBrowsingProvider.Builder instance.
    • getDataSharingEnabled

      @Nullable public Boolean getDataSharingEnabled()
      Get whether to share threat data with the provider.
      Returns:
      true if the browser should whare threat data with the provider, false otherwise.
    • writeToParcel

      @AnyThread public void writeToParcel(Parcel out, int flags)
      Specified by:
      writeToParcel in interface Parcelable
      Overrides:
      writeToParcel in class RuntimeSettings