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 experimental.app API. | 5 // Custom bindings for the experimental.app 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('experimental_app'); | 10 var appNatives = requireNative('experimental_app'); |
| 11 var DeserializeString = appNatives.DeserializeString; | 11 var DeserializeString = appNatives.DeserializeString; |
| 12 var CreateBlob = appNatives.CreateBlob; | 12 var CreateBlob = appNatives.CreateBlob; |
| 13 | 13 |
| 14 chromeHidden.Event.registerArgumentMassager('experimental.app.onLaunched', | 14 chromeHidden.Event.registerArgumentMassager('experimental.app.onLaunched', |
| 15 function(args, dispatch) { | 15 function(args, dispatch) { |
| 16 var launchData = args[0]; | 16 var id = args[0]; |
| 17 var intentData = args[1]; | 17 var launchData = args[1]; |
| 18 var intentData = args[2]; | |
| 19 | |
| 20 if (launchData) { | |
| 21 var fn = chrome.experimental.app.postIntentResponse; | |
| 22 | |
| 23 launchData.intent.postResult = function(data) { | |
| 24 fn({ 'intentId': id, 'success': true, 'data': data }); | |
|
koz (OOO until 15th September)
2012/08/08 04:47:30
no spaces after curlies, here and below.
thorogood
2012/08/08 07:15:49
I've put the dictionary definition on multiple lin
| |
| 25 }; | |
| 26 launchData.intent.postFailure = function(data) { | |
| 27 fn({ 'intentId': id, 'success': false, 'data': data }); | |
| 28 }; | |
| 29 } | |
| 18 | 30 |
| 19 if (launchData && intentData) { | 31 if (launchData && intentData) { |
| 20 switch(intentData.format) { | 32 switch(intentData.format) { |
| 21 case('fileEntry'): | 33 case('fileEntry'): |
| 22 var fs = GetIsolatedFileSystem(intentData.fileSystemId); | 34 var fs = GetIsolatedFileSystem(intentData.fileSystemId); |
| 23 try { | 35 try { |
| 24 fs.root.getFile(intentData.baseName, {}, function(fileEntry) { | 36 fs.root.getFile(intentData.baseName, {}, function(fileEntry) { |
| 25 launchData.intent.data = fileEntry; | 37 launchData.intent.data = fileEntry; |
| 26 launchData.intent.postResult = function() {}; | |
| 27 launchData.intent.postFailure = function() {}; | |
| 28 dispatch([launchData]); | 38 dispatch([launchData]); |
| 29 }, function(fileError) { | 39 }, function(fileError) { |
| 30 console.error('Error getting fileEntry, code: ' + fileError.code); | 40 console.error('Error getting fileEntry, code: ' + fileError.code); |
| 31 dispatch([]); | 41 dispatch([]); |
| 32 }); | 42 }); |
| 33 } catch (e) { | 43 } catch (e) { |
| 34 console.error('Error in event handler for onLaunched: ' + e.stack); | 44 console.error('Error in event handler for onLaunched: ' + e.stack); |
| 35 dispatch([]); | 45 dispatch([]); |
| 36 } | 46 } |
| 37 break; | 47 break; |
| 38 case('serialized'): | 48 case('serialized'): |
| 39 var deserializedData = DeserializeString(intentData.data); | 49 var deserializedData = DeserializeString(intentData.data); |
| 40 launchData.intent.data = deserializedData; | 50 launchData.intent.data = deserializedData; |
| 41 launchData.intent.postResult = function() {}; | |
| 42 launchData.intent.postFailure = function() {}; | |
| 43 dispatch([launchData]); | 51 dispatch([launchData]); |
| 44 break; | 52 break; |
| 45 case('blob'): | 53 case('blob'): |
| 46 var blobData = CreateBlob(intentData.blobFilePath, | 54 var blobData = CreateBlob(intentData.blobFilePath, |
| 47 intentData.blobLength); | 55 intentData.blobLength); |
| 48 launchData.intent.data = blobData; | 56 launchData.intent.data = blobData; |
| 49 launchData.intent.postResult = function() {}; | |
| 50 launchData.intent.postFailure = function() {}; | |
| 51 dispatch([launchData]); | 57 dispatch([launchData]); |
| 52 break; | 58 break; |
| 53 default: | 59 default: |
| 54 console.error('Unexpected launch data format'); | 60 console.error('Unexpected launch data format'); |
| 55 dispatch([]); | 61 dispatch([]); |
| 56 } | 62 } |
| 57 } else if (launchData) { | 63 } else if (launchData) { |
| 58 dispatch([launchData]); | 64 dispatch([launchData]); |
| 59 } else { | 65 } else { |
| 60 dispatch([]); | 66 dispatch([]); |
| 61 } | 67 } |
| 62 }); | 68 }); |
| OLD | NEW |