Skip to content

Commit

Permalink
Remove ios/web/public/block_types.h
Browse files Browse the repository at this point in the history
This header has a single typedef of a block which is
mostly used in deprecated files. Typedef itself does not
make code more readable, because the type name does not
convey any information about block return type and arguments.

Per Style Guide the code should be optimized for reader, not
for writer: http://go/objc-style#optimize-for-the-reader-not-the-writer

Bug: 942244
Change-Id: I9fcd09a2a990e32450f98ec55455508bf919a72b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1527208
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Auto-Submit: Eugene But <eugenebut@chromium.org>
Reviewed-by: Mike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#642071}
  • Loading branch information
Eugene But authored and Commit Bot committed Mar 19, 2019
1 parent 1f97a46 commit 8f18c40
Show file tree
Hide file tree
Showing 22 changed files with 28 additions and 55 deletions.
2 changes: 1 addition & 1 deletion ios/chrome/browser/ui/browser_view_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4186,7 +4186,7 @@ - (void)viewSource {
NSString* script = @"document.documentElement.outerHTML;";
__weak Tab* weakTab = tab;
__weak BrowserViewController* weakSelf = self;
web::JavaScriptResultBlock completionHandlerBlock = ^(id result, NSError*) {
auto completionHandlerBlock = ^(id result, NSError*) {
Tab* strongTab = weakTab;
if (!strongTab)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ - (BOOL)isViewAlive {
}

- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)handler {
completionHandler:(void (^)(id, NSError*))handler {
[_staticHTMLViewController executeJavaScript:script
completionHandler:handler];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>

#import "ios/web/public/block_types.h"
#include "url/gurl.h"

@protocol CRWNativeContentDelegate;
Expand Down Expand Up @@ -82,7 +81,7 @@ typedef void (^HtmlCallback)(NSString*);
// moment, |completionHandler| is called with an NSError. The
// |completionHandler| can be nil.
- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completionHandler;
completionHandler:(void (^)(id, NSError*))completionHandler;

// The web page title. Will return nil if not available.
- (NSString*)title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ - (void)dealloc {
}

- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)handler {
completionHandler:(void (^)(id, NSError*))handler {
[webView_ evaluateJavaScript:script completionHandler:handler];
}

Expand Down
1 change: 0 additions & 1 deletion ios/chrome/test/earl_grey/chrome_matchers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/web/public/block_types.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/test/ios/ui_image_test_utils.h"
Expand Down
11 changes: 6 additions & 5 deletions ios/web/interstitials/web_interstitial_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class WebStateImpl;
// has access to private ExecuteJavaScript method to be used for testing.
void ExecuteScriptForTesting(WebInterstitialImpl*,
NSString*,
JavaScriptResultBlock);
void (^)(id, NSError*));

// An abstract subclass of WebInterstitial that exposes the views necessary to
// embed the interstitial into a WebState.
Expand Down Expand Up @@ -63,7 +63,7 @@ class WebInterstitialImpl : public WebInterstitial, public WebStateObserver {
// Calls |completionHandler| with results of the evaluation.
// The |completionHandler| can be nil. Must be used only for testing.
virtual void ExecuteJavaScript(NSString* script,
JavaScriptResultBlock completion_handler);
void (^completion_handler)(id, NSError*));

private:
// The WebState this instance is observing. Will be null after
Expand Down Expand Up @@ -91,9 +91,10 @@ class WebInterstitialImpl : public WebInterstitial, public WebStateObserver {
CRWContentView* content_view_;

// Must be implemented only for testing purposes.
friend void web::ExecuteScriptForTesting(WebInterstitialImpl*,
NSString*,
JavaScriptResultBlock);
friend void web::ExecuteScriptForTesting(
WebInterstitialImpl*,
NSString*,
void (^completion_handler)(id, NSError*));
};

} // namespace web
Expand Down
2 changes: 1 addition & 1 deletion ios/web/interstitials/web_interstitial_impl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ - (void)webView:(WKWebView*)webView

void WebInterstitialImpl::ExecuteJavaScript(
NSString* script,
JavaScriptResultBlock completion_handler) {
void (^completion_handler)(id, NSError*)) {
web::ExecuteJavaScript(web_view_, script, completion_handler);
}

Expand Down
1 change: 0 additions & 1 deletion ios/web/public/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ source_set("public") {
]

sources = [
"block_types.h",
"browser_state.h",
"browser_url_rewriter.h",
"browsing_data_removing_util.h",
Expand Down
21 changes: 0 additions & 21 deletions ios/web/public/block_types.h

This file was deleted.

2 changes: 1 addition & 1 deletion ios/web/public/test/earl_grey/js_test_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Evaluates the given |script| on |interstitial|.
void ExecuteScriptForTesting(web::WebInterstitialImpl* interstitial,
NSString* script,
web::JavaScriptResultBlock handler) {
void (^handler)(id result, NSError*)) {
DCHECK(interstitial);
interstitial->ExecuteJavaScript(script, handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ - (instancetype)init {
}

- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completionHandler {
completionHandler:(void (^)(id, NSError*))completionHandler {
web::ExecuteJavaScript(_webView, script, completionHandler);
}

Expand Down
4 changes: 1 addition & 3 deletions ios/web/public/web_state/js/crw_js_injection_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@

#import <Foundation/Foundation.h>

#import "ios/web/public/block_types.h"

@protocol CRWJSInjectionEvaluator

// Executes the supplied JavaScript in the WebView. Calls |completionHandler|
// with results of the execution (which may be nil if the implementing object
// has no way to run the execution or the execution returns a nil value)
// or an NSError if there is an error. The |completionHandler| can be nil.
- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completionHandler;
completionHandler:(void (^)(id, NSError*))completionHandler;

// Checks to see if the script for a class has been injected into the
// current page already.
Expand Down
2 changes: 1 addition & 1 deletion ios/web/public/web_state/js/crw_js_injection_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// with results of the execution (which may be nil) or an NSError if there is an
// error. The |completionHandler| can be nil.
- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completionHandler;
completionHandler:(void (^)(id, NSError*))completionHandler;

@end

Expand Down
3 changes: 1 addition & 2 deletions ios/web/public/web_state/ui/crw_native_content.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#import <UIKit/UIKit.h>

#import "ios/web/public/block_types.h"
#include "url/gurl.h"

namespace web {
Expand Down Expand Up @@ -54,7 +53,7 @@ struct ContextMenuParams;
// of the evaluation. If the native view cannot evaluate JS at the moment,
// |handler| is called with an NSError.
- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)handler;
completionHandler:(void (^)(id, NSError*))handler;

// Dismisses any outstanding modal interaction elements (e.g. modal view
// controllers, context menus, etc).
Expand Down
2 changes: 1 addition & 1 deletion ios/web/web_state/js/crw_js_injection_manager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ - (void)lowMemoryWarning:(NSNotification*)notify {
}

- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completionHandler {
completionHandler:(void (^)(id, NSError*))completionHandler {
[_receiver executeJavaScript:script completionHandler:completionHandler];
}

Expand Down
2 changes: 1 addition & 1 deletion ios/web/web_state/js/crw_js_injection_receiver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (id)initWithEvaluator:(id<CRWJSInjectionEvaluator>)evaluator {
#pragma mark CRWJSInjectionEvaluatorMethods

- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completionHandler {
completionHandler:(void (^)(id, NSError*))completionHandler {
[_evaluator executeJavaScript:script completionHandler:completionHandler];
}

Expand Down
2 changes: 0 additions & 2 deletions ios/web/web_state/ui/crw_context_menu_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>

#import "ios/web/public/block_types.h"

namespace web {
class BrowserState;
} // namespace web
Expand Down
4 changes: 2 additions & 2 deletions ios/web/web_state/ui/crw_context_menu_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ - (void)cancelContextMenuDisplay;
// Forwards the execution of |script| to |javaScriptDelegate| and if it is nil,
// to |webView|.
- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completionHandler;
completionHandler:(void (^)(id, NSError*))completionHandler;
@end

@implementation CRWContextMenuController {
Expand Down Expand Up @@ -258,7 +258,7 @@ - (CGPoint)scrollPosition {
}

- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completionHandler {
completionHandler:(void (^)(id, NSError*))completionHandler {
if (self.injectionEvaluator) {
[self.injectionEvaluator executeJavaScript:script
completionHandler:completionHandler];
Expand Down
5 changes: 4 additions & 1 deletion ios/web/web_state/ui/crw_web_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ class WebStateImpl;
- (void)stopLoading;

// Executes |script| in the web view, registering user interaction.
// |result| will be backed up by different classes depending on resulting JS
// type: NSString (string), NSNumber (number or boolean), NSDictionary (object),
// NSArray (array), NSNull (null), NSDate (Date), nil (undefined).
- (void)executeUserJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completion;
completionHandler:(void (^)(id result, NSError*))completion;

// Requires that the next load rebuild the web view. This is expensive, and
// should be used only in the case where something has changed that the web view
Expand Down
4 changes: 2 additions & 2 deletions ios/web/web_state/ui/crw_web_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ - (void)loadHTML:(NSString*)HTML forURL:(const GURL&)URL {
}

- (void)executeUserJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completion {
completionHandler:(void (^)(id, NSError*))completion {
// For security reasons, executing JavaScript on pages with app-specific URLs
// is not allowed, because those pages may have elevated privileges.
GURL lastCommittedURL = self.webState->GetLastCommittedURL();
Expand Down Expand Up @@ -1580,7 +1580,7 @@ - (void)takeSnapshotWithRect:(CGRect)rect
#pragma mark - CRWJSInjectionEvaluator (Public)

- (void)executeJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completionHandler {
completionHandler:(void (^)(id, NSError*))completionHandler {
NSString* safeScript = [self scriptByAddingWindowIDCheckForScript:script];
web::ExecuteJavaScript(self.webView, safeScript, completionHandler);
}
Expand Down
4 changes: 1 addition & 3 deletions ios/web/web_state/ui/web_view_js_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#import <Foundation/Foundation.h>
#include <memory>

#import "ios/web/public/block_types.h"

@class WKWebView;

namespace base {
Expand Down Expand Up @@ -39,7 +37,7 @@ std::unique_ptr<base::Value> ValueResultFromWKResult(id result);
// moment, |completion_handler| is called with an NSError.
void ExecuteJavaScript(WKWebView* web_view,
NSString* script,
JavaScriptResultBlock completion_handler);
void (^completion_handler)(id, NSError*));

} // namespace web

Expand Down
2 changes: 1 addition & 1 deletion ios/web/web_state/ui/web_view_js_utils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

void ExecuteJavaScript(WKWebView* web_view,
NSString* script,
JavaScriptResultBlock completion_handler) {
void (^completion_handler)(id, NSError*)) {
DCHECK([script length]);
if (!web_view && completion_handler) {
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down

0 comments on commit 8f18c40

Please sign in to comment.