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 a2e98946d4c4a6856aeb3dfe987b11ee09b7374a..d01e1d893158f8573ba4cc0561a793227fcd9dfe 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" |
| @@ -852,6 +853,13 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); |
| completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, |
| NSURLCredential*))completionHandler; |
| +// Helper to respond to |webView:runJavaScript...| delegate methods. |
|
Eugene But (OOO till 7-30)
2016/06/24 17:04:52
Please document whether or not |completionHandler|
michaeldo
2016/06/27 20:30:10
you're right, made it non-nil.
|
| +- (void)runJavaScriptDialogOfType:(web::JavaScriptMessageType)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 |
| @@ -3717,30 +3725,44 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| runAuthDialogForProtectionSpace: |
| proposedCredential: |
| completionHandler:); |
| - if (![self.UIDelegate respondsToSelector:selector]) { |
| - // Embedder does not support HTTP Authentication. |
| - completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); |
| - return; |
| + if ([self.UIDelegate respondsToSelector:selector]) { |
| + [self.UIDelegate webController:self |
| + runAuthDialogForProtectionSpace:space |
| + proposedCredential:challenge.proposedCredential |
| + completionHandler:^(NSString* user, NSString* password) { |
| + [CRWWebController |
| + processHTTPAuthForUser:user |
| + password:password |
| + completionHandler:completionHandler]; |
| + }]; |
| + } else { |
| + void (^callback)(NSURLSessionAuthChallengeDisposition, NSURLCredential*) = |
| + nil; |
| + if (completionHandler) { |
| + callback = [completionHandler copy]; |
| + } |
| + self.webStateImpl->RunAuthDialog( |
| + space, challenge.proposedCredential, |
| + base::BindBlock(^(const net::AuthCredentials& credentials) { |
| + if (callback) { |
| + [CRWWebController processHTTPAuthForUser:base::SysUTF16ToNSString( |
| + credentials.username()) |
| + password:base::SysUTF16ToNSString( |
| + credentials.password()) |
| + completionHandler:callback]; |
| + [callback release]; |
| + } |
| + })); |
| } |
| - |
| - [self.UIDelegate webController:self |
| - runAuthDialogForProtectionSpace:space |
| - proposedCredential:challenge.proposedCredential |
| - completionHandler:^(NSString* user, NSString* password) { |
| - [CRWWebController |
| - processHTTPAuthForUser:user |
| - password:password |
| - completionHandler:completionHandler]; |
| - }]; |
| } |
| + (void)processHTTPAuthForUser:(NSString*)user |
| password:(NSString*)password |
| completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, |
| NSURLCredential*))completionHandler { |
| - DCHECK_EQ(user == nil, password == nil); |
| if (!user || !password) { |
| - // Embedder cancelled authentication. |
| + // Embedder cancelled authentication or embedder does not support HTTP |
| + // Authentication. |
| completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); |
| return; |
| } |
| @@ -3753,6 +3775,28 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| } |
| #pragma mark - |
| +#pragma mark JavaScript Dialog |
| + |
| +- (void)runJavaScriptDialogOfType:(web::JavaScriptMessageType)type |
| + initiatedByFrame:(WKFrameInfo*)frame |
| + message:(NSString*)message |
| + defaultText:(NSString*)defaultText |
| + completion:(void (^)(BOOL, NSString*))completionHandler { |
|
Eugene But (OOO till 7-30)
2016/06/24 17:04:52
I think if you always pass |completionHandler| the
michaeldo
2016/06/27 20:30:10
Agreed, made the completion handler required per y
|
| + void (^callback)(BOOL, NSString*) = nil; |
| + if (completionHandler) { |
| + callback = [completionHandler copy]; |
|
Eugene But (OOO till 7-30)
2016/06/24 17:04:52
Why do you need a separate |callback| variable? Ca
michaeldo
2016/06/27 20:30:10
Done.
|
| + } |
| + self.webStateImpl->RunJavaScriptDialog( |
| + net::GURLWithNSURL(frame.request.URL), type, message, defaultText, |
| + base::BindBlock(^(bool success, NSString* input) { |
| + if (callback) { |
| + callback(success, input); |
| + [callback release]; |
| + } |
| + })); |
| +} |
| + |
| +#pragma mark - |
| #pragma mark TouchTracking |
| - (void)touched:(BOOL)touched { |
| @@ -4686,6 +4730,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]; |
| @@ -4704,6 +4749,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]) |
| @@ -4831,7 +4877,9 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| completionHandler:(void (^)())completionHandler { |
| if (self.shouldSuppressDialogs) { |
| [self didSuppressDialog]; |
| - completionHandler(); |
| + if (completionHandler) { |
| + completionHandler(); |
| + } |
| return; |
| } |
| @@ -4844,8 +4892,18 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| runJavaScriptAlertPanelWithMessage:message |
| requestURL:net::GURLWithNSURL(frame.request.URL) |
| completionHandler:completionHandler]; |
| - } else if (completionHandler) { |
| - completionHandler(); |
| + } else { |
| + void (^completion)(BOOL, NSString*) = nil; |
| + if (completionHandler) { |
| + completion = ^(BOOL, NSString*) { |
| + completionHandler(); |
| + }; |
| + } |
| + [self runJavaScriptDialogOfType:web::JAVASCRIPT_MESSAGE_TYPE_ALERT |
| + initiatedByFrame:frame |
| + message:message |
| + defaultText:nil |
| + completion:completion]; |
| } |
| } |
| @@ -4870,8 +4928,18 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| requestURL:net::GURLWithNSURL( |
| frame.request.URL) |
| completionHandler:completionHandler]; |
| - } else if (completionHandler) { |
| - completionHandler(NO); |
| + } else { |
| + void (^completion)(BOOL, NSString*) = nil; |
| + if (completionHandler) { |
| + completion = ^(BOOL success, NSString*) { |
| + completionHandler(success); |
| + }; |
| + } |
| + [self runJavaScriptDialogOfType:web::JAVASCRIPT_MESSAGE_TYPE_CONFIRM |
| + initiatedByFrame:frame |
| + message:message |
| + defaultText:nil |
| + completion:completion]; |
| } |
| } |
| @@ -4908,8 +4976,18 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| defaultText:defaultText |
| requestURL:requestURL |
| completionHandler:completionHandler]; |
| - } else if (completionHandler) { |
| - completionHandler(nil); |
| + } else { |
| + void (^completion)(BOOL, NSString*) = nil; |
| + if (completionHandler) { |
| + completion = ^(BOOL, NSString* input) { |
| + completionHandler(input); |
| + }; |
| + } |
| + [self runJavaScriptDialogOfType:web::JAVASCRIPT_MESSAGE_TYPE_PROMPT |
| + initiatedByFrame:frame |
| + message:prompt |
| + defaultText:defaultText |
| + completion:completion]; |
| } |
| } |