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

Side by Side Diff: ext/background.js

Issue 5056848617013248: Issue 1706 - Move first-run page to adblockplusui repository (Closed)
Patch Set: Addressed comments Created Jan. 7, 2015, 4:34 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 | « chrome/skin/social/weibo.png ('k') | ext/common.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", null);
19 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null);
20 let {MessageProxy, EventTarget, getSender} = require("ext_common");
21 exports.onMessage = new EventTarget();
22
23 let messageProxy = new MessageProxy(
24 Cc["@mozilla.org/globalmessagemanager;1"]
25 .getService(Ci.nsIMessageListenerManager),
26 exports.onMessage);
27 onShutdown.add(function()
28 {
29 messageProxy._disconnect();
30 });
31
32 function Page(sender)
33 {
34 this._sender = sender;
35 }
36 Page.prototype = {
37 sendMessage: function(message)
38 {
39 if (this._sender)
40 this._sender.sendAsyncMessage("AdblockPlus:Message", {payload: message});
41 }
42 };
43 exports.Page = Page;
44
45 function PageMap()
46 {
47 this._map = new Map();
48
49 Services.obs.addObserver(this, "message-manager-disconnect", true);
50 onShutdown.add(function()
51 {
52 Services.obs.removeObserver(this, "message-manager-disconnect");
53 }.bind(this));
54 }
55 PageMap.prototype = {
56 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence]),
57
58 observe: function(subject, topic, data)
59 {
60 if (topic == "message-manager-disconnect")
61 this._map.delete(subject);
62 },
63
64 keys: function()
65 {
66 let result = [];
67 for (let sender of this._map.keys())
68 result.push(new Page(sender));
69 return result;
70 },
71
72 get: function(page)
73 {
74 return this._map.get(page._sender);
75 },
76
77 set: function(page, value)
78 {
79 if (page._sender)
80 this._map.set(page._sender, value);
81 },
82
83 has: function(page)
84 {
85 return this._map.has(page._sender);
86 },
87
88 delete: function(page)
89 {
90 this._map.delete(page._sender);
91 }
92 };
93 exports.PageMap = PageMap;
OLDNEW
« no previous file with comments | « chrome/skin/social/weibo.png ('k') | ext/common.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld