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

Delta Between Two Patch Sets: background.js

Issue 29336084: Issue 2426 - Open block.html as a popup window (Closed)
Left Patch Set: Addressed some initial feedback Created Feb. 10, 2016, 2:18 p.m.
Right Patch Set: Assume createData parameter has been given Created Feb. 17, 2016, 8:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | block.html » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 277 }
278 278
279 return {filters: filters, exceptions: exceptions}; 279 return {filters: filters, exceptions: exceptions};
280 } 280 }
281 281
282 ext.onMessage.addListener(function (msg, sender, sendResponse) 282 ext.onMessage.addListener(function (msg, sender, sendResponse)
283 { 283 {
284 switch (msg.type) 284 switch (msg.type)
285 { 285 {
286 case "blockelement-open-popup": 286 case "blockelement-open-popup":
287 var url = ext.getURL("block.html") + "?targetPageId=" + sender.page.id +
288 "&filters=" + encodeURIComponent(JSON.stringify(msg.filters));
289 ext.windows.create({ 287 ext.windows.create({
290 url: url, 288 url: ext.getURL("block.html"),
291 left: 50, 289 left: 50,
292 top: 50, 290 top: 50,
293 width: 420, 291 width: 420,
294 height: 200, 292 height: 200,
295 focused: true, 293 focused: true,
296 type: "popup" 294 type: "popup"
297 }, 295 },
298 function (popupPage) { 296 function (popupPage) {
299 var popupPageId = popupPage.id; 297 var popupPageId = popupPage.id;
300 function onRemoved(removedPageId) 298 function onRemoved(removedPageId)
301 { 299 {
302 if (popupPageId == removedPageId) 300 if (popupPageId == removedPageId)
303 { 301 {
304 sender.page.sendMessage({ 302 sender.page.sendMessage({
305 type: "blockelement-popup-closed", 303 type: "blockelement-popup-closed",
306 popupId: popupPageId 304 popupId: popupPageId
307 }); 305 });
308 ext.pages.onRemoved.removeListener(onRemoved); 306 ext.pages.onRemoved.removeListener(onRemoved);
309 } 307 }
310 } 308 }
311 ext.pages.onRemoved.addListener(onRemoved); 309 ext.pages.onRemoved.addListener(onRemoved);
312 310
313 sender.page.sendMessage({ 311 sendResponse(popupPageId);
314 type: "blockelement-popup-opened",
315 popupId: popupPageId
316 });
317 }); 312 });
313 return true;
318 break; 314 break;
319 case "get-selectors": 315 case "get-selectors":
320 var selectors = []; 316 var selectors = [];
321 var trace = devtools && devtools.hasPanel(sender.page); 317 var trace = devtools && devtools.hasPanel(sender.page);
322 318
323 if (!checkWhitelisted(sender.page, sender.frame, 319 if (!checkWhitelisted(sender.page, sender.frame,
324 RegExpFilter.typeMap.DOCUMENT | 320 RegExpFilter.typeMap.DOCUMENT |
325 RegExpFilter.typeMap.ELEMHIDE)) 321 RegExpFilter.typeMap.ELEMHIDE))
326 { 322 {
327 var noStyleRules = false; 323 var noStyleRules = false;
(...skipping 27 matching lines...) Expand all
355 { 351 {
356 sendResponse(false); 352 sendResponse(false);
357 break; 353 break;
358 } 354 }
359 355
360 var typeMask = RegExpFilter.typeMap[msg.mediatype]; 356 var typeMask = RegExpFilter.typeMap[msg.mediatype];
361 var documentHost = extractHostFromFrame(sender.frame); 357 var documentHost = extractHostFromFrame(sender.frame);
362 var sitekey = getKey(sender.page, sender.frame); 358 var sitekey = getKey(sender.page, sender.frame);
363 var blocked = false; 359 var blocked = false;
364 360
361 var specificOnly = checkWhitelisted(
362 sender.page, sender.frame,
363 RegExpFilter.typeMap.GENERICBLOCK
364 );
365
365 for (var i = 0; i < msg.urls.length; i++) 366 for (var i = 0; i < msg.urls.length; i++)
366 { 367 {
367 var url = new URL(msg.urls[i], msg.baseURL); 368 var url = new URL(msg.urls[i], msg.baseURL);
368 var filter = defaultMatcher.matchesAny( 369 var filter = defaultMatcher.matchesAny(
369 stringifyURL(url), typeMask, 370 stringifyURL(url), typeMask,
370 documentHost, isThirdParty(url, documentHost), sitekey 371 documentHost, isThirdParty(url, documentHost),
372 sitekey, specificOnly
371 ); 373 );
372 374
373 if (filter instanceof BlockingFilter) 375 if (filter instanceof BlockingFilter)
374 { 376 {
375 if (filter.collapse != null) 377 if (filter.collapse != null)
376 { 378 {
377 sendResponse(filter.collapse); 379 sendResponse(filter.collapse);
378 return; 380 return;
379 } 381 }
380 382
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 break; 438 break;
437 case "forward": 439 case "forward":
438 var targetPage; 440 var targetPage;
439 if (msg.targetPageId) 441 if (msg.targetPageId)
440 targetPage = ext.getPage(msg.targetPageId); 442 targetPage = ext.getPage(msg.targetPageId);
441 else 443 else
442 targetPage = sender.page; 444 targetPage = sender.page;
443 445
444 if (targetPage) 446 if (targetPage)
445 { 447 {
448 msg.payload.sender = sender.page.id;
446 if (msg.expectsResponse) 449 if (msg.expectsResponse)
447 { 450 {
448 targetPage.sendMessage(msg.payload, sendResponse); 451 targetPage.sendMessage(msg.payload, sendResponse);
449 return true; 452 return true;
450 } 453 }
451 454
452 targetPage.sendMessage(msg.payload); 455 targetPage.sendMessage(msg.payload);
453 } 456 }
454 break; 457 break;
455 } 458 }
456 }); 459 });
457 460
458 // update icon when page changes location 461 // update icon when page changes location
459 ext.pages.onLoading.addListener(function(page) 462 ext.pages.onLoading.addListener(function(page)
460 { 463 {
461 page.sendMessage({type: "blockelement-finished"}); 464 page.sendMessage({type: "blockelement-finished"});
462 refreshIconAndContextMenu(page); 465 refreshIconAndContextMenu(page);
463 showNextNotificationForUrl(page.url); 466 showNextNotificationForUrl(page.url);
464 }); 467 });
LEFTRIGHT
« no previous file | block.html » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld