blob: b34e19ceb1bdb9447009bd3384c50969b8819385 [file] [log] [blame] [view]
Daniel Murphyf296b362022-11-17 22:06:161# [Web Apps](README.md) - Operating System Integration
Fabio Rocha1c346192021-02-12 05:07:162
Daniel Murphyf296b362022-11-17 22:06:163The WebAppProvider system has to provide a lot of integrations with operating system surfaces for web apps. This functionality is usually different per operating system, and is usually invoked through the [`OsIntegrationManager`][2].
Daniel Murphy11adede82021-06-03 15:05:064
Daniel Murphyf296b362022-11-17 22:06:165The [`OsIntegrationManager`][2]'s main responsibility is support the following operations:
Daniel Murphy11adede82021-06-03 15:05:0661. Install operating system integration for a given web app.
71. Update operating system integration for a given web app.
81. Uninstall/remove operating system integration for a given web app.
9
Daniel Murphyf296b362022-11-17 22:06:1610It owns sub-managers who are responsible for each individual operating system integration functionality (e.g. [`web_app_file_handler_manager.h`][1] which owns the file handling feature). That manager will implement the non-os-specific logic, and then call into functions that have os-specific implementations (e.g. `web_app_file_handler_registration.h/_mac.h/_win.h/_linux.h` files).
Daniel Murphy11adede82021-06-03 15:05:0611
12Below are sections describing how each OS integration works.
Fabio Rocha1c346192021-02-12 05:07:1613
14## Protocol Handler
15
16The Protocol Handler component is responsible for handling the registration and
17unregistration of custom protocols for web apps ([explainer](https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/URLProtocolHandler/explainer.md)).
18
Song Fangzhen8333d7b2021-09-03 08:23:2619### WebAppProtocolHandlerManager
Fabio Rocha1c346192021-02-12 05:07:1620
Song Fangzhen8333d7b2021-09-03 08:23:2621The entrypoint to the component is `web_app_protocol_handler_manager.cc`, which contains
Fabio Rocha1c346192021-02-12 05:07:1622methods for registering and unregistering custom protocol handlers for web apps,
23as well as any other logic related to protocol handling that should be
24OS-agnostic - such as URL translation (translating from a protocol URL to a web
25app URL) and interactions with the `ProtocolHandlerRegistry`, the browser
26component that stores information about handlers internally.
27
Song Fangzhen8333d7b2021-09-03 08:23:2628`WebAppProtocolHandlerManager` is also responsible for leveraging the
Fabio Rocha1c346192021-02-12 05:07:1629web_app_protocol_handler_registration API to register and unregister protocols
30with the underlying OS, so that custom protocols for a web app can be used
31from outside the browser.
32
33### web_app_protocol_handler_registration
34`web_app_protocol_handler_registration` exposes a simple API that has
35OS-specific files / implementations. This API communicates with other components
36responsible for directly managing OS integrations. For example, on Windows this
37interacts with the `ShellUtil` class, which manages the interactions with the
38Windows registry for us.
39
40Since some of these interactions with the OSes can be a bit costly, we try to do
41as much as possible off the main thread. For the Windows implementation, we
42post a task and wait for confirmation before proceeding with other steps (such
43as updating the browser internal registry).
44
45### ProtocolHandlerRegistry
46Protocol handlers, like other Web App features, interact both with the OS and
47the browser. On the browser, `protocol_handler_registry.cc` stores and manages
48all protocol handler registrations, for both web apps and web sites (registered
Song Fangzhen8333d7b2021-09-03 08:23:2649via the HTML5 `registerProtocolHandler` API). The `WebAppProtocolHandlerManager` is
Fabio Rocha1c346192021-02-12 05:07:1650responsible for keeping both the OS and the browser in sync, by ensuring OS
51changes are reflected in the browser registry accordingly.
52
53### Flow of execution for a protocol registration call (Windows)
54
55The flow of execution is similar for both registrations and unregistrations, so
56we only describe registrations below.
57
581) Other components (typically the `OSIntegrationManager`) call into
Song Fangzhen8333d7b2021-09-03 08:23:2659WebAppProtocolHandlerManager:
Fabio Rocha1c346192021-02-12 05:07:1660
61```cpp
62protocol_handler_manager_->RegisterOsProtocolHandlers(app_id);
63```
64
Song Fangzhen8333d7b2021-09-03 08:23:26652) `WebAppProtocolHandlerManager` forwards that to
Fabio Rocha1c346192021-02-12 05:07:1666`web_app_protocol_handler_registration`, which is OS specific. That API registers
67protocols with the OS via `ShellUtil` utilities off the main thread:
68
69```cpp
70base::ThreadPool::PostTaskAndReply(
71 FROM_HERE,
72 {base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
73 base::BindOnce(&RegisterProtocolHandlersWithOSInBackground, app_id,
74 base::UTF8ToUTF16(app_name), profile, profile->GetPath(),
75 protocol_handlers, app_name_extension),
76 base::BindOnce(&CheckAndUpdateExternalInstallations, profile->GetPath(),
77 app_id));
78```
79
803) Once the protocols are registered successfully, a callback is invoked inside
81`RegisterProtocolHandlersWithOSInBackground` which then completes the
82registration with the `ProtocolHandlerRegistry`.
83
84```cpp
85ProtocolHandlerRegistry* registry =
86 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile);
87
88registry->RegisterAppProtocolHandlers(app_id, protocol_handlers);
89```
90
914) `CheckAndUpdateExternalInstallations` is then called as the reply to the task
92in 2) and checks if there is an installation of this app in another profile that
93needs to be updated with a profile specific name and executes required update.
94
95
Daniel Murphyf296b362022-11-17 22:06:1696[1]: /chrome/browser/web_applications/os_integration/web_app_file_handler_manager.h
97[2]: /chrome/browser/web_applications/os_integration/os_integration_manager.h