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

Side by Side Diff: ios/web/web_state/ui/crw_wk_web_view_web_controller.mm

Issue 1839323003: Move _changingHistoryState to superclass. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove old comment. Created 4 years, 8 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/web_state/ui/crw_web_controller+protected.h ('k') | no next file » | 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/web_state/ui/crw_wk_web_view_web_controller.h" 5 #import "ios/web/web_state/ui/crw_wk_web_view_web_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 185
186 // Referrer for the current page. 186 // Referrer for the current page.
187 base::scoped_nsobject<NSString> _currentReferrerString; 187 base::scoped_nsobject<NSString> _currentReferrerString;
188 188
189 // Handles downloading PassKit data for WKWebView. Lazy initialized. 189 // Handles downloading PassKit data for WKWebView. Lazy initialized.
190 base::scoped_nsobject<CRWPassKitDownloader> _passKitDownloader; 190 base::scoped_nsobject<CRWPassKitDownloader> _passKitDownloader;
191 191
192 // Object for loading POST requests with body. 192 // Object for loading POST requests with body.
193 base::scoped_nsobject<CRWJSPOSTRequestLoader> _POSTRequestLoader; 193 base::scoped_nsobject<CRWJSPOSTRequestLoader> _POSTRequestLoader;
194 194
195 // Whether the web page is currently performing window.history.pushState or
196 // window.history.replaceState
197 // Set to YES on window.history.willChangeState message. To NO on
198 // window.history.didPushState or window.history.didReplaceState.
199 BOOL _changingHistoryState;
200
201 // CRWWebUIManager object for loading WebUI pages. 195 // CRWWebUIManager object for loading WebUI pages.
202 base::scoped_nsobject<CRWWebUIManager> _webUIManager; 196 base::scoped_nsobject<CRWWebUIManager> _webUIManager;
203 197
204 // Controller used for certs verification to help with blocking requests with 198 // Controller used for certs verification to help with blocking requests with
205 // bad SSL cert, presenting SSL interstitials and determining SSL status for 199 // bad SSL cert, presenting SSL interstitials and determining SSL status for
206 // Navigation Items. 200 // Navigation Items.
207 base::scoped_nsobject<CRWCertVerificationController> 201 base::scoped_nsobject<CRWCertVerificationController>
208 _certVerificationController; 202 _certVerificationController;
209 203
210 // CertVerification errors which happened inside 204 // CertVerification errors which happened inside
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 // history changes when a window.history.didPushState or 1288 // history changes when a window.history.didPushState or
1295 // window.history.didReplaceState message is received, which should happen in 1289 // window.history.didReplaceState message is received, which should happen in
1296 // the next runloop. 1290 // the next runloop.
1297 // 1291 //
1298 // Otherwise, simulate the whole delegate flow for a load (since the 1292 // Otherwise, simulate the whole delegate flow for a load (since the
1299 // superclass currently doesn't have a clean separation between URL changes 1293 // superclass currently doesn't have a clean separation between URL changes
1300 // and document changes). Note that the order of these calls is important: 1294 // and document changes). Note that the order of these calls is important:
1301 // registering a load request logically comes before updating the document 1295 // registering a load request logically comes before updating the document
1302 // URL, but also must come first since it uses state that is reset on URL 1296 // URL, but also must come first since it uses state that is reset on URL
1303 // changes. 1297 // changes.
1304 if (!_changingHistoryState) { 1298 if (!self.changingHistoryState) {
1305 // If this wasn't a previously-expected load (e.g., certain back/forward 1299 // If this wasn't a previously-expected load (e.g., certain back/forward
1306 // navigations), register the load request. 1300 // navigations), register the load request.
1307 if (![self isLoadRequestPendingForURL:newURL]) 1301 if (![self isLoadRequestPendingForURL:newURL])
1308 [self registerLoadRequest:newURL]; 1302 [self registerLoadRequest:newURL];
1309 } 1303 }
1310 1304
1311 [self setDocumentURL:newURL]; 1305 [self setDocumentURL:newURL];
1312 1306
1313 if (!_changingHistoryState) { 1307 if (!self.changingHistoryState) {
1314 [self didStartLoadingURL:_documentURL updateHistory:YES]; 1308 [self didStartLoadingURL:_documentURL updateHistory:YES];
1315 [self updateSSLStatusForCurrentNavigationItem]; 1309 [self updateSSLStatusForCurrentNavigationItem];
1316 [self didFinishNavigation]; 1310 [self didFinishNavigation];
1317 } 1311 }
1318 } 1312 }
1319 1313
1320 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { 1314 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL {
1321 if (self.loadPhase != web::LOAD_REQUESTED) 1315 if (self.loadPhase != web::LOAD_REQUESTED)
1322 return NO; 1316 return NO;
1323 1317
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 [scriptMessage.name isEqualToString:kScriptMessageName]) { 1362 [scriptMessage.name isEqualToString:kScriptMessageName]) {
1369 return [self respondToMessage:command 1363 return [self respondToMessage:command
1370 userIsInteracting:[self userIsInteracting] 1364 userIsInteracting:[self userIsInteracting]
1371 originURL:net::GURLWithNSURL([_wkWebView URL])]; 1365 originURL:net::GURLWithNSURL([_wkWebView URL])];
1372 } 1366 }
1373 1367
1374 NOTREACHED(); 1368 NOTREACHED();
1375 return NO; 1369 return NO;
1376 } 1370 }
1377 1371
1378 - (SEL)selectorToHandleJavaScriptCommand:(const std::string&)command {
1379 static std::map<std::string, SEL>* handlers = nullptr;
1380 static dispatch_once_t onceToken;
1381 dispatch_once(&onceToken, ^{
1382 handlers = new std::map<std::string, SEL>();
1383 (*handlers)["window.history.didPushState"] =
1384 @selector(handleWindowHistoryDidPushStateMessage:context:);
1385 (*handlers)["window.history.didReplaceState"] =
1386 @selector(handleWindowHistoryDidReplaceStateMessage:context:);
1387 (*handlers)["window.history.willChangeState"] =
1388 @selector(handleWindowHistoryWillChangeStateMessage:context:);
1389 });
1390 DCHECK(handlers);
1391 auto iter = handlers->find(command);
1392 return iter != handlers->end()
1393 ? iter->second
1394 : [super selectorToHandleJavaScriptCommand:command];
1395 }
1396
1397 - (BOOL)shouldAbortLoadForCancelledError:(NSError*)error { 1372 - (BOOL)shouldAbortLoadForCancelledError:(NSError*)error {
1398 DCHECK_EQ(error.code, NSURLErrorCancelled); 1373 DCHECK_EQ(error.code, NSURLErrorCancelled);
1399 // Do not abort the load if it is for an app specific URL, as such errors 1374 // Do not abort the load if it is for an app specific URL, as such errors
1400 // are produced during the app specific URL load process. 1375 // are produced during the app specific URL load process.
1401 const GURL errorURL = 1376 const GURL errorURL =
1402 net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey]); 1377 net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey]);
1403 if (web::GetWebClient()->IsAppSpecificURL(errorURL)) 1378 if (web::GetWebClient()->IsAppSpecificURL(errorURL))
1404 return NO; 1379 return NO;
1405 // Don't abort NSURLErrorCancelled errors originating from navigation 1380 // Don't abort NSURLErrorCancelled errors originating from navigation
1406 // as the WKWebView will automatically retry these loads. 1381 // as the WKWebView will automatically retry these loads.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 } 1426 }
1452 1427
1453 - (void)webViewScrollViewDidEndDragging: 1428 - (void)webViewScrollViewDidEndDragging:
1454 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy 1429 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy
1455 willDecelerate:(BOOL)decelerate { 1430 willDecelerate:(BOOL)decelerate {
1456 [self evaluateJavaScript:@"__gCrWeb.setWebViewScrollViewIsDragging(false)" 1431 [self evaluateJavaScript:@"__gCrWeb.setWebViewScrollViewIsDragging(false)"
1457 stringResultHandler:nil]; 1432 stringResultHandler:nil];
1458 } 1433 }
1459 1434
1460 #pragma mark - 1435 #pragma mark -
1461 #pragma mark JavaScript message handlers
1462
1463 - (BOOL)handleWindowHistoryWillChangeStateMessage:
1464 (base::DictionaryValue*)message
1465 context:(NSDictionary*)context {
1466 _changingHistoryState = YES;
1467 return
1468 [super handleWindowHistoryWillChangeStateMessage:message context:context];
1469 }
1470
1471 - (BOOL)handleWindowHistoryDidPushStateMessage:(base::DictionaryValue*)message
1472 context:(NSDictionary*)context {
1473 DCHECK(_changingHistoryState);
1474 _changingHistoryState = NO;
1475 return [super handleWindowHistoryDidPushStateMessage:message context:context];
1476 }
1477
1478 - (BOOL)handleWindowHistoryDidReplaceStateMessage:
1479 (base::DictionaryValue*)message
1480 context:(NSDictionary*)context {
1481 DCHECK(_changingHistoryState);
1482 _changingHistoryState = NO;
1483 return [super handleWindowHistoryDidReplaceStateMessage:message
1484 context:context];
1485 }
1486
1487 #pragma mark -
1488 #pragma mark WebUI 1436 #pragma mark WebUI
1489 1437
1490 - (void)createWebUIForURL:(const GURL&)URL { 1438 - (void)createWebUIForURL:(const GURL&)URL {
1491 [super createWebUIForURL:URL]; 1439 [super createWebUIForURL:URL];
1492 _webUIManager.reset( 1440 _webUIManager.reset(
1493 [[CRWWebUIManager alloc] initWithWebState:self.webStateImpl]); 1441 [[CRWWebUIManager alloc] initWithWebState:self.webStateImpl]);
1494 } 1442 }
1495 1443
1496 - (void)clearWebUI { 1444 - (void)clearWebUI {
1497 [super clearWebUI]; 1445 [super clearWebUI];
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 runJavaScriptTextInputPanelWithPrompt:prompt 1973 runJavaScriptTextInputPanelWithPrompt:prompt
2026 defaultText:defaultText 1974 defaultText:defaultText
2027 requestURL:requestURL 1975 requestURL:requestURL
2028 completionHandler:completionHandler]; 1976 completionHandler:completionHandler];
2029 } else if (completionHandler) { 1977 } else if (completionHandler) {
2030 completionHandler(nil); 1978 completionHandler(nil);
2031 } 1979 }
2032 } 1980 }
2033 1981
2034 @end 1982 @end
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller+protected.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698