Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Auth from UIWebView to WKWebView #3549

Merged
merged 2 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Firebase/Auth/Source/Public/FIRAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,10 @@ DEPRECATED_MSG_ATTRIBUTE("Please use fetchSignInMethodsForEmail:completion: for
<li>@c FIRAuthErrorCodeUserDisabled - Indicates the user's account is disabled.
</li>
<li>@c FIRAuthErrorCodeWebNetworkRequestFailed - Indicates that a network request within a
SFSafariViewController or UIWebview failed.
SFSafariViewController or WKWebView failed.
</li>
<li>@c FIRAuthErrorCodeWebInternalError - Indicates that an internal error occurred within a
SFSafariViewController or UIWebview.
SFSafariViewController or WKWebView.
</li>
<li>@c FIRAuthErrorCodeWebSignInUserInteractionFailure - Indicates a general failure during
a web sign-in flow.
Expand Down
4 changes: 2 additions & 2 deletions Firebase/Auth/Source/Public/FIRAuthErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ typedef NS_ENUM(NSInteger, FIRAuthErrorCode) {
*/
FIRAuthErrorCodeInvalidClientID = 17060,

/** Indicates that a network request within a SFSafariViewController or UIWebview failed.
/** Indicates that a network request within a SFSafariViewController or WKWebView failed.
*/
FIRAuthErrorCodeWebNetworkRequestFailed = 17061,

/** Indicates that an internal error occurred within a SFSafariViewController or UIWebview.
/** Indicates that an internal error occurred within a SFSafariViewController or WKWebView.
*/
FIRAuthErrorCodeWebInternalError = 17062,

Expand Down
6 changes: 3 additions & 3 deletions Firebase/Auth/Source/Utilities/FIRAuthErrorUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@

/** @var kURLResponseErrorCodeNetworkRequestFailed
@brief Error code that indicates that a network request within the SFSafariViewController or
UIWebView failed.
WKWebView failed.
*/
static NSString *const kURLResponseErrorCodeNetworkRequestFailed = @"auth/network-request-failed";

/** @var kURLResponseErrorCodeInternalError
@brief Error code that indicates that an internal error occurred within the
SFSafariViewController or UIWebView failed.
SFSafariViewController or WKWebView failed.
*/
static NSString *const kURLResponseErrorCodeInternalError = @"auth/internal-error";

Expand Down Expand Up @@ -412,7 +412,7 @@
@brief Message for @c FIRAuthErrorCodeWebInternalError error code.
*/
static NSString *const kFIRAuthErrorMessageWebInternalError = @"An internal error has occurred "
"within the SFSafariViewController or UIWebView.";
"within the SFSafariViewController or WKWebView.";

/** @var kFIRAuthErrorMessageAppVerificationUserInteractionFailure
@brief Message for @c FIRAuthErrorCodeInvalidClientID error code.
Expand Down
6 changes: 3 additions & 3 deletions Firebase/Auth/Source/Utilities/FIRAuthInternalErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,17 @@ typedef NS_ENUM(NSInteger, FIRAuthInternalErrorCode) {
FIRAuthInternalErrorCodeInvalidClientID =
FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidClientID,

/** Indicates that a network request within a SFSafariViewController or UIWebview failed.
/** Indicates that a network request within a SFSafariViewController or WKWebView failed.
*/
FIRAuthInternalErrorCodeWebNetworkRequestFailed =
FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeWebNetworkRequestFailed,

/** Indicates that an internal error occurred within a SFSafariViewController or UIWebview.
/** Indicates that an internal error occurred within a SFSafariViewController or WKWebView.
*/
FIRAuthInternalErrorCodeWebInternalError =
FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeWebInternalError,

/** Indicates that an internal error occurred within a SFSafariViewController or UIWebview.
/** Indicates that an internal error occurred within a SFSafariViewController or WKWebView.
*/
FIRAuthInternalErrorCodeWebSignInUserInteractionFailure =
FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeWebSignInUserInteractionFailure,
Expand Down
2 changes: 1 addition & 1 deletion Firebase/Auth/Source/Utilities/FIRAuthURLPresenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef void (^FIRAuthURLPresentationCompletion)(NSURL *_Nullable callbackURL,
typedef BOOL (^FIRAuthURLCallbackMatcher)(NSURL * _Nullable callbackURL);

/** @class FIRAuthURLPresenter
@brief A Class responsible for presenting URL via SFSafariViewController or UIWebView.
@brief A Class responsible for presenting URL via SFSafariViewController or WKWebView.
*/
@interface FIRAuthURLPresenter : NSObject

Expand Down
5 changes: 3 additions & 2 deletions Firebase/Auth/Source/Utilities/FIRAuthWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
*/

#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>

NS_ASSUME_NONNULL_BEGIN

/** @class FIRAuthWebView
@brief A class reponsible for creating a UIWebview for use within Firebase Auth.
@brief A class reponsible for creating a WKWebView for use within Firebase Auth.
*/
@interface FIRAuthWebView : UIView

/** @property webView
* @brief The web view.
*/
@property(nonatomic, weak) UIWebView *webView;
@property(nonatomic, weak) WKWebView *webView;

/** @property spinner
* @brief The spinner that indicates web view loading.
Expand Down
17 changes: 13 additions & 4 deletions Firebase/Auth/Source/Utilities/FIRAuthWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
@brief Initializes the subviews of this view.
*/
- (void)initializeSubviews {
UIWebView *webView = [self createWebView];
WKWebView *webView = [self createWebView];
UIActivityIndicatorView *spinner = [self createSpinner];

// The order of the following controls z-order.
Expand All @@ -56,8 +56,8 @@ - (void)layoutSubviews {
@brief Creates a web view to be used by this view.
@return The newly created web view.
*/
- (UIWebView *)createWebView {
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
- (WKWebView *)createWebView {
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero];
// Trickery to make the web view not do weird things (like showing a black background when
// the prompt in the navigation bar animates changes.)
webView.opaque = NO;
Expand All @@ -75,7 +75,16 @@ - (UIWebView *)createWebView {
@return The newly created spinner.
*/
- (UIActivityIndicatorView *)createSpinner {
UIActivityIndicatorViewStyle spinnerStyle = UIActivityIndicatorViewStyleGray;
UIActivityIndicatorViewStyle spinnerStyle;
#if defined(TARGET_OS_MACCATALYST)
if (@available(iOS 13.0, *)) {
spinnerStyle = UIActivityIndicatorViewStyleMedium;
} else {
spinnerStyle = UIActivityIndicatorViewStyleGray;
}
#else
spinnerStyle = UIActivityIndicatorViewStyleGray;
#endif
UIActivityIndicatorView *spinner =
[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:spinnerStyle];
return spinner;
Expand Down
29 changes: 16 additions & 13 deletions Firebase/Auth/Source/Utilities/FIRAuthWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface FIRAuthWebViewController () <UIWebViewDelegate>
@interface FIRAuthWebViewController () <WKNavigationDelegate>
@end

@implementation FIRAuthWebViewController {
Expand Down Expand Up @@ -54,7 +54,7 @@ - (instancetype)initWithURL:(NSURL *)URL

- (void)loadView {
FIRAuthWebView *webView = [[FIRAuthWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
webView.webView.delegate = self;
webView.webView.navigationDelegate = self;
self.view = webView;
_webView = webView;
self.navigationItem.leftBarButtonItem =
Expand All @@ -76,33 +76,36 @@ - (void)cancel {
[_delegate webViewControllerDidCancel:self];
}

#pragma mark - UIWebViewDelegate
#pragma mark - WKNavigationDelegate

- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
return ![_delegate webViewController:self canHandleURL:request.URL];
- (void)webView:(WKWebView *)webView
decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
[_delegate webViewController:self canHandleURL:navigationAction.request.URL];
decisionHandler(WKNavigationActionPolicyAllow);
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
// Show & animate the activity indicator.
- (void)webView:(WKWebView *)webView
didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation {
_webView.spinner.hidden = NO;
[_webView.spinner startAnimating];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Hide & stop the activity indicator.
- (void)webView:(WKWebView *)webView
didFinishNavigation:(null_unspecified WKNavigation *)navigation {
_webView.spinner.hidden = YES;
[_webView.spinner stopAnimating];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
- (void)webView:(WKWebView *)webView
didFailNavigation:(null_unspecified WKNavigation *)navigation
withError:(NSError *)error {
if ([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled) {
// It's okay for the page to be redirected before it is completely loaded. See b/32028062 .
return;
}
// Forward notification to our delegate.
[self webViewDidFinishLoad:webView];
[self webView:webView didFinishNavigation:navigation];
[_delegate webViewController:self didFailWithError:error];
}

Expand Down