1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_AlertNotificationIPCSerializer_h__
6 #define mozilla_AlertNotificationIPCSerializer_h__
8 #include "nsComponentManagerUtils.h"
10 #include "nsIAlertsService.h"
11 #include "nsIPrincipal.h"
14 #include "ipc/IPCMessageUtils.h"
16 #include "mozilla/dom/PermissionMessageUtils.h"
22 struct IPDLParamTraits
<nsIAlertNotification
*> {
23 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
24 nsIAlertNotification
* aParam
) {
25 bool isNull
= !aParam
;
27 WriteIPDLParam(aWriter
, aActor
, isNull
);
31 nsString name
, imageURL
, title
, text
, cookie
, dir
, lang
, data
;
32 bool textClickable
, inPrivateBrowsing
, requireInteraction
, silent
;
33 nsCOMPtr
<nsIPrincipal
> principal
;
34 nsTArray
<uint32_t> vibrate
;
36 if (NS_WARN_IF(NS_FAILED(aParam
->GetName(name
))) ||
37 NS_WARN_IF(NS_FAILED(aParam
->GetImageURL(imageURL
))) ||
38 NS_WARN_IF(NS_FAILED(aParam
->GetTitle(title
))) ||
39 NS_WARN_IF(NS_FAILED(aParam
->GetText(text
))) ||
40 NS_WARN_IF(NS_FAILED(aParam
->GetTextClickable(&textClickable
))) ||
41 NS_WARN_IF(NS_FAILED(aParam
->GetCookie(cookie
))) ||
42 NS_WARN_IF(NS_FAILED(aParam
->GetDir(dir
))) ||
43 NS_WARN_IF(NS_FAILED(aParam
->GetLang(lang
))) ||
44 NS_WARN_IF(NS_FAILED(aParam
->GetData(data
))) ||
46 NS_FAILED(aParam
->GetPrincipal(getter_AddRefs(principal
)))) ||
48 NS_FAILED(aParam
->GetInPrivateBrowsing(&inPrivateBrowsing
))) ||
50 NS_FAILED(aParam
->GetRequireInteraction(&requireInteraction
))) ||
51 NS_WARN_IF(NS_FAILED(aParam
->GetSilent(&silent
))) ||
52 NS_WARN_IF(NS_FAILED(aParam
->GetVibrate(vibrate
)))) {
53 // Write a `null` object if any getter returns an error. Otherwise, the
54 // receiver will try to deserialize an incomplete object and crash.
55 WriteIPDLParam(aWriter
, aActor
, /* isNull */ true);
59 WriteIPDLParam(aWriter
, aActor
, isNull
);
60 WriteIPDLParam(aWriter
, aActor
, name
);
61 WriteIPDLParam(aWriter
, aActor
, imageURL
);
62 WriteIPDLParam(aWriter
, aActor
, title
);
63 WriteIPDLParam(aWriter
, aActor
, text
);
64 WriteIPDLParam(aWriter
, aActor
, textClickable
);
65 WriteIPDLParam(aWriter
, aActor
, cookie
);
66 WriteIPDLParam(aWriter
, aActor
, dir
);
67 WriteIPDLParam(aWriter
, aActor
, lang
);
68 WriteIPDLParam(aWriter
, aActor
, data
);
69 WriteIPDLParam(aWriter
, aActor
, principal
);
70 WriteIPDLParam(aWriter
, aActor
, inPrivateBrowsing
);
71 WriteIPDLParam(aWriter
, aActor
, requireInteraction
);
72 WriteIPDLParam(aWriter
, aActor
, silent
);
73 WriteIPDLParam(aWriter
, aActor
, vibrate
);
76 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
77 RefPtr
<nsIAlertNotification
>* aResult
) {
79 NS_ENSURE_TRUE(ReadIPDLParam(aReader
, aActor
, &isNull
), false);
85 nsString name
, imageURL
, title
, text
, cookie
, dir
, lang
, data
;
86 bool textClickable
, inPrivateBrowsing
, requireInteraction
, silent
;
87 nsCOMPtr
<nsIPrincipal
> principal
;
88 nsTArray
<uint32_t> vibrate
;
90 if (!ReadIPDLParam(aReader
, aActor
, &name
) ||
91 !ReadIPDLParam(aReader
, aActor
, &imageURL
) ||
92 !ReadIPDLParam(aReader
, aActor
, &title
) ||
93 !ReadIPDLParam(aReader
, aActor
, &text
) ||
94 !ReadIPDLParam(aReader
, aActor
, &textClickable
) ||
95 !ReadIPDLParam(aReader
, aActor
, &cookie
) ||
96 !ReadIPDLParam(aReader
, aActor
, &dir
) ||
97 !ReadIPDLParam(aReader
, aActor
, &lang
) ||
98 !ReadIPDLParam(aReader
, aActor
, &data
) ||
99 !ReadIPDLParam(aReader
, aActor
, &principal
) ||
100 !ReadIPDLParam(aReader
, aActor
, &inPrivateBrowsing
) ||
101 !ReadIPDLParam(aReader
, aActor
, &requireInteraction
) ||
102 !ReadIPDLParam(aReader
, aActor
, &silent
) ||
103 !ReadIPDLParam(aReader
, aActor
, &vibrate
)) {
107 nsCOMPtr
<nsIAlertNotification
> alert
=
108 do_CreateInstance(ALERT_NOTIFICATION_CONTRACTID
);
109 if (NS_WARN_IF(!alert
)) {
113 nsresult rv
= alert
->Init(
114 name
, imageURL
, title
, text
, textClickable
, cookie
, dir
, lang
, data
,
115 principal
, inPrivateBrowsing
, requireInteraction
, silent
, vibrate
);
116 if (NS_WARN_IF(NS_FAILED(rv
))) {
120 *aResult
= ToRefPtr(std::move(alert
));
126 } // namespace mozilla
128 #endif /* mozilla_AlertNotificationIPCSerializer_h__ */