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

Side by Side Diff: ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.mm

Issue 2675763002: [ios clean] Consumer interface for WebContents (Closed)
Patch Set: Feedback. Created 3 years, 10 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // ====== New Architecture ===== 5 // ====== New Architecture =====
6 // = This code is only used in the new iOS Chrome architecture. = 6 // = This code is only used in the new iOS Chrome architecture. =
7 // ============================================================================ 7 // ============================================================================
8 8
9 #import "ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.h " 9 #import "ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.h "
10 10
11 #import "ios/web/public/navigation_manager.h"
12 #include "ios/web/public/web_state/web_state.h"
13 #include "ui/base/page_transition_types.h"
14 #include "url/gurl.h"
15
16 #if !defined(__has_feature) || !__has_feature(objc_arc) 11 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support." 12 #error "This file requires ARC support."
18 #endif 13 #endif
19 14
15 @interface WebContentsViewController ()
16 @property(nonatomic, strong) UIView* contentView;
17 @end
18
20 @implementation WebContentsViewController 19 @implementation WebContentsViewController
21 20
22 @synthesize webState = _webState; 21 @synthesize contentView = _contentView;
23
24 - (instancetype)initWithWebState:(web::WebState*)webState {
25 if ((self = [super initWithNibName:nil bundle:nil])) {
26 DCHECK(webState);
27 _webState = webState;
28 }
29 return self;
30 }
31 22
32 - (void)viewDidLoad { 23 - (void)viewDidLoad {
33 self.view.backgroundColor = [UIColor colorWithWhite:0.75 alpha:1.0]; 24 self.view.backgroundColor = [UIColor colorWithWhite:0.75 alpha:1.0];
34 25
35 UIView* webContentsView = self.webState->GetView(); 26 [self updateContentView];
36 webContentsView.translatesAutoresizingMaskIntoConstraints = NO; 27 }
37 [self.view addSubview:webContentsView];
38 [NSLayoutConstraint activateConstraints:@[
39 [webContentsView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
40 [webContentsView.bottomAnchor
41 constraintEqualToAnchor:self.view.bottomAnchor],
42 [webContentsView.leadingAnchor
43 constraintEqualToAnchor:self.view.leadingAnchor],
44 [webContentsView.trailingAnchor
45 constraintEqualToAnchor:self.view.trailingAnchor],
46 ]];
47 28
48 if (!self.webState->GetNavigationManager()->GetItemCount()) { 29 #pragma mark - WebContentsConsumer
49 web::NavigationManager::WebLoadParams params( 30
50 GURL("https://dev.chromium.org/")); 31 - (void)contentViewDidChange:(UIView*)contentView {
51 params.transition_type = ui::PAGE_TRANSITION_TYPED; 32 if (contentView == self.contentView)
52 _webState->GetNavigationManager()->LoadURLWithParams(params); 33 return;
53 } 34
35 // If there was a previous content view, remove it from the view hierarchy.
36 [self.contentView removeFromSuperview];
37 self.contentView = contentView;
38
39 // If self.view hasn't loaded yet, this call shouldn't induce that load.
40 // (calling self.view will trigger -loadView, etc.). Only update for the
41 // new content view if there's a view to update.
42 if (self.viewIfLoaded)
43 [self updateContentView];
44 }
45
46 #pragma mark - Private methods
47
48 - (void)updateContentView {
49 self.contentView.frame = self.view.bounds;
50 self.contentView.autoresizingMask =
51 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
52 [self.view addSubview:self.contentView];
54 } 53 }
55 54
56 @end 55 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698