Chromium Code Reviews| Index: ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.mm |
| diff --git a/ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.mm b/ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.mm |
| index 1b9c41dcf22333f16988936e56360275a7e75abb..66a44e953b6856dbf5f5c1768b26a38bad722f09 100644 |
| --- a/ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.mm |
| +++ b/ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.mm |
| @@ -8,49 +8,49 @@ |
| #import "ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.h" |
| -#import "ios/web/public/navigation_manager.h" |
| -#include "ios/web/public/web_state/web_state.h" |
| -#include "ui/base/page_transition_types.h" |
| -#include "url/gurl.h" |
| #if !defined(__has_feature) || !__has_feature(objc_arc) |
| #error "This file requires ARC support." |
| #endif |
| -@implementation WebContentsViewController |
| +@interface WebContentsViewController () |
| +@property(nonatomic, strong) UIView* contentView; |
| +@end |
| -@synthesize webState = _webState; |
| +@implementation WebContentsViewController |
| -- (instancetype)initWithWebState:(web::WebState*)webState { |
| - if ((self = [super initWithNibName:nil bundle:nil])) { |
| - DCHECK(webState); |
| - _webState = webState; |
| - } |
| - return self; |
| -} |
| +@synthesize contentView = _contentView; |
| - (void)viewDidLoad { |
| self.view.backgroundColor = [UIColor colorWithWhite:0.75 alpha:1.0]; |
| - UIView* webContentsView = self.webState->GetView(); |
| - webContentsView.translatesAutoresizingMaskIntoConstraints = NO; |
| - [self.view addSubview:webContentsView]; |
| - [NSLayoutConstraint activateConstraints:@[ |
| - [webContentsView.topAnchor constraintEqualToAnchor:self.view.topAnchor], |
| - [webContentsView.bottomAnchor |
| - constraintEqualToAnchor:self.view.bottomAnchor], |
| - [webContentsView.leadingAnchor |
| - constraintEqualToAnchor:self.view.leadingAnchor], |
| - [webContentsView.trailingAnchor |
| - constraintEqualToAnchor:self.view.trailingAnchor], |
| - ]]; |
| - |
| - if (!self.webState->GetNavigationManager()->GetItemCount()) { |
| - web::NavigationManager::WebLoadParams params( |
| - GURL("https://dev.chromium.org/")); |
| - params.transition_type = ui::PAGE_TRANSITION_TYPED; |
| - _webState->GetNavigationManager()->LoadURLWithParams(params); |
| + [self updateContentView]; |
| +} |
| + |
| +#pragma mark - WebContentsConsumer |
| + |
| +- (void)contentViewDidChange:(UIView*)contentView { |
| + if (contentView == self.contentView) |
| + 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.
|
| + // If there was a previous content view, remove it from the view hierarchy. |
| + [self.contentView removeFromSuperview]; |
| + self.contentView = contentView; |
| + |
| + // If self.view hasn't loaded yet, this call shouldn't induce that load. |
| + // (calling self.view will trigger -loadView, etc.). Only update for the |
| + // new content view if there's a view to update. |
| + if (self.viewIfLoaded) { |
| + [self updateContentView]; |
| } |
| } |
| +#pragma mark - Private methods |
| + |
| +- (void)updateContentView { |
| + self.contentView.frame = self.view.bounds; |
| + self.contentView.autoresizingMask = |
| + UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| + [self.view addSubview:self.contentView]; |
| +} |
| + |
| @end |