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

Side by Side Diff: background.js

Issue 29336084: Issue 2426 - Open block.html as a popup window (Closed)
Patch Set: Open block.html as a popup window Created Feb. 8, 2016, 12:32 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 | block.html » ('j') | chrome/ext/background.js » ('J')
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // See http://crbug.com/68705. 112 // See http://crbug.com/68705.
113 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; 113 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"];
114 114
115 var htmlPages = new ext.PageMap(); 115 var htmlPages = new ext.PageMap();
116 116
117 var contextMenuItem = { 117 var contextMenuItem = {
118 title: ext.i18n.getMessage("block_element"), 118 title: ext.i18n.getMessage("block_element"),
119 contexts: ["image", "video", "audio"], 119 contexts: ["image", "video", "audio"],
120 onclick: function(page) 120 onclick: function(page)
121 { 121 {
122 page.sendMessage({type: "clickhide-new-filter"}); 122 page.sendMessage({type: "blockelement-context-menu-clicked"});
123 } 123 }
124 }; 124 };
125 125
126 // Adds or removes browser action icon according to options. 126 // Adds or removes browser action icon according to options.
127 function refreshIconAndContextMenu(page) 127 function refreshIconAndContextMenu(page)
128 { 128 {
129 var whitelisted = !!checkWhitelisted(page); 129 var whitelisted = !!checkWhitelisted(page);
130 updateIcon(page, whitelisted); 130 updateIcon(page, whitelisted);
131 131
132 // show or hide the context menu entry dependent on whether 132 // show or hide the context menu entry dependent on whether
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 276 }
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":
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({
290 url: url,
291 left: 50,
292 top: 50,
293 width: 420,
294 height: 200,
295 focused: true,
296 type: "popup"
297 },
298 function (popupPage) {
299 var popupPageId = popupPage._id;
300 function onRemoved(removedPageId)
301 {
302 if (popupPageId == removedPageId)
303 {
304 sender.page.sendMessage({
305 type: "blockelement-popup-closed",
306 popupId: popupPageId
307 });
308 ext.pages.onRemoved.removeListener(onRemoved);
309 }
310 }
311 ext.pages.onRemoved.addListener(onRemoved);
312
313 sender.page.sendMessage({
314 type: "blockelement-popup-opened",
315 popupId: popupPageId
316 });
317 });
318 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;
286 case "get-selectors": 320 case "get-selectors":
287 var selectors = []; 321 var selectors = [];
288 var trace = devtools && devtools.hasPanel(sender.page); 322 var trace = devtools && devtools.hasPanel(sender.page);
289 323
290 if (!checkWhitelisted(sender.page, sender.frame, 324 if (!checkWhitelisted(sender.page, sender.frame,
291 RegExpFilter.typeMap.DOCUMENT | 325 RegExpFilter.typeMap.DOCUMENT |
292 RegExpFilter.typeMap.ELEMHIDE)) 326 RegExpFilter.typeMap.ELEMHIDE))
293 { 327 {
294 var noStyleRules = false; 328 var noStyleRules = false;
295 var specificOnly = checkWhitelisted(sender.page, sender.frame, 329 var specificOnly = checkWhitelisted(sender.page, sender.frame,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 frame: sender.frame 429 frame: sender.frame
396 })); 430 }));
397 break; 431 break;
398 case "trace-elemhide": 432 case "trace-elemhide":
399 devtools.logHiddenElements( 433 devtools.logHiddenElements(
400 sender.page, msg.selectors, 434 sender.page, msg.selectors,
401 extractHostFromFrame(sender.frame) 435 extractHostFromFrame(sender.frame)
402 ); 436 );
403 break; 437 break;
404 case "forward": 438 case "forward":
405 if (sender.page) 439 var targetPage;
440 if (msg.targetPageId)
441 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 targetPage = sender.page;
444
445 if (targetPage)
406 { 446 {
407 if (msg.expectsResponse) 447 if (msg.expectsResponse)
408 { 448 {
409 sender.page.sendMessage(msg.payload, sendResponse); 449 targetPage.sendMessage(msg.payload, sendResponse);
410 return true; 450 return true;
411 } 451 }
412 452
413 sender.page.sendMessage(msg.payload); 453 targetPage.sendMessage(msg.payload);
414 } 454 }
415 break; 455 break;
416 } 456 }
417 }); 457 });
418 458
419 // update icon when page changes location 459 // update icon when page changes location
420 ext.pages.onLoading.addListener(function(page) 460 ext.pages.onLoading.addListener(function(page)
421 { 461 {
422 page.sendMessage({type: "clickhide-deactivate"}); 462 page.sendMessage({type: "blockelement-finished"});
423 refreshIconAndContextMenu(page); 463 refreshIconAndContextMenu(page);
424 showNextNotificationForUrl(page.url); 464 showNextNotificationForUrl(page.url);
425 }); 465 });
OLDNEW
« no previous file with comments | « no previous file | block.html » ('j') | chrome/ext/background.js » ('J')

Powered by Google App Engine
This is Rietveld