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

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

Issue 2653083002: Cleanup ios/web_view. (Closed)
Patch Set: Respond to more comments. 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_web_view_impl.h ('k') | ios/web_view/internal/pref_names.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/web_view/internal/criwv_web_view_impl.h"
6
7 #include <memory>
8 #include <utility>
9
10 #import "base/ios/weak_nsobject.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/strings/sys_string_conversions.h"
13 #import "ios/web/navigation/crw_session_controller.h"
14 #include "ios/web/public/referrer.h"
15 #import "ios/web/public/navigation_manager.h"
16 #import "ios/web/public/web_state/ui/crw_web_delegate.h"
17 #import "ios/web/public/web_state/web_state.h"
18 #import "ios/web/public/web_state/web_state_delegate_bridge.h"
19 #import "ios/web/web_state/ui/crw_web_controller.h"
20 #import "ios/web/web_state/web_state_impl.h"
21 #include "ios/web_view/internal/criwv_browser_state.h"
22 #import "ios/web_view/internal/translate/criwv_translate_client.h"
23 #import "ios/web_view/public/criwv_web_view_delegate.h"
24 #import "net/base/mac/url_conversions.h"
25 #include "ui/base/page_transition_types.h"
26 #include "url/gurl.h"
27
28 @interface CRIWVWebViewImpl ()<CRWWebDelegate, CRWWebStateDelegate> {
29 id<CRIWVWebViewDelegate> _delegate;
30 ios_web_view::CRIWVBrowserState* _browserState;
31 std::unique_ptr<web::WebStateImpl> _webStateImpl;
32 base::WeakNSObject<CRWWebController> _webController;
33 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate;
34
35 CGFloat _loadProgress;
36 }
37
38 @end
39
40 @implementation CRIWVWebViewImpl
41
42 @synthesize delegate = _delegate;
43 @synthesize loadProgress = _loadProgress;
44
45 - (instancetype)initWithBrowserState:
46 (ios_web_view::CRIWVBrowserState*)browserState {
47 self = [super init];
48 if (self) {
49 _browserState = browserState;
50 _webStateImpl = base::MakeUnique<web::WebStateImpl>(_browserState);
51 _webStateImpl->GetNavigationManagerImpl().InitializeSession(nil, nil, NO,
52 0);
53 _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self);
54 _webStateImpl->SetDelegate(_webStateDelegate.get());
55 _webController.reset(_webStateImpl->GetWebController());
56 [_webController setDelegate:self];
57 [_webController setWebUsageEnabled:YES];
58
59 // Initialize Translate.
60 ios_web_view::CRIWVTranslateClient::CreateForWebState(_webStateImpl.get());
61 }
62 return self;
63 }
64
65 - (UIView*)view {
66 return [_webController view];
67 }
68
69 - (BOOL)canGoBack {
70 return _webStateImpl && _webStateImpl->GetNavigationManager()->CanGoBack();
71 }
72
73 - (BOOL)canGoForward {
74 return _webStateImpl && _webStateImpl->GetNavigationManager()->CanGoForward();
75 }
76
77 - (BOOL)isLoading {
78 return _webStateImpl->IsLoading();
79 }
80
81 - (NSURL*)visibleURL {
82 return net::NSURLWithGURL(_webStateImpl->GetVisibleURL());
83 }
84
85 - (NSString*)pageTitle {
86 return base::SysUTF16ToNSString(_webStateImpl->GetTitle());
87 }
88
89 - (void)goBack {
90 if (_webStateImpl->GetNavigationManager())
91 _webStateImpl->GetNavigationManager()->GoBack();
92 }
93
94 - (void)goForward {
95 if (_webStateImpl->GetNavigationManager())
96 _webStateImpl->GetNavigationManager()->GoForward();
97 }
98
99 - (void)reload {
100 [_webController reload];
101 }
102
103 - (void)stopLoading {
104 [_webController stopLoading];
105 }
106
107 - (void)loadURL:(NSURL*)URL {
108 web::NavigationManager::WebLoadParams params(net::GURLWithNSURL(URL));
109 params.transition_type = ui::PAGE_TRANSITION_TYPED;
110 [_webController loadWithParams:params];
111 }
112
113 - (void)evaluateJavaScript:(NSString*)javaScriptString
114 completionHandler:(void (^)(id, NSError*))completionHandler {
115 [_webStateImpl->GetJSInjectionReceiver() executeJavaScript:javaScriptString
116 completionHandler:completionHandler];
117 }
118
119 - (void)setDelegate:(id<CRIWVWebViewDelegate>)delegate {
120 _delegate = delegate;
121
122 // Set up the translate delegate.
123 ios_web_view::CRIWVTranslateClient* translateClient =
124 ios_web_view::CRIWVTranslateClient::FromWebState(_webStateImpl.get());
125 id<CRIWVTranslateDelegate> translateDelegate = nil;
126 if ([_delegate respondsToSelector:@selector(translateDelegate)])
127 translateDelegate = [_delegate translateDelegate];
128 translateClient->set_translate_delegate(translateDelegate);
129 }
130
131 // -----------------------------------------------------------------------
132 // WebDelegate implementation.
133
134 - (void)notifyDidUpdateWithChanges:(CRIWVWebViewUpdateType)changes {
135 SEL selector = @selector(webView:didUpdateWithChanges:);
136 if ([_delegate respondsToSelector:selector]) {
137 [_delegate webView:self didUpdateWithChanges:changes];
138 }
139 }
140
141 - (void)webController:(CRWWebController*)webController
142 titleDidChange:(NSString*)title {
143 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeTitle];
144 }
145
146 - (void)webDidUpdateSessionForLoadWithParams:
147 (const web::NavigationManager::WebLoadParams&)params
148 wasInitialNavigation:(BOOL)initialNavigation {
149 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
150 }
151
152 - (void)webWillFinishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry {
153 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
154 }
155
156 - (void)webDidAddPendingURL {
157 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
158 }
159
160 - (void)webDidUpdateHistoryStateWithPageURL:(const GURL&)pageUrl {
161 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
162 }
163
164 - (void)webCancelStartLoadingRequest {
165 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
166 }
167
168 - (void)webDidStartLoadingURL:(const GURL&)currentUrl
169 shouldUpdateHistory:(BOOL)updateHistory {
170 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
171 }
172
173 - (void)webDidFinishWithURL:(const GURL&)url loadSuccess:(BOOL)loadSuccess {
174 SEL selector = @selector(webView:didFinishLoadingWithURL:loadSuccess:);
175 if ([_delegate respondsToSelector:selector]) {
176 [_delegate webView:self
177 didFinishLoadingWithURL:net::NSURLWithGURL(url)
178 loadSuccess:loadSuccess];
179 }
180 }
181
182 - (void)webLoadCancelled:(const GURL&)url {
183 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeURL];
184 }
185
186 - (void)webWillAddPendingURL:(const GURL&)url
187 transition:(ui::PageTransition)transition {
188 }
189 - (CRWWebController*)webPageOrderedOpen:(const GURL&)url
190 referrer:(const web::Referrer&)referrer
191 windowName:(NSString*)windowName
192 inBackground:(BOOL)inBackground {
193 return nil;
194 }
195
196 - (CRWWebController*)webPageOrderedOpen {
197 return nil;
198 }
199
200 - (void)webPageOrderedClose {
201 }
202 - (void)openURLWithParams:(const web::WebState::OpenURLParams&)params {
203 }
204 - (BOOL)openExternalURL:(const GURL&)url linkClicked:(BOOL)linkClicked {
205 return NO;
206 }
207 - (void)webController:(CRWWebController*)webController
208 retrievePlaceholderOverlayImage:(void (^)(UIImage*))block {
209 }
210 - (void)webController:(CRWWebController*)webController
211 onFormResubmissionForRequest:(NSURLRequest*)request
212 continueBlock:(ProceduralBlock)continueBlock
213 cancelBlock:(ProceduralBlock)cancelBlock {
214 }
215 - (void)webWillReload {
216 }
217 - (void)webWillInitiateLoadWithParams:
218 (web::NavigationManager::WebLoadParams&)params {
219 }
220 - (BOOL)webController:(CRWWebController*)webController
221 shouldOpenURL:(const GURL&)url
222 mainDocumentURL:(const GURL&)mainDocumentURL
223 linkClicked:(BOOL)linkClicked {
224 SEL selector = @selector(webView:shouldOpenURL:mainDocumentURL:linkClicked:);
225 if ([_delegate respondsToSelector:selector]) {
226 return [_delegate webView:self
227 shouldOpenURL:net::NSURLWithGURL(url)
228 mainDocumentURL:net::NSURLWithGURL(mainDocumentURL)
229 linkClicked:linkClicked];
230 }
231 return YES;
232 }
233
234 // -----------------------------------------------------------------------
235 // CRWWebStateDelegate implementation.
236
237 - (void)webState:(web::WebState*)webState didChangeProgress:(double)progress {
238 _loadProgress = progress;
239 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeProgress];
240 }
241
242 @end
OLDNEW
« no previous file with comments | « ios/web_view/internal/criwv_web_view_impl.h ('k') | ios/web_view/internal/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698