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: Open block.html as a popup window Created Feb. 8, 2016, 12:32 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 +
Sebastian Noack 2016/02/10 12:26:56 Alternatively, you could send this data to the pop
kzar 2016/02/10 14:20:16 I think this would work for Chrome but not Safari.
Sebastian Noack 2016/02/10 14:43:24 As I said, we already do so for the options page.
Sebastian Noack 2016/02/12 17:00:00 So what's about that comment?
kzar 2016/02/13 14:18:12 Well I tried it and it didn't work for me. Lookin
Sebastian Noack 2016/02/15 14:50:17 Well, when opening the options page, we look for a
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 });
318 return true; 313 return true;
Sebastian Noack 2016/02/10 12:26:56 By returning true but never calling sendResponse()
kzar 2016/02/10 14:20:16 Done.
319 break; 314 break;
320 case "get-selectors": 315 case "get-selectors":
321 var selectors = []; 316 var selectors = [];
322 var trace = devtools && devtools.hasPanel(sender.page); 317 var trace = devtools && devtools.hasPanel(sender.page);
323 318
324 if (!checkWhitelisted(sender.page, sender.frame, 319 if (!checkWhitelisted(sender.page, sender.frame,
325 RegExpFilter.typeMap.DOCUMENT | 320 RegExpFilter.typeMap.DOCUMENT |
326 RegExpFilter.typeMap.ELEMHIDE)) 321 RegExpFilter.typeMap.ELEMHIDE))
327 { 322 {
328 var noStyleRules = false; 323 var noStyleRules = false;
(...skipping 27 matching lines...) Expand all
356 { 351 {
357 sendResponse(false); 352 sendResponse(false);
358 break; 353 break;
359 } 354 }
360 355
361 var typeMask = RegExpFilter.typeMap[msg.mediatype]; 356 var typeMask = RegExpFilter.typeMap[msg.mediatype];
362 var documentHost = extractHostFromFrame(sender.frame); 357 var documentHost = extractHostFromFrame(sender.frame);
363 var sitekey = getKey(sender.page, sender.frame); 358 var sitekey = getKey(sender.page, sender.frame);
364 var blocked = false; 359 var blocked = false;
365 360
361 var specificOnly = checkWhitelisted(
362 sender.page, sender.frame,
363 RegExpFilter.typeMap.GENERICBLOCK
364 );
365
366 for (var i = 0; i < msg.urls.length; i++) 366 for (var i = 0; i < msg.urls.length; i++)
367 { 367 {
368 var url = new URL(msg.urls[i], msg.baseURL); 368 var url = new URL(msg.urls[i], msg.baseURL);
369 var filter = defaultMatcher.matchesAny( 369 var filter = defaultMatcher.matchesAny(
370 stringifyURL(url), typeMask, 370 stringifyURL(url), typeMask,
371 documentHost, isThirdParty(url, documentHost), sitekey 371 documentHost, isThirdParty(url, documentHost),
372 sitekey, specificOnly
372 ); 373 );
373 374
374 if (filter instanceof BlockingFilter) 375 if (filter instanceof BlockingFilter)
375 { 376 {
376 if (filter.collapse != null) 377 if (filter.collapse != null)
377 { 378 {
378 sendResponse(filter.collapse); 379 sendResponse(filter.collapse);
379 return; 380 return;
380 } 381 }
381 382
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 break; 432 break;
432 case "trace-elemhide": 433 case "trace-elemhide":
433 devtools.logHiddenElements( 434 devtools.logHiddenElements(
434 sender.page, msg.selectors, 435 sender.page, msg.selectors,
435 extractHostFromFrame(sender.frame) 436 extractHostFromFrame(sender.frame)
436 ); 437 );
437 break; 438 break;
438 case "forward": 439 case "forward":
439 var targetPage; 440 var targetPage;
440 if (msg.targetPageId) 441 if (msg.targetPageId)
441 targetPage = ext._getPage(msg.targetPageId); 442 targetPage = ext.getPage(msg.targetPageId);
Sebastian Noack 2016/02/10 12:26:56 I guess it's time, to remove the prefix from ext._
kzar 2016/02/10 14:20:16 Done.
442 else 443 else
443 targetPage = sender.page; 444 targetPage = sender.page;
444 445
445 if (targetPage) 446 if (targetPage)
446 { 447 {
448 msg.payload.sender = sender.page.id;
447 if (msg.expectsResponse) 449 if (msg.expectsResponse)
448 { 450 {
449 targetPage.sendMessage(msg.payload, sendResponse); 451 targetPage.sendMessage(msg.payload, sendResponse);
450 return true; 452 return true;
451 } 453 }
452 454
453 targetPage.sendMessage(msg.payload); 455 targetPage.sendMessage(msg.payload);
454 } 456 }
455 break; 457 break;
456 } 458 }
457 }); 459 });
458 460
459 // update icon when page changes location 461 // update icon when page changes location
460 ext.pages.onLoading.addListener(function(page) 462 ext.pages.onLoading.addListener(function(page)
461 { 463 {
462 page.sendMessage({type: "blockelement-finished"}); 464 page.sendMessage({type: "blockelement-finished"});
463 refreshIconAndContextMenu(page); 465 refreshIconAndContextMenu(page);
464 showNextNotificationForUrl(page.url); 466 showNextNotificationForUrl(page.url);
465 }); 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