@@ -22,13 +22,18 @@ nw_binding.registerCustomHook(function(bindingsAPI) {
22
22
NWWindow . prototype [ key ] = value ;
23
23
} ) ;
24
24
25
- NWWindow . prototype . onNewWinPolicy = new Event ( ) ;
26
- NWWindow . prototype . onNavigation = new Event ( ) ;
25
+ NWWindow . prototype . onNewWinPolicy = new Event ( ) ;
26
+ NWWindow . prototype . onNavigation = new Event ( ) ;
27
+ NWWindow . prototype . LoadingStateChanged = new Event ( ) ;
28
+
27
29
NWWindow . prototype . on = function ( event , callback ) {
28
30
switch ( event ) {
29
31
case 'closed' :
30
32
this . appWindow . onClosed . addListener ( callback ) ;
31
33
break ;
34
+ case 'loaded' :
35
+ this . LoadingStateChanged . addListener ( function ( status ) { callback ( status ) ; } ) ;
36
+ break ;
32
37
case 'new-win-policy' :
33
38
this . onNewWinPolicy . addListener ( function ( frame , url , policy ) {
34
39
policy . ignore = function ( ) { this . val = 'ignore' ; } ;
@@ -48,6 +53,28 @@ nw_binding.registerCustomHook(function(bindingsAPI) {
48
53
break ;
49
54
}
50
55
} ;
56
+ NWWindow . prototype . capturePage = function ( callback , options ) {
57
+ var cb = callback ;
58
+ if ( ! options )
59
+ options = { 'format' :'jpeg' , 'datatype' :'datauri' } ;
60
+ if ( typeof options == 'string' )
61
+ options = { 'format' :options , 'datatype' :'datauri' } ;
62
+ if ( options . datatype != 'datauri' ) {
63
+ cb = function ( format , datauri ) {
64
+ var raw = datauri . replace ( / ^ d a t a : [ ^ ; ] * ; b a s e 6 4 , / , '' ) ;
65
+ switch ( format ) {
66
+ case 'buffer' :
67
+ callback ( new nw . Buffer ( raw , "base64" ) ) ;
68
+ break ;
69
+ case 'raw' :
70
+ callback ( raw ) ;
71
+ break ;
72
+ }
73
+ } ;
74
+ cb = cb . bind ( undefined , options . datatype ) ;
75
+ }
76
+ currentNWWindowInternal . capturePageInternal ( options , cb ) ;
77
+ } ;
51
78
NWWindow . prototype . eval = function ( frame , script ) {
52
79
nwNatives . evalScript ( frame , script ) ;
53
80
} ;
@@ -131,34 +158,36 @@ nw_binding.registerCustomHook(function(bindingsAPI) {
131
158
//FIXME: unify this conversion code with nwjs/default.js
132
159
options . innerBounds = { } ;
133
160
options . outerBounds = { } ;
134
- if ( params . frame === false )
135
- options . frame = 'none' ;
136
- if ( params . resizable === false )
137
- options . resizable = false ;
138
- if ( params . x )
139
- options . outerBounds . left = params . x ;
140
- if ( params . y )
141
- options . outerBounds . top = params . y ;
142
- if ( params . height )
143
- options . innerBounds . height = params . height ;
144
- if ( params . width )
145
- options . innerBounds . width = params . width ;
146
- if ( params . min_width )
147
- options . innerBounds . minWidth = params . min_width ;
148
- if ( params . max_width )
149
- options . innerBounds . maxWidth = params . max_width ;
150
- if ( params . min_height )
151
- options . innerBounds . minHeight = params . min_height ;
152
- if ( params . max_height )
153
- options . innerBounds . maxHeight = params . max_height ;
154
- if ( params . fullscreen === true )
155
- options . state = 'fullscreen' ;
156
- if ( params . show === false )
157
- options . hidden = true ;
158
- if ( params [ 'always_on_top' ] === true )
159
- options . alwaysOnTop = true ;
160
- if ( params [ 'visible_on_all_workspaces' ] === true )
161
- options . visibleOnAllWorkspaces = true ;
161
+ if ( params ) {
162
+ if ( params . frame === false )
163
+ options . frame = 'none' ;
164
+ if ( params . resizable === false )
165
+ options . resizable = false ;
166
+ if ( params . x )
167
+ options . outerBounds . left = params . x ;
168
+ if ( params . y )
169
+ options . outerBounds . top = params . y ;
170
+ if ( params . height )
171
+ options . innerBounds . height = params . height ;
172
+ if ( params . width )
173
+ options . innerBounds . width = params . width ;
174
+ if ( params . min_width )
175
+ options . innerBounds . minWidth = params . min_width ;
176
+ if ( params . max_width )
177
+ options . innerBounds . maxWidth = params . max_width ;
178
+ if ( params . min_height )
179
+ options . innerBounds . minHeight = params . min_height ;
180
+ if ( params . max_height )
181
+ options . innerBounds . maxHeight = params . max_height ;
182
+ if ( params . fullscreen === true )
183
+ options . state = 'fullscreen' ;
184
+ if ( params . show === false )
185
+ options . hidden = true ;
186
+ if ( params [ 'always_on_top' ] === true )
187
+ options . alwaysOnTop = true ;
188
+ if ( params [ 'visible_on_all_workspaces' ] === true )
189
+ options . visibleOnAllWorkspaces = true ;
190
+ }
162
191
chrome . app . window . create ( url , options , function ( appWin ) {
163
192
callback ( appWin . contentWindow . nw . Window . get ( ) ) ;
164
193
} ) ;
@@ -190,6 +219,14 @@ function onNavigation(frame, url, policy, context) {
190
219
dispatchEventIfExists ( currentNWWindow , "onNavigation" , [ frame , url , policy , context ] ) ;
191
220
}
192
221
222
+ function onLoadingStateChanged ( status ) {
223
+ console . log ( "onLoadingStateChanged: " + status ) ;
224
+ if ( ! currentNWWindow )
225
+ return ;
226
+ dispatchEventIfExists ( currentNWWindow , "LoadingStateChanged" , [ status ] ) ;
227
+ }
228
+
193
229
exports . binding = nw_binding . generate ( ) ;
194
230
exports . onNewWinPolicy = onNewWinPolicy ;
195
- exports . onNavigation = onNavigation ;
231
+ exports . onNavigation = onNavigation ;
232
+ exports . LoadingStateChanged = onLoadingStateChanged ;
0 commit comments