addon-sdk/source/lib/sdk/places/history.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 module.metadata = {
michael@0 8 "stability": "unstable",
michael@0 9 "engines": {
michael@0 10 "Firefox": "*"
michael@0 11 }
michael@0 12 };
michael@0 13
michael@0 14 /*
michael@0 15 * Requiring hosts so they can subscribe to client messages
michael@0 16 */
michael@0 17 require('./host/host-bookmarks');
michael@0 18 require('./host/host-tags');
michael@0 19 require('./host/host-query');
michael@0 20
michael@0 21 const { Cc, Ci } = require('chrome');
michael@0 22 const { Class } = require('../core/heritage');
michael@0 23 const { events, send } = require('../addon/events');
michael@0 24 const { defer, reject, all } = require('../core/promise');
michael@0 25 const { uuid } = require('../util/uuid');
michael@0 26 const { flatten } = require('../util/array');
michael@0 27 const { has, extend, merge, pick } = require('../util/object');
michael@0 28 const { emit } = require('../event/core');
michael@0 29 const { defer: async } = require('../lang/functional');
michael@0 30 const { EventTarget } = require('../event/target');
michael@0 31 const {
michael@0 32 urlQueryParser, createQuery, createQueryOptions
michael@0 33 } = require('./utils');
michael@0 34
michael@0 35 /*
michael@0 36 * Constant used by nsIHistoryQuery; 0 is a history query
michael@0 37 * https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsINavHistoryQueryOptions
michael@0 38 */
michael@0 39 const HISTORY_QUERY = 0;
michael@0 40
michael@0 41 let search = function query (queries, options) {
michael@0 42 queries = [].concat(queries);
michael@0 43 let emitter = EventTarget();
michael@0 44 let queryObjs = queries.map(createQuery.bind(null, HISTORY_QUERY));
michael@0 45 let optionsObj = createQueryOptions(HISTORY_QUERY, options);
michael@0 46
michael@0 47 // Can remove after `Promise.jsm` is implemented in Bug 881047,
michael@0 48 // which will guarantee next tick execution
michael@0 49 async(() => {
michael@0 50 send('sdk-places-query', {
michael@0 51 query: queryObjs,
michael@0 52 options: optionsObj
michael@0 53 }).then(results => {
michael@0 54 results.map(item => emit(emitter, 'data', item));
michael@0 55 emit(emitter, 'end', results);
michael@0 56 }, reason => {
michael@0 57 emit(emitter, 'error', reason);
michael@0 58 emit(emitter, 'end', []);
michael@0 59 });
michael@0 60 })();
michael@0 61
michael@0 62 return emitter;
michael@0 63 };
michael@0 64 exports.search = search;

mercurial