Chromium Code Reviews| 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 chrome.app.runtime API. | 5 // Custom bindings for the chrome.app.runtime API. |
| 6 | 6 |
| 7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 8 var fileSystemHelpers = requireNative('file_system_natives'); | 8 var fileSystemHelpers = requireNative('file_system_natives'); |
| 9 var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem; | 9 var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem; |
| 10 var appNatives = requireNative('app_runtime'); | 10 var appNatives = requireNative('app_runtime'); |
| 11 var DeserializeString = appNatives.DeserializeString; | 11 var DeserializeString = appNatives.DeserializeString; |
| 12 var SerializeToString = appNatives.SerializeToString; | |
| 12 var CreateBlob = appNatives.CreateBlob; | 13 var CreateBlob = appNatives.CreateBlob; |
| 13 | 14 |
| 14 chromeHidden.Event.registerArgumentMassager('app.runtime.onLaunched', | 15 chromeHidden.Event.registerArgumentMassager('app.runtime.onLaunched', |
| 15 function(args, dispatch) { | 16 function(args, dispatch) { |
| 16 var launchData = args[0]; | 17 var launchData = args[0]; |
| 17 var intentData = args[1]; | 18 var intentData = args[1]; |
| 19 var intentId = args[2]; | |
| 20 | |
| 21 if (launchData) { | |
| 22 if (intentId) { | |
| 23 var fn = function(success, data) { | |
| 24 // TODO(thorogood): What if data is not of a serializable type? | |
|
benwells
2012/08/29 12:19:21
We should answer this question before landing this
thorogood
2012/09/03 03:37:40
I have answered it, as discussed in person! Non-se
| |
| 25 chrome.app.runtime.postIntentResponse({ | |
| 26 'intentId': intentId, | |
| 27 'success': success, | |
| 28 'data': SerializeToString(data) | |
| 29 }); | |
| 30 }; | |
| 31 launchData.intent.postResult = fn.bind(undefined, true); | |
| 32 launchData.intent.postFailure = fn.bind(undefined, false); | |
| 33 } else { | |
| 34 launchData.intent.postResult = function() {}; | |
| 35 launchData.intent.postFailure = function() {}; | |
| 36 } | |
| 37 } | |
| 18 | 38 |
| 19 if (launchData && intentData) { | 39 if (launchData && intentData) { |
| 20 switch(intentData.format) { | 40 switch(intentData.format) { |
| 21 case('fileEntry'): | 41 case('fileEntry'): |
| 22 var fs = GetIsolatedFileSystem(intentData.fileSystemId); | 42 var fs = GetIsolatedFileSystem(intentData.fileSystemId); |
| 23 try { | 43 try { |
| 24 fs.root.getFile(intentData.baseName, {}, function(fileEntry) { | 44 fs.root.getFile(intentData.baseName, {}, function(fileEntry) { |
| 25 launchData.intent.data = fileEntry; | 45 launchData.intent.data = fileEntry; |
| 26 launchData.intent.postResult = function() {}; | |
| 27 launchData.intent.postFailure = function() {}; | |
| 28 dispatch([launchData]); | 46 dispatch([launchData]); |
| 29 }, function(fileError) { | 47 }, function(fileError) { |
| 30 console.error('Error getting fileEntry, code: ' + fileError.code); | 48 console.error('Error getting fileEntry, code: ' + fileError.code); |
| 31 dispatch([]); | 49 dispatch([]); |
| 32 }); | 50 }); |
| 33 } catch (e) { | 51 } catch (e) { |
| 34 console.error('Error in event handler for onLaunched: ' + e.stack); | 52 console.error('Error in event handler for onLaunched: ' + e.stack); |
| 35 dispatch([]); | 53 dispatch([]); |
| 36 } | 54 } |
| 37 break; | 55 break; |
| 38 case('serialized'): | 56 case('serialized'): |
| 39 var deserializedData = DeserializeString(intentData.data); | 57 var deserializedData = DeserializeString(intentData.data); |
| 40 launchData.intent.data = deserializedData; | 58 launchData.intent.data = deserializedData; |
| 41 launchData.intent.postResult = function() {}; | |
| 42 launchData.intent.postFailure = function() {}; | |
| 43 dispatch([launchData]); | 59 dispatch([launchData]); |
| 44 break; | 60 break; |
| 45 case('blob'): | 61 case('blob'): |
| 46 var blobData = CreateBlob(intentData.blobFilePath, | 62 var blobData = CreateBlob(intentData.blobFilePath, |
| 47 intentData.blobLength); | 63 intentData.blobLength); |
| 48 launchData.intent.data = blobData; | 64 launchData.intent.data = blobData; |
| 49 launchData.intent.postResult = function() {}; | |
| 50 launchData.intent.postFailure = function() {}; | |
| 51 dispatch([launchData]); | 65 dispatch([launchData]); |
| 52 break; | 66 break; |
| 53 default: | 67 default: |
| 54 console.error('Unexpected launch data format'); | 68 console.error('Unexpected launch data format'); |
| 55 dispatch([]); | 69 dispatch([]); |
| 56 } | 70 } |
| 57 } else if (launchData) { | 71 } else if (launchData) { |
| 58 dispatch([launchData]); | 72 dispatch([launchData]); |
| 59 } else { | 73 } else { |
| 60 dispatch([]); | 74 dispatch([]); |
| 61 } | 75 } |
| 62 }); | 76 }); |
| OLD | NEW |