summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/resources/extensions/app_custom_bindings.js
blob: 9cae9d4c2777764d1d39e82a77593c61f1276092 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Custom bindings for the app API.

var appNatives = requireNative('app');
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();

chrome.app = {
  getIsInstalled: appNatives.GetIsInstalled,
  install: appNatives.Install,
  getDetails: appNatives.GetDetails,
  getDetailsForFrame: appNatives.GetDetailsForFrame
};

// Tricky; "getIsInstalled" is actually exposed as the getter "isInstalled",
// but we don't have a way to express this in the schema JSON (nor is it
// worth it for this one special case).
//
// So, define it manually, and let the getIsInstalled function act as its
// documentation.
chrome.app.__defineGetter__('isInstalled', appNatives.GetIsInstalled);

// Called by app_bindings.cc.
chromeHidden.app = {
  onGetAppNotifyChannelResponse: function(channelId, error, callbackId) {
    if (callbackId) {
      callbacks[callbackId](channelId, error);
      delete callbacks[callbackId];
    }
  }
};

// appNotification stuff.
//
// TODO(kalman): move this stuff to its own custom bindings.
// It will be bit tricky since I'll need to look into why there are
// permissions defined for app notifications, yet this always sets it up?
var callbacks = {};
var nextCallbackId = 1;

chrome.appNotifications = {
  getChannel: function getChannel(clientId, callback) {
    var callbackId = 0;
    if (callback) {
      callbackId = nextCallbackId++;
      callbacks[callbackId] = callback;
    }
    appNatives.GetAppNotifyChannel(clientId, callbackId);
  }
};