Chromium Code Reviews| Index: chrome/browser/resources/pdf/pdf.js |
| diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..533b14701cfb50b025ceeb771f6c1f5bd8c9bdde |
| --- /dev/null |
| +++ b/chrome/browser/resources/pdf/pdf.js |
| @@ -0,0 +1,43 @@ |
| +// 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. |
| +var plugin; |
|
tapted
2013/12/02 04:17:19
nit: maybe do that closury thing, putting
`(funct
raymes
2013/12/04 04:54:49
Done.
|
| +var sizer; |
| + |
| +function onScroll() { |
| + var coordinates = [window.pageXOffset, window.pageYOffset]; |
| + plugin.postMessage(coordinates); |
| +} |
| + |
| +function handleMessage(message) { |
| + if (message.data['type'] == 'document_dimensions') { |
| + if (sizer.style.height != message.data['document_height'] + 'px') { |
| + sizer.style.height = message.data['document_height'] + 'px'; |
| + sizer.style.width = message.data['document_width'] + 'px'; |
| + } |
| + } |
| +} |
| + |
| +function load() { |
| + window.onscroll = function() { webkitRequestAnimationFrame(onScroll); }; |
|
tapted
2013/12/02 04:17:19
Is this the same as window.addEventListener('scrol
raymes
2013/12/04 04:54:49
Done.
|
| + |
| + var url = location.search.substring(1); |
|
tapted
2013/12/02 04:17:19
Maybe a comment, "pop off the leading '?'". And is
raymes
2013/12/04 04:54:49
Done.
|
| + plugin = document.createElement('object'); |
| + plugin.setAttribute('width', '100%'); |
| + plugin.setAttribute('height', '100%'); |
| + plugin.setAttribute('type', 'application/x-google-chrome-pdf'); |
| + plugin.setAttribute('src', url); |
| + plugin.style.zIndex = '1'; |
| + plugin.style.position = 'fixed'; |
| + plugin.addEventListener('message', handleMessage, false); |
| + document.body.appendChild(plugin); |
| + |
| + sizer = document.createElement('div'); |
| + sizer.style.zIndex = '0'; |
| + sizer.style.position = 'absolute'; |
| + sizer.style.width = '100%'; |
| + sizer.style.height = '100%'; |
| + document.body.appendChild(sizer); |
| +} |
| + |
| +load(); |