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 bindings for the fileBrowserHandler API. | 5 // Custom bindings for the fileBrowserHandler API. |
6 | 6 |
7 var fileBrowserNatives = requireNative('file_browser_handler'); | 7 var fileBrowserNatives = requireNative('file_browser_handler'); |
8 var GetExternalFileEntry = fileBrowserNatives.GetExternalFileEntry; | 8 var GetExternalFileEntry = fileBrowserNatives.GetExternalFileEntry; |
9 | 9 |
10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
11 | 11 |
12 chromeHidden.Event.registerArgumentMassager('fileBrowserHandler.onExecute', | 12 chromeHidden.Event.registerArgumentMassager('fileBrowserHandler.onExecute', |
13 function(args) { | 13 function(args, dispatch) { |
14 if (args.length < 2) | 14 if (args.length < 2) { |
| 15 dispatch(args); |
15 return; | 16 return; |
| 17 } |
16 var fileList = args[1].entries; | 18 var fileList = args[1].entries; |
17 if (!fileList) | 19 if (!fileList) { |
| 20 dispatch(args); |
18 return; | 21 return; |
| 22 } |
19 // The second parameter for this event's payload is file definition | 23 // The second parameter for this event's payload is file definition |
20 // dictionary that we used to reconstruct File API's Entry instance | 24 // dictionary that we used to reconstruct File API's Entry instance |
21 // here. | 25 // here. |
22 for (var i = 0; i < fileList.length; i++) | 26 for (var i = 0; i < fileList.length; i++) |
23 fileList[i] = GetExternalFileEntry(fileList[i]); | 27 fileList[i] = GetExternalFileEntry(fileList[i]); |
| 28 dispatch(args); |
24 }); | 29 }); |
25 | 30 |
26 chromeHidden.registerCustomHook('fileBrowserHandler', function(bindingsAPI) { | 31 chromeHidden.registerCustomHook('fileBrowserHandler', function(bindingsAPI) { |
27 var apiFunctions = bindingsAPI.apiFunctions; | 32 var apiFunctions = bindingsAPI.apiFunctions; |
28 | 33 |
29 apiFunctions.setHandleRequest('selectFile', | 34 apiFunctions.setHandleRequest('selectFile', |
30 function(selectionParams, callback) { | 35 function(selectionParams, callback) { |
31 function internalCallback(externalCallback, internalResult) { | 36 function internalCallback(externalCallback, internalResult) { |
32 if (!externalCallback) | 37 if (!externalCallback) |
33 return; | 38 return; |
34 var result = undefined; | 39 var result = undefined; |
35 if (internalResult) { | 40 if (internalResult) { |
36 result = { success: internalResult.success, entry: null }; | 41 result = { success: internalResult.success, entry: null }; |
37 if (internalResult.success) | 42 if (internalResult.success) |
38 result.entry = GetExternalFileEntry(internalResult.entry); | 43 result.entry = GetExternalFileEntry(internalResult.entry); |
39 } | 44 } |
40 | 45 |
41 externalCallback(result); | 46 externalCallback(result); |
42 } | 47 } |
43 | 48 |
44 return chromeHidden.internalAPIs.fileBrowserHandlerInternal.selectFile( | 49 return chromeHidden.internalAPIs.fileBrowserHandlerInternal.selectFile( |
45 selectionParams, internalCallback.bind(null, callback)); | 50 selectionParams, internalCallback.bind(null, callback)); |
46 }); | 51 }); |
47 }); | 52 }); |
OLD | NEW |