01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: * An IFRAME implementation of
22: * {@link com.google.gwt.user.client.impl.HistoryImpl}.
23: */
24: abstract class HistoryImplFrame extends HistoryImpl {
25:
26: private static native Element findHistoryFrame() /*-{
27: var historyFrame = $doc.getElementById('__gwt_historyFrame');
28: return historyFrame || null;
29: }-*/;
30:
31: private static native Element getTokenElement(Element historyFrame) /*-{
32: // Initialize the history iframe. If '__gwt_historyToken' already exists, then
33: // we're probably backing into the app, so _don't_ set the iframe's location.
34: var tokenElement = null;
35: if (historyFrame.contentWindow) {
36: var doc = historyFrame.contentWindow.document;
37: tokenElement = doc.getElementById('__gwt_historyToken') || null;
38: }
39: return tokenElement;
40: }-*/;
41:
42: private Element historyFrame;
43:
44: @Override
45: public boolean init() {
46: historyFrame = findHistoryFrame();
47: if (historyFrame == null) {
48: return false;
49: }
50:
51: initHistoryToken();
52:
53: // Initialize the history iframe. If a token element already exists, then
54: // we're probably backing into the app, so _don't_ create a new item.
55: Element tokenElement = getTokenElement(historyFrame);
56: if (tokenElement != null) {
57: setToken(getTokenElementContent(tokenElement));
58: } else {
59: newItemImpl(historyFrame, getToken(), true);
60: }
61:
62: injectGlobalHandler();
63: return true;
64: }
65:
66: @Override
67: public void newItem(String historyToken) {
68: newItemImpl(historyFrame, historyToken, false);
69: }
70:
71: protected abstract String getTokenElementContent(
72: Element tokenElement);
73:
74: protected abstract void initHistoryToken();
75:
76: protected abstract void injectGlobalHandler();
77:
78: protected abstract void newItemImpl(Element historyFrame,
79: String historyToken, boolean forceAdd);
80: }
|