This source file includes following definitions.
- RegisterProfilePrefs
- GetCloudPrintServiceURL
- GetCloudPrintSigninURL
- GetCloudPrintAddAccountURL
- GetCloudPrintServiceDialogURL
- GetCloudPrintServiceManageURL
- GetCloudPrintServiceEnableURL
- GetCloudPrintLearnMoreURL
- GetCloudPrintTestPageURL
#include "chrome/browser/printing/cloud_print/cloud_print_url.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "google_apis/gaia/gaia_urls.h"
#include "net/base/url_util.h"
#include "url/gurl.h"
const char kDefaultCloudPrintServiceURL[] = "https://www.google.com/cloudprint";
const char kLearnMoreURL[] =
"https://www.google.com/support/cloudprint";
const char kTestPageURL[] =
"http://www.google.com/landing/cloudprint/enable.html?print=true";
void CloudPrintURL::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
const CommandLine* command_line = CommandLine::ForCurrentProcess();
GURL cloud_print_url(
command_line->GetSwitchValueASCII(switches::kCloudPrintServiceURL));
if (cloud_print_url.is_empty())
cloud_print_url = GURL(kDefaultCloudPrintServiceURL);
registry->RegisterStringPref(
prefs::kCloudPrintServiceURL,
cloud_print_url.spec(),
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
GURL gaia_url(GaiaUrls::GetInstance()->service_login_url());
gaia_url = net::AppendQueryParameter(gaia_url, "service", "cloudprint");
gaia_url = net::AppendQueryParameter(gaia_url, "sarp", "1");
gaia_url = net::AppendQueryParameter(gaia_url, "continue",
cloud_print_url.spec());
registry->RegisterStringPref(
prefs::kCloudPrintSigninURL,
gaia_url.spec(),
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
GURL CloudPrintURL::GetCloudPrintServiceURL() {
DCHECK(profile_);
return GURL(profile_->GetPrefs()->GetString(prefs::kCloudPrintServiceURL));
}
GURL CloudPrintURL::GetCloudPrintSigninURL() {
DCHECK(profile_);
GURL cloud_print_signin_url(
profile_->GetPrefs()->GetString(prefs::kCloudPrintSigninURL));
return google_util::AppendGoogleLocaleParam(cloud_print_signin_url);
}
GURL CloudPrintURL::GetCloudPrintAddAccountURL() {
DCHECK(profile_);
GURL url(GaiaUrls::GetInstance()->add_account_url());
url = net::AppendQueryParameter(url, "service", "cloudprint");
url = net::AppendQueryParameter(url, "sarp", "1");
url = net::AppendQueryParameter(
url,
"continue",
profile_->GetPrefs()->GetString(prefs::kCloudPrintServiceURL));
return google_util::AppendGoogleLocaleParam(url);
}
GURL CloudPrintURL::GetCloudPrintServiceDialogURL() {
GURL cloud_print_service_url = GetCloudPrintServiceURL();
std::string path(cloud_print_service_url.path() + "/client/dialog.html");
GURL::Replacements replacements;
replacements.SetPathStr(path);
GURL cloud_print_dialog_url = cloud_print_service_url.ReplaceComponents(
replacements);
return google_util::AppendGoogleLocaleParam(cloud_print_dialog_url);
}
GURL CloudPrintURL::GetCloudPrintServiceManageURL() {
GURL cloud_print_service_url = GetCloudPrintServiceURL();
std::string path(cloud_print_service_url.path() + "/manage.html");
GURL::Replacements replacements;
replacements.SetPathStr(path);
GURL cloud_print_manage_url = cloud_print_service_url.ReplaceComponents(
replacements);
return cloud_print_manage_url;
}
GURL CloudPrintURL::GetCloudPrintServiceEnableURL(
const std::string& proxy_id) {
GURL cloud_print_service_url = GetCloudPrintServiceURL();
std::string path(cloud_print_service_url.path() +
"/enable_chrome_connector/enable.html");
GURL::Replacements replacements;
replacements.SetPathStr(path);
std::string query = base::StringPrintf("proxy=%s", proxy_id.c_str());
replacements.SetQueryStr(query);
GURL cloud_print_enable_url = cloud_print_service_url.ReplaceComponents(
replacements);
return cloud_print_enable_url;
}
GURL CloudPrintURL::GetCloudPrintLearnMoreURL() {
GURL cloud_print_learn_more_url(kLearnMoreURL);
return cloud_print_learn_more_url;
}
GURL CloudPrintURL::GetCloudPrintTestPageURL() {
GURL cloud_print_learn_more_url(kTestPageURL);
return cloud_print_learn_more_url;
}