-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom html error page implementation (#2136)
Task/Issue URL: https://app.asana.com/0/72649045549333/1203487090719123/f Tech Design URL: https://app.asana.com/0/481882893211075/1203487090719150/f BSK PR: duckduckgo/BrowserServicesKit#644 Content-Scope-Scripts PR: duckduckgo/content-scope-scripts#906
- Loading branch information
Showing
50 changed files
with
1,846 additions
and
505 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
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+2.32 KB
...ckGo/Assets.xcassets/Images/Alert-Circle-Color-16.imageset/Alert-Medium-Multicolor-16.pdf
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
DuckDuckGo/Assets.xcassets/Images/Alert-Circle-Color-16.imageset/Contents.json
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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Alert-Medium-Multicolor-16.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
DuckDuckGo/Assets.xcassets/Images/DefaultFavicon.imageset/Contents.json
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-180 Bytes
DuckDuckGo/Assets.xcassets/Images/DefaultFavicon.imageset/default-fav.png
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
DuckDuckGo/Assets.xcassets/Images/Globe-Multicolor-16.imageset/Contents.json
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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Globe-Multicolor-16.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+4.02 KB
DuckDuckGo/Assets.xcassets/Images/Globe-Multicolor-16.imageset/Globe-Multicolor-16.pdf
Binary file not shown.
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
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,27 @@ | ||
// | ||
// NSObject+performSelector.h | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface NSObject (performSelector) | ||
- (id)performSelector:(SEL)selector withArguments:(NSArray *)arguments; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// NSObject+performSelector.m | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import "NSObject+performSelector.h" | ||
|
||
@implementation NSObject (performSelector) | ||
|
||
- (id)performSelector:(SEL)selector withArguments:(NSArray *)arguments { | ||
NSMethodSignature *methodSignature = [self methodSignatureForSelector:selector]; | ||
|
||
if (!methodSignature) { | ||
[[[NSException alloc] initWithName:@"InvalidSelectorOrTarget" reason:[NSString stringWithFormat:@"Could not get method signature for selector %@ on %@", NSStringFromSelector(selector), self] userInfo:nil] raise]; | ||
} | ||
|
||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; | ||
[invocation setSelector:selector]; | ||
[invocation setTarget:self]; | ||
|
||
for (NSInteger i = 0; i < arguments.count; i++) { | ||
id argument = arguments[i]; | ||
[invocation setArgument:&argument atIndex:i + 2]; // Indices 0 and 1 are reserved for target and selector | ||
} | ||
|
||
[invocation invoke]; | ||
|
||
if (methodSignature.methodReturnLength > 0) { | ||
id returnValue; | ||
[invocation getReturnValue:&returnValue]; | ||
|
||
return returnValue; | ||
} | ||
|
||
return nil; | ||
} | ||
|
||
|
||
@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
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
35 changes: 35 additions & 0 deletions
35
DuckDuckGo/Common/Extensions/WKBackForwardListItemExtension.swift
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,35 @@ | ||
// | ||
// WKBackForwardListItemExtension.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import WebKit | ||
|
||
extension WKBackForwardListItem { | ||
|
||
// sometimes WKBackForwardListItem returns wrong or outdated title | ||
private static let tabTitleKey = UnsafeRawPointer(bitPattern: "tabTitleKey".hashValue)! | ||
var tabTitle: String? { | ||
get { | ||
objc_getAssociatedObject(self, Self.tabTitleKey) as? String | ||
} | ||
set { | ||
objc_setAssociatedObject(self, Self.tabTitleKey, newValue, .OBJC_ASSOCIATION_RETAIN) | ||
} | ||
} | ||
|
||
} |
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
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
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
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
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,45 @@ | ||
// | ||
// ErrorPageHTMLTemplate.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import ContentScopeScripts | ||
import WebKit | ||
|
||
struct ErrorPageHTMLTemplate { | ||
|
||
static var htmlTemplatePath: String { | ||
guard let file = ContentScopeScripts.Bundle.path(forResource: "index", ofType: "html", inDirectory: "pages/errorpage") else { | ||
assertionFailure("HTML template not found") | ||
return "" | ||
} | ||
return file | ||
} | ||
|
||
let error: WKError | ||
let header: String | ||
|
||
func makeHTMLFromTemplate() -> String { | ||
guard let html = try? String(contentsOfFile: Self.htmlTemplatePath) else { | ||
assertionFailure("Should be able to load template") | ||
return "" | ||
} | ||
return html.replacingOccurrences(of: "$ERROR_DESCRIPTION$", with: error.localizedDescription.escapedUnicodeHtmlString(), options: .literal) | ||
.replacingOccurrences(of: "$HEADER$", with: header.escapedUnicodeHtmlString(), options: .literal) | ||
} | ||
|
||
} |
Oops, something went wrong.