tree: 1a3af1087ee2ecbe2740877f31587d54364089da [path history] [tgz]
  1. BUILD.gn
  2. DEPS
  3. OWNERS
  4. pref_names.cc
  5. pref_names.h
  6. protocol_handler.cc
  7. protocol_handler.h
  8. protocol_handler_registry.cc
  9. protocol_handler_registry.h
  10. protocol_handler_registry_browsertest.cc
  11. protocol_handler_registry_unittest.cc
  12. protocol_handler_throttle.cc
  13. protocol_handler_throttle.h
  14. README.md
  15. register_protocol_handler_permission_request.cc
  16. register_protocol_handler_permission_request.h
  17. simple_protocol_handler_registry_factory.cc
  18. simple_protocol_handler_registry_factory.h
  19. test_protocol_handler_registry_delegate.cc
  20. test_protocol_handler_registry_delegate.h
components/custom_handlers/README.md

Custom Handlers

The custom handlers component provides a way to register custom protocol handlers for specific URL schemes. This is part of the implementation of the System state and capabilities defined in the HTML spec. Specifically, it implements the interface NavigatorContentUtils from which the Navigator object derives.

These handlers may be used to translate the http request's URL so that it is redirected to the appropriated service (e.g. email, apps) or a different http(s) site.

All the component's code is intended to be run by the Browser process, in the UI thread.

Security and privacy

The component addresses the security and privacy considerations described in the HTML spec.

A protocol handler is only valid if it passes all protocol handler parameters normalization steps. These security and privacy checks are:

Chromium defines a hierarchy of security levels to relax the restrictions imposed by the spec and allow the implementation of certain features. Being strict the default behavior and the one defined in the spec, there are levels for allowing untrusted-origins and schemes not listed in the mentioned safelist defined in the spec.

For instance, on order to make possible for extensions to register their own pages as handlers, the chrome-extension scheme is also allowed when security level is blink::ProtocolHandlerSecurityLevel::kExtensionFeatures.

It's also worth mentioned that Chromium defines its own kProtocolSafelist that includes some additional decentralized schemes that are not being explicitly defined in the mentioned.

High-level architecture

Browser

  +--------------------------------------------------------------------+
  | //components/custom_handlers                                       |
  |                                                                    |
  |                     +------------------------------------------+   |
  |                     | RegisterProtocolHandlerPermissionRequest |   |
  |                     +------------------------------------------+   |
  |                                                / \                 |
  |      +-----------------+                        |                  |
  |      | ProtocolHandler | <-------------+        |                  |
  |      +-----------------+               |        |                  |
  |              / \                       |        |                  |
  |               |                        |        |                  |
  |               |                        |        |                  |
  |               |                        |        |                  |
  |   +-------------------------+          |        |                  |
  |   | ProtocolHandlerRegistry | <--------+        |                  |
  |   +-------------------------+          |        |                  |
  |              / \                       |        |                  |
  |               |                        |        |                  |
  |               |                        |        |                  |
  +--------------------------------------------------------------------+
                  |                        |        |
                  |                        |        |
  +--------------------------------------------------------------------+
  | //chrome      |                        |        |                  |
  |               |                        |        |                  |
  | +--------------------------------+     |  +---------+              |    +--------------------------+
  | | ProtocolHandlerRegistryFactory | <----- | Browser | ----------------> | PermissionRequestManager |
  | +--------------------------------+        +---------+              |    +--------------------------+
  |                                                / \                 |
  |                                                 |                  |
  +--------------------------------------------------------------------+
                                                    |
  +--------------------------------------------------------------------+
  | //content                                       |                  |
  |                                                 |                 |
  |   +-----------------+            +---------------------+           |
  |   | WebContentsImpl | ---------> | WebContentsDelegate |           |
  |   +-----------------+            +---------------------+           |
  |          / \                                                       |
  |           |                                                        |
  |           |                                                        |
  |           |                                                        |
  |  +-------------------------+            +---------------------+    |
  |  | RenderFrameHostDelegate | <--------- | RenderFrameHostImpl |    |
  |  +-------------------------+            +---------------------+    |
  |                                                 |                  |
  |                                                 |                  |
  +--------------------------------------------------------------------+
                                                    |
                                                    |
+--------------------------------------------------------------------------------------------------------+
Renderer                                            |
                                                    |
  +--------------------------------------------------------------------+
  | //blink                                         |                  |
  |                                                 V                  |
  |  +-----------------------+       +------------------------------+  |
  |  | NavigatorContentUtils | ----> | mojom::blink::LocalFrameHost |  |
  |  +-----------------------+       +------------------------------+  |
  |                                                                    |
  +--------------------------------------------------------------------+

Here is a summary of the core responsibilities of the classes and interfaces:

  • ProtocolHandler

    It‘s the class responsible of the security and privacy validation mentioned before, and eventually of the http request’s URL translation, using the protocol handler's url spec.

  • ProtocolHandlerRegistry

    This class is implemented as a KeyedService which means it is attached to a BrowserContext.

    The registry holds different kind of protocol handlers lists, depending on their source during the registration: user or internal policies. The registry also provides an API to selectively ignore protocol handlers, which are managed in an independent list.

    There are also some predefined-handlers, which are automatically registered by the registry factory during the service's initialization.

    Finally there is a list of the default handlers for each protocol.

    All the protocol handlers managed by the registry are stored in the user preference storage, based on the user profile (the Browser Context) used to initialize the keyed service. This makes possible to guarantee the persistence of the protocol handlers state.

  • ProtocolHandlerThrottle

    It implements the blink's blink::URLLoaderThrottle interface to manage the http request. It holds a pointer to a ProtocolHandlerRegistry instance to performs the URL translation if there is a custom handler for the protocol used for the request.

  • RegisterProtocolHandlerPermissionRequest

    It implements the PermissionRequest interface to manage user authorization for the requests issued by the Navigator object's registerProtocolHandler() method. An instance of this class holds a pointer to a ProtocolHandlerRegistry instance and a ProtocolHandler reference to be registered.

    It performs the handler registration of granted, or adds it to the ignored list if denied.