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..5ab859d5f4257c25006d87e437be6f99d01678b0 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,48 @@ |
#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 |
+@interface WebContentsViewController () |
+@property(nonatomic, strong) UIView* contentView; |
+@end |
+ |
@implementation WebContentsViewController |
-@synthesize webState = _webState; |
- |
-- (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; |
+ |
+ // 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 |