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: Export variables differently in common.js Created Jan. 7, 2015, 6:58 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 {
21 _MessageProxy: MessageProxy,
22 _EventTarget: EventTarget,
23 _getSender: getSender
24 } = require("ext_common");
25 exports.onMessage = new EventTarget();
26
27 let messageProxy = new MessageProxy(
28 Cc["@mozilla.org/globalmessagemanager;1"]
29 .getService(Ci.nsIMessageListenerManager),
30 exports.onMessage);
31 onShutdown.add(function()
32 {
33 messageProxy._disconnect();
34 });
35
36 function Page(sender)
37 {
38 this._sender = sender;
39 }
40 Page.prototype = {
41 sendMessage: function(message)
42 {
43 if (this._sender)
44 this._sender.sendAsyncMessage("AdblockPlus:Message", {payload: message});
45 }
46 };
47 exports.Page = Page;
48
49 function PageMap()
50 {
51 this._map = new Map();
52
53 Services.obs.addObserver(this, "message-manager-disconnect", true);
54 onShutdown.add(function()
55 {
56 Services.obs.removeObserver(this, "message-manager-disconnect");
57 }.bind(this));
58 }
59 PageMap.prototype = {
60 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence]),
61
62 observe: function(subject, topic, data)
63 {
64 if (topic == "message-manager-disconnect")
65 this._map.delete(subject);
66 },
67
68 keys: function()
69 {
70 let result = [];
71 for (let sender of this._map.keys())
72 result.push(new Page(sender));
73 return result;
74 },
75
76 get: function(page)
77 {
78 return this._map.get(page._sender);
79 },
80
81 set: function(page, value)
82 {
83 if (page._sender)
84 this._map.set(page._sender, value);
85 },
86
87 has: function(page)
88 {
89 return this._map.has(page._sender);
90 },
91
92 delete: function(page)
93 {
94 this._map.delete(page._sender);
95 }
96 };
97 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