no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / toolkit / components / windowwatcher / nsWindowWatcher.h
blob9f457a876385cbaaaf9cdcc27d4aa31a67e1c948
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
7 #ifndef __nsWindowWatcher_h__
8 #define __nsWindowWatcher_h__
10 // {a21bfa01-f349-4394-a84c-8de5cf0737d0}
11 #define NS_WINDOWWATCHER_CID \
12 { \
13 0xa21bfa01, 0xf349, 0x4394, { \
14 0xa8, 0x4c, 0x8d, 0xe5, 0xcf, 0x7, 0x37, 0xd0 \
15 } \
18 #include "nsCOMPtr.h"
19 #include "Units.h"
20 #include "mozilla/Mutex.h"
21 #include "mozilla/Maybe.h"
22 #include "nsIWindowCreator.h" // for stupid compilers
23 #include "nsIWindowWatcher.h"
24 #include "nsIOpenWindowInfo.h"
25 #include "nsIPromptFactory.h"
26 #include "nsIRemoteTab.h"
27 #include "nsPIWindowWatcher.h"
28 #include "nsTArray.h"
29 #include "mozilla/dom/UserActivation.h" // mozilla::dom::UserActivation
30 #include "mozilla/dom/WindowFeatures.h" // mozilla::dom::WindowFeatures
32 class nsIURI;
33 class nsIDocShellTreeItem;
34 class nsIDocShellTreeOwner;
35 class nsPIDOMWindowOuter;
36 class nsWatcherWindowEnumerator;
37 class nsPromptService;
38 struct nsWatcherWindowEntry;
40 class nsWindowWatcher : public nsIWindowWatcher,
41 public nsPIWindowWatcher,
42 public nsIPromptFactory {
43 friend class nsWatcherWindowEnumerator;
45 public:
46 nsWindowWatcher();
48 nsresult Init();
50 NS_DECL_ISUPPORTS
52 NS_DECL_NSIWINDOWWATCHER
53 NS_DECL_NSPIWINDOWWATCHER
54 NS_DECL_NSIPROMPTFACTORY
56 static bool IsWindowOpenLocationModified(
57 const mozilla::dom::UserActivation::Modifiers& aModifiers,
58 int32_t* aLocation);
60 static int32_t GetWindowOpenLocation(
61 nsPIDOMWindowOuter* aParent, uint32_t aChromeFlags,
62 const mozilla::dom::UserActivation::Modifiers& aModifiers,
63 bool aCalledFromJS, bool aIsForPrinting);
65 static bool HaveSpecifiedSize(const mozilla::dom::WindowFeatures& features);
67 /**
68 * Creates a load state from the given uri and the parent window.
70 * If `aParent` is present, his function will set
71 * - the triggering window id
72 * - if the triggering window has storage access
73 * - the source `BrowsingContext``
74 * - the triggering browsing context's sandbox flags
75 * - the user gesture activation flag based on the parent document
76 * - the text directive user activation flag; this will consume the parent
77 * document's flag and OR's it with the user gesture activation flag.
79 * Currently, the returned load state is intended to be passed into
80 * `OpenWindowInternal()`.
81 * Note that the triggering principal and referrer info are not set by this
82 * function.
84 static already_AddRefed<nsDocShellLoadState> CreateLoadState(
85 nsIURI* aUri, nsPIDOMWindowOuter* aParent);
87 protected:
88 virtual ~nsWindowWatcher();
90 friend class nsPromptService;
91 bool AddEnumerator(nsWatcherWindowEnumerator* aEnumerator);
92 bool RemoveEnumerator(nsWatcherWindowEnumerator* aEnumerator);
94 nsWatcherWindowEntry* FindWindowEntry(mozIDOMWindowProxy* aWindow);
95 nsresult RemoveWindow(nsWatcherWindowEntry* aInfo);
97 // Just like OpenWindowJS, but knows whether it got called via OpenWindowJS
98 // (which means called from script) or called via OpenWindow.
99 nsresult OpenWindowInternal(
100 mozIDOMWindowProxy* aParent, const nsACString& aUrl,
101 const nsACString& aName, const nsACString& aFeatures,
102 const mozilla::dom::UserActivation::Modifiers& aModifiers,
103 bool aCalledFromJS, bool aDialog, bool aNavigate, nsIArray* aArgv,
104 bool aIsPopupSpam, bool aForceNoOpener, bool aForceNoReferrer, PrintKind,
105 nsDocShellLoadState* aLoadState, mozilla::dom::BrowsingContext** aResult);
106 nsresult OpenWindowInternal(
107 mozIDOMWindowProxy* aParent, nsIURI* aUri, const nsACString& aName,
108 const nsACString& aFeatures,
109 const mozilla::dom::UserActivation::Modifiers& aModifiers,
110 bool aCalledFromJS, bool aDialog, bool aNavigate, nsIArray* aArgv,
111 bool aIsPopupSpam, bool aForceNoOpener, bool aForceNoReferrer, PrintKind,
112 nsDocShellLoadState* aLoadState, mozilla::dom::BrowsingContext** aResult);
114 static nsresult URIfromURL(const nsACString& aURL,
115 mozIDOMWindowProxy* aParent, nsIURI** aURI);
117 static bool ShouldOpenPopup(const mozilla::dom::WindowFeatures& aFeatures);
119 static uint32_t CalculateChromeFlagsForContent(
120 const mozilla::dom::WindowFeatures& aFeatures,
121 const mozilla::dom::UserActivation::Modifiers& aModifiers,
122 bool* aIsPopupRequested);
124 static uint32_t CalculateChromeFlagsForSystem(
125 const mozilla::dom::WindowFeatures& aFeatures, bool aDialog,
126 bool aChromeURL);
128 private:
129 MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult CreateChromeWindow(
130 nsIWebBrowserChrome* aParentChrome, uint32_t aChromeFlags,
131 nsIOpenWindowInfo* aOpenWindowInfo, nsIWebBrowserChrome** aResult);
133 protected:
134 nsTArray<nsWatcherWindowEnumerator*> mEnumeratorList;
135 nsWatcherWindowEntry* mOldestWindow;
136 mozilla::Mutex mListLock MOZ_UNANNOTATED;
138 nsCOMPtr<nsIWindowCreator> mWindowCreator;
141 #endif