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

Side by Side Diff: chrome/ext/background.js

Issue 5693109165883392: Issue 2040 - Replaced localStorage with chrome.storage.local (Closed)
Patch Set: Rebased Created March 3, 2015, 3:11 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
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 }); 492 });
493 493
494 // We have to ensure there is at least one listener for the onConnect event. 494 // We have to ensure there is at least one listener for the onConnect event.
495 // Otherwise we can't connect a port later, which we need to do in order to 495 // Otherwise we can't connect a port later, which we need to do in order to
496 // detect when the extension is reloaded, disabled or uninstalled. 496 // detect when the extension is reloaded, disabled or uninstalled.
497 chrome.runtime.onConnect.addListener(function() {}); 497 chrome.runtime.onConnect.addListener(function() {});
498 498
499 499
500 /* Storage */ 500 /* Storage */
501 501
502 ext.storage = localStorage; 502 ext.storage = {
503 get: function(keys, callback)
504 {
505 chrome.storage.local.get(keys, callback);
506 },
507 set: function(key, value, callback)
508 {
509 let items = {};
510 items[key] = value;
511 chrome.storage.local.set(items, callback);
512 },
513 remove: function(key, callback)
514 {
515 chrome.storage.local.remove(key, callback);
516 },
517 onChanged: chrome.storage.onChanged,
503 518
519 // Migrate localStorage to chrome.storage.local,
520 // ignoring unkown and inavlid preferences.
521 migratePrefs: function(prefs)
522 {
523 var items = {};
524
525 for (let key in localStorage)
526 {
527 var value = localStorage[key];
528
529 if (key in prefs)
530 {
531 try
532 {
533 items["pref:" + key] = JSON.parse(value);
534 }
535 catch (e)
536 {
537 }
538 }
539 else if (key == "currentVersion")
540 {
541 items[key] = value;
542 }
543 }
Sebastian Noack 2015/03/12 23:35:29 Well, where doese code with a different implementa
544
545 chrome.storage.local.set(items, function() {
546 localStorage.clear();
547 });
548 }
549 };
504 550
505 /* Options */ 551 /* Options */
506 552
507 ext.showOptions = function(callback) 553 ext.showOptions = function(callback)
508 { 554 {
509 chrome.windows.getLastFocused(function(win) 555 chrome.windows.getLastFocused(function(win)
510 { 556 {
511 var optionsUrl = chrome.extension.getURL("options.html"); 557 var optionsUrl = chrome.extension.getURL("options.html");
512 var queryInfo = {url: optionsUrl}; 558 var queryInfo = {url: optionsUrl};
513 559
(...skipping 16 matching lines...) Expand all
530 callback(new Page(tab)); 576 callback(new Page(tab));
531 } 577 }
532 else 578 else
533 { 579 {
534 ext.pages.open(optionsUrl, callback); 580 ext.pages.open(optionsUrl, callback);
535 } 581 }
536 }); 582 });
537 }); 583 });
538 }; 584 };
539 })(); 585 })();
OLDNEW
« no previous file with comments | « background.js ('k') | include.postload.js » ('j') | safari/ext/background.js » ('J')

Powered by Google App Engine
This is Rietveld