| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/passwords/manage_passwords_view_utils.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/strings/stringprintf.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sync/profile_sync_service_factory.h" | 13 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 15 #include "chrome/grit/chromium_strings.h" | 14 #include "chrome/grit/chromium_strings.h" |
| 16 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 17 #include "components/autofill/core/common/password_form.h" | 16 #include "components/autofill/core/common/password_form.h" |
| 18 #include "components/browser_sync/profile_sync_service.h" | 17 #include "components/browser_sync/profile_sync_service.h" |
| 19 #include "components/password_manager/core/browser/affiliation_utils.h" | 18 #include "components/password_manager/core/browser/affiliation_utils.h" |
| 20 #include "components/strings/grit/components_strings.h" | 19 #include "components/strings/grit/components_strings.h" |
| 21 #include "components/url_formatter/elide_url.h" | 20 #include "components/url_formatter/elide_url.h" |
| 22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 21 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" |
| 25 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
| 26 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
| 27 #include "ui/gfx/image/image_skia_operations.h" | 26 #include "ui/gfx/image/image_skia_operations.h" |
| 28 #include "ui/gfx/range/range.h" | 27 #include "ui/gfx/range/range.h" |
| 29 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 30 #include "url/origin.h" | 29 #include "url/origin.h" |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 // Checks whether two URLs are from the same domain or host. | 33 // Checks whether two URLs are from the same domain or host. |
| 35 bool SameDomainOrHost(const GURL& gurl1, const GURL& gurl2) { | 34 bool SameDomainOrHost(const GURL& gurl1, const GURL& gurl2) { |
| 36 return net::registry_controlled_domains::SameDomainOrHost( | 35 return net::registry_controlled_domains::SameDomainOrHost( |
| 37 gurl1, gurl2, | 36 gurl1, gurl2, |
| 38 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 37 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 39 } | 38 } |
| 40 | 39 |
| 41 // TODO(crbug.com/658902): Remove |CheckExpectedPlaceholders| after | |
| 42 // investigation, including the stringprintf.h #include. | |
| 43 // Retrieves the string for |string_id| and checks that all expected | |
| 44 // placeholders are present. | |
| 45 void CheckExpectedPlaceholders(size_t number_of_placeholders, int string_id) { | |
| 46 std::string format_string = l10n_util::GetStringUTF8(string_id); | |
| 47 bool success = true; | |
| 48 | |
| 49 for (size_t placeholder = 1; placeholder <= number_of_placeholders; | |
| 50 ++placeholder) { | |
| 51 std::string placeholder_string = base::StringPrintf("$%zu", placeholder); | |
| 52 if (format_string.find(placeholder_string) == std::string::npos) { | |
| 53 success = false; | |
| 54 LOG(ERROR) << "Expected placeholder " << placeholder_string | |
| 55 << " missing in format_string '" << format_string << "'"; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 CHECK(success); | |
| 60 } | |
| 61 | |
| 62 // TODO(crbug.com/658902): Remove |CheckReplacementSize| after investigation. | |
| 63 void CheckReplacementSize(const std::vector<base::string16>& replacements, | |
| 64 size_t expected_size) { | |
| 65 if (replacements.size() != expected_size) { | |
| 66 LOG(ERROR) << "Expected " << expected_size | |
| 67 << " replacements but only found " << replacements.size(); | |
| 68 // Separated logging from CHECK instead of using CHECK_EQ, because CHECKs in | |
| 69 // release builds apparently discard logging (see "CHECK functions discard | |
| 70 // their log" in base/logging.h). | |
| 71 CHECK(false); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 } // namespace | 40 } // namespace |
| 76 | 41 |
| 77 gfx::ImageSkia ScaleImageForAccountAvatar(gfx::ImageSkia skia_image) { | 42 gfx::ImageSkia ScaleImageForAccountAvatar(gfx::ImageSkia skia_image) { |
| 78 gfx::Size size = skia_image.size(); | 43 gfx::Size size = skia_image.size(); |
| 79 if (size.height() != size.width()) { | 44 if (size.height() != size.width()) { |
| 80 gfx::Rect target(size); | 45 gfx::Rect target(size); |
| 81 int side = std::min(size.height(), size.width()); | 46 int side = std::min(size.height(), size.width()); |
| 82 target.ClampToCenteredSize(gfx::Size(side, side)); | 47 target.ClampToCenteredSize(gfx::Size(side, side)); |
| 83 skia_image = gfx::ImageSkiaOperations::ExtractSubset(skia_image, target); | 48 skia_image = gfx::ImageSkiaOperations::ExtractSubset(skia_image, target); |
| 84 } | 49 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 : IDS_SAVE_PASSWORD_DIFFERENT_DOMAINS_TITLE; | 108 : IDS_SAVE_PASSWORD_DIFFERENT_DOMAINS_TITLE; |
| 144 replacements.push_back( | 109 replacements.push_back( |
| 145 url_formatter::FormatUrlForSecurityDisplay(form_origin_url)); | 110 url_formatter::FormatUrlForSecurityDisplay(form_origin_url)); |
| 146 } | 111 } |
| 147 | 112 |
| 148 if (is_smartlock_branding_enabled) { | 113 if (is_smartlock_branding_enabled) { |
| 149 // "Google Smart Lock" should be a hyperlink. | 114 // "Google Smart Lock" should be a hyperlink. |
| 150 base::string16 title_link = | 115 base::string16 title_link = |
| 151 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK); | 116 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK); |
| 152 replacements.insert(replacements.begin(), title_link); | 117 replacements.insert(replacements.begin(), title_link); |
| 153 // TODO(crbug.com/658902): Remove |number_of_placeholders| after | 118 *title = l10n_util::GetStringFUTF16(title_id, replacements, &offsets); |
| 154 // investigation. | 119 if (!offsets.empty()) { |
| 155 size_t number_of_placeholders = 1; | 120 // |offsets| can be empty when the localised string associated with |
| 156 if (title_id == IDS_UPDATE_PASSWORD_DIFFERENT_DOMAINS_TITLE || | 121 // |title_id| could not be found. While this situation is an error, it |
| 157 title_id == IDS_SAVE_PASSWORD_DIFFERENT_DOMAINS_TITLE) { | 122 // needs to be handled gracefully, see http://crbug.com/658902#c18. |
| 158 number_of_placeholders = 2; | 123 *title_link_range = |
| 124 gfx::Range(offsets[0], offsets[0] + title_link.length()); |
| 159 } | 125 } |
| 160 CheckExpectedPlaceholders(number_of_placeholders, title_id); | |
| 161 CheckReplacementSize(replacements, number_of_placeholders); | |
| 162 *title = l10n_util::GetStringFUTF16(title_id, replacements, &offsets); | |
| 163 // TODO(crbug.com/658902): Remove this CHECK after investigation. | |
| 164 CHECK(!offsets.empty()); | |
| 165 *title_link_range = | |
| 166 gfx::Range(offsets[0], offsets[0] + title_link.length()); | |
| 167 } else { | 126 } else { |
| 168 replacements.insert( | 127 replacements.insert( |
| 169 replacements.begin(), | 128 replacements.begin(), |
| 170 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_TITLE_BRAND)); | 129 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_TITLE_BRAND)); |
| 171 *title = l10n_util::GetStringFUTF16(title_id, replacements, &offsets); | 130 *title = l10n_util::GetStringFUTF16(title_id, replacements, &offsets); |
| 172 } | 131 } |
| 173 } | 132 } |
| 174 | 133 |
| 175 void GetManagePasswordsDialogTitleText(const GURL& user_visible_url, | 134 void GetManagePasswordsDialogTitleText(const GURL& user_visible_url, |
| 176 const GURL& password_origin_url, | 135 const GURL& password_origin_url, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 : form.username_value; | 187 : form.username_value; |
| 229 } | 188 } |
| 230 | 189 |
| 231 bool IsSyncingAutosignSetting(Profile* profile) { | 190 bool IsSyncingAutosignSetting(Profile* profile) { |
| 232 const browser_sync::ProfileSyncService* sync_service = | 191 const browser_sync::ProfileSyncService* sync_service = |
| 233 ProfileSyncServiceFactory::GetForProfile(profile); | 192 ProfileSyncServiceFactory::GetForProfile(profile); |
| 234 return (sync_service && sync_service->IsFirstSetupComplete() && | 193 return (sync_service && sync_service->IsFirstSetupComplete() && |
| 235 sync_service->IsSyncActive() && | 194 sync_service->IsSyncActive() && |
| 236 sync_service->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)); | 195 sync_service->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)); |
| 237 } | 196 } |
| OLD | NEW |