Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_bubble_model.cc

Issue 1141413002: Prepare password_bubble_experiment and password_manager_util for componentisation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android 2 Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_bubble_model.h" 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/password_manager/password_store_factory.h" 9 #include "chrome/browser/password_manager/password_store_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/signin/signin_manager_factory.h" 11 #include "chrome/browser/signin/signin_manager_factory.h"
12 #include "chrome/browser/sync/profile_sync_service.h"
13 #include "chrome/browser/sync/profile_sync_service_factory.h"
12 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_finder.h" 15 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 16 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
15 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" 17 #include "chrome/browser/ui/passwords/password_bubble_experiment.h"
16 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
17 #include "chrome/grit/chromium_strings.h" 19 #include "chrome/grit/chromium_strings.h"
18 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
19 #include "components/feedback/feedback_data.h" 21 #include "components/feedback/feedback_data.h"
20 #include "components/feedback/feedback_util.h" 22 #include "components/feedback/feedback_util.h"
21 #include "components/password_manager/core/browser/password_store.h" 23 #include "components/password_manager/core/browser/password_store.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const std::vector<const autofill::PasswordForm*>& forms) { 67 const std::vector<const autofill::PasswordForm*>& forms) {
66 ScopedVector<const autofill::PasswordForm> result; 68 ScopedVector<const autofill::PasswordForm> result;
67 result.reserve(forms.size()); 69 result.reserve(forms.size());
68 std::transform(forms.begin(), forms.end(), std::back_inserter(result), 70 std::transform(forms.begin(), forms.end(), std::back_inserter(result),
69 [](const autofill::PasswordForm* form) { 71 [](const autofill::PasswordForm* form) {
70 return new autofill::PasswordForm(*form); 72 return new autofill::PasswordForm(*form);
71 }); 73 });
72 return result.Pass(); 74 return result.Pass();
73 } 75 }
74 76
77 // A wrapper around password_bubble_experiment::IsSmartLockBrandingEnabled
78 // extracting the sync_service from the profile.
79 bool IsSmartLockBrandingEnabled(Profile* profile) {
80 const ProfileSyncService* sync_service =
81 ProfileSyncServiceFactory::GetForProfile(profile);
82 return password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service);
83 }
84
75 } // namespace 85 } // namespace
76 86
77 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( 87 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
78 content::WebContents* web_contents) 88 content::WebContents* web_contents)
79 : content::WebContentsObserver(web_contents), 89 : content::WebContentsObserver(web_contents),
80 never_save_passwords_(false), 90 never_save_passwords_(false),
81 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), 91 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING),
82 dismissal_reason_(metrics_util::NOT_DISPLAYED) { 92 dismissal_reason_(metrics_util::NOT_DISPLAYED) {
83 ManagePasswordsUIController* controller = 93 ManagePasswordsUIController* controller =
84 ManagePasswordsUIController::FromWebContents(web_contents); 94 ManagePasswordsUIController::FromWebContents(web_contents);
(...skipping 29 matching lines...) Expand all
114 title_ = IsNewUIActive() ? 124 title_ = IsNewUIActive() ?
115 l10n_util::GetStringFUTF16(IDS_MANAGE_ACCOUNTS_TITLE, 125 l10n_util::GetStringFUTF16(IDS_MANAGE_ACCOUNTS_TITLE,
116 base::UTF8ToUTF16(origin_.spec())) : 126 base::UTF8ToUTF16(origin_.spec())) :
117 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); 127 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE);
118 } 128 }
119 129
120 if (state_ == password_manager::ui::CONFIRMATION_STATE) { 130 if (state_ == password_manager::ui::CONFIRMATION_STATE) {
121 base::string16 save_confirmation_link = 131 base::string16 save_confirmation_link =
122 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_LINK); 132 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_LINK);
123 int confirmation_text_id = IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT; 133 int confirmation_text_id = IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT;
124 if (password_bubble_experiment::IsSmartLockBrandingEnabled(GetProfile())) { 134 if (IsSmartLockBrandingEnabled(GetProfile())) {
125 std::string management_hostname = 135 std::string management_hostname =
126 GURL(chrome::kPasswordManagerAccountDashboardURL).host(); 136 GURL(chrome::kPasswordManagerAccountDashboardURL).host();
127 save_confirmation_link = base::UTF8ToUTF16(management_hostname); 137 save_confirmation_link = base::UTF8ToUTF16(management_hostname);
128 confirmation_text_id = 138 confirmation_text_id =
129 IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_SMART_LOCK_TEXT; 139 IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_SMART_LOCK_TEXT;
130 } 140 }
131 141
132 size_t offset; 142 size_t offset;
133 save_confirmation_text_ = 143 save_confirmation_text_ =
134 l10n_util::GetStringFUTF16( 144 l10n_util::GetStringFUTF16(
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } 252 }
243 253
244 // TODO(gcasto): Is it worth having this be separate from OnDoneClicked()? 254 // TODO(gcasto): Is it worth having this be separate from OnDoneClicked()?
245 // User intent is pretty similar in both cases. 255 // User intent is pretty similar in both cases.
246 void ManagePasswordsBubbleModel::OnOKClicked() { 256 void ManagePasswordsBubbleModel::OnOKClicked() {
247 dismissal_reason_ = metrics_util::CLICKED_OK; 257 dismissal_reason_ = metrics_util::CLICKED_OK;
248 } 258 }
249 259
250 void ManagePasswordsBubbleModel::OnManageLinkClicked() { 260 void ManagePasswordsBubbleModel::OnManageLinkClicked() {
251 dismissal_reason_ = metrics_util::CLICKED_MANAGE; 261 dismissal_reason_ = metrics_util::CLICKED_MANAGE;
252 if (password_bubble_experiment::IsSmartLockBrandingEnabled(GetProfile())) { 262 if (IsSmartLockBrandingEnabled(GetProfile())) {
253 ManagePasswordsUIController::FromWebContents(web_contents()) 263 ManagePasswordsUIController::FromWebContents(web_contents())
254 ->NavigateToExternalPasswordManager(); 264 ->NavigateToExternalPasswordManager();
255 } else { 265 } else {
256 ManagePasswordsUIController::FromWebContents(web_contents()) 266 ManagePasswordsUIController::FromWebContents(web_contents())
257 ->NavigateToPasswordManagerSettingsPage(); 267 ->NavigateToPasswordManagerSettingsPage();
258 } 268 }
259 } 269 }
260 270
261 void ManagePasswordsBubbleModel::OnBrandLinkClicked() { 271 void ManagePasswordsBubbleModel::OnBrandLinkClicked() {
262 dismissal_reason_ = metrics_util::CLICKED_BRAND_NAME; 272 dismissal_reason_ = metrics_util::CLICKED_BRAND_NAME;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // static 331 // static
322 int ManagePasswordsBubbleModel::PasswordFieldWidth() { 332 int ManagePasswordsBubbleModel::PasswordFieldWidth() {
323 return GetFieldWidth(PASSWORD_FIELD); 333 return GetFieldWidth(PASSWORD_FIELD);
324 } 334 }
325 335
326 void ManagePasswordsBubbleModel::UpdatePendingStateTitle() { 336 void ManagePasswordsBubbleModel::UpdatePendingStateTitle() {
327 title_brand_link_range_ = gfx::Range(); 337 title_brand_link_range_ = gfx::Range();
328 if (never_save_passwords_) { 338 if (never_save_passwords_) {
329 title_ = l10n_util::GetStringUTF16( 339 title_ = l10n_util::GetStringUTF16(
330 IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE); 340 IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE);
331 } else if (password_bubble_experiment::IsSmartLockBrandingEnabled( 341 } else if (IsSmartLockBrandingEnabled(GetProfile())) {
332 GetProfile())) {
333 // "Google Smart Lock" should be a hyperlink. 342 // "Google Smart Lock" should be a hyperlink.
334 base::string16 brand_link = 343 base::string16 brand_link =
335 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK); 344 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK);
336 size_t offset = 0; 345 size_t offset = 0;
337 title_ = l10n_util::GetStringFUTF16(IDS_SAVE_PASSWORD, brand_link, &offset); 346 title_ = l10n_util::GetStringFUTF16(IDS_SAVE_PASSWORD, brand_link, &offset);
338 title_brand_link_range_ = gfx::Range(offset, offset + brand_link.length()); 347 title_brand_link_range_ = gfx::Range(offset, offset + brand_link.length());
339 } else { 348 } else {
340 base::string16 brand_link = 349 base::string16 brand_link =
341 l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD_TITLE_BRAND); 350 l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD_TITLE_BRAND);
342 title_ = l10n_util::GetStringFUTF16(IDS_SAVE_PASSWORD, brand_link); 351 title_ = l10n_util::GetStringFUTF16(IDS_SAVE_PASSWORD, brand_link);
343 } 352 }
344 } 353 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698