@@ -5,67 +5,54 @@ import Bridge from 'react-devtools-shared/src/bridge';
5
5
import { initBackend } from 'react-devtools-shared/src/backend' ;
6
6
import { installHook } from 'react-devtools-shared/src/hook' ;
7
7
import setupNativeStyleEditor from 'react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor' ;
8
- import {
9
- MESSAGE_TYPE_GET_SAVED_PREFERENCES ,
10
- MESSAGE_TYPE_SAVED_PREFERENCES ,
11
- } from './constants' ;
12
8
13
9
import type { BackendBridge } from 'react-devtools-shared/src/bridge' ;
14
10
import type { Wall } from 'react-devtools-shared/src/types' ;
15
11
16
12
function startActivation ( contentWindow : window , bridge : BackendBridge ) {
17
- const { parent} = contentWindow ;
18
-
19
- const onMessage = ( { data} ) => {
20
- switch ( data . type ) {
21
- case MESSAGE_TYPE_SAVED_PREFERENCES :
22
- // This is the only message we're listening for,
23
- // so it's safe to cleanup after we've received it.
24
- contentWindow . removeEventListener ( 'message' , onMessage ) ;
25
-
26
- const {
27
- appendComponentStack,
28
- breakOnConsoleErrors,
29
- componentFilters,
30
- showInlineWarningsAndErrors,
31
- hideConsoleLogsInStrictMode,
32
- } = data ;
33
-
34
- contentWindow . __REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ = appendComponentStack ;
35
- contentWindow . __REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__ = breakOnConsoleErrors ;
36
- contentWindow . __REACT_DEVTOOLS_COMPONENT_FILTERS__ = componentFilters ;
37
- contentWindow . __REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ = showInlineWarningsAndErrors ;
38
- contentWindow . __REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ = hideConsoleLogsInStrictMode ;
39
-
40
- // TRICKY
41
- // The backend entry point may be required in the context of an iframe or the parent window.
42
- // If it's required within the parent window, store the saved values on it as well,
43
- // since the injected renderer interface will read from window.
44
- // Technically we don't need to store them on the contentWindow in this case,
45
- // but it doesn't really hurt anything to store them there too.
46
- if ( contentWindow !== window ) {
47
- window . __REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ = appendComponentStack ;
48
- window . __REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__ = breakOnConsoleErrors ;
49
- window . __REACT_DEVTOOLS_COMPONENT_FILTERS__ = componentFilters ;
50
- window . __REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ = showInlineWarningsAndErrors ;
51
- window . __REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ = hideConsoleLogsInStrictMode ;
52
- }
53
-
54
- finishActivation ( contentWindow , bridge ) ;
55
- break ;
56
- default :
57
- break ;
13
+ const onSavedPreferences = data => {
14
+ // This is the only message we're listening for,
15
+ // so it's safe to cleanup after we've received it.
16
+ bridge . removeListener ( 'savedPreferences' , onSavedPreferences ) ;
17
+
18
+ const {
19
+ appendComponentStack,
20
+ breakOnConsoleErrors,
21
+ componentFilters,
22
+ showInlineWarningsAndErrors,
23
+ hideConsoleLogsInStrictMode,
24
+ } = data ;
25
+
26
+ contentWindow . __REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ = appendComponentStack ;
27
+ contentWindow . __REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__ = breakOnConsoleErrors ;
28
+ contentWindow . __REACT_DEVTOOLS_COMPONENT_FILTERS__ = componentFilters ;
29
+ contentWindow . __REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ = showInlineWarningsAndErrors ;
30
+ contentWindow . __REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ = hideConsoleLogsInStrictMode ;
31
+
32
+ // TRICKY
33
+ // The backend entry point may be required in the context of an iframe or the parent window.
34
+ // If it's required within the parent window, store the saved values on it as well,
35
+ // since the injected renderer interface will read from window.
36
+ // Technically we don't need to store them on the contentWindow in this case,
37
+ // but it doesn't really hurt anything to store them there too.
38
+ if ( contentWindow !== window ) {
39
+ window . __REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ = appendComponentStack ;
40
+ window . __REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__ = breakOnConsoleErrors ;
41
+ window . __REACT_DEVTOOLS_COMPONENT_FILTERS__ = componentFilters ;
42
+ window . __REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ = showInlineWarningsAndErrors ;
43
+ window . __REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ = hideConsoleLogsInStrictMode ;
58
44
}
45
+
46
+ finishActivation ( contentWindow , bridge ) ;
59
47
} ;
60
48
61
- contentWindow . addEventListener ( 'message ', onMessage ) ;
49
+ bridge . addListener ( 'savedPreferences ', onSavedPreferences ) ;
62
50
63
51
// The backend may be unable to read saved preferences directly,
64
52
// because they are stored in localStorage within the context of the extension (on the frontend).
65
53
// Instead it relies on the extension to pass preferences through.
66
54
// Because we might be in a sandboxed iframe, we have to ask for them by way of postMessage().
67
- // TODO WHAT HUH
68
- parent . postMessage ( { type : MESSAGE_TYPE_GET_SAVED_PREFERENCES } , '*' ) ;
55
+ bridge . send ( 'getSavedPreferences' ) ;
69
56
}
70
57
71
58
function finishActivation ( contentWindow : window , bridge : BackendBridge ) {
@@ -114,9 +101,9 @@ export function createBridge(
114
101
const onMessage = ( { data} ) => {
115
102
fn ( data ) ;
116
103
} ;
117
- window . addEventListener ( 'message' , onMessage ) ;
104
+ contentWindow . addEventListener ( 'message' , onMessage ) ;
118
105
return ( ) => {
119
- window . removeEventListener ( 'message' , onMessage ) ;
106
+ contentWindow . removeEventListener ( 'message' , onMessage ) ;
120
107
} ;
121
108
} ,
122
109
send ( event : string , payload : any , transferable ?: Array < any > ) {
0 commit comments