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*);
// 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)
// 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
stringResultHandler:(web::JavaScriptCompletion)handler;
......
......@@ -9,13 +9,8 @@
#include "ios/web/public/block_types.h"
@class UIWebView;
@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 {
// The domain for JS evaluation NSErrors in web.
......@@ -27,18 +22,9 @@ enum JSEvaluationErrorCode {
JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW = 1,
};
// The error code for JS evaluation NSErrors.
extern const NSInteger kJSEvaluationErrorCode;
// 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.
// Evaluates JavaScript on WKWebView. Provides evaluation result as a string.
// If the web view cannot evaluate JS at the moment, |completion_handler| is
// called with an NSError.
void EvaluateJavaScript(WKWebView* web_view,
NSString* script,
JavaScriptCompletion completion_handler);
......
......@@ -4,17 +4,16 @@
#import "ios/web/web_state/ui/web_view_js_utils.h"
#import <UIKit/UIKit.h>
#include <CoreFoundation/CoreFoundation.h>
#import <WebKit/WebKit.h>
#include "base/ios/weak_nsobject.h"
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
namespace {
// Converts result of WKWebView script evaluation to UIWebView format.
NSString* UIResultFromWKResult(id result) {
// Converts result of WKWebView script evaluation to a string.
NSString* StringResultFromWKResult(id result) {
if (!result)
return @"";
......@@ -42,18 +41,6 @@ namespace web {
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,
NSString* script,
JavaScriptCompletion completion_handler) {
......@@ -79,7 +66,7 @@ void EvaluateJavaScript(WKWebView* web_view,
// need to call those completion handlers.
if (completion_handler) {
web_view_completion_handler = ^(id result, NSError* error) {
completion_handler(UIResultFromWKResult(result), error);
completion_handler(StringResultFromWKResult(result), error);
};
}
[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