| Index: ios/web_view/internal/criwv_web_view_impl.mm
|
| diff --git a/ios/web_view/internal/criwv_web_view_impl.mm b/ios/web_view/internal/criwv_web_view_impl.mm
|
| index 76709d39a14adbbb71cd7ec7a4a12a70cc24dc76..7c85e56f91b900749f1afa1ea6565e80cafc8e62 100644
|
| --- a/ios/web_view/internal/criwv_web_view_impl.mm
|
| +++ b/ios/web_view/internal/criwv_web_view_impl.mm
|
| @@ -10,14 +10,12 @@
|
| #import "base/ios/weak_nsobject.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| -#import "ios/web/navigation/crw_session_controller.h"
|
| #include "ios/web/public/referrer.h"
|
| #import "ios/web/public/navigation_manager.h"
|
| #import "ios/web/public/web_state/ui/crw_web_delegate.h"
|
| #import "ios/web/public/web_state/web_state.h"
|
| #import "ios/web/public/web_state/web_state_delegate_bridge.h"
|
| -#import "ios/web/web_state/ui/crw_web_controller.h"
|
| -#import "ios/web/web_state/web_state_impl.h"
|
| +#import "ios/web/public/web_state/web_state_observer_bridge.h"
|
| #include "ios/web_view/internal/criwv_browser_state.h"
|
| #import "ios/web_view/internal/translate/criwv_translate_client.h"
|
| #import "ios/web_view/public/criwv_web_view_delegate.h"
|
| @@ -25,13 +23,12 @@
|
| #include "ui/base/page_transition_types.h"
|
| #include "url/gurl.h"
|
|
|
| -@interface CRIWVWebViewImpl ()<CRWWebDelegate, CRWWebStateDelegate> {
|
| +@interface CRIWVWebViewImpl ()<CRWWebStateDelegate, CRWWebStateObserver> {
|
| id<CRIWVWebViewDelegate> _delegate;
|
| ios_web_view::CRIWVBrowserState* _browserState;
|
| - std::unique_ptr<web::WebStateImpl> _webStateImpl;
|
| - base::WeakNSObject<CRWWebController> _webController;
|
| + std::unique_ptr<web::WebState> _webState;
|
| std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate;
|
| -
|
| + std::unique_ptr<web::WebStateObserverBridge> _webStateObserver;
|
| CGFloat _loadProgress;
|
| }
|
|
|
| @@ -47,73 +44,74 @@
|
| self = [super init];
|
| if (self) {
|
| _browserState = browserState;
|
| - _webStateImpl = base::MakeUnique<web::WebStateImpl>(_browserState);
|
| - _webStateImpl->GetNavigationManagerImpl().InitializeSession(nil, nil, NO,
|
| - 0);
|
| +
|
| + web::WebState::CreateParams webStateCreateParams(_browserState);
|
| + _webState = web::WebState::Create(webStateCreateParams);
|
| + _webState->SetWebUsageEnabled(true);
|
| +
|
| + _webStateObserver =
|
| + base::MakeUnique<web::WebStateObserverBridge>(_webState.get(), self);
|
| _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self);
|
| - _webStateImpl->SetDelegate(_webStateDelegate.get());
|
| - _webController.reset(_webStateImpl->GetWebController());
|
| - [_webController setDelegate:self];
|
| - [_webController setWebUsageEnabled:YES];
|
| + _webState->SetDelegate(_webStateDelegate.get());
|
|
|
| // Initialize Translate.
|
| - ios_web_view::CRIWVTranslateClient::CreateForWebState(_webStateImpl.get());
|
| + ios_web_view::CRIWVTranslateClient::CreateForWebState(_webState.get());
|
| }
|
| return self;
|
| }
|
|
|
| - (UIView*)view {
|
| - return [_webController view];
|
| + return _webState->GetView();
|
| }
|
|
|
| - (BOOL)canGoBack {
|
| - return _webStateImpl && _webStateImpl->GetNavigationManager()->CanGoBack();
|
| + return _webState && _webState->GetNavigationManager()->CanGoBack();
|
| }
|
|
|
| - (BOOL)canGoForward {
|
| - return _webStateImpl && _webStateImpl->GetNavigationManager()->CanGoForward();
|
| + return _webState && _webState->GetNavigationManager()->CanGoForward();
|
| }
|
|
|
| - (BOOL)isLoading {
|
| - return _webStateImpl->IsLoading();
|
| + return _webState->IsLoading();
|
| }
|
|
|
| - (NSURL*)visibleURL {
|
| - return net::NSURLWithGURL(_webStateImpl->GetVisibleURL());
|
| + return net::NSURLWithGURL(_webState->GetVisibleURL());
|
| }
|
|
|
| - (NSString*)pageTitle {
|
| - return base::SysUTF16ToNSString(_webStateImpl->GetTitle());
|
| + return base::SysUTF16ToNSString(_webState->GetTitle());
|
| }
|
|
|
| - (void)goBack {
|
| - if (_webStateImpl->GetNavigationManager())
|
| - _webStateImpl->GetNavigationManager()->GoBack();
|
| + if (_webState->GetNavigationManager())
|
| + _webState->GetNavigationManager()->GoBack();
|
| }
|
|
|
| - (void)goForward {
|
| - if (_webStateImpl->GetNavigationManager())
|
| - _webStateImpl->GetNavigationManager()->GoForward();
|
| + if (_webState->GetNavigationManager())
|
| + _webState->GetNavigationManager()->GoForward();
|
| }
|
|
|
| - (void)reload {
|
| - [_webController reload];
|
| + _webState->GetNavigationManager()->Reload(true);
|
| }
|
|
|
| - (void)stopLoading {
|
| - [_webController stopLoading];
|
| + _webState->Stop();
|
| }
|
|
|
| - (void)loadURL:(NSURL*)URL {
|
| web::NavigationManager::WebLoadParams params(net::GURLWithNSURL(URL));
|
| params.transition_type = ui::PAGE_TRANSITION_TYPED;
|
| - [_webController loadWithParams:params];
|
| + _webState->GetNavigationManager()->LoadURLWithParams(params);
|
| }
|
|
|
| - (void)evaluateJavaScript:(NSString*)javaScriptString
|
| completionHandler:(void (^)(id, NSError*))completionHandler {
|
| - [_webStateImpl->GetJSInjectionReceiver() executeJavaScript:javaScriptString
|
| - completionHandler:completionHandler];
|
| + [_webState->GetJSInjectionReceiver() executeJavaScript:javaScriptString
|
| + completionHandler:completionHandler];
|
| }
|
|
|
| - (void)setDelegate:(id<CRIWVWebViewDelegate>)delegate {
|
| @@ -121,16 +119,13 @@
|
|
|
| // Set up the translate delegate.
|
| ios_web_view::CRIWVTranslateClient* translateClient =
|
| - ios_web_view::CRIWVTranslateClient::FromWebState(_webStateImpl.get());
|
| + ios_web_view::CRIWVTranslateClient::FromWebState(_webState.get());
|
| id<CRIWVTranslateDelegate> translateDelegate = nil;
|
| if ([_delegate respondsToSelector:@selector(translateDelegate)])
|
| translateDelegate = [_delegate translateDelegate];
|
| translateClient->set_translate_delegate(translateDelegate);
|
| }
|
|
|
| -// -----------------------------------------------------------------------
|
| -// WebDelegate implementation.
|
| -
|
| - (void)notifyDidUpdateWithChanges:(CRIWVWebViewUpdateType)changes {
|
| SEL selector = @selector(webView:didUpdateWithChanges:);
|
| if ([_delegate respondsToSelector:selector]) {
|
| @@ -138,97 +133,26 @@
|
| }
|
| }
|
|
|
| -- (void)webController:(CRWWebController*)webController
|
| - titleDidChange:(NSString*)title {
|
| - [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeTitle];
|
| -}
|
| -
|
| -- (void)webDidUpdateSessionForLoadWithParams:
|
| - (const web::NavigationManager::WebLoadParams&)params
|
| - wasInitialNavigation:(BOOL)initialNavigation {
|
| - [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
|
| -}
|
| -
|
| -- (void)webWillFinishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry {
|
| - [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
|
| -}
|
| -
|
| -- (void)webDidAddPendingURL {
|
| - [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
|
| -}
|
| -
|
| -- (void)webDidUpdateHistoryStateWithPageURL:(const GURL&)pageUrl {
|
| - [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
|
| -}
|
| +// -----------------------------------------------------------------------
|
| +// WebStateObserver implementation.
|
|
|
| -- (void)webCancelStartLoadingRequest {
|
| +- (void)didStartProvisionalNavigationForURL:(const GURL&)URL {
|
| [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
|
| }
|
|
|
| -- (void)webDidStartLoadingURL:(const GURL&)currentUrl
|
| - shouldUpdateHistory:(BOOL)updateHistory {
|
| +- (void)didCommitNavigationWithDetails:
|
| + (const web::LoadCommittedDetails&)details {
|
| [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
|
| }
|
|
|
| -- (void)webDidFinishWithURL:(const GURL&)url loadSuccess:(BOOL)loadSuccess {
|
| +- (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success {
|
| + DCHECK_EQ(_webState.get(), webState);
|
| SEL selector = @selector(webView:didFinishLoadingWithURL:loadSuccess:);
|
| if ([_delegate respondsToSelector:selector]) {
|
| [_delegate webView:self
|
| - didFinishLoadingWithURL:net::NSURLWithGURL(url)
|
| - loadSuccess:loadSuccess];
|
| - }
|
| -}
|
| -
|
| -- (void)webLoadCancelled:(const GURL&)url {
|
| - [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
|
| -}
|
| -
|
| -- (void)webWillAddPendingURL:(const GURL&)url
|
| - transition:(ui::PageTransition)transition {
|
| -}
|
| -- (CRWWebController*)webPageOrderedOpen:(const GURL&)url
|
| - referrer:(const web::Referrer&)referrer
|
| - windowName:(NSString*)windowName
|
| - inBackground:(BOOL)inBackground {
|
| - return nil;
|
| -}
|
| -
|
| -- (CRWWebController*)webPageOrderedOpen {
|
| - return nil;
|
| -}
|
| -
|
| -- (void)webPageOrderedClose {
|
| -}
|
| -- (void)openURLWithParams:(const web::WebState::OpenURLParams&)params {
|
| -}
|
| -- (BOOL)openExternalURL:(const GURL&)url linkClicked:(BOOL)linkClicked {
|
| - return NO;
|
| -}
|
| -- (void)webController:(CRWWebController*)webController
|
| - retrievePlaceholderOverlayImage:(void (^)(UIImage*))block {
|
| -}
|
| -- (void)webController:(CRWWebController*)webController
|
| - onFormResubmissionForRequest:(NSURLRequest*)request
|
| - continueBlock:(ProceduralBlock)continueBlock
|
| - cancelBlock:(ProceduralBlock)cancelBlock {
|
| -}
|
| -- (void)webWillReload {
|
| -}
|
| -- (void)webWillInitiateLoadWithParams:
|
| - (web::NavigationManager::WebLoadParams&)params {
|
| -}
|
| -- (BOOL)webController:(CRWWebController*)webController
|
| - shouldOpenURL:(const GURL&)url
|
| - mainDocumentURL:(const GURL&)mainDocumentURL
|
| - linkClicked:(BOOL)linkClicked {
|
| - SEL selector = @selector(webView:shouldOpenURL:mainDocumentURL:linkClicked:);
|
| - if ([_delegate respondsToSelector:selector]) {
|
| - return [_delegate webView:self
|
| - shouldOpenURL:net::NSURLWithGURL(url)
|
| - mainDocumentURL:net::NSURLWithGURL(mainDocumentURL)
|
| - linkClicked:linkClicked];
|
| + didFinishLoadingWithURL:[self visibleURL]
|
| + loadSuccess:success];
|
| }
|
| - return YES;
|
| }
|
|
|
| // -----------------------------------------------------------------------
|
|
|