Commit 281c2845 authored by eugenebut's avatar eugenebut Committed by Commit bot

[ios] Removed UIWebView JS evaluation code.

BUG=579697

Review URL: https://codereview.chromium.org/1808993002

Cr-Commit-Position: refs/heads/master@{#381743}
parent f851b2c9
...@@ -21,6 +21,7 @@ typedef void (^JavaScriptCompletion)(NSString*, NSError*); ...@@ -21,6 +21,7 @@ typedef void (^JavaScriptCompletion)(NSString*, NSError*);
// with results of the evaluation (which may be nil if the implementing object // with results of the evaluation (which may be nil if the implementing object
// has no way to run the evaluation or the evaluation returns a nil value) // has no way to run the evaluation or the evaluation returns a nil value)
// or an NSError if there is an error. The |completionHandler| can be nil. // or an NSError if there is an error. The |completionHandler| can be nil.
// TODO(crbug.com/595761): Change this API to return |id| instead of string.
- (void)evaluateJavaScript:(NSString*)script - (void)evaluateJavaScript:(NSString*)script
stringResultHandler:(web::JavaScriptCompletion)handler; stringResultHandler:(web::JavaScriptCompletion)handler;
......
...@@ -9,13 +9,8 @@ ...@@ -9,13 +9,8 @@
#include "ios/web/public/block_types.h" #include "ios/web/public/block_types.h"
@class UIWebView;
@class WKWebView; @class WKWebView;
// This file contains functions that asynchronously evaluate JavaScript on
// WKWebView/UIWebView and provide result in the same format. Call
// |completion_handler| with results of the evaluation or an NSError if there is
// an error. The |completion_handler| can be nil.
namespace web { namespace web {
// The domain for JS evaluation NSErrors in web. // The domain for JS evaluation NSErrors in web.
...@@ -27,18 +22,9 @@ enum JSEvaluationErrorCode { ...@@ -27,18 +22,9 @@ enum JSEvaluationErrorCode {
JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW = 1, JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW = 1,
}; };
// The error code for JS evaluation NSErrors. // Evaluates JavaScript on WKWebView. Provides evaluation result as a string.
extern const NSInteger kJSEvaluationErrorCode; // If the web view cannot evaluate JS at the moment, |completion_handler| is
// called with an NSError.
// Asynchronous adaptor to evaluate JavaScript on UIWebView. Provides evaluation
// result as it is, without modifications.
void EvaluateJavaScript(UIWebView* web_view,
NSString* script,
JavaScriptCompletion completion_handler);
// Evaluates JavaScript on WKWebView. Provides evaluation result in the same
// format as UIWebView. If the web view cannot evaluate JS at the moment,
// |completion_handler| is called with an NSError.
void EvaluateJavaScript(WKWebView* web_view, void EvaluateJavaScript(WKWebView* web_view,
NSString* script, NSString* script,
JavaScriptCompletion completion_handler); JavaScriptCompletion completion_handler);
......
...@@ -4,17 +4,16 @@ ...@@ -4,17 +4,16 @@
#import "ios/web/web_state/ui/web_view_js_utils.h" #import "ios/web/web_state/ui/web_view_js_utils.h"
#import <UIKit/UIKit.h> #include <CoreFoundation/CoreFoundation.h>
#import <WebKit/WebKit.h> #import <WebKit/WebKit.h>
#include "base/ios/weak_nsobject.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
namespace { namespace {
// Converts result of WKWebView script evaluation to UIWebView format. // Converts result of WKWebView script evaluation to a string.
NSString* UIResultFromWKResult(id result) { NSString* StringResultFromWKResult(id result) {
if (!result) if (!result)
return @""; return @"";
...@@ -42,18 +41,6 @@ namespace web { ...@@ -42,18 +41,6 @@ namespace web {
NSString* const kJSEvaluationErrorDomain = @"JSEvaluationError"; NSString* const kJSEvaluationErrorDomain = @"JSEvaluationError";
void EvaluateJavaScript(UIWebView* web_view,
NSString* script,
JavaScriptCompletion completion_handler) {
base::WeakNSObject<UIWebView> weak_web_view(web_view);
dispatch_async(dispatch_get_main_queue(), ^{
NSString* result =
[weak_web_view stringByEvaluatingJavaScriptFromString:script];
if (completion_handler)
completion_handler(result, nil);
});
}
void EvaluateJavaScript(WKWebView* web_view, void EvaluateJavaScript(WKWebView* web_view,
NSString* script, NSString* script,
JavaScriptCompletion completion_handler) { JavaScriptCompletion completion_handler) {
...@@ -79,7 +66,7 @@ void EvaluateJavaScript(WKWebView* web_view, ...@@ -79,7 +66,7 @@ void EvaluateJavaScript(WKWebView* web_view,
// need to call those completion handlers. // need to call those completion handlers.
if (completion_handler) { if (completion_handler) {
web_view_completion_handler = ^(id result, NSError* error) { web_view_completion_handler = ^(id result, NSError* error) {
completion_handler(UIResultFromWKResult(result), error); completion_handler(StringResultFromWKResult(result), error);
}; };
} }
[web_view evaluateJavaScript:script [web_view evaluateJavaScript:script
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment