~ubuntu-branches/ubuntu/vivid/ubufox/vivid

« back to all changes in this revision

Viewing changes to modules/libs/gio.jsm

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-01-03 12:54:26 UTC
  • mfrom: (1.1.28)
  • Revision ID: package-import@ubuntu.com-20120103125426-6huvc70js97j10i4
Tags: 1.5-0ubuntu1
* New upstream release
  - Update for Firefox 12.0a1 compatibility
  - Rewrite the plugin installer code to natively support aptdaemon
    (instead of apturl).
    + Note, this only affects plugin installation - search still happens
      using the online PFS.
  - Simplify the update restart notification code
  - Set the update restart notification reminder period to 15 minutes
* Drop dependency on apturl, and add dependency on aptdaemon and
  libglib2.0-0 (we're using GDBus via ctypes)
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Mozilla Public License Version
 
6
 * 1.1 (the "License"); you may not use this file except in compliance with
 
7
 * the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/MPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is ubufox.
 
16
 *
 
17
 * The Initial Developer of the Original Code is
 
18
 * Canonical Ltd.
 
19
 * Portions created by the Initial Developer are Copyright (C) 2011
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *   Chris Coulson <chris.coulson@canonical.com>
 
24
 *
 
25
 * Alternatively, the contents of this file may be used under the terms of
 
26
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
27
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
29
 * of those above. If you wish to allow use of your version of this file only
 
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
31
 * use your version of this file under the terms of the MPL, indicate your
 
32
 * decision by deleting the provisions above and replace them with the notice
 
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
34
 * the provisions above, a recipient may use your version of this file under
 
35
 * the terms of any one of the MPL, the GPL or the LGPL.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
var EXPORTED_SYMBOLS = [ "gio" ];
 
40
 
 
41
const GIO_LIBNAME = "gio-2.0";
 
42
const GIO_ABIS = [ 0 ];
 
43
 
 
44
const Cu = Components.utils;
 
45
 
 
46
Cu.import("resource://gre/modules/ctypes.jsm");
 
47
Cu.import("resource://ubufox/libs/ctypes-utils.jsm");
 
48
Cu.import("resource://ubufox/libs/gobject.jsm");
 
49
Cu.import("resource://ubufox/libs/glib.jsm");
 
50
 
 
51
["LOG", "WARN", "ERROR"].forEach(function(aName) {
 
52
  this.__defineGetter__(aName, function() {
 
53
    Components.utils.import("resource://gre/modules/AddonLogging.jsm");
 
54
 
 
55
    LogManager.getLogger("ubufox.gio", this);
 
56
    return this[aName];
 
57
  });
 
58
}, this);
 
59
 
 
60
var asyncCbHandlers = {};
 
61
var asyncCbIdSerial = 0;
 
62
 
 
63
function AsyncCbData(cb, ccb) {
 
64
  this.cb = cb,
 
65
  this.ccb = ccb;
 
66
}
 
67
 
 
68
function newAsyncCbId() {
 
69
  while (asyncCbHandlers[++asyncCbIdSerial]) {}
 
70
  return asyncCbIdSerial;
 
71
}
 
72
 
 
73
function gio_defines(lib) {
 
74
  // Enums
 
75
  // GBusType
 
76
  this.GBusType = ctypes.int;
 
77
  this.G_BUS_TYPE_STARTER = -1;
 
78
  this.G_BUS_TYPE_NONE = 0;
 
79
  this.G_BUS_TYPE_SYSTEM = 1;
 
80
  this.G_BUS_TYPE_SESSION = 2;
 
81
 
 
82
  // GDBusProxyFlags
 
83
  this.GDBusProxyFlags = ctypes.int;
 
84
  this.G_DBUS_PROXY_FLAGS_NONE = 0;
 
85
  this.G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES = (1<<0);
 
86
  this.G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS = (1<<1);
 
87
  this.G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START = (1<<2);
 
88
 
 
89
  // GDBusCallFlags
 
90
  this.GDBusCallFlags = ctypes.int;
 
91
  this.G_DBUS_CALL_FLAGS_NONE = 0;
 
92
  this.G_DBUS_CALL_FLAGS_NO_AUTO_START = (1<<0);
 
93
 
 
94
  // GIOErrorEnum
 
95
  this.G_IO_ERROR_DBUS_ERROR = 36;
 
96
 
 
97
  // Types
 
98
  this.GDBusInterfaceInfo = ctypes.StructType("GDBusInterfaceInfo");
 
99
  this.GCancellable = ctypes.StructType("GCancellable");
 
100
  this.GAsyncResult = ctypes.StructType("GAsyncResult");
 
101
  this.GDBusProxy = ctypes.StructType("GDBusProxy");
 
102
 
 
103
  // Templates
 
104
  this.GAsyncReadyCallback = ctypes.FunctionType(ctypes.default_abi,
 
105
                                                 ctypes.void_t,
 
106
                                                 [gobject.GObject.ptr,
 
107
                                                  this.GAsyncResult.ptr,
 
108
                                                  glib.gpointer]).ptr;
 
109
 
 
110
  // Functions
 
111
  lib.lazy_bind("g_dbus_proxy_new_for_bus", ctypes.void_t, this.GBusType,
 
112
                this.GDBusProxyFlags, this.GDBusInterfaceInfo.ptr,
 
113
                glib.gchar.ptr, glib.gchar.ptr, glib.gchar.ptr,
 
114
                this.GCancellable.ptr, this.GAsyncReadyCallback, glib.gpointer);
 
115
  lib.lazy_bind("g_dbus_proxy_new_for_bus_finish", this.GDBusProxy.ptr,
 
116
                this.GAsyncResult.ptr, glib.GError.ptr.ptr);
 
117
  lib.lazy_bind("g_dbus_proxy_call", ctypes.void_t, this.GDBusProxy.ptr,
 
118
                glib.gchar.ptr, glib.GVariant.ptr, this.GDBusCallFlags,
 
119
                glib.gint, this.GCancellable.ptr, this.GAsyncReadyCallback,
 
120
                glib.gpointer);
 
121
  lib.lazy_bind("g_dbus_proxy_call_finish", glib.GVariant.ptr,
 
122
                this.GDBusProxy.ptr, this.GAsyncResult.ptr, glib.GError.ptr.ptr);
 
123
  lib.lazy_bind("g_io_error_quark", glib.GQuark);
 
124
  lib.lazy_bind("g_dbus_error_get_remote_error", glib.gchar.ptr, glib.GError.ptr);
 
125
 
 
126
  // Helpers to work around jsctypes limitations
 
127
  this.GDbusProxyNewForBus = function(aType, aFlags, aInfo, aName,
 
128
                                      aPath, aInterface, aCancellable,
 
129
                                      aCallback) {
 
130
    let cb = function(aObject, aResult, aData) {
 
131
      try {
 
132
        aCallback(aObject, aResult);
 
133
      } catch(e) {
 
134
        Cu.reportError(e);
 
135
      }
 
136
      delete asyncCbHandlers[id];
 
137
    };
 
138
    let ccb = gio.GAsyncReadyCallback(cb);
 
139
 
 
140
    var id = newAsyncCbId();
 
141
    asyncCbHandlers[id] = new AsyncCbData(cb, ccb);
 
142
 
 
143
    gio.g_dbus_proxy_new_for_bus(aType, aFlags, aInfo, aName, aPath,
 
144
                                 aInterface, aCancellable, ccb, null);
 
145
  };
 
146
 
 
147
  this.GDbusProxyCall = function(aProxy, aMethod, aParams, aFlags, aTimeout,
 
148
                                 aCancellable, aCallback) {
 
149
    let cb = function(aObject, aResult, aData) {
 
150
      try {
 
151
        aCallback(aObject, aResult);
 
152
      } catch(e) {
 
153
        Cu.reportError(e);
 
154
      }
 
155
      delete asyncCbHandlers[id];
 
156
    };
 
157
    let ccb = gio.GAsyncReadyCallback(cb);
 
158
 
 
159
    var id = newAsyncCbId();
 
160
    asyncCbHandlers[id] = new AsyncCbData(cb, ccb);
 
161
 
 
162
    gio.g_dbus_proxy_call(aProxy, aMethod, aParams, aFlags, aTimeout,
 
163
                          aCancellable, ccb, null);
 
164
  };
 
165
 
 
166
  this.G_IO_ERROR = this.g_io_error_quark();
 
167
}
 
168
 
 
169
if (!gio || !gio.available()) {
 
170
  var gio = new ctypes_library(GIO_LIBNAME, GIO_ABIS, gio_defines);
 
171
}