nsIWindowWatcher.idl 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #include "nsISupports.idl"
  7. interface mozIDOMWindowProxy;
  8. interface nsIObserver;
  9. interface nsIPrompt;
  10. interface nsIAuthPrompt;
  11. interface nsISimpleEnumerator;
  12. interface nsIWebBrowserChrome;
  13. interface nsIWindowCreator;
  14. /**
  15. * nsIWindowWatcher is the keeper of Gecko/DOM Windows. It maintains
  16. * a list of open top-level windows, and allows some operations on them.
  17. * Usage notes:
  18. * This component has an |activeWindow| property. Clients may expect
  19. * this property to be always current, so to properly integrate this component
  20. * the application will need to keep it current by setting the property
  21. * as the active window changes.
  22. * This component should not keep a (XPCOM) reference to any windows;
  23. * the implementation will claim no ownership. Windows must notify
  24. * this component when they are created or destroyed, so only a weak
  25. * reference is kept. Note that there is no interface for such notifications
  26. * (not a public one, anyway). This is taken care of both in Mozilla and
  27. * by common embedding code. Embedding clients need do nothing special
  28. * about that requirement.
  29. * This component must be initialized at application startup by calling
  30. * setWindowCreator.
  31. */
  32. [scriptable, uuid(641fe945-6902-4b3f-87c2-0daef32499b3)]
  33. interface nsIWindowWatcher : nsISupports {
  34. /** Create a new window. It will automatically be added to our list
  35. (via addWindow()).
  36. @param aParent parent window, if any. Null if no parent. If it is
  37. impossible to get to an nsIWebBrowserChrome from aParent, this
  38. method will effectively act as if aParent were null.
  39. @param aURL url to which to open the new window. Must already be
  40. escaped, if applicable. can be null.
  41. @param aName window name from JS window.open. can be null. If a window
  42. with this name already exists, the openWindow call may just load
  43. aUrl in it (if aUrl is not null) and return it.
  44. @param aFeatures window features from JS window.open. can be null.
  45. @param aArguments extra argument(s) to the new window, to be attached
  46. as the |arguments| property. An nsIArray will be
  47. unwound into multiple arguments (but not recursively!).
  48. can be null.
  49. @return the new window
  50. @note This method may examine the JS context stack for purposes of
  51. determining the security context to use for the search for a given
  52. window named aName.
  53. @note This method should try to set the default charset for the new
  54. window to the default charset of aParent. This is not guaranteed,
  55. however.
  56. @note This method may dispatch a "toplevel-window-ready" notification
  57. via nsIObserverService if the window did not already exist.
  58. */
  59. mozIDOMWindowProxy openWindow(in mozIDOMWindowProxy aParent, in string aUrl,
  60. in string aName, in string aFeatures,
  61. in nsISupports aArguments);
  62. /** Clients of this service can register themselves to be notified
  63. when a window is opened or closed (added to or removed from this
  64. service). This method adds an aObserver to the list of objects
  65. to be notified.
  66. @param aObserver the object to be notified when windows are
  67. opened or closed. Its Observe method will be
  68. called with the following parameters:
  69. aObserver::Observe interprets its parameters so:
  70. aSubject the window being opened or closed, sent as an nsISupports
  71. which can be QIed to an nsIDOMWindow.
  72. aTopic a wstring, either "domwindowopened" or "domwindowclosed".
  73. someData not used.
  74. */
  75. void registerNotification(in nsIObserver aObserver);
  76. /** Clients of this service can register themselves to be notified
  77. when a window is opened or closed (added to or removed from this
  78. service). This method removes an aObserver from the list of objects
  79. to be notified.
  80. @param aObserver the observer to be removed.
  81. */
  82. void unregisterNotification(in nsIObserver aObserver);
  83. /** Get an iterator for currently open windows in the order they were opened,
  84. guaranteeing that each will be visited exactly once.
  85. @return an enumerator which will itself return nsISupports objects which
  86. can be QIed to an nsIDOMWindow
  87. */
  88. nsISimpleEnumerator getWindowEnumerator();
  89. /** Return a newly created nsIPrompt implementation.
  90. @param aParent the parent window used for posing alerts. can be null.
  91. @return a new nsIPrompt object
  92. */
  93. nsIPrompt getNewPrompter(in mozIDOMWindowProxy aParent);
  94. /** Return a newly created nsIAuthPrompt implementation.
  95. @param aParent the parent window used for posing alerts. can be null.
  96. @return a new nsIAuthPrompt object
  97. */
  98. nsIAuthPrompt getNewAuthPrompter(in mozIDOMWindowProxy aParent);
  99. /** Set the window creator callback. It must be filled in by the app.
  100. openWindow will use it to create new windows.
  101. @param creator the callback. if null, the callback will be cleared
  102. and window creation capabilities lost.
  103. */
  104. void setWindowCreator(in nsIWindowCreator creator);
  105. /** Returns true if a window creator callback has been set, false otherwise.
  106. */
  107. boolean hasWindowCreator();
  108. /** Retrieve the chrome window mapped to the given DOM window. Window
  109. Watcher keeps a list of all top-level DOM windows currently open,
  110. along with their corresponding chrome interfaces. Since DOM Windows
  111. lack a (public) means of retrieving their corresponding chrome,
  112. this method will do that.
  113. @param aWindow the DOM window whose chrome window the caller needs
  114. @return the corresponding chrome window
  115. */
  116. nsIWebBrowserChrome getChromeForWindow(in mozIDOMWindowProxy aWindow);
  117. /**
  118. Retrieve an existing window (or frame).
  119. @param aTargetName the window name
  120. @param aCurrentWindow a starting point in the window hierarchy to
  121. begin the search. If null, each toplevel window
  122. will be searched.
  123. Note: This method will search all open windows for any window or
  124. frame with the given window name. Make sure you understand the
  125. security implications of this before using this method!
  126. */
  127. mozIDOMWindowProxy getWindowByName(in AString aTargetName,
  128. in mozIDOMWindowProxy aCurrentWindow);
  129. /** The Watcher serves as a global storage facility for the current active
  130. (frontmost non-floating-palette-type) window, storing and returning
  131. it on demand. Users must keep this attribute current, including after
  132. the topmost window is closed. This attribute obviously can return null
  133. if no windows are open, but should otherwise always return a valid
  134. window.
  135. */
  136. attribute mozIDOMWindowProxy activeWindow;
  137. };
  138. %{C++
  139. #define NS_WINDOWWATCHER_CONTRACTID "@mozilla.org/embedcomp/window-watcher;1"
  140. %}