Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/resources/pdf/main.js

Issue 797183005: Add a mimeHandler extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@streams-lifetime
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Global PDFViewer object, accessible for testing. 8 * Global PDFViewer object, accessible for testing.
9 * @type Object 9 * @type Object
10 */ 10 */
(...skipping 22 matching lines...) Expand all
33 * contained in the PDF. 33 * contained in the PDF.
34 */ 34 */
35 function initViewer(streamDetails) { 35 function initViewer(streamDetails) {
36 // PDFViewer will handle any messages after it is created. 36 // PDFViewer will handle any messages after it is created.
37 window.removeEventListener('message', handleScriptingMessage, false); 37 window.removeEventListener('message', handleScriptingMessage, false);
38 viewer = new PDFViewer(streamDetails); 38 viewer = new PDFViewer(streamDetails);
39 while (pendingMessages.length > 0) 39 while (pendingMessages.length > 0)
40 viewer.handleScriptingMessage(pendingMessages.shift()); 40 viewer.handleScriptingMessage(pendingMessages.shift());
41 } 41 }
42 42
43 /** 43 function generateStreamDetailsAndInitViewer() {
44 * Entrypoint for starting the PDF viewer. This function obtains the details
45 * of the PDF 'stream' (the data that points to the PDF) and constructs a
46 * PDFViewer object with it.
47 */
48 function main() {
49 // Set up an event listener to catch scripting messages which are sent prior
50 // to the PDFViewer being created.
51 window.addEventListener('message', handleScriptingMessage, false);
52
53 // If the viewer is started from the browser plugin, the view ID will be
54 // passed in which identifies the instance of the plugin.
55 var params = window.location.search.substring(1).split('=');
56 if (params.length == 2 && params[0] == 'id') {
57 var viewId = params[1];
58
59 // Send a message to the background page to obtain the stream details. It
60 // will run the callback function passed in to initialize the viewer.
61 chrome.runtime.sendMessage(
62 'mhjfbmdgcfjbbpaeojofohoefgiehjai',
63 {viewId: viewId},
64 initViewer);
65 return;
66 }
67
68 // The viewer may be started directly by passing in the URL of the PDF to
69 // load as the query string. This is used for print preview in particular.
70 // The URL of this page will be of the form
71 // 'chrome-extension://<extension id>?<pdf url>'. We pull out the <pdf url>
72 // part here.
73 var url = window.location.search.substring(1); 44 var url = window.location.search.substring(1);
74 var streamDetails = { 45 var streamDetails = {
75 streamUrl: url, 46 streamUrl: url,
76 originalUrl: url, 47 originalUrl: url,
77 responseHeaders: '', 48 responseHeaders: '',
78 embedded: window.parent != window, 49 embedded: window.parent != window,
79 tabId: -1 50 tabId: -1
80 }; 51 };
81 if (!chrome.tabs) { 52 if (!chrome.tabs) {
82 initViewer(streamDetails); 53 initViewer(streamDetails);
83 return; 54 return;
84 } 55 }
85 chrome.tabs.getCurrent(function(tab) { 56 chrome.tabs.getCurrent(function(tab) {
86 if (tab && tab.id != undefined) 57 streamDetails.tabId = tab.id;
87 streamDetails.tabId = tab.id;
88 initViewer(streamDetails); 58 initViewer(streamDetails);
89 }); 59 });
90 } 60 }
91 61
62 /**
63 * Entrypoint for starting the PDF viewer. This function obtains the details
64 * of the PDF 'stream' (the data that points to the PDF) and constructs a
65 * PDFViewer object with it.
66 */
67 function main() {
68 // Set up an event listener to catch scripting messages which are sent prior
69 // to the PDFViewer being created.
70 window.addEventListener('message', handleScriptingMessage, false);
71
72 // If the viewer is started from the browser plugin, getStreamInfo will
73 // return the details of the stream.
74 if (!chrome.mimeHandler) {
75 generateStreamDetailsAndInitViewer();
76 return;
77 }
78 chrome.mimeHandler.getStreamInfo(function(streamDetails) {
79 if (streamDetails) {
80 initViewer(streamDetails);
81 } else {
82 generateStreamDetailsAndInitViewer();
83 }
84 });
85 };
86
92 main(); 87 main();
93 })(); 88 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698