openLocation.js
Go to the documentation of this file.
1 # -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 #
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 #
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
10 #
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
15 #
16 # The Original Code is Mozilla Communicator client code, released
17 # March 31, 1998.
18 #
19 # The Initial Developer of the Original Code is
20 # Netscape Communications Corporation.
21 # Portions created by the Initial Developer are Copyright (C) 1998
22 # the Initial Developer. All Rights Reserved.
23 #
24 # Contributor(s):
25 # Michael Lowe <michael.lowe@bigfoot.com>
26 # Blake Ross <blaker@netscape.com>
27 #
28 # Alternatively, the contents of this file may be used under the terms of
29 # either the GNU General Public License Version 2 or later (the "GPL"), or
30 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 # in which case the provisions of the GPL or the LGPL are applicable instead
32 # of those above. If you wish to allow use of your version of this file only
33 # under the terms of either the GPL or the LGPL, and not to allow others to
34 # use your version of this file under the terms of the MPL, indicate your
35 # decision by deleting the provisions above and replace them with the notice
36 # and other provisions required by the GPL or the LGPL. If you do not delete
37 # the provisions above, a recipient may use your version of this file under
38 # the terms of any one of the MPL, the GPL or the LGPL.
39 #
40 # ***** END LICENSE BLOCK *****
41 
42 var browser;
43 var dialog = {};
44 var pref = null;
45 try {
46  pref = Components.classes["@mozilla.org/preferences-service;1"]
47  .getService(Components.interfaces.nsIPrefBranch);
48 } catch (ex) {
49  // not critical, remain silent
50 }
51 
52 Components.utils.import("resource:///modules/openLocationLastURL.jsm");
53 
54 function onLoad()
55 {
56  dialog.input = document.getElementById("dialog.input");
57  dialog.open = document.documentElement.getButton("accept");
58  dialog.openWhereList = document.getElementById("openWhereList");
59  dialog.openTopWindow = document.getElementById("currentWindow");
60  dialog.bundle = document.getElementById("openLocationBundle");
61 
62  if ("arguments" in window && window.arguments.length >= 1)
63  browser = window.arguments[0];
64 
65  dialog.openWhereList.selectedItem = dialog.openTopWindow;
66 
67  if (pref) {
68  try {
69  var useAutoFill = pref.getBoolPref("browser.urlbar.autoFill");
70  if (useAutoFill)
71  dialog.input.setAttribute("completedefaultindex", "true");
72  } catch (ex) {}
73 
74  try {
75  var value = pref.getIntPref("general.open_location.last_window_choice");
76  var element = dialog.openWhereList.getElementsByAttribute("value", value)[0];
77  if (element)
78  dialog.openWhereList.selectedItem = element;
79  dialog.input.value = gOpenLocationLastURL.value;
80  }
81  catch(ex) {
82  }
83  if (dialog.input.value)
84  dialog.input.select(); // XXX should probably be done automatically
85  }
86 
87  doEnabling();
88 }
89 
90 function doEnabling()
91 {
92  dialog.open.disabled = !dialog.input.value;
93 }
94 
95 function open()
96 {
97  var url;
98  var postData = {};
99  if (browser)
100  url = browser.getShortcutOrURI(dialog.input.value, postData);
101  else
102  url = dialog.input.value;
103 
104  try {
105  // Whichever target we use for the load, we allow third-party services to
106  // fixup the URI
107  switch (dialog.openWhereList.value) {
108  case "0":
109  browser.loadURI(url, null, postData.value, true);
110  break;
111  case "1":
112  window.opener.delayedOpenWindow(getBrowserURL(), "all,dialog=no",
113  url, postData.value, null, null, true);
114  break;
115  case "3":
116  browser.delayedOpenTab(url, null, null, postData.value, true);
117  break;
118  }
119  }
120  catch(exception) {
121  }
122 
123  if (pref) {
124  gOpenLocationLastURL.value = dialog.input.value;
125  pref.setIntPref("general.open_location.last_window_choice", dialog.openWhereList.value);
126  }
127 
128  // Delay closing slightly to avoid timing bug on Linux.
129  window.close();
130  return false;
131 }
132 
133 function createInstance(contractid, iidName)
134 {
135  var iid = Components.interfaces[iidName];
136  return Components.classes[contractid].createInstance(iid);
137 }
138 
139 const nsIFilePicker = Components.interfaces.nsIFilePicker;
140 function onChooseFile()
141 {
142  try {
143  var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
144  fp.init(window, dialog.bundle.getString("chooseFileDialogTitle"), nsIFilePicker.modeOpen);
145  fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterText |
146  nsIFilePicker.filterAll | nsIFilePicker.filterImages | nsIFilePicker.filterXML);
147 
148  if (fp.show() == nsIFilePicker.returnOK && fp.fileURL.spec && fp.fileURL.spec.length > 0)
149  dialog.input.value = fp.fileURL.spec;
150  }
151  catch(ex) {
152  }
153  doEnabling();
154 }
function open()
Definition: openLocation.js:95
var pref
Definition: openLocation.js:44
let window
let gOpenLocationLastURL
function createInstance(contractid, iidName)
var dialog
Definition: openLocation.js:43
function onLoad()
Definition: openLocation.js:54
const nsIFilePicker
function getBrowserURL()
return null
Definition: FeedWriter.js:1143
function onChooseFile()
function url(spec)
countRef value
Definition: FeedWriter.js:1423
function doEnabling()
Definition: openLocation.js:90
var browser
Definition: openLocation.js:42