Skip to content

Commit

Permalink
Safari: performance gain via cleanup of overhead, & improves getTabId…
Browse files Browse the repository at this point in the history
… efficiency
  • Loading branch information
Chris committed Feb 5, 2015
1 parent b2ae524 commit 32da7cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
22 changes: 11 additions & 11 deletions platform/safari/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions platform/safari/vapi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
if(frameId === 0) {
safari.self.tab.canLoad(beforeLoadEvent, {
url: location.href,
type: "navigatedToNew"
type: "main_frame"
});
}
var nodeTypes = {
Expand All @@ -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,
Expand Down

0 comments on commit 32da7cd

Please sign in to comment.