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 chrome.app.runtime API.
7 var binding = require('binding').Binding.create('app.runtime');
9 var eventBindings = require('event_bindings');
10 var fileSystemHelpers = requireNative('file_system_natives');
11 var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem;
12 var appNatives = requireNative('app_runtime');
13 var DeserializeString = appNatives.DeserializeString;
14 var SerializeToString = appNatives.SerializeToString;
15 var CreateBlob = appNatives.CreateBlob;
16 var entryIdManager = require('entryIdManager');
18 eventBindings.registerArgumentMassager('app.runtime.onLaunched',
19 function(args, dispatch) {
20 var launchData = args[0];
21 if (launchData.items) {
22 // An onLaunched corresponding to file_handlers in the app's manifest.
24 var numItems = launchData.items.length;
25 var itemLoaded = function(err, item) {
27 console.error('Error getting fileEntry, code: ' + err.code);
29 $Array.push(items, item);
31 if (--numItems === 0) {
32 var data = { isKioskSession: launchData.isKioskSession };
33 if (items.length !== 0) {
34 data.id = launchData.id;
40 $Array.forEach(launchData.items, function(item) {
41 var fs = GetIsolatedFileSystem(item.fileSystemId);
42 fs.root.getFile(item.baseName, {}, function(fileEntry) {
43 entryIdManager.registerEntry(item.entryId, fileEntry);
44 itemLoaded(null, { entry: fileEntry, type: item.mimeType });
45 }, function(fileError) {
46 itemLoaded(fileError);
50 // Default case. This currently covers an onLaunched corresponding to
51 // url_handlers in the app's manifest.
52 dispatch([launchData]);
56 exports.binding = binding.generate();