15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <map> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector> 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL; 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DictionaryValue; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Helper consts and methods for both cloud print and chrome browser. 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace cloud_print { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A map representing printer tags. 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef std::map<std::string, std::string> PrinterTags; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Appends a relative path to the url making sure to append a '/' if the 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// URL's path does not end with a slash. It is assumed that |path| does not 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// begin with a '/'. 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: Since we ALWAYS want to append here, we simply append the path string 30010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// instead of calling url::ResolveRelative. The input |url| may or may not 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// contain a '/' at the end. 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)std::string AppendPathToUrl(const GURL& url, const std::string& path); 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GURL GetUrlForSearch(const GURL& cloud_print_server_url); 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GURL GetUrlForSubmit(const GURL& cloud_print_server_url); 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)GURL GetUrlForPrinterList(const GURL& cloud_print_server_url, 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& proxy_id); 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)GURL GetUrlForPrinterRegistration(const GURL& cloud_print_server_url); 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)GURL GetUrlForPrinterUpdate(const GURL& cloud_print_server_url, 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& printer_id); 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)GURL GetUrlForPrinterDelete(const GURL& cloud_print_server_url, 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& printer_id, 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& reason); 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)GURL GetUrlForJobFetch(const GURL& cloud_print_server_url, 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& printer_id, 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& reason); 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)GURL GetUrlForJobCjt(const GURL& cloud_print_server_url, 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& job_id, 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& reason); 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)GURL GetUrlForJobDelete(const GURL& cloud_print_server_url, 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& job_id); 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)GURL GetUrlForJobStatusUpdate(const GURL& cloud_print_server_url, 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& job_id, 5468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const std::string& status_string, 5568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int connector_code); 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)GURL GetUrlForUserMessage(const GURL& cloud_print_server_url, 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& message_id); 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)GURL GetUrlForGetAuthCode(const GURL& cloud_print_server_url, 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& oauth_client_id, 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& proxy_id); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Parses the response data for any cloud print server request. The method 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// returns null if there was an error in parsing the JSON. The succeeded 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// value returns the value of the "success" value in the response JSON. 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the response as a dictionary value. 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)scoped_ptr<base::DictionaryValue> ParseResponseJSON( 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& response_data, 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool* succeeded); 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the MIME type of multipart with |mime_boundary|. 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)std::string GetMultipartMimeType(const std::string& mime_boundary); 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Create a MIME boundary marker (27 '-' characters followed by 16 hex digits). 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CreateMimeBoundaryForUpload(std::string *out); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns an MD5 hash for |printer_tags| and the default required tags. 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)std::string GetHashOfPrinterTags(const PrinterTags& printer_tags); 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the post data for |printer_tags| and the default required tags. 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)std::string GetPostDataForPrinterTags( 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const PrinterTags& printer_tags, 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& mime_boundary, 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& proxy_tag_prefix, 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& tags_hash_tag_name); 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Get the cloud print auth header from |auth_token|. 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)std::string GetCloudPrintAuthHeader(const std::string& auth_token); 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace cloud_print 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ 92