/
NavigationImpl.java
248 lines (198 loc) · 6.71 KB
/
NavigationImpl.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
* 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 RaptorCanvas.
*
* The Initial Developer of the Original Code is Kirk Baker and
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
* Rights Reserved.
*
* Contributor(s): Ed Burns <edburns@acm.org>
* Brian Satterfield <bsatterf@atl.lmco.com>
* Anthony Sizer <sizera@yahoo.com>
*/
package org.mozilla.webclient.impl.wrapper_native;
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
import org.mozilla.util.RangeException;
import org.mozilla.webclient.BrowserControl;
import org.mozilla.webclient.Navigation;
import org.mozilla.webclient.Navigation2;
import org.mozilla.webclient.WindowControl;
import org.mozilla.webclient.impl.WrapperFactory;
import org.mozilla.webclient.Prompt;
import java.io.InputStream;
import java.util.Properties;
public class NavigationImpl extends ImplObjectNative implements Navigation2
{
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public NavigationImpl(WrapperFactory yourFactory,
BrowserControl yourBrowserControl) {
super(yourFactory, yourBrowserControl);
}
//
// Class methods
//
//
// General Methods
//
//
// Methods from Navigation
//
public void loadURL(String absoluteURL)
{
ParameterCheck.nonNull(absoluteURL);
getWrapperFactory().verifyInitialized();
final int bc = getNativeBrowserControl();
final String url = new String(absoluteURL);
Assert.assert_it(-1 != bc);
NativeEventThread.instance.pushRunnable(new Runnable() {
public void run() {
NavigationImpl.this.nativeLoadURL(bc, url);
}
});
}
public void loadFromStream(InputStream stream, String uri,
String contentType, int contentLength,
Properties loadInfo)
{
ParameterCheck.nonNull(stream);
ParameterCheck.nonNull(uri);
ParameterCheck.nonNull(contentType);
if (contentLength < -1 || contentLength == 0) {
throw new RangeException("contentLength value " + contentLength +
" is out of range. It is should be either -1 or greater than 0.");
}
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
synchronized(getBrowserControl()) {
nativeLoadFromStream(getNativeBrowserControl(), stream,
uri, contentType, contentLength,
loadInfo);
}
}
public void refresh(long loadFlags)
{
ParameterCheck.noLessThan(loadFlags, 0);
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
synchronized(getBrowserControl()) {
nativeRefresh(getNativeBrowserControl(), loadFlags);
}
}
public void stop()
{
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
synchronized(getBrowserControl()) {
nativeStop(getNativeBrowserControl());
}
}
public void setPrompt(Prompt yourPrompt)
{
ParameterCheck.nonNull(yourPrompt);
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
synchronized(getBrowserControl()) {
nativeSetPrompt(getNativeBrowserControl(), yourPrompt);
}
}
//
// Methods from Navigation2
//
public void post(String absoluteUrl,
String target,
String postData,
String postHeaders)
{
ParameterCheck.nonNull(absoluteUrl);
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
int postDataLength = 0;
int postHeadersLength = 0;
// PENDING(edburns): make it so the url doesn't have to be absolute.
// PENDING(edburns): check postData and postHeaders for correct
// "\r\n" as specified in Navigation.java
if (postData != null){
postDataLength = postData.length();
}
if (postHeaders != null){
postHeadersLength = postHeaders.length();
}
synchronized(getBrowserControl()) {
nativePost(getNativeBrowserControl(),
absoluteUrl,
target,
postDataLength,
postData,
postHeadersLength,
postHeaders);
}
}
//
// Native methods
//
public native void nativeLoadURL(int webShellPtr, String absoluteURL);
public native void nativeLoadFromStream(int webShellPtr, InputStream stream,
String uri,
String contentType,
int contentLength,
Properties loadInfo);
public native void nativePost(int webShellPtr,
String absoluteUrl,
String target,
int postDataLength,
String postData,
int PostHeadersLength,
String postHeaders);
public native void nativeRefresh(int webShellPtr, long loadFlags);
public native void nativeStop(int webShellPtr);
public native void nativeSetPrompt(int webShellPtr, Prompt yourPrompt);
// ----VERTIGO_TEST_START
//
// Test methods
//
public static void main(String [] args)
{
Assert.setEnabled(true);
Log.setApplicationName("NavigationImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.5 2004/04/17 21:25:11 edburns%acm.org Exp $");
try {
org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]);
org.mozilla.webclient.BrowserControl control =
org.mozilla.webclient.BrowserControlFactory.newBrowserControl();
Assert.assert_it(control != null);
Navigation wc = (Navigation)
control.queryInterface(org.mozilla.webclient.BrowserControl.WINDOW_CONTROL_NAME);
Assert.assert_it(wc != null);
}
catch (Exception e) {
System.out.println("got exception: " + e.getMessage());
}
}
// ----VERTIGO_TEST_END
} // end of class NavigationImpl