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

Delta Between Two Patch Sets: chrome/ext/background.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Left Patch Set: Add arrow-parens rule to match existing convention Created March 7, 2017, 10:48 a.m.
Right Patch Set: Use .includes again Created March 31, 2017, 8:37 a.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 | « chrome/devtools.js ('k') | chrome/ext/common.js » ('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-2017 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 (function()
20 { 21 {
21 /* Pages */ 22 /* Pages */
22 23
23 let Page = ext.Page = function(tab) 24 let Page = ext.Page = function(tab)
24 { 25 {
25 this.id = tab.id; 26 this.id = tab.id;
26 this._url = tab.url && new URL(tab.url); 27 this._url = tab.url && new URL(tab.url);
27 28
28 this.browserAction = new BrowserAction(tab.id); 29 this.browserAction = new BrowserAction(tab.id);
29 this.contextMenus = new ContextMenus(this); 30 this.contextMenus = new ContextMenus(this);
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 { 315 {
315 if (addedTabId == this._tabId) 316 if (addedTabId == this._tabId)
316 { 317 {
317 chrome.tabs.onReplaced.removeListener(onReplaced); 318 chrome.tabs.onReplaced.removeListener(onReplaced);
318 this._applyChanges(); 319 this._applyChanges();
319 } 320 }
320 }; 321 };
321 chrome.tabs.onReplaced.addListener(onReplaced); 322 chrome.tabs.onReplaced.addListener(onReplaced);
322 } 323 }
323 else 324 else
325 {
324 this._applyChanges(); 326 this._applyChanges();
327 }
325 }); 328 });
326 }, 329 },
327 _addChange(name, value) 330 _addChange(name, value)
328 { 331 {
329 if (!this._changes) 332 if (!this._changes)
330 { 333 {
331 this._changes = {}; 334 this._changes = {};
332 this._queueChanges(); 335 this._queueChanges();
333 } 336 }
334 337
335 this._changes[name] = value; 338 this._changes[name] = value;
336 }, 339 },
337 setIcon(path) 340 setIcon(path)
338 { 341 {
339 this._addChange("iconPath", path); 342 this._addChange("iconPath", path);
340 }, 343 },
341 setBadge(badge) 344 setBadge(badge)
342 { 345 {
343 if (!badge) 346 if (!badge)
347 {
344 this._addChange("badgeText", ""); 348 this._addChange("badgeText", "");
349 }
345 else 350 else
346 { 351 {
347 if ("number" in badge) 352 if ("number" in badge)
348 this._addChange("badgeText", badge.number.toString()); 353 this._addChange("badgeText", badge.number.toString());
349 354
350 if ("color" in badge) 355 if ("color" in badge)
351 this._addChange("badgeColor", badge.color); 356 this._addChange("badgeColor", badge.color);
352 } 357 }
353 } 358 }
354 }; 359 };
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 let results = ext.webRequest.onBeforeRequest._dispatch( 536 let results = ext.webRequest.onBeforeRequest._dispatch(
532 new URL(details.url), 537 new URL(details.url),
533 type.toUpperCase(), 538 type.toUpperCase(),
534 new Page({id: details.tabId}), 539 new Page({id: details.tabId}),
535 frame 540 frame
536 ); 541 );
537 542
538 if (results.indexOf(false) != -1) 543 if (results.indexOf(false) != -1)
539 return {cancel: true}; 544 return {cancel: true};
540 } 545 }
541 }, {urls: ["http://*/*", "https://*/*"]}, ["blocking"]); 546 }, {urls: ["<all_urls>"]}, ["blocking"]);
542 547
543 548
544 /* Message passing */ 549 /* Message passing */
545 550
546 chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) => 551 chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) =>
547 { 552 {
548 let sender = {}; 553 let sender = {};
549 554
550 // Add "page" and "frame" if the message was sent by a content script. 555 // Add "page" and "frame" if the message was sent by a content script.
551 // If sent by popup or the background page itself, there is no "tab". 556 // If sent by popup or the background page itself, there is no "tab".
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 onChanged: chrome.storage.onChanged 601 onChanged: chrome.storage.onChanged
597 }; 602 };
598 603
599 /* Options */ 604 /* Options */
600 605
601 if ("openOptionsPage" in chrome.runtime) 606 if ("openOptionsPage" in chrome.runtime)
602 { 607 {
603 ext.showOptions = callback => 608 ext.showOptions = callback =>
604 { 609 {
605 if (!callback) 610 if (!callback)
611 {
606 chrome.runtime.openOptionsPage(); 612 chrome.runtime.openOptionsPage();
613 }
607 else 614 else
608 { 615 {
609 chrome.runtime.openOptionsPage(() => 616 chrome.runtime.openOptionsPage(() =>
610 { 617 {
611 if (chrome.runtime.lastError) 618 if (chrome.runtime.lastError)
612 return; 619 return;
613 620
614 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => 621 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
615 { 622 {
616 if (tabs.length > 0) 623 if (tabs.length > 0)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 { 655 {
649 let tab = tabs[0]; 656 let tab = tabs[0];
650 657
651 chrome.windows.update(tab.windowId, {focused: true}); 658 chrome.windows.update(tab.windowId, {focused: true});
652 chrome.tabs.update(tab.id, {active: true}); 659 chrome.tabs.update(tab.id, {active: true});
653 660
654 if (callback) 661 if (callback)
655 callback(new Page(tab)); 662 callback(new Page(tab));
656 } 663 }
657 else 664 else
665 {
658 ext.pages.open(optionsUrl, callback); 666 ext.pages.open(optionsUrl, callback);
667 }
659 }); 668 });
660 }); 669 });
661 }; 670 };
662 } 671 }
663 672
664 /* Windows */ 673 /* Windows */
665 ext.windows = { 674 ext.windows = {
666 create(createData, callback) 675 create(createData, callback)
667 { 676 {
668 chrome.windows.create(createData, createdWindow => 677 chrome.windows.create(createData, createdWindow =>
669 { 678 {
670 afterTabLoaded(callback)(createdWindow.tabs[0]); 679 afterTabLoaded(callback)(createdWindow.tabs[0]);
671 }); 680 });
672 } 681 }
673 }; 682 };
674 } 683 }());
LEFTRIGHT

Powered by Google App Engine
This is Rietveld