/*
 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
 * Copyright (C) 2011 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

[
    CheckSecurity,
    JSCustomDefineOwnProperty,
    CustomDeleteProperty,
    CustomGetOwnPropertySlot,
	CustomGetPrototype,
    CustomGetOwnPropertyNames,
	CustomProxyToJSObject,
    JSCustomMarkFunction,
    JSCustomToNativeObject,
    CustomPut,
    ExtendsDOMGlobalObject,
    JSLegacyParent=JSDOMWindowBase,
    InterfaceName=Window,
	IsImmutablePrototypeExoticObject,
	IsImmutablePrototypeExoticObjectOnPrototype,
] interface DOMWindow : EventTarget {
    // DOM Level 0
    [Replaceable] readonly attribute Screen screen;
    readonly attribute History history;
    [Replaceable] readonly attribute BarProp locationbar;
    [Replaceable] readonly attribute BarProp menubar;
    [Replaceable] readonly attribute BarProp personalbar;
    [Replaceable] readonly attribute BarProp scrollbars;
    [Replaceable] readonly attribute BarProp statusbar;
    [Replaceable] readonly attribute BarProp toolbar;
    readonly attribute Navigator navigator;
    [Replaceable] readonly attribute Navigator clientInformation;
#if !defined(LANGUAGE_CPP) || !LANGUAGE_CPP
	[DoNotCheckSecurity, PutForwards=href, Unforgeable] readonly attribute Location? location; // FIXME: Should not be nullable.
#endif
    [Replaceable, CustomGetter] readonly attribute Event event;

    DOMSelection getSelection();

    [CheckSecurityForNode] readonly attribute Element frameElement;

    [DoNotCheckSecurity, CallWith=CallerWindow, ForwardDeclareInHeader] void focus();
    [DoNotCheckSecurity, ForwardDeclareInHeader] void blur();
    [DoNotCheckSecurity, CallWith=CallerDocument, ForwardDeclareInHeader] void close();

    // OIPF 7.15.5
    [Conditional=HBBTV] void debug(optional DOMString? arg = null);

    void print();
    void stop();
        
 	[CallWith=ActiveWindow&FirstWindow] DOMWindow? open(optional USVString url = "about:blank", optional DOMString target = "_blank", [TreatNullAs=EmptyString] optional DOMString features = "");

    [Custom] any showModalDialog(in DOMString url,
                                       in optional any dialogArgs,
                                       in optional DOMString featureArgs);

	// FIXME: Using "undefined" as default parameter value is wrong.
    void alert(in optional DOMString message = "undefined");
    boolean confirm(in optional DOMString message = "undefined");
    DOMString? prompt(in optional DOMString message = "undefined", optional DOMString? defaultValue = null);

	// FIXME: Using "undefined" as default parameter value is wrong.
    boolean find(in optional DOMString string = "undefined",
                 in optional boolean caseSensitive = false,
                 in optional boolean backwards = false,
                 in optional boolean wrap = false,
                 in optional boolean wholeWord = false,
                 in optional boolean searchInFrames = false,
                 in optional boolean showDialog = false);

    [Replaceable] readonly attribute boolean offscreenBuffering;

    [Replaceable] readonly attribute long outerHeight;
    [Replaceable] readonly attribute long outerWidth;
    [Replaceable] readonly attribute long innerHeight;
    [Replaceable] readonly attribute long innerWidth;

    [Conditional=CEHTML, ImplementedAs=innerHeight, Replaceable] readonly attribute long height;
    [Conditional=CEHTML, ImplementedAs=innerWidth, Replaceable] readonly attribute long width;
    [Conditional=CEHTML, ImplementedAs=innerHeight, Replaceable] readonly attribute long maxHeight;
    [Conditional=CEHTML, ImplementedAs=innerWidth, Replaceable] readonly attribute long maxWidth;

    [Replaceable] readonly attribute long screenX;
    [Replaceable] readonly attribute long screenY;
    [Replaceable] readonly attribute long screenLeft;
    [Replaceable] readonly attribute long screenTop;
    
    [Replaceable] readonly attribute double scrollX;
	[Replaceable] readonly attribute double scrollY;
	[Replaceable, ImplementedAs=scrollX] readonly attribute double pageXOffset;
	[Replaceable, ImplementedAs=scrollY] readonly attribute double pageYOffset;


    void scrollBy(in optional long x = 0, in optional long y = 0);
    void scrollTo(in optional long x = 0, in optional long y = 0);
    void scroll(in optional long x = 0, in optional long y = 0);
    void moveBy(in optional unrestricted float x = NaN, in optional unrestricted float y = NaN); // FIXME: this should take longs not floats.
    void moveTo(in optional unrestricted float x = NaN, in optional unrestricted float y = NaN); // FIXME: this should take longs not floats.
    void resizeBy(in optional unrestricted float x = NaN, in optional unrestricted float y = NaN); // FIXME: this should take longs not floats.
    void resizeTo(in optional unrestricted float width = NaN, in optional unrestricted float height = NaN); // FIXME: this should take longs not floats.

    [DoNotCheckSecurity, ForwardDeclareInHeader] readonly attribute boolean closed;

    [Replaceable, DoNotCheckSecurityOnGetter] readonly attribute unsigned long length;

    attribute DOMString name;

    attribute DOMString status;
    attribute DOMString defaultStatus;
#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
    // This attribute is an alias of defaultStatus and is necessary for legacy uses.
    attribute DOMString defaultstatus;
#endif

    // Self referential attributes
    [Replaceable, DoNotCheckSecurityOnGetter] readonly attribute DOMWindow self;
    [DoNotCheckSecurity, Unforgeable] readonly attribute DOMWindow window;
    [Replaceable, DoNotCheckSecurityOnGetter] readonly attribute DOMWindow frames;

    [DoNotCheckSecurityOnGetter, CustomSetter] attribute DOMWindow? opener;
    [Replaceable, DoNotCheckSecurityOnGetter] readonly attribute DOMWindow parent;
    [DoNotCheckSecurityOnGetter, Unforgeable] readonly attribute DOMWindow top;

    // CE-HTML specific methods
    [Conditional=CEHTML, ImplementedAs=top, DoNotCheckSecurityOnGetter, V8Unforgeable] readonly attribute DOMWindow topmost;
    [Conditional=CEHTML, Custom, V8Unforgeable] boolean escapeBeyondTopMost(in optional DOMString url);
    [Conditional=CEHTML] readonly attribute DOMString cea2014_protocol_subversionNr;
    [Conditional=CEHTML] readonly attribute DOMString cea2014_protocol_version;
    [Conditional=CEHTML, Custom, V8Unforgeable] void reload();
    [Conditional=CEHTML, Custom, V8Unforgeable] void replace(in optional DOMString url);
    [Conditional=CEHTML, DoNotCheckSecurity, CallWith=ScriptExecutionContext] boolean requestFocus();
    [Conditional=CEHTML] DOMWindow getFrame(in DOMString id);
    [Conditional=CEHTML, ImplementedAs=name] attribute DOMString id;
    [Conditional=CEHTML] attribute unsigned long httptimeout;
    [Conditional=CEHTML] void exitUnit();
    [Conditional=CEHTML] void setRenderMode(in DOMString mode);
    [Conditional=CEHTML] void setHttpTimeout(DOMString url, long seconds);
    [Conditional=CEHTML] Document openURL(DOMString url);
    [Conditional=CEHTML, Custom] long setTimer(in optional TimeoutHandler handler, in optional long timeout);

    // DOM Level 2 AbstractView Interface
    [Unforgeable] readonly attribute Document document;

    // CSSOM View Module
    MediaQueryList matchMedia(in DOMString query);

    // styleMedia has been removed from the CSSOM View specification.
    readonly attribute StyleMedia styleMedia;

    // DOM Level 2 Style Interface
    CSSStyleDeclaration getComputedStyle(optional Element? element = 0, optional DOMString? pseudoElement = null);

    // WebKit extensions
#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
    CSSRuleList getMatchedCSSRules(optional Element? element = 0, optional DOMString? pseudoElement = null);
#endif

    [Replaceable] readonly attribute unrestricted double devicePixelRatio;
    
    WebKitPoint webkitConvertPointFromPageToNode(optional Node? node = 0,
                                             optional WebKitPoint? p = 0);
    WebKitPoint webkitConvertPointFromNodeToPage(optional Node? node = 0,
                                             optional WebKitPoint? p = 0);

    readonly attribute DOMApplicationCache applicationCache;

    readonly attribute Storage sessionStorage
        getter raises(DOMException);
    readonly attribute Storage localStorage
        getter raises(DOMException);

    readonly attribute OfflineCache offlineCache
        getter raises(DOMException);

#if defined(ENABLE_LEGACY_NOTIFICATIONS) && ENABLE_LEGACY_NOTIFICATIONS
    readonly attribute NotificationCenter webkitNotifications;
#endif

#if defined(ENABLE_ORIENTATION_EVENTS) && ENABLE_ORIENTATION_EVENTS
    // This is the interface orientation in degrees. Some examples are:
    //  0 is straight up; -90 is when the device is rotated 90 clockwise;
    //  90 is when rotated counter clockwise.
    readonly attribute long orientation;
#endif

#if defined(ENABLE_RMAI) && ENABLE_RMAI
    [CustomGetter, Replaceable] readonly attribute MOM mom;
    [Replaceable] readonly attribute GalioDebug debug;
#endif

	[Replaceable] readonly attribute Console console;

    // cross-document messaging
#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
    [DoNotCheckSecurity, Custom, ForwardDeclareInHeader] void postMessage(in SerializedScriptValue message, in USVString targetOrigin, in optional Array messagePorts)
        raises(DOMException);
    [DoNotCheckSecurity, Custom, ForwardDeclareInHeader] void webkitPostMessage(in SerializedScriptValue message, in USVString targetOrigin, in optional Array transferList)
        raises(DOMException);
#else
    // There's no good way to expose an array via the ObjC bindings, so for now just allow passing in a single port.
    [DoNotCheckSecurity, Custom] void postMessage(in SerializedScriptValue message, in optional MessagePort messagePort, in DOMString targetOrigin)
        raises(DOMException);
#endif

#if defined(ENABLE_WEB_TIMING) && ENABLE_WEB_TIMING
    [Replaceable] readonly attribute Performance performance;
#endif

    // Timers
    [Custom] long setTimeout(in optional TimeoutHandler handler, 
                             in optional long timeout);
    // [Custom] long setTimeout(in TimeoutHandler handler, in long timeout, arguments...);
    // [Custom] long setTimeout(in DOMString code, in long timeout);
    void clearTimeout(in optional long handle = 0);
    [Custom] long setInterval(in TimeoutHandler handler, in long timeout);
    // [Custom] long setInterval(in TimeoutHandler handler, in long timeout, arguments...);
    // [Custom] long setInterval(in DOMString code, in long timeout);
    void clearInterval(in optional long handle = 0);

#if defined(ENABLE_REQUEST_ANIMATION_FRAME)
	long requestAnimationFrame(in RequestAnimationFrameCallback callback);
    void cancelAnimationFrame(in long id);
    [ImplementedAs=requestAnimationFrame] long webkitRequestAnimationFrame(in RequestAnimationFrameCallback callback);
    [ImplementedAs=cancelAnimationFrame] void webkitCancelAnimationFrame(in long id);
    [ImplementedAs=cancelAnimationFrame] void webkitCancelRequestAnimationFrame(in long id); // This is a deprecated alias for webkitCancelAnimationFrame(). Remove this when removing vendor prefix.
#endif

    // Base64
    DOMString atob(DOMString string)
        raises(DOMException);
    DOMString btoa(DOMString string)
        raises(DOMException);

	[Replaceable,Conditional=CSS3_CONDITIONAL_RULES] readonly attribute DOMWindowCSS CSS;

    // Events
    attribute EventListener onabort;
    attribute EventListener onbeforeunload;
    attribute EventListener onblur;
    attribute EventListener oncanplay;
    attribute EventListener oncanplaythrough;
    attribute EventListener onchange;
    attribute EventListener onclick;
    attribute EventListener oncontextmenu;
    attribute EventListener ondblclick;
    attribute EventListener ondrag;
    attribute EventListener ondragend;
    attribute EventListener ondragenter;
    attribute EventListener ondragleave;
    attribute EventListener ondragover;
    attribute EventListener ondragstart;
    attribute EventListener ondrop;
    attribute EventListener ondurationchange;
    attribute EventListener onemptied;
    attribute EventListener onended;
    attribute EventListener onerror;
    attribute EventListener onfocus;
    attribute EventListener onhashchange;
    attribute EventListener oninput;
    attribute EventListener oninvalid;
    attribute EventListener onkeydown;
    attribute EventListener onkeypress;
    attribute EventListener onkeyup;
    attribute EventListener onload;
    attribute EventListener onloadeddata;
    attribute EventListener onloadedmetadata;
    attribute EventListener onloadstart;
    attribute EventListener onmessage;
    attribute EventListener onmousedown;
	[LenientThis] attribute EventListener onmouseenter;
	[LenientThis] attribute EventListener onmouseleave;
    attribute EventListener onmousemove;
    attribute EventListener onmouseout;
    attribute EventListener onmouseover;
    attribute EventListener onmouseup;
    attribute EventListener onmousewheel;
    attribute EventListener onoffline;
    attribute EventListener ononline;
    attribute EventListener onpagehide;
    attribute EventListener onpageshow;
    attribute EventListener onpause;
    attribute EventListener onplay;
    attribute EventListener onplaying;
    attribute EventListener onpopstate;
    attribute EventListener onprogress;
    attribute EventListener onratechange;
    attribute EventListener onresize;
    attribute EventListener onscroll;
    attribute EventListener onseeked;
    attribute EventListener onseeking;
    attribute EventListener onselect;
    attribute EventListener onstalled;
    attribute EventListener onstorage;
    attribute EventListener onsubmit;
    attribute EventListener onsuspend;
    attribute EventListener ontimeupdate;
    attribute EventListener onunload;
    attribute EventListener onvolumechange;
    attribute EventListener onwaiting;

    // Not implemented yet.
    // attribute EventListener onafterprint;
    // attribute EventListener onbeforeprint;
    // attribute EventListener onreadystatechange;
    // attribute EventListener onredo;
    // attribute EventListener onshow;
    // attribute EventListener onundo;

    // Webkit extensions
    attribute EventListener onreset;
    attribute EventListener onsearch;
    attribute EventListener onwebkitanimationend;
    attribute EventListener onwebkitanimationiteration;
    attribute EventListener onwebkitanimationstart;
    attribute EventListener onanimationend;
    attribute EventListener onanimationiteration;
    attribute EventListener onanimationstart;
    attribute EventListener onwebkittransitionend;
    attribute EventListener ontransitionend;
#if defined(ENABLE_ORIENTATION_EVENTS) && ENABLE_ORIENTATION_EVENTS
    attribute EventListener onorientationchange;
#endif
    [Conditional=TOUCH_EVENTS] attribute EventListener ontouchstart;
    [Conditional=TOUCH_EVENTS] attribute EventListener ontouchmove;
    [Conditional=TOUCH_EVENTS] attribute EventListener ontouchend;
    [Conditional=TOUCH_EVENTS] attribute EventListener ontouchcancel;

    [Conditional=DEVICE_ORIENTATION] attribute EventListener ondevicemotion;
    [Conditional=DEVICE_ORIENTATION] attribute EventListener ondeviceorientation;

    void captureEvents(/*in long eventFlags*/);
    void releaseEvents(/*in long eventFlags*/);

#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
	// Additional constructors.

    // Mozilla has a separate XMLDocument object for XML documents. 
    // We just use Document for this.
    attribute DocumentConstructor XMLDocument;
    
	[Conditional=BLOB] attribute DOMURLConstructor webkitURL; // FIXME: deprecate this.
    [Conditional=MUTATION_OBSERVERS] attribute MutationObserverConstructor WebKitMutationObserver; // FIXME: Add metrics to determine when we can remove this.
   
    // Constructors whose name does not match the interface name.
    // FIXME: Remove these once [ImplementedAs] is used and once constructor names match interface names.    
    [Conditional=WEB_AUDIO, CustomGetter] attribute AudioContextConstructor webkitAudioContext;
        	        
    [Conditional=SCRIPTED_SPEECH] attribute SpeechGrammarConstructor webkitSpeechGrammar;
    [Conditional=SCRIPTED_SPEECH] attribute SpeechGrammarListConstructor webkitSpeechGrammarList;
    [Conditional=SCRIPTED_SPEECH] attribute SpeechRecognitionConstructor webkitSpeechRecognition;
    [Conditional=SCRIPTED_SPEECH] attribute SpeechRecognitionErrorConstructor webkitSpeechRecognitionError;
    [Conditional=SCRIPTED_SPEECH] attribute SpeechRecognitionEventConstructor webkitSpeechRecognitionEvent;
#endif // defined(LANGUAGE_JAVASCRIPT)

    };

DOMWindow implements GlobalCrypto;

