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

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

Issue 169613005: Hookup print and save buttons in the out of process PDF plugin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/pdf/index.in.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 (function() { 5 (function() {
6 'use strict'; 6 'use strict';
7 7
8 <include src="../../../../ui/webui/resources/js/util.js"></include> 8 <include src="../../../../ui/webui/resources/js/util.js"></include>
9 <include src="viewport.js"></include> 9 <include src="viewport.js"></include>
10 10
(...skipping 18 matching lines...) Expand all
29 29
30 // The element indicating there was an error loading the document. 30 // The element indicating there was an error loading the document.
31 var viewerErrorScreen; 31 var viewerErrorScreen;
32 32
33 // The viewport object. 33 // The viewport object.
34 var viewport; 34 var viewport;
35 35
36 // The document dimensions. 36 // The document dimensions.
37 var documentDimensions; 37 var documentDimensions;
38 38
39 // Notify the plugin to print.
40 function print() {
41 plugin.postMessage({
42 type: 'print',
43 });
44 }
45
39 // Returns true if the fit-to-page button is enabled. 46 // Returns true if the fit-to-page button is enabled.
40 function isFitToPageEnabled() { 47 function isFitToPageEnabled() {
41 return $('fit-to-page-button').classList.contains('polymer-selected'); 48 return $('fit-to-page-button').classList.contains('polymer-selected');
42 } 49 }
43 50
44 function updateProgress(progress) { 51 function updateProgress(progress) {
45 viewerProgressBar.progress = progress; 52 viewerProgressBar.progress = progress;
46 if (progress == -1) { 53 if (progress == -1) {
47 // Document load failed. 54 // Document load failed.
48 viewerErrorScreen.style.visibility = 'visible'; 55 viewerErrorScreen.style.visibility = 'visible';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 viewport = new Viewport(window, 120 viewport = new Viewport(window,
114 sizer, 121 sizer,
115 isFitToPageEnabled, 122 isFitToPageEnabled,
116 viewportChangedCallback); 123 viewportChangedCallback);
117 124
118 // Create the plugin object dynamically so we can set its src. 125 // Create the plugin object dynamically so we can set its src.
119 plugin = document.createElement('object'); 126 plugin = document.createElement('object');
120 plugin.id = 'plugin'; 127 plugin.id = 'plugin';
121 plugin.type = 'application/x-google-chrome-pdf'; 128 plugin.type = 'application/x-google-chrome-pdf';
122 plugin.addEventListener('message', handleMessage, false); 129 plugin.addEventListener('message', handleMessage, false);
123 // The pdf location is passed in the document url in the format: 130 // The pdf location is passed in stream details in the background page.
124 // http://<.../pdf.html>?<pdf location>. 131 var streamDetails = chrome.extension.getBackgroundPage().popStreamDetails();
125 var url = window.location.search.substring(1); 132 plugin.setAttribute('src', streamDetails.streamURL);
126 plugin.setAttribute('src', url);
127 document.body.appendChild(plugin); 133 document.body.appendChild(plugin);
128 134
129 // Setup the button event listeners. 135 // Setup the button event listeners.
130 $('fit-to-width-button').addEventListener('click', 136 $('fit-to-width-button').addEventListener('click',
131 viewport.fitToWidth.bind(viewport)); 137 viewport.fitToWidth.bind(viewport));
132 $('fit-to-page-button').addEventListener('click', 138 $('fit-to-page-button').addEventListener('click',
133 viewport.fitToPage.bind(viewport)); 139 viewport.fitToPage.bind(viewport));
134 $('zoom-in-button').addEventListener('click', 140 $('zoom-in-button').addEventListener('click',
135 viewport.zoomIn.bind(viewport)); 141 viewport.zoomIn.bind(viewport));
136 $('zoom-out-button').addEventListener('click', 142 $('zoom-out-button').addEventListener('click',
137 viewport.zoomOut.bind(viewport)); 143 viewport.zoomOut.bind(viewport));
144 $('save-button-link').href = streamDetails.originalURL;
145 $('print-button').addEventListener('click', print);
146
138 147
139 // Setup keyboard event listeners. 148 // Setup keyboard event listeners.
140 document.onkeydown = function(e) { 149 document.onkeydown = function(e) {
141 switch (e.keyCode) { 150 switch (e.keyCode) {
142 case 37: // Left arrow key. 151 case 37: // Left arrow key.
143 // Go to the previous page if there are no horizontal scrollbars. 152 // Go to the previous page if there are no horizontal scrollbars.
144 if (!viewport.documentHasScrollbars().x) { 153 if (!viewport.documentHasScrollbars().x) {
145 viewport.goToPage(viewport.getMostVisiblePage() - 1); 154 viewport.goToPage(viewport.getMostVisiblePage() - 1);
146 // Since we do the movement of the page 155 // Since we do the movement of the page
147 e.preventDefault(); 156 e.preventDefault();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 e.preventDefault(); 200 e.preventDefault();
192 } 201 }
193 return; 202 return;
194 } 203 }
195 }; 204 };
196 } 205 }
197 206
198 load(); 207 load();
199 208
200 })(); 209 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/index.in.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698