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');
10 require('binding').Binding
.create('appViewInternal').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 AppViewInternal
.attachFrame(url
, id
);
29 appEmbeddingRequest
.deny = function() {
30 AppViewInternal
.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) {
50 var data
= { isKioskSession
: launchData
.isKioskSession
};
51 if (items
.length
!== 0) {
52 data
.id
= launchData
.id
;
58 $Array
.forEach(launchData
.items
, function(item
) {
59 var fs
= GetIsolatedFileSystem(item
.fileSystemId
);
60 fs
.root
.getFile(item
.baseName
, {}, function(fileEntry
) {
61 entryIdManager
.registerEntry(item
.entryId
, fileEntry
);
62 itemLoaded(null, { entry
: fileEntry
, type
: item
.mimeType
});
63 }, function(fileError
) {
64 itemLoaded(fileError
);
68 // Default case. This currently covers an onLaunched corresponding to
69 // url_handlers in the app's manifest.
70 dispatch([launchData
]);
74 exports
.binding
= binding
.generate();