From 32da7cd1e584c48445f41ed21870d949e151f69c Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 5 Feb 2015 16:23:56 -0700 Subject: [PATCH] Safari: performance gain via cleanup of overhead, & improves getTabId efficiency --- platform/safari/vapi-background.js | 22 +++++++++++----------- platform/safari/vapi-client.js | 5 ++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index 9df2dc3e2..78b2077c5 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -206,9 +206,12 @@ /******************************************************************************/ vAPI.tabs.getTabId = function(tab) { + if(typeof tab.uBlockCachedID !== "undefined") { + return tab.uBlockCachedID; + } for(var i in vAPI.tabs.stack) { if(vAPI.tabs.stack[i] === tab) { - return +i; + return (tab.uBlockCachedID = +i); } } @@ -629,21 +632,20 @@ } e.stopPropagation && e.stopPropagation(); switch(e.message.type) { - case "isWhiteListed": - e.message = !µb.getNetFilteringSwitch(e.message.url); - break; - case "navigatedToNew": + case "main_frame": vAPI.tabs.onNavigation({ url: e.message.url, frameId: 0, tabId: vAPI.tabs.getTabId(e.target) }); - break; + // Don't break here; let main_frame go through case "popup": if(e.message.url === 'about:blank') { vAPI.tabs.popupCandidate = vAPI.tabs.getTabId(e.target); e.message = true; - } else { + return; + } + else { e.message = !vAPI.tabs.onPopup({ url: e.message.url, tabId: 0, @@ -659,17 +661,15 @@ }); break; default: - if(!blockableTypes.contains(e.message.type)) { - e.message = true; - return; - } e.message.hostname = µb.URI.hostnameFromURI(e.message.url); e.message.tabId = vAPI.tabs.getTabId(e.target); var blockVerdict = onBeforeRequestClient(e.message); if(blockVerdict && blockVerdict.cancel) { e.message = false; + return; } else { e.message = true; + return; } } return; diff --git a/platform/safari/vapi-client.js b/platform/safari/vapi-client.js index 5ba2d1497..0a9dd5526 100644 --- a/platform/safari/vapi-client.js +++ b/platform/safari/vapi-client.js @@ -163,7 +163,7 @@ if(frameId === 0) { safari.self.tab.canLoad(beforeLoadEvent, { url: location.href, - type: "navigatedToNew" + type: "main_frame" }); } var nodeTypes = { @@ -189,9 +189,8 @@ return; } linkHelper.href = e.url; - var url = linkHelper.href; var details = { - url: url, + url: linkHelper.href, type: nodeTypes[e.target.nodeName.toLowerCase()] || "other", // tabId is determined in the background script frameId: frameId,