1 // Copyright 2014 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 AppViewGuestInternal =
10 require('binding').Binding.create('appViewGuestInternal').generate();
11 var eventBindings = require('event_bindings');
12 var fileSystemHelpers = requireNative('file_system_natives');
13 var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem;
14 var entryIdManager = require('entryIdManager');
16 eventBindings.registerArgumentMassager('app.runtime.onEmbedRequested',
17 function(args, dispatch) {
18 var appEmbeddingRequest = args[0];
19 var id = appEmbeddingRequest.guestInstanceId;
20 delete appEmbeddingRequest.guestInstanceId;
21 appEmbeddingRequest.allow = function(url) {
22 AppViewGuestInternal.attachFrame(url, id);
25 appEmbeddingRequest.deny = function() {
26 AppViewGuestInternal.denyRequest(id);
29 dispatch([appEmbeddingRequest]);
32 eventBindings.registerArgumentMassager('app.runtime.onLaunched',
33 function(args, dispatch) {
34 var launchData = args[0];
35 if (launchData.items) {
36 // An onLaunched corresponding to file_handlers in the app's manifest.
38 var numItems = launchData.items.length;
39 var itemLoaded = function(err, item) {
41 console.error('Error getting fileEntry, code: ' + err.code);
43 $Array.push(items, item);
45 if (--numItems === 0) {
47 isKioskSession: launchData.isKioskSession,
48 source: launchData.source
50 if (items.length !== 0) {
51 data.id = launchData.id;
57 $Array.forEach(launchData.items, function(item) {
58 var fs = GetIsolatedFileSystem(item.fileSystemId);
59 fs.root.getFile(item.baseName, {}, function(fileEntry) {
60 entryIdManager.registerEntry(item.entryId, fileEntry);
61 itemLoaded(null, { entry: fileEntry, type: item.mimeType });
62 }, function(fileError) {
63 itemLoaded(fileError);
67 // Default case. This currently covers an onLaunched corresponding to
68 // url_handlers in the app's manifest.
69 dispatch([launchData]);
73 exports.binding = binding.generate();