1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Custom binding for the app API.
7 var GetAvailability
= requireNative('v8_context').GetAvailability
;
8 if (!GetAvailability('app').is_available
) {
10 exports
.onInstallStateResponse = function(){};
14 var appNatives
= requireNative('app');
15 var process
= requireNative('process');
16 var extensionId
= process
.GetExtensionId();
17 var logActivity
= requireNative('activityLogger');
19 function wrapForLogging(fun
) {
21 return fun
; // nothing interesting to log without an extension
24 // TODO(ataly): We need to make sure we use the right prototype for
25 // fun.apply. Array slice can either be rewritten or similarly defined.
26 logActivity
.LogAPICall(extensionId
, "app." + fun
.name
,
27 $Array
.slice(arguments
));
28 return $Function
.apply(fun
, this, arguments
);
32 // This becomes chrome.app
34 getIsInstalled
: wrapForLogging(appNatives
.GetIsInstalled
),
35 getDetails
: wrapForLogging(appNatives
.GetDetails
),
36 runningState
: wrapForLogging(appNatives
.GetRunningState
)
39 // Tricky; "getIsInstalled" is actually exposed as the getter "isInstalled",
40 // but we don't have a way to express this in the schema JSON (nor is it
41 // worth it for this one special case).
43 // So, define it manually, and let the getIsInstalled function act as its
45 app
.__defineGetter__('isInstalled', wrapForLogging(appNatives
.GetIsInstalled
));
47 // Called by app_bindings.cc.
48 function onInstallStateResponse(state
, callbackId
) {
49 var callback
= callbacks
[callbackId
];
50 delete callbacks
[callbackId
];
51 if (typeof(callback
) == 'function') {
55 console
.error('Exception in chrome.app.installState response handler: ' +
61 // TODO(kalman): move this stuff to its own custom bindings.
63 var nextCallbackId
= 1;
65 app
.installState
= function getInstallState(callback
) {
66 var callbackId
= nextCallbackId
++;
67 callbacks
[callbackId
] = callback
;
68 appNatives
.GetInstallState(callbackId
);
71 app
.installState
= wrapForLogging(app
.installState
);
73 exports
.binding
= app
;
74 exports
.onInstallStateResponse
= onInstallStateResponse
;