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

Side by Side Diff: chrome/common.js

Issue 4549521954570240: Added backwards compatibility for Chrome's old messaging API (Closed)
Patch Set: Handled case when chrome.runtime isn't present Created Nov. 17, 2013, 1:21 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/background.js ('k') | no next file » | 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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 this._target.removeListener(this._wrappedListeners[idx]); 49 this._target.removeListener(this._wrappedListeners[idx]);
50 50
51 this._listeners.splice(idx, 1); 51 this._listeners.splice(idx, 1);
52 this._wrappedListeners.splice(idx, 1); 52 this._wrappedListeners.splice(idx, 1);
53 } 53 }
54 } 54 }
55 }; 55 };
56 56
57 var MessageEventTarget = function() 57 var MessageEventTarget = function()
58 { 58 {
59 WrappedEventTarget.call(this, chrome.runtime.onMessage); 59 WrappedEventTarget.call(this, (chrome.runtime || {}).onMessage || chrome.ext ension.onRequest);
60 }; 60 };
61 MessageEventTarget.prototype = { 61 MessageEventTarget.prototype = {
62 __proto__: WrappedEventTarget.prototype, 62 __proto__: WrappedEventTarget.prototype,
63 _wrapListener: function(listener) { 63 _wrapListener: function(listener) {
64 return function(message, sender, sendResponse) 64 return function(message, sender, sendResponse)
65 { 65 {
66 listener(message, {tab: sender.tab && new Tab(sender.tab)}, sendResponse ); 66 listener(message, {tab: sender.tab && new Tab(sender.tab)}, sendResponse );
67 }; 67 };
68 } 68 }
69 }; 69 };
70 70
71
71 /* API */ 72 /* API */
72 73
73 ext = { 74 ext = {
74 backgroundPage: { 75 backgroundPage: {
75 sendMessage: function(message, responseCallback) 76 sendMessage: (chrome.runtime || {}).sendMessage || chrome.extension.sendRe quest,
76 { 77 getWindow: chrome.extension.getBackgroundPage
77 chrome.runtime.sendMessage(message, responseCallback);
78 },
79 getWindow: function()
80 {
81 return chrome.extension.getBackgroundPage();
82 }
83 }, 78 },
84 getURL: chrome.extension.getURL, 79 getURL: chrome.extension.getURL,
85 onMessage: new MessageEventTarget(), 80 onMessage: new MessageEventTarget(),
86 i18n: chrome.i18n 81 i18n: chrome.i18n
87 }; 82 };
88 })(); 83 })();
OLDNEW
« no previous file with comments | « chrome/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld