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