001: /*
002: * Copyright (c) 2002-2008 Gargoyle Software Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: * 2. Redistributions in binary form must reproduce the above copyright notice,
010: * this list of conditions and the following disclaimer in the documentation
011: * and/or other materials provided with the distribution.
012: * 3. The end-user documentation included with the redistribution, if any, must
013: * include the following acknowledgment:
014: *
015: * "This product includes software developed by Gargoyle Software Inc.
016: * (http://www.GargoyleSoftware.com/)."
017: *
018: * Alternately, this acknowledgment may appear in the software itself, if
019: * and wherever such third-party acknowledgments normally appear.
020: * 4. The name "Gargoyle Software" must not be used to endorse or promote
021: * products derived from this software without prior written permission.
022: * For written permission, please contact info@GargoyleSoftware.com.
023: * 5. Products derived from this software may not be called "HtmlUnit", nor may
024: * "HtmlUnit" appear in their name, without prior written permission of
025: * Gargoyle Software Inc.
026: *
027: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
028: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
029: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
030: * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
031: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
032: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
033: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
034: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
035: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
036: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037: */
038: package com.gargoylesoftware.htmlunit;
039:
040: import java.io.Serializable;
041:
042: /**
043: * A window representing a top level browser window.
044: *
045: * @version $Revision: 2132 $
046: * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
047: * @author David K. Taylor
048: * @author David D. Kilzer
049: * @author Ahmed Ashour
050: */
051: public class TopLevelWindow extends WebWindowImpl implements
052: Serializable {
053:
054: private static final long serialVersionUID = 2448888802967514906L;
055:
056: private WebWindow opener_;
057:
058: /**
059: * Create an instance.
060: * @param name The name of the new window
061: * @param webClient The web client that "owns" this window.
062: */
063: public TopLevelWindow(final String name, final WebClient webClient) {
064: super (webClient);
065: Assert.notNull("name", name);
066: setName(name);
067: }
068:
069: /**
070: * {@inheritDoc}
071: * Since this is a top level window, return this window.
072: */
073: public WebWindow getParentWindow() {
074: return this ;
075: }
076:
077: /**
078: * {@inheritDoc}
079: * Since this is a top level window, return this window.
080: */
081: public WebWindow getTopWindow() {
082: return this ;
083: }
084:
085: /**
086: * {@inheritDoc}
087: */
088: protected boolean isJavaScriptInitializationNeeded() {
089: return true;
090: }
091:
092: /**
093: * Return a string representation of this object
094: * @return A string representation of this object
095: */
096: public String toString() {
097: return "TopLevelWindow[name=\"" + getName() + "\"]";
098: }
099:
100: /**
101: * Set the opener property. This is the WebWindow that caused this new window to be opened.
102: * @param opener The new opener
103: */
104: public void setOpener(final WebWindow opener) {
105: opener_ = opener;
106: }
107:
108: /**
109: * Return the opener property. This is the WebWindow that caused this new window to be opened.
110: * @return The opener
111: */
112: public WebWindow getOpener() {
113: return opener_;
114: }
115:
116: /**
117: * Close this window.
118: */
119: public void close() {
120: destroyChildren();
121: getWebClient().deregisterWebWindow(this);
122: }
123: }
|