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

Delta Between Two Patch Sets: adblockplus/Api.jsm

Issue 4920541991403520: Create a minimal settings UI (Closed)
Left Patch Set: Typos, extra-summary into strings.xml. Created March 20, 2015, 11:54 p.m.
Right Patch Set: Removed default case Created March 22, 2015, 9:23 p.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 | « no previous file | mobile/android/base/moz.build » ('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-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 15 matching lines...) Expand all
26 Cu.import("resource://gre/modules/Messaging.jsm"); 26 Cu.import("resource://gre/modules/Messaging.jsm");
27 27
28 function require(module) 28 function require(module)
29 { 29 {
30 let result = {}; 30 let result = {};
31 result.wrappedJSObject = result; 31 result.wrappedJSObject = result;
32 Services.obs.notifyObservers(result, "adblockplus-require", module); 32 Services.obs.notifyObservers(result, "adblockplus-require", module);
33 return result.exports; 33 return result.exports;
34 } 34 }
35 35
36 let {FilterNotifier} = require("filterNotifier");
37 let {FilterStorage} = require("filterStorage"); 36 let {FilterStorage} = require("filterStorage");
38 let {Prefs} = require("prefs"); 37 let {Prefs} = require("prefs");
39 let {UI} = require("ui"); 38 let {UI} = require("ui");
40
41 let {FilterNotifier} = require("filterNotifier");
42 39
43 var AdblockPlusApi = 40 var AdblockPlusApi =
44 { 41 {
45 get filtersLoaded() 42 get filtersLoaded()
46 { 43 {
47 return filtersLoaded; 44 return !FilterStorage._loading;
48 }, 45 },
49 get acceptableAdsEnabled() 46 get acceptableAdsEnabled()
50 { 47 {
51 return FilterStorage.subscriptions.some( 48 return FilterStorage.subscriptions.some(
52 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl); 49 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl);
53 }, 50 },
54 set acceptableAdsEnabled(acceptableAdsEnabled) 51 set acceptableAdsEnabled(acceptableAdsEnabled)
55 { 52 {
56 if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled) 53 if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled)
57 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 }
81 return {"success": false, "error": "malformed request"};
82 }).bind(this), "AdblockPlus:Api");
58 } 83 }
59 }; 84 };
60 85
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");
LEFTRIGHT

Powered by Google App Engine
This is Rietveld