summaryrefslogtreecommitdiffstats
path: root/b2g/components/test/mochitest/filepicker_path_handler_chrome.js
blob: a175746cb93f264a58dccfbb27b5cee14b2071f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';

var Cc = Components.classes;
var Ci = Components.interfaces;

// use ppmm to handle file-picker message.
var ppmm = Cc['@mozilla.org/parentprocessmessagemanager;1']
             .getService(Ci.nsIMessageListenerManager);

var pickResult = null;

function processPickMessage(message) {
  let sender = message.target.QueryInterface(Ci.nsIMessageSender);
  // reply FilePicker's message
  sender.sendAsyncMessage('file-picked', pickResult);
  // notify caller
  sendAsyncMessage('file-picked-posted', { type: 'file-picked-posted' });
}

function updatePickResult(result) {
  pickResult = result;
  sendAsyncMessage('pick-result-updated', { type: 'pick-result-updated' });
}

ppmm.addMessageListener('file-picker', processPickMessage);
// use update-pick-result to change the expected pick result.
addMessageListener('update-pick-result', updatePickResult);