blob: a50c96407ca99b5c153e203c8130aa7d942a7ab8 (
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
53
54
55
56
|
// 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 binding for the chrome.app.runtime API.
var binding = require('binding').Binding.create('app.runtime');
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var chrome = requireNative('chrome').GetChrome();
var fileSystemHelpers = requireNative('file_system_natives');
var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem;
var appNatives = requireNative('app_runtime');
var DeserializeString = appNatives.DeserializeString;
var SerializeToString = appNatives.SerializeToString;
var CreateBlob = appNatives.CreateBlob;
chromeHidden.Event.registerArgumentMassager('app.runtime.onLaunched',
function(args, dispatch) {
var launchData = args[0];
if (launchData && typeof launchData.id !== 'undefined') {
// new-style dispatch.
var items = []
var numItems = launchData.items.length;
var itemLoaded = function(err, item) {
if (err) {
console.error('Error getting fileEntry, code: ' + err.code);
} else {
items.push(item);
}
if (--numItems === 0) {
if (items.length === 0) {
dispatch([]);
} else {
var data = { id: launchData.id, items: items };
dispatch([data]);
}
}
};
launchData.items.forEach(function(item) {
var fs = GetIsolatedFileSystem(item.fileSystemId);
fs.root.getFile(item.baseName, {}, function(fileEntry) {
itemLoaded(null, { entry: fileEntry, type: item.mimeType });
}, function(fileError) {
itemLoaded(fileError);
});
});
} else if (launchData) {
dispatch([launchData]);
} else {
dispatch([]);
}
});
exports.binding = binding.generate();
|