Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: ios/web/shell/view_controller.mm

Issue 1833983002: [ios] Switched web shell to use WebState for view and navigation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 22 matching lines...) Expand all
33 NSString* const kWebShellAddressFieldAccessibilityLabel = @"Address field"; 33 NSString* const kWebShellAddressFieldAccessibilityLabel = @"Address field";
34 34
35 @interface ViewController ()<CRWWebUserInterfaceDelegate> { 35 @interface ViewController ()<CRWWebUserInterfaceDelegate> {
36 web::BrowserState* _browserState; 36 web::BrowserState* _browserState;
37 base::scoped_nsobject<CRWWebController> _webController; 37 base::scoped_nsobject<CRWWebController> _webController;
38 scoped_ptr<web::RequestTrackerFactoryImpl> _requestTrackerFactory; 38 scoped_ptr<web::RequestTrackerFactoryImpl> _requestTrackerFactory;
39 scoped_ptr<web::WebHTTPProtocolHandlerDelegate> _httpProtocolDelegate; 39 scoped_ptr<web::WebHTTPProtocolHandlerDelegate> _httpProtocolDelegate;
40 40
41 base::mac::ObjCPropertyReleaser _propertyReleaser_ViewController; 41 base::mac::ObjCPropertyReleaser _propertyReleaser_ViewController;
42 } 42 }
43 @property(nonatomic, assign, readonly) web::WebState* webState;
43 @property(nonatomic, readwrite, retain) UITextField* field; 44 @property(nonatomic, readwrite, retain) UITextField* field;
44 @end 45 @end
45 46
46 @implementation ViewController 47 @implementation ViewController
47 48
48 @synthesize field = _field; 49 @synthesize field = _field;
49 @synthesize containerView = _containerView; 50 @synthesize containerView = _containerView;
50 @synthesize toolbarView = _toolbarView; 51 @synthesize toolbarView = _toolbarView;
51 52
52 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState { 53 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Set up the network stack before creating the WebState. 112 // Set up the network stack before creating the WebState.
112 [self setUpNetworkStack]; 113 [self setUpNetworkStack];
113 114
114 scoped_ptr<web::WebStateImpl> webState(new web::WebStateImpl(_browserState)); 115 scoped_ptr<web::WebStateImpl> webState(new web::WebStateImpl(_browserState));
115 webState->GetNavigationManagerImpl().InitializeSession(nil, nil, NO, 0); 116 webState->GetNavigationManagerImpl().InitializeSession(nil, nil, NO, 0);
116 _webController.reset(web::CreateWebController(std::move(webState))); 117 _webController.reset(web::CreateWebController(std::move(webState)));
117 [_webController setDelegate:self]; 118 [_webController setDelegate:self];
118 [_webController setUIDelegate:self]; 119 [_webController setUIDelegate:self];
119 [_webController setWebUsageEnabled:YES]; 120 [_webController setWebUsageEnabled:YES];
120 121
121 [[_webController view] setFrame:[_containerView bounds]]; 122 UIView* view = self.webState->GetView();
122 [_containerView addSubview:[_webController view]]; 123 [view setFrame:[_containerView bounds]];
124 [_containerView addSubview:view];
123 125
124 web::WebLoadParams params(GURL("https://dev.chromium.org/")); 126 web::WebLoadParams params(GURL("https://dev.chromium.org/"));
125 params.transition_type = ui::PAGE_TRANSITION_TYPED; 127 params.transition_type = ui::PAGE_TRANSITION_TYPED;
126 [_webController loadWithParams:params]; 128 [_webController loadWithParams:params];
127 } 129 }
128 130
131 - (web::WebState*)webState {
132 return [_webController webState];
133 }
134
129 - (void)setUpNetworkStack { 135 - (void)setUpNetworkStack {
130 // Disable the default cache. 136 // Disable the default cache.
131 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; 137 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]];
132 138
133 _httpProtocolDelegate.reset(new web::WebHTTPProtocolHandlerDelegate( 139 _httpProtocolDelegate.reset(new web::WebHTTPProtocolHandlerDelegate(
134 _browserState->GetRequestContext())); 140 _browserState->GetRequestContext()));
135 net::HTTPProtocolHandlerDelegate::SetInstance(_httpProtocolDelegate.get()); 141 net::HTTPProtocolHandlerDelegate::SetInstance(_httpProtocolDelegate.get());
136 BOOL success = [NSURLProtocol registerClass:[CRNHTTPProtocolHandler class]]; 142 BOOL success = [NSURLProtocol registerClass:[CRNHTTPProtocolHandler class]];
137 DCHECK(success); 143 DCHECK(success);
138 // The CRWURLVerifyingProtocolHandler is used to verify URL in the 144 // The CRWURLVerifyingProtocolHandler is used to verify URL in the
(...skipping 13 matching lines...) Expand all
152 } 158 }
153 159
154 - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { 160 - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar {
155 if (bar == _toolbarView) { 161 if (bar == _toolbarView) {
156 return UIBarPositionTopAttached; 162 return UIBarPositionTopAttached;
157 } 163 }
158 return UIBarPositionAny; 164 return UIBarPositionAny;
159 } 165 }
160 166
161 - (void)back { 167 - (void)back {
162 if ([_webController canGoBack]) { 168 web::NavigationManager* navManager = self.webState->GetNavigationManager();
163 [_webController goBack]; 169 if (navManager->CanGoBack()) {
170 navManager->GoBack();
164 } 171 }
165 } 172 }
166 173
167 - (void)forward { 174 - (void)forward {
168 if ([_webController canGoForward]) { 175 web::NavigationManager* navManager = self.webState->GetNavigationManager();
169 [_webController goForward]; 176 if (navManager->CanGoForward()) {
177 navManager->GoForward();
170 } 178 }
171 } 179 }
172 180
173 - (BOOL)textFieldShouldReturn:(UITextField*)field { 181 - (BOOL)textFieldShouldReturn:(UITextField*)field {
174 GURL url = GURL(base::SysNSStringToUTF8([field text])); 182 GURL url = GURL(base::SysNSStringToUTF8([field text]));
175 183
176 // Do not try to load invalid URLs. 184 // Do not try to load invalid URLs.
177 if (url.is_valid()) { 185 if (url.is_valid()) {
178 web::WebLoadParams params(url); 186 web::WebLoadParams params(url);
179 params.transition_type = ui::PAGE_TRANSITION_TYPED; 187 params.transition_type = ui::PAGE_TRANSITION_TYPED;
180 [_webController loadWithParams:params]; 188 [_webController loadWithParams:params];
181 } 189 }
182 190
183 [field resignFirstResponder]; 191 [field resignFirstResponder];
184 [self updateToolbar]; 192 [self updateToolbar];
185 return YES; 193 return YES;
186 } 194 }
187 195
188 - (void)updateToolbar { 196 - (void)updateToolbar {
189 // Do not update the URL if the text field is currently being edited. 197 // Do not update the URL if the text field is currently being edited.
190 if ([_field isFirstResponder]) { 198 if ([_field isFirstResponder]) {
191 return; 199 return;
192 } 200 }
193 201
194 const GURL& url = [_webController webStateImpl]->GetVisibleURL(); 202 const GURL& visibleURL = self.webState->GetVisibleURL();
195 [_field setText:base::SysUTF8ToNSString(url.spec())]; 203 [_field setText:base::SysUTF8ToNSString(visibleURL.spec())];
196 } 204 }
197 205
198 // ----------------------------------------------------------------------- 206 // -----------------------------------------------------------------------
199 #pragma mark Bikeshedding Implementation 207 #pragma mark Bikeshedding Implementation
200 208
201 // Overridden to allow this view controller to receive motion events by being 209 // Overridden to allow this view controller to receive motion events by being
202 // first responder when no other views are. 210 // first responder when no other views are.
203 - (BOOL)canBecomeFirstResponder { 211 - (BOOL)canBecomeFirstResponder {
204 return YES; 212 return YES;
205 } 213 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 runAuthDialogForProtectionSpace:(NSURLProtectionSpace*)protectionSpace 358 runAuthDialogForProtectionSpace:(NSURLProtectionSpace*)protectionSpace
351 proposedCredential:(NSURLCredential*)credential 359 proposedCredential:(NSURLCredential*)credential
352 completionHandler: 360 completionHandler:
353 (void (^)(NSString* user, NSString* password))handler { 361 (void (^)(NSString* user, NSString* password))handler {
354 // Calling |handler| with nil objects is the same as not implemeting it. This 362 // Calling |handler| with nil objects is the same as not implemeting it. This
355 // method is implemented to make testing easier. 363 // method is implemented to make testing easier.
356 handler(nil, nil); 364 handler(nil, nil);
357 } 365 }
358 366
359 @end 367 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698