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

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

Issue 1838653002: [ios] Use WebStateObserver to update url bar in ios_web_shell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed CANARY_VERSION 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
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 #import "ios/web/net/crw_url_verifying_protocol_handler.h" 19 #import "ios/web/net/crw_url_verifying_protocol_handler.h"
20 #include "ios/web/net/request_tracker_factory_impl.h" 20 #include "ios/web/net/request_tracker_factory_impl.h"
21 #import "ios/web/net/web_http_protocol_handler_delegate.h" 21 #import "ios/web/net/web_http_protocol_handler_delegate.h"
22 #include "ios/web/public/referrer.h" 22 #include "ios/web/public/referrer.h"
23 #import "ios/web/public/web_controller_factory.h" 23 #import "ios/web/public/web_controller_factory.h"
24 #include "ios/web/public/web_state/web_state.h" 24 #include "ios/web/public/web_state/web_state.h"
25 #import "ios/web/public/web_state/web_state_observer_bridge.h"
25 #include "ios/web/shell/shell_browser_state.h" 26 #include "ios/web/shell/shell_browser_state.h"
26 #include "ios/web/web_state/ui/crw_web_controller.h" 27 #include "ios/web/web_state/ui/crw_web_controller.h"
27 #include "ios/web/web_state/web_state_impl.h" 28 #include "ios/web/web_state/web_state_impl.h"
28 #include "ui/base/page_transition_types.h" 29 #include "ui/base/page_transition_types.h"
29 30
30 NSString* const kWebShellBackButtonAccessibilityLabel = @"Back"; 31 NSString* const kWebShellBackButtonAccessibilityLabel = @"Back";
31 NSString* const kWebShellForwardButtonAccessibilityLabel = @"Forward"; 32 NSString* const kWebShellForwardButtonAccessibilityLabel = @"Forward";
32 NSString* const kWebShellAddressFieldAccessibilityLabel = @"Address field"; 33 NSString* const kWebShellAddressFieldAccessibilityLabel = @"Address field";
33 34
34 using web::NavigationManager; 35 using web::NavigationManager;
35 36
36 @interface ViewController ()<CRWWebUserInterfaceDelegate> { 37 @interface ViewController ()<CRWWebStateObserver, CRWWebUserInterfaceDelegate> {
37 web::BrowserState* _browserState; 38 web::BrowserState* _browserState;
38 base::scoped_nsobject<CRWWebController> _webController; 39 base::scoped_nsobject<CRWWebController> _webController;
39 scoped_ptr<web::RequestTrackerFactoryImpl> _requestTrackerFactory; 40 scoped_ptr<web::RequestTrackerFactoryImpl> _requestTrackerFactory;
40 scoped_ptr<web::WebHTTPProtocolHandlerDelegate> _httpProtocolDelegate; 41 scoped_ptr<web::WebHTTPProtocolHandlerDelegate> _httpProtocolDelegate;
42 scoped_ptr<web::WebStateObserverBridge> _webStateObserver;
41 43
42 base::mac::ObjCPropertyReleaser _propertyReleaser_ViewController; 44 base::mac::ObjCPropertyReleaser _propertyReleaser_ViewController;
43 } 45 }
44 @property(nonatomic, assign, readonly) web::WebState* webState; 46 @property(nonatomic, assign, readonly) web::WebState* webState;
45 @property(nonatomic, readwrite, retain) UITextField* field; 47 @property(nonatomic, readwrite, retain) UITextField* field;
46 @end 48 @end
47 49
48 @implementation ViewController 50 @implementation ViewController
49 51
50 @synthesize field = _field; 52 @synthesize field = _field;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // Set up the network stack before creating the WebState. 115 // Set up the network stack before creating the WebState.
114 [self setUpNetworkStack]; 116 [self setUpNetworkStack];
115 117
116 scoped_ptr<web::WebStateImpl> webState(new web::WebStateImpl(_browserState)); 118 scoped_ptr<web::WebStateImpl> webState(new web::WebStateImpl(_browserState));
117 webState->GetNavigationManagerImpl().InitializeSession(nil, nil, NO, 0); 119 webState->GetNavigationManagerImpl().InitializeSession(nil, nil, NO, 0);
118 _webController.reset(web::CreateWebController(std::move(webState))); 120 _webController.reset(web::CreateWebController(std::move(webState)));
119 [_webController setDelegate:self]; 121 [_webController setDelegate:self];
120 [_webController setUIDelegate:self]; 122 [_webController setUIDelegate:self];
121 [_webController setWebUsageEnabled:YES]; 123 [_webController setWebUsageEnabled:YES];
122 124
125 _webStateObserver.reset(new web::WebStateObserverBridge(self.webState, self));
126
123 UIView* view = self.webState->GetView(); 127 UIView* view = self.webState->GetView();
124 [view setFrame:[_containerView bounds]]; 128 [view setFrame:[_containerView bounds]];
125 [_containerView addSubview:view]; 129 [_containerView addSubview:view];
126 130
127 NavigationManager::WebLoadParams params(GURL("https://dev.chromium.org/")); 131 NavigationManager::WebLoadParams params(GURL("https://dev.chromium.org/"));
128 params.transition_type = ui::PAGE_TRANSITION_TYPED; 132 params.transition_type = ui::PAGE_TRANSITION_TYPED;
129 [_webController loadWithParams:params]; 133 [_webController loadWithParams:params];
130 } 134 }
131 135
132 - (web::WebState*)webState { 136 - (web::WebState*)webState {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 if (newIndex >= [colors count]) { 256 if (newIndex >= [colors count]) {
253 // TODO(rohitrao): Out of colors! Consider prompting the user to pick their 257 // TODO(rohitrao): Out of colors! Consider prompting the user to pick their
254 // own color here. Also consider allowing the user to choose the entire set 258 // own color here. Also consider allowing the user to choose the entire set
255 // of colors or allowing the user to choose color randomization. 259 // of colors or allowing the user to choose color randomization.
256 newIndex = 0; 260 newIndex = 0;
257 } 261 }
258 _toolbarView.barTintColor = [colors objectAtIndex:newIndex]; 262 _toolbarView.barTintColor = [colors objectAtIndex:newIndex];
259 } 263 }
260 264
261 // ----------------------------------------------------------------------- 265 // -----------------------------------------------------------------------
266 // WebStateObserver implementation.
267
268 - (void)didStartProvisionalNavigationForURL:(const GURL&)URL {
269 [self updateToolbar];
270 }
271
272 - (void)didCommitNavigationWithDetails:
273 (const web::LoadCommittedDetails&)details {
274 [self updateToolbar];
275 }
276
277 - (void)webStateDidLoadPage:(web::WebState*)webState {
278 DCHECK_EQ(self.webState, webState);
279 [self updateToolbar];
280 }
281
282 // -----------------------------------------------------------------------
262 // WebDelegate implementation. 283 // WebDelegate implementation.
263 284
264 - (void)webWillAddPendingURL:(const GURL&)url 285 - (void)webWillAddPendingURL:(const GURL&)url
265 transition:(ui::PageTransition)transition { 286 transition:(ui::PageTransition)transition {
266 } 287 }
267 - (void)webDidAddPendingURL { 288 - (void)webDidAddPendingURL {
268 [self updateToolbar];
269 } 289 }
270 - (void)webCancelStartLoadingRequest { 290 - (void)webCancelStartLoadingRequest {
271 } 291 }
272 - (void)webDidStartLoadingURL:(const GURL&)currentUrl 292 - (void)webDidStartLoadingURL:(const GURL&)currentUrl
273 shouldUpdateHistory:(BOOL)updateHistory { 293 shouldUpdateHistory:(BOOL)updateHistory {
274 [self updateToolbar];
275 } 294 }
276 - (void)webDidFinishWithURL:(const GURL&)url loadSuccess:(BOOL)loadSuccess { 295 - (void)webDidFinishWithURL:(const GURL&)url loadSuccess:(BOOL)loadSuccess {
277 [self updateToolbar];
278 } 296 }
279 297
280 - (CRWWebController*)webPageOrderedOpen:(const GURL&)url 298 - (CRWWebController*)webPageOrderedOpen:(const GURL&)url
281 referrer:(const web::Referrer&)referrer 299 referrer:(const web::Referrer&)referrer
282 windowName:(NSString*)windowName 300 windowName:(NSString*)windowName
283 inBackground:(BOOL)inBackground { 301 inBackground:(BOOL)inBackground {
284 return nil; 302 return nil;
285 } 303 }
286 304
287 - (CRWWebController*)webPageOrderedOpen { 305 - (CRWWebController*)webPageOrderedOpen {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 runAuthDialogForProtectionSpace:(NSURLProtectionSpace*)protectionSpace 379 runAuthDialogForProtectionSpace:(NSURLProtectionSpace*)protectionSpace
362 proposedCredential:(NSURLCredential*)credential 380 proposedCredential:(NSURLCredential*)credential
363 completionHandler: 381 completionHandler:
364 (void (^)(NSString* user, NSString* password))handler { 382 (void (^)(NSString* user, NSString* password))handler {
365 // Calling |handler| with nil objects is the same as not implemeting it. This 383 // Calling |handler| with nil objects is the same as not implemeting it. This
366 // method is implemented to make testing easier. 384 // method is implemented to make testing easier.
367 handler(nil, nil); 385 handler(nil, nil);
368 } 386 }
369 387
370 @end 388 @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