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 mozilla_dom_PopupBlocker_h
8 #define mozilla_dom_PopupBlocker_h
11 #include "mozilla/Attributes.h"
12 #include "mozilla/TimeStamp.h"
14 class AutoPopupStatePusherInternal
;
22 class PopupBlocker final
{
24 // Popup control state enum. The values in this enum must go from most
25 // permissive to least permissive so that it's safe to push state in
26 // all situations. Pushing popup state onto the stack never makes the
27 // current popup state less permissive.
28 // Keep this in sync with PopupBlockerState webidl dictionary!
29 enum PopupControlState
{
30 openAllowed
= 0, // open that window without worries
31 openControlled
, // it's a popup, but allow it
32 openBlocked
, // it's a popup, but not from an allowed event
33 openAbused
, // it's a popup. disallow it, but allow domain override.
34 openOverridden
// disallow window open
37 static PopupControlState
PushPopupControlState(PopupControlState aState
,
40 static void PopPopupControlState(PopupControlState aState
);
42 static PopupControlState
GetPopupControlState();
44 static void PopupStatePusherCreated();
45 static void PopupStatePusherDestroyed();
47 static uint32_t GetPopupPermission(nsIPrincipal
* aPrincipal
);
49 static PopupBlocker::PopupControlState
GetEventPopupControlState(
50 WidgetEvent
* aEvent
, Event
* aDOMEvent
= nullptr);
52 // Returns if a external protocol iframe is allowed.
53 static bool ConsumeTimerTokenForExternalProtocolIframe();
55 // Returns when the last external protocol iframe has been allowed.
56 static TimeStamp
WhenLastExternalProtocolIframeAllowed();
58 // Reset the last external protocol iframe timestamp.
59 static void ResetLastExternalProtocolIframeAllowed();
61 // These method track the number of popup which is considered as a spam popup.
62 static void RegisterOpenPopupSpam();
63 static void UnregisterOpenPopupSpam();
64 static uint32_t GetOpenPopupSpamCount();
66 static void Initialize();
67 static void Shutdown();
71 } // namespace mozilla
73 #ifdef MOZILLA_INTERNAL_API
74 # define AUTO_POPUP_STATE_PUSHER AutoPopupStatePusherInternal
76 # define AUTO_POPUP_STATE_PUSHER AutoPopupStatePusherExternal
79 // Helper class that helps with pushing and popping popup control
80 // state. Note that this class looks different from within code that's
81 // part of the layout library than it does in code outside the layout
82 // library. We give the two object layouts different names so the symbols
83 // don't conflict, but code should always use the name
84 // |AutoPopupStatePusher|.
85 class MOZ_RAII AUTO_POPUP_STATE_PUSHER final
{
87 #ifdef MOZILLA_INTERNAL_API
88 explicit AUTO_POPUP_STATE_PUSHER(
89 mozilla::dom::PopupBlocker::PopupControlState aState
,
91 ~AUTO_POPUP_STATE_PUSHER();
93 AUTO_POPUP_STATE_PUSHER(nsPIDOMWindowOuter
* aWindow
,
94 mozilla::dom::PopupBlocker::PopupControlState aState
)
95 : mWindow(aWindow
), mOldState(openAbused
) {
97 mOldState
= PopupBlocker::PushPopupControlState(aState
, false);
101 ~AUTO_POPUP_STATE_PUSHER() {
103 PopupBlocker::PopPopupControlState(mOldState
);
109 #ifndef MOZILLA_INTERNAL_API
110 nsCOMPtr
<nsPIDOMWindowOuter
> mWindow
;
112 mozilla::dom::PopupBlocker::PopupControlState mOldState
;
115 #define AutoPopupStatePusher AUTO_POPUP_STATE_PUSHER
117 #endif // mozilla_PopupBlocker_h