1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_AUTOFILL_CORE_COMMON_SAVE_PASSWORD_PROGRESS_LOGGER_H_
6#define COMPONENTS_AUTOFILL_CORE_COMMON_SAVE_PASSWORD_PROGRESS_LOGGER_H_
7
8#include <string>
9
10#include "url/gurl.h"
11
12namespace base {
13class Value;
14}
15
16namespace autofill {
17
18struct PasswordForm;
19
20// When logging decisions made by password management code about whether to
21// offer user-entered credentials for saving or not, do use this class. It
22// offers a suite of convenience methods to format and scrub logs. The methods
23// have built-in privacy protections (never include a password, scrub URLs), so
24// that the result is appropriate for display on the internals page.
25//
26// To use this class, the method SendLog needs to be overriden to send the logs
27// for display as appropriate.
28//
29// TODO(vabr): Logically, this class belongs to the password_manager component.
30// But the PasswordAutofillAgent needs to use it, so until that agent is in a
31// third component, shared by autofill and password_manager, this helper needs
32// to stay in autofill as well.
33class SavePasswordProgressLogger {
34 public:
35  // IDs of strings allowed in the logs: for security reasons, we only pass the
36  // IDs from the renderer, and map them to strings in the browser.
37  enum StringID {
38    STRING_DECISION_ASK,
39    STRING_DECISION_DROP,
40    STRING_DECISION_SAVE,
41    STRING_OTHER,
42    STRING_SCHEME_HTML,
43    STRING_SCHEME_BASIC,
44    STRING_SCHEME_DIGEST,
45    STRING_SCHEME_MESSAGE,
46    STRING_SIGNON_REALM,
47    STRING_ORIGINAL_SIGNON_REALM,
48    STRING_ORIGIN,
49    STRING_ACTION,
50    STRING_USERNAME_ELEMENT,
51    STRING_PASSWORD_ELEMENT,
52    STRING_PASSWORD_AUTOCOMPLETE_SET,
53    STRING_NEW_PASSWORD_ELEMENT,
54    STRING_SSL_VALID,
55    STRING_PASSWORD_GENERATED,
56    STRING_TIMES_USED,
57    STRING_USE_ADDITIONAL_AUTHENTICATION,
58    STRING_PSL_MATCH,
59    STRING_NAME_OR_ID,
60    STRING_MESSAGE,
61    STRING_SET_AUTH_METHOD,
62    STRING_AUTHENTICATION_HANDLED,
63    STRING_LOGINHANDLER_FORM,
64    STRING_SEND_PASSWORD_FORMS_METHOD,
65    STRING_SECURITY_ORIGIN,
66    STRING_SECURITY_ORIGIN_FAILURE,
67    STRING_WEBPAGE_EMPTY,
68    STRING_NUMBER_OF_ALL_FORMS,
69    STRING_FORM_FOUND_ON_PAGE,
70    STRING_FORM_IS_VISIBLE,
71    STRING_FORM_IS_PASSWORD,
72    STRING_WILL_SUBMIT_FORM_METHOD,
73    STRING_HTML_FORM_FOR_SUBMIT,
74    STRING_CREATED_PASSWORD_FORM,
75    STRING_SUBMITTED_PASSWORD_REPLACED,
76    STRING_DID_START_PROVISIONAL_LOAD_METHOD,
77    STRING_FORM_FRAME_EQ_FRAME,
78    STRING_PROVISIONALLY_SAVED_FORM_FOR_FRAME,
79    STRING_PASSWORD_FORM_FOUND_ON_PAGE,
80    STRING_PROVISIONALLY_SAVE_PASSWORD_METHOD,
81    STRING_PROVISIONALLY_SAVE_PASSWORD_FORM,
82    STRING_IS_SAVING_ENABLED,
83    STRING_EMPTY_PASSWORD,
84    STRING_EXACT_MATCH,
85    STRING_MATCH_WITHOUT_ACTION,
86    STRING_MATCHING_NOT_COMPLETE,
87    STRING_FORM_BLACKLISTED,
88    STRING_INVALID_FORM,
89    STRING_AUTOCOMPLETE_OFF,
90    STRING_SYNC_CREDENTIAL,
91    STRING_PROVISIONALLY_SAVED_FORM,
92    STRING_IGNORE_POSSIBLE_USERNAMES,
93    STRING_ON_PASSWORD_FORMS_RENDERED_METHOD,
94    STRING_NO_PROVISIONAL_SAVE_MANAGER,
95    STRING_NUMBER_OF_VISIBLE_FORMS,
96    STRING_PASSWORD_FORM_REAPPEARED,
97    STRING_SAVING_DISABLED,
98    STRING_NO_MATCHING_FORM,
99    STRING_SSL_ERRORS_PRESENT,
100    STRING_ONLY_VISIBLE,
101    STRING_SHOW_PASSWORD_PROMPT,
102    STRING_INVALID,  // Represents a string returned in a case of an error.
103    STRING_MAX = STRING_INVALID
104  };
105
106  SavePasswordProgressLogger();
107  virtual ~SavePasswordProgressLogger();
108
109  // Call these methods to log information. They sanitize the input and call
110  // SendLog to pass it for display.
111  void LogPasswordForm(StringID label, const PasswordForm& form);
112  void LogHTMLForm(StringID label,
113                   const std::string& name_or_id,
114                   const GURL& action);
115  void LogURL(StringID label, const GURL& url);
116  void LogBoolean(StringID label, bool truth_value);
117  void LogNumber(StringID label, int signed_number);
118  void LogNumber(StringID label, size_t unsigned_number);
119  void LogMessage(StringID message);
120
121 protected:
122  // Sends |log| immediately for display.
123  virtual void SendLog(const std::string& log) = 0;
124
125 private:
126  // Converts |log| and its |label| to a string and calls SendLog on the result.
127  void LogValue(StringID label, const base::Value& log);
128
129  DISALLOW_COPY_AND_ASSIGN(SavePasswordProgressLogger);
130};
131
132}  // namespace autofill
133
134#endif  // COMPONENTS_AUTOFILL_CORE_COMMON_SAVE_PASSWORD_PROGRESS_LOGGER_H_
135