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 appNatives
= requireNative('app_runtime');
15 var DeserializeString
= appNatives
.DeserializeString
;
16 var SerializeToString
= appNatives
.SerializeToString
;
17 var CreateBlob
= appNatives
.CreateBlob
;
18 var entryIdManager
= require('entryIdManager');
20 eventBindings
.registerArgumentMassager('app.runtime.onEmbedRequested',
21 function(args
, dispatch
) {
22 var appEmbeddingRequest
= args
[0];
23 var id
= appEmbeddingRequest
.guestInstanceId
;
24 delete appEmbeddingRequest
.guestInstanceId
;
25 appEmbeddingRequest
.allow = function(url
) {
26 AppViewGuestInternal
.attachFrame(url
, id
);
29 appEmbeddingRequest
.deny = function() {
30 AppViewGuestInternal
.denyRequest(id
);
33 dispatch([appEmbeddingRequest
]);
36 eventBindings
.registerArgumentMassager('app.runtime.onLaunched',
37 function(args
, dispatch
) {
38 var launchData
= args
[0];
39 if (launchData
.items
) {
40 // An onLaunched corresponding to file_handlers in the app's manifest.
42 var numItems
= launchData
.items
.length
;
43 var itemLoaded = function(err
, item
) {
45 console
.error('Error getting fileEntry, code: ' + err
.code
);
47 $Array
.push(items
, item
);
49 if (--numItems
=== 0) {
51 isKioskSession
: launchData
.isKioskSession
,
52 source
: launchData
.source
54 if (items
.length
!== 0) {
55 data
.id
= launchData
.id
;
61 $Array
.forEach(launchData
.items
, function(item
) {
62 var fs
= GetIsolatedFileSystem(item
.fileSystemId
);
63 fs
.root
.getFile(item
.baseName
, {}, function(fileEntry
) {
64 entryIdManager
.registerEntry(item
.entryId
, fileEntry
);
65 itemLoaded(null, { entry
: fileEntry
, type
: item
.mimeType
});
66 }, function(fileError
) {
67 itemLoaded(fileError
);
71 // Default case. This currently covers an onLaunched corresponding to
72 // url_handlers in the app's manifest.
73 dispatch([launchData
]);
77 exports
.binding
= binding
.generate();