From a1d1526ae4e880dba57160673a08d348614a60ad Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Mon, 30 Jun 2014 16:02:01 -0700 Subject: [PATCH] Bug 1031051: Part 5 - Migrate PopupBlockedEvent to the WebIDL code generator. r=smaug --- content/html/content/src/HTMLInputElement.cpp | 4 +- dom/base/nsGlobalWindow.cpp | 48 +++++++++--------- dom/base/nsGlobalWindow.h | 9 ++-- dom/base/nsPIDOMWindow.h | 13 ++++- dom/events/EventDispatcher.cpp | 2 - dom/interfaces/events/moz.build | 1 - .../events/nsIDOMPopupBlockedEvent.idl | 49 ------------------- dom/media/MediaManager.cpp | 13 ++--- dom/webidl/PopupBlockedEvent.webidl | 11 +---- dom/webidl/moz.build | 1 + js/xpconnect/src/event_impl_gen.conf.in | 1 - xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp | 3 -- 12 files changed, 52 insertions(+), 103 deletions(-) delete mode 100644 dom/interfaces/events/nsIDOMPopupBlockedEvent.idl diff --git a/content/html/content/src/HTMLInputElement.cpp b/content/html/content/src/HTMLInputElement.cpp index c47aaccb65a7..7ac34d9c714e 100644 --- a/content/html/content/src/HTMLInputElement.cpp +++ b/content/html/content/src/HTMLInputElement.cpp @@ -851,7 +851,7 @@ HTMLInputElement::InitColorPicker() } if (IsPopupBlocked()) { - nsGlobalWindow::FirePopupBlockedEvent(doc, win, nullptr, EmptyString(), EmptyString()); + win->FirePopupBlockedEvent(doc, nullptr, EmptyString(), EmptyString()); return NS_OK; } @@ -898,7 +898,7 @@ HTMLInputElement::InitFilePicker(FilePickerType aType) } if (IsPopupBlocked()) { - nsGlobalWindow::FirePopupBlockedEvent(doc, win, nullptr, EmptyString(), EmptyString()); + win->FirePopupBlockedEvent(doc, nullptr, EmptyString(), EmptyString()); return NS_OK; } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index d13d32349cba..af54b81678f0 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -87,7 +87,6 @@ #include "nsIDOMDocument.h" #include "nsIDOMElement.h" #include "nsIDOMEvent.h" -#include "nsIDOMPopupBlockedEvent.h" #include "nsIDOMPopStateEvent.h" #include "nsIDOMOfflineResourceList.h" #include "nsPIDOMStorage.h" @@ -217,6 +216,7 @@ #include "mozilla/dom/Console.h" #include "mozilla/dom/FunctionBinding.h" #include "mozilla/dom/HashChangeEvent.h" +#include "mozilla/dom/PopupBlockedEvent.h" #include "mozilla/dom/WindowBinding.h" #include "nsITabChild.h" #include "mozilla/dom/MediaQueryList.h" @@ -7380,31 +7380,33 @@ bool IsPopupBlocked(nsIDocument* aDoc) return permission == nsIPopupWindowManager::DENY_POPUP; } -/* static */ void nsGlobalWindow::FirePopupBlockedEvent(nsIDocument* aDoc, - nsIDOMWindow *aRequestingWindow, nsIURI *aPopupURI, - const nsAString &aPopupWindowName, - const nsAString &aPopupWindowFeatures) + nsIURI* aPopupURI, + const nsAString& aPopupWindowName, + const nsAString& aPopupWindowFeatures) { - if (aDoc) { - // Fire a "DOMPopupBlocked" event so that the UI can hear about - // blocked popups. - nsCOMPtr doc = do_QueryInterface(aDoc); - nsCOMPtr event; - doc->CreateEvent(NS_LITERAL_STRING("PopupBlockedEvents"), getter_AddRefs(event)); - if (event) { - nsCOMPtr pbev(do_QueryInterface(event)); - pbev->InitPopupBlockedEvent(NS_LITERAL_STRING("DOMPopupBlocked"), - true, true, aRequestingWindow, - aPopupURI, aPopupWindowName, - aPopupWindowFeatures); - event->SetTrusted(true); + MOZ_ASSERT(aDoc); - bool defaultActionEnabled; - aDoc->DispatchEvent(event, &defaultActionEnabled); - } - } + // Fire a "DOMPopupBlocked" event so that the UI can hear about + // blocked popups. + PopupBlockedEventInit init; + init.mBubbles = true; + init.mCancelable = true; + init.mRequestingWindow = this; + init.mPopupWindowURI = aPopupURI; + init.mPopupWindowName = aPopupWindowName; + init.mPopupWindowFeatures = aPopupWindowFeatures; + + nsRefPtr event = + PopupBlockedEvent::Constructor(aDoc, + NS_LITERAL_STRING("DOMPopupBlocked"), + init); + + event->SetTrusted(true); + + bool defaultActionEnabled; + aDoc->DispatchEvent(event, &defaultActionEnabled); } static void FirePopupWindowEvent(nsIDocument* aDoc) @@ -7541,7 +7543,7 @@ nsGlobalWindow::FireAbuseEvents(bool aBlocked, bool aWindow, // fire an event chock full of informative URIs if (aBlocked) { - FirePopupBlockedEvent(topDoc, this, popupURI, aPopupWindowName, + FirePopupBlockedEvent(topDoc, popupURI, aPopupWindowName, aPopupWindowFeatures); } if (aWindow) diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 7c970c5b1775..bdacc1df49e5 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -682,10 +682,11 @@ public: mCleanedUp); } - static void FirePopupBlockedEvent(nsIDocument* aDoc, - nsIDOMWindow *aRequestingWindow, nsIURI *aPopupURI, - const nsAString &aPopupWindowName, - const nsAString &aPopupWindowFeatures); + virtual void + FirePopupBlockedEvent(nsIDocument* aDoc, + nsIURI* aPopupURI, + const nsAString& aPopupWindowName, + const nsAString& aPopupWindowFeatures) MOZ_OVERRIDE; virtual uint32_t GetSerial() { return mSerial; diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index b8d0e5efcd8e..c147df8d7de4 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -60,8 +60,8 @@ enum UIStateChangeType }; #define NS_PIDOMWINDOW_IID \ -{ 0x33403513, 0x6e4a, 0x4985, \ - { 0x99, 0x8d, 0xfc, 0x02, 0x81, 0x6e, 0xb9, 0xf2 } } +{ 0x71412748, 0x6368, 0x4332, \ + { 0x82, 0x66, 0xff, 0xaa, 0x19, 0xda, 0x09, 0x7c } } class nsPIDOMWindow : public nsIDOMWindowInternal { @@ -705,6 +705,15 @@ public: OpenNoNavigate(const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions, nsIDOMWindow **_retval) = 0; + /** + * Fire a popup blocked event on the document. + */ + virtual void + FirePopupBlockedEvent(nsIDocument* aDoc, + nsIURI* aPopupURI, + const nsAString& aPopupWindowName, + const nsAString& aPopupWindowFeatures) = 0; + // Inner windows only. void AddAudioContext(mozilla::dom::AudioContext* aAudioContext); void RemoveAudioContext(mozilla::dom::AudioContext* aAudioContext); diff --git a/dom/events/EventDispatcher.cpp b/dom/events/EventDispatcher.cpp index 338929209a5c..109e25c3600e 100644 --- a/dom/events/EventDispatcher.cpp +++ b/dom/events/EventDispatcher.cpp @@ -776,8 +776,6 @@ EventDispatcher::CreateEvent(EventTarget* aOwner, if (aEventType.LowerCaseEqualsLiteral("textevent") || aEventType.LowerCaseEqualsLiteral("textevents")) return NS_NewDOMUIEvent(aDOMEvent, aOwner, aPresContext, nullptr); - if (aEventType.LowerCaseEqualsLiteral("popupblockedevents")) - return NS_NewDOMPopupBlockedEvent(aDOMEvent, aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("deviceorientationevent")) return NS_NewDOMDeviceOrientationEvent(aDOMEvent, aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("devicemotionevent")) diff --git a/dom/interfaces/events/moz.build b/dom/interfaces/events/moz.build index 898127a15277..e167203f0d2d 100644 --- a/dom/interfaces/events/moz.build +++ b/dom/interfaces/events/moz.build @@ -30,7 +30,6 @@ XPIDL_SOURCES += [ 'nsIDOMPageTransitionEvent.idl', 'nsIDOMPaintRequest.idl', 'nsIDOMPopStateEvent.idl', - 'nsIDOMPopupBlockedEvent.idl', 'nsIDOMRecordErrorEvent.idl', 'nsIDOMScrollAreaEvent.idl', 'nsIDOMSimpleGestureEvent.idl', diff --git a/dom/interfaces/events/nsIDOMPopupBlockedEvent.idl b/dom/interfaces/events/nsIDOMPopupBlockedEvent.idl deleted file mode 100644 index b119e7974714..000000000000 --- a/dom/interfaces/events/nsIDOMPopupBlockedEvent.idl +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsIDOMEvent.idl" - -interface nsIURI; - -/** - * The nsIDOMPopupBlockedEvent interface is the datatype for events - * posted when a popup window is blocked. - */ - -[builtinclass, uuid(f6e77f79-d178-419d-8177-dfae4392d318)] -interface nsIDOMPopupBlockedEvent : nsIDOMEvent -{ - /** - * The window object that attempted to open the blocked popup - * (i.e. the window object on which open() was called). - */ - readonly attribute nsIDOMWindow requestingWindow; - - - /** - * The URI of the window that was blocked. - */ - readonly attribute nsIURI popupWindowURI; - - /** - * The window name passed to the window.open() call - * (as the second argument) - */ - readonly attribute DOMString popupWindowName; - - /** - * The string of features passed to the window.open() call - * (as the third argument) - */ - readonly attribute DOMString popupWindowFeatures; - - void initPopupBlockedEvent(in DOMString typeArg, - in boolean canBubbleArg, - in boolean cancelableArg, - in nsIDOMWindow requestingWindow, - in nsIURI popupWindowURI, - in DOMString popupWindowName, - in DOMString popupWindowFeatures); -}; diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index f24ffbcdfbc3..4c1d689601c1 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -1378,12 +1378,13 @@ MediaManager::GetUserMedia(bool aPrivileged, } uint32_t permission; nsCOMPtr doc = aWindow->GetExtantDoc(); - pm->TestPermission(doc->NodePrincipal(), &permission); - if (permission == nsIPopupWindowManager::DENY_POPUP) { - nsGlobalWindow::FirePopupBlockedEvent( - doc, aWindow, nullptr, EmptyString(), EmptyString() - ); - return NS_OK; + if (doc) { + pm->TestPermission(doc->NodePrincipal(), &permission); + if (permission == nsIPopupWindowManager::DENY_POPUP) { + aWindow->FirePopupBlockedEvent(doc, nullptr, EmptyString(), + EmptyString()); + return NS_OK; + } } } } diff --git a/dom/webidl/PopupBlockedEvent.webidl b/dom/webidl/PopupBlockedEvent.webidl index f5ee2914d697..bf338d56b263 100644 --- a/dom/webidl/PopupBlockedEvent.webidl +++ b/dom/webidl/PopupBlockedEvent.webidl @@ -5,22 +5,13 @@ */ interface URI; -[Constructor(DOMString type, optional PopupBlockedEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"] +[Constructor(DOMString type, optional PopupBlockedEventInit eventInitDict)] interface PopupBlockedEvent : Event { readonly attribute Window? requestingWindow; readonly attribute URI? popupWindowURI; readonly attribute DOMString? popupWindowName; readonly attribute DOMString? popupWindowFeatures; - - [Throws] - void initPopupBlockedEvent(DOMString type, - boolean canBubble, - boolean cancelable, - Window? requestingWindow, - URI? popupWindowURI, - DOMString? popupWindowName, - DOMString? popupWindowFeatures); }; dictionary PopupBlockedEventInit : EventInit diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index b552626cbf3e..a94aea9835ae 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -647,6 +647,7 @@ GENERATED_EVENTS_WEBIDL_FILES = [ 'MozOtaStatusEvent.webidl', 'MozSmsEvent.webidl', 'MozStkCommandEvent.webidl', + 'PopupBlockedEvent.webidl', 'ProgressEvent.webidl', 'RTCDataChannelEvent.webidl', 'RTCPeerConnectionIceEvent.webidl', diff --git a/js/xpconnect/src/event_impl_gen.conf.in b/js/xpconnect/src/event_impl_gen.conf.in index f609613164b1..d75954ed500f 100644 --- a/js/xpconnect/src/event_impl_gen.conf.in +++ b/js/xpconnect/src/event_impl_gen.conf.in @@ -23,7 +23,6 @@ simple_events = [ 'SpeechSynthesisEvent', #endif 'DeviceStorageChangeEvent', - 'PopupBlockedEvent', 'RecordErrorEvent', #ifdef MOZ_WEBSPEECH 'SpeechRecognitionEvent', diff --git a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp index 33b1355d16dd..abd336fb33ee 100644 --- a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp +++ b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp @@ -124,7 +124,6 @@ #include "nsIDOMPaintRequest.h" #include "nsIDOMParser.h" #include "nsIDOMPopStateEvent.h" -#include "nsIDOMPopupBlockedEvent.h" #include "nsIDOMProcessingInstruction.h" #include "nsIDOMRange.h" #include "nsIDOMRecordErrorEvent.h" @@ -280,7 +279,6 @@ #include "mozilla/dom/PageTransitionEventBinding.h" #include "mozilla/dom/PaintRequestBinding.h" #include "mozilla/dom/PopStateEventBinding.h" -#include "mozilla/dom/PopupBlockedEventBinding.h" #include "mozilla/dom/PositionErrorBinding.h" #include "mozilla/dom/ProcessingInstructionBinding.h" #include "mozilla/dom/RangeBinding.h" @@ -489,7 +487,6 @@ const ComponentsInterfaceShimEntry kComponentsInterfaceShimMap[] = DEFINE_SHIM(PaintRequest), DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMParser, DOMParser), DEFINE_SHIM(PopStateEvent), - DEFINE_SHIM(PopupBlockedEvent), DEFINE_SHIM(ProcessingInstruction), DEFINE_SHIM(Range), DEFINE_SHIM(RecordErrorEvent),