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

Side by Side Diff: background.js

Issue 8354161: Align whitelisting behavior in Chrome with Firefox (Closed)
Patch Set: Created Sept. 17, 2012, 2:52 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include.preload.js » ('j') | webrequest.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 importAll("filterClasses", this); 1 importAll("filterClasses", this);
2 importAll("subscriptionClasses", this); 2 importAll("subscriptionClasses", this);
3 importAll("filterStorage", this); 3 importAll("filterStorage", this);
4 importAll("elemHide", this); 4 importAll("elemHide", this);
5 importAll("filterListener", this); 5 importAll("filterListener", this);
6 importAll("filterNotifier", this); 6 importAll("filterNotifier", this);
7 importAll("matcher", this); 7 importAll("matcher", this);
8 importAll("synchronizer", this); 8 importAll("synchronizer", this);
9 9
10 // Some types cannot be distinguished 10 // Some types cannot be distinguished
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
49 // Upgrade options before we do anything else. 49 // Upgrade options before we do anything else.
50 setDefaultOptions(); 50 setDefaultOptions();
51 51
52 /** 52 /**
53 * Checks whether a page is whitelisted. 53 * Checks whether a page is whitelisted.
54 * @param url {String} 54 * @param url {String}
55 * @return {Filter} filter that matched the URL or null if not whitelisted 55 * @return {Filter} filter that matched the URL or null if not whitelisted
56 */ 56 */
57 function isWhitelisted(url) 57 function isWhitelisted(url, type)
Felix Dahlke 2012/09/18 13:23:14 The new type parameter isn't documented above.
58 { 58 {
59 // Ignore fragment identifier 59 // Ignore fragment identifier
60 var index = url.indexOf("#"); 60 var index = url.indexOf("#");
61 if (index >= 0) 61 if (index >= 0)
62 url = url.substring(0, index); 62 url = url.substring(0, index);
63 63
64 var result = defaultMatcher.matchesAny(url, "DOCUMENT", extractHostFromURL(url ), false); 64 var result = defaultMatcher.matchesAny(url, type || "DOCUMENT", extractHostFro mURL(url), false);
65 return (result instanceof WhitelistFilter ? result : null); 65 return (result instanceof WhitelistFilter ? result : null);
66 } 66 }
67 67
68 // Adds or removes page action icon according to options. 68 // Adds or removes page action icon according to options.
69 function refreshIconAndContextMenu(tab) 69 function refreshIconAndContextMenu(tab)
70 { 70 {
71 // The tab could have been closed by the time this function is called 71 // The tab could have been closed by the time this function is called
72 if(!tab) 72 if(!tab)
73 return; 73 return;
74 74
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 }); 349 });
350 } 350 }
351 351
352 chrome.extension.onRequest.addListener(function(request, sender, sendResponse) 352 chrome.extension.onRequest.addListener(function(request, sender, sendResponse)
353 { 353 {
354 switch (request.reqtype) 354 switch (request.reqtype)
355 { 355 {
356 case "get-settings": 356 case "get-settings":
357 var hostDomain = null; 357 var hostDomain = null;
358 var selectors = null; 358 var selectors = null;
359 var enabled = sender.tab ? !isWhitelisted(sender.tab.url) : true; 359
360 // HACK: We don't know which frame sent us the message, try to find it
361 // in webRequest's frame data.
362 var tabId = -1;
363 var frameId = -1;
364 if (sender.tab)
365 {
366 var tabId = sender.tab.id;
Felix Dahlke 2012/09/18 13:23:14 You're redeclaring tabId here.
367 if (tabId in frames)
Felix Dahlke 2012/09/18 13:23:14 I don't think this statement is necessary here. Th
Wladimir Palant 2012/09/18 15:12:11 Yes, I don't usually rely on this and generally av
368 {
369 for (var f in frames[tabId])
370 {
371 if (getFrameUrl(tabId, f) == request.frameUrl)
372 {
373 frameId = f;
374 break;
375 }
376 }
377 }
378 }
379
380 var enabled = !isFrameWhitelisted(tabId, frameId, "DOCUMENT") && !isFrameW hitelisted(tabId, frameId, "ELEMHIDE");
360 if (enabled && request.selectors) 381 if (enabled && request.selectors)
361 { 382 {
362 var noStyleRules = false; 383 var noStyleRules = false;
363 var host = request.host; 384 var host = extractHostFromURL(request.frameUrl);
385 hostDomain = getBaseDomain(host);
364 for (var i = 0; i < noStyleRulesHosts.length; i++) 386 for (var i = 0; i < noStyleRulesHosts.length; i++)
365 { 387 {
366 var noStyleHost = noStyleRulesHosts[i]; 388 var noStyleHost = noStyleRulesHosts[i];
367 if (host == noStyleHost || (host.length > noStyleHost.length && 389 if (host == noStyleHost || (host.length > noStyleHost.length &&
368 host.substr(host.length - noStyleHost.leng th - 1) == "." + noStyleHost)) 390 host.substr(host.length - noStyleHost.leng th - 1) == "." + noStyleHost))
369 { 391 {
370 noStyleRules = true; 392 noStyleRules = true;
371 } 393 }
372 } 394 }
373 selectors = ElemHide.getSelectorsForDomain(host, false); 395 selectors = ElemHide.getSelectorsForDomain(host, false);
374 if (noStyleRules) 396 if (noStyleRules)
375 { 397 {
376 selectors = selectors.filter(function(s) 398 selectors = selectors.filter(function(s)
377 { 399 {
378 return !/\[style[\^\$]?=/.test(s); 400 return !/\[style[\^\$]?=/.test(s);
379 }); 401 });
380 } 402 }
381 } 403 }
382 if (enabled) 404
383 hostDomain = getBaseDomain(request.host);
384 sendResponse({enabled: enabled, hostDomain: hostDomain, selectors: selecto rs}); 405 sendResponse({enabled: enabled, hostDomain: hostDomain, selectors: selecto rs});
385 break; 406 break;
386 case "get-domain-enabled-state": 407 case "get-domain-enabled-state":
387 // Returns whether this domain is in the exclusion list. 408 // Returns whether this domain is in the exclusion list.
388 // The page action popup asks us this. 409 // The page action popup asks us this.
389 if(sender.tab) 410 if(sender.tab)
390 { 411 {
391 sendResponse({enabled: !isWhitelisted(sender.tab.url), specialCaseYouTub e: localStorage["specialCaseYouTube"] == "true", disableInlineTextAds: localStor age["disableInlineTextAds"] == "true"}); 412 sendResponse({enabled: !isWhitelisted(sender.tab.url), specialCaseYouTub e: localStorage["specialCaseYouTube"] == "true", disableInlineTextAds: localStor age["disableInlineTextAds"] == "true"});
392 return; 413 return;
393 } 414 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 refreshIconAndContextMenu(windows[i].tabs[j]); 486 refreshIconAndContextMenu(windows[i].tabs[j]);
466 }); 487 });
467 488
468 // Update icon if a tab changes location 489 // Update icon if a tab changes location
469 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) 490 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
470 { 491 {
471 chrome.tabs.sendRequest(tabId, {reqtype: "clickhide-deactivate"}) 492 chrome.tabs.sendRequest(tabId, {reqtype: "clickhide-deactivate"})
472 if(changeInfo.status == "loading") 493 if(changeInfo.status == "loading")
473 refreshIconAndContextMenu(tab); 494 refreshIconAndContextMenu(tab);
474 }); 495 });
OLDNEW
« no previous file with comments | « no previous file | include.preload.js » ('j') | webrequest.js » ('J')

Powered by Google App Engine
This is Rietveld