OLD | NEW |
---|---|
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 | 11 |
16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
17 #error "This file requires ARC support." | 13 #error "This file requires ARC support." |
18 #endif | 14 #endif |
19 | 15 |
16 @interface WebContentsViewController () | |
17 @property(nonatomic, strong) UIView* contentView; | |
18 @end | |
19 | |
20 @implementation WebContentsViewController | 20 @implementation WebContentsViewController |
21 | 21 |
22 @synthesize webState = _webState; | 22 @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 | 23 |
32 - (void)viewDidLoad { | 24 - (void)viewDidLoad { |
33 self.view.backgroundColor = [UIColor colorWithWhite:0.75 alpha:1.0]; | 25 self.view.backgroundColor = [UIColor colorWithWhite:0.75 alpha:1.0]; |
34 | 26 |
35 UIView* webContentsView = self.webState->GetView(); | 27 [self updateContentView]; |
36 webContentsView.translatesAutoresizingMaskIntoConstraints = NO; | 28 } |
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 | 29 |
48 if (!self.webState->GetNavigationManager()->GetItemCount()) { | 30 #pragma mark - WebContentsConsumer |
49 web::NavigationManager::WebLoadParams params( | 31 |
50 GURL("https://dev.chromium.org/")); | 32 - (void)contentViewDidChange:(UIView*)contentView { |
51 params.transition_type = ui::PAGE_TRANSITION_TYPED; | 33 if (contentView == self.contentView) |
52 _webState->GetNavigationManager()->LoadURLWithParams(params); | 34 return; |
sdefresne
2017/02/07 14:44:53
ditto, can you add braces or remove them from the
marq (ping after 24h)
2017/02/07 15:08:09
Done.
| |
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]; | |
53 } | 44 } |
54 } | 45 } |
55 | 46 |
47 #pragma mark - Private methods | |
48 | |
49 - (void)updateContentView { | |
50 self.contentView.frame = self.view.bounds; | |
51 self.contentView.autoresizingMask = | |
52 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
53 [self.view addSubview:self.contentView]; | |
54 } | |
55 | |
56 @end | 56 @end |
OLD | NEW |