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

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
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 #include "ios/web/public/referrer.h" 13 #include "ios/web/public/referrer.h"
14 #import "ios/web/public/navigation_manager.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 NSAssert(NO, @"Should not be called");
michaeldo 2017/02/02 19:39:18 Please use NOTREACHED() instead of NSAssert for bo
Eugene But (OOO till 7-30) 2017/02/02 20:54:32 Do we even need this implementation? No one can ca
Hiroshi Ichikawa 2017/02/03 02:14:57 Good point, I found that I don't need this impleme
44 self = [super init]; 44 return nil;
45 }
46
47 - (instancetype)initWithCoder:(NSCoder*)aDecoder {
48 NSAssert(NO, @"Should not be called");
49 return nil;
50 }
51
52 - (instancetype)initWithFrame:(CGRect)frame
53 browserState:(ios_web_view::CRIWVBrowserState*)browserState {
54 self = [super initWithFrame:frame];
45 if (self) { 55 if (self) {
46 _browserState = browserState; 56 _browserState = browserState;
47 57
48 web::WebState::CreateParams webStateCreateParams(_browserState); 58 web::WebState::CreateParams webStateCreateParams(_browserState);
49 _webState = web::WebState::Create(webStateCreateParams); 59 _webState = web::WebState::Create(webStateCreateParams);
50 _webState->SetWebUsageEnabled(true); 60 _webState->SetWebUsageEnabled(true);
51 61
52 _webStateObserver = 62 _webStateObserver =
53 base::MakeUnique<web::WebStateObserverBridge>(_webState.get(), self); 63 base::MakeUnique<web::WebStateObserverBridge>(_webState.get(), self);
54 _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self); 64 _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self);
55 _webState->SetDelegate(_webStateDelegate.get()); 65 _webState->SetDelegate(_webStateDelegate.get());
56 66
57 // Initialize Translate. 67 // Initialize Translate.
58 ios_web_view::CRIWVTranslateClient::CreateForWebState(_webState.get()); 68 ios_web_view::CRIWVTranslateClient::CreateForWebState(_webState.get());
59 } 69 }
60 return self; 70 return self;
61 } 71 }
62 72
73 - (void)willMoveToSuperview:(UIView*)newSuperview {
74 [super willMoveToSuperview:newSuperview];
75 UIView* subview = _webState->GetView();
76 subview.frame = self.frame;
Eugene But (OOO till 7-30) 2017/02/02 20:54:32 Do you need to check if |subview| is already a sub
Hiroshi Ichikawa 2017/02/03 02:14:57 Done.
77 subview.autoresizingMask =
78 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
79 [self addSubview:subview];
80 }
81
63 - (UIView*)view { 82 - (UIView*)view {
64 return _webState->GetView(); 83 return _webState->GetView();
65 } 84 }
66 85
67 - (BOOL)canGoBack { 86 - (BOOL)canGoBack {
68 return _webState && _webState->GetNavigationManager()->CanGoBack(); 87 return _webState && _webState->GetNavigationManager()->CanGoBack();
69 } 88 }
70 89
71 - (BOOL)canGoForward { 90 - (BOOL)canGoForward {
72 return _webState && _webState->GetNavigationManager()->CanGoForward(); 91 return _webState && _webState->GetNavigationManager()->CanGoForward();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 loadSuccess:success]; 173 loadSuccess:success];
155 } 174 }
156 } 175 }
157 176
158 - (void)webState:(web::WebState*)webState 177 - (void)webState:(web::WebState*)webState
159 didChangeLoadingProgress:(double)progress { 178 didChangeLoadingProgress:(double)progress {
160 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeProgress]; 179 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeProgress];
161 } 180 }
162 181
163 @end 182 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698