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: Forgot commenting out Created March 22, 2015, 3:40 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 | 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
35 let {FilterStorage} = require("filterStorage"); 36 let {FilterStorage} = require("filterStorage");
36 let {Prefs} = require("prefs"); 37 let {Prefs} = require("prefs");
37 let {UI} = require("ui"); 38 let {UI} = require("ui");
38 39
39 var AdblockPlusApi = 40 var AdblockPlusApi =
40 { 41 {
42 get filtersLoaded()
43 {
44 return !FilterStorage._loading;
45 },
41 get acceptableAdsEnabled() 46 get acceptableAdsEnabled()
42 { 47 {
43 return FilterStorage.subscriptions.some( 48 return FilterStorage.subscriptions.some(
44 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl); 49 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl);
45 }, 50 },
46 set acceptableAdsEnabled(acceptableAdsEnabled) 51 set acceptableAdsEnabled(acceptableAdsEnabled)
47 { 52 {
48 if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled) 53 if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled)
49 UI.toggleAcceptableAds(); 54 UI.toggleAcceptableAds();
55 },
56 initCommunication : function()
57 {
58 RequestService.addListener((function(data)
59 {
60 if (!data)
61 return {"success" : false, "error" : "malformed request"};
62
63 if (data["action"] == "getFiltersLoaded")
64 return {"success" : true, "value" : this.filtersLoaded};
65
66 if (!this.filtersLoaded)
67 return {"success" : false, "error" : "filters not loaded"};
68
69 switch (data["action"])
70 {
71 case "getAcceptableAdsEnabled":
72 return {"success" : true, "value" : this.acceptableAdsEnabled};
73 case "setAcceptableAdsEnabled":
74 if ("enable" in data)
75 {
76 this.acceptableAdsEnabled = !!data["enable"];
77 return {"success" : true};
78 }
79 return {"success" : false, "error" : "malformed request"};
80 default:
81 return {"success" : false, "error" : "unknown action '" + data["action "] + "'"};
82 }
83 return {"success" : false, "error" : "misformed request"};
Felix Dahlke 2015/03/22 15:51:45 Also "malformed" then? :)
84 }).bind(this), "AdblockPlus:Api");
50 } 85 }
51 }; 86 };
87
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