Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 1 | |
| 2 | # ApplicationContext |
| 3 | |
| 4 | ApplicationContext is a global singleton. It gives access to other global |
| 5 | objects and settings that are shared by all user sessions. Those settings |
| 6 | are called "local settings" as they are not synchronised and only affect |
| 7 | the current device (as the settings are shared by all sessions there is |
| 8 | no account to sync them to). |
| 9 | |
| 10 | The corresponding object on desktop is BrowserProcess. |
| 11 | |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 12 | # ProfileIOS |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 13 | |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 14 | ProfileIOS objects correspond to a user browsing session. There is |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 15 | one for the off-the-record session, and one per user created in the UI (at |
| 16 | the time this document is written, there is only one user on iOS so at most |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 17 | there are two ProfileIOSs). |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 18 | |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 19 | The ProfileIOS objects are owned by the ProfileManagerIOS that can be |
Sylvain Defresne | d268b28c | 2024-08-28 12:34:37 | [diff] [blame] | 20 | accessed via the ApplicationContext. It is possible to access the off-the-record |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 21 | ProfileIOS from a non-incognito instance. |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 22 | |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 23 | Each ProfileIOS, including the off-the-record ProfileIOS, |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 24 | have a directory used to store some state (current session, settings, ...). |
| 25 | The settings may be synchronised if the user has logged in and has enabled |
| 26 | the synchronisation (thus they are non-local). |
| 27 | |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 28 | The off-the-record ProfileIOS needs to record some state because the |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 29 | application can be killed at any time when the application is in the background |
| 30 | and the state needs to be persisted as this termination should be transparent to |
| 31 | the user. The state is deleted when the last off-the-record tab is closed |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 32 | and the off-the-record ProfileIOS is deleted. |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 33 | |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 34 | The ProfileIOSs support attaching base::SupportsUserData::Data |
| 35 | objects to tie some objects to the ProfileIOS lifetime. Check the |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 36 | documentation of base::SupportsUserData for more information. |
| 37 | |
| 38 | A special case of base::SupportsUserData::Data is the KeyedService. They |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 39 | are managed by the ProfileKeyedServiceFactoryIOS infrastructure. This |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 40 | infrastructure allows to declare dependencies between services and ensure |
| 41 | that they are created and destroyed in an order compatible with those |
| 42 | dependencies. |
| 43 | |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 44 | It should never be required to extend ProfileIOS. Instead consider |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 45 | adding a preference to the settings, a base::SupportsUserData::Data if the |
| 46 | change is just to add some data or a KeyedService if behaviour needs to be |
| 47 | added. |
| 48 | |
| 49 | The corresponding object on desktop is Profile. |
| 50 | |
| 51 | # BrowserList |
| 52 | |
| 53 | BrowserList is a container owning Browser instances. It is owned by the |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 54 | ProfileIOS and each ProfileIOS has one associated |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 55 | BrowserList. |
| 56 | |
Sylvain Defresne | 165999e | 2017-09-06 21:53:16 | [diff] [blame] | 57 | The BrowserList owns the WebStateListDelegate that is passed to all the |
| 58 | created Browsers (and then forwarded to their WebStateList). |
| 59 | |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 60 | The corresponding object on desktop is BrowserList but the API is |
| 61 | different. On desktop, it is a singleton and it points to all the |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 62 | Browsers instances whereas on iOS there is one per ProfileIOS. |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 63 | |
| 64 | # Browser |
| 65 | |
| 66 | Browser is the model for a window containing multiple tabs. Currently |
Federica Germinario | d731a3b | 2024-10-15 09:55:29 | [diff] [blame] | 67 | on iOS there is only one window per ProfileIOS, thus there is |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 68 | a single Browser per BrowserList. |
| 69 | |
| 70 | The Browser owns a WebStateList and thus indirectly owns all the tabs |
Sylvain Defresne | 165999e | 2017-09-06 21:53:16 | [diff] [blame] | 71 | (aka WebState and their associated tab helpers). The Browser also owns |
| 72 | the CommandDispatcher and ChromeBroadcaster used for dispatching UI |
| 73 | commands and property synchronisation. |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 74 | |
| 75 | The corresponding object on desktop is Browser. |
| 76 | |
| 77 | # WebStateList |
| 78 | |
| 79 | WebStateList represents a list of WebStates. It maintains a notion of |
| 80 | an active WebState and opener-opened relationship between WebStates. |
| 81 | |
| 82 | The WebStateList exposes an API to observe modification to the list of |
| 83 | WebStates (additions, moves, removals, replacements). |
| 84 | |
| 85 | The WebStateList also has a delegate that is invoked when a WebState |
Asami Doi | 9fc006b | 2023-08-24 14:11:09 | [diff] [blame] | 86 | is added to or removed from the WebStateList. This is used to attach |
| 87 | all necessary tab helpers to the WebState. |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 88 | |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 89 | The corresponding object on desktop is TabStripModel. |
| 90 | |
Sylvain Defresne | 165999e | 2017-09-06 21:53:16 | [diff] [blame] | 91 | # WebStateListDelegate |
| 92 | |
| 93 | WebStateListDelegate is the delegate for WebStateList. It is invoked |
Asami Doi | b60e22f73 | 2023-07-20 08:54:51 | [diff] [blame] | 94 | before a WebState is inserted to the WebStateList. |
Sylvain Defresne | 165999e | 2017-09-06 21:53:16 | [diff] [blame] | 95 | |
| 96 | Each WebStateList points to a WebStateListDelegate but does not own |
| 97 | it to allow sharing the same delegate for multiple WebStateList. In |
| 98 | general, the WebStateListDelegate role is to attach tab helpers to |
| 99 | the WebState when it is added to the WebStateList (and optionally to |
| 100 | shut them down). |
| 101 | |
| 102 | The corresponding object on desktop is TabStripModelDelegate. |
| 103 | |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 104 | # WebState |
| 105 | |
| 106 | WebState wraps a WKWebView and allows navigation. A WebState can have |
| 107 | many tab helpers attached. A WebState in a WebStateList corresponds to |
| 108 | an open tab and the corresponding tab helpers can be assumed to be |
| 109 | created. |
| 110 | |
| 111 | As the tab helpers are only added to a WebState upon insertion into a |
| 112 | WebStateList (or in a limited number of code paths), code should not |
| 113 | assume that a tab helper will be available when using a WebState but |
| 114 | instead should support the tab helper being unavailable. |
| 115 | |
| 116 | A WebState and all the attached tab helpers are sometimes called a |
Mohammad Refaat | 7d71ee6 | 2019-07-30 15:14:19 | [diff] [blame] | 117 | tab because they implement what the user sees and interacts with in |
| 118 | a browser tab. |
Sylvain Defresne | 1aa1703d | 2017-08-10 16:37:49 | [diff] [blame] | 119 | |
| 120 | The corresponding object on desktop is WebContents. |