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/. */
10 } = require("resource://devtools/client/webconsole/utils/messages.js");
13 } = require("resource://devtools/client/webconsole/utils/id-generator.js");
16 } = require("resource://devtools/client/shared/redux/middleware/debounce.js");
19 CSS_MESSAGE_ADD_MATCHING_ELEMENTS
,
27 NETWORK_MESSAGES_UPDATE
,
28 NETWORK_UPDATES_REQUEST
,
29 PRIVATE_MESSAGES_CLEAR
,
30 TARGET_MESSAGES_REMOVE
,
31 } = require("resource://devtools/client/webconsole/constants.js");
33 const defaultIdGenerator
= new IdGenerator();
35 function messagesAdd(resources
, idGenerator
= null, persistLogs
= false) {
36 if (idGenerator
== null) {
37 idGenerator
= defaultIdGenerator
;
40 for (const resource
of resources
) {
41 const message
= prepareMessage(resource
, idGenerator
, persistLogs
);
43 messages
.push(message
);
46 // Sort the messages by their timestamps.
47 messages
.sort(getNaturalOrder
);
50 for (let i
= messages
.length
- 1; i
>= 0; i
--) {
51 if (messages
[i
].type
=== MESSAGE_TYPE
.CLEAR
) {
56 messages
: messages
.slice(i
),
63 // When this is used for non-cached messages then handle clear message and
64 // split up into batches
71 function messagesClear() {
77 function messagesDisable(ids
) {
79 type
: MESSAGES_DISABLE
,
84 function privateMessagesClear() {
86 type
: PRIVATE_MESSAGES_CLEAR
,
90 function targetMessagesRemove(targetFront
) {
92 type
: TARGET_MESSAGES_REMOVE
,
97 function messageOpen(id
) {
104 function messageClose(id
) {
112 * Make a query on the server to get a list of DOM elements matching the given
113 * CSS selectors and store the information in the state.
115 * @param {Message} message
116 * The CSSWarning message
118 function messageGetMatchingElements(message
) {
119 return async ({ dispatch
, commands
}) => {
121 // We need to do the querySelectorAll using the target the message is coming from,
122 // as well as with the window the warning message was emitted from.
123 const selectedTargetFront
= message
?.targetFront
;
125 const response
= await commands
.scriptCommand
.execute(
126 `document.querySelectorAll('${message.cssSelectors}')`,
129 innerWindowID
: message
.innerWindowID
,
134 type
: CSS_MESSAGE_ADD_MATCHING_ELEMENTS
,
136 elements
: response
.result
,
144 function messageRemove(id
) {
146 type
: MESSAGE_REMOVE
,
151 function networkMessageUpdates(packets
, idGenerator
= null) {
152 if (idGenerator
== null) {
153 idGenerator
= defaultIdGenerator
;
156 const messages
= packets
.map(packet
=> prepareMessage(packet
, idGenerator
));
159 type
: NETWORK_MESSAGES_UPDATE
,
164 function networkUpdateRequests(updates
) {
166 type
: NETWORK_UPDATES_REQUEST
,
178 messageGetMatchingElements
,
179 networkMessageUpdates
,
180 networkUpdateRequests
,
181 privateMessagesClear
,
182 targetMessagesRemove
,