| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/mac/objc_property_releaser.h" | 11 #include "base/mac/objc_property_releaser.h" |
| 12 #import "base/mac/scoped_nsobject.h" | 12 #import "base/mac/scoped_nsobject.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.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 #import "ios/web/navigation/crw_session_controller.h" | 18 #import "ios/web/navigation/crw_session_controller.h" |
| 19 #include "ios/web/navigation/web_load_params.h" | |
| 20 #import "ios/web/net/crw_url_verifying_protocol_handler.h" | 19 #import "ios/web/net/crw_url_verifying_protocol_handler.h" |
| 21 #include "ios/web/net/request_tracker_factory_impl.h" | 20 #include "ios/web/net/request_tracker_factory_impl.h" |
| 22 #import "ios/web/net/web_http_protocol_handler_delegate.h" | 21 #import "ios/web/net/web_http_protocol_handler_delegate.h" |
| 23 #include "ios/web/public/referrer.h" | 22 #include "ios/web/public/referrer.h" |
| 24 #import "ios/web/public/web_controller_factory.h" | 23 #import "ios/web/public/web_controller_factory.h" |
| 25 #include "ios/web/public/web_state/web_state.h" | 24 #include "ios/web/public/web_state/web_state.h" |
| 26 #include "ios/web/shell/shell_browser_state.h" | 25 #include "ios/web/shell/shell_browser_state.h" |
| 27 #include "ios/web/web_state/ui/crw_web_controller.h" | 26 #include "ios/web/web_state/ui/crw_web_controller.h" |
| 28 #include "ios/web/web_state/web_state_impl.h" | 27 #include "ios/web/web_state/web_state_impl.h" |
| 29 #include "ui/base/page_transition_types.h" | 28 #include "ui/base/page_transition_types.h" |
| 30 | 29 |
| 31 NSString* const kWebShellBackButtonAccessibilityLabel = @"Back"; | 30 NSString* const kWebShellBackButtonAccessibilityLabel = @"Back"; |
| 32 NSString* const kWebShellForwardButtonAccessibilityLabel = @"Forward"; | 31 NSString* const kWebShellForwardButtonAccessibilityLabel = @"Forward"; |
| 33 NSString* const kWebShellAddressFieldAccessibilityLabel = @"Address field"; | 32 NSString* const kWebShellAddressFieldAccessibilityLabel = @"Address field"; |
| 34 | 33 |
| 34 using web::NavigationManager; |
| 35 |
| 35 @interface ViewController ()<CRWWebUserInterfaceDelegate> { | 36 @interface ViewController ()<CRWWebUserInterfaceDelegate> { |
| 36 web::BrowserState* _browserState; | 37 web::BrowserState* _browserState; |
| 37 base::scoped_nsobject<CRWWebController> _webController; | 38 base::scoped_nsobject<CRWWebController> _webController; |
| 38 scoped_ptr<web::RequestTrackerFactoryImpl> _requestTrackerFactory; | 39 scoped_ptr<web::RequestTrackerFactoryImpl> _requestTrackerFactory; |
| 39 scoped_ptr<web::WebHTTPProtocolHandlerDelegate> _httpProtocolDelegate; | 40 scoped_ptr<web::WebHTTPProtocolHandlerDelegate> _httpProtocolDelegate; |
| 40 | 41 |
| 41 base::mac::ObjCPropertyReleaser _propertyReleaser_ViewController; | 42 base::mac::ObjCPropertyReleaser _propertyReleaser_ViewController; |
| 42 } | 43 } |
| 43 @property(nonatomic, assign, readonly) web::WebState* webState; | 44 @property(nonatomic, assign, readonly) web::WebState* webState; |
| 44 @property(nonatomic, readwrite, retain) UITextField* field; | 45 @property(nonatomic, readwrite, retain) UITextField* field; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 webState->GetNavigationManagerImpl().InitializeSession(nil, nil, NO, 0); | 117 webState->GetNavigationManagerImpl().InitializeSession(nil, nil, NO, 0); |
| 117 _webController.reset(web::CreateWebController(std::move(webState))); | 118 _webController.reset(web::CreateWebController(std::move(webState))); |
| 118 [_webController setDelegate:self]; | 119 [_webController setDelegate:self]; |
| 119 [_webController setUIDelegate:self]; | 120 [_webController setUIDelegate:self]; |
| 120 [_webController setWebUsageEnabled:YES]; | 121 [_webController setWebUsageEnabled:YES]; |
| 121 | 122 |
| 122 UIView* view = self.webState->GetView(); | 123 UIView* view = self.webState->GetView(); |
| 123 [view setFrame:[_containerView bounds]]; | 124 [view setFrame:[_containerView bounds]]; |
| 124 [_containerView addSubview:view]; | 125 [_containerView addSubview:view]; |
| 125 | 126 |
| 126 web::WebLoadParams params(GURL("https://dev.chromium.org/")); | 127 NavigationManager::WebLoadParams params(GURL("https://dev.chromium.org/")); |
| 127 params.transition_type = ui::PAGE_TRANSITION_TYPED; | 128 params.transition_type = ui::PAGE_TRANSITION_TYPED; |
| 128 [_webController loadWithParams:params]; | 129 [_webController loadWithParams:params]; |
| 129 } | 130 } |
| 130 | 131 |
| 131 - (web::WebState*)webState { | 132 - (web::WebState*)webState { |
| 132 return [_webController webState]; | 133 return [_webController webState]; |
| 133 } | 134 } |
| 134 | 135 |
| 135 - (void)setUpNetworkStack { | 136 - (void)setUpNetworkStack { |
| 136 // Disable the default cache. | 137 // Disable the default cache. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 158 } | 159 } |
| 159 | 160 |
| 160 - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { | 161 - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { |
| 161 if (bar == _toolbarView) { | 162 if (bar == _toolbarView) { |
| 162 return UIBarPositionTopAttached; | 163 return UIBarPositionTopAttached; |
| 163 } | 164 } |
| 164 return UIBarPositionAny; | 165 return UIBarPositionAny; |
| 165 } | 166 } |
| 166 | 167 |
| 167 - (void)back { | 168 - (void)back { |
| 168 web::NavigationManager* navManager = self.webState->GetNavigationManager(); | 169 NavigationManager* navManager = self.webState->GetNavigationManager(); |
| 169 if (navManager->CanGoBack()) { | 170 if (navManager->CanGoBack()) { |
| 170 navManager->GoBack(); | 171 navManager->GoBack(); |
| 171 } | 172 } |
| 172 } | 173 } |
| 173 | 174 |
| 174 - (void)forward { | 175 - (void)forward { |
| 175 web::NavigationManager* navManager = self.webState->GetNavigationManager(); | 176 NavigationManager* navManager = self.webState->GetNavigationManager(); |
| 176 if (navManager->CanGoForward()) { | 177 if (navManager->CanGoForward()) { |
| 177 navManager->GoForward(); | 178 navManager->GoForward(); |
| 178 } | 179 } |
| 179 } | 180 } |
| 180 | 181 |
| 181 - (BOOL)textFieldShouldReturn:(UITextField*)field { | 182 - (BOOL)textFieldShouldReturn:(UITextField*)field { |
| 182 GURL url = GURL(base::SysNSStringToUTF8([field text])); | 183 GURL URL = GURL(base::SysNSStringToUTF8([field text])); |
| 183 | 184 |
| 184 // Do not try to load invalid URLs. | 185 // Do not try to load invalid URLs. |
| 185 if (url.is_valid()) { | 186 if (URL.is_valid()) { |
| 186 web::WebLoadParams params(url); | 187 NavigationManager::WebLoadParams params(URL); |
| 187 params.transition_type = ui::PAGE_TRANSITION_TYPED; | 188 params.transition_type = ui::PAGE_TRANSITION_TYPED; |
| 188 [_webController loadWithParams:params]; | 189 [_webController loadWithParams:params]; |
| 189 } | 190 } |
| 190 | 191 |
| 191 [field resignFirstResponder]; | 192 [field resignFirstResponder]; |
| 192 [self updateToolbar]; | 193 [self updateToolbar]; |
| 193 return YES; | 194 return YES; |
| 194 } | 195 } |
| 195 | 196 |
| 196 - (void)updateToolbar { | 197 - (void)updateToolbar { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 - (void)webController:(CRWWebController*)webController | 331 - (void)webController:(CRWWebController*)webController |
| 331 retrievePlaceholderOverlayImage:(void (^)(UIImage*))block { | 332 retrievePlaceholderOverlayImage:(void (^)(UIImage*))block { |
| 332 } | 333 } |
| 333 - (void)webController:(CRWWebController*)webController | 334 - (void)webController:(CRWWebController*)webController |
| 334 onFormResubmissionForRequest:(NSURLRequest*)request | 335 onFormResubmissionForRequest:(NSURLRequest*)request |
| 335 continueBlock:(ProceduralBlock)continueBlock | 336 continueBlock:(ProceduralBlock)continueBlock |
| 336 cancelBlock:(ProceduralBlock)cancelBlock { | 337 cancelBlock:(ProceduralBlock)cancelBlock { |
| 337 } | 338 } |
| 338 - (void)webWillReload { | 339 - (void)webWillReload { |
| 339 } | 340 } |
| 340 - (void)webWillInitiateLoadWithParams:(web::WebLoadParams&)params { | 341 - (void)webWillInitiateLoadWithParams: |
| 342 (NavigationManager::WebLoadParams&)params { |
| 341 } | 343 } |
| 342 - (void)webDidUpdateSessionForLoadWithParams:(const web::WebLoadParams&)params | 344 - (void)webDidUpdateSessionForLoadWithParams: |
| 345 (const NavigationManager::WebLoadParams&)params |
| 343 wasInitialNavigation:(BOOL)initialNavigation { | 346 wasInitialNavigation:(BOOL)initialNavigation { |
| 344 } | 347 } |
| 345 - (void)webWillFinishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { | 348 - (void)webWillFinishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { |
| 346 } | 349 } |
| 347 - (int)downloadImageAtUrl:(const GURL&)url | 350 - (int)downloadImageAtUrl:(const GURL&)url |
| 348 maxBitmapSize:(uint32_t)maxBitmapSize | 351 maxBitmapSize:(uint32_t)maxBitmapSize |
| 349 callback: | 352 callback: |
| 350 (const web::WebState::ImageDownloadCallback&)callback { | 353 (const web::WebState::ImageDownloadCallback&)callback { |
| 351 return -1; | 354 return -1; |
| 352 } | 355 } |
| 353 | 356 |
| 354 // ----------------------------------------------------------------------- | 357 // ----------------------------------------------------------------------- |
| 355 // CRWWebUserInterfaceDelegate implementation. | 358 // CRWWebUserInterfaceDelegate implementation. |
| 356 | 359 |
| 357 - (void)webController:(CRWWebController*)webController | 360 - (void)webController:(CRWWebController*)webController |
| 358 runAuthDialogForProtectionSpace:(NSURLProtectionSpace*)protectionSpace | 361 runAuthDialogForProtectionSpace:(NSURLProtectionSpace*)protectionSpace |
| 359 proposedCredential:(NSURLCredential*)credential | 362 proposedCredential:(NSURLCredential*)credential |
| 360 completionHandler: | 363 completionHandler: |
| 361 (void (^)(NSString* user, NSString* password))handler { | 364 (void (^)(NSString* user, NSString* password))handler { |
| 362 // Calling |handler| with nil objects is the same as not implemeting it. This | 365 // Calling |handler| with nil objects is the same as not implemeting it. This |
| 363 // method is implemented to make testing easier. | 366 // method is implemented to make testing easier. |
| 364 handler(nil, nil); | 367 handler(nil, nil); |
| 365 } | 368 } |
| 366 | 369 |
| 367 @end | 370 @end |
| OLD | NEW |