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(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 }); | 45 }); |
46 })(fe, fs); | 46 })(fe, fs); |
47 } | 47 } |
48 dispatchIfNoPendingCallbacks(); | 48 dispatchIfNoPendingCallbacks(); |
49 }); | 49 }); |
50 | 50 |
51 chromeHidden.Event.registerArgumentMassager('app.runtime.onLaunched', | 51 chromeHidden.Event.registerArgumentMassager('app.runtime.onLaunched', |
52 function(args, dispatch) { | 52 function(args, dispatch) { |
53 var launchData = args[0]; | 53 var launchData = args[0]; |
54 | 54 |
55 if (launchData && typeof launchData.id !== 'undefined') { | 55 if (!launchData) { |
56 // new-style dispatch. | 56 dispatch([]); |
| 57 return; |
| 58 } |
| 59 |
| 60 if (launchData.items) { |
| 61 // An onLaunched corresponding to file_handlers in the app's manifest. |
| 62 // NOTE: Using the new-style dispatch. |
57 var items = [] | 63 var items = [] |
58 var numItems = launchData.items.length; | 64 var numItems = launchData.items.length; |
59 var itemLoaded = function(err, item) { | 65 var itemLoaded = function(err, item) { |
60 if (err) { | 66 if (err) { |
61 console.error('Error getting fileEntry, code: ' + err.code); | 67 console.error('Error getting fileEntry, code: ' + err.code); |
62 } else { | 68 } else { |
63 items.push(item); | 69 items.push(item); |
64 } | 70 } |
65 if (--numItems === 0) { | 71 if (--numItems === 0) { |
66 if (items.length === 0) { | 72 if (items.length === 0) { |
67 dispatch([]); | 73 dispatch([]); |
68 } else { | 74 } else { |
69 var data = { id: launchData.id, items: items }; | 75 var data = { id: launchData.id, items: items }; |
70 dispatch([data]); | 76 dispatch([data]); |
71 } | 77 } |
72 } | 78 } |
73 }; | 79 }; |
74 forEach(launchData.items, function(i, item) { | 80 forEach(launchData.items, function(i, item) { |
75 var fs = GetIsolatedFileSystem(item.fileSystemId); | 81 var fs = GetIsolatedFileSystem(item.fileSystemId); |
76 fs.root.getFile(item.baseName, {}, function(fileEntry) { | 82 fs.root.getFile(item.baseName, {}, function(fileEntry) { |
77 itemLoaded(null, { entry: fileEntry, type: item.mimeType }); | 83 itemLoaded(null, { entry: fileEntry, type: item.mimeType }); |
78 }, function(fileError) { | 84 }, function(fileError) { |
79 itemLoaded(fileError); | 85 itemLoaded(fileError); |
80 }); | 86 }); |
81 }); | 87 }); |
82 } else if (launchData) { | 88 } else { |
| 89 // Default case. This currently covers an onLaunched corresponding to |
| 90 // url_handlers in the app's manifest. |
83 dispatch([launchData]); | 91 dispatch([launchData]); |
84 } else { | |
85 dispatch([]); | |
86 } | 92 } |
87 }); | 93 }); |
88 | 94 |
89 exports.binding = binding.generate(); | 95 exports.binding = binding.generate(); |
OLD | NEW |