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:24 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,55 @@
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
- },
+ backgroundPage: {},
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;
+
+ try
Sebastian Noack 2013/12/19 10:38:59 I would prefer to wrap chrome.extension.getBackgro
Wladimir Palant 2013/12/19 10:47:17 True, that's a better solution - done.
+ {
+ ext.backgroundPage.getWindow = chrome.extension.getBackgroundPage;
+ }
+ catch (e)
+ {
+ // This exception is expected in content scripts in older Chrome versions.
+ }
})();
« 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