| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_setup_source.h" | 5 #include "chrome/browser/printing/cloud_print/cloud_print_setup_source.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/google/google_util.h" | 11 #include "chrome/browser/google/google_util.h" |
| 12 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 12 #include "chrome/common/jstemplate_builder.h" | 13 #include "chrome/common/jstemplate_builder.h" |
| 14 #include "chrome/common/url_constants.h" |
| 13 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 14 #include "grit/browser_resources.h" | 16 #include "grit/browser_resources.h" |
| 15 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
| 16 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 17 #include "grit/locale_settings.h" | 19 #include "grit/locale_settings.h" |
| 18 #include "grit/ui_resources.h" | 20 #include "grit/ui_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 21 | 23 |
| 22 // Define the values of standard URLs. | 24 // Define the values of standard URLs. |
| 23 const char CloudPrintSetupSource::kInvalidPasswordHelpUrl[] = | 25 const char CloudPrintSetupSource::kInvalidPasswordHelpUrl[] = |
| 24 "https://www.google.com/support/accounts/bin/answer.py?ctx=ch&answer=27444"; | 26 "https://www.google.com/support/accounts/bin/answer.py?ctx=ch&answer=27444"; |
| 25 const char CloudPrintSetupSource::kCanNotAccessAccountUrl[] = | 27 const char CloudPrintSetupSource::kCanNotAccessAccountUrl[] = |
| 26 "https://www.google.com/support/accounts/bin/answer.py?answer=48598"; | 28 "https://www.google.com/support/accounts/bin/answer.py?answer=48598"; |
| 27 const char CloudPrintSetupSource::kCreateNewAccountUrl[] = | 29 const char CloudPrintSetupSource::kCreateNewAccountUrl[] = |
| 28 "https://accounts.google.com/NewAccount?service=chromiumsync"; | 30 "https://accounts.google.com/NewAccount?service=chromiumsync"; |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 // Utility method to keep dictionary population code streamlined. | 34 // Utility method to keep dictionary population code streamlined. |
| 33 void AddString(DictionaryValue* dictionary, | 35 void AddString(DictionaryValue* dictionary, |
| 34 const std::string& key, | 36 const std::string& key, |
| 35 int resource_id) { | 37 int resource_id) { |
| 36 dictionary->SetString(key, l10n_util::GetStringUTF16(resource_id)); | 38 dictionary->SetString(key, l10n_util::GetStringUTF16(resource_id)); |
| 37 } | 39 } |
| 38 | 40 |
| 39 } // namespace | 41 } // namespace |
| 40 | 42 |
| 41 CloudPrintSetupSource::CloudPrintSetupSource() | 43 CloudPrintSetupSource::CloudPrintSetupSource() { |
| 42 : DataSource(chrome::kChromeUICloudPrintSetupHost, MessageLoop::current()) { | 44 } |
| 45 |
| 46 std::string CloudPrintSetupSource::GetSource() { |
| 47 return chrome::kChromeUICloudPrintSetupHost; |
| 43 } | 48 } |
| 44 | 49 |
| 45 void CloudPrintSetupSource::StartDataRequest(const std::string& path_raw, | 50 void CloudPrintSetupSource::StartDataRequest(const std::string& path_raw, |
| 46 bool is_incognito, | 51 bool is_incognito, |
| 47 int request_id) { | 52 int request_id) { |
| 48 const char kCloudPrintSetupPath[] = "cloudprintsetup"; | 53 const char kCloudPrintSetupPath[] = "cloudprintsetup"; |
| 49 const char kCloudPrintGaiaLoginPath[] = "gaialogin"; | 54 const char kCloudPrintGaiaLoginPath[] = "gaialogin"; |
| 50 const char kCloudPrintSetupFlowPath[] = "setupflow"; | 55 const char kCloudPrintSetupFlowPath[] = "setupflow"; |
| 51 const char kCloudPrintSetupDonePath[] = "setupdone"; | 56 const char kCloudPrintSetupDonePath[] = "setupdone"; |
| 52 | 57 |
| 53 DictionaryValue localized_strings; | 58 DictionaryValue localized_strings; |
| 54 DictionaryValue* dict = &localized_strings; | 59 DictionaryValue* dict = &localized_strings; |
| 55 | 60 |
| 56 std::string response; | 61 std::string response; |
| 57 if (path_raw == kCloudPrintSetupPath) { | 62 if (path_raw == kCloudPrintSetupPath) { |
| 58 dict->SetString("header", | 63 dict->SetString("header", |
| 59 l10n_util::GetStringFUTF16(IDS_CLOUD_PRINT_SETUP_HEADER, | 64 l10n_util::GetStringFUTF16(IDS_CLOUD_PRINT_SETUP_HEADER, |
| 60 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); | 65 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); |
| 61 AddString(dict, "explain", IDS_CLOUD_PRINT_SETUP_EXPLAIN); | 66 AddString(dict, "explain", IDS_CLOUD_PRINT_SETUP_EXPLAIN); |
| 62 AddString(dict, "anywhereheader", IDS_CLOUD_PRINT_SETUP_ANYWHERE_HEADER); | 67 AddString(dict, "anywhereheader", IDS_CLOUD_PRINT_SETUP_ANYWHERE_HEADER); |
| 63 AddString(dict, "anywhereexplain", IDS_CLOUD_PRINT_SETUP_ANYWHERE_EXPLAIN); | 68 AddString(dict, "anywhereexplain", IDS_CLOUD_PRINT_SETUP_ANYWHERE_EXPLAIN); |
| 64 AddString(dict, "printerheader", IDS_CLOUD_PRINT_SETUP_PRINTER_HEADER); | 69 AddString(dict, "printerheader", IDS_CLOUD_PRINT_SETUP_PRINTER_HEADER); |
| 65 AddString(dict, "printerexplain", IDS_CLOUD_PRINT_SETUP_PRINTER_EXPLAIN); | 70 AddString(dict, "printerexplain", IDS_CLOUD_PRINT_SETUP_PRINTER_EXPLAIN); |
| 66 AddString(dict, "sharingheader", IDS_CLOUD_PRINT_SETUP_SHARING_HEADER); | 71 AddString(dict, "sharingheader", IDS_CLOUD_PRINT_SETUP_SHARING_HEADER); |
| 67 AddString(dict, "sharingexplain", IDS_CLOUD_PRINT_SETUP_SHARING_EXPLAIN); | 72 AddString(dict, "sharingexplain", IDS_CLOUD_PRINT_SETUP_SHARING_EXPLAIN); |
| 68 | 73 |
| 69 static const base::StringPiece html(ResourceBundle::GetSharedInstance() | 74 static const base::StringPiece html(ResourceBundle::GetSharedInstance() |
| 70 .GetRawDataResource(IDR_CLOUD_PRINT_SETUP_LOGIN_HTML)); | 75 .GetRawDataResource(IDR_CLOUD_PRINT_SETUP_LOGIN_HTML)); |
| 71 SetFontAndTextDirection(dict); | 76 URLDataSource::SetFontAndTextDirection(dict); |
| 72 response = jstemplate_builder::GetI18nTemplateHtml(html, dict); | 77 response = jstemplate_builder::GetI18nTemplateHtml(html, dict); |
| 73 } else if (path_raw == kCloudPrintGaiaLoginPath) { | 78 } else if (path_raw == kCloudPrintGaiaLoginPath) { |
| 74 // Start by setting the per-locale URLs we show on the setup wizard. | 79 // Start by setting the per-locale URLs we show on the setup wizard. |
| 75 dict->SetString("invalidpasswordhelpurl", | 80 dict->SetString("invalidpasswordhelpurl", |
| 76 GetLocalizedUrl(kInvalidPasswordHelpUrl)); | 81 GetLocalizedUrl(kInvalidPasswordHelpUrl)); |
| 77 dict->SetString("cannotaccessaccounturl", | 82 dict->SetString("cannotaccessaccounturl", |
| 78 GetLocalizedUrl(kCanNotAccessAccountUrl)); | 83 GetLocalizedUrl(kCanNotAccessAccountUrl)); |
| 79 dict->SetString("createnewaccounturl", | 84 dict->SetString("createnewaccounturl", |
| 80 GetLocalizedUrl(kCreateNewAccountUrl)); | 85 GetLocalizedUrl(kCreateNewAccountUrl)); |
| 81 | 86 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 97 AddString(dict, "success", IDS_SYNC_SUCCESS); | 102 AddString(dict, "success", IDS_SYNC_SUCCESS); |
| 98 AddString(dict, "errorsigningin", IDS_SYNC_ERROR_SIGNING_IN); | 103 AddString(dict, "errorsigningin", IDS_SYNC_ERROR_SIGNING_IN); |
| 99 AddString(dict, "captchainstructions", IDS_SYNC_GAIA_CAPTCHA_INSTRUCTIONS); | 104 AddString(dict, "captchainstructions", IDS_SYNC_GAIA_CAPTCHA_INSTRUCTIONS); |
| 100 AddString(dict, "invalidaccesscode", IDS_SYNC_INVALID_ACCESS_CODE_LABEL); | 105 AddString(dict, "invalidaccesscode", IDS_SYNC_INVALID_ACCESS_CODE_LABEL); |
| 101 AddString(dict, "enteraccesscode", IDS_SYNC_ENTER_ACCESS_CODE_LABEL); | 106 AddString(dict, "enteraccesscode", IDS_SYNC_ENTER_ACCESS_CODE_LABEL); |
| 102 AddString(dict, "getaccesscodehelp", IDS_SYNC_ACCESS_CODE_HELP_LABEL); | 107 AddString(dict, "getaccesscodehelp", IDS_SYNC_ACCESS_CODE_HELP_LABEL); |
| 103 AddString(dict, "getaccesscodeurl", IDS_SYNC_GET_ACCESS_CODE_URL); | 108 AddString(dict, "getaccesscodeurl", IDS_SYNC_GET_ACCESS_CODE_URL); |
| 104 | 109 |
| 105 static const base::StringPiece html(ResourceBundle::GetSharedInstance() | 110 static const base::StringPiece html(ResourceBundle::GetSharedInstance() |
| 106 .GetRawDataResource(IDR_GAIA_LOGIN_HTML)); | 111 .GetRawDataResource(IDR_GAIA_LOGIN_HTML)); |
| 107 SetFontAndTextDirection(dict); | 112 URLDataSource::SetFontAndTextDirection(dict); |
| 108 response = jstemplate_builder::GetI18nTemplateHtml(html, dict); | 113 response = jstemplate_builder::GetI18nTemplateHtml(html, dict); |
| 109 } else if (path_raw == kCloudPrintSetupDonePath) { | 114 } else if (path_raw == kCloudPrintSetupDonePath) { |
| 110 AddString(dict, "testpage", IDS_CLOUD_PRINT_SETUP_TEST_PAGE); | 115 AddString(dict, "testpage", IDS_CLOUD_PRINT_SETUP_TEST_PAGE); |
| 111 AddString(dict, "success", IDS_SYNC_SUCCESS); | 116 AddString(dict, "success", IDS_SYNC_SUCCESS); |
| 112 AddString(dict, "okay", IDS_SYNC_SETUP_OK_BUTTON_LABEL); | 117 AddString(dict, "okay", IDS_SYNC_SETUP_OK_BUTTON_LABEL); |
| 113 static const base::StringPiece html(ResourceBundle::GetSharedInstance() | 118 static const base::StringPiece html(ResourceBundle::GetSharedInstance() |
| 114 .GetRawDataResource(IDR_CLOUD_PRINT_SETUP_DONE_HTML)); | 119 .GetRawDataResource(IDR_CLOUD_PRINT_SETUP_DONE_HTML)); |
| 115 SetFontAndTextDirection(dict); | 120 URLDataSource::SetFontAndTextDirection(dict); |
| 116 response = jstemplate_builder::GetI18nTemplateHtml(html, dict); | 121 response = jstemplate_builder::GetI18nTemplateHtml(html, dict); |
| 117 } else if (path_raw == kCloudPrintSetupFlowPath) { | 122 } else if (path_raw == kCloudPrintSetupFlowPath) { |
| 118 static const base::StringPiece html( | 123 static const base::StringPiece html( |
| 119 ResourceBundle::GetSharedInstance() | 124 ResourceBundle::GetSharedInstance() |
| 120 .GetRawDataResource(IDR_CLOUD_PRINT_SETUP_FLOW_HTML)); | 125 .GetRawDataResource(IDR_CLOUD_PRINT_SETUP_FLOW_HTML)); |
| 121 response = html.as_string(); | 126 response = html.as_string(); |
| 122 } | 127 } |
| 123 | 128 |
| 124 SendResponse(request_id, base::RefCountedString::TakeString(&response)); | 129 url_data_source()->SendResponse( |
| 130 request_id, base::RefCountedString::TakeString(&response)); |
| 125 } | 131 } |
| 126 | 132 |
| 127 std::string CloudPrintSetupSource::GetMimeType(const std::string& path) const { | 133 std::string CloudPrintSetupSource::GetMimeType(const std::string& path) const { |
| 128 return "text/html"; | 134 return "text/html"; |
| 129 } | 135 } |
| 130 | 136 |
| 131 std::string CloudPrintSetupSource::GetLocalizedUrl( | 137 std::string CloudPrintSetupSource::GetLocalizedUrl( |
| 132 const std::string& url) const { | 138 const std::string& url) const { |
| 133 GURL original_url(url); | 139 GURL original_url(url); |
| 134 DCHECK(original_url.is_valid()); | 140 DCHECK(original_url.is_valid()); |
| 135 GURL localized_url = google_util::AppendGoogleLocaleParam(original_url); | 141 GURL localized_url = google_util::AppendGoogleLocaleParam(original_url); |
| 136 return localized_url.spec(); | 142 return localized_url.spec(); |
| 137 } | 143 } |
| OLD | NEW |