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

Side by Side Diff: ios/web_view/internal/criwv_web_view.mm

Issue 2675633002: Let CRIWVWebView inherit UIView instead of NSObject. (Closed)
Patch Set: Fix format. 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
« no previous file with comments | « ios/web_view/internal/criwv.mm ('k') | ios/web_view/internal/criwv_web_view_impl.h » ('j') | 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_view/internal/criwv_web_view_impl.h" 5 #import "ios/web_view/internal/criwv_web_view_internal.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #import "base/ios/weak_nsobject.h" 10 #import "base/ios/weak_nsobject.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #import "ios/web/public/navigation_manager.h"
13 #include "ios/web/public/referrer.h" 14 #include "ios/web/public/referrer.h"
14 #import "ios/web/public/navigation_manager.h"
15 #import "ios/web/public/web_state/ui/crw_web_delegate.h" 15 #import "ios/web/public/web_state/ui/crw_web_delegate.h"
16 #import "ios/web/public/web_state/web_state.h" 16 #import "ios/web/public/web_state/web_state.h"
17 #import "ios/web/public/web_state/web_state_delegate_bridge.h" 17 #import "ios/web/public/web_state/web_state_delegate_bridge.h"
18 #import "ios/web/public/web_state/web_state_observer_bridge.h" 18 #import "ios/web/public/web_state/web_state_observer_bridge.h"
19 #include "ios/web_view/internal/criwv_browser_state.h" 19 #include "ios/web_view/internal/criwv_browser_state.h"
20 #import "ios/web_view/internal/translate/criwv_translate_client.h" 20 #import "ios/web_view/internal/translate/criwv_translate_client.h"
21 #import "ios/web_view/public/criwv_web_view_delegate.h" 21 #import "ios/web_view/public/criwv_web_view_delegate.h"
22 #import "net/base/mac/url_conversions.h" 22 #import "net/base/mac/url_conversions.h"
23 #include "ui/base/page_transition_types.h" 23 #include "ui/base/page_transition_types.h"
24 #include "url/gurl.h" 24 #include "url/gurl.h"
25 25
26 @interface CRIWVWebViewImpl ()<CRWWebStateDelegate, CRWWebStateObserver> { 26 @interface CRIWVWebView ()<CRWWebStateDelegate, CRWWebStateObserver> {
27 id<CRIWVWebViewDelegate> _delegate; 27 id<CRIWVWebViewDelegate> _delegate;
28 ios_web_view::CRIWVBrowserState* _browserState; 28 ios_web_view::CRIWVBrowserState* _browserState;
29 std::unique_ptr<web::WebState> _webState; 29 std::unique_ptr<web::WebState> _webState;
30 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; 30 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate;
31 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; 31 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver;
32 CGFloat _loadProgress; 32 CGFloat _loadProgress;
33 } 33 }
34 34
35 @end 35 @end
36 36
37 @implementation CRIWVWebViewImpl 37 @implementation CRIWVWebView
38 38
39 @synthesize delegate = _delegate; 39 @synthesize delegate = _delegate;
40 @synthesize loadProgress = _loadProgress; 40 @synthesize loadProgress = _loadProgress;
41 41
42 - (instancetype)initWithBrowserState: 42 - (instancetype)initWithFrame:(CGRect)frame
43 (ios_web_view::CRIWVBrowserState*)browserState { 43 browserState:(ios_web_view::CRIWVBrowserState*)browserState {
44 self = [super init]; 44 self = [super initWithFrame:frame];
45 if (self) { 45 if (self) {
46 _browserState = browserState; 46 _browserState = browserState;
47 47
48 web::WebState::CreateParams webStateCreateParams(_browserState); 48 web::WebState::CreateParams webStateCreateParams(_browserState);
49 _webState = web::WebState::Create(webStateCreateParams); 49 _webState = web::WebState::Create(webStateCreateParams);
50 _webState->SetWebUsageEnabled(true); 50 _webState->SetWebUsageEnabled(true);
51 51
52 _webStateObserver = 52 _webStateObserver =
53 base::MakeUnique<web::WebStateObserverBridge>(_webState.get(), self); 53 base::MakeUnique<web::WebStateObserverBridge>(_webState.get(), self);
54 _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self); 54 _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self);
55 _webState->SetDelegate(_webStateDelegate.get()); 55 _webState->SetDelegate(_webStateDelegate.get());
56 56
57 // Initialize Translate. 57 // Initialize Translate.
58 ios_web_view::CRIWVTranslateClient::CreateForWebState(_webState.get()); 58 ios_web_view::CRIWVTranslateClient::CreateForWebState(_webState.get());
59 } 59 }
60 return self; 60 return self;
61 } 61 }
62 62
63 - (void)willMoveToSuperview:(UIView*)newSuperview {
64 [super willMoveToSuperview:newSuperview];
65 UIView* subview = _webState->GetView();
66 if (subview.superview == self) {
67 return;
68 }
69 subview.frame = self.frame;
70 subview.autoresizingMask =
71 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
72 [self addSubview:subview];
73 }
74
63 - (UIView*)view { 75 - (UIView*)view {
64 return _webState->GetView(); 76 return _webState->GetView();
65 } 77 }
66 78
67 - (BOOL)canGoBack { 79 - (BOOL)canGoBack {
68 return _webState && _webState->GetNavigationManager()->CanGoBack(); 80 return _webState && _webState->GetNavigationManager()->CanGoBack();
69 } 81 }
70 82
71 - (BOOL)canGoForward { 83 - (BOOL)canGoForward {
72 return _webState && _webState->GetNavigationManager()->CanGoForward(); 84 return _webState && _webState->GetNavigationManager()->CanGoForward();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 loadSuccess:success]; 166 loadSuccess:success];
155 } 167 }
156 } 168 }
157 169
158 - (void)webState:(web::WebState*)webState 170 - (void)webState:(web::WebState*)webState
159 didChangeLoadingProgress:(double)progress { 171 didChangeLoadingProgress:(double)progress {
160 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeProgress]; 172 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeProgress];
161 } 173 }
162 174
163 @end 175 @end
OLDNEW
« no previous file with comments | « ios/web_view/internal/criwv.mm ('k') | ios/web_view/internal/criwv_web_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698