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

Delta Between Two Patch Sets: chrome/common.js

Issue 4549521954570240: Added backwards compatibility for Chrome's old messaging API (Closed)
Left Patch Set: Created Nov. 15, 2013, 6:42 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « chrome/background.js ('k') | no next file » | 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 <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 || chrome.extension.o nRequest); 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
72 /* API */ 72 /* API */
73 73
74 ext = { 74 ext = {
75 backgroundPage: { 75 backgroundPage: {
76 sendMessage: chrome.runtime.sendMessage || chrome.extension.sendRequest, 76 sendMessage: (chrome.runtime || {}).sendMessage || chrome.extension.sendRe quest,
Wladimir Palant 2013/11/17 06:19:45 This will error out with "Cannot get property send
77 getWindow: chrome.extension.getBackgroundPage 77 getWindow: chrome.extension.getBackgroundPage
78 }, 78 },
79 getURL: chrome.extension.getURL, 79 getURL: chrome.extension.getURL,
80 onMessage: new MessageEventTarget(), 80 onMessage: new MessageEventTarget(),
81 i18n: chrome.i18n 81 i18n: chrome.i18n
82 }; 82 };
83 })(); 83 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld