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