-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash on iOS due to navigation proxy returning nullptr.
Fixes crash on iOS in Cr117 by overriding the NavigationProxy to use our own proxy instead of the Chromium one, when a webView is not available (such is the case when syncing history or fetching favicons).
- Loading branch information
Showing
3 changed files
with
110 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_IOS_WEB_WEB_STATE_UI_CRW_WEB_CONTROLLER_H_ | ||
#define BRAVE_CHROMIUM_SRC_IOS_WEB_WEB_STATE_UI_CRW_WEB_CONTROLLER_H_ | ||
|
||
#define webViewNavigationProxy \ | ||
webViewNavigationProxy_ChromiumImpl; \ | ||
@property(weak, nonatomic, readonly) id<CRWWebViewNavigationProxy> \ | ||
webViewNavigationProxy | ||
|
||
#include "src/ios/web/web_state/ui/crw_web_controller.h" // IWYU pragma: export | ||
|
||
#undef webViewNavigationProxy | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_IOS_WEB_WEB_STATE_UI_CRW_WEB_CONTROLLER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "ios/web/web_state/ui/crw_web_controller.h" | ||
#include "net/base/mac/url_conversions.h" | ||
#include "url/gurl.h" | ||
|
||
#include <Webkit/Webkit.h> | ||
|
||
#define webViewNavigationProxy webViewNavigationProxy_ChromiumImpl | ||
#include "src/ios/web/web_state/ui/crw_web_controller.mm" | ||
#undef webViewNavigationProxy | ||
|
||
#pragma mark - BackForwardList | ||
|
||
// Back Forward List for use in Navigation Manager | ||
@interface BackForwardList : NSObject | ||
@property(nonatomic, readonly, copy) WKBackForwardListItem* currentItem; | ||
@property(nonatomic, readonly, copy) NSArray<WKBackForwardListItem*>* backList; | ||
@property(nonatomic, readonly, copy) | ||
NSArray<WKBackForwardListItem*>* forwardList; | ||
@end | ||
|
||
@implementation BackForwardList | ||
@synthesize currentItem; | ||
@synthesize backList; | ||
@synthesize forwardList; | ||
|
||
- (instancetype)init { | ||
self = [super init]; | ||
return self; | ||
} | ||
|
||
- (WKBackForwardListItem*)itemAtIndex:(NSInteger)index { | ||
if (index == 0) { | ||
return currentItem; | ||
} | ||
|
||
if (index > 0 && forwardList.count) { | ||
return forwardList[index - 1]; | ||
} | ||
|
||
if (backList.count) { | ||
return backList[backList.count + index]; | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
- (WKBackForwardListItem*)backItem { | ||
return backList.lastObject; | ||
} | ||
|
||
- (WKBackForwardListItem*)forwardItem { | ||
return forwardList.firstObject; | ||
} | ||
@end | ||
|
||
#pragma mark - NavigationProxy | ||
|
||
@interface NavigationProxy : NSObject <CRWWebViewNavigationProxy> | ||
@end | ||
|
||
@implementation NavigationProxy | ||
- (instancetype)init { | ||
if ((self = [super init])) { | ||
} | ||
return self; | ||
} | ||
|
||
- (NSURL*)URL { | ||
return net::NSURLWithGURL(GURL(url::kAboutBlankURL)); | ||
} | ||
|
||
- (WKBackForwardList*)backForwardList { | ||
return (WKBackForwardList*)[[BackForwardList alloc] init]; | ||
} | ||
@end | ||
|
||
#pragma mark - CRWWebController | ||
|
||
@implementation CRWWebController (Brave) | ||
- (id<CRWWebViewNavigationProxy>)webViewNavigationProxy { | ||
if (self.webView) { | ||
return [self webViewNavigationProxy_ChromiumImpl]; | ||
} | ||
|
||
return [[NavigationProxy alloc] init]; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters