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(); | |
Noam Samuel
2013/09/05 19:35:35
Maybe it's cleaner to have this be a const ptr rat
Vitaly Buka (NO REVIEWS)
2013/09/05 20:47:39
Done.
| |
34 GURL cloud_print_url = | |
35 GURL(command_line.GetSwitchValueASCII(switches::kCloudPrintServiceURL)); | |
33 registry->RegisterStringPref( | 36 registry->RegisterStringPref( |
34 prefs::kCloudPrintServiceURL, | 37 prefs::kCloudPrintServiceURL, |
35 kDefaultCloudPrintServiceURL, | 38 cloud_print_url.spec(), |
36 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 39 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
37 std::string url = GaiaUrls::GetInstance()->service_login_url(); | 40 GURL gaia_url(GaiaUrls::GetInstance()->service_login_url()); |
38 url.append("?service=cloudprint&sarp=1&continue="); | 41 gaia_url = net::AppendQueryParameter(gaia_url, "service", "cloudprint"); |
39 url.append(net::EscapeQueryParamValue(kDefaultCloudPrintServiceURL, false)); | 42 gaia_url = net::AppendQueryParameter(gaia_url, "sarp", "1"); |
43 gaia_url = net::AppendQueryParameter(gaia_url, "continue", | |
44 cloud_print_url.spec()); | |
40 registry->RegisterStringPref( | 45 registry->RegisterStringPref( |
41 prefs::kCloudPrintSigninURL, | 46 prefs::kCloudPrintSigninURL, |
42 url, | 47 gaia_url.spec(), |
43 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 48 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
44 } | 49 } |
45 | 50 |
46 // Returns the root service URL for the cloud print service. The default is to | 51 // 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 | 52 // point at the Google Cloud Print service. This can be overridden by the |
48 // command line or by the user preferences. | 53 // command line or by the user preferences. |
49 GURL CloudPrintURL::GetCloudPrintServiceURL() { | 54 GURL CloudPrintURL::GetCloudPrintServiceURL() { |
50 DCHECK(profile_); | 55 DCHECK(profile_); |
51 | 56 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 } | 57 } |
61 | 58 |
62 GURL CloudPrintURL::GetCloudPrintSigninURL() { | 59 GURL CloudPrintURL::GetCloudPrintSigninURL() { |
63 DCHECK(profile_); | 60 DCHECK(profile_); |
64 | |
65 GURL cloud_print_signin_url = GURL( | 61 GURL cloud_print_signin_url = GURL( |
66 profile_->GetPrefs()->GetString(prefs::kCloudPrintSigninURL)); | 62 profile_->GetPrefs()->GetString(prefs::kCloudPrintSigninURL)); |
67 return google_util::AppendGoogleLocaleParam(cloud_print_signin_url); | 63 return google_util::AppendGoogleLocaleParam(cloud_print_signin_url); |
68 } | 64 } |
69 | 65 |
70 GURL CloudPrintURL::GetCloudPrintServiceDialogURL() { | 66 GURL CloudPrintURL::GetCloudPrintServiceDialogURL() { |
71 GURL cloud_print_service_url = GetCloudPrintServiceURL(); | 67 GURL cloud_print_service_url = GetCloudPrintServiceURL(); |
72 std::string path(cloud_print_service_url.path() + "/client/dialog.html"); | 68 std::string path(cloud_print_service_url.path() + "/client/dialog.html"); |
73 GURL::Replacements replacements; | 69 GURL::Replacements replacements; |
74 replacements.SetPathStr(path); | 70 replacements.SetPathStr(path); |
(...skipping 28 matching lines...) Expand all Loading... | |
103 | 99 |
104 GURL CloudPrintURL::GetCloudPrintLearnMoreURL() { | 100 GURL CloudPrintURL::GetCloudPrintLearnMoreURL() { |
105 GURL cloud_print_learn_more_url(kLearnMoreURL); | 101 GURL cloud_print_learn_more_url(kLearnMoreURL); |
106 return cloud_print_learn_more_url; | 102 return cloud_print_learn_more_url; |
107 } | 103 } |
108 | 104 |
109 GURL CloudPrintURL::GetCloudPrintTestPageURL() { | 105 GURL CloudPrintURL::GetCloudPrintTestPageURL() { |
110 GURL cloud_print_learn_more_url(kTestPageURL); | 106 GURL cloud_print_learn_more_url(kTestPageURL); |
111 return cloud_print_learn_more_url; | 107 return cloud_print_learn_more_url; |
112 } | 108 } |
OLD | NEW |