| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Custom binding for the chrome.app.runtime API. | 5 // Custom binding for the chrome.app.runtime API. |
| 6 | 6 |
| 7 var binding = require('binding').Binding.create('app.runtime'); | 7 var binding = require('binding').Binding.create('app.runtime'); |
| 8 | 8 |
| 9 var eventBindings = require('event_bindings'); | 9 var eventBindings = require('event_bindings'); |
| 10 var fileSystemHelpers = requireNative('file_system_natives'); | 10 var fileSystemHelpers = requireNative('file_system_natives'); |
| 11 var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem; | 11 var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem; |
| 12 var appNatives = requireNative('app_runtime'); | 12 var appNatives = requireNative('app_runtime'); |
| 13 var DeserializeString = appNatives.DeserializeString; | 13 var DeserializeString = appNatives.DeserializeString; |
| 14 var SerializeToString = appNatives.SerializeToString; | 14 var SerializeToString = appNatives.SerializeToString; |
| 15 var CreateBlob = appNatives.CreateBlob; | 15 var CreateBlob = appNatives.CreateBlob; |
| 16 var entryIdManager = require('entryIdManager'); | 16 var entryIdManager = require('entryIdManager'); |
| 17 | 17 |
| 18 eventBindings.registerArgumentMassager('app.runtime.onLaunched', | 18 eventBindings.registerArgumentMassager('app.runtime.onLaunched', |
| 19 function(args, dispatch) { | 19 function(args, dispatch) { |
| 20 var launchData = args[0]; | 20 var launchData = args[0]; |
| 21 | 21 |
| 22 if (launchData && typeof launchData.id !== 'undefined') { | 22 if (launchData && typeof launchData.id !== 'undefined') { |
| 23 // new-style dispatch. | 23 // new-style dispatch. |
| 24 var items = [] | 24 var items = [] |
| 25 var numItems = launchData.items.length; | 25 var numItems = launchData.items.length; |
| 26 var itemLoaded = function(err, item) { | 26 var itemLoaded = function(err, item) { |
| 27 if (err) { | 27 if (err) { |
| 28 console.error('Error getting fileEntry, code: ' + err.code); | 28 console.error('Error getting fileEntry, code: ' + err.code); |
| 29 } else { | 29 } else { |
| 30 items.push(item); | 30 $Array.push(items, item); |
| 31 } | 31 } |
| 32 if (--numItems === 0) { | 32 if (--numItems === 0) { |
| 33 if (items.length === 0) { | 33 if (items.length === 0) { |
| 34 dispatch([]); | 34 dispatch([]); |
| 35 } else { | 35 } else { |
| 36 var data = { id: launchData.id, items: items }; | 36 var data = { id: launchData.id, items: items }; |
| 37 dispatch([data]); | 37 dispatch([data]); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 }; | 40 }; |
| 41 $Array.forEach(launchData.items, function(item) { | 41 $Array.forEach(launchData.items, function(item) { |
| 42 var fs = GetIsolatedFileSystem(item.fileSystemId); | 42 var fs = GetIsolatedFileSystem(item.fileSystemId); |
| 43 fs.root.getFile(item.baseName, {}, function(fileEntry) { | 43 fs.root.getFile(item.baseName, {}, function(fileEntry) { |
| 44 entryIdManager.registerEntry(item.entryId, fileEntry); | 44 entryIdManager.registerEntry(item.entryId, fileEntry); |
| 45 itemLoaded(null, { entry: fileEntry, type: item.mimeType }); | 45 itemLoaded(null, { entry: fileEntry, type: item.mimeType }); |
| 46 }, function(fileError) { | 46 }, function(fileError) { |
| 47 itemLoaded(fileError); | 47 itemLoaded(fileError); |
| 48 }); | 48 }); |
| 49 }); | 49 }); |
| 50 } else if (launchData) { | 50 } else if (launchData) { |
| 51 dispatch([launchData]); | 51 dispatch([launchData]); |
| 52 } else { | 52 } else { |
| 53 dispatch([]); | 53 dispatch([]); |
| 54 } | 54 } |
| 55 }); | 55 }); |
| 56 | 56 |
| 57 exports.binding = binding.generate(); | 57 exports.binding = binding.generate(); |
| OLD | NEW |