@@ -52,6 +52,8 @@ function getPageName(size, isPortrait, pageNames) {
52
52
*/
53
53
54
54
class PDFDocumentProperties {
55
+ #fieldData = null ;
56
+
55
57
/**
56
58
* @param {PDFDocumentPropertiesOptions } options
57
59
* @param {OverlayManager } overlayManager - Manager for the viewer overlays.
@@ -70,7 +72,7 @@ class PDFDocumentProperties {
70
72
this . overlayManager = overlayManager ;
71
73
this . l10n = l10n ;
72
74
73
- this . _reset ( ) ;
75
+ this . #reset ( ) ;
74
76
// Bind the event listener for the Close button.
75
77
closeButton . addEventListener ( "click" , this . close . bind ( this ) ) ;
76
78
@@ -97,15 +99,6 @@ class PDFDocumentProperties {
97
99
* Open the document properties overlay.
98
100
*/
99
101
async open ( ) {
100
- const freezeFieldData = data => {
101
- Object . defineProperty ( this , "fieldData" , {
102
- value : Object . freeze ( data ) ,
103
- writable : false ,
104
- enumerable : true ,
105
- configurable : true ,
106
- } ) ;
107
- } ;
108
-
109
102
await Promise . all ( [
110
103
this . overlayManager . open ( this . overlayName ) ,
111
104
this . _dataAvailableCapability . promise ,
@@ -116,11 +109,11 @@ class PDFDocumentProperties {
116
109
// If the document properties were previously fetched (for this PDF file),
117
110
// just update the dialog immediately to avoid redundant lookups.
118
111
if (
119
- this . fieldData &&
120
- currentPageNumber === this . fieldData . _currentPageNumber &&
121
- pagesRotation === this . fieldData . _pagesRotation
112
+ this . # fieldData &&
113
+ currentPageNumber === this . # fieldData. _currentPageNumber &&
114
+ pagesRotation === this . # fieldData. _pagesRotation
122
115
) {
123
- this . _updateUI ( ) ;
116
+ this . #updateUI ( ) ;
124
117
return ;
125
118
}
126
119
@@ -141,16 +134,16 @@ class PDFDocumentProperties {
141
134
isLinearized ,
142
135
] = await Promise . all ( [
143
136
contentDispositionFilename || getPdfFilenameFromUrl ( this . url ) ,
144
- this . _parseFileSize ( contentLength ) ,
145
- this . _parseDate ( info . CreationDate ) ,
146
- this . _parseDate ( info . ModDate ) ,
137
+ this . #parseFileSize ( contentLength ) ,
138
+ this . #parseDate ( info . CreationDate ) ,
139
+ this . #parseDate ( info . ModDate ) ,
147
140
this . pdfDocument . getPage ( currentPageNumber ) . then ( pdfPage => {
148
- return this . _parsePageSize ( getPageSizeInches ( pdfPage ) , pagesRotation ) ;
141
+ return this . #parsePageSize ( getPageSizeInches ( pdfPage ) , pagesRotation ) ;
149
142
} ) ,
150
- this . _parseLinearization ( info . IsLinearized ) ,
143
+ this . #parseLinearization ( info . IsLinearized ) ,
151
144
] ) ;
152
145
153
- freezeFieldData ( {
146
+ this . #fieldData = Object . freeze ( {
154
147
fileName,
155
148
fileSize,
156
149
title : info . Title ,
@@ -168,19 +161,19 @@ class PDFDocumentProperties {
168
161
_currentPageNumber : currentPageNumber ,
169
162
_pagesRotation : pagesRotation ,
170
163
} ) ;
171
- this . _updateUI ( ) ;
164
+ this . #updateUI ( ) ;
172
165
173
166
// Get the correct fileSize, since it may not have been available
174
167
// or could potentially be wrong.
175
168
const { length } = await this . pdfDocument . getDownloadInfo ( ) ;
176
169
if ( contentLength === length ) {
177
170
return ; // The fileSize has already been correctly set.
178
171
}
179
- const data = Object . assign ( Object . create ( null ) , this . fieldData ) ;
180
- data . fileSize = await this . _parseFileSize ( length ) ;
172
+ const data = Object . assign ( Object . create ( null ) , this . # fieldData) ;
173
+ data . fileSize = await this . #parseFileSize ( length ) ;
181
174
182
- freezeFieldData ( data ) ;
183
- this . _updateUI ( ) ;
175
+ this . #fieldData = Object . freeze ( data ) ;
176
+ this . #updateUI ( ) ;
184
177
}
185
178
186
179
/**
@@ -201,8 +194,8 @@ class PDFDocumentProperties {
201
194
*/
202
195
setDocument ( pdfDocument , url = null ) {
203
196
if ( this . pdfDocument ) {
204
- this . _reset ( ) ;
205
- this . _updateUI ( true ) ;
197
+ this . #reset ( ) ;
198
+ this . #updateUI ( true ) ;
206
199
}
207
200
if ( ! pdfDocument ) {
208
201
return ;
@@ -213,14 +206,11 @@ class PDFDocumentProperties {
213
206
this . _dataAvailableCapability . resolve ( ) ;
214
207
}
215
208
216
- /**
217
- * @private
218
- */
219
- _reset ( ) {
209
+ #reset( ) {
220
210
this . pdfDocument = null ;
221
211
this . url = null ;
222
212
223
- delete this . fieldData ;
213
+ this . # fieldData = null ;
224
214
this . _dataAvailableCapability = createPromiseCapability ( ) ;
225
215
this . _currentPageNumber = 1 ;
226
216
this . _pagesRotation = 0 ;
@@ -230,10 +220,9 @@ class PDFDocumentProperties {
230
220
* Always updates all of the dialog fields, to prevent inconsistent UI state.
231
221
* NOTE: If the contents of a particular field is neither a non-empty string,
232
222
* nor a number, it will fall back to `DEFAULT_FIELD_CONTENT`.
233
- * @private
234
223
*/
235
- _updateUI ( reset = false ) {
236
- if ( reset || ! this . fieldData ) {
224
+ #updateUI ( reset = false ) {
225
+ if ( reset || ! this . # fieldData) {
237
226
for ( const id in this . fields ) {
238
227
this . fields [ id ] . textContent = DEFAULT_FIELD_CONTENT ;
239
228
}
@@ -245,16 +234,13 @@ class PDFDocumentProperties {
245
234
return ;
246
235
}
247
236
for ( const id in this . fields ) {
248
- const content = this . fieldData [ id ] ;
237
+ const content = this . # fieldData[ id ] ;
249
238
this . fields [ id ] . textContent =
250
239
content || content === 0 ? content : DEFAULT_FIELD_CONTENT ;
251
240
}
252
241
}
253
242
254
- /**
255
- * @private
256
- */
257
- async _parseFileSize ( fileSize = 0 ) {
243
+ async #parseFileSize( fileSize = 0 ) {
258
244
const kb = fileSize / 1024 ,
259
245
mb = kb / 1024 ;
260
246
if ( ! kb ) {
@@ -267,10 +253,7 @@ class PDFDocumentProperties {
267
253
} ) ;
268
254
}
269
255
270
- /**
271
- * @private
272
- */
273
- async _parsePageSize ( pageSizeInches , pagesRotation ) {
256
+ async #parsePageSize( pageSizeInches , pagesRotation ) {
274
257
if ( ! pageSizeInches ) {
275
258
return undefined ;
276
259
}
@@ -364,10 +347,7 @@ class PDFDocumentProperties {
364
347
) ;
365
348
}
366
349
367
- /**
368
- * @private
369
- */
370
- async _parseDate ( inputDate ) {
350
+ async #parseDate( inputDate ) {
371
351
const dateObject = PDFDateString . toDateObject ( inputDate ) ;
372
352
if ( ! dateObject ) {
373
353
return undefined ;
@@ -378,10 +358,7 @@ class PDFDocumentProperties {
378
358
} ) ;
379
359
}
380
360
381
- /**
382
- * @private
383
- */
384
- _parseLinearization ( isLinearized ) {
361
+ #parseLinearization( isLinearized ) {
385
362
return this . l10n . get (
386
363
`document_properties_linearized_${ isLinearized ? "yes" : "no" } `
387
364
) ;
0 commit comments