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
3 // found in the LICENSE file.
5 // Called by the common.js module.
6 function attachListeners() {
7 document.getElementById('fileInput').addEventListener('change',
9 document.getElementById('listener').addEventListener('drop',
10 handleFileDrop, true);
13 function postFileContents(file) {
14 var reader = new FileReader();
15 reader.onload = function(load_event) {
16 if (common.naclModule)
17 common.naclModule.postMessage(load_event.target.result);
19 reader.readAsArrayBuffer(file);
22 // Handle a file being dropped on to the plugin's rectangle.
23 function handleFileDrop(dropEvent) {
24 if (!dropEvent.dataTransfer || !dropEvent.dataTransfer.files)
26 dropEvent.stopPropagation();
27 dropEvent.preventDefault();
28 var files = dropEvent.dataTransfer.files;
29 for(var i = 0; i < files.length; ++i)
30 postFileContents(files[i]);
33 // Handle a file being chosen from the <input type=file...> tag.
34 function handleFileInput() {
35 var file_input = document.getElementById("fileInput");
36 var files = file_input.files;
37 for(var i = 0; i < files.length; ++i)
38 postFileContents(files[i]);