Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: Source/devtools/front_end/devtools.js

Issue 1157733004: [DevTools] Cleanup frontend-in-iframe support. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/devtools.html ('k') | Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function() { 5 (function(window) {
6 6
7 // DevToolsAPI ---------------------------------------------------------------- 7 // DevToolsAPI ----------------------------------------------------------------
8 8
9 /** 9 /**
10 * @constructor 10 * @constructor
11 */ 11 */
12 function DevToolsAPIImpl() 12 function DevToolsAPIImpl()
13 { 13 {
14 /** 14 /**
15 * @type {?Window}
16 */
17 this._inspectorWindow;
18
19 /**
20 * @type {!Array.<function(!Window)>}
21 */
22 this._pendingDispatches = [];
23
24 /**
25 * @type {number} 15 * @type {number}
26 */ 16 */
27 this._lastCallId = 0; 17 this._lastCallId = 0;
28 18
29 /** 19 /**
30 * @type {!Object.<number, function(?Object)>} 20 * @type {!Object.<number, function(?Object)>}
31 */ 21 */
32 this._callbacks = {}; 22 this._callbacks = {};
33
34 /**
35 * @type {?function(!Array.<!Adb.Device>)}
36 */
37 this._devicesUpdatedCallback = null;
38 } 23 }
39 24
40 DevToolsAPIImpl.prototype = { 25 DevToolsAPIImpl.prototype = {
41 /** 26 /**
42 * @param {number} id 27 * @param {number} id
43 * @param {?Object} arg 28 * @param {?Object} arg
44 */ 29 */
45 embedderMessageAck: function(id, arg) 30 embedderMessageAck: function(id, arg)
46 { 31 {
47 var callback = this._callbacks[id]; 32 var callback = this._callbacks[id];
(...skipping 12 matching lines...) Expand all
60 var callId = ++this._lastCallId; 45 var callId = ++this._lastCallId;
61 if (callback) 46 if (callback)
62 this._callbacks[callId] = callback; 47 this._callbacks[callId] = callback;
63 var message = { "id": callId, "method": method }; 48 var message = { "id": callId, "method": method };
64 if (args.length) 49 if (args.length)
65 message.params = args; 50 message.params = args;
66 DevToolsHost.sendMessageToEmbedder(JSON.stringify(message)); 51 DevToolsHost.sendMessageToEmbedder(JSON.stringify(message));
67 }, 52 },
68 53
69 /** 54 /**
70 * @param {function(!Array.<!Adb.Device>)} callback
71 */
72 setDevicesUpdatedCallback: function(callback)
73 {
74 this._devicesUpdatedCallback = callback;
75 },
76
77 /**
78 * @param {?Window} inspectorWindow
79 */
80 setInspectorWindow: function(inspectorWindow)
81 {
82 this._inspectorWindow = inspectorWindow;
83 if (!inspectorWindow)
84 return;
85 while (this._pendingDispatches.length)
86 this._pendingDispatches.shift()(inspectorWindow);
87 },
88
89 /**
90 * @param {function(!Window)} callback
91 */
92 _dispatchOnInspectorWindow: function(callback)
93 {
94 if (this._inspectorWindow) {
95 callback(this._inspectorWindow);
96 } else {
97 this._pendingDispatches.push(callback);
98 }
99 },
100
101 /**
102 * @param {string} method 55 * @param {string} method
103 * @param {!Array.<*>} args 56 * @param {!Array.<*>} args
104 */ 57 */
105 _dispatchOnInspectorFrontendAPI: function(method, args) 58 _dispatchOnInspectorFrontendAPI: function(method, args)
106 { 59 {
107 /** 60 var api = window["InspectorFrontendAPI"];
108 * @param {!Window} inspectorWindow 61 api[method].apply(api, args);
109 */
110 function dispatch(inspectorWindow)
111 {
112 var api = inspectorWindow["InspectorFrontendAPI"];
113 api[method].apply(api, args);
114 }
115
116 this._dispatchOnInspectorWindow(dispatch);
117 }, 62 },
118 63
119 // API methods below this line -------------------------------------------- 64 // API methods below this line --------------------------------------------
120 65
121 /** 66 /**
122 * @param {!Array.<!ExtensionDescriptor>} extensions 67 * @param {!Array.<!ExtensionDescriptor>} extensions
123 */ 68 */
124 addExtensions: function(extensions) 69 addExtensions: function(extensions)
125 { 70 {
126 /** 71 // Support for legacy front-ends (<M41).
127 * @param {!Window} inspectorWindow 72 if (window["WebInspector"].addExtensions)
128 */ 73 window["WebInspector"].addExtensions(extensions);
129 function dispatch(inspectorWindow) 74 else
130 { 75 this._dispatchOnInspectorFrontendAPI("addExtensions", [extensions]);
131 // Support for legacy front-ends (<M41).
132 if (inspectorWindow["WebInspector"].addExtensions)
133 inspectorWindow["WebInspector"].addExtensions(extensions);
134 else
135 inspectorWindow["InspectorFrontendAPI"].addExtensions(extensions );
136 }
137
138 this._dispatchOnInspectorWindow(dispatch);
139 }, 76 },
140 77
141 /** 78 /**
142 * @param {string} url 79 * @param {string} url
143 */ 80 */
144 appendedToURL: function(url) 81 appendedToURL: function(url)
145 { 82 {
146 this._dispatchOnInspectorFrontendAPI("appendedToURL", [url]); 83 this._dispatchOnInspectorFrontendAPI("appendedToURL", [url]);
147 }, 84 },
148 85
(...skipping 24 matching lines...) Expand all
173 deviceCountUpdated: function(count) 110 deviceCountUpdated: function(count)
174 { 111 {
175 this._dispatchOnInspectorFrontendAPI("deviceCountUpdated", [count]); 112 this._dispatchOnInspectorFrontendAPI("deviceCountUpdated", [count]);
176 }, 113 },
177 114
178 /** 115 /**
179 * @param {!Array.<!Adb.Device>} devices 116 * @param {!Array.<!Adb.Device>} devices
180 */ 117 */
181 devicesUpdated: function(devices) 118 devicesUpdated: function(devices)
182 { 119 {
183 if (this._devicesUpdatedCallback)
184 this._devicesUpdatedCallback.call(null, devices);
185 this._dispatchOnInspectorFrontendAPI("devicesUpdated", [devices]); 120 this._dispatchOnInspectorFrontendAPI("devicesUpdated", [devices]);
186 }, 121 },
187 122
188 /** 123 /**
189 * @param {string} message 124 * @param {string} message
190 */ 125 */
191 dispatchMessage: function(message) 126 dispatchMessage: function(message)
192 { 127 {
193 // TODO(dgozman): remove once iframe is gone.
194 if (typeof message !== "string")
195 message = JSON.stringify(message);
196 this._dispatchOnInspectorFrontendAPI("dispatchMessage", [message]); 128 this._dispatchOnInspectorFrontendAPI("dispatchMessage", [message]);
197 }, 129 },
198 130
199 /** 131 /**
200 * @param {string} messageChunk 132 * @param {string} messageChunk
201 * @param {number} messageSize 133 * @param {number} messageSize
202 */ 134 */
203 dispatchMessageChunk: function(messageChunk, messageSize) 135 dispatchMessageChunk: function(messageChunk, messageSize)
204 { 136 {
205 this._dispatchOnInspectorFrontendAPI("dispatchMessageChunk", [messageChu nk, messageSize]); 137 this._dispatchOnInspectorFrontendAPI("dispatchMessageChunk", [messageChu nk, messageSize]);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 searchCompleted: function(requestId, fileSystemPath, files) 230 searchCompleted: function(requestId, fileSystemPath, files)
299 { 231 {
300 this._dispatchOnInspectorFrontendAPI("searchCompleted", [requestId, file SystemPath, files]); 232 this._dispatchOnInspectorFrontendAPI("searchCompleted", [requestId, file SystemPath, files]);
301 }, 233 },
302 234
303 /** 235 /**
304 * @param {string} tabId 236 * @param {string} tabId
305 */ 237 */
306 setInspectedTabId: function(tabId) 238 setInspectedTabId: function(tabId)
307 { 239 {
308 /** 240 // Support for legacy front-ends (<M41).
309 * @param {!Window} inspectorWindow 241 if (window["WebInspector"].setInspectedTabId)
310 */ 242 window["WebInspector"].setInspectedTabId(tabId);
311 function dispatch(inspectorWindow) 243 else
312 { 244 this._dispatchOnInspectorFrontendAPI("setInspectedTabId", [tabId]);
313 // Support for legacy front-ends (<M41).
314 if (inspectorWindow["WebInspector"].setInspectedTabId)
315 inspectorWindow["WebInspector"].setInspectedTabId(tabId);
316 else
317 inspectorWindow["InspectorFrontendAPI"].setInspectedTabId(tabId) ;
318 }
319
320 this._dispatchOnInspectorWindow(dispatch);
321 }, 245 },
322 246
323 /** 247 /**
324 * @param {string} backgroundColor 248 * @param {string} backgroundColor
325 * @param {string} color 249 * @param {string} color
326 */ 250 */
327 setToolbarColors: function(backgroundColor, color) 251 setToolbarColors: function(backgroundColor, color)
328 { 252 {
329 this._dispatchOnInspectorFrontendAPI("setToolbarColors", [backgroundColo r, color]); 253 this._dispatchOnInspectorFrontendAPI("setToolbarColors", [backgroundColo r, color]);
330 }, 254 },
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 /** 767 /**
844 * Support for legacy front-ends (<M44). 768 * Support for legacy front-ends (<M44).
845 * @param {number} panelCode 769 * @param {number} panelCode
846 */ 770 */
847 recordPanelShown: function(panelCode) 771 recordPanelShown: function(panelCode)
848 { 772 {
849 this.recordEnumeratedHistogram("DevTools.PanelShown", panelCode, 20); 773 this.recordEnumeratedHistogram("DevTools.PanelShown", panelCode, 20);
850 } 774 }
851 } 775 }
852 776
777 window.InspectorFrontendHost = new InspectorFrontendHostImpl();
853 778
854 // DevToolsApp --------------------------------------------------------------- 779 // DevToolsApp ---------------------------------------------------------------
855 780
856 function installBackwardsCompatibility(window) 781 /**
782 * @suppressGlobalPropertiesCheck
783 */
784 function installBackwardsCompatibility()
857 { 785 {
858 /** 786 /**
859 * @this {CSSStyleDeclaration} 787 * @this {CSSStyleDeclaration}
860 */ 788 */
861 function getValue(property) 789 function getValue(property)
862 { 790 {
863 // Note that |property| comes from another context, so we can't use === here. 791 // Note that |property| comes from another context, so we can't use === here.
864 if (property == "padding-left") { 792 if (property == "padding-left") {
865 return { 793 return {
866 /** 794 /**
(...skipping 11 matching lines...) Expand all
878 window.CSSStyleDeclaration.prototype.getPropertyCSSValue = getValue; 806 window.CSSStyleDeclaration.prototype.getPropertyCSSValue = getValue;
879 window.CSSPrimitiveValue = { CSS_PX: "CSS_PX" }; 807 window.CSSPrimitiveValue = { CSS_PX: "CSS_PX" };
880 808
881 // Support for legacy (<M44) frontends. Remove in M48. 809 // Support for legacy (<M44) frontends. Remove in M48.
882 var styleElement = window.document.createElement("style"); 810 var styleElement = window.document.createElement("style");
883 styleElement.type = "text/css"; 811 styleElement.type = "text/css";
884 styleElement.textContent = "html /deep/ * { min-width: 0; min-height: 0; }"; 812 styleElement.textContent = "html /deep/ * { min-width: 0; min-height: 0; }";
885 window.document.head.appendChild(styleElement); 813 window.document.head.appendChild(styleElement);
886 } 814 }
887 815
888 /** 816 function windowLoaded()
889 * @constructor
890 * @suppressGlobalPropertiesCheck
891 */
892 function DevToolsApp()
893 { 817 {
894 this._iframe = document.getElementById("inspector-app-iframe"); 818 window.removeEventListener("DOMContentLoaded", windowLoaded, false);
895 this._inspectorFrontendHostImpl = new InspectorFrontendHostImpl(); 819 installBackwardsCompatibility();
896
897 /**
898 * @type {!Window}
899 */
900 this._inspectorWindow = this._iframe.contentWindow;
901 this._inspectorWindow.InspectorFrontendHost = this._inspectorFrontendHostImp l;
902 DevToolsAPI.setInspectorWindow(this._inspectorWindow);
903
904 this._iframe.focus();
905 this._iframe.addEventListener("load", this._onIframeLoad.bind(this), false);
906 } 820 }
907 821
908 DevToolsApp.prototype = { 822 if (window.document.readyState === "complete" || window.document.readyState === "interactive")
909 _onIframeLoad: function() 823 installBackwardsCompatibility();
910 { 824 else
911 installBackwardsCompatibility(this._iframe.contentWindow); 825 window.addEventListener("DOMContentLoaded", windowLoaded, false);
912 }
913 };
914
915 /**
916 * @suppressGlobalPropertiesCheck
917 */
918 function startup()
919 {
920 var path = window.location.pathname;
921 var injected = path.substring(path.length - 14) === "inspector.html";
922 if (injected) {
923 window.InspectorFrontendHost = new InspectorFrontendHostImpl();
924 window.DevToolsAPI.setInspectorWindow(window);
925 }
926
927 function run()
928 {
929 if (injected)
930 installBackwardsCompatibility(window);
931 else
932 new DevToolsApp();
933 }
934
935 /**
936 * @suppressGlobalPropertiesCheck
937 */
938 function windowLoaded()
939 {
940 window.removeEventListener("DOMContentLoaded", windowLoaded, false);
941 run();
942 }
943
944 if (document.readyState === "complete" || document.readyState === "interacti ve")
945 run();
946 else
947 window.addEventListener("DOMContentLoaded", windowLoaded, false);
948 }
949
950 startup();
951 826
952 // UITests ------------------------------------------------------------------ 827 // UITests ------------------------------------------------------------------
953 828
954 if (window.domAutomationController) { 829 if (window.domAutomationController) {
955 var uiTests = {}; 830 var uiTests = {};
956 831
957 uiTests._tryRun = function() 832 uiTests._tryRun = function()
958 { 833 {
959 if (uiTests._testSuite && uiTests._pendingTestName) { 834 if (uiTests._testSuite && uiTests._pendingTestName) {
960 var name = uiTests._pendingTestName; 835 var name = uiTests._pendingTestName;
(...skipping 10 matching lines...) Expand all
971 846
972 uiTests.testSuiteReady = function(testSuiteConstructor, testBase) 847 uiTests.testSuiteReady = function(testSuiteConstructor, testBase)
973 { 848 {
974 uiTests._testSuite = testSuiteConstructor(window.domAutomationController ); 849 uiTests._testSuite = testSuiteConstructor(window.domAutomationController );
975 uiTests._tryRun(); 850 uiTests._tryRun();
976 }; 851 };
977 852
978 window.uiTests = uiTests; 853 window.uiTests = uiTests;
979 } 854 }
980 855
981 })(); 856 })(window);
OLDNEW
« no previous file with comments | « Source/devtools/front_end/devtools.html ('k') | Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698