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 |
11 #import "ios/web/public/block_types.h" | 11 #import "ios/web/public/block_types.h" |
12 | 12 |
13 @class WKWebView; | 13 @class WKWebView; |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class Value; | 16 class Value; |
17 } // namespace base | 17 } // namespace base |
18 | 18 |
19 namespace web { | 19 namespace web { |
20 | 20 |
21 // The domain for JS evaluation NSErrors in web. | 21 // The domain for JS evaluation NSErrors in web. |
22 extern NSString* const kJSEvaluationErrorDomain; | 22 extern NSString* const kJSEvaluationErrorDomain; |
23 | 23 |
24 // The maximum recursion depth when parsing JS results. | 24 // The maximum recursion depth when parsing JS results. |
25 extern int const kMaximumParsingRecursionDepth; | 25 extern int const kMaximumParsingRecursionDepth; |
26 | 26 |
27 // The type of errors that can occur while evaluating JS. | 27 // The type of errors that can occur while evaluating JS. |
28 enum JSEvaluationErrorCode { | 28 enum JSEvaluationErrorCode { |
29 // No web view present to evaluate JS. | 29 // No web view present to evaluate JS. |
30 JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW = 1, | 30 JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW = -1000, |
| 31 // JS evaluation is not allowed for security reasons. |
| 32 JS_EVALUATION_ERROR_CODE_REJECTED = -1001, |
31 }; | 33 }; |
32 | 34 |
33 // Converts result of WKWebView script evaluation to base::Value. | 35 // Converts result of WKWebView script evaluation to base::Value. |
34 std::unique_ptr<base::Value> ValueResultFromWKResult(id result); | 36 std::unique_ptr<base::Value> ValueResultFromWKResult(id result); |
35 | 37 |
36 // Executes JavaScript on WKWebView. If the web view cannot execute JS at the | 38 // Executes JavaScript on WKWebView. If the web view cannot execute JS at the |
37 // moment, |completion_handler| is called with an NSError. | 39 // moment, |completion_handler| is called with an NSError. |
38 void ExecuteJavaScript(WKWebView* web_view, | 40 void ExecuteJavaScript(WKWebView* web_view, |
39 NSString* script, | 41 NSString* script, |
40 JavaScriptResultBlock completion_handler); | 42 JavaScriptResultBlock completion_handler); |
41 | 43 |
42 } // namespace web | 44 } // namespace web |
43 | 45 |
44 #endif // IOS_WEB_WEB_STATE_UI_WEB_VIEW_JS_UTILS_H_ | 46 #endif // IOS_WEB_WEB_STATE_UI_WEB_VIEW_JS_UTILS_H_ |
OLD | NEW |