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 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" 6 7 #include "base/command_line.h" 8 #include "base/logging.h" 9 #include "base/prefs/pref_service.h" 10 #include "base/strings/stringprintf.h" 11 #include "chrome/browser/google/google_util.h" 12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/pref_names.h" 15 #include "components/user_prefs/pref_registry_syncable.h" 16 #include "google_apis/gaia/gaia_urls.h" 17 #include "net/base/escape.h" 18 #include "url/gurl.h" 19 20 // Url must not be matched by "urls" section of 21 // cloud_print_app/manifest.json. If it's matched, print driver dialog will 22 // open sign-in page in separate window. 23 const char kDefaultCloudPrintServiceURL[] = "https://www.google.com/cloudprint"; 24 25 const char kLearnMoreURL[] = 26 "https://www.google.com/support/cloudprint"; 27 const char kTestPageURL[] = 28 "http://www.google.com/landing/cloudprint/enable.html?print=true"; 29 30 // static 31 void CloudPrintURL::RegisterProfilePrefs( 32 user_prefs::PrefRegistrySyncable* registry) { 33 registry->RegisterStringPref( 34 prefs::kCloudPrintServiceURL, 35 kDefaultCloudPrintServiceURL, 36 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 37 std::string url = GaiaUrls::GetInstance()->service_login_url(); 38 url.append("?service=cloudprint&sarp=1&continue="); 39 url.append(net::EscapeQueryParamValue(kDefaultCloudPrintServiceURL, false)); 40 registry->RegisterStringPref( 41 prefs::kCloudPrintSigninURL, 42 url, 43 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 44 } 45 46 // Returns the root service URL for the cloud print service. The default is to 47 // point at the Google Cloud Print service. This can be overridden by the 48 // command line or by the user preferences. 49 GURL CloudPrintURL::GetCloudPrintServiceURL() { 50 DCHECK(profile_); 51 52 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 53 GURL cloud_print_service_url = GURL(command_line.GetSwitchValueASCII( 54 switches::kCloudPrintServiceURL)); 55 if (cloud_print_service_url.is_empty()) { 56 cloud_print_service_url = GURL( 57 profile_->GetPrefs()->GetString(prefs::kCloudPrintServiceURL)); 58 } 59 return cloud_print_service_url; 60 } 61 62 GURL CloudPrintURL::GetCloudPrintSigninURL() { 63 DCHECK(profile_); 64 65 GURL cloud_print_signin_url = GURL( 66 profile_->GetPrefs()->GetString(prefs::kCloudPrintSigninURL)); 67 return google_util::AppendGoogleLocaleParam(cloud_print_signin_url); 68 } 69 70 GURL CloudPrintURL::GetCloudPrintServiceDialogURL() { 71 GURL cloud_print_service_url = GetCloudPrintServiceURL(); 72 std::string path(cloud_print_service_url.path() + "/client/dialog.html"); 73 GURL::Replacements replacements; 74 replacements.SetPathStr(path); 75 GURL cloud_print_dialog_url = cloud_print_service_url.ReplaceComponents( 76 replacements); 77 return google_util::AppendGoogleLocaleParam(cloud_print_dialog_url); 78 } 79 80 GURL CloudPrintURL::GetCloudPrintServiceManageURL() { 81 GURL cloud_print_service_url = GetCloudPrintServiceURL(); 82 std::string path(cloud_print_service_url.path() + "/manage.html"); 83 GURL::Replacements replacements; 84 replacements.SetPathStr(path); 85 GURL cloud_print_manage_url = cloud_print_service_url.ReplaceComponents( 86 replacements); 87 return cloud_print_manage_url; 88 } 89 90 GURL CloudPrintURL::GetCloudPrintServiceEnableURL( 91 const std::string& proxy_id) { 92 GURL cloud_print_service_url = GetCloudPrintServiceURL(); 93 std::string path(cloud_print_service_url.path() + 94 "/enable_chrome_connector/enable.html"); 95 GURL::Replacements replacements; 96 replacements.SetPathStr(path); 97 std::string query = base::StringPrintf("proxy=%s", proxy_id.c_str()); 98 replacements.SetQueryStr(query); 99 GURL cloud_print_enable_url = cloud_print_service_url.ReplaceComponents( 100 replacements); 101 return cloud_print_enable_url; 102 } 103 104 GURL CloudPrintURL::GetCloudPrintLearnMoreURL() { 105 GURL cloud_print_learn_more_url(kLearnMoreURL); 106 return cloud_print_learn_more_url; 107 } 108 109 GURL CloudPrintURL::GetCloudPrintTestPageURL() { 110 GURL cloud_print_learn_more_url(kTestPageURL); 111 return cloud_print_learn_more_url; 112 } 113