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

Unified Diff: chrome/common.js

Issue 5867629902299136: Fixed various issues in older Chrome versions (Closed)
Patch Set: Created Dec. 19, 2013, 10:46 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/background.js ('k') | popup.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common.js
===================================================================
--- a/chrome/common.js
+++ b/chrome/common.js
@@ -51,33 +51,51 @@
this._listeners.splice(idx, 1);
this._wrappedListeners.splice(idx, 1);
}
}
};
var MessageEventTarget = function()
{
- WrappedEventTarget.call(this, (chrome.runtime || {}).onMessage || chrome.extension.onRequest);
+ var target;
+ if ("runtime" in chrome && "onMessage" in chrome.runtime)
+ target = chrome.runtime.onMessage;
+ else if ("onMessage" in chrome.extension)
+ target = chrome.extension.onMessage;
+ else
+ target = chrome.extension.onRequest;
+ WrappedEventTarget.call(this, target);
};
MessageEventTarget.prototype = {
__proto__: WrappedEventTarget.prototype,
_wrapListener: function(listener) {
return function(message, sender, sendResponse)
{
- return listener(message, {tab: sender.tab && new Tab(sender.tab)}, sendResponse);
+ if (sender.tab && sender.tab.id >= 0)
+ sender.tab = new Tab(sender.tab);
+ return listener(message, sender, sendResponse);
};
}
};
/* API */
ext = {
backgroundPage: {
- sendMessage: (chrome.runtime || {}).sendMessage || chrome.extension.sendRequest,
- getWindow: chrome.extension.getBackgroundPage
+ getWindow: function()
+ {
+ return chrome.extension.getBackgroundPage();
+ }
},
getURL: chrome.extension.getURL,
onMessage: new MessageEventTarget(),
i18n: chrome.i18n
};
+
+ if ("runtime" in chrome && "sendMessage" in chrome.runtime)
+ ext.backgroundPage.sendMessage = chrome.runtime.sendMessage;
+ else if ("sendMessage" in chrome.extension)
+ ext.backgroundPage.sendMessage = chrome.extension.sendMessage;
+ else
+ ext.backgroundPage.sendMessage = chrome.extension.sendRequest;
})();
« no previous file with comments | « chrome/background.js ('k') | popup.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld