Commit e92aff54 authored by Mohammad Refaat's avatar Mohammad Refaat Committed by Commit Bot

Remove webController from Tab

WebController is accessed from tab by BVC and preloadController to set
nativecontent and sideswipe delegates. Both are to be removed with
the release of slim navigation and the removal of native content.
For now create some utility methods to be used to set delegates inside
the webController of the webState and have them on the deprecated web
folder and use them instead of tab.

Bug: 960950
Change-Id: I79ba36b665e8fba92ec5595d5a51ec3ec6773de4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1674473
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672562}
parent 27dffa6e
...@@ -36,6 +36,7 @@ source_set("prerender") { ...@@ -36,6 +36,7 @@ source_set("prerender") {
"//ios/chrome/browser/web", "//ios/chrome/browser/web",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
"//ios/web/public/deprecated", "//ios/web/public/deprecated",
"//ios/web/public/deprecated:deprecated_web_util",
"//ui/base", "//ui/base",
"//url", "//url",
] ]
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
#import "ios/chrome/browser/tabs/legacy_tab_helper.h" #import "ios/chrome/browser/tabs/legacy_tab_helper.h"
#import "ios/chrome/browser/tabs/tab.h" #import "ios/chrome/browser/tabs/tab.h"
#import "ios/chrome/browser/tabs/tab_helper_util.h" #import "ios/chrome/browser/tabs/tab_helper_util.h"
#import "ios/chrome/browser/tabs/tab_private.h"
#import "ios/web/public/deprecated/crw_native_content.h" #import "ios/web/public/deprecated/crw_native_content.h"
#import "ios/web/public/deprecated/crw_native_content_holder.h" #import "ios/web/public/deprecated/crw_native_content_holder.h"
#import "ios/web/public/deprecated/crw_web_controller_util.h"
#import "ios/web/public/navigation_item.h" #import "ios/web/public/navigation_item.h"
#import "ios/web/public/navigation_manager.h" #import "ios/web/public/navigation_manager.h"
#include "ios/web/public/thread/web_thread.h" #include "ios/web/public/thread/web_thread.h"
...@@ -277,9 +277,7 @@ bool IsPrerenderTabEvictionExperimentalGroup() { ...@@ -277,9 +277,7 @@ bool IsPrerenderTabEvictionExperimentalGroup() {
std::unique_ptr<web::WebState> webState = std::move(webState_); std::unique_ptr<web::WebState> webState = std::move(webState_);
DCHECK(![self isWebStatePrerendered:webState.get()]); DCHECK(![self isWebStatePrerendered:webState.get()]);
Tab* tab = LegacyTabHelper::GetTabForWebState(webState.get()); web_deprecated::SetNativeProvider(webState.get(), nil);
[tab.webController nativeContentHolder].nativeProvider = nil;
webState->RemoveObserver(webStateObserver_.get()); webState->RemoveObserver(webStateObserver_.get());
breakpad::StopMonitoringURLsForWebState(webState.get()); breakpad::StopMonitoringURLsForWebState(webState.get());
webState->SetDelegate(nullptr); webState->SetDelegate(nullptr);
...@@ -401,10 +399,7 @@ bool IsPrerenderTabEvictionExperimentalGroup() { ...@@ -401,10 +399,7 @@ bool IsPrerenderTabEvictionExperimentalGroup() {
std::make_unique<web::WebStatePolicyDeciderBridge>(webState_.get(), self); std::make_unique<web::WebStatePolicyDeciderBridge>(webState_.get(), self);
AttachTabHelpers(webState_.get(), /*for_prerender=*/true); AttachTabHelpers(webState_.get(), /*for_prerender=*/true);
Tab* tab = LegacyTabHelper::GetTabForWebState(webState_.get()); web_deprecated::SetNativeProvider(webState_.get(), nil);
DCHECK(tab);
[tab.webController nativeContentHolder].nativeProvider = nil;
webState_->SetDelegate(webStateDelegate_.get()); webState_->SetDelegate(webStateDelegate_.get());
webState_->AddObserver(webStateObserver_.get()); webState_->AddObserver(webStateObserver_.get());
...@@ -448,8 +443,7 @@ bool IsPrerenderTabEvictionExperimentalGroup() { ...@@ -448,8 +443,7 @@ bool IsPrerenderTabEvictionExperimentalGroup() {
UMA_HISTOGRAM_ENUMERATION(kPrerenderFinalStatusHistogramName, reason, UMA_HISTOGRAM_ENUMERATION(kPrerenderFinalStatusHistogramName, reason,
PRERENDER_FINAL_STATUS_MAX); PRERENDER_FINAL_STATUS_MAX);
Tab* tab = LegacyTabHelper::GetTabForWebState(webState_.get()); web_deprecated::SetNativeProvider(webState_.get(), nil);
[tab.webController nativeContentHolder].nativeProvider = nil;
webState_->RemoveObserver(webStateObserver_.get()); webState_->RemoveObserver(webStateObserver_.get());
breakpad::StopMonitoringURLsForWebState(webState_.get()); breakpad::StopMonitoringURLsForWebState(webState_.get());
webState_->SetDelegate(nullptr); webState_->SetDelegate(nullptr);
......
...@@ -12,7 +12,6 @@ source_set("tabs") { ...@@ -12,7 +12,6 @@ source_set("tabs") {
"tab_model_list_observer.h", "tab_model_list_observer.h",
"tab_model_synced_window_delegate.h", "tab_model_synced_window_delegate.h",
"tab_model_synced_window_delegate_getter.h", "tab_model_synced_window_delegate_getter.h",
"tab_private.h",
"tab_title_util.h", "tab_title_util.h",
] ]
public_deps = [ public_deps = [
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/tabs/tab.h" #import "ios/chrome/browser/tabs/tab.h"
#import "ios/chrome/browser/tabs/tab_private.h"
#import "ios/web/public/web_state/web_state_observer_bridge.h" #import "ios/web/public/web_state/web_state_observer_bridge.h"
#import "ios/web/web_state/ui/crw_web_controller.h" #import "ios/web/web_state/ui/crw_web_controller.h"
...@@ -73,15 +72,3 @@ ...@@ -73,15 +72,3 @@
} }
@end @end
#pragma mark - TestingSupport
@implementation Tab (TestingSupport)
// TODO(crbug.com/620465): this require the Tab's WebState to be a WebStateImpl,
// remove this helper once this is no longer true (and fix the unit tests).
- (CRWWebController*)webController {
return _webStateImpl ? _webStateImpl->GetWebController() : nil;
}
@end
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#import "ios/chrome/browser/tabs/tab.h" #import "ios/chrome/browser/tabs/tab.h"
#import "ios/chrome/browser/tabs/tab_helper_util.h" #import "ios/chrome/browser/tabs/tab_helper_util.h"
#import "ios/chrome/browser/tabs/tab_model.h" #import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/tabs/tab_private.h"
#import "ios/chrome/browser/web/chrome_web_client.h" #import "ios/chrome/browser/web/chrome_web_client.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_opener.h" #import "ios/chrome/browser/web_state_list/web_state_opener.h"
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_TABS_TAB_PRIVATE_H_
#define IOS_CHROME_BROWSER_TABS_TAB_PRIVATE_H_
@class CRWWebController;
// Exposed private methods for testing purpose.
@interface Tab (TestingSupport)
// The CRWWebController from the Tab's WebState. This should only be used
// by tests and will be removed when Tab can wrap TestWebState (see issue
// crbug.com/620465 for progress).
@property(nonatomic, readonly) CRWWebController* webController;
@end
#endif // IOS_CHROME_BROWSER_TABS_TAB_PRIVATE_H_
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#import "ios/chrome/browser/tabs/tab.h" #import "ios/chrome/browser/tabs/tab.h"
#import "ios/chrome/browser/tabs/tab_helper_util.h" #import "ios/chrome/browser/tabs/tab_helper_util.h"
#import "ios/chrome/browser/tabs/tab_model.h" #import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/tabs/tab_private.h"
#import "ios/chrome/browser/ui/open_in/open_in_controller.h" #import "ios/chrome/browser/ui/open_in/open_in_controller.h"
#import "ios/chrome/browser/ui/open_in/open_in_controller_testing.h" #import "ios/chrome/browser/ui/open_in/open_in_controller_testing.h"
#import "ios/chrome/browser/web/tab_id_tab_helper.h" #import "ios/chrome/browser/web/tab_id_tab_helper.h"
......
...@@ -168,6 +168,7 @@ source_set("browser_view") { ...@@ -168,6 +168,7 @@ source_set("browser_view") {
"//ios/web/common", "//ios/web/common",
"//ios/web/public", "//ios/web/public",
"//ios/web/public/deprecated", "//ios/web/public/deprecated",
"//ios/web/public/deprecated:deprecated_web_util",
"//third_party/google_toolbox_for_mac", "//third_party/google_toolbox_for_mac",
"//ui/base", "//ui/base",
"//ui/gfx", "//ui/gfx",
......
...@@ -69,7 +69,6 @@ ...@@ -69,7 +69,6 @@
#include "ios/chrome/browser/system_flags.h" #include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/tabs/legacy_tab_helper.h" #import "ios/chrome/browser/tabs/legacy_tab_helper.h"
#import "ios/chrome/browser/tabs/tab.h" #import "ios/chrome/browser/tabs/tab.h"
#import "ios/chrome/browser/tabs/tab_private.h"
#import "ios/chrome/browser/translate/chrome_ios_translate_client.h" #import "ios/chrome/browser/translate/chrome_ios_translate_client.h"
#import "ios/chrome/browser/ui/activity_services/activity_service_legacy_coordinator.h" #import "ios/chrome/browser/ui/activity_services/activity_service_legacy_coordinator.h"
#import "ios/chrome/browser/ui/activity_services/requirements/activity_service_positioner.h" #import "ios/chrome/browser/ui/activity_services/requirements/activity_service_positioner.h"
...@@ -190,6 +189,7 @@ ...@@ -190,6 +189,7 @@
#import "ios/web/public/deprecated/crw_js_injection_receiver.h" #import "ios/web/public/deprecated/crw_js_injection_receiver.h"
#import "ios/web/public/deprecated/crw_native_content_holder.h" #import "ios/web/public/deprecated/crw_native_content_holder.h"
#import "ios/web/public/deprecated/crw_native_content_provider.h" #import "ios/web/public/deprecated/crw_native_content_provider.h"
#import "ios/web/public/deprecated/crw_web_controller_util.h"
#include "ios/web/public/navigation_item.h" #include "ios/web/public/navigation_item.h"
#include "ios/web/public/thread/web_thread.h" #include "ios/web/public/thread/web_thread.h"
#include "ios/web/public/url_scheme_util.h" #include "ios/web/public/url_scheme_util.h"
...@@ -734,8 +734,8 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -734,8 +734,8 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// is notified that the webState has changed. // is notified that the webState has changed.
- (void)webStateSelected:(web::WebState*)webState - (void)webStateSelected:(web::WebState*)webState
notifyToolbar:(BOOL)notifyToolbar; notifyToolbar:(BOOL)notifyToolbar;
// Returns the native controller being used by |tab|'s web controller. // Returns the native controller being used by |web_state|'s web controller.
- (id)nativeControllerForTab:(Tab*)tab; - (id)nativeControllerForWebState:(web::WebState*)webState;
// Voice Search // Voice Search
// ------------ // ------------
...@@ -2770,13 +2770,11 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -2770,13 +2770,11 @@ NSString* const kBrowserViewControllerSnackbarCategory =
OverscrollActionsTabHelper::FromWebState(webState)->SetDelegate(self); OverscrollActionsTabHelper::FromWebState(webState)->SetDelegate(self);
} }
// TODO(crbug.com/960950): Remove this once webController is moved out of tab.
Tab* tab = LegacyTabHelper::GetTabForWebState(webState);
// Install the proper CRWWebController delegates. // Install the proper CRWWebController delegates.
[tab.webController nativeContentHolder].nativeProvider = self; web_deprecated::SetNativeProvider(webState, self);
tab.webController.swipeRecognizerProvider = self.sideSwipeController; web_deprecated::SetSwipeRecognizerProvider(webState,
tab.webState->SetDelegate(_webStateDelegate.get()); self.sideSwipeController);
webState->SetDelegate(_webStateDelegate.get());
SadTabTabHelper::FromWebState(webState)->SetDelegate(_sadTabCoordinator); SadTabTabHelper::FromWebState(webState)->SetDelegate(_sadTabCoordinator);
NetExportTabHelper::CreateForWebState(webState, self); NetExportTabHelper::CreateForWebState(webState, self);
CaptivePortalDetectorTabHelper::CreateForWebState(webState, self); CaptivePortalDetectorTabHelper::CreateForWebState(webState, self);
...@@ -2825,11 +2823,8 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -2825,11 +2823,8 @@ NSString* const kBrowserViewControllerSnackbarCategory =
OverscrollActionsTabHelper::FromWebState(webState)->SetDelegate(nil); OverscrollActionsTabHelper::FromWebState(webState)->SetDelegate(nil);
} }
// TODO(crbug.com/960950): Remove this once webController is moved out of tab. web_deprecated::SetNativeProvider(webState, nil);
Tab* tab = LegacyTabHelper::GetTabForWebState(webState); web_deprecated::SetSwipeRecognizerProvider(webState, nil);
[tab.webController nativeContentHolder].nativeProvider = nil;
tab.webController.swipeRecognizerProvider = nil;
webState->SetDelegate(nullptr); webState->SetDelegate(nullptr);
if (AccountConsistencyService* accountConsistencyService = if (AccountConsistencyService* accountConsistencyService =
ios::AccountConsistencyServiceFactory::GetForBrowserState( ios::AccountConsistencyServiceFactory::GetForBrowserState(
...@@ -2866,9 +2861,8 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -2866,9 +2861,8 @@ NSString* const kBrowserViewControllerSnackbarCategory =
} }
} }
- (id)nativeControllerForTab:(Tab*)tab { - (id)nativeControllerForWebState:(web::WebState*)webState {
id nativeController = id nativeController = web_deprecated::GetNativeController(webState);
[tab.webController nativeContentHolder].nativeController;
return nativeController ? nativeController : _temporaryNativeController; return nativeController ? nativeController : _temporaryNativeController;
} }
...@@ -3042,9 +3036,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -3042,9 +3036,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
- (void)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator - (void)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
willUpdateSnapshotForWebState:(web::WebState*)webState { willUpdateSnapshotForWebState:(web::WebState*)webState {
DCHECK(webState); DCHECK(webState);
Tab* tab = LegacyTabHelper::GetTabForWebState(webState); id nativeController = [self nativeControllerForWebState:webState];
DCHECK([self.tabModel indexOfTab:tab] != NSNotFound);
id nativeController = [self nativeControllerForTab:tab];
if ([nativeController respondsToSelector:@selector(willUpdateSnapshot)]) { if ([nativeController respondsToSelector:@selector(willUpdateSnapshot)]) {
[nativeController willUpdateSnapshot]; [nativeController willUpdateSnapshot];
} }
...@@ -3732,10 +3724,9 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -3732,10 +3724,9 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// be used as the native controller key. // be used as the native controller key.
// TODO(crbug.com/498568): To reduce complexity here, refactor the flow so // TODO(crbug.com/498568): To reduce complexity here, refactor the flow so
// that native controllers vended here always correspond to the current tab. // that native controllers vended here always correspond to the current tab.
Tab* currentTab = self.tabModel.currentTab;
if (!self.currentWebState || if (!self.currentWebState ||
self.currentWebState->GetLastCommittedURL() != url || self.currentWebState->GetLastCommittedURL() != url ||
[[currentTab.webController nativeContentHolder].nativeController [web_deprecated::GetNativeController(self.currentWebState)
isKindOfClass:[nativeController class]]) { isKindOfClass:[nativeController class]]) {
_temporaryNativeController = nativeController; _temporaryNativeController = nativeController;
} }
......
...@@ -27,6 +27,23 @@ source_set("deprecated") { ...@@ -27,6 +27,23 @@ source_set("deprecated") {
] ]
} }
# A separate target is needed for util to prevent cyclic dependency, as
# "web_state:web_state_impl_header" depends on ":deprecated" target.
source_set("deprecated_web_util") {
configs += [ "//build/config/compiler:enable_arc" ]
deps = [
":deprecated",
"//ios/web/public",
"//ios/web/web_state:web_state_impl_header",
"//ios/web/web_state/ui",
]
sources = [
"crw_web_controller_util.h",
"crw_web_controller_util.mm",
]
}
source_set("test_doubles") { source_set("test_doubles") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_DEPRECATED_CRW_WEB_CONTROLLER_UTIL_H_
#define IOS_WEB_PUBLIC_DEPRECATED_CRW_WEB_CONTROLLER_UTIL_H_
@protocol CRWNativeContentProvider;
@protocol CRWSwipeRecognizerProvider;
@protocol CRWNativeContent;
namespace web {
class WebState;
}
// Utility functions needed to access CRWWebController methods via WebState.
// All functions defined here should be removed after native content removal and
// slim navigation launching.
namespace web_deprecated {
// Sets native provider for the |web_state|.
// |web_state| can't be null.
void SetNativeProvider(web::WebState* web_state,
id<CRWNativeContentProvider> delegate);
// Sets side swipe recognizer for the |web_state|.
// |web_state| can't be null.
void SetSwipeRecognizerProvider(web::WebState* web_state,
id<CRWSwipeRecognizerProvider> delegate);
// Gets the native controller associated with |web_state|.
// |web_state| can't be null.
id<CRWNativeContent> GetNativeController(web::WebState* web_state);
} // namespace web_deprecated
#endif // IOS_WEB_PUBLIC_DEPRECATED_CRW_WEB_CONTROLLER_UTIL_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/public/deprecated/crw_web_controller_util.h"
#import <Foundation/Foundation.h>
#import "ios/web/public/deprecated/crw_native_content.h"
#import "ios/web/public/deprecated/crw_native_content_holder.h"
#import "ios/web/public/deprecated/crw_native_content_provider.h"
#import "ios/web/public/web_state/web_state.h"
#import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h"
#import "ios/web/web_state/ui/crw_web_controller.h"
#import "ios/web/web_state/web_state_impl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Gets the web controller from |web_state|.
CRWWebController* GetWebController(web::WebState* web_state) {
return static_cast<web::WebStateImpl*>(web_state)->GetWebController();
}
} // namespace
namespace web_deprecated {
void SetNativeProvider(web::WebState* web_state,
id<CRWNativeContentProvider> delegate) {
GetWebController(web_state).nativeContentHolder.nativeProvider = delegate;
}
void SetSwipeRecognizerProvider(web::WebState* web_state,
id<CRWSwipeRecognizerProvider> delegate) {
GetWebController(web_state).swipeRecognizerProvider = delegate;
}
id<CRWNativeContent> GetNativeController(web::WebState* web_state) {
return GetWebController(web_state).nativeContentHolder.nativeController;
}
} // namespace web_deprecated
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment