| OLD | NEW |
| 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/web_view_js_utils.h" | 5 #import "ios/web/web_state/ui/web_view_js_utils.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 #import <WebKit/WebKit.h> | 8 #import <WebKit/WebKit.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 NOTREACHED(); // Convert other types as needed. | 71 NOTREACHED(); // Convert other types as needed. |
| 72 } | 72 } |
| 73 return result; | 73 return result; |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace | 76 } // namespace |
| 77 | 77 |
| 78 namespace web { | 78 namespace web { |
| 79 | 79 |
| 80 NSString* const kJSEvaluationErrorDomain = @"JSEvaluationError"; | 80 NSString* const kJSEvaluationErrorDomain = @"JSEvaluationError"; |
| 81 int const kMaximumParsingRecursionDepth = 6; | 81 int const kMaximumParsingRecursionDepth = 8; |
| 82 | 82 |
| 83 std::unique_ptr<base::Value> ValueResultFromWKResult(id wk_result) { | 83 std::unique_ptr<base::Value> ValueResultFromWKResult(id wk_result) { |
| 84 return ::ValueResultFromWKResult(wk_result, kMaximumParsingRecursionDepth); | 84 return ::ValueResultFromWKResult(wk_result, kMaximumParsingRecursionDepth); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void ExecuteJavaScript(WKWebView* web_view, | 87 void ExecuteJavaScript(WKWebView* web_view, |
| 88 NSString* script, | 88 NSString* script, |
| 89 JavaScriptResultBlock completion_handler) { | 89 JavaScriptResultBlock completion_handler) { |
| 90 DCHECK([script length]); | 90 DCHECK([script length]); |
| 91 if (!web_view && completion_handler) { | 91 if (!web_view && completion_handler) { |
| 92 dispatch_async(dispatch_get_main_queue(), ^{ | 92 dispatch_async(dispatch_get_main_queue(), ^{ |
| 93 NSString* error_message = | 93 NSString* error_message = |
| 94 @"JS evaluation failed because there is no web view."; | 94 @"JS evaluation failed because there is no web view."; |
| 95 base::scoped_nsobject<NSError> error([[NSError alloc] | 95 base::scoped_nsobject<NSError> error([[NSError alloc] |
| 96 initWithDomain:kJSEvaluationErrorDomain | 96 initWithDomain:kJSEvaluationErrorDomain |
| 97 code:JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW | 97 code:JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW |
| 98 userInfo:@{NSLocalizedDescriptionKey : error_message}]); | 98 userInfo:@{NSLocalizedDescriptionKey : error_message}]); |
| 99 completion_handler(nil, error); | 99 completion_handler(nil, error); |
| 100 }); | 100 }); |
| 101 return; | 101 return; |
| 102 } | 102 } |
| 103 | 103 |
| 104 [web_view evaluateJavaScript:script completionHandler:completion_handler]; | 104 [web_view evaluateJavaScript:script completionHandler:completion_handler]; |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace web | 107 } // namespace web |
| OLD | NEW |