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 chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 9 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
10 var chrome = requireNative('chrome').GetChrome(); | 10 var chrome = requireNative('chrome').GetChrome(); |
11 var fileSystemHelpers = requireNative('file_system_natives'); | 11 var fileSystemHelpers = requireNative('file_system_natives'); |
12 var forEach = require('utils').forEach; | 12 var forEach = require('utils').forEach; |
13 var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem; | 13 var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem; |
14 var appNatives = requireNative('app_runtime'); | 14 var appNatives = requireNative('app_runtime'); |
15 var DeserializeString = appNatives.DeserializeString; | 15 var DeserializeString = appNatives.DeserializeString; |
16 var SerializeToString = appNatives.SerializeToString; | 16 var SerializeToString = appNatives.SerializeToString; |
17 var CreateBlob = appNatives.CreateBlob; | 17 var CreateBlob = appNatives.CreateBlob; |
| 18 var entryIdManager = require('entryIdManager'); |
| 19 |
| 20 chromeHidden.Event.registerArgumentMassager('app.runtime.onRestarted', |
| 21 function(args, dispatch) { |
| 22 // These file entries don't get dispatched, we just use this hook to register |
| 23 // them all with entryIdManager. |
| 24 var fileEntries = args[0]; |
| 25 |
| 26 var pendingCallbacks = fileEntries.length; |
| 27 |
| 28 var dispatchIfNoPendingCallbacks = function() { |
| 29 if (pendingCallbacks == 0) |
| 30 dispatch([]); |
| 31 }; |
| 32 |
| 33 for (var i = 0; i < fileEntries.length; i++) { |
| 34 var fe = fileEntries[i]; |
| 35 var fs = GetIsolatedFileSystem(fe.fileSystemId); |
| 36 (function(fe, fs) { |
| 37 fs.root.getFile(fe.baseName, {}, function(fileEntry) { |
| 38 entryIdManager.registerEntry(fe.id, fileEntry); |
| 39 pendingCallbacks--; |
| 40 dispatchIfNoPendingCallbacks(); |
| 41 }, function(err) { |
| 42 console.error('Error getting fileEntry, code: ' + err.code); |
| 43 pendingCallbacks--; |
| 44 dispatchIfNoPendingCallbacks(); |
| 45 }); |
| 46 })(fe, fs); |
| 47 } |
| 48 dispatchIfNoPendingCallbacks(); |
| 49 }); |
18 | 50 |
19 chromeHidden.Event.registerArgumentMassager('app.runtime.onLaunched', | 51 chromeHidden.Event.registerArgumentMassager('app.runtime.onLaunched', |
20 function(args, dispatch) { | 52 function(args, dispatch) { |
21 var launchData = args[0]; | 53 var launchData = args[0]; |
22 | 54 |
23 if (launchData && typeof launchData.id !== 'undefined') { | 55 if (launchData && typeof launchData.id !== 'undefined') { |
24 // new-style dispatch. | 56 // new-style dispatch. |
25 var items = [] | 57 var items = [] |
26 var numItems = launchData.items.length; | 58 var numItems = launchData.items.length; |
27 var itemLoaded = function(err, item) { | 59 var itemLoaded = function(err, item) { |
(...skipping 20 matching lines...) Expand all Loading... |
48 }); | 80 }); |
49 }); | 81 }); |
50 } else if (launchData) { | 82 } else if (launchData) { |
51 dispatch([launchData]); | 83 dispatch([launchData]); |
52 } else { | 84 } else { |
53 dispatch([]); | 85 dispatch([]); |
54 } | 86 } |
55 }); | 87 }); |
56 | 88 |
57 exports.binding = binding.generate(); | 89 exports.binding = binding.generate(); |
OLD | NEW |