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: Pass tab directly instead of getTab callback Created Feb. 11, 2016, 3: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 | 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 +
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 break;
286 case "get-selectors": 319 case "get-selectors":
287 var selectors = []; 320 var selectors = [];
288 var trace = devtools && devtools.hasPanel(sender.page); 321 var trace = devtools && devtools.hasPanel(sender.page);
289 322
290 if (!checkWhitelisted(sender.page, sender.frame, 323 if (!checkWhitelisted(sender.page, sender.frame,
291 RegExpFilter.typeMap.DOCUMENT | 324 RegExpFilter.typeMap.DOCUMENT |
292 RegExpFilter.typeMap.ELEMHIDE)) 325 RegExpFilter.typeMap.ELEMHIDE))
293 { 326 {
294 var noStyleRules = false; 327 var noStyleRules = false;
295 var specificOnly = checkWhitelisted(sender.page, sender.frame, 328 var specificOnly = checkWhitelisted(sender.page, sender.frame,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 frame: sender.frame 428 frame: sender.frame
396 })); 429 }));
397 break; 430 break;
398 case "trace-elemhide": 431 case "trace-elemhide":
399 devtools.logHiddenElements( 432 devtools.logHiddenElements(
400 sender.page, msg.selectors, 433 sender.page, msg.selectors,
401 extractHostFromFrame(sender.frame) 434 extractHostFromFrame(sender.frame)
402 ); 435 );
403 break; 436 break;
404 case "forward": 437 case "forward":
405 if (sender.page) 438 var targetPage;
439 if (msg.targetPageId)
440 targetPage = ext.getPage(msg.targetPageId);
441 else
442 targetPage = sender.page;
443
444 if (targetPage)
406 { 445 {
407 if (msg.expectsResponse) 446 if (msg.expectsResponse)
408 { 447 {
409 sender.page.sendMessage(msg.payload, sendResponse); 448 targetPage.sendMessage(msg.payload, sendResponse);
410 return true; 449 return true;
411 } 450 }
412 451
413 sender.page.sendMessage(msg.payload); 452 targetPage.sendMessage(msg.payload);
414 } 453 }
415 break; 454 break;
416 } 455 }
417 }); 456 });
418 457
419 // update icon when page changes location 458 // update icon when page changes location
420 ext.pages.onLoading.addListener(function(page) 459 ext.pages.onLoading.addListener(function(page)
421 { 460 {
422 page.sendMessage({type: "clickhide-deactivate"}); 461 page.sendMessage({type: "blockelement-finished"});
423 refreshIconAndContextMenu(page); 462 refreshIconAndContextMenu(page);
424 showNextNotificationForUrl(page.url); 463 showNextNotificationForUrl(page.url);
425 }); 464 });
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