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.
5 #include "chrome/browser/printing/cloud_print/cloud_print_url.h"
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/url_util.h"
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";
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";
31 void CloudPrintURL::RegisterProfilePrefs(
32 user_prefs::PrefRegistrySyncable
* registry
) {
33 const CommandLine
* command_line
= CommandLine::ForCurrentProcess();
35 command_line
->GetSwitchValueASCII(switches::kCloudPrintServiceURL
));
36 if (cloud_print_url
.is_empty())
37 cloud_print_url
= GURL(kDefaultCloudPrintServiceURL
);
38 registry
->RegisterStringPref(
39 prefs::kCloudPrintServiceURL
,
40 cloud_print_url
.spec(),
41 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
42 GURL
gaia_url(GaiaUrls::GetInstance()->service_login_url());
43 gaia_url
= net::AppendQueryParameter(gaia_url
, "service", "cloudprint");
44 gaia_url
= net::AppendQueryParameter(gaia_url
, "sarp", "1");
45 gaia_url
= net::AppendQueryParameter(gaia_url
, "continue",
46 cloud_print_url
.spec());
47 registry
->RegisterStringPref(
48 prefs::kCloudPrintSigninURL
,
50 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
53 // Returns the root service URL for the cloud print service. The default is to
54 // point at the Google Cloud Print service. This can be overridden by the
55 // command line or by the user preferences.
56 GURL
CloudPrintURL::GetCloudPrintServiceURL() {
58 return GURL(profile_
->GetPrefs()->GetString(prefs::kCloudPrintServiceURL
));
61 GURL
CloudPrintURL::GetCloudPrintSigninURL() {
63 GURL
cloud_print_signin_url(
64 profile_
->GetPrefs()->GetString(prefs::kCloudPrintSigninURL
));
65 return google_util::AppendGoogleLocaleParam(cloud_print_signin_url
);
68 GURL
CloudPrintURL::GetCloudPrintServiceDialogURL() {
69 GURL cloud_print_service_url
= GetCloudPrintServiceURL();
70 std::string
path(cloud_print_service_url
.path() + "/client/dialog.html");
71 GURL::Replacements replacements
;
72 replacements
.SetPathStr(path
);
73 GURL cloud_print_dialog_url
= cloud_print_service_url
.ReplaceComponents(
75 return google_util::AppendGoogleLocaleParam(cloud_print_dialog_url
);
78 GURL
CloudPrintURL::GetCloudPrintServiceManageURL() {
79 GURL cloud_print_service_url
= GetCloudPrintServiceURL();
80 std::string
path(cloud_print_service_url
.path() + "/manage.html");
81 GURL::Replacements replacements
;
82 replacements
.SetPathStr(path
);
83 GURL cloud_print_manage_url
= cloud_print_service_url
.ReplaceComponents(
85 return cloud_print_manage_url
;
88 GURL
CloudPrintURL::GetCloudPrintServiceEnableURL(
89 const std::string
& proxy_id
) {
90 GURL cloud_print_service_url
= GetCloudPrintServiceURL();
91 std::string
path(cloud_print_service_url
.path() +
92 "/enable_chrome_connector/enable.html");
93 GURL::Replacements replacements
;
94 replacements
.SetPathStr(path
);
95 std::string query
= base::StringPrintf("proxy=%s", proxy_id
.c_str());
96 replacements
.SetQueryStr(query
);
97 GURL cloud_print_enable_url
= cloud_print_service_url
.ReplaceComponents(
99 return cloud_print_enable_url
;
102 GURL
CloudPrintURL::GetCloudPrintLearnMoreURL() {
103 GURL
cloud_print_learn_more_url(kLearnMoreURL
);
104 return cloud_print_learn_more_url
;
107 GURL
CloudPrintURL::GetCloudPrintTestPageURL() {
108 GURL
cloud_print_learn_more_url(kTestPageURL
);
109 return cloud_print_learn_more_url
;