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

Unified Diff: include.preload.js

Issue 8722030: Topic 11337 - Generalized placeholder blocking approach to cover image buttons and HTML5 media (Closed)
Patch Set: Created Oct. 31, 2012, 1:28 p.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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.preload.js
===================================================================
--- a/include.preload.js
+++ b/include.preload.js
@@ -48,48 +48,56 @@ function setElemhideCSSRules(selectors)
{
var selector = selectors.slice(i, i + SELECTOR_GROUP_SIZE).join(", ");
elt.sheet.insertRule(selector + " { display: none !important; }", j);
}
}
setRules();
}
+var typeMap = {
+ "img": "IMAGE",
+ "input": "IMAGE",
+ "audio": "MEDIA",
+ "video": "MEDIA",
+ "iframe": "SUBDOCUMENT"
+};
+
function checkCollapse(event)
{
var target = event.target;
- if ((event.type == "error" && target instanceof HTMLImageElement) ||
- (event.type == "load" && target instanceof HTMLIFrameElement))
+ var tag = target.localName;
+ if (tag in typeMap && event.type == (tag == "iframe" ? "load" : "error"))
{
// This element failed loading, did we block it?
var url = target.src;
if (!url)
return;
- var type = (target instanceof HTMLImageElement ? "IMAGE": "SUBDOCUMENT");
+ var type = typeMap[tag];
chrome.extension.sendRequest({reqtype: "should-collapse", url: url, documentUrl: document.URL, type: type}, function(response)
{
if (response && target.parentNode)
target.parentNode.removeChild(target);
});
}
}
-function sendRequests()
+function init()
{
// Make sure this is really an HTML page, as Chrome runs these scripts on just about everything
if (!(document.documentElement instanceof HTMLElement))
return;
+ document.addEventListener("error", checkCollapse, true);
+ document.addEventListener("load", checkCollapse, true);
+
chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameUrl: window.location.href}, function(response)
{
setElemhideCSSRules(response.selectors);
});
}
-document.addEventListener("error", checkCollapse, true);
-document.addEventListener("load", checkCollapse, true);
-
// In Chrome 18 the document might not be initialized yet
if (document.documentElement)
- sendRequests();
+ init();
else
- window.setTimeout(sendRequests, 0);
+ window.setTimeout(init, 0);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld