1
- var Binding = require ( 'binding' ) . Binding ;
2
- var nw_binding = require ( 'binding' ) . Binding . create ( 'nw.Window' ) ;
3
1
var nwNatives = requireNative ( 'nw_natives' ) ;
4
2
var forEach = require ( 'utils' ) . forEach ;
5
- var Event = require ( 'event_bindings' ) . Event ;
6
- var dispatchEvent = require ( 'event_bindings' ) . dispatchEvent ;
7
- var dispatchEventNW = require ( 'event_bindings' ) . dispatchEventNW ;
8
- var sendRequest = require ( 'sendRequest' ) ;
9
3
var runtimeNatives = requireNative ( 'runtime' ) ;
10
4
var renderFrameObserverNatives = requireNative ( 'renderFrameObserverNatives' ) ;
11
5
var appWindowNatives = requireNative ( 'app_window_natives' ) ;
12
6
13
7
var GetExtensionViews = runtimeNatives . GetExtensionViews ;
14
8
15
9
var currentNWWindow = null ;
10
+ var currentNWWindowInternal = null ;
16
11
var currentRoutingID = nwNatives . getRoutingID ( ) ;
17
12
var currentWidgetRoutingID = nwNatives . getWidgetRoutingID ( ) ;
18
13
19
- var nw_internal = require ( 'binding' ) . Binding . create ( 'nw.currentWindowInternal' ) ;
20
-
21
14
var bgPage = GetExtensionViews ( - 1 , - 1 , 'BACKGROUND' ) [ 0 ] ;
22
15
23
16
var try_hidden = function ( view ) {
@@ -74,39 +67,6 @@ var wrapEventsMapNewWin = {
74
67
'close' : 'onRemoving'
75
68
} ;
76
69
77
- nw_internal . registerCustomHook ( function ( bindingsAPI ) {
78
- var apiFunctions = bindingsAPI . apiFunctions ;
79
- apiFunctions . setHandleRequest ( 'getCurrent' , function ( ) {
80
- return sendRequest . sendRequestSync ( 'nw.currentWindowInternal.getCurrent' , arguments , this . definition . parameters , { } ) [ 0 ] ;
81
- } ) ;
82
- apiFunctions . setHandleRequest ( 'getZoom' , function ( ) {
83
- return sendRequest . sendRequestSync ( 'nw.currentWindowInternal.getZoom' , arguments , this . definition . parameters , { } ) [ 0 ] ;
84
- } ) ;
85
- apiFunctions . setHandleRequest ( 'setZoom' , function ( ) {
86
- return sendRequest . sendRequestSync ( 'nw.currentWindowInternal.setZoom' , arguments , this . definition . parameters , { } ) ;
87
- } ) ;
88
- apiFunctions . setHandleRequest ( 'getTitleInternal' , function ( ) {
89
- return sendRequest . sendRequestSync ( 'nw.currentWindowInternal.getTitleInternal' , arguments , this . definition . parameters , { } ) [ 0 ] ;
90
- } ) ;
91
- apiFunctions . setHandleRequest ( 'setTitleInternal' , function ( ) {
92
- return sendRequest . sendRequestSync ( 'nw.currentWindowInternal.setTitleInternal' , arguments , this . definition . parameters , { } ) ;
93
- } ) ;
94
- apiFunctions . setHandleRequest ( 'isKioskInternal' , function ( ) {
95
- return sendRequest . sendRequestSync ( 'nw.currentWindowInternal.isKioskInternal' , arguments , this . definition . parameters , { } ) [ 0 ] ;
96
- } ) ;
97
- apiFunctions . setHandleRequest ( 'getWinParamInternal' , function ( ) {
98
- return sendRequest . sendRequestSync ( 'nw.currentWindowInternal.getWinParamInternal' , arguments , this . definition . parameters , { } ) [ 0 ] ;
99
- } ) ;
100
- apiFunctions . setHandleRequest ( 'setPrintSettingsInternal' , function ( ) {
101
- return sendRequest . sendRequestSync ( 'nw.currentWindowInternal.setPrintSettingsInternal' , arguments , this . definition . parameters , { } ) [ 0 ] ;
102
- } ) ;
103
- apiFunctions . setHandleRequest ( 'setMenu' , function ( ) {
104
- return sendRequest . sendRequestSync ( 'nw.currentWindowInternal.setMenu' , arguments , this . definition . parameters , { } ) [ 0 ] ;
105
- } ) ;
106
- } ) ;
107
-
108
- var currentNWWindowInternal = nw_internal . generate ( ) ;
109
-
110
70
function NWWindow ( cWindow ) {
111
71
var self = this ;
112
72
if ( cWindow )
@@ -150,18 +110,18 @@ forEach(currentNWWindowInternal, function(key, value) {
150
110
NWWindow . prototype [ key ] = value ;
151
111
} ) ;
152
112
153
- NWWindow . prototype . onNewWinPolicy = new Event ( "nw.Window.onNewWinPolicy" ) ;
154
- NWWindow . prototype . onNavigation = new Event ( ) ;
155
- NWWindow . prototype . LoadingStateChanged = new Event ( ) ;
156
- NWWindow . prototype . onDocumentStart = new Event ( "nw.Window.onDocumentStart" ) ;
157
- NWWindow . prototype . onDocumentEnd = new Event ( "nw.Window.onDocumentEnd" ) ;
158
- NWWindow . prototype . onZoom = new Event ( ) ;
159
- NWWindow . prototype . onClose = new Event ( "nw.Window.onClose" , undefined , { supportsFilters : true } ) ;
160
- NWWindow . prototype . onMinimized = new Event ( ) ;
161
- NWWindow . prototype . onMaximized = new Event ( ) ;
162
- NWWindow . prototype . onFullscreen = new Event ( ) ;
163
- NWWindow . prototype . onResized = new Event ( ) ;
164
- NWWindow . prototype . onRestore = new Event ( ) ;
113
+ NWWindow . prototype . onNewWinPolicy = bindingUtil . createCustomEvent ( "nw.Window.onNewWinPolicy" , undefined , false , false ) ;
114
+ NWWindow . prototype . onNavigation = bindingUtil . createCustomEvent ( "nw.Window.onNavigation" , undefined , false , false ) ;
115
+ NWWindow . prototype . LoadingStateChanged = bindingUtil . createCustomEvent ( "nw.Window.LoadingStateChanged" , undefined , false , false ) ;
116
+ NWWindow . prototype . onDocumentStart = bindingUtil . createCustomEvent ( "nw.Window.onDocumentStart" , undefined , false , false ) ;
117
+ NWWindow . prototype . onDocumentEnd = bindingUtil . createCustomEvent ( "nw.Window.onDocumentEnd" , undefined , false , false ) ;
118
+ NWWindow . prototype . onZoom = bindingUtil . createCustomEvent ( "nw.Window.onZoom" , undefined , false , false ) ;
119
+ NWWindow . prototype . onClose = bindingUtil . createCustomEvent ( "nw.Window.onClose" , undefined , true , false ) ;
120
+ NWWindow . prototype . onMinimized = bindingUtil . createCustomEvent ( "nw.Window.onMinimized" , undefined , false , false ) ;
121
+ NWWindow . prototype . onMaximized = bindingUtil . createCustomEvent ( "nw.Window.onMaximized" , undefined , false , false ) ;
122
+ NWWindow . prototype . onFullscreen = bindingUtil . createCustomEvent ( "nw.Window.onFullscreen" , undefined , false , false ) ;
123
+ NWWindow . prototype . onResized = bindingUtil . createCustomEvent ( "nw.Window.onResized" , undefined , false , false ) ;
124
+ NWWindow . prototype . onRestore = bindingUtil . createCustomEvent ( "nw.Window.onRestore" , undefined , false , false ) ;
165
125
166
126
NWWindow . prototype . close = function ( force ) {
167
127
currentNWWindowInternal . close ( force , this . cWindow . id ) ;
@@ -652,8 +612,9 @@ Object.defineProperty(NWWindow.prototype, 'frameId', {
652
612
}
653
613
} ) ;
654
614
655
- nw_binding . registerCustomHook ( function ( bindingsAPI ) {
615
+ apiBridge . registerCustomHook ( function ( bindingsAPI ) {
656
616
var apiFunctions = bindingsAPI . apiFunctions ;
617
+ currentNWWindowInternal = getInternalApi ( 'nw.currentWindowInternal' ) ;
657
618
apiFunctions . setHandleRequest ( 'get' , function ( domWindow ) {
658
619
if ( domWindow )
659
620
return try_nw ( domWindow . top ) . nw . Window . get ( ) ;
@@ -745,7 +706,7 @@ function dispatchEventIfExists(target, name, varargs) {
745
706
746
707
function onNewWinPolicy ( frame , url , policy ) {
747
708
//console.log("onNewWinPolicy called: " + url + ", " + policy);
748
- dispatchEventNW ( "nw.Window. onNewWinPolicy", [ frame , url , policy ] ) ;
709
+ dispatchEventIfExists ( currentNWWindow , " onNewWinPolicy", [ frame , url , policy ] ) ;
749
710
}
750
711
751
712
function onNavigation ( frame , url , policy , context ) {
@@ -764,11 +725,10 @@ function onLoadingStateChanged(status) {
764
725
765
726
function onDocumentStartEnd ( start , frame , top_routing_id ) {
766
727
if ( start ) {
767
- //could use the non-NW version?
768
- dispatchEventNW ( "nw.Window.onDocumentStart" , [ frame , top_routing_id ] ) ;
728
+ dispatchEventIfExists ( currentNWWindow , "onDocumentStart" , [ frame , top_routing_id ] ) ;
769
729
}
770
730
else
771
- dispatchEventNW ( "nw.Window. onDocumentEnd", [ frame , top_routing_id ] ) ;
731
+ dispatchEventIfExists ( currentNWWindow , " onDocumentEnd", [ frame , top_routing_id ] ) ;
772
732
}
773
733
774
734
function updateAppWindowZoom ( old_level , new_level ) {
@@ -780,7 +740,7 @@ function updateAppWindowZoom(old_level, new_level) {
780
740
function onClose ( user_force ) {
781
741
if ( ! currentNWWindow )
782
742
return ;
783
- dispatchEventNW ( "nw.Window. onClose" , [ user_force ] , { instanceId : currentWidgetRoutingID } ) ;
743
+ currentNWWindow . onClose . dispatchNW ( { instanceId : currentWidgetRoutingID } , user_force ) ;
784
744
}
785
745
786
746
function get_nw ( ) {
@@ -794,7 +754,6 @@ function get_nw() {
794
754
// renderFrameObserverNatives.OnDocumentElementCreated(currentRoutingID, get_nw);
795
755
//}
796
756
797
- exports . binding = nw_binding . generate ( ) ;
798
757
exports . onNewWinPolicy = onNewWinPolicy ;
799
758
exports . onNavigation = onNavigation ;
800
759
exports . LoadingStateChanged = onLoadingStateChanged ;
0 commit comments