Android: Avoid calling TabImpl.getActivity() where possible
For some of the callsites of TabImpl.getActivity(), what they actually need is not ChromeActivity, but either Context or Activity. This CL replaces them with Tab.getContext(). TabImpl.getActivity() and Tab.getContext() is different in that the former returns null if the tab is not attached to ChromeActivity (or not attached at all) while the latter returns the application context for such case. The callsites updated in this CL are not affected by the difference due to one of following reasons: - a null check to see if the tab is detached is already in place (ModuleInstallUi) - it is okay to proceed with the application context (ContextualSearchTabHelper - works for ChromeActivity only. For non-ChromeActivity, its scaleFactor could be set wrongly but CS won't be activated anyway) - getActivity() is always returning a non-null activity i.e. Tab.getContext() returns activity contenxt (LayerTitleCache, ExploreSitesPage, SurveyInfoBar, PictureInPictureActivity, TabParentIntent, ArConteInstallUtils) - a null check was added newly to check if the tab is in the detached state (AddToHomescreenInstaller - it is used by ChromeActivity-inherited activity only, therefore TabImpl.getActivity() returning null due to the tab being attached to non-ChromeActivity won't happen). Bug: 995903 Change-Id: I763787c57db62e3af61ee7f88bf172b1b93c45ef Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2109392 Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org> Reviewed-by:Ted Choc <tedchoc@chromium.org> Cr-Commit-Position: refs/heads/master@{#751977}
Showing
Please register or sign in to comment