| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/web/shell/view_controller.h" | 5 #import "ios/web/shell/view_controller.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/mac/objc_property_releaser.h" | 12 #include "base/mac/objc_property_releaser.h" |
| 13 #import "base/mac/scoped_nsobject.h" | 13 #import "base/mac/scoped_nsobject.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "ios/net/cookies/cookie_store_ios.h" | 15 #include "ios/net/cookies/cookie_store_ios.h" |
| 16 #import "ios/net/crn_http_protocol_handler.h" | 16 #import "ios/net/crn_http_protocol_handler.h" |
| 17 #import "ios/net/empty_nsurlcache.h" | 17 #import "ios/net/empty_nsurlcache.h" |
| 18 #include "ios/web/public/referrer.h" | 18 #include "ios/web/public/referrer.h" |
| 19 #import "ios/web/public/web_controller_factory.h" | |
| 20 #include "ios/web/public/web_state/web_state.h" | 19 #include "ios/web/public/web_state/web_state.h" |
| 21 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 20 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 22 #include "ios/web/shell/shell_browser_state.h" | 21 #include "ios/web/shell/shell_browser_state.h" |
| 23 #include "ios/web/web_state/ui/crw_web_controller.h" | 22 #include "ios/web/web_state/ui/crw_web_controller.h" |
| 24 #include "ios/web/web_state/web_state_impl.h" | 23 #include "ios/web/web_state/web_state_impl.h" |
| 25 #include "ui/base/page_transition_types.h" | 24 #include "ui/base/page_transition_types.h" |
| 26 | 25 |
| 27 NSString* const kWebShellBackButtonAccessibilityLabel = @"Back"; | 26 NSString* const kWebShellBackButtonAccessibilityLabel = @"Back"; |
| 28 NSString* const kWebShellForwardButtonAccessibilityLabel = @"Forward"; | 27 NSString* const kWebShellForwardButtonAccessibilityLabel = @"Forward"; |
| 29 NSString* const kWebShellAddressFieldAccessibilityLabel = @"Address field"; | 28 NSString* const kWebShellAddressFieldAccessibilityLabel = @"Address field"; |
| 30 | 29 |
| 31 using web::NavigationManager; | 30 using web::NavigationManager; |
| 32 | 31 |
| 33 @interface ViewController ()<CRWWebStateObserver> { | 32 @interface ViewController ()<CRWWebStateObserver> { |
| 34 web::BrowserState* _browserState; | 33 web::BrowserState* _browserState; |
| 35 base::scoped_nsobject<CRWWebController> _webController; | 34 std::unique_ptr<web::WebStateImpl> _webState; |
| 36 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; | 35 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; |
| 37 | 36 |
| 38 base::mac::ObjCPropertyReleaser _propertyReleaser_ViewController; | 37 base::mac::ObjCPropertyReleaser _propertyReleaser_ViewController; |
| 39 } | 38 } |
| 40 @property(nonatomic, assign, readonly) web::WebState* webState; | |
| 41 @property(nonatomic, assign, readonly) NavigationManager* navigationManager; | 39 @property(nonatomic, assign, readonly) NavigationManager* navigationManager; |
| 42 @property(nonatomic, readwrite, retain) UITextField* field; | 40 @property(nonatomic, readwrite, retain) UITextField* field; |
| 43 @end | 41 @end |
| 44 | 42 |
| 45 @implementation ViewController | 43 @implementation ViewController |
| 46 | 44 |
| 47 @synthesize field = _field; | 45 @synthesize field = _field; |
| 48 @synthesize containerView = _containerView; | 46 @synthesize containerView = _containerView; |
| 49 @synthesize toolbarView = _toolbarView; | 47 @synthesize toolbarView = _toolbarView; |
| 50 | 48 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 [field setClearButtonMode:UITextFieldViewModeWhileEditing]; | 101 [field setClearButtonMode:UITextFieldViewModeWhileEditing]; |
| 104 self.field = field; | 102 self.field = field; |
| 105 | 103 |
| 106 [_toolbarView addSubview:back]; | 104 [_toolbarView addSubview:back]; |
| 107 [_toolbarView addSubview:forward]; | 105 [_toolbarView addSubview:forward]; |
| 108 [_toolbarView addSubview:field]; | 106 [_toolbarView addSubview:field]; |
| 109 | 107 |
| 110 // Set up the network stack before creating the WebState. | 108 // Set up the network stack before creating the WebState. |
| 111 [self setUpNetworkStack]; | 109 [self setUpNetworkStack]; |
| 112 | 110 |
| 113 std::unique_ptr<web::WebStateImpl> webState( | 111 _webState.reset(new web::WebStateImpl(_browserState)); |
| 114 new web::WebStateImpl(_browserState)); | 112 _webState->GetNavigationManagerImpl().InitializeSession(nil, nil, NO, 0); |
| 115 webState->GetNavigationManagerImpl().InitializeSession(nil, nil, NO, 0); | 113 [_webState->GetWebController() setDelegate:self]; |
| 116 _webController.reset(web::CreateWebController(std::move(webState))); | 114 [_webState->GetWebController() setWebUsageEnabled:YES]; |
| 117 [_webController setDelegate:self]; | |
| 118 [_webController setWebUsageEnabled:YES]; | |
| 119 | 115 |
| 120 _webStateObserver.reset(new web::WebStateObserverBridge(self.webState, self)); | 116 _webStateObserver.reset( |
| 117 new web::WebStateObserverBridge(_webState.get(), self)); |
| 121 | 118 |
| 122 UIView* view = self.webState->GetView(); | 119 UIView* view = _webState->GetView(); |
| 123 [view setFrame:[_containerView bounds]]; | 120 [view setFrame:[_containerView bounds]]; |
| 124 [_containerView addSubview:view]; | 121 [_containerView addSubview:view]; |
| 125 | 122 |
| 126 NavigationManager::WebLoadParams params(GURL("https://dev.chromium.org/")); | 123 NavigationManager::WebLoadParams params(GURL("https://dev.chromium.org/")); |
| 127 params.transition_type = ui::PAGE_TRANSITION_TYPED; | 124 params.transition_type = ui::PAGE_TRANSITION_TYPED; |
| 128 self.navigationManager->LoadURLWithParams(params); | 125 self.navigationManager->LoadURLWithParams(params); |
| 129 } | 126 } |
| 130 | 127 |
| 131 - (web::WebState*)webState { | |
| 132 return [_webController webState]; | |
| 133 } | |
| 134 | |
| 135 - (NavigationManager*)navigationManager { | 128 - (NavigationManager*)navigationManager { |
| 136 return self.webState->GetNavigationManager(); | 129 return _webState->GetNavigationManager(); |
| 137 } | 130 } |
| 138 | 131 |
| 139 - (void)setUpNetworkStack { | 132 - (void)setUpNetworkStack { |
| 140 // Disable the default cache. | 133 // Disable the default cache. |
| 141 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; | 134 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; |
| 142 net::CookieStoreIOS::SetCookiePolicy(net::CookieStoreIOS::ALLOW); | 135 net::CookieStoreIOS::SetCookiePolicy(net::CookieStoreIOS::ALLOW); |
| 143 } | 136 } |
| 144 | 137 |
| 145 - (void)didReceiveMemoryWarning { | 138 - (void)didReceiveMemoryWarning { |
| 146 [super didReceiveMemoryWarning]; | 139 [super didReceiveMemoryWarning]; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 [self updateToolbar]; | 172 [self updateToolbar]; |
| 180 return YES; | 173 return YES; |
| 181 } | 174 } |
| 182 | 175 |
| 183 - (void)updateToolbar { | 176 - (void)updateToolbar { |
| 184 // Do not update the URL if the text field is currently being edited. | 177 // Do not update the URL if the text field is currently being edited. |
| 185 if ([_field isFirstResponder]) { | 178 if ([_field isFirstResponder]) { |
| 186 return; | 179 return; |
| 187 } | 180 } |
| 188 | 181 |
| 189 const GURL& visibleURL = self.webState->GetVisibleURL(); | 182 const GURL& visibleURL = _webState->GetVisibleURL(); |
| 190 [_field setText:base::SysUTF8ToNSString(visibleURL.spec())]; | 183 [_field setText:base::SysUTF8ToNSString(visibleURL.spec())]; |
| 191 } | 184 } |
| 192 | 185 |
| 193 // ----------------------------------------------------------------------- | 186 // ----------------------------------------------------------------------- |
| 194 #pragma mark Bikeshedding Implementation | 187 #pragma mark Bikeshedding Implementation |
| 195 | 188 |
| 196 // Overridden to allow this view controller to receive motion events by being | 189 // Overridden to allow this view controller to receive motion events by being |
| 197 // first responder when no other views are. | 190 // first responder when no other views are. |
| 198 - (BOOL)canBecomeFirstResponder { | 191 - (BOOL)canBecomeFirstResponder { |
| 199 return YES; | 192 return YES; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 - (void)didStartProvisionalNavigationForURL:(const GURL&)URL { | 243 - (void)didStartProvisionalNavigationForURL:(const GURL&)URL { |
| 251 [self updateToolbar]; | 244 [self updateToolbar]; |
| 252 } | 245 } |
| 253 | 246 |
| 254 - (void)didCommitNavigationWithDetails: | 247 - (void)didCommitNavigationWithDetails: |
| 255 (const web::LoadCommittedDetails&)details { | 248 (const web::LoadCommittedDetails&)details { |
| 256 [self updateToolbar]; | 249 [self updateToolbar]; |
| 257 } | 250 } |
| 258 | 251 |
| 259 - (void)webStateDidLoadPage:(web::WebState*)webState { | 252 - (void)webStateDidLoadPage:(web::WebState*)webState { |
| 260 DCHECK_EQ(self.webState, webState); | 253 DCHECK_EQ(_webState.get(), webState); |
| 261 [self updateToolbar]; | 254 [self updateToolbar]; |
| 262 } | 255 } |
| 263 | 256 |
| 264 // ----------------------------------------------------------------------- | 257 // ----------------------------------------------------------------------- |
| 265 // WebDelegate implementation. | 258 // WebDelegate implementation. |
| 266 | 259 |
| 267 - (void)webWillAddPendingURL:(const GURL&)url | 260 - (void)webWillAddPendingURL:(const GURL&)url |
| 268 transition:(ui::PageTransition)transition { | 261 transition:(ui::PageTransition)transition { |
| 269 } | 262 } |
| 270 - (void)webDidAddPendingURL { | 263 - (void)webDidAddPendingURL { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 - (void)webWillFinishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { | 341 - (void)webWillFinishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { |
| 349 } | 342 } |
| 350 - (int)downloadImageAtUrl:(const GURL&)url | 343 - (int)downloadImageAtUrl:(const GURL&)url |
| 351 maxBitmapSize:(uint32_t)maxBitmapSize | 344 maxBitmapSize:(uint32_t)maxBitmapSize |
| 352 callback: | 345 callback: |
| 353 (const web::WebState::ImageDownloadCallback&)callback { | 346 (const web::WebState::ImageDownloadCallback&)callback { |
| 354 return -1; | 347 return -1; |
| 355 } | 348 } |
| 356 | 349 |
| 357 @end | 350 @end |
| OLD | NEW |