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

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
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 15 matching lines...) Expand all
26 26
27 // The progress bar element. 27 // The progress bar element.
28 var viewerProgressBar; 28 var viewerProgressBar;
29 29
30 // The viewport object. 30 // The viewport object.
31 var viewport; 31 var viewport;
32 32
33 // The document dimensions. 33 // The document dimensions.
34 var documentDimensions; 34 var documentDimensions;
35 35
36 // Notify the plugin to print.
37 function print() {
38 plugin.postMessage({
39 type: 'print',
40 });
41 }
42
36 // Returns true if the fit-to-page button is enabled. 43 // Returns true if the fit-to-page button is enabled.
37 function isFitToPageEnabled() { 44 function isFitToPageEnabled() {
38 return $('fit-to-page-button').classList.contains('polymer-selected'); 45 return $('fit-to-page-button').classList.contains('polymer-selected');
39 } 46 }
40 47
41 function updateProgress(progress) { 48 function updateProgress(progress) {
42 viewerProgressBar.progress = progress; 49 viewerProgressBar.progress = progress;
43 if (progress == -1) { 50 if (progress == -1) {
44 // Document load failed. 51 // Document load failed.
45 sizer.style.display = 'none'; 52 sizer.style.display = 'none';
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 viewport = new Viewport(window, 108 viewport = new Viewport(window,
102 sizer, 109 sizer,
103 isFitToPageEnabled, 110 isFitToPageEnabled,
104 viewportChangedCallback); 111 viewportChangedCallback);
105 112
106 // Create the plugin object dynamically so we can set its src. 113 // Create the plugin object dynamically so we can set its src.
107 plugin = document.createElement('object'); 114 plugin = document.createElement('object');
108 plugin.id = 'plugin'; 115 plugin.id = 'plugin';
109 plugin.type = 'application/x-google-chrome-pdf'; 116 plugin.type = 'application/x-google-chrome-pdf';
110 plugin.addEventListener('message', handleMessage, false); 117 plugin.addEventListener('message', handleMessage, false);
111 // The pdf location is passed in the document url in the format: 118 // The pdf location is passed in stream details in the background page.
112 // http://<.../pdf.html>?<pdf location>. 119 var streamDetails = chrome.extension.getBackgroundPage().popStreamDetails();
113 var url = window.location.search.substring(1); 120 plugin.setAttribute('src', streamDetails.streamURL);
114 plugin.setAttribute('src', url);
115 document.body.appendChild(plugin); 121 document.body.appendChild(plugin);
116 122
117 // Setup the button event listeners. 123 // Setup the button event listeners.
118 $('fit-to-width-button').addEventListener('click', 124 $('fit-to-width-button').addEventListener('click',
119 viewport.fitToWidth.bind(viewport)); 125 viewport.fitToWidth.bind(viewport));
120 $('fit-to-page-button').addEventListener('click', 126 $('fit-to-page-button').addEventListener('click',
121 viewport.fitToPage.bind(viewport)); 127 viewport.fitToPage.bind(viewport));
122 $('zoom-in-button').addEventListener('click', 128 $('zoom-in-button').addEventListener('click',
123 viewport.zoomIn.bind(viewport)); 129 viewport.zoomIn.bind(viewport));
124 $('zoom-out-button').addEventListener('click', 130 $('zoom-out-button').addEventListener('click',
125 viewport.zoomOut.bind(viewport)); 131 viewport.zoomOut.bind(viewport));
132 $('save-button-link').href = streamDetails.originalURL;
133 $('print-button').addEventListener('click', print);
134
126 135
127 // Setup keyboard event listeners. 136 // Setup keyboard event listeners.
128 document.onkeydown = function(e) { 137 document.onkeydown = function(e) {
129 switch (e.keyCode) { 138 switch (e.keyCode) {
130 case 37: // Left arrow key. 139 case 37: // Left arrow key.
131 // Go to the previous page if there are no horizontal scrollbars. 140 // Go to the previous page if there are no horizontal scrollbars.
132 if (!viewport.documentHasScrollbars().x) { 141 if (!viewport.documentHasScrollbars().x) {
133 viewport.goToPage(viewport.getMostVisiblePage() - 1); 142 viewport.goToPage(viewport.getMostVisiblePage() - 1);
134 // Since we do the movement of the page 143 // Since we do the movement of the page
135 e.preventDefault(); 144 e.preventDefault();
(...skipping 20 matching lines...) Expand all
156 e.preventDefault(); 165 e.preventDefault();
157 } 166 }
158 return; 167 return;
159 } 168 }
160 }; 169 };
161 } 170 }
162 171
163 load(); 172 load();
164 173
165 })(); 174 })();
OLDNEW
« chrome/browser/resources/pdf/index.html ('K') | « 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