Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

[IB2-71] - Ghotery count fix

  • Loading branch information
Tim Palade committed Apr 16, 2018
1 parent 2c540bb commit 5e0d7faa50a30f6cfd0fdff5375f751853ba133f
Showing with 24 additions and 0 deletions.
  1. +2 −0 Client/Frontend/Browser/Tab.swift
  2. +13 −0 Cliqz/Extensions/TabExtension.swift
  3. +9 −0 Cliqz/Privacy/UI/GhosteryButton.swift
@@ -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)

0 comments on commit 5e0d7fa

Please sign in to comment.