Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[IB2-71] - Ghotery count fix
- Loading branch information
|
|
@@ -455,6 +455,8 @@ class Tab: NSObject { |
|
|
} |
|
|
|
|
|
self.urlDidChangeDelegate?.tab(self, urlDidChangeTo: url) |
|
|
//Cliqz: Needed for Ghostery Count |
|
|
self.sendURLChangedNotification() |
|
|
} |
|
|
|
|
|
func isDescendentOf(_ ancestor: Tab) -> Bool { |
|
|
|
|
|
@@ -7,6 +7,9 @@ |
|
|
// |
|
|
|
|
|
import WebKit |
|
|
import Shared |
|
|
|
|
|
let urlChangedNotification = Notification.Name(rawValue: "URLChangedNotification") |
|
|
|
|
|
extension Tab { |
|
|
|
|
|
@@ -78,4 +81,14 @@ extension Tab { |
|
|
setupBlocking() |
|
|
} |
|
|
|
|
|
func sendURLChangedNotification() { |
|
|
|
|
|
var userInfo: [String: URL] = [:] |
|
|
if let url = self.webView?.url { |
|
|
userInfo["url"] = url |
|
|
} |
|
|
|
|
|
NotificationCenter.default.post(name: urlChangedNotification, object: self, userInfo: userInfo) |
|
|
} |
|
|
|
|
|
} |
|
|
@@ -112,12 +112,21 @@ class GhosteryCount { |
|
|
init() { |
|
|
NotificationCenter.default.addObserver(self, selector: #selector(newTrackerDetected), name: detectedTrackerNotification, object: nil) |
|
|
NotificationCenter.default.addObserver(self, selector: #selector(newTabSelected), name: didChangeTabNotification, object: nil) |
|
|
NotificationCenter.default.addObserver(self, selector: #selector(urlChanged), name: urlChangedNotification, object: nil) |
|
|
} |
|
|
|
|
|
deinit { |
|
|
NotificationCenter.default.removeObserver(self) |
|
|
} |
|
|
|
|
|
@objc func urlChanged(notification: Notification) { |
|
|
guard let del = UIApplication.shared.delegate as? AppDelegate, let currentTab = del.tabManager.selectedTab else {return} |
|
|
if let tab = notification.object as? Tab, tab == currentTab, let currentUrl = self.dataSource?.currentUrl() { |
|
|
let count = TrackerList.instance.detectedTrackerCountForPage(currentUrl.absoluteString) |
|
|
self.delegate?.updateCount(count: count) |
|
|
} |
|
|
} |
|
|
|
|
|
@objc func newTrackerDetected(notification: Notification) { |
|
|
if let currentUrl = self.dataSource?.currentUrl() { |
|
|
let count = TrackerList.instance.detectedTrackerCountForPage(currentUrl.absoluteString) |
|
|
|