Skip to content

Commit d1683e3

Browse files
FilippoZazzeroniFilippo
and
Filippo
authored
Bugix [Content Sharing opt] fix home page activity and File copy to clipboard message (#26167)
* Fix home page activity and add correct label when copying pdf to clipboard * Fixed tests and removed unused import --------- Co-authored-by: Filippo <[email protected]>
1 parent 58d564a commit d1683e3

File tree

7 files changed

+117
-14
lines changed

7 files changed

+117
-14
lines changed

firefox-ios/Client.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
0B7C1E951F6097AD006A8869 /* TrackingProtectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B7C1E941F6097AD006A8869 /* TrackingProtectionTests.swift */; };
5959
0B7CF8872CAC1C4E00DC02F8 /* DefaultFolderHierarchyFetcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B7CF8862CAC1C4E00DC02F8 /* DefaultFolderHierarchyFetcherTests.swift */; };
6060
0B7FC3D32CAE811F005C5CCE /* DefaultBookmarksSaverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B7FC3D12CAE811B005C5CCE /* DefaultBookmarksSaverTests.swift */; };
61+
0B81AFEC2DB1000C000AF70F /* HomePageActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B81AFEB2DB1000C000AF70F /* HomePageActivity.swift */; };
62+
0B81AFEE2DB1036B000AF70F /* HomePageActivityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B81AFED2DB1036B000AF70F /* HomePageActivityTests.swift */; };
6163
0B8A39EF2D3514C100853E47 /* EditBookmarkDiffableDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B8A39EE2D3514C100853E47 /* EditBookmarkDiffableDataSource.swift */; };
6264
0B8A39F12D351C2500853E47 /* EditBookmarkDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B8A39F02D351C2500853E47 /* EditBookmarkDataSourceTests.swift */; };
6365
0B8BF3702CA2D60B00E9812D /* BookmarksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B8BF36F2CA2D60B00E9812D /* BookmarksViewController.swift */; };
@@ -2418,6 +2420,8 @@
24182420
0B7C1E941F6097AD006A8869 /* TrackingProtectionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrackingProtectionTests.swift; sourceTree = "<group>"; };
24192421
0B7CF8862CAC1C4E00DC02F8 /* DefaultFolderHierarchyFetcherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultFolderHierarchyFetcherTests.swift; sourceTree = "<group>"; };
24202422
0B7FC3D12CAE811B005C5CCE /* DefaultBookmarksSaverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultBookmarksSaverTests.swift; sourceTree = "<group>"; };
2423+
0B81AFEB2DB1000C000AF70F /* HomePageActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageActivity.swift; sourceTree = "<group>"; };
2424+
0B81AFED2DB1036B000AF70F /* HomePageActivityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageActivityTests.swift; sourceTree = "<group>"; };
24212425
0B8749EB891EE229EA88FEF3 /* kn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = kn; path = kn.lproj/ErrorPages.strings; sourceTree = "<group>"; };
24222426
0B8A39EE2D3514C100853E47 /* EditBookmarkDiffableDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditBookmarkDiffableDataSource.swift; sourceTree = "<group>"; };
24232427
0B8A39F02D351C2500853E47 /* EditBookmarkDataSourceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditBookmarkDataSourceTests.swift; sourceTree = "<group>"; };
@@ -13985,6 +13989,7 @@
1398513989
2128E27A292E624400FB91BE /* SendToDeviceActivity.swift */,
1398613990
E1AFBAF8292EA0330065E35E /* SendToDeviceHelper.swift */,
1398713991
D3972BF11C22412B00035B87 /* ShareManager.swift */,
13992+
0B81AFEB2DB1000C000AF70F /* HomePageActivity.swift */,
1398813993
ED67B2952D0C921600BDC599 /* ShareTelemetry.swift */,
1398913994
ED7A08DA2CF674730035EC8F /* ShareMessage.swift */,
1399013995
ED7A08DC2CF6749B0035EC8F /* ShareType.swift */,
@@ -14781,6 +14786,7 @@
1478114786
ED67B2932D0B80E200BDC599 /* TitleActivityItemProviderTests.swift */,
1478214787
ED67B2912D0B79F000BDC599 /* TitleSubtitleActivityItemProviderTests.swift */,
1478314788
ED33E3562D0A4CE9002265A7 /* URLActivityItemProviderTests.swift */,
14789+
0B81AFED2DB1036B000AF70F /* HomePageActivityTests.swift */,
1478414790
);
1478514791
path = Sharing;
1478614792
sourceTree = "<group>";
@@ -17032,6 +17038,7 @@
1703217038
C2D71B9B2A3850B4003DEC7A /* ThemedTableViewCellViewModel.swift in Sources */,
1703317039
C869912F28917688007ACC5C /* WallpaperMetadataLoader.swift in Sources */,
1703417040
8A6904802B97BBAE00E30047 /* SplashScreenAnimation.swift in Sources */,
17041+
0B81AFEC2DB1000C000AF70F /* HomePageActivity.swift in Sources */,
1703517042
2137785D297F1F2800D01309 /* DownloadedFile.swift in Sources */,
1703617043
1DCEC4142D83B7EB00129966 /* ASSearchEngineIconDataFetcher.swift in Sources */,
1703717044
745DAB301CDAAFAA00D44181 /* RecentlyClosedTabsPanel.swift in Sources */,
@@ -18092,6 +18099,7 @@
1809218099
8A8629E72880B7330096DDB1 /* LegacyBookmarksPanelTests.swift in Sources */,
1809318100
61A1644A2CE7BE8A001D6058 /* WallpaperMiddlewareTests.swift in Sources */,
1809418101
C8B394362A0ED55D00700E49 /* MockOnboardingCardDelegate.swift in Sources */,
18102+
0B81AFEE2DB1036B000AF70F /* HomePageActivityTests.swift in Sources */,
1809518103
8A5604F829DF0D2600035CA3 /* BrowserCoordinatorTests.swift in Sources */,
1809618104
8ABB15C92D5A4E3900A4635C /* RemoteTabsMiddlewareTests.swift in Sources */,
1809718105
C787D8C32C1CB77900940123 /* FirefoxAccountSignInViewControllerTests.swift in Sources */,

firefox-ios/Client/Coordinators/ShareSheetCoordinator.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ class ShareSheetCoordinator: BaseCoordinator,
102102
showSendToDevice(url: shareType.wrappedURL, relatedTab: nil)
103103
}
104104
case .copyToPasteboard:
105-
showToast(text: .LegacyAppMenu.AppMenuCopyURLConfirmMessage)
105+
if case .file = shareType {
106+
showToast(text: .ShareFileCopiedToClipboard)
107+
} else {
108+
showToast(text: .LegacyAppMenu.AppMenuCopyURLConfirmMessage)
109+
}
106110
dequeueNotShownJSAlert()
107111
default:
108112
dequeueNotShownJSAlert()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/
4+
5+
import Shared
6+
import WebKit
7+
8+
/// The activity representing in the Share sheet the action to add a website to the iOS homepage.
9+
///
10+
/// - Note: the activity is a `WKWebView` cause the frameworks generates the add to home page activity only
11+
/// when passing a `WKWebView`. This `WKWebView` subclass gives the ability to modify the content of the activity,
12+
/// by modifying the title and/or the url.
13+
class HomePageActivity: WKWebView {
14+
private let stubbedURL: URL?
15+
private let stubbedTitle: String?
16+
17+
init(url: URL?, title: String?) {
18+
if let internalURL = InternalURL(url) {
19+
stubbedURL = internalURL.extractedUrlParam
20+
} else {
21+
stubbedURL = url
22+
}
23+
stubbedTitle = title
24+
super.init(frame: .zero, configuration: .init())
25+
}
26+
27+
required init?(coder: NSCoder) {
28+
fatalError("init(coder:) has not been implemented")
29+
}
30+
31+
override var url: URL? {
32+
return stubbedURL
33+
}
34+
35+
override var title: String? {
36+
return stubbedTitle
37+
}
38+
}

firefox-ios/Client/Frontend/Share/ShareManager.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ class ShareManager: NSObject, FeatureFlaggable {
115115

116116
// Add the webview for an option to add a website to the iOS home screen
117117
if #available(iOS 16.4, *), let webView = tab.webView {
118-
// NOTE: You will not see "Add to Home Screen" option on debug builds. Possibly this is because of how the
119-
// com.apple.developer.web-browser entitlement is applied...
120-
activityItems.append(webView)
118+
activityItems.append(HomePageActivity(url: webView.url,
119+
title: webView.title))
121120
}
122121

123122
if let explicitShareMessage {

firefox-ios/Shared/Strings.swift

+5
Original file line numberDiff line numberDiff line change
@@ -5422,6 +5422,11 @@ extension String {
54225422
tableName: nil,
54235423
value: "Add to Reading List",
54245424
comment: "Action label on share extension to add page to the Firefox reading list.")
5425+
public static let ShareFileCopiedToClipboard = MZLocalizedString(
5426+
key: "ShareExtension.FileCopiedToClipboard.Title.v139",
5427+
tableName: "Share",
5428+
value: "File Copied To Clipboard",
5429+
comment: "The Toast message that appears when the user press copy on the share sheet with a file like a pdf")
54255430
public static let ShareAddToReadingListDone = MZLocalizedString(
54265431
key: "ShareExtension.AddToReadingListActionDone.Title",
54275432
tableName: nil,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/
4+
5+
import XCTest
6+
import Common
7+
import Shared
8+
@testable import Client
9+
10+
final class HomePageActivityTests: XCTestCase {
11+
func testInit_withOnlineURL_returnsSameURL() {
12+
let urlString = "https://www.google.com"
13+
let url = URL(string: urlString)!
14+
let title = "test title"
15+
let subject = createSubject(url: url, title: title)
16+
17+
XCTAssertEqual(subject.url, url)
18+
XCTAssertEqual(subject.title, title)
19+
RunLoop.current.run(until: Date().addingTimeInterval(0.1))
20+
}
21+
22+
func testInit_withLocalURL_returnsNilURL() {
23+
let urlString = "internal://fennec.test"
24+
let url = URL(string: urlString)!
25+
let subject = createSubject(url: url)
26+
27+
// has to be nil since we try only to unwrap the url param from internal url
28+
XCTAssertNil(subject.url)
29+
RunLoop.current.run(until: Date().addingTimeInterval(0.1))
30+
}
31+
32+
func testInit_withLocalHostURL_returnsUnwrappedURLParameter() {
33+
let innerUrl = "https//:www.google.com"
34+
let urlString = "http://localhost:\(AppInfo.webserverPort)/?url=\(innerUrl)"
35+
let url = URL(string: urlString)!
36+
let subject = createSubject(url: url)
37+
38+
XCTAssertEqual(subject.url, URL(string: innerUrl))
39+
// needed to fully deallocate the WKWebView
40+
RunLoop.current.run(until: Date().addingTimeInterval(0.1))
41+
}
42+
43+
private func createSubject(url: URL? = nil,
44+
title: String? = nil) -> HomePageActivity {
45+
let subject = HomePageActivity(url: url, title: title)
46+
trackForMemoryLeaks(subject)
47+
return subject
48+
}
49+
}

firefox-ios/firefox-ios-tests/Tests/ClientTests/Sharing/ShareManagerTests.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ final class ShareManagerTests: XCTestCase {
199199

200200
_ = try XCTUnwrap(activityItems[safe: 1] as? TabPrintPageRenderer)
201201

202-
_ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView)
202+
_ = try XCTUnwrap(activityItems[safe: 2] as? HomePageActivity)
203203

204204
let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider)
205205
let itemForTitleActivity = titleActivityItemProvider.activityViewController(
@@ -244,7 +244,7 @@ final class ShareManagerTests: XCTestCase {
244244

245245
_ = try XCTUnwrap(activityItems[safe: 1] as? TabPrintPageRenderer)
246246

247-
_ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView)
247+
_ = try XCTUnwrap(activityItems[safe: 2] as? HomePageActivity)
248248

249249
let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider)
250250
let itemForTitleActivity = titleActivityItemProvider.activityViewController(
@@ -290,7 +290,7 @@ final class ShareManagerTests: XCTestCase {
290290

291291
_ = try XCTUnwrap(activityItems[safe: 1] as? TabPrintPageRenderer)
292292

293-
_ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView)
293+
_ = try XCTUnwrap(activityItems[safe: 2] as? HomePageActivity)
294294

295295
let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleSubtitleActivityItemProvider)
296296

@@ -339,7 +339,7 @@ final class ShareManagerTests: XCTestCase {
339339
// The rest of the content should be unchanged from other tests:
340340
_ = try XCTUnwrap(activityItems[safe: 1] as? TabPrintPageRenderer)
341341

342-
_ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView)
342+
_ = try XCTUnwrap(activityItems[safe: 2] as? HomePageActivity)
343343

344344
let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider)
345345
let itemForTitleActivity = titleActivityItemProvider.activityViewController(
@@ -389,7 +389,7 @@ final class ShareManagerTests: XCTestCase {
389389
// The rest of the content should be unchanged from other tests:
390390
_ = try XCTUnwrap(activityItems[safe: 1] as? TabPrintPageRenderer)
391391

392-
_ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView)
392+
_ = try XCTUnwrap(activityItems[safe: 2] as? HomePageActivity)
393393

394394
let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider)
395395
let itemForTitleActivity = titleActivityItemProvider.activityViewController(
@@ -437,7 +437,7 @@ final class ShareManagerTests: XCTestCase {
437437
// The rest of the content should be unchanged from other tests:
438438
_ = try XCTUnwrap(activityItems[safe: 1] as? TabPrintPageRenderer)
439439

440-
_ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView)
440+
_ = try XCTUnwrap(activityItems[safe: 2] as? HomePageActivity)
441441

442442
let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider)
443443
let itemForTitleActivity = titleActivityItemProvider.activityViewController(
@@ -485,7 +485,7 @@ final class ShareManagerTests: XCTestCase {
485485
// The rest of the content should be unchanged from other tests:
486486
_ = try XCTUnwrap(activityItems[safe: 1] as? TabPrintPageRenderer)
487487

488-
_ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView)
488+
_ = try XCTUnwrap(activityItems[safe: 2] as? HomePageActivity)
489489

490490
let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider)
491491
let itemForTitleActivity = titleActivityItemProvider.activityViewController(
@@ -535,7 +535,7 @@ final class ShareManagerTests: XCTestCase {
535535
// The rest of the content should be unchanged from other tests:
536536
_ = try XCTUnwrap(activityItems[safe: 1] as? TabPrintPageRenderer)
537537

538-
_ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView)
538+
_ = try XCTUnwrap(activityItems[safe: 2] as? HomePageActivity)
539539

540540
let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider)
541541
let itemForTitleActivity = titleActivityItemProvider.activityViewController(
@@ -592,7 +592,7 @@ final class ShareManagerTests: XCTestCase {
592592
// The rest of the content should be unchanged from other tests:
593593
_ = try XCTUnwrap(activityItems[safe: 1] as? TabPrintPageRenderer)
594594

595-
_ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView)
595+
_ = try XCTUnwrap(activityItems[safe: 2] as? HomePageActivity)
596596

597597
let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider)
598598
let itemForTitleActivity = titleActivityItemProvider.activityViewController(
@@ -651,7 +651,7 @@ final class ShareManagerTests: XCTestCase {
651651
// The rest of the content should be unchanged from other tests:
652652
_ = try XCTUnwrap(activityItems[safe: 1] as? TabPrintPageRenderer)
653653

654-
_ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView)
654+
_ = try XCTUnwrap(activityItems[safe: 2] as? HomePageActivity)
655655

656656
let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider)
657657
let itemForTitleActivity = titleActivityItemProvider.activityViewController(

0 commit comments

Comments
 (0)