@@ -5,67 +5,54 @@ import Bridge from 'react-devtools-shared/src/bridge';
55import { initBackend } from 'react-devtools-shared/src/backend' ;
66import { installHook } from 'react-devtools-shared/src/hook' ;
77import 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' ;
128
139import type { BackendBridge } from 'react-devtools-shared/src/bridge' ;
1410import type { Wall } from 'react-devtools-shared/src/types' ;
1511
1612function 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 ;
5844 }
45+
46+ finishActivation ( contentWindow , bridge ) ;
5947 } ;
6048
61- contentWindow . addEventListener ( 'message ', onMessage ) ;
49+ bridge . addListener ( 'savedPreferences ', onSavedPreferences ) ;
6250
6351 // The backend may be unable to read saved preferences directly,
6452 // because they are stored in localStorage within the context of the extension (on the frontend).
6553 // Instead it relies on the extension to pass preferences through.
6654 // 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' ) ;
6956}
7057
7158function finishActivation ( contentWindow : window , bridge : BackendBridge ) {
@@ -114,9 +101,9 @@ export function createBridge(
114101 const onMessage = ( { data} ) => {
115102 fn ( data ) ;
116103 } ;
117- window . addEventListener ( 'message' , onMessage ) ;
104+ contentWindow . addEventListener ( 'message' , onMessage ) ;
118105 return ( ) => {
119- window . removeEventListener ( 'message' , onMessage ) ;
106+ contentWindow . removeEventListener ( 'message' , onMessage ) ;
120107 } ;
121108 } ,
122109 send ( event : string , payload : any , transferable ?: Array < any > ) {
0 commit comments