1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @return {number} Width of a scrollbar in pixels
*/
function getScrollbarWidth() {
var div = document.createElement('div');
div.style.visibility = 'hidden';
div.style.overflow = 'scroll';
div.style.width = '50px';
div.style.height = '50px';
div.style.position = 'absolute';
document.body.appendChild(div);
var result = div.offsetWidth - div.clientWidth;
div.parentNode.removeChild(div);
return result;
}
/**
* Return the filename component of a URL.
* @param {string} url The URL to get the filename from.
* @return {string} The filename component.
*/
function getFilenameFromURL(url) {
var components = url.split(/\/|\\/);
return components[components.length - 1];
}
/**
* The minimum number of pixels to offset the toolbar by from the bottom and
* right side of the screen.
*/
PDFViewer.MIN_TOOLBAR_OFFSET = 15;
/**
* Creates a new PDFViewer. There should only be one of these objects per
* document.
* @constructor
* @param {Object} streamDetails The stream object which points to the data
* contained in the PDF.
*/
function PDFViewer(streamDetails) {
this.streamDetails_ = streamDetails;
this.loaded_ = false;
this.parentWindow_ = null;
this.delayedScriptingMessages_ = [];
this.isPrintPreview_ =
this.streamDetails_.originalUrl.indexOf('chrome://print') == 0;
this.isMaterial_ = location.pathname.substring(1) == 'index-material.html';
// The sizer element is placed behind the plugin element to cause scrollbars
// to be displayed in the window. It is sized according to the document size
// of the pdf and zoom level.
this.sizer_ = $('sizer');
this.toolbar_ = $('toolbar');
this.pageIndicator_ = $('page-indicator');
this.progressBar_ = $('progress-bar');
this.passwordScreen_ = $('password-screen');
this.passwordScreen_.addEventListener('password-submitted',
this.onPasswordSubmitted_.bind(this));
this.errorScreen_ = $('error-screen');
this.toolbarHeight_ = this.isMaterial_ ? $('pdf-toolbar').clientHeight : 0;
// Create the viewport.
this.viewport_ = new Viewport(window,
this.sizer_,
this.viewportChanged_.bind(this),
this.beforeZoom_.bind(this),
this.afterZoom_.bind(this),
getScrollbarWidth(),
this.toolbarHeight_);
// Create the plugin object dynamically so we can set its src. The plugin
// element is sized to fill the entire window and is set to be fixed
// positioning, acting as a viewport. The plugin renders into this viewport
// according to the scroll position of the window.
this.plugin_ = document.createElement('embed');
// NOTE: The plugin's 'id' field must be set to 'plugin' since
// chrome/renderer/printing/print_web_view_helper.cc actually references it.
this.plugin_.id = 'plugin';
this.plugin_.type = 'application/x-google-chrome-pdf';
this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this),
false);
if (this.isMaterial_) {
this.plugin_.style.height =
(window.innerHeight - this.toolbarHeight_) + 'px';
this.plugin_.style.width = window.innerWidth + 'px';
}
// Handle scripting messages from outside the extension that wish to interact
// with it. We also send a message indicating that extension has loaded and
// is ready to receive messages.
window.addEventListener('message', this.handleScriptingMessage.bind(this),
false);
document.title = getFilenameFromURL(this.streamDetails_.originalUrl);
if (this.isMaterial_)
$('title').textContent = document.title;
this.plugin_.setAttribute('src', this.streamDetails_.originalUrl);
this.plugin_.setAttribute('stream-url', this.streamDetails_.streamUrl);
var headers = '';
for (var header in this.streamDetails_.responseHeaders) {
headers += header + ': ' +
this.streamDetails_.responseHeaders[header] + '\n';
}
this.plugin_.setAttribute('headers', headers);
if (!this.streamDetails_.embedded)
this.plugin_.setAttribute('full-frame', '');
document.body.appendChild(this.plugin_);
// Setup the button event listeners.
$('fit-to-width-button').addEventListener('click',
this.viewport_.fitToWidth.bind(this.viewport_));
$('fit-to-page-button').addEventListener('click',
this.viewport_.fitToPage.bind(this.viewport_));
$('zoom-in-button').addEventListener('click',
this.viewport_.zoomIn.bind(this.viewport_));
$('zoom-out-button').addEventListener('click',
this.viewport_.zoomOut.bind(this.viewport_));
$('save-button').addEventListener('click', this.save_.bind(this));
$('print-button').addEventListener('click', this.print_.bind(this));
// Setup the keyboard event listener.
document.onkeydown = this.handleKeyEvent_.bind(this);
// Set up the zoom API.
if (this.shouldManageZoom_()) {
chrome.tabs.setZoomSettings(this.streamDetails_.tabId,
{mode: 'manual', scope: 'per-tab'},
this.afterZoom_.bind(this));
chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) {
if (zoomChangeInfo.tabId != this.streamDetails_.tabId)
return;
// If the zoom level is close enough to the current zoom level, don't
// change it. This avoids us getting into an infinite loop of zoom changes
// due to floating point error.
var MIN_ZOOM_DELTA = 0.01;
var zoomDelta = Math.abs(this.viewport_.zoom -
zoomChangeInfo.newZoomFactor);
// We should not change zoom level when we are responsible for initiating
// the zoom. onZoomChange() is called before setZoomComplete() callback
// when we initiate the zoom.
if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_)
this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
}.bind(this));
}
// Parse open pdf parameters.
this.paramsParser_ = new OpenPDFParamsParser();
}
PDFViewer.prototype = {
/**
* @private
* Handle key events. These may come from the user directly or via the
* scripting API.
* @param {KeyboardEvent} e the event to handle.
*/
handleKeyEvent_: function(e) {
var position = this.viewport_.position;
// Certain scroll events may be sent from outside of the extension.
var fromScriptingAPI = e.type == 'scriptingKeypress';
var pageUpHandler = function() {
// Go to the previous page if we are fit-to-page.
if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1);
// Since we do the movement of the page.
e.preventDefault();
} else if (fromScriptingAPI) {
position.y -= this.viewport.size.height;
this.viewport.position = position;
}
}.bind(this);
var pageDownHandler = function() {
// Go to the next page if we are fit-to-page.
if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1);
// Since we do the movement of the page.
e.preventDefault();
} else if (fromScriptingAPI) {
position.y += this.viewport.size.height;
this.viewport.position = position;
}
}.bind(this);
switch (e.keyCode) {
case 32: // Space key.
if (e.shiftKey)
pageUpHandler();
else
pageDownHandler();
return;
case 33: // Page up key.
pageUpHandler();
return;
case 34: // Page down key.
pageDownHandler();
return;
case 37: // Left arrow key.
if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) {
// Go to the previous page if there are no horizontal scrollbars.
if (!this.viewport_.documentHasScrollbars().x) {
this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1);
// Since we do the movement of the page.
e.preventDefault();
} else if (fromScriptingAPI) {
position.x -= Viewport.SCROLL_INCREMENT;
this.viewport.position = position;
}
}
return;
case 38: // Up arrow key.
if (fromScriptingAPI) {
position.y -= Viewport.SCROLL_INCREMENT;
this.viewport.position = position;
}
return;
case 39: // Right arrow key.
if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) {
// Go to the next page if there are no horizontal scrollbars.
if (!this.viewport_.documentHasScrollbars().x) {
this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1);
// Since we do the movement of the page.
e.preventDefault();
} else if (fromScriptingAPI) {
position.x += Viewport.SCROLL_INCREMENT;
this.viewport.position = position;
}
}
return;
case 40: // Down arrow key.
if (fromScriptingAPI) {
position.y += Viewport.SCROLL_INCREMENT;
this.viewport.position = position;
}
return;
case 65: // a key.
if (e.ctrlKey || e.metaKey) {
this.plugin_.postMessage({
type: 'selectAll'
});
}
return;
case 80: // p key.
if (e.ctrlKey || e.metaKey) {
this.print_();
// Since we do the printing of the page.
e.preventDefault();
}
return;
case 219: // left bracket.
if (e.ctrlKey) {
this.plugin_.postMessage({
type: 'rotateCounterclockwise'
});
}
return;
case 221: // right bracket.
if (e.ctrlKey) {
this.plugin_.postMessage({
type: 'rotateClockwise'
});
}
return;
}
},
/**
* @private
* Notify the plugin to print.
*/
print_: function() {
this.plugin_.postMessage({
type: 'print'
});
},
/**
* @private
* Notify the plugin to save.
*/
save_: function() {
this.plugin_.postMessage({
type: 'save'
});
},
/**
* @private
* Handle open pdf parameters. This function updates the viewport as per
* the parameters mentioned in the url while opening pdf. The order is
* important as later actions can override the effects of previous actions.
*/
handleURLParams_: function() {
var urlParams =
this.paramsParser_.getViewportFromUrlParams(
this.streamDetails_.originalUrl);
if (urlParams.page)
this.viewport_.goToPage(urlParams.page);
if (urlParams.position) {
// Make sure we don't cancel effect of page parameter.
this.viewport_.position = {
x: this.viewport_.position.x + urlParams.position.x,
y: this.viewport_.position.y + urlParams.position.y
};
}
if (urlParams.zoom)
this.viewport_.setZoom(urlParams.zoom);
},
/**
* @private
* Update the loading progress of the document in response to a progress
* message being received from the plugin.
* @param {number} progress the progress as a percentage.
*/
updateProgress_: function(progress) {
if (this.isMaterial_)
this.progressBar_.value = progress;
else
this.progressBar_.progress = progress;
if (progress == -1) {
// Document load failed.
this.errorScreen_.style.visibility = 'visible';
this.sizer_.style.display = 'none';
this.toolbar_.style.visibility = 'hidden';
if (this.passwordScreen_.active) {
this.passwordScreen_.deny();
this.passwordScreen_.active = false;
}
} else if (progress == 100) {
// Document load complete.
if (this.lastViewportPosition_)
this.viewport_.position = this.lastViewportPosition_;
this.handleURLParams_();
this.loaded_ = true;
while (this.delayedScriptingMessages_.length > 0)
this.handleScriptingMessage(this.delayedScriptingMessages_.shift());
}
},
/**
* @private
* An event handler for handling password-submitted events. These are fired
* when an event is entered into the password screen.
* @param {Object} event a password-submitted event.
*/
onPasswordSubmitted_: function(event) {
this.plugin_.postMessage({
type: 'getPasswordComplete',
password: event.detail.password
});
},
/**
* @private
* Helper function to navigate to given URL. This might involve navigating
* within the PDF page or opening a new url (in the same tab or a new tab).
* @param {string} url The URL to navigate to.
* @param {boolean} newTab Whether to perform the navigation in a new tab or
* in the current tab.
*/
navigate_: function(url, newTab) {
if (url.length == 0)
return;
var originalUrl = this.streamDetails_.originalUrl;
// If |urlFragment| starts with '#', then it's for the same URL with a
// different URL fragment.
if (url.charAt(0) == '#') {
// if '#' is already present in |originalUrl| then remove old fragment
// and add new url fragment.
var hashIndex = originalUrl.search('#');
if (hashIndex != -1)
url = originalUrl.substring(0, hashIndex) + url;
else
url = originalUrl + url;
}
// If there's no scheme, add http.
if (url.indexOf('://') == -1 && url.indexOf('mailto:') == -1)
url = 'http://' + url;
// Make sure url starts with a valid scheme.
if (url.indexOf('http://') != 0 &&
url.indexOf('https://') != 0 &&
url.indexOf('ftp://') != 0 &&
url.indexOf('file://') != 0 &&
url.indexOf('mailto:') != 0) {
return;
}
// Make sure url is not only a scheme.
if (url == 'http://' ||
url == 'https://' ||
url == 'ftp://' ||
url == 'file://' ||
url == 'mailto:') {
return;
}
if (newTab) {
// Prefer the tabs API because it guarantees we can just open a new tab.
// window.open doesn't have this guarantee.
if (chrome.tabs)
chrome.tabs.create({ url: url });
else
window.open(url);
} else {
var pageNumber =
this.paramsParser_.getViewportFromUrlParams(url).page;
if (pageNumber != undefined)
this.viewport_.goToPage(pageNumber);
else
window.location.href = url;
}
},
/**
* @private
* An event handler for handling message events received from the plugin.
* @param {MessageObject} message a message event.
*/
handlePluginMessage_: function(message) {
switch (message.data.type.toString()) {
case 'documentDimensions':
this.documentDimensions_ = message.data;
this.viewport_.setDocumentDimensions(this.documentDimensions_);
// If we received the document dimensions, the password was good so we
// can dismiss the password screen.
if (this.passwordScreen_.active)
this.passwordScreen_.accept();
this.pageIndicator_.initialFadeIn();
this.toolbar_.initialFadeIn();
break;
case 'email':
var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc +
'&bcc=' + message.data.bcc + '&subject=' + message.data.subject +
'&body=' + message.data.body;
window.location.href = href;
break;
case 'getAccessibilityJSONReply':
this.sendScriptingMessage_(message.data);
break;
case 'getPassword':
// If the password screen isn't up, put it up. Otherwise we're
// responding to an incorrect password so deny it.
if (!this.passwordScreen_.active)
this.passwordScreen_.active = true;
else
this.passwordScreen_.deny();
break;
case 'getSelectedTextReply':
this.sendScriptingMessage_(message.data);
break;
case 'goToPage':
this.viewport_.goToPage(message.data.page);
break;
case 'loadProgress':
this.updateProgress_(message.data.progress);
break;
case 'navigate':
// If in print preview, always open a new tab.
if (this.isPrintPreview_)
this.navigate_(message.data.url, true);
else
this.navigate_(message.data.url, message.data.newTab);
break;
case 'setNamedDestinations':
this.paramsParser_.namedDestinations = message.data.namedDestinations;
break;
case 'setScrollPosition':
var position = this.viewport_.position;
if (message.data.x !== undefined)
position.x = message.data.x;
if (message.data.y !== undefined)
position.y = message.data.y;
this.viewport_.position = position;
break;
case 'setTranslatedStrings':
this.passwordScreen_.text = message.data.getPasswordString;
this.progressBar_.text = message.data.loadingString;
if (!this.isPrintPreview_)
this.progressBar_.style.visibility = 'visible';
this.errorScreen_.text = message.data.loadFailedString;
break;
case 'cancelStreamUrl':
chrome.streamsPrivate.abort(this.streamDetails_.streamUrl);
break;
case 'bookmarks':
this.bookmarks_ = message.data.bookmarks;
break;
}
},
/**
* @private
* A callback that's called before the zoom changes. Notify the plugin to stop
* reacting to scroll events while zoom is taking place to avoid flickering.
*/
beforeZoom_: function() {
this.plugin_.postMessage({
type: 'stopScrolling'
});
},
/**
* @private
* A callback that's called after the zoom changes. Notify the plugin of the
* zoom change and to continue reacting to scroll events.
*/
afterZoom_: function() {
var position = this.viewport_.position;
var zoom = this.viewport_.zoom;
if (this.shouldManageZoom_() && !this.setZoomInProgress_) {
this.setZoomInProgress_ = true;
chrome.tabs.setZoom(this.streamDetails_.tabId, zoom,
this.setZoomComplete_.bind(this, zoom));
}
this.plugin_.postMessage({
type: 'viewport',
zoom: zoom,
xOffset: position.x,
yOffset: position.y
});
},
/**
* @private
* A callback that's called after chrome.tabs.setZoom is complete. This will
* call chrome.tabs.setZoom again if the zoom level has changed since it was
* last called.
* @param {number} lastZoom the zoom level that chrome.tabs.setZoom was called
* with.
*/
setZoomComplete_: function(lastZoom) {
var zoom = this.viewport_.zoom;
if (zoom !== lastZoom) {
chrome.tabs.setZoom(this.streamDetails_.tabId, zoom,
this.setZoomComplete_.bind(this, zoom));
} else {
this.setZoomInProgress_ = false;
}
},
/**
* @private
* A callback that's called after the viewport changes.
*/
viewportChanged_: function() {
if (!this.documentDimensions_)
return;
if (this.isMaterial_) {
this.plugin_.style.height =
(window.innerHeight - this.toolbarHeight_) + 'px';
this.plugin_.style.width = window.innerWidth + 'px';
}
// Update the buttons selected.
$('fit-to-page-button').classList.remove('polymer-selected');
$('fit-to-width-button').classList.remove('polymer-selected');
if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
$('fit-to-page-button').classList.add('polymer-selected');
} else if (this.viewport_.fittingType ==
Viewport.FittingType.FIT_TO_WIDTH) {
$('fit-to-width-button').classList.add('polymer-selected');
}
var hasScrollbars = this.viewport_.documentHasScrollbars();
var scrollbarWidth = this.viewport_.scrollbarWidth;
// Offset the toolbar position so that it doesn't move if scrollbars appear.
var toolbarRight = Math.max(PDFViewer.MIN_TOOLBAR_OFFSET, scrollbarWidth);
var toolbarBottom = Math.max(PDFViewer.MIN_TOOLBAR_OFFSET, scrollbarWidth);
if (hasScrollbars.vertical)
toolbarRight -= scrollbarWidth;
if (hasScrollbars.horizontal)
toolbarBottom -= scrollbarWidth;
this.toolbar_.style.right = toolbarRight + 'px';
this.toolbar_.style.bottom = toolbarBottom + 'px';
// Hide the toolbar if it doesn't fit in the viewport.
if (this.toolbar_.offsetLeft < 0 || this.toolbar_.offsetTop < 0)
this.toolbar_.style.visibility = 'hidden';
else
this.toolbar_.style.visibility = 'visible';
// Update the page indicator.
var visiblePage = this.viewport_.getMostVisiblePage();
this.pageIndicator_.index = visiblePage;
if (this.documentDimensions_.pageDimensions.length > 1 &&
hasScrollbars.vertical) {
this.pageIndicator_.style.visibility = 'visible';
} else {
this.pageIndicator_.style.visibility = 'hidden';
}
var visiblePageDimensions = this.viewport_.getPageScreenRect(visiblePage);
var size = this.viewport_.size;
this.sendScriptingMessage_({
type: 'viewport',
pageX: visiblePageDimensions.x,
pageY: visiblePageDimensions.y,
pageWidth: visiblePageDimensions.width,
viewportWidth: size.width,
viewportHeight: size.height
});
},
/**
* Handle a scripting message from outside the extension (typically sent by
* PDFScriptingAPI in a page containing the extension) to interact with the
* plugin.
* @param {MessageObject} message the message to handle.
*/
handleScriptingMessage: function(message) {
if (this.parentWindow_ != message.source)
this.parentWindow_ = message.source;
if (this.handlePrintPreviewScriptingMessage_(message))
return;
// Delay scripting messages from users of the scripting API until the
// document is loaded. This simplifies use of the APIs.
if (!this.loaded_) {
this.delayedScriptingMessages_.push(message);
return;
}
switch (message.data.type.toString()) {
case 'getAccessibilityJSON':
case 'getSelectedText':
case 'print':
case 'selectAll':
this.plugin_.postMessage(message.data);
break;
case 'isDocumentLoaded':
// Since this is only hit after the document has been loaded, we can
// send a reply immediately.
this.sendScriptingMessage_({
type: 'documentLoaded'
});
break;
}
},
/**
* @private
* Handle scripting messages specific to print preview.
* @param {MessageObject} message the message to handle.
* @return {boolean} true if the message was handled, false otherwise.
*/
handlePrintPreviewScriptingMessage_: function(message) {
if (!this.isPrintPreview_)
return false;
switch (message.data.type.toString()) {
case 'loadPreviewPage':
this.plugin_.postMessage(message.data);
return true;
case 'resetPrintPreviewMode':
if (!this.inPrintPreviewMode_) {
this.inPrintPreviewMode_ = true;
this.viewport_.fitToPage();
}
// Stash the scroll location so that it can be restored when the new
// document is loaded.
this.lastViewportPosition_ = this.viewport_.position;
// TODO(raymes): Disable these properly in the plugin.
var printButton = $('print-button');
if (printButton)
printButton.parentNode.removeChild(printButton);
var saveButton = $('save-button');
if (saveButton)
saveButton.parentNode.removeChild(saveButton);
this.pageIndicator_.pageLabels = message.data.pageNumbers;
this.plugin_.postMessage({
type: 'resetPrintPreviewMode',
url: message.data.url,
grayscale: message.data.grayscale,
// If the PDF isn't modifiable we send 0 as the page count so that no
// blank placeholder pages get appended to the PDF.
pageCount: (message.data.modifiable ?
message.data.pageNumbers.length : 0)
});
return true;
case 'sendKeyEvent':
var e = document.createEvent('Event');
e.initEvent('scriptingKeypress');
e.keyCode = message.data.keyCode;
this.handleKeyEvent_(e);
return true;
}
return false;
},
/**
* @private
* Send a scripting message outside the extension (typically to
* PDFScriptingAPI in a page containing the extension).
* @param {Object} message the message to send.
*/
sendScriptingMessage_: function(message) {
if (this.parentWindow_)
this.parentWindow_.postMessage(message, '*');
},
/**
* @private
* Return whether this PDFViewer should manage zoom for its containing page.
* @return {boolean} Whether this PDFViewer should manage zoom for its
* containing page.
*/
shouldManageZoom_: function() {
return !!(chrome.tabs && !this.streamDetails_.embedded &&
this.streamDetails_.tabId != -1);
},
/**
* @type {Viewport} the viewport of the PDF viewer.
*/
get viewport() {
return this.viewport_;
}
};
|