⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.js

📁 Here is utils.js.zip for linux web probrammer.
💻 JS
📖 第 1 页 / 共 4 页
字号:
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is the Places Command Controller. * * The Initial Developer of the Original Code is Google Inc. * Portions created by the Initial Developer are Copyright (C) 2005 * the Initial Developer. All Rights Reserved. * * Contributor(s): *   Ben Goodger <beng@google.com> *   Myk Melez <myk@mozilla.org> *   Asaf Romano <mano@mozilla.com> *   Sungjoon Steve Won <stevewon@gmail.com> *   Dietrich Ayala <dietrich@mozilla.com> * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */function LOG(str) {  dump("*** " + str + "\n");}var EXPORTED_SYMBOLS = ["PlacesUtils"];var Ci = Components.interfaces;var Cc = Components.classes;var Cr = Components.results;const POST_DATA_ANNO = "bookmarkProperties/POSTData";const READ_ONLY_ANNO = "placesInternal/READ_ONLY";const LMANNO_FEEDURI = "livemark/feedURI";const LMANNO_SITEURI = "livemark/siteURI";//@line 62 "/home/orange/mozilla/toolkit/components/places/src/utils.js"// On other platforms, the transferable system converts "\r\n" to "\n".const NEWLINE = "\r\n";//@line 65 "/home/orange/mozilla/toolkit/components/places/src/utils.js"function QI_node(aNode, aIID) {  var result = null;  try {    result = aNode.QueryInterface(aIID);  }  catch (e) {  }  return result;}function asVisit(aNode)    { return QI_node(aNode, Ci.nsINavHistoryVisitResultNode);    }function asFullVisit(aNode){ return QI_node(aNode, Ci.nsINavHistoryFullVisitResultNode);}function asContainer(aNode){ return QI_node(aNode, Ci.nsINavHistoryContainerResultNode);}function asQuery(aNode)    { return QI_node(aNode, Ci.nsINavHistoryQueryResultNode);    }var PlacesUtils = {  // Place entries that are containers, e.g. bookmark folders or queries.  TYPE_X_MOZ_PLACE_CONTAINER: "text/x-moz-place-container",  // Place entries that are bookmark separators.  TYPE_X_MOZ_PLACE_SEPARATOR: "text/x-moz-place-separator",  // Place entries that are not containers or separators  TYPE_X_MOZ_PLACE: "text/x-moz-place",  // Place entries in shortcut url format (url\ntitle)  TYPE_X_MOZ_URL: "text/x-moz-url",  // Place entries formatted as HTML anchors  TYPE_HTML: "text/html",  // Place entries as raw URL text  TYPE_UNICODE: "text/unicode",  /**   * The Bookmarks Service.   */  get bookmarks() {    delete this.bookmarks;    return this.bookmarks = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].                            getService(Ci.nsINavBookmarksService);  },  /**   * The Nav History Service.   */  get history() {    delete this.history;    return this.history = Cc["@mozilla.org/browser/nav-history-service;1"].                          getService(Ci.nsINavHistoryService);  },  /**   * The Live Bookmark Service.   */  get livemarks() {    delete this.livemarks;    return this.livemarks = Cc["@mozilla.org/browser/livemark-service;2"].                            getService(Ci.nsILivemarkService);  },  /**   * The Annotations Service.   */  get annotations() {    delete this.annotations;    return this.annotations = Cc["@mozilla.org/browser/annotation-service;1"].                              getService(Ci.nsIAnnotationService);  },  /**   * The Favicons Service   */  get favicons() {    delete this.favicons;    return this.favicons = Cc["@mozilla.org/browser/favicon-service;1"].                           getService(Ci.nsIFaviconService);  },  /**   * The Places Tagging Service   */  get tagging() {    delete this.tagging;    return this.tagging = Cc["@mozilla.org/browser/tagging-service;1"].                          getService(Ci.nsITaggingService);  },  /**   * Makes a URI from a spec.   * @param   aSpec   *          The string spec of the URI   * @returns A URI object for the spec.   */  _uri: function PU__uri(aSpec) {    return Cc["@mozilla.org/network/io-service;1"].           getService(Ci.nsIIOService).           newURI(aSpec, null, null);  },  /**   * String bundle helpers   */  get _bundle() {    const PLACES_STRING_BUNDLE_URI =        "chrome://places/locale/places.properties";    delete this._bundle;    return this._bundle = Cc["@mozilla.org/intl/stringbundle;1"].                          getService(Ci.nsIStringBundleService).                          createBundle(PLACES_STRING_BUNDLE_URI);  },  getFormattedString: function PU_getFormattedString(key, params) {    return this._bundle.formatStringFromName(key, params, params.length);  },  getString: function PU_getString(key) {    return this._bundle.GetStringFromName(key);  },  /**   * Determines whether or not a ResultNode is a Bookmark folder.   * @param   aNode   *          A result node   * @returns true if the node is a Bookmark folder, false otherwise   */  nodeIsFolder: function PU_nodeIsFolder(aNode) {    return (aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER ||            aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT);  },  /**   * Determines whether or not a ResultNode represents a bookmarked URI.   * @param   aNode   *          A result node   * @returns true if the node represents a bookmarked URI, false otherwise   */  nodeIsBookmark: function PU_nodeIsBookmark(aNode) {    return aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_URI &&           aNode.itemId != -1;  },  /**   * Determines whether or not a ResultNode is a Bookmark separator.   * @param   aNode   *          A result node   * @returns true if the node is a Bookmark separator, false otherwise   */  nodeIsSeparator: function PU_nodeIsSeparator(aNode) {    return (aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR);  },  /**   * Determines whether or not a ResultNode is a visit item.   * @param   aNode   *          A result node   * @returns true if the node is a visit item, false otherwise   */  nodeIsVisit: function PU_nodeIsVisit(aNode) {    const NHRN = Ci.nsINavHistoryResultNode;    var type = aNode.type;    return type == NHRN.RESULT_TYPE_VISIT ||           type == NHRN.RESULT_TYPE_FULL_VISIT;  },  /**   * Determines whether or not a ResultNode is a URL item.   * @param   aNode   *          A result node   * @returns true if the node is a URL item, false otherwise   */  uriTypes: [Ci.nsINavHistoryResultNode.RESULT_TYPE_URI,             Ci.nsINavHistoryResultNode.RESULT_TYPE_VISIT,             Ci.nsINavHistoryResultNode.RESULT_TYPE_FULL_VISIT],  nodeIsURI: function PU_nodeIsURI(aNode) {    return this.uriTypes.indexOf(aNode.type) != -1;  },  /**   * Determines whether or not a ResultNode is a Query item.   * @param   aNode   *          A result node   * @returns true if the node is a Query item, false otherwise   */  nodeIsQuery: function PU_nodeIsQuery(aNode) {    return aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY;  },  /**   * Determines if a node is read only (children cannot be inserted, sometimes   * they cannot be removed depending on the circumstance)   * @param   aNode   *          A result node   * @returns true if the node is readonly, false otherwise   */  nodeIsReadOnly: function PU_nodeIsReadOnly(aNode) {    if (this.nodeIsFolder(aNode))      return this.bookmarks.getFolderReadonly(asQuery(aNode).folderItemId);    if (this.nodeIsQuery(aNode) &&        asQuery(aNode).queryOptions.resultType !=          Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_CONTENTS)      return aNode.childrenReadOnly;    return false;  },  /**   * Determines whether or not a ResultNode is a host container.   * @param   aNode   *          A result node   * @returns true if the node is a host container, false otherwise   */  nodeIsHost: function PU_nodeIsHost(aNode) {    return aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY &&           aNode.parent &&           asQuery(aNode.parent).queryOptions.resultType ==             Ci.nsINavHistoryQueryOptions.RESULTS_AS_SITE_QUERY;  },  /**   * Determines whether or not a ResultNode is a day container.   * @param   node   *          A NavHistoryResultNode   * @returns true if the node is a day container, false otherwise   */  nodeIsDay: function PU_nodeIsDay(aNode) {    var resultType;    return aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY &&           aNode.parent &&           ((resultType = asQuery(aNode.parent).queryOptions.resultType) ==               Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_QUERY ||             resultType == Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_SITE_QUERY);  },  /**   * Determines whether or not a result-node is a tag container.   * @param   aNode   *          A result-node   * @returns true if the node is a tag container, false otherwise   */  nodeIsTagQuery: function PU_nodeIsTagQuery(aNode) {    return aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY &&           asQuery(aNode).queryOptions.resultType ==             Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_CONTENTS;  },  /**   * Determines whether or not a ResultNode is a container.   * @param   aNode   *          A result node   * @returns true if the node is a container item, false otherwise   */  containerTypes: [Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER,                   Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT,                   Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY,                   Ci.nsINavHistoryResultNode.RESULT_TYPE_DYNAMIC_CONTAINER],  nodeIsContainer: function PU_nodeIsContainer(aNode) {    return this.containerTypes.indexOf(aNode.type) != -1;  },  /**   * Determines whether or not a ResultNode is an history related container.   * @param   node   *          A result node   * @returns true if the node is an history related container, false otherwise   */  nodeIsHistoryContainer: function PU_nodeIsHistoryContainer(aNode) {    var resultType;    return this.nodeIsQuery(aNode) &&           ((resultType = asQuery(aNode).queryOptions.resultType) ==              Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_SITE_QUERY ||            resultType == Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_QUERY ||            resultType == Ci.nsINavHistoryQueryOptions.RESULTS_AS_SITE_QUERY ||            this.nodeIsDay(aNode) ||            this.nodeIsHost(aNode));  },  /**   * Determines whether or not a result-node is a dynamic-container item.   * The dynamic container result node type is for dynamically created   * containers (e.g. for the file browser service where you get your folders   * in bookmark menus).   * @param   aNode   *          A result node   * @returns true if the node is a dynamic container item, false otherwise   */  nodeIsDynamicContainer: function PU_nodeIsDynamicContainer(aNode) {    if (aNode.type == NHRN.RESULT_TYPE_DYNAMIC_CONTAINER)      return true;    return false;  }, /**  * Determines whether a result node is a remote container registered by the  * livemark service.  * @param aNode  *        A result Node  * @returns true if the node is a livemark container item  */  nodeIsLivemarkContainer: function PU_nodeIsLivemarkContainer(aNode) {    // Use the annotations service directly to avoid instantiating    // the Livemark service on startup. (bug 398300)    return this.nodeIsFolder(aNode) &&           this.annotations.itemHasAnnotation(aNode.itemId, LMANNO_FEEDURI);  }, /**  * Determines whether a result node is a live-bookmark item  * @param aNode  *        A result node  * @returns true if the node is a livemark container item  */  nodeIsLivemarkItem: function PU_nodeIsLivemarkItem(aNode) {    return aNode.parent && this.nodeIsLivemarkContainer(aNode.parent);  },  /**   * Determines whether or not a node is a readonly folder.   * @param   aNode   *          The node to test.   * @returns true if the node is a readonly folder.  */  isReadonlyFolder: function(aNode) {    return this.nodeIsFolder(aNode) &&           this.bookmarks.getFolderReadonly(asQuery(aNode).folderItemId);  },  /**   * Gets the concrete item-id for the given node. Generally, this is just   * node.itemId, but for folder-shortcuts that's node.folderItemId.   */  getConcreteItemId: function PU_getConcreteItemId(aNode) {    if (aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT)      return asQuery(aNode).folderItemId;    else if (PlacesUtils.nodeIsTagQuery(aNode)) {      // RESULTS_AS_TAG_CONTENTS queries are similar to folder shortcuts      // so we can still get the concrete itemId for them.      var queries = aNode.getQueries({});      var folders = queries[0].getFolders({});      return folders[0];    }    return aNode.itemId;  },  /**   * Gets the index of a node within its parent container   * @param   aNode   *          The node to look up   * @returns The index of the node within its parent container, or -1 if the   *          node was not found or the node specified has no parent.   */  getIndexOfNode: function PU_getIndexOfNode(aNode) {    var parent = aNode.parent;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -