@@ -16,7 +16,7 @@ import getTopOpenerWindow from '../../utils/get-top-opener-window';
16
16
import nextTick from '../../utils/next-tick' ;
17
17
import { version , isSafari } from '../../utils/browser' ;
18
18
import getCorrectedTargetForSinglePageMode from '../../utils/get-corrected-target-for-single-page-mode' ;
19
-
19
+ import isTargetBlank from '../../../utils/is-target-blank' ;
20
20
21
21
const DEFAULT_WINDOW_PARAMETERS = 'width=500px, height=500px' ;
22
22
const STORE_CHILD_WINDOW_CMD = 'hammerhead|command|store-child-window' ;
@@ -48,18 +48,18 @@ export default class ChildWindowSandbox extends SandboxBase {
48
48
target = target . toLowerCase ( ) ;
49
49
50
50
if ( isKeywordTarget ( target ) )
51
- return target === '_blank' ;
51
+ return isTargetBlank ( target ) ;
52
52
53
53
return ! windowsStorage . findByName ( target ) ;
54
54
}
55
55
56
- private _openUrlInNewWindow ( url : string , windowName ?: string , windowParams ?: string , window ?: Window ) : OpenedWindowInfo | null {
56
+ private _openUrlInNewWindow ( url : string , windowName ?: string , windowParams ?: string , window ?: Window , form ?: HTMLFormElement ) : OpenedWindowInfo | null {
57
57
const windowId = getRandomInt16Value ( ) . toString ( ) ;
58
58
59
59
windowParams = windowParams || DEFAULT_WINDOW_PARAMETERS ;
60
60
windowName = windowName || windowId ;
61
61
62
- const newPageUrl = settings . get ( ) . nativeAutomation ? url : urlUtils . getPageProxyUrl ( url , windowId ) ;
62
+ const newPageUrl = urlUtils . getPageProxyUrl ( url , windowId , settings . get ( ) . nativeAutomation ) ;
63
63
const targetWindow = window || this . window ;
64
64
const beforeWindowOpenedEventArgs = { isPrevented : false } ;
65
65
@@ -68,11 +68,12 @@ export default class ChildWindowSandbox extends SandboxBase {
68
68
if ( beforeWindowOpenedEventArgs . isPrevented )
69
69
return null ;
70
70
71
- const openedWindow = nativeMethods . windowOpen . call ( targetWindow , newPageUrl , windowName , windowParams ) ;
71
+ const startPageUrl = settings . get ( ) . nativeAutomation ? SPECIAL_BLANK_PAGE : newPageUrl ;
72
+ const openedWindow = nativeMethods . windowOpen . call ( targetWindow , startPageUrl , windowName , windowParams ) ;
72
73
73
74
this . _tryToStoreChildWindow ( openedWindow , getTopOpenerWindow ( ) ) ;
74
75
75
- this . emit ( this . WINDOW_OPENED_EVENT , { windowId, window : openedWindow } ) ;
76
+ this . emit ( this . WINDOW_OPENED_EVENT , { windowId, window : openedWindow , windowName , pageUrl : newPageUrl , form } ) ;
76
77
77
78
return { windowId, wnd : openedWindow } ;
78
79
}
@@ -160,7 +161,7 @@ export default class ChildWindowSandbox extends SandboxBase {
160
161
const [ url , target , parameters ] = args ;
161
162
162
163
if ( settings . get ( ) . allowMultipleWindows && ChildWindowSandbox . _shouldOpenInNewWindow ( target , DefaultTarget . windowOpen ) ) {
163
- const openedWindowInfo = this . _openUrlInNewWindow ( url , target , parameters , window ) ;
164
+ const openedWindowInfo = this . _openUrlInNewWindow ( url , isTargetBlank ( target ) ? void 0 : target , parameters , window ) ;
164
165
165
166
return openedWindowInfo ?. wnd ;
166
167
}
@@ -204,18 +205,22 @@ export default class ChildWindowSandbox extends SandboxBase {
204
205
! ChildWindowSandbox . _shouldOpenInNewWindowOnElementAction ( form , DefaultTarget . form ) )
205
206
return ;
206
207
207
- const aboutBlankUrl = urlUtils . getProxyUrl ( SPECIAL_BLANK_PAGE ) ;
208
- const openedInfo = this . _openUrlInNewWindow ( aboutBlankUrl ) ;
208
+ const isNativeAutomation = settings . get ( ) . nativeAutomation ;
209
+ const aboutBlankUrl = urlUtils . getProxyUrl ( SPECIAL_BLANK_PAGE , void 0 , isNativeAutomation ) ;
210
+ const openedInfo = this . _openUrlInNewWindow ( aboutBlankUrl , void 0 , void 0 , void 0 , form ) ;
209
211
210
212
if ( ! openedInfo )
211
213
return ;
212
214
213
215
const formAction = nativeMethods . formActionGetter . call ( form ) ;
214
- const newWindowUrl = urlUtils . getPageProxyUrl ( formAction , openedInfo . windowId ) ;
216
+ const newWindowUrl = urlUtils . getPageProxyUrl ( formAction , openedInfo . windowId , isNativeAutomation ) ;
215
217
216
218
nativeMethods . formActionSetter . call ( form , newWindowUrl ) ;
217
219
nativeMethods . formTargetSetter . call ( form , openedInfo . windowId ) ;
218
220
221
+ if ( isNativeAutomation )
222
+ e . preventDefault ( ) ;
223
+
219
224
// TODO: On hammerhead start we need to clean up the window.name
220
225
// It's necessary for form submit.
221
226
// Also we need clean up the form target to the original value.
0 commit comments