| 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 #ifndef IOS_WEB_WEB_STATE_UI_WEB_VIEW_JS_UTILS_H_ | 5 #ifndef IOS_WEB_WEB_STATE_UI_WEB_VIEW_JS_UTILS_H_ |
| 6 #define IOS_WEB_WEB_STATE_UI_WEB_VIEW_JS_UTILS_H_ | 6 #define IOS_WEB_WEB_STATE_UI_WEB_VIEW_JS_UTILS_H_ |
| 7 | 7 |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 // The type of errors that can occur while evaluating JS. | 24 // The type of errors that can occur while evaluating JS. |
| 25 enum JSEvaluationErrorCode { | 25 enum JSEvaluationErrorCode { |
| 26 // No web view present to evaluate JS. | 26 // No web view present to evaluate JS. |
| 27 JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW = 1, | 27 JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW = 1, |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 // Converts result of WKWebView script evaluation to base::Value. | 30 // Converts result of WKWebView script evaluation to base::Value. |
| 31 std::unique_ptr<base::Value> ValueResultFromWKResult(id result); | 31 std::unique_ptr<base::Value> ValueResultFromWKResult(id result); |
| 32 | 32 |
| 33 // Evaluates JavaScript on WKWebView. Provides evaluation result as a string. | |
| 34 // If the web view cannot evaluate JS at the moment, |completion_handler| is | |
| 35 // called with an NSError. | |
| 36 void EvaluateJavaScript(WKWebView* web_view, | |
| 37 NSString* script, | |
| 38 JavaScriptCompletion completion_handler); | |
| 39 | |
| 40 // Executes JavaScript on WKWebView. If the web view cannot execute JS at the | 33 // Executes JavaScript on WKWebView. If the web view cannot execute JS at the |
| 41 // moment, |completion_handler| is called with an NSError. | 34 // moment, |completion_handler| is called with an NSError. |
| 42 void ExecuteJavaScript(WKWebView* web_view, | 35 void ExecuteJavaScript(WKWebView* web_view, |
| 43 NSString* script, | 36 NSString* script, |
| 44 JavaScriptResultBlock completion_handler); | 37 JavaScriptResultBlock completion_handler); |
| 45 | 38 |
| 46 } // namespace web | 39 } // namespace web |
| 47 | 40 |
| 48 #endif // IOS_WEB_WEB_STATE_UI_WEB_VIEW_JS_UTILS_H_ | 41 #endif // IOS_WEB_WEB_STATE_UI_WEB_VIEW_JS_UTILS_H_ |
| OLD | NEW |