Skip to content

Commit

Permalink
Update readme files that mention the old Tab class.
Browse files Browse the repository at this point in the history
TBR=marq@chromium.org

Change-Id: I4379fe780d4365b9857a9e3a8b692112152b32df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1726091
Reviewed-by: Mohammad Refaat <mrefaat@chromium.org>
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682280}
  • Loading branch information
mrefaat88 authored and Commit Bot committed Jul 30, 2019
1 parent e4e6979 commit 7d71ee6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
6 changes: 2 additions & 4 deletions docs/ios/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ assume that a tab helper will be available when using a WebState but
instead should support the tab helper being unavailable.

A WebState and all the attached tab helpers are sometimes called a
tab (because they implement what the user sees and interacts with in
a browser tab). There currently is a Tab interface but it is a legacy
object that is deprecated and is slowly being removed. If possible,
prefer to use WebState directly instead of Tab.
tab because they implement what the user sees and interacts with in
a browser tab.

The corresponding object on desktop is WebContents.
28 changes: 5 additions & 23 deletions ios/chrome/browser/tabs/tab_lifecycle.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
# `Tab` lifecycle

`LegacyTabHelper` creates `Tab` and keep it retained. `AttachTabHelpers`
creates `LegacyTabHelper` first and then all the other tab helpers. The
`AttachTabHelpers` method can be invoked on a newly created `WebState`.

From that point, `LegacyTabHelper::GetTabFromWebState()` will return the
`Tab` associated with `WebState`. That method will return `nil` before
the call to `AttachTabHelpers`.
`Tab` is a virtual concept that refers to the` WebState` UI. A `WebState` is created then it's
passed to `AttachTabHelpers` which creates all the other tab helpers. and attaches them to
the `WebState`.

````cpp
web::WebState::CreateParams params{...};
std::unique_ptr<web::WebState> web_state = web::WebState::Create(params);
AttachTabHelper(web_state.get());

Tab* tab = LegacyTabHelper::GetFromWebState(web_state.get());
DCHECK(tab != nil);
````
When a `WebState` is added to a `TabModel`'s `WebStateList`,
Expand All @@ -24,18 +17,7 @@ When a `WebState` is added to a `TabModel`'s `WebStateList`,
TabModel* tab_model = ...;
std::unique_ptr<web::WebState> web_state = ...;
[tab_model webStateList]->InsertWebState(0, std::move(web_state));
Tab* tab = LegacyTabHelper::GetFromWebState(
[tab_model webStateList]->GetWebStateAt(0));
DCHECK(tab != nil);
```
`Tab` register itself as a `WebStateObserver`. When `-webStateDestroyed:`
is invoked as part of `WebState` destruction, `Tab` destroys its state and
should no longer be used (as `-webState` will return `nullptr`).
`LegacyTabHelper` is a `WebStateUserData` thus it is destroyed after the
`WebState` destructor completes. `LegacyTabHelper` release its reference
to `Tab` when destroyed.
It is better to only use `WebState` and to access the `Tab` via
`LegacyTabHelper` as `Tab` will be removed in the new architecture.
All Tab helpers are `WebStateUserData` thus they are destroyed after the
`WebState` destructor completes.

0 comments on commit 7d71ee6

Please sign in to comment.