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: 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:
View unified diff | Download patch
« no previous file with comments | « no previous file | block.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 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 ext.windows.create({
288 url: ext.getURL("block.html"),
289 left: 50,
290 top: 50,
291 width: 420,
292 height: 200,
293 focused: true,
294 type: "popup"
295 },
296 function (popupPage) {
297 var popupPageId = popupPage.id;
298 function onRemoved(removedPageId)
299 {
300 if (popupPageId == removedPageId)
301 {
302 sender.page.sendMessage({
303 type: "blockelement-popup-closed",
304 popupId: popupPageId
305 });
306 ext.pages.onRemoved.removeListener(onRemoved);
307 }
308 }
309 ext.pages.onRemoved.addListener(onRemoved);
310
311 sendResponse(popupPageId);
312 });
313 return true;
314 break;
286 case "get-selectors": 315 case "get-selectors":
287 var selectors = []; 316 var selectors = [];
288 var trace = devtools && devtools.hasPanel(sender.page); 317 var trace = devtools && devtools.hasPanel(sender.page);
289 318
290 if (!checkWhitelisted(sender.page, sender.frame, 319 if (!checkWhitelisted(sender.page, sender.frame,
291 RegExpFilter.typeMap.DOCUMENT | 320 RegExpFilter.typeMap.DOCUMENT |
292 RegExpFilter.typeMap.ELEMHIDE)) 321 RegExpFilter.typeMap.ELEMHIDE))
293 { 322 {
294 var noStyleRules = false; 323 var noStyleRules = false;
295 var specificOnly = checkWhitelisted(sender.page, sender.frame, 324 var specificOnly = checkWhitelisted(sender.page, sender.frame,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 frame: sender.frame 430 frame: sender.frame
402 })); 431 }));
403 break; 432 break;
404 case "trace-elemhide": 433 case "trace-elemhide":
405 devtools.logHiddenElements( 434 devtools.logHiddenElements(
406 sender.page, msg.selectors, 435 sender.page, msg.selectors,
407 extractHostFromFrame(sender.frame) 436 extractHostFromFrame(sender.frame)
408 ); 437 );
409 break; 438 break;
410 case "forward": 439 case "forward":
411 if (sender.page) 440 var targetPage;
441 if (msg.targetPageId)
442 targetPage = ext.getPage(msg.targetPageId);
443 else
444 targetPage = sender.page;
445
446 if (targetPage)
412 { 447 {
448 msg.payload.sender = sender.page.id;
413 if (msg.expectsResponse) 449 if (msg.expectsResponse)
414 { 450 {
415 sender.page.sendMessage(msg.payload, sendResponse); 451 targetPage.sendMessage(msg.payload, sendResponse);
416 return true; 452 return true;
417 } 453 }
418 454
419 sender.page.sendMessage(msg.payload); 455 targetPage.sendMessage(msg.payload);
420 } 456 }
421 break; 457 break;
422 } 458 }
423 }); 459 });
424 460
425 // update icon when page changes location 461 // update icon when page changes location
426 ext.pages.onLoading.addListener(function(page) 462 ext.pages.onLoading.addListener(function(page)
427 { 463 {
428 page.sendMessage({type: "clickhide-deactivate"}); 464 page.sendMessage({type: "blockelement-finished"});
429 refreshIconAndContextMenu(page); 465 refreshIconAndContextMenu(page);
430 showNextNotificationForUrl(page.url); 466 showNextNotificationForUrl(page.url);
431 }); 467 });
OLDNEW
« no previous file with comments | « no previous file | block.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld