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

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

Issue 7038028: Initial support for cloudprint in print preview (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix bad merge Created 9 years, 7 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
(Empty)
1 // Copyright (c) 2011 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 cr.define('cloudprint', function() {
6
7 var cloudPrintBaseURL = '';
8
9 function setBaseURL(cloudPrintURL) {
10 cloudPrintBaseURL = cloudPrintURL;
11 }
12
13 function sendCloudPrintRequest(method,
14 action,
15 headers,
16 body,
17 callback,
18 async) {
19 var xhr = new XMLHttpRequest();
20 if (callback != null) {
21 xhr.onreadystatechange = function() {
22 if (xhr.readyState == 4) {
23 callback.call(this, xhr);
24 }
25 };
26 }
27 var url = cloudPrintBaseURL + '/' + action
28 xhr.open(method, url, async);
29 xhr.setRequestHeader("Content-Type",
30 "application/x-www-form-urlencoded;charset=UTF-8");
31 if (headers) {
32 for (var header in headers) {
33 if (headers.hasOwnProperty(header)) {
34 xhr.setRequestHeader(header, headers[header]);
35 }
36 }
37 }
38 xhr.send(body);
39 return xhr;
40 }
41
42 function fetchPrinters(callback) {
43 try {
44 var xhr = sendCloudPrintRequest('POST',
45 'search',
46 {'Content-Type':
47 'application/x-www-form-urlencoded',
48 'X-CloudPrint-Proxy':
49 'ChromePrintPreview'},
50 '',
51 null,
52 false);
53 var searchResult = JSON.parse(xhr.responseText);
54 if (searchResult['success']) {
55 var printerList = searchResult['printers'];
56 callback.call(this, printerList);
57 }
58 } catch (err) {
59 callback.call(this, null);
60 }
61 }
62
63 function printToCloudResponse(callback, xhr) {
64 if (xhr.status == 200) {
sanjeevr 2011/05/24 23:21:25 Don't we need to update some error status if it fa
Albert Bodenhamer 2011/06/09 17:33:11 Some sort of feedback would definitely be good. I
65 var printResult = JSON.parse(xhr.responseText);
66 if (printResult['success']) {
67 callback.call();
68 }
69 }
70 }
71
72 function printToCloud(data, callback) {
73 sendCloudPrintRequest('POST',
74 'submit',
75 {'X-CloudPrint-Proxy': 'ChromePrintPreview'},
76 data,
77 printToCloudResponse.bind(this, callback),
78 true);
79 }
80
81 return {
82 fetchPrinters: fetchPrinters,
83 printToCloud: printToCloud,
84 setBaseURL: setBaseURL
85 };
86 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698