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

Side by Side Diff: background.js

Issue 6393086494113792: Issue 154 - Added devtools panel showing blocked and blockable items (Closed)
Patch Set: Rebased and refactored Created Jan. 28, 2016, 8:19 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 | chrome/devtools.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 var ElemHide = require("elemHide").ElemHide; 46 var ElemHide = require("elemHide").ElemHide;
47 var defaultMatcher = require("matcher").defaultMatcher; 47 var defaultMatcher = require("matcher").defaultMatcher;
48 var Prefs = require("prefs").Prefs; 48 var Prefs = require("prefs").Prefs;
49 var Synchronizer = require("synchronizer").Synchronizer; 49 var Synchronizer = require("synchronizer").Synchronizer;
50 var Utils = require("utils").Utils; 50 var Utils = require("utils").Utils;
51 var parseFilters = require("filterValidation").parseFilters; 51 var parseFilters = require("filterValidation").parseFilters;
52 var composeFilters = require("filterComposer").composeFilters; 52 var composeFilters = require("filterComposer").composeFilters;
53 var updateIcon = require("icon").updateIcon; 53 var updateIcon = require("icon").updateIcon;
54 var initNotifications = require("notificationHelper").initNotifications; 54 var initNotifications = require("notificationHelper").initNotifications;
55 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat ionForUrl; 55 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat ionForUrl;
56 var devtools = require("devtools");
56 57
57 var seenDataCorruption = false; 58 var seenDataCorruption = false;
58 var filterlistsReinitialized = false; 59 var filterlistsReinitialized = false;
59 60
60 function init() 61 function init()
61 { 62 {
62 var filtersLoaded = new Promise(function(resolve) 63 var filtersLoaded = new Promise(function(resolve)
63 { 64 {
64 function onFilterAction(action) 65 function onFilterAction(action)
65 { 66 {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 279
279 return {filters: filters, exceptions: exceptions}; 280 return {filters: filters, exceptions: exceptions};
280 } 281 }
281 282
282 ext.onMessage.addListener(function (msg, sender, sendResponse) 283 ext.onMessage.addListener(function (msg, sender, sendResponse)
283 { 284 {
284 switch (msg.type) 285 switch (msg.type)
285 { 286 {
286 case "get-selectors": 287 case "get-selectors":
287 var selectors = []; 288 var selectors = [];
289 var trace = devtools && devtools.hasPanel(sender.page);
288 290
289 if (!isFrameWhitelisted(sender.page, sender.frame, 291 if (!isFrameWhitelisted(sender.page, sender.frame,
290 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeM ap.ELEMHIDE)) 292 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeM ap.ELEMHIDE))
291 { 293 {
292 var noStyleRules = false; 294 var noStyleRules = false;
293 var specificOnly = isFrameWhitelisted(sender.page, sender.frame, 295 var specificOnly = isFrameWhitelisted(sender.page, sender.frame,
294 RegExpFilter.typeMap.GENERICHIDE); 296 RegExpFilter.typeMap.GENERICHIDE);
295 var host = extractHostFromFrame(sender.frame); 297 var host = extractHostFromFrame(sender.frame);
296 298
297 for (var i = 0; i < noStyleRulesHosts.length; i++) 299 for (var i = 0; i < noStyleRulesHosts.length; i++)
298 { 300 {
299 var noStyleHost = noStyleRulesHosts[i]; 301 var noStyleHost = noStyleRulesHosts[i];
300 if (host == noStyleHost || (host.length > noStyleHost.length && 302 if (host == noStyleHost || (host.length > noStyleHost.length &&
301 host.substr(host.length - noStyleHost.leng th - 1) == "." + noStyleHost)) 303 host.substr(host.length - noStyleHost.leng th - 1) == "." + noStyleHost))
302 { 304 {
303 noStyleRules = true; 305 noStyleRules = true;
304 } 306 }
305 } 307 }
306 selectors = ElemHide.getSelectorsForDomain(host, specificOnly); 308 selectors = ElemHide.getSelectorsForDomain(host, specificOnly);
307 if (noStyleRules) 309 if (noStyleRules)
308 { 310 {
309 selectors = selectors.filter(function(s) 311 selectors = selectors.filter(function(s)
310 { 312 {
311 return !/\[style[\^\$]?=/.test(s); 313 return !/\[style[\^\$]?=/.test(s);
312 }); 314 });
313 } 315 }
314 } 316 }
315 317
316 sendResponse(selectors); 318 sendResponse({selectors: selectors, trace: trace});
317 break; 319 break;
318 case "should-collapse": 320 case "should-collapse":
319 if (isFrameWhitelisted(sender.page, sender.frame, RegExpFilter.typeMap.DOC UMENT)) 321 if (isFrameWhitelisted(sender.page, sender.frame, RegExpFilter.typeMap.DOC UMENT))
320 { 322 {
321 sendResponse(false); 323 sendResponse(false);
322 break; 324 break;
323 } 325 }
324 326
325 var typeMask = RegExpFilter.typeMap[msg.mediatype]; 327 var typeMask = RegExpFilter.typeMap[msg.mediatype];
326 var documentHost = extractHostFromFrame(sender.frame); 328 var documentHost = extractHostFromFrame(sender.frame);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 src: msg.src, 388 src: msg.src,
387 style: msg.style, 389 style: msg.style,
388 classes: msg.classes, 390 classes: msg.classes,
389 urls: msg.urls, 391 urls: msg.urls,
390 type: msg.mediatype, 392 type: msg.mediatype,
391 baseURL: msg.baseURL, 393 baseURL: msg.baseURL,
392 page: sender.page, 394 page: sender.page,
393 frame: sender.frame 395 frame: sender.frame
394 })); 396 }));
395 break; 397 break;
398 case "trace-elemhide":
399 devtools.logHiddenElements(sender.page, msg.selectors, extractHostFromFram e(sender.frame));
400 break;
396 case "forward": 401 case "forward":
397 if (sender.page) 402 if (sender.page)
398 { 403 {
399 if (msg.expectsResponse) 404 if (msg.expectsResponse)
400 { 405 {
401 sender.page.sendMessage(msg.payload, sendResponse); 406 sender.page.sendMessage(msg.payload, sendResponse);
402 return true; 407 return true;
403 } 408 }
404 409
405 sender.page.sendMessage(msg.payload); 410 sender.page.sendMessage(msg.payload);
406 } 411 }
407 break; 412 break;
408 } 413 }
409 }); 414 });
410 415
411 // update icon when page changes location 416 // update icon when page changes location
412 ext.pages.onLoading.addListener(function(page) 417 ext.pages.onLoading.addListener(function(page)
413 { 418 {
414 page.sendMessage({type: "clickhide-deactivate"}); 419 page.sendMessage({type: "clickhide-deactivate"});
415 refreshIconAndContextMenu(page); 420 refreshIconAndContextMenu(page);
416 showNextNotificationForUrl(page.url); 421 showNextNotificationForUrl(page.url);
417 }); 422 });
OLDNEW
« no previous file with comments | « no previous file | chrome/devtools.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld