OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 'use strict'; |
| 6 |
| 7 <include src="../../../../ui/webui/resources/js/util.js"> |
| 8 <include src="open_pdf_params_parser.js"> |
| 9 <include src="pdf.js"> |
| 10 <include src="pdf_scripting_api.js"> |
| 11 <include src="viewport.js"> |
| 12 |
| 13 /** |
| 14 * Global PDFViewer object, accessible for testing. |
| 15 * @type Object |
| 16 */ |
| 17 var viewer; |
| 18 |
| 19 /** |
| 20 * Entrypoint for starting the PDF viewer. This function obtains the details |
| 21 * of the PDF 'stream' (the data that points to the PDF) and constructs a |
| 22 * PDFViewer object with it. |
| 23 */ |
| 24 (function main() { |
| 25 // If the viewer is started from the browser plugin, the view ID will be |
| 26 // passed in which identifies the instance of the plugin. |
| 27 var params = window.location.search.substring(1).split('='); |
| 28 if (params.length == 2 && params[0] == 'id') { |
| 29 var viewId = params[1]; |
| 30 |
| 31 // Send a message to the background page to obtain the stream details. It |
| 32 // will run the callback function passed in to initialize the viewer. |
| 33 chrome.runtime.sendMessage( |
| 34 'mhjfbmdgcfjbbpaeojofohoefgiehjai', |
| 35 {viewId: viewId}, |
| 36 function(streamDetails) { viewer = new PDFViewer(streamDetails); }); |
| 37 return; |
| 38 } |
| 39 |
| 40 // The viewer may be started directly by passing in the URL of the PDF to load |
| 41 // as the query string. This is used for print preview in particular. The URL |
| 42 // of this page will be of the form |
| 43 // 'chrome-extension://<extension id>?<pdf url>'. We pull out the <pdf url> |
| 44 // part here. |
| 45 var url = window.location.search.substring(1); |
| 46 var streamDetails = { |
| 47 streamUrl: url, |
| 48 originalUrl: url, |
| 49 responseHeaders: '' |
| 50 }; |
| 51 viewer = new PDFViewer(streamDetails); |
| 52 })(); |
OLD | NEW |