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/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "chrome/browser/google/google_util.h" | 10 #include "chrome/browser/google/google_util.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.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 "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 | 16 |
17 const char kDefaultCloudPrintServiceURL[] = "https://www.google.com/cloudprint"; | 17 const char kDefaultCloudPrintServiceURL[] = "https://www.google.com/cloudprint"; |
| 18 const char kDefaultCloudPrintSigninURL[] = |
| 19 "https://www.google.com/accounts/ServiceLogin?" |
| 20 "service=cloudprint&continue=https%3A%2F%2Fwww.google.com%2Fcloudprint"; |
| 21 |
18 const char kLearnMoreURL[] = | 22 const char kLearnMoreURL[] = |
19 "https://www.google.com/support/cloudprint"; | 23 "https://www.google.com/support/cloudprint"; |
20 const char kTestPageURL[] = | 24 const char kTestPageURL[] = |
21 "http://www.google.com/landing/cloudprint/enable.html?print=true"; | 25 "http://www.google.com/landing/cloudprint/enable.html?print=true"; |
22 | 26 |
23 void CloudPrintURL::RegisterPreferences() { | 27 void CloudPrintURL::RegisterPreferences() { |
24 DCHECK(profile_); | 28 DCHECK(profile_); |
25 PrefService* pref_service = profile_->GetPrefs(); | 29 PrefService* pref_service = profile_->GetPrefs(); |
26 if (pref_service->FindPreference(prefs::kCloudPrintServiceURL)) | 30 if (!pref_service->FindPreference(prefs::kCloudPrintServiceURL)) { |
27 return; | 31 pref_service->RegisterStringPref(prefs::kCloudPrintServiceURL, |
28 pref_service->RegisterStringPref(prefs::kCloudPrintServiceURL, | 32 kDefaultCloudPrintServiceURL, |
29 kDefaultCloudPrintServiceURL, | 33 PrefService::UNSYNCABLE_PREF); |
30 PrefService::UNSYNCABLE_PREF); | 34 } |
| 35 if (!pref_service->FindPreference(prefs::kCloudPrintSigninURL)) { |
| 36 pref_service->RegisterStringPref(prefs::kCloudPrintSigninURL, |
| 37 kDefaultCloudPrintSigninURL, |
| 38 PrefService::UNSYNCABLE_PREF); |
| 39 } |
31 } | 40 } |
32 | 41 |
33 // Returns the root service URL for the cloud print service. The default is to | 42 // Returns the root service URL for the cloud print service. The default is to |
34 // point at the Google Cloud Print service. This can be overridden by the | 43 // point at the Google Cloud Print service. This can be overridden by the |
35 // command line or by the user preferences. | 44 // command line or by the user preferences. |
36 GURL CloudPrintURL::GetCloudPrintServiceURL() { | 45 GURL CloudPrintURL::GetCloudPrintServiceURL() { |
37 DCHECK(profile_); | 46 DCHECK(profile_); |
38 RegisterPreferences(); | 47 RegisterPreferences(); |
39 | 48 |
40 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 49 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
41 GURL cloud_print_service_url = GURL(command_line.GetSwitchValueASCII( | 50 GURL cloud_print_service_url = GURL(command_line.GetSwitchValueASCII( |
42 switches::kCloudPrintServiceURL)); | 51 switches::kCloudPrintServiceURL)); |
43 if (cloud_print_service_url.is_empty()) { | 52 if (cloud_print_service_url.is_empty()) { |
44 cloud_print_service_url = GURL( | 53 cloud_print_service_url = GURL( |
45 profile_->GetPrefs()->GetString(prefs::kCloudPrintServiceURL)); | 54 profile_->GetPrefs()->GetString(prefs::kCloudPrintServiceURL)); |
46 } | 55 } |
47 return cloud_print_service_url; | 56 return cloud_print_service_url; |
48 } | 57 } |
49 | 58 |
| 59 GURL CloudPrintURL::GetCloudPrintSigninURL() { |
| 60 DCHECK(profile_); |
| 61 RegisterPreferences(); |
| 62 |
| 63 GURL cloud_print_signin_url = GURL( |
| 64 profile_->GetPrefs()->GetString(prefs::kCloudPrintSigninURL)); |
| 65 return google_util::AppendGoogleLocaleParam(cloud_print_signin_url); |
| 66 } |
| 67 |
50 GURL CloudPrintURL::GetCloudPrintServiceDialogURL() { | 68 GURL CloudPrintURL::GetCloudPrintServiceDialogURL() { |
51 GURL cloud_print_service_url = GetCloudPrintServiceURL(); | 69 GURL cloud_print_service_url = GetCloudPrintServiceURL(); |
52 std::string path(cloud_print_service_url.path() + "/client/dialog.html"); | 70 std::string path(cloud_print_service_url.path() + "/client/dialog.html"); |
53 GURL::Replacements replacements; | 71 GURL::Replacements replacements; |
54 replacements.SetPathStr(path); | 72 replacements.SetPathStr(path); |
55 GURL cloud_print_dialog_url = cloud_print_service_url.ReplaceComponents( | 73 GURL cloud_print_dialog_url = cloud_print_service_url.ReplaceComponents( |
56 replacements); | 74 replacements); |
57 return google_util::AppendGoogleLocaleParam(cloud_print_dialog_url); | 75 return google_util::AppendGoogleLocaleParam(cloud_print_dialog_url); |
58 } | 76 } |
59 | 77 |
(...skipping 23 matching lines...) Expand all Loading... |
83 | 101 |
84 GURL CloudPrintURL::GetCloudPrintLearnMoreURL() { | 102 GURL CloudPrintURL::GetCloudPrintLearnMoreURL() { |
85 GURL cloud_print_learn_more_url(kLearnMoreURL); | 103 GURL cloud_print_learn_more_url(kLearnMoreURL); |
86 return cloud_print_learn_more_url; | 104 return cloud_print_learn_more_url; |
87 } | 105 } |
88 | 106 |
89 GURL CloudPrintURL::GetCloudPrintTestPageURL() { | 107 GURL CloudPrintURL::GetCloudPrintTestPageURL() { |
90 GURL cloud_print_learn_more_url(kTestPageURL); | 108 GURL cloud_print_learn_more_url(kTestPageURL); |
91 return cloud_print_learn_more_url; | 109 return cloud_print_learn_more_url; |
92 } | 110 } |
OLD | NEW |