Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #2981: Social Sharing #3387

Merged
merged 17 commits into from
Mar 12, 2021
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
12 changes: 12 additions & 0 deletions BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,12 @@ extension Strings {
value: "Take a look",
comment: "Action title for inspectable Education warnings")

public static let shareTheNewsTitle =
NSLocalizedString("shieldEducation.shareTheNewsTitle",
bundle: .braveShared,
value: "Share the news",
comment: "Action title for actionable Share warnings")

public static let benchmarkSpecialTierTitle =
NSLocalizedString("shieldEducation.benchmarkSpecialTierTitle",
bundle: .braveShared,
Expand Down Expand Up @@ -977,6 +983,12 @@ extension Strings {
bundle: .braveShared,
value: "Congratulations. You are legendary.",
comment: "Subtitle for tracker benchmark Share")

public static let shareDescriptionTitle = NSLocalizedString(
"socialSharing.shareDescriptionTitle",
bundle: Bundle.shared,
value: "Everyday I save data by browsing the web with Brave.",
comment: "Text used shile sharing Brave Shield values")
}
}

Expand Down
1 change: 1 addition & 0 deletions BraveShared/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ extension Preferences {
public static let privacyProtectionBlockShown = Option<Bool>(key: "product-benchmark.privacyProtectionBlockShown", default: false)
public static let httpsUpgradeShown = Option<Bool>(key: "product-benchmark.httpsUpgradeShown", default: false)
public static let videoAdBlockShown = Option<Bool>(key: "product-benchmark.videoAdBlockShown", default: false)
public static let trackerTierCount = Option<Int>(key: "product-benchmark.trackerTierCount", default: 0)
}

public final class Shields {
Expand Down
12 changes: 8 additions & 4 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@
2F44FCCB1A9E972E00FD20CC /* SearchEnginePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F44FCCA1A9E972E00FD20CC /* SearchEnginePicker.swift */; };
2F55443225913BD5000E4689 /* OpenSearchEngineButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F55443125913BD5000E4689 /* OpenSearchEngineButton.swift */; };
2F697F7E1A9FD22D009E03AE /* SearchEnginesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F697F7D1A9FD22D009E03AE /* SearchEnginesTests.swift */; };
2FA01E2825F29B0900103D67 /* BenchmarkTierTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA01E2725F29B0900103D67 /* BenchmarkTierTests.swift */; };
2FA01E5D25F2C93800103D67 /* ShieldsActivityItemSourceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA01E5C25F2C93800103D67 /* ShieldsActivityItemSourceProvider.swift */; };
2FB9C2A12587E742009DA1FE /* BrowserViewController+ProductNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FB9C2A02587E742009DA1FE /* BrowserViewController+ProductNotification.swift */; };
2FCAE2251ABB51F800877008 /* Storage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2FCAE21A1ABB51F800877008 /* Storage.framework */; };
2FCAE2311ABB51F800877008 /* Storage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2FCAE21A1ABB51F800877008 /* Storage.framework */; };
Expand All @@ -462,7 +464,6 @@
2FD0E3D62577F327000C773B /* SearchSuggestionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FD0E3D52577F327000C773B /* SearchSuggestionCell.swift */; };
2FDB10931A9FBEC5006CF312 /* PrefsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FDB10921A9FBEC5006CF312 /* PrefsTests.swift */; };
2FE5B42B2580216700BFDDB8 /* ShareTrackersController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FE5B42A2580216700BFDDB8 /* ShareTrackersController.swift */; };
2FE5B4542582BEF500BFDDB8 /* ShareTrayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FE5B4532582BEF500BFDDB8 /* ShareTrayView.swift */; };
2FE63DB8258BCC29004B219D /* BrowserViewController+OpenSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FE63DB7258BCC29004B219D /* BrowserViewController+OpenSearch.swift */; };
2FEA1613259CDFE800E00E4D /* SearchCustomEngineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FEA1612259CDFE800E00E4D /* SearchCustomEngineViewController.swift */; };
2FF0EDB325BA19E9004B18E2 /* SearchQuickEnginesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FF0EDB225BA19E9004B18E2 /* SearchQuickEnginesViewController.swift */; };
Expand Down Expand Up @@ -1919,6 +1920,8 @@
2F44FCCA1A9E972E00FD20CC /* SearchEnginePicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchEnginePicker.swift; sourceTree = "<group>"; };
2F55443125913BD5000E4689 /* OpenSearchEngineButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenSearchEngineButton.swift; sourceTree = "<group>"; };
2F697F7D1A9FD22D009E03AE /* SearchEnginesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchEnginesTests.swift; sourceTree = "<group>"; };
2FA01E2725F29B0900103D67 /* BenchmarkTierTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BenchmarkTierTests.swift; sourceTree = "<group>"; };
2FA01E5C25F2C93800103D67 /* ShieldsActivityItemSourceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShieldsActivityItemSourceProvider.swift; sourceTree = "<group>"; };
2FB9C2A02587E742009DA1FE /* BrowserViewController+ProductNotification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BrowserViewController+ProductNotification.swift"; sourceTree = "<group>"; };
2FCAE21A1ABB51F800877008 /* Storage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Storage.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2FCAE2241ABB51F800877008 /* StorageTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StorageTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -1940,7 +1943,6 @@
2FD0E3D52577F327000C773B /* SearchSuggestionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSuggestionCell.swift; sourceTree = "<group>"; };
2FDB10921A9FBEC5006CF312 /* PrefsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrefsTests.swift; sourceTree = "<group>"; };
2FE5B42A2580216700BFDDB8 /* ShareTrackersController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareTrackersController.swift; sourceTree = "<group>"; };
2FE5B4532582BEF500BFDDB8 /* ShareTrayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareTrayView.swift; sourceTree = "<group>"; };
2FE63DB7258BCC29004B219D /* BrowserViewController+OpenSearch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BrowserViewController+OpenSearch.swift"; sourceTree = "<group>"; };
2FEA1612259CDFE800E00E4D /* SearchCustomEngineViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchCustomEngineViewController.swift; sourceTree = "<group>"; };
2FEBABAE1AB3659000DB5728 /* ResultTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4711,7 +4713,7 @@
278C6FFE24F6EA3700A246C8 /* ReportBrokenSiteView.swift */,
278C700124F6F33D00A246C8 /* SiteReportedView.swift */,
2FE5B42A2580216700BFDDB8 /* ShareTrackersController.swift */,
2FE5B4532582BEF500BFDDB8 /* ShareTrayView.swift */,
2FA01E5C25F2C93800103D67 /* ShieldsActivityItemSourceProvider.swift */,
);
path = Shields;
sourceTree = "<group>";
Expand Down Expand Up @@ -5310,6 +5312,7 @@
F95ED17D25A95426001A432D /* UserScriptManagerTest.swift */,
0A2BFB3325F2754600719AA9 /* NTPDownloaderTests.swift */,
27C5AE2D25D72B0A00B8F50E /* OPMLParsingTests.swift */,
2FA01E2725F29B0900103D67 /* BenchmarkTierTests.swift */,
);
path = ClientTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -7131,7 +7134,6 @@
A9072B801D07B34100459960 /* NoImageModeHelper.swift in Sources */,
4422D4EB21BFFB7600BF1855 /* filename.cc in Sources */,
2726636924944BFA0056CFE1 /* BraveTodayWelcomeView.swift in Sources */,
2FE5B4542582BEF500BFDDB8 /* ShareTrayView.swift in Sources */,
2755EABD255323C60033C43F /* PublisherInfoExtensions.swift in Sources */,
2746D28324A4FB7400E38852 /* RewardsInternalsSharable.swift in Sources */,
44331DDA22552313007E3E93 /* LocationContainerView.swift in Sources */,
Expand All @@ -7143,6 +7145,7 @@
27448536245B608E001920B5 /* QRCodePopupView.swift in Sources */,
4422D50121BFFB7600BF1855 /* repair.cc in Sources */,
E660BDD91BB06521009AC090 /* TabsButton.swift in Sources */,
2FA01E5D25F2C93800103D67 /* ShieldsActivityItemSourceProvider.swift in Sources */,
4422D55721BFFB7F00BF1855 /* unicode_groups.cc in Sources */,
4422D55421BFFB7E00BF1855 /* re2_fuzzer.cc in Sources */,
2F44FCCB1A9E972E00FD20CC /* SearchEnginePicker.swift in Sources */,
Expand Down Expand Up @@ -7327,6 +7330,7 @@
A83E5B1D1C1DA8D80026D912 /* UIPasteboardExtensionsTests.swift in Sources */,
E696FE511C47F86E00EC007C /* AuthenticatorTests.swift in Sources */,
275965E224EEC4EA0051A827 /* FeedFillStrategyTests.swift in Sources */,
2FA01E2825F29B0900103D67 /* BenchmarkTierTests.swift in Sources */,
F95ED17E25A95426001A432D /* UserScriptManagerTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"images" : [
{
"filename" : "share-bubble-mail.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "share-bubble-mail@2x.png",
"filename" : "share-activity-background@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "share-bubble-more.png",
"filename" : "help.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "share-bubble-more@2x.png",
"filename" : "help@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "share-bubble-more@3x.png",
"filename" : "help@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"images" : [
{
"filename" : "shields-help.png",
"idiom" : "universal",
"filename" : "help.png",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "share-bubble-twitter.png",
"filename" : "shields-share.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "share-bubble-twitter@2x.png",
"filename" : "shields-share@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "share-bubble-twitter@3x.png",
"filename" : "share-shields@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Client/Extensions/UIViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ extension UIView {

return screenshot(size, offset: offset, quality: quality)
}

/// Getting a snapshot from a view using image renderer
var snapshot: UIImage {
UIGraphicsImageRenderer(size: bounds.size).image { _ in
drawHierarchy(in: bounds, afterScreenUpdates: true)
}
}

/**
* rounds the requested corners of a view with the provided radius
Expand Down
5 changes: 5 additions & 0 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ class BrowserViewController: UIViewController {

/// Number of Ads/Trackers used a limit to show benchmark notification
let benchmarkNumberOfTrackers = 10

/// Used to determine when to present benchmark pop-overs
/// Current session ad count is compared with live ad count
/// So user will not be introduced with a pop-over directly
let benchmarkCurrentSessionAdCount = BraveGlobalShieldStats.shared.adblock + BraveGlobalShieldStats.shared.trackingProtection

init(profile: Profile, tabManager: TabManager, crashedLastSession: Bool,
safeBrowsingManager: SafeBrowsing? = SafeBrowsing()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,45 @@ import Shared

extension BrowserViewController {

// MARK: BenchmarkTrackerCountTier

enum BenchmarkTrackerCountTier: Int, Equatable, CaseIterable {
case specialTier = 1000
case newbieExclusiveTier = 5000
case casualExclusiveTier = 10_000
case regularExclusiveTier = 25_000
case expertExclusiveTier = 75_000
case professionalTier = 100_000
case primeTier = 250_000
case grandTier = 500_000
case legendaryTier = 1_000_000

var title: String {
switch self {
case .specialTier:
return Strings.ShieldEducation.benchmarkSpecialTierTitle
case .newbieExclusiveTier, .casualExclusiveTier, .regularExclusiveTier, .expertExclusiveTier:
return Strings.ShieldEducation.benchmarkExclusiveTierTitle
case .professionalTier:
return Strings.ShieldEducation.benchmarkProfessionalTierTitle
case .primeTier:
return Strings.ShieldEducation.benchmarkPrimeTierTitle
case .grandTier:
return Strings.ShieldEducation.benchmarkGrandTierTitle
case .legendaryTier:
return Strings.ShieldEducation.benchmarkLegendaryTierTitle
}
}

var nextTier: BenchmarkTrackerCountTier? {
guard let indexOfSelf = Self.allCases.firstIndex(where: { self == $0 }) else {
return nil
}

return Self.allCases[safe: indexOfSelf + 1]
}
}

// MARK: Internal

@objc func updateShieldNotifications() {
Expand Down Expand Up @@ -43,7 +82,7 @@ extension BrowserViewController {

return
}

// Step 2: Load a video on a streaming site
if !Preferences.ProductNotificationBenchmarks.videoAdBlockShown.value,
selectedTab.url?.isVideoSteamingSiteURL == true {
Expand Down Expand Up @@ -73,20 +112,34 @@ extension BrowserViewController {

return
}

// Step 5: Share Brave Benchmark Tiers
// Benchmark Tier Pop-Over only exist in JP locale
if Locale.current.regionCode == "JP" {
let numOfTrackerAds = BraveGlobalShieldStats.shared.adblock + BraveGlobalShieldStats.shared.trackingProtection
guard numOfTrackerAds > benchmarkCurrentSessionAdCount + 20 else { return }

let existingTierList = BenchmarkTrackerCountTier.allCases.filter({ Preferences.ProductNotificationBenchmarks.trackerTierCount.value < $0.rawValue})

if !existingTierList.isEmpty {
guard let firstExistingTier = existingTierList.first else { return }

Preferences.ProductNotificationBenchmarks.trackerTierCount.value = numOfTrackerAds

if numOfTrackerAds > firstExistingTier.rawValue {
notifyTrackerAdsCount(firstExistingTier.rawValue, theme: Theme.of(selectedTab))
}
}
}
}

private func notifyFirstTimeBlock(theme: Theme) {
let shareTrackersViewController = ShareTrackersController(theme: theme, trackingType: .trackerAdWarning)

shareTrackersViewController.actionHandler = { [weak self] action in
guard let self = self else { return }
guard let self = self, action == .takeALookTapped else { return }

switch action {
case .takeALookTapped:
self.showShieldsScreen()
default:
break
}
self.showShieldsScreen()
}

showBenchmarkNotificationPopover(controller: shareTrackersViewController)
Expand All @@ -111,6 +164,19 @@ extension BrowserViewController {
showBenchmarkNotificationPopover(controller: shareTrackersViewController)
}

private func notifyTrackerAdsCount(_ count: Int, theme: Theme) {
let shareTrackersViewController = ShareTrackersController(theme: theme, trackingType: .trackerCountShare(count: count))
dismiss(animated: true)

shareTrackersViewController.actionHandler = { [weak self] action in
guard let self = self, action == .shareTheNewsTapped else { return }

self.showShareScreen(with: theme)
}

showBenchmarkNotificationPopover(controller: shareTrackersViewController)
}

private func showBenchmarkNotificationPopover(controller: (UIViewController & PopoverContentComponent)) {
benchmarkNotificationPresented = true

Expand All @@ -126,4 +192,14 @@ extension BrowserViewController {
self.presentBraveShieldsViewController()
}
}

func showShareScreen(with theme: Theme) {
dismiss(animated: true) {
let globalShieldsActivityController =
ShieldsActivityItemSourceProvider.shared.setupGlobalShieldsActivityController(theme: theme)
globalShieldsActivityController.popoverPresentationController?.sourceView = self.view

self.present(globalShieldsActivityController, animated: true, completion: nil)
}
}
}
Loading