| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 isInterstitialShowing() { | 122 isInterstitialShowing() { |
| 123 return this._isInterstitialShowing; | 123 return this._isInterstitialShowing; |
| 124 } | 124 } |
| 125 | 125 |
| 126 /** | 126 /** |
| 127 * @param {!SDK.ResourceTreeFrame} frame | 127 * @param {!SDK.ResourceTreeFrame} frame |
| 128 * @param {boolean=} aboutToNavigate | 128 * @param {boolean=} aboutToNavigate |
| 129 */ | 129 */ |
| 130 _addFrame(frame, aboutToNavigate) { | 130 _addFrame(frame, aboutToNavigate) { |
| 131 this._frames.set(frame.id, frame); | 131 this._frames.set(frame.id, frame); |
| 132 if (frame.isMainFrame()) { | 132 if (frame.isMainFrame()) |
| 133 this.mainFrame = frame; | 133 this.mainFrame = frame; |
| 134 this._securityOriginManager.setMainSecurityOrigin(frame.url); | |
| 135 } | |
| 136 this.dispatchEventToListeners(SDK.ResourceTreeModel.Events.FrameAdded, frame
); | 134 this.dispatchEventToListeners(SDK.ResourceTreeModel.Events.FrameAdded, frame
); |
| 137 if (!aboutToNavigate) | 135 this._updateSecurityOrigins(); |
| 138 this._securityOriginManager.addSecurityOrigin(frame.securityOrigin); | |
| 139 } | 136 } |
| 140 | 137 |
| 141 /** | 138 /** |
| 142 * @param {!SDK.ResourceTreeFrame} mainFrame | |
| 143 */ | |
| 144 _handleMainFrameDetached(mainFrame) { | |
| 145 /** | |
| 146 * @param {!SDK.ResourceTreeFrame} frame | |
| 147 * @this {SDK.ResourceTreeModel} | |
| 148 */ | |
| 149 function removeOriginForFrame(frame) { | |
| 150 for (var i = 0; i < frame.childFrames.length; ++i) | |
| 151 removeOriginForFrame.call(this, frame.childFrames[i]); | |
| 152 if (!frame.isMainFrame()) | |
| 153 this._securityOriginManager.removeSecurityOrigin(frame.securityOrigin); | |
| 154 } | |
| 155 removeOriginForFrame.call(this, mainFrame); | |
| 156 } | |
| 157 | |
| 158 /** | |
| 159 * @param {!Protocol.Page.FrameId} frameId | 139 * @param {!Protocol.Page.FrameId} frameId |
| 160 * @param {?Protocol.Page.FrameId} parentFrameId | 140 * @param {?Protocol.Page.FrameId} parentFrameId |
| 161 * @return {?SDK.ResourceTreeFrame} | 141 * @return {?SDK.ResourceTreeFrame} |
| 162 */ | 142 */ |
| 163 _frameAttached(frameId, parentFrameId) { | 143 _frameAttached(frameId, parentFrameId) { |
| 164 // Do nothing unless cached resource tree is processed - it will overwrite e
verything. | 144 // Do nothing unless cached resource tree is processed - it will overwrite e
verything. |
| 165 if (!this._cachedResourcesProcessed && parentFrameId) | 145 if (!this._cachedResourcesProcessed && parentFrameId) |
| 166 return null; | 146 return null; |
| 167 if (this._frames.has(frameId)) | 147 if (this._frames.has(frameId)) |
| 168 return null; | 148 return null; |
| 169 | 149 |
| 170 var parentFrame = parentFrameId ? (this._frames.get(parentFrameId) || null)
: null; | 150 var parentFrame = parentFrameId ? (this._frames.get(parentFrameId) || null)
: null; |
| 171 var frame = new SDK.ResourceTreeFrame(this, parentFrame, frameId); | 151 var frame = new SDK.ResourceTreeFrame(this, parentFrame, frameId); |
| 172 if (frame.isMainFrame() && this.mainFrame) { | 152 if (frame.isMainFrame() && this.mainFrame) { |
| 173 this._handleMainFrameDetached(this.mainFrame); | |
| 174 // Navigation to the new backend process. | 153 // Navigation to the new backend process. |
| 175 this._frameDetached(this.mainFrame.id); | 154 this._frameDetached(this.mainFrame.id); |
| 176 } | 155 } |
| 177 this._addFrame(frame, true); | 156 this._addFrame(frame, true); |
| 178 return frame; | 157 return frame; |
| 179 } | 158 } |
| 180 | 159 |
| 181 /** | 160 /** |
| 182 * @param {!Protocol.Page.Frame} framePayload | 161 * @param {!Protocol.Page.Frame} framePayload |
| 183 */ | 162 */ |
| 184 _frameNavigated(framePayload) { | 163 _frameNavigated(framePayload) { |
| 185 // Do nothing unless cached resource tree is processed - it will overwrite e
verything. | 164 // Do nothing unless cached resource tree is processed - it will overwrite e
verything. |
| 186 if (!this._cachedResourcesProcessed && framePayload.parentId) | 165 if (!this._cachedResourcesProcessed && framePayload.parentId) |
| 187 return; | 166 return; |
| 188 var frame = this._frames.get(framePayload.id); | 167 var frame = this._frames.get(framePayload.id); |
| 189 if (!frame) { | 168 if (!frame) { |
| 190 // Simulate missed "frameAttached" for a main frame navigation to the new
backend process. | 169 // Simulate missed "frameAttached" for a main frame navigation to the new
backend process. |
| 191 console.assert(!framePayload.parentId, 'Main frame shouldn\'t have parent
frame id.'); | 170 console.assert(!framePayload.parentId, 'Main frame shouldn\'t have parent
frame id.'); |
| 192 frame = this._frameAttached(framePayload.id, framePayload.parentId || ''); | 171 frame = this._frameAttached(framePayload.id, framePayload.parentId || ''); |
| 193 console.assert(frame); | 172 console.assert(frame); |
| 194 } | 173 } |
| 195 | 174 |
| 196 this.dispatchEventToListeners(SDK.ResourceTreeModel.Events.FrameWillNavigate
, frame); | 175 this.dispatchEventToListeners(SDK.ResourceTreeModel.Events.FrameWillNavigate
, frame); |
| 176 frame._navigate(framePayload); |
| 177 this.dispatchEventToListeners(SDK.ResourceTreeModel.Events.FrameNavigated, f
rame); |
| 197 | 178 |
| 198 this._securityOriginManager.removeSecurityOrigin(frame.securityOrigin); | |
| 199 frame._navigate(framePayload); | |
| 200 var addedOrigin = frame.securityOrigin; | |
| 201 | |
| 202 this.dispatchEventToListeners(SDK.ResourceTreeModel.Events.FrameNavigated, f
rame); | |
| 203 if (frame.isMainFrame()) { | 179 if (frame.isMainFrame()) { |
| 204 this.dispatchEventToListeners(SDK.ResourceTreeModel.Events.MainFrameNaviga
ted, frame); | 180 this.dispatchEventToListeners(SDK.ResourceTreeModel.Events.MainFrameNaviga
ted, frame); |
| 205 if (Common.moduleSetting('preserveConsoleLog').get()) | 181 if (Common.moduleSetting('preserveConsoleLog').get()) |
| 206 Common.console.log(Common.UIString('Navigated to %s', frame.url)); | 182 Common.console.log(Common.UIString('Navigated to %s', frame.url)); |
| 207 } | 183 } |
| 208 if (addedOrigin) | |
| 209 this._securityOriginManager.addSecurityOrigin(addedOrigin); | |
| 210 | 184 |
| 211 // Fill frame with retained resources (the ones loaded using new loader). | 185 // Fill frame with retained resources (the ones loaded using new loader). |
| 212 var resources = frame.resources(); | 186 var resources = frame.resources(); |
| 213 for (var i = 0; i < resources.length; ++i) | 187 for (var i = 0; i < resources.length; ++i) |
| 214 this.dispatchEventToListeners(SDK.ResourceTreeModel.Events.ResourceAdded,
resources[i]); | 188 this.dispatchEventToListeners(SDK.ResourceTreeModel.Events.ResourceAdded,
resources[i]); |
| 215 | 189 |
| 216 if (frame.isMainFrame()) | 190 if (frame.isMainFrame()) |
| 217 this.target().setInspectedURL(frame.url); | 191 this.target().setInspectedURL(frame.url); |
| 192 this._updateSecurityOrigins(); |
| 218 } | 193 } |
| 219 | 194 |
| 220 /** | 195 /** |
| 221 * @param {!Protocol.Page.FrameId} frameId | 196 * @param {!Protocol.Page.FrameId} frameId |
| 222 */ | 197 */ |
| 223 _frameDetached(frameId) { | 198 _frameDetached(frameId) { |
| 224 // Do nothing unless cached resource tree is processed - it will overwrite e
verything. | 199 // Do nothing unless cached resource tree is processed - it will overwrite e
verything. |
| 225 if (!this._cachedResourcesProcessed) | 200 if (!this._cachedResourcesProcessed) |
| 226 return; | 201 return; |
| 227 | 202 |
| 228 var frame = this._frames.get(frameId); | 203 var frame = this._frames.get(frameId); |
| 229 if (!frame) | 204 if (!frame) |
| 230 return; | 205 return; |
| 231 | 206 |
| 232 this._securityOriginManager.removeSecurityOrigin(frame.securityOrigin); | |
| 233 if (frame.parentFrame) | 207 if (frame.parentFrame) |
| 234 frame.parentFrame._removeChildFrame(frame); | 208 frame.parentFrame._removeChildFrame(frame); |
| 235 else | 209 else |
| 236 frame._remove(); | 210 frame._remove(); |
| 211 this._updateSecurityOrigins(); |
| 237 } | 212 } |
| 238 | 213 |
| 239 /** | 214 /** |
| 240 * @param {!Protocol.Page.FrameId} frameId | 215 * @param {!Protocol.Page.FrameId} frameId |
| 241 */ | 216 */ |
| 242 _frameStartedLoading(frameId) { | 217 _frameStartedLoading(frameId) { |
| 243 // Do nothing unless cached resource tree is processed - it will overwrite e
verything. | 218 // Do nothing unless cached resource tree is processed - it will overwrite e
verything. |
| 244 if (!this._cachedResourcesProcessed) | 219 if (!this._cachedResourcesProcessed) |
| 245 return; | 220 return; |
| 246 | 221 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 return -1; | 419 return -1; |
| 445 | 420 |
| 446 if (!frameB && frameA) | 421 if (!frameB && frameA) |
| 447 return 1; | 422 return 1; |
| 448 | 423 |
| 449 if (frameA && frameB) | 424 if (frameA && frameB) |
| 450 return frameA.id.localeCompare(frameB.id); | 425 return frameA.id.localeCompare(frameB.id); |
| 451 | 426 |
| 452 return SDK.ExecutionContext.comparator(a, b); | 427 return SDK.ExecutionContext.comparator(a, b); |
| 453 } | 428 } |
| 429 |
| 430 _updateSecurityOrigins() { |
| 431 var securityOrigins = new Set(); |
| 432 var mainSecurityOrigin = null; |
| 433 for (var frame of this._frames.values()) { |
| 434 var origin = frame.securityOrigin; |
| 435 if (!origin) |
| 436 continue; |
| 437 securityOrigins.add(origin); |
| 438 if (frame.isMainFrame()) |
| 439 mainSecurityOrigin = origin; |
| 440 } |
| 441 this._securityOriginManager.updateSecurityOrigins(securityOrigins); |
| 442 this._securityOriginManager.setMainSecurityOrigin(mainSecurityOrigin || ''); |
| 443 } |
| 454 }; | 444 }; |
| 455 | 445 |
| 456 /** @enum {symbol} */ | 446 /** @enum {symbol} */ |
| 457 SDK.ResourceTreeModel.Events = { | 447 SDK.ResourceTreeModel.Events = { |
| 458 FrameAdded: Symbol('FrameAdded'), | 448 FrameAdded: Symbol('FrameAdded'), |
| 459 FrameNavigated: Symbol('FrameNavigated'), | 449 FrameNavigated: Symbol('FrameNavigated'), |
| 460 FrameDetached: Symbol('FrameDetached'), | 450 FrameDetached: Symbol('FrameDetached'), |
| 461 FrameResized: Symbol('FrameResized'), | 451 FrameResized: Symbol('FrameResized'), |
| 462 FrameWillNavigate: Symbol('FrameWillNavigate'), | 452 FrameWillNavigate: Symbol('FrameWillNavigate'), |
| 463 MainFrameNavigated: Symbol('MainFrameNavigated'), | 453 MainFrameNavigated: Symbol('MainFrameNavigated'), |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 this._resourceTreeModel.dispatchEventToListeners(SDK.ResourceTreeModel.Event
s.InterstitialHidden); | 883 this._resourceTreeModel.dispatchEventToListeners(SDK.ResourceTreeModel.Event
s.InterstitialHidden); |
| 894 } | 884 } |
| 895 | 885 |
| 896 /** | 886 /** |
| 897 * @override | 887 * @override |
| 898 */ | 888 */ |
| 899 navigationRequested() { | 889 navigationRequested() { |
| 900 // Frontend is not interested in when navigations are requested. | 890 // Frontend is not interested in when navigations are requested. |
| 901 } | 891 } |
| 902 }; | 892 }; |
| OLD | NEW |