KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > impl > HistoryImplIE6


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.user.client.impl;
17
18 import com.google.gwt.user.client.Element;
19
20 /**
21  * Internet Explorer 6 implementation of
22  * {@link com.google.gwt.user.client.impl.HistoryImplFrame}.
23  */

24 class HistoryImplIE6 extends HistoryImplFrame {
25
26   private static native void initUrlCheckTimer() /*-{
27     // This is the URL check timer. It detects when an unexpected change
28     // occurs in the document's URL (e.g. when the user enters one manually
29     // or selects a 'favorite', but only the #hash part changes). When this
30     // occurs, we _must_ reload the page. This is because IE has a really
31     // nasty bug that totally mangles its history stack and causes the location
32     // bar in the UI to stop working under these circumstances.
33     var urlChecker = function() {
34       var hash = $wnd.location.hash;
35       if (hash.length > 0) {
36         var token = '';
37         try {
38           token = decodeURIComponent(hash.substring(1));
39         } catch (e) {
40           // If there's a bad hash, always reload. This could only happen if
41           // if someone entered or linked to a bad url.
42           $wnd.location.reload();
43         }
44
45         if ($wnd.__gwt_historyToken && (token != $wnd.__gwt_historyToken)) {
46           $wnd.location.reload();
47         }
48       }
49       $wnd.setTimeout(urlChecker, 250);
50     };
51     urlChecker();
52   }-*/
;
53
54   public boolean init() {
55     if (!super.init()) {
56       return false;
57     }
58     initUrlCheckTimer();
59     return true;
60   }
61
62   protected native String JavaDoc getTokenElementContent(Element tokenElement) /*-{
63     return tokenElement.innerText;
64   }-*/
;
65
66   protected native void initHistoryToken() /*-{
67     // Get the initial token from the url's hash component.
68     var hash = $wnd.location.hash;
69     if (hash.length > 0) {
70       try {
71         $wnd.__gwt_historyToken = decodeURIComponent(hash.substring(1));
72       } catch (e) {
73         // Clear the bad hash and __gwt_historyToken
74         // (this can't have been a valid token).
75         $wnd.location.hash = '';
76         $wnd.__gwt_historyToken = '';
77       }
78       return;
79     }
80
81     // There was no hash. Just start off with an empty token.
82     $wnd.__gwt_historyToken = '';
83   }-*/
;
84
85   protected native void injectGlobalHandler() /*-{
86     $wnd.__gwt_onHistoryLoad = function(token) {
87       // Change the URL and notify the application that its history frame
88       // is changing.
89       if (token != $wnd.__gwt_historyToken) {
90         $wnd.__gwt_historyToken = token;
91         $wnd.location.hash = encodeURIComponent(token);
92         @com.google.gwt.user.client.impl.HistoryImpl::onHistoryChanged(Ljava/lang/String;)(token);
93       }
94     };
95   }-*/
;
96
97   protected native void newItemImpl(Element historyFrame, String JavaDoc historyToken, boolean forceAdd) /*-{
98     historyToken = historyToken || "";
99
100     if (forceAdd || ($wnd.__gwt_historyToken != historyToken)) {
101       var doc = historyFrame.contentWindow.document;
102       doc.open();
103       doc.write('<html><body onload="if(parent.__gwt_onHistoryLoad)parent.__gwt_onHistoryLoad(__gwt_historyToken.innerText)"><div id="__gwt_historyToken">' + historyToken + '</div></body></html>');
104       doc.close();
105     }
106   }-*/
;
107 }
108
Popular Tags