Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: webrequest.js

Issue 5088751004942336: Issue 370 - Right-clicked element is removed independent of created filter (Closed)
Patch Set: Rebase to rev 3c9cea80c481 Created July 18, 2014, 8:54 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « stats.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrequest.js
===================================================================
--- a/webrequest.js
+++ b/webrequest.js
@@ -1,6 +1,6 @@
/*
* This file is part of Adblock Plus <http://adblockplus.org/>,
- * Copyright (C) 2006-2013 Eyeo GmbH
+ * Copyright (C) 2006-2014 Eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
@@ -16,6 +16,7 @@
*/
var FilterNotifier = require("filterNotifier").FilterNotifier;
+var platform = require("info").platform;
var onFilterChangeTimeout = null;
function onFilterChange()
@@ -46,162 +47,61 @@
}
});
-var frames = new TabMap();
-
-function onBeforeRequest(url, type, tab, frameId, parentFrameId)
+function onBeforeRequest(url, type, page, frame)
{
- if (!tab)
+ if (isFrameWhitelisted(page, frame))
return true;
- // Assume that the first request belongs to the top frame. Chrome may give the
- // top frame the type "object" instead of "main_frame".
- // https://code.google.com/p/chromium/issues/detail?id=281711
- if (frameId == 0 && !frames.has(tab) && type == "object")
- type = "main_frame";
+ var docDomain = extractHostFromFrame(frame);
+ var filter = defaultMatcher.matchesAny(
+ url,
+ type == "sub_frame" ? "SUBDOCUMENT" : type.toUpperCase(),
+ docDomain,
+ isThirdParty(extractHostFromURL(url), docDomain)
+ );
- if (type == "main_frame" || type == "sub_frame")
+ // We can't listen to onHeadersReceived in Safari so we need to
+ // check for notifications here
+ if (platform != "chromium" && type == "sub_frame")
{
- recordFrame(tab, frameId, parentFrameId, url);
-
- if (type == "main_frame")
- return true;
-
- type = "subdocument";
- frameId = parentFrameId;
+ var notificationToShow = Notification.getNextToShow(url);
+ if (notificationToShow)
+ showNotification(notificationToShow);
}
- var filter = checkRequest(type.toUpperCase(), tab, url, frameId);
- FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, tab);
+ FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page);
return !(filter instanceof BlockingFilter);
}
-function recordFrame(tab, frameId, parentFrameId, url)
-{
- var framesOfTab = frames.get(tab);
+ext.webRequest.onBeforeRequest.addListener(onBeforeRequest);
- if (!framesOfTab)
- frames.set(tab, (framesOfTab = {}));
-
- framesOfTab[frameId] = {url: url, parent: parentFrameId};
-}
-
-function getFrameData(tab, frameId)
-{
- var framesOfTab = frames.get(tab);
-
- if (framesOfTab)
- {
- if (frameId in framesOfTab)
- return framesOfTab[frameId];
-
- // We don't know anything about javascript: or data: frames, use top frame
- if (frameId != -1)
- return framesOfTab[0];
- }
-}
-
-function getFrameUrl(tab, frameId)
-{
- var frameData = getFrameData(tab, frameId);
- return (frameData ? frameData.url : null);
-}
-
-function checkRequest(type, tab, url, frameId)
-{
- if (isFrameWhitelisted(tab, frameId))
- return false;
-
- var documentUrl = getFrameUrl(tab, frameId);
- if (!documentUrl)
- return false;
-
- var requestHost = extractHostFromURL(url);
- var documentHost = extractHostFromURL(documentUrl);
- var thirdParty = isThirdParty(requestHost, documentHost);
- return defaultMatcher.matchesAny(url, type, documentHost, thirdParty);
-}
-
-function isFrameWhitelisted(tab, frameId, type)
-{
- var parent = frameId;
- var parentData = getFrameData(tab, parent);
- while (parentData)
- {
- var frame = parent;
- var frameData = parentData;
-
- parent = frameData.parent;
- parentData = getFrameData(tab, parent);
-
- var frameUrl = frameData.url;
- var parentUrl = (parentData ? parentData.url : frameUrl);
- if ("keyException" in frameData || isWhitelisted(frameUrl, parentUrl, type))
- return true;
- }
- return false;
-}
-
-ext.webRequest.onBeforeRequest.addListener(onBeforeRequest, ["http://*/*", "https://*/*"]);
-
-if (require("info").platform == "chromium")
+if (platform == "chromium")
{
function onHeadersReceived(details)
{
if (details.tabId == -1)
return;
- var type = details.type;
- if (type != "main_frame" && type != "sub_frame")
+ if (details.type != "main_frame" && details.type != "sub_frame")
return;
- var tab = new Tab({id: details.tabId});
- var url = getFrameUrl(tab, details.frameId);
- if (url != details.url)
+ var page = new ext.Page({id: details.tabId});
+ var frame = ext.getFrame(details.tabId, details.frameId);
+
+ if (!frame || frame.url != details.url)
return;
- var key = null;
- var signature = null;
for (var i = 0; i < details.responseHeaders.length; i++)
{
var header = details.responseHeaders[i];
if (header.name.toLowerCase() == "x-adblock-key" && header.value)
- {
- var index = header.value.indexOf("_");
- if (index >= 0)
- {
- key = header.value.substr(0, index);
- signature = header.value.substr(index + 1);
- break;
- }
- }
+ processKeyException(header.value, page, frame);
}
- if (!key)
- return;
- var parentUrl = null;
- if (type == "sub_frame")
- parentUrl = getFrameUrl(tab, details.parentFrameId);
- if (!parentUrl)
- parentUrl = url;
- var docDomain = extractHostFromURL(parentUrl);
- var keyMatch = defaultMatcher.matchesByKey(url, key.replace(/=/g, ""), docDomain);
- if (keyMatch)
- {
- // Website specifies a key that we know but is the signature valid?
- var uri = new URI(url);
- var host = uri.asciiHost;
- if (uri.port > 0)
- host += ":" + uri.port;
-
- var params = [
- uri.path.replace(/#.*/, ""), // REQUEST_URI
- host, // HTTP_HOST
- window.navigator.userAgent // HTTP_USER_AGENT
- ];
- if (verifySignature(key, signature, params.join("\0")))
- frames.get(tab)[details.frameId].keyException = true;
- }
+ var notificationToShow = Notification.getNextToShow(details.url);
+ if (notificationToShow)
+ showNotification(notificationToShow);
}
- chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["http://*/*", "https://*/*"]}, ["responseHeaders"]);
+ chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["<all_urls>"]}, ["responseHeaders"]);
}
« no previous file with comments | « stats.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld