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

Side by Side Diff: adblockplus/Api.jsm

Issue 4920541991403520: Create a minimal settings UI (Closed)
Patch Set: Added missing slashes Created March 21, 2015, 1:52 a.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 | mobile/android/base/moz.build » ('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-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
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 var EXPORTED_SYMBOLS = ["AdblockPlusApi"]; 18 var EXPORTED_SYMBOLS = ["AdblockPlusApi"];
19 19
20 const Cc = Components.classes; 20 const Cc = Components.classes;
21 const Ci = Components.interfaces; 21 const Ci = Components.interfaces;
22 const Cr = Components.results; 22 const Cr = Components.results;
23 const Cu = Components.utils; 23 const Cu = Components.utils;
24 24
25 Cu.import("resource://gre/modules/Services.jsm"); 25 Cu.import("resource://gre/modules/Services.jsm");
26 Cu.import("resource://gre/modules/Messaging.jsm");
26 27
27 function require(module) 28 function require(module)
28 { 29 {
29 let result = {}; 30 let result = {};
30 result.wrappedJSObject = result; 31 result.wrappedJSObject = result;
31 Services.obs.notifyObservers(result, "adblockplus-require", module); 32 Services.obs.notifyObservers(result, "adblockplus-require", module);
32 return result.exports; 33 return result.exports;
33 } 34 }
34 35
36 let {FilterNotifier} = require("filterNotifier");
35 let {FilterStorage} = require("filterStorage"); 37 let {FilterStorage} = require("filterStorage");
36 let {Prefs} = require("prefs"); 38 let {Prefs} = require("prefs");
37 let {UI} = require("ui"); 39 let {UI} = require("ui");
38 40
41 let {FilterNotifier} = require("filterNotifier");
42
39 var AdblockPlusApi = 43 var AdblockPlusApi =
40 { 44 {
45 get filtersLoaded()
46 {
47 return filtersLoaded;
48 },
41 get acceptableAdsEnabled() 49 get acceptableAdsEnabled()
42 { 50 {
43 return FilterStorage.subscriptions.some( 51 return FilterStorage.subscriptions.some(
44 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl); 52 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl);
45 }, 53 },
46 set acceptableAdsEnabled(acceptableAdsEnabled) 54 set acceptableAdsEnabled(acceptableAdsEnabled)
47 { 55 {
48 if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled) 56 if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled)
49 UI.toggleAcceptableAds(); 57 UI.toggleAcceptableAds();
50 } 58 }
51 }; 59 };
60
61
62 FilterNotifier.addListener(function filterListener(action)
63 {
64 if (action != "load")
65 return;
66
67 filtersLoaded = true;
68 FilterNotifier.removeListener(filterListener);
69 });
70
71 RequestService.addListener(function(data)
72 {
73 if (!data)
74 return {"success" : false, "error" : "misformed request"};
75
76 if (data["action"] == "query_ready_state")
77 return {"success" : true, "value" : AdblockPlusApi.filtersLoaded};
78
79 if (!AdblockPlusApi.filtersLoaded)
80 return {"success" : false, "error" : "filters not loaded"};
81
82 switch (data["action"])
83 {
84 case "query_acceptable_ads_state":
85 return {"success" : true, "value" : AdblockPlusApi.acceptableAdsEnabled};
86 case "change_acceptable_ads_state":
87 if ("enable" in data)
88 {
89 AdblockPlusApi.acceptableAdsEnabled = !!data["enable"];
90 return {"success" : true};
91 }
92 return {"success" : false, "error" : "misformed request"};
93 default:
94 return {"success" : false, "error" : "unknown action '" + data["action"] + "'"};
95 }
96 return {"success" : false, "error" : "misformed request"};
97 }, "AdblockPlus:Api");
OLDNEW
« no previous file with comments | « no previous file | mobile/android/base/moz.build » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld