/work/obj-fuzz/dist/include/mozilla/AlertNotificationIPCSerializer.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
4 | | |
5 | | #ifndef mozilla_AlertNotificationIPCSerializer_h__ |
6 | | #define mozilla_AlertNotificationIPCSerializer_h__ |
7 | | |
8 | | #include "nsComponentManagerUtils.h" |
9 | | #include "nsCOMPtr.h" |
10 | | #include "nsIAlertsService.h" |
11 | | #include "nsIPrincipal.h" |
12 | | #include "nsString.h" |
13 | | |
14 | | #include "ipc/IPCMessageUtils.h" |
15 | | |
16 | | #include "mozilla/dom/PermissionMessageUtils.h" |
17 | | |
18 | | namespace IPC { |
19 | | |
20 | | template <> |
21 | | struct ParamTraits<nsIAlertNotification> |
22 | | { |
23 | | static void Write(Message* aMsg, nsIAlertNotification* aParam) |
24 | 0 | { |
25 | 0 | bool isNull = !aParam; |
26 | 0 | if (isNull) { |
27 | 0 | WriteParam(aMsg, isNull); |
28 | 0 | return; |
29 | 0 | } |
30 | 0 | |
31 | 0 | nsString name, imageURL, title, text, cookie, dir, lang, data; |
32 | 0 | bool textClickable, inPrivateBrowsing, requireInteraction; |
33 | 0 | nsCOMPtr<nsIPrincipal> principal; |
34 | 0 |
|
35 | 0 | if (NS_WARN_IF(NS_FAILED(aParam->GetName(name))) || |
36 | 0 | NS_WARN_IF(NS_FAILED(aParam->GetImageURL(imageURL))) || |
37 | 0 | NS_WARN_IF(NS_FAILED(aParam->GetTitle(title))) || |
38 | 0 | NS_WARN_IF(NS_FAILED(aParam->GetText(text))) || |
39 | 0 | NS_WARN_IF(NS_FAILED(aParam->GetTextClickable(&textClickable))) || |
40 | 0 | NS_WARN_IF(NS_FAILED(aParam->GetCookie(cookie))) || |
41 | 0 | NS_WARN_IF(NS_FAILED(aParam->GetDir(dir))) || |
42 | 0 | NS_WARN_IF(NS_FAILED(aParam->GetLang(lang))) || |
43 | 0 | NS_WARN_IF(NS_FAILED(aParam->GetData(data))) || |
44 | 0 | NS_WARN_IF(NS_FAILED(aParam->GetPrincipal(getter_AddRefs(principal)))) || |
45 | 0 | NS_WARN_IF(NS_FAILED(aParam->GetInPrivateBrowsing(&inPrivateBrowsing))) || |
46 | 0 | NS_WARN_IF(NS_FAILED(aParam->GetRequireInteraction(&requireInteraction)))) { |
47 | 0 |
|
48 | 0 | // Write a `null` object if any getter returns an error. Otherwise, the |
49 | 0 | // receiver will try to deserialize an incomplete object and crash. |
50 | 0 | WriteParam(aMsg, /* isNull */ true); |
51 | 0 | return; |
52 | 0 | } |
53 | 0 | |
54 | 0 | WriteParam(aMsg, isNull); |
55 | 0 | WriteParam(aMsg, name); |
56 | 0 | WriteParam(aMsg, imageURL); |
57 | 0 | WriteParam(aMsg, title); |
58 | 0 | WriteParam(aMsg, text); |
59 | 0 | WriteParam(aMsg, textClickable); |
60 | 0 | WriteParam(aMsg, cookie); |
61 | 0 | WriteParam(aMsg, dir); |
62 | 0 | WriteParam(aMsg, lang); |
63 | 0 | WriteParam(aMsg, data); |
64 | 0 | WriteParam(aMsg, IPC::Principal(principal)); |
65 | 0 | WriteParam(aMsg, inPrivateBrowsing); |
66 | 0 | WriteParam(aMsg, requireInteraction); |
67 | 0 | } |
68 | | |
69 | | static bool Read(const Message* aMsg, PickleIterator* aIter, RefPtr<nsIAlertNotification>* aResult) |
70 | 0 | { |
71 | 0 | bool isNull; |
72 | 0 | NS_ENSURE_TRUE(ReadParam(aMsg, aIter, &isNull), false); |
73 | 0 | if (isNull) { |
74 | 0 | *aResult = nullptr; |
75 | 0 | return true; |
76 | 0 | } |
77 | 0 | |
78 | 0 | nsString name, imageURL, title, text, cookie, dir, lang, data; |
79 | 0 | bool textClickable, inPrivateBrowsing, requireInteraction; |
80 | 0 | IPC::Principal principal; |
81 | 0 |
|
82 | 0 | if (!ReadParam(aMsg, aIter, &name) || |
83 | 0 | !ReadParam(aMsg, aIter, &imageURL) || |
84 | 0 | !ReadParam(aMsg, aIter, &title) || |
85 | 0 | !ReadParam(aMsg, aIter, &text) || |
86 | 0 | !ReadParam(aMsg, aIter, &textClickable) || |
87 | 0 | !ReadParam(aMsg, aIter, &cookie) || |
88 | 0 | !ReadParam(aMsg, aIter, &dir) || |
89 | 0 | !ReadParam(aMsg, aIter, &lang) || |
90 | 0 | !ReadParam(aMsg, aIter, &data) || |
91 | 0 | !ReadParam(aMsg, aIter, &principal) || |
92 | 0 | !ReadParam(aMsg, aIter, &inPrivateBrowsing) || |
93 | 0 | !ReadParam(aMsg, aIter, &requireInteraction)) { |
94 | 0 |
|
95 | 0 | return false; |
96 | 0 | } |
97 | 0 | |
98 | 0 | nsCOMPtr<nsIAlertNotification> alert = |
99 | 0 | do_CreateInstance(ALERT_NOTIFICATION_CONTRACTID); |
100 | 0 | if (NS_WARN_IF(!alert)) { |
101 | 0 | *aResult = nullptr; |
102 | 0 | return true; |
103 | 0 | } |
104 | 0 | nsresult rv = alert->Init(name, imageURL, title, text, textClickable, |
105 | 0 | cookie, dir, lang, data, principal, |
106 | 0 | inPrivateBrowsing, requireInteraction); |
107 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { |
108 | 0 | *aResult = nullptr; |
109 | 0 | return true; |
110 | 0 | } |
111 | 0 | *aResult = alert.forget(); |
112 | 0 | return true; |
113 | 0 | } |
114 | | }; |
115 | | |
116 | | } // namespace IPC |
117 | | |
118 | | #endif /* mozilla_AlertNotificationIPCSerializer_h__ */ |