1
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
41
var commandHandler = null;
44
function nsCommandHandler()
48
nsCommandHandler.prototype =
50
QueryInterface : function(iid)
52
if (iid.equals(Components.interfaces.nsICommandHandler) ||
53
iid.equals(Components.interfaces.nsISupports))
57
throw Components.results.NS_NOINTERFACE;
60
exec : function(command, params)
63
query : function(command, params, result)
71
function nsBrowserStatusHandler()
76
nsBrowserStatusHandler.prototype =
78
QueryInterface : function(aIID)
80
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
81
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
82
aIID.equals(Components.interfaces.nsISupports))
86
throw Components.results.NS_NOINTERFACE;
91
this.urlBar = document.getElementById("urlbar");
99
onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
103
onProgressChange : function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
107
onLocationChange : function(aWebProgress, aRequest, aLocation)
109
domWindow = aWebProgress.DOMWindow;
110
// Update urlbar only if there was a load on the root docshell
111
if (domWindow == domWindow.top) {
112
this.urlBar.value = location;
116
onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
120
onSecurityChange : function(aWebProgress, aRequest, aState)
125
var gBrowserStatusHandler;
126
function MiniNavStartup()
128
dump("*** MiniNavStartup\n");
131
gBrowserStatusHandler = new nsBrowserStatusHandler();
132
var webNavigation = getWebNavigation();
133
webNavigation.sessionHistory = Components.classes["@mozilla.org/browser/shistory;1"]
134
.createInstance(Components.interfaces.nsISHistory);
136
var interfaceRequestor = getBrowser().docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
137
var webProgress = interfaceRequestor.getInterface(Components.interfaces.nsIWebProgress);
138
webProgress.addProgressListener(gBrowserStatusHandler, Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
140
alert("Error opening a mini-nav window");
146
// create the embedding command handler
147
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
148
var commandHandlerInit = Components
149
.classes["@mozilla.org/embedding/browser/nsCommandHandler;1"]
150
.createInstance(Components.interfaces.nsICommandHandlerInit);
152
// Attach it to the window
153
commandHandlerInit.window = window;
154
commandHandler = commandHandlerInit.QueryInterface(Components.interfaces.nsICommandHandler);
156
gURLBar = document.getElementById("urlbar");
157
dump("gURLBar " + gURLBar + "\n");
160
function MiniNavShutdown()
162
dump("*** MiniNavShutdown\n");
163
if (gBrowserStatusHandler)
164
gBrowserStatusHandler.destroy();
167
function getBrowser()
169
return document.getElementById("content");
172
function getWebNavigation()
174
return getBrowser().webNavigation;
177
function CHExecTest()
179
if (commandHandler != null)
181
commandHandler.exec("hello", "xxx");
185
function CHQueryTest()
187
if (commandHandler != null)
189
var result = commandHandler.query("hello", "xxx");
193
function InitContextMenu(xulMenu)
195
// Back determined by canGoBack broadcaster.
196
InitMenuItemAttrFromNode( "context-back", "disabled", "canGoBack" );
198
// Forward determined by canGoForward broadcaster.
199
InitMenuItemAttrFromNode( "context-forward", "disabled", "canGoForward" );
202
function InitMenuItemAttrFromNode( item_id, attr, other_id )
204
var elem = document.getElementById( other_id );
205
if ( elem && elem.getAttribute( attr ) == "true" ) {
206
SetMenuItemAttr( item_id, attr, "true" );
208
SetMenuItemAttr( item_id, attr, null );
212
function SetMenuItemAttr( id, attr, val )
214
var elem = document.getElementById( id );
217
// null indicates attr should be removed.
218
elem.removeAttribute( attr );
221
elem.setAttribute( attr, val );
226
function loadURI(uri)
228
getWebNavigation().loadURI(uri, nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
231
function BrowserLoadURL()
233
dump("browserloadurl: " + gURLBar.value + '\n');
235
loadURI(gURLBar.value);
241
function BrowserBack()
243
getWebNavigation().goBack();
246
function BrowserForward()
248
getWebNavigation().goForward();
251
function BrowserStop()
253
getWebNavigation().stop(nsIWebNavigation.STOP_ALL);
256
function BrowserReload()
258
getWebNavigation().reload(nsIWebNavigation.LOAD_FLAGS_NONE);