forked from Asana/Chrome-Extension-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension_server.js
More file actions
29 lines (25 loc) · 964 Bytes
/
extension_server.js
File metadata and controls
29 lines (25 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* The "server" portion of the chrome extension, which listens to events
* from other clients such as the popup or per-page content windows.
*/
Asana.ExtensionServer = {
/**
* Call from the background page: listen to chrome events and
* requests from page clients, which can't make cross-domain requests.
*/
listen: function() {
var me = this;
// Mark our Api Bridge as the server side (the one that actually makes
// API requests to Asana vs. just forwarding them to the server window).
Asana.ApiBridge.is_server = true;
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.type === "api") {
// Request to the API. Pass it on to the bridge.
Asana.ApiBridge.request(
request.method, request.path, request.params, sendResponse,
request.options || {});
return true; // will call sendResponse asynchronously
}
});
}
};