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.registerCustomHook('experimental.app', function(bindingsAPI) { | 14 chromeHidden.Event.registerArgumentMassager('experimental.app.onLaunched', |
15 chrome.experimental.app.onLaunched.dispatch = | 15 function(args, dispatch) { |
16 function(launchData, intentData) { | 16 var launchData = args[0]; |
17 // TODO(benwells): Remove this logging. | 17 var intentData = args[1]; |
18 console.log("In onLaunched dispatch hook."); | 18 |
19 if (launchData && intentData) { | 19 // TODO(benwells): Remove this logging. |
20 switch(intentData.format) { | 20 console.log("In onLaunched dispatch hook."); |
21 case('fileEntry'): | 21 if (launchData && intentData) { |
22 var event = this; | 22 switch(intentData.format) { |
23 var fs = GetIsolatedFileSystem(intentData.fileSystemId); | 23 case('fileEntry'): |
24 try { | 24 var fs = GetIsolatedFileSystem(intentData.fileSystemId); |
25 fs.root.getFile(intentData.baseName, {}, function(fileEntry) { | 25 try { |
26 launchData.intent.data = fileEntry; | 26 fs.root.getFile(intentData.baseName, {}, function(fileEntry) { |
27 launchData.intent.postResult = function() {}; | 27 launchData.intent.data = fileEntry; |
28 launchData.intent.postFailure = function() {}; | 28 launchData.intent.postResult = function() {}; |
29 chrome.Event.prototype.dispatch.call(event, launchData); | 29 launchData.intent.postFailure = function() {}; |
30 }, function(fileError) { | 30 dispatch([launchData]); |
31 console.error('Error getting fileEntry, code: ' + fileError.code); | 31 }, function(fileError) { |
32 chrome.Event.prototype.dispatch.call(event); | 32 console.error('Error getting fileEntry, code: ' + fileError.code); |
33 }); | 33 dispatch([]); |
34 } catch (e) { | 34 }); |
35 console.error('Error in event handler for onLaunched: ' + e.stack); | 35 } catch (e) { |
36 chrome.Event.prototype.dispatch.call(event); | 36 console.error('Error in event handler for onLaunched: ' + e.stack); |
37 } | 37 dispatch([]); |
38 break; | 38 } |
39 case('serialized'): | 39 break; |
40 var deserializedData = DeserializeString(intentData.data); | 40 case('serialized'): |
41 launchData.intent.data = deserializedData; | 41 var deserializedData = DeserializeString(intentData.data); |
42 launchData.intent.postResult = function() {}; | 42 launchData.intent.data = deserializedData; |
43 launchData.intent.postFailure = function() {}; | 43 launchData.intent.postResult = function() {}; |
44 chrome.Event.prototype.dispatch.call(this, launchData); | 44 launchData.intent.postFailure = function() {}; |
45 break; | 45 dispatch([launchData]); |
46 case('blob'): | 46 break; |
47 var blobData = CreateBlob(intentData.blobFilePath, | 47 case('blob'): |
48 intentData.blobLength); | 48 var blobData = CreateBlob(intentData.blobFilePath, |
49 launchData.intent.data = blobData; | 49 intentData.blobLength); |
50 launchData.intent.postResult = function() {}; | 50 launchData.intent.data = blobData; |
51 launchData.intent.postFailure = function() {}; | 51 launchData.intent.postResult = function() {}; |
52 chrome.Event.prototype.dispatch.call(this, launchData); | 52 launchData.intent.postFailure = function() {}; |
53 break; | 53 dispatch([launchData]); |
54 default: | 54 break; |
55 console.error('Unexpected launch data format'); | 55 default: |
56 chrome.Event.prototype.dispatch.call(this); | 56 console.error('Unexpected launch data format'); |
57 } | 57 dispatch([]); |
58 } else if (launchData) { | |
59 chrome.Event.prototype.dispatch.call(this, launchData); | |
60 } else { | |
61 chrome.Event.prototype.dispatch.call(this); | |
62 } | 58 } |
63 }; | 59 } else if (launchData) { |
| 60 dispatch([launchData]); |
| 61 } else { |
| 62 dispatch([]); |
| 63 } |
64 }); | 64 }); |
OLD | NEW |