Chromium Code Reviews| Index: ios/web/web_state/ui/crw_web_controller.mm |
| diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm |
| index b886c699a6990c67e09ef077fb9b501db18288f4..dae7d2949cfef34ba71219da9f27fb52dc245ef2 100644 |
| --- a/ios/web/web_state/ui/crw_web_controller.mm |
| +++ b/ios/web/web_state/ui/crw_web_controller.mm |
| @@ -13,6 +13,7 @@ |
| #include <memory> |
| #include <utility> |
| +#include "base/callback.h" |
| #include "base/containers/mru_cache.h" |
| #include "base/ios/block_types.h" |
| #include "base/ios/ios_util.h" |
| @@ -54,6 +55,8 @@ |
| #include "ios/web/public/browser_state.h" |
| #include "ios/web/public/cert_store.h" |
| #include "ios/web/public/favicon_url.h" |
| +#include "ios/web/public/javascript_dialog_presenter.h" |
|
Eugene But (OOO till 7-30)
2016/06/27 21:09:37
s/include/import
michaeldo
2016/06/27 22:25:10
Done.
|
| +#include "ios/web/public/javascript_dialog_type.h" |
| #include "ios/web/public/navigation_item.h" |
| #import "ios/web/public/navigation_manager.h" |
| #import "ios/web/public/origin_util.h" |
| @@ -852,6 +855,14 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); |
| completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, |
| NSURLCredential*))completionHandler; |
| +// Helper to respond to |webView:runJavaScript...| delegate methods. |
| +// |completionHandler| must not be nil. |
| +- (void)runJavaScriptDialogOfType:(web::JavaScriptDialogType)type |
| + initiatedByFrame:(WKFrameInfo*)frame |
| + message:(NSString*)message |
| + defaultText:(NSString*)defaultText |
| + completion:(void (^)(BOOL, NSString*))completionHandler; |
| + |
| // Called when WKWebView estimatedProgress has been changed. |
| - (void)webViewEstimatedProgressDidChange; |
| // Called when WKWebView certificateChain or hasOnlySecureContent property has |
| @@ -3760,6 +3771,23 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| } |
| #pragma mark - |
| +#pragma mark JavaScript Dialog |
| + |
| +- (void)runJavaScriptDialogOfType:(web::JavaScriptDialogType)type |
| + initiatedByFrame:(WKFrameInfo*)frame |
| + message:(NSString*)message |
| + defaultText:(NSString*)defaultText |
| + completion:(void (^)(BOOL, NSString*))completionHandler { |
| + completionHandler = [completionHandler copy]; |
|
Eugene But (OOO till 7-30)
2016/06/27 21:09:37
Why do you need this? |completionHandler| should b
michaeldo
2016/06/27 22:25:10
You are correct, I don't need this copy.
|
| + self.webStateImpl->RunJavaScriptDialog( |
| + net::GURLWithNSURL(frame.request.URL), type, message, defaultText, |
| + base::BindBlock(^(bool success, NSString* input) { |
| + completionHandler(success, input); |
| + [completionHandler release]; |
| + })); |
| +} |
| + |
| +#pragma mark - |
| #pragma mark TouchTracking |
| - (void)touched:(BOOL)touched { |
| @@ -4693,6 +4721,7 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); |
| if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) |
| [self.UIDelegate cancelDialogsForWebController:self]; |
| + _webStateImpl->CancelActiveAndPendingDialogs(); |
| if (allowCache) |
| _expectedReconstructionURL = [self currentNavigationURL]; |
| @@ -4711,6 +4740,7 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); |
| if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) |
| [self.UIDelegate cancelDialogsForWebController:self]; |
| + _webStateImpl->CancelActiveAndPendingDialogs(); |
| SEL rendererCrashSelector = @selector(webControllerWebProcessDidCrash:); |
| if ([self.delegate respondsToSelector:rendererCrashSelector]) |
| @@ -4838,7 +4868,9 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| completionHandler:(void (^)())completionHandler { |
| if (self.shouldSuppressDialogs) { |
| [self didSuppressDialog]; |
| - completionHandler(); |
| + if (completionHandler) { |
|
Eugene But (OOO till 7-30)
2016/06/27 21:09:37
Optional NIT: We never had crashes here, so I beli
michaeldo
2016/06/27 22:25:10
The if check was here, I simply moved it from the
Eugene But (OOO till 7-30)
2016/06/27 22:33:56
Right, so if block is nil then we'll crash. But ac
michaeldo
2016/06/28 17:44:47
Yes, you are right! I'll remove the check.
|
| + completionHandler(); |
| + } |
| return; |
| } |
| @@ -4851,8 +4883,16 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| runJavaScriptAlertPanelWithMessage:message |
| requestURL:net::GURLWithNSURL(frame.request.URL) |
| completionHandler:completionHandler]; |
| - } else if (completionHandler) { |
| - completionHandler(); |
| + } else { |
| + [self runJavaScriptDialogOfType:web::JAVASCRIPT_DIALOG_TYPE_ALERT |
| + initiatedByFrame:frame |
| + message:message |
| + defaultText:nil |
| + completion:^(BOOL, NSString*) { |
| + if (completionHandler) { |
| + completionHandler(); |
| + } |
| + }]; |
| } |
| } |
| @@ -4877,8 +4917,16 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| requestURL:net::GURLWithNSURL( |
| frame.request.URL) |
| completionHandler:completionHandler]; |
| - } else if (completionHandler) { |
| - completionHandler(NO); |
| + } else { |
| + [self runJavaScriptDialogOfType:web::JAVASCRIPT_DIALOG_TYPE_CONFIRM |
| + initiatedByFrame:frame |
| + message:message |
| + defaultText:nil |
| + completion:^(BOOL success, NSString*) { |
| + if (completionHandler) { |
| + completionHandler(success); |
| + } |
| + }]; |
| } |
| } |
| @@ -4915,8 +4963,16 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| defaultText:defaultText |
| requestURL:requestURL |
| completionHandler:completionHandler]; |
| - } else if (completionHandler) { |
| - completionHandler(nil); |
| + } else { |
| + [self runJavaScriptDialogOfType:web::JAVASCRIPT_DIALOG_TYPE_PROMPT |
| + initiatedByFrame:frame |
| + message:prompt |
| + defaultText:defaultText |
| + completion:^(BOOL, NSString* input) { |
| + if (completionHandler) { |
| + completionHandler(input); |
| + } |
| + }]; |
| } |
| } |