| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #import <objc/runtime.h> | 9 #import <objc/runtime.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 2467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2478 } | 2478 } |
| 2479 | 2479 |
| 2480 - (CGFloat)headerHeightForContainerView: | 2480 - (CGFloat)headerHeightForContainerView: |
| 2481 (CRWWebControllerContainerView*)containerView { | 2481 (CRWWebControllerContainerView*)containerView { |
| 2482 return [self headerHeight]; | 2482 return [self headerHeight]; |
| 2483 } | 2483 } |
| 2484 | 2484 |
| 2485 #pragma mark - | 2485 #pragma mark - |
| 2486 #pragma mark CRWJSInjectionEvaluator Methods | 2486 #pragma mark CRWJSInjectionEvaluator Methods |
| 2487 | 2487 |
| 2488 - (void)evaluateJavaScript:(NSString*)script | |
| 2489 stringResultHandler:(web::JavaScriptCompletion)handler { | |
| 2490 NSString* safeScript = [self scriptByAddingWindowIDCheckForScript:script]; | |
| 2491 web::EvaluateJavaScript(_webView, safeScript, handler); | |
| 2492 } | |
| 2493 | |
| 2494 - (void)executeJavaScript:(NSString*)script | 2488 - (void)executeJavaScript:(NSString*)script |
| 2495 completionHandler:(web::JavaScriptResultBlock)completionHandler { | 2489 completionHandler:(web::JavaScriptResultBlock)completionHandler { |
| 2496 NSString* safeScript = [self scriptByAddingWindowIDCheckForScript:script]; | 2490 NSString* safeScript = [self scriptByAddingWindowIDCheckForScript:script]; |
| 2497 web::ExecuteJavaScript(_webView, safeScript, completionHandler); | 2491 web::ExecuteJavaScript(_webView, safeScript, completionHandler); |
| 2498 } | 2492 } |
| 2499 | 2493 |
| 2500 - (BOOL)scriptHasBeenInjectedForClass:(Class)injectionManagerClass { | 2494 - (BOOL)scriptHasBeenInjectedForClass:(Class)injectionManagerClass { |
| 2501 return [_injectedScriptManagers containsObject:injectionManagerClass]; | 2495 return [_injectedScriptManagers containsObject:injectionManagerClass]; |
| 2502 } | 2496 } |
| 2503 | 2497 |
| 2504 - (void)injectScript:(NSString*)script forClass:(Class)JSInjectionManagerClass { | 2498 - (void)injectScript:(NSString*)script forClass:(Class)JSInjectionManagerClass { |
| 2505 DCHECK(script.length); | 2499 DCHECK(script.length); |
| 2506 // Script execution is an asynchronous operation which may pass sensitive | 2500 // Script execution is an asynchronous operation which may pass sensitive |
| 2507 // data to the page. executeJavaScript:completionHandler makes sure that | 2501 // data to the page. executeJavaScript:completionHandler makes sure that |
| 2508 // receiver page did not change by checking its window id. | 2502 // receiver page did not change by checking its window id. |
| 2509 // |[_webView executeJavaScript:completionHandler:]| is not used here because | 2503 // |[_webView executeJavaScript:completionHandler:]| is not used here because |
| 2510 // it does not check that page is the same. | 2504 // it does not check that page is the same. |
| 2511 [self executeJavaScript:script completionHandler:nil]; | 2505 [self executeJavaScript:script completionHandler:nil]; |
| 2512 [_injectedScriptManagers addObject:JSInjectionManagerClass]; | 2506 [_injectedScriptManagers addObject:JSInjectionManagerClass]; |
| 2513 } | 2507 } |
| 2514 | 2508 |
| 2515 #pragma mark - | 2509 #pragma mark - |
| 2516 | 2510 |
| 2517 - (void)executeUserJavaScript:(NSString*)script | 2511 - (void)executeUserJavaScript:(NSString*)script |
| 2518 completionHandler:(web::JavaScriptResultBlock)completion { | 2512 completionHandler:(web::JavaScriptResultBlock)completion { |
| 2519 [self setUserInteractionRegistered:YES]; | 2513 [self setUserInteractionRegistered:YES]; |
| 2520 [self executeJavaScript:script completionHandler:completion]; | 2514 [self executeJavaScript:script completionHandler:completion]; |
| 2521 } | 2515 } |
| 2522 | 2516 |
| 2523 // DEPRECATED. TODO(crbug.com/595761): Remove this API. | |
| 2524 - (void)evaluateUserJavaScript:(NSString*)script { | |
| 2525 [self executeUserJavaScript:script completionHandler:nil]; | |
| 2526 } | |
| 2527 | |
| 2528 - (BOOL)respondToMessage:(base::DictionaryValue*)message | 2517 - (BOOL)respondToMessage:(base::DictionaryValue*)message |
| 2529 userIsInteracting:(BOOL)userIsInteracting | 2518 userIsInteracting:(BOOL)userIsInteracting |
| 2530 originURL:(const GURL&)originURL { | 2519 originURL:(const GURL&)originURL { |
| 2531 std::string command; | 2520 std::string command; |
| 2532 if (!message->GetString("command", &command)) { | 2521 if (!message->GetString("command", &command)) { |
| 2533 DLOG(WARNING) << "JS message parameter not found: command"; | 2522 DLOG(WARNING) << "JS message parameter not found: command"; |
| 2534 return NO; | 2523 return NO; |
| 2535 } | 2524 } |
| 2536 | 2525 |
| 2537 SEL handler = [self selectorToHandleJavaScriptCommand:command]; | 2526 SEL handler = [self selectorToHandleJavaScriptCommand:command]; |
| (...skipping 3101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5639 } | 5628 } |
| 5640 | 5629 |
| 5641 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5630 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
| 5642 } | 5631 } |
| 5643 | 5632 |
| 5644 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5633 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
| 5645 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5634 return [action.request valueForHTTPHeaderField:@"Referer"]; |
| 5646 } | 5635 } |
| 5647 | 5636 |
| 5648 @end | 5637 @end |
| OLD | NEW |