blob: b436bc3f9edefb29b395f13c84aa75339ec23032 [file] [log] [blame] [view]
Sylvain Defresne1aa1703d2017-08-10 16:37:491
2# ApplicationContext
3
4ApplicationContext is a global singleton. It gives access to other global
5objects and settings that are shared by all user sessions. Those settings
6are called "local settings" as they are not synchronised and only affect
7the current device (as the settings are shared by all sessions there is
8no account to sync them to).
9
10The corresponding object on desktop is BrowserProcess.
11
Federica Germinariod731a3b2024-10-15 09:55:2912# ProfileIOS
Sylvain Defresne1aa1703d2017-08-10 16:37:4913
Federica Germinariod731a3b2024-10-15 09:55:2914ProfileIOS objects correspond to a user browsing session. There is
Sylvain Defresne1aa1703d2017-08-10 16:37:4915one for the off-the-record session, and one per user created in the UI (at
16the time this document is written, there is only one user on iOS so at most
Federica Germinariod731a3b2024-10-15 09:55:2917there are two ProfileIOSs).
Sylvain Defresne1aa1703d2017-08-10 16:37:4918
Federica Germinariod731a3b2024-10-15 09:55:2919The ProfileIOS objects are owned by the ProfileManagerIOS that can be
Sylvain Defresned268b28c2024-08-28 12:34:3720accessed via the ApplicationContext. It is possible to access the off-the-record
Federica Germinariod731a3b2024-10-15 09:55:2921ProfileIOS from a non-incognito instance.
Sylvain Defresne1aa1703d2017-08-10 16:37:4922
Federica Germinariod731a3b2024-10-15 09:55:2923Each ProfileIOS, including the off-the-record ProfileIOS,
Sylvain Defresne1aa1703d2017-08-10 16:37:4924have a directory used to store some state (current session, settings, ...).
25The settings may be synchronised if the user has logged in and has enabled
26the synchronisation (thus they are non-local).
27
Federica Germinariod731a3b2024-10-15 09:55:2928The off-the-record ProfileIOS needs to record some state because the
Sylvain Defresne1aa1703d2017-08-10 16:37:4929application can be killed at any time when the application is in the background
30and the state needs to be persisted as this termination should be transparent to
31the user. The state is deleted when the last off-the-record tab is closed
Federica Germinariod731a3b2024-10-15 09:55:2932and the off-the-record ProfileIOS is deleted.
Sylvain Defresne1aa1703d2017-08-10 16:37:4933
Federica Germinariod731a3b2024-10-15 09:55:2934The ProfileIOSs support attaching base::SupportsUserData::Data
35objects to tie some objects to the ProfileIOS lifetime. Check the
Sylvain Defresne1aa1703d2017-08-10 16:37:4936documentation of base::SupportsUserData for more information.
37
38A special case of base::SupportsUserData::Data is the KeyedService. They
Federica Germinariod731a3b2024-10-15 09:55:2939are managed by the ProfileKeyedServiceFactoryIOS infrastructure. This
Sylvain Defresne1aa1703d2017-08-10 16:37:4940infrastructure allows to declare dependencies between services and ensure
41that they are created and destroyed in an order compatible with those
42dependencies.
43
Federica Germinariod731a3b2024-10-15 09:55:2944It should never be required to extend ProfileIOS. Instead consider
Sylvain Defresne1aa1703d2017-08-10 16:37:4945adding a preference to the settings, a base::SupportsUserData::Data if the
46change is just to add some data or a KeyedService if behaviour needs to be
47added.
48
49The corresponding object on desktop is Profile.
50
51# BrowserList
52
53BrowserList is a container owning Browser instances. It is owned by the
Federica Germinariod731a3b2024-10-15 09:55:2954ProfileIOS and each ProfileIOS has one associated
Sylvain Defresne1aa1703d2017-08-10 16:37:4955BrowserList.
56
Sylvain Defresne165999e2017-09-06 21:53:1657The BrowserList owns the WebStateListDelegate that is passed to all the
58created Browsers (and then forwarded to their WebStateList).
59
Sylvain Defresne1aa1703d2017-08-10 16:37:4960The corresponding object on desktop is BrowserList but the API is
61different. On desktop, it is a singleton and it points to all the
Federica Germinariod731a3b2024-10-15 09:55:2962Browsers instances whereas on iOS there is one per ProfileIOS.
Sylvain Defresne1aa1703d2017-08-10 16:37:4963
64# Browser
65
66Browser is the model for a window containing multiple tabs. Currently
Federica Germinariod731a3b2024-10-15 09:55:2967on iOS there is only one window per ProfileIOS, thus there is
Sylvain Defresne1aa1703d2017-08-10 16:37:4968a single Browser per BrowserList.
69
70The Browser owns a WebStateList and thus indirectly owns all the tabs
Sylvain Defresne165999e2017-09-06 21:53:1671(aka WebState and their associated tab helpers). The Browser also owns
72the CommandDispatcher and ChromeBroadcaster used for dispatching UI
73commands and property synchronisation.
Sylvain Defresne1aa1703d2017-08-10 16:37:4974
75The corresponding object on desktop is Browser.
76
77# WebStateList
78
79WebStateList represents a list of WebStates. It maintains a notion of
80an active WebState and opener-opened relationship between WebStates.
81
82The WebStateList exposes an API to observe modification to the list of
83WebStates (additions, moves, removals, replacements).
84
85The WebStateList also has a delegate that is invoked when a WebState
Asami Doi9fc006b2023-08-24 14:11:0986is added to or removed from the WebStateList. This is used to attach
87all necessary tab helpers to the WebState.
Sylvain Defresne1aa1703d2017-08-10 16:37:4988
Sylvain Defresne1aa1703d2017-08-10 16:37:4989The corresponding object on desktop is TabStripModel.
90
Sylvain Defresne165999e2017-09-06 21:53:1691# WebStateListDelegate
92
93WebStateListDelegate is the delegate for WebStateList. It is invoked
Asami Doib60e22f732023-07-20 08:54:5194before a WebState is inserted to the WebStateList.
Sylvain Defresne165999e2017-09-06 21:53:1695
96Each WebStateList points to a WebStateListDelegate but does not own
97it to allow sharing the same delegate for multiple WebStateList. In
98general, the WebStateListDelegate role is to attach tab helpers to
99the WebState when it is added to the WebStateList (and optionally to
100shut them down).
101
102The corresponding object on desktop is TabStripModelDelegate.
103
Sylvain Defresne1aa1703d2017-08-10 16:37:49104# WebState
105
106WebState wraps a WKWebView and allows navigation. A WebState can have
107many tab helpers attached. A WebState in a WebStateList corresponds to
108an open tab and the corresponding tab helpers can be assumed to be
109created.
110
111As the tab helpers are only added to a WebState upon insertion into a
112WebStateList (or in a limited number of code paths), code should not
113assume that a tab helper will be available when using a WebState but
114instead should support the tab helper being unavailable.
115
116A WebState and all the attached tab helpers are sometimes called a
Mohammad Refaat7d71ee62019-07-30 15:14:19117tab because they implement what the user sees and interacts with in
118a browser tab.
Sylvain Defresne1aa1703d2017-08-10 16:37:49119
120The corresponding object on desktop is WebContents.