save_password_progress_logger.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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_METHOD, 42 STRING_METHOD_GET, 43 STRING_METHOD_POST, 44 STRING_METHOD_EMPTY, 45 STRING_OTHER, 46 STRING_SCHEME_HTML, 47 STRING_SCHEME_BASIC, 48 STRING_SCHEME_DIGEST, 49 STRING_SCHEME_MESSAGE, 50 STRING_SIGNON_REALM, 51 STRING_ORIGINAL_SIGNON_REALM, 52 STRING_ORIGIN, 53 STRING_ACTION, 54 STRING_USERNAME_ELEMENT, 55 STRING_PASSWORD_ELEMENT, 56 STRING_PASSWORD_AUTOCOMPLETE_SET, 57 STRING_OLD_PASSWORD_ELEMENT, 58 STRING_SSL_VALID, 59 STRING_PASSWORD_GENERATED, 60 STRING_TIMES_USED, 61 STRING_USE_ADDITIONAL_AUTHENTICATION, 62 STRING_PSL_MATCH, 63 STRING_NAME_OR_ID, 64 STRING_MESSAGE, 65 STRING_SET_AUTH_METHOD, 66 STRING_AUTHENTICATION_HANDLED, 67 STRING_LOGINHANDLER_FORM, 68 STRING_SEND_PASSWORD_FORMS_METHOD, 69 STRING_SECURITY_ORIGIN, 70 STRING_SECURITY_ORIGIN_FAILURE, 71 STRING_WEBPAGE_EMPTY, 72 STRING_NUMBER_OF_ALL_FORMS, 73 STRING_FORM_FOUND_ON_PAGE, 74 STRING_FORM_IS_VISIBLE, 75 STRING_FORM_IS_PASSWORD, 76 STRING_WILL_SUBMIT_FORM_METHOD, 77 STRING_HTML_FORM_FOR_SUBMIT, 78 STRING_CREATED_PASSWORD_FORM, 79 STRING_SUBMITTED_PASSWORD_REPLACED, 80 STRING_DID_START_PROVISIONAL_LOAD_METHOD, 81 STRING_FORM_FRAME_EQ_FRAME, 82 STRING_PROVISIONALLY_SAVED_FORM_FOR_FRAME, 83 STRING_PASSWORD_FORM_FOUND_ON_PAGE, 84 STRING_PROVISIONALLY_SAVE_PASSWORD_METHOD, 85 STRING_PROVISIONALLY_SAVE_PASSWORD_FORM, 86 STRING_IS_SAVING_ENABLED, 87 STRING_EMPTY_PASSWORD, 88 STRING_EXACT_MATCH, 89 STRING_MATCH_WITHOUT_ACTION, 90 STRING_NO_FORM_MANAGER, 91 STRING_FORM_BLACKLISTED, 92 STRING_INVALID_FORM, 93 STRING_AUTOCOMPLETE_OFF, 94 STRING_PROVISIONALLY_SAVED_FORM, 95 STRING_IGNORE_POSSIBLE_USERNAMES, 96 STRING_ON_PASSWORD_FORMS_RENDERED_METHOD, 97 STRING_NO_PROVISIONAL_SAVE_MANAGER, 98 STRING_NUMBER_OF_VISIBLE_FORMS, 99 STRING_PASSWORD_FORM_REAPPEARED, 100 STRING_SAVING_DISABLED, 101 STRING_NO_MATCHING_FORM, 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 autofill::PasswordForm& form); 112 void LogHTMLForm(StringID label, 113 const std::string& name_or_id, 114 const std::string& method, 115 const GURL& action); 116 void LogURL(StringID label, const GURL& url); 117 void LogBoolean(StringID label, bool truth_value); 118 void LogNumber(StringID label, int signed_number); 119 void LogNumber(StringID label, size_t unsigned_number); 120 void LogMessage(StringID message); 121 122 protected: 123 // Sends |log| immediately for display. 124 virtual void SendLog(const std::string& log) = 0; 125 126 private: 127 // Converts |log| and its |label| to a string and calls SendLog on the result. 128 void LogValue(StringID label, const base::Value& log); 129 130 DISALLOW_COPY_AND_ASSIGN(SavePasswordProgressLogger); 131}; 132 133} // namespace autofill 134 135#endif // COMPONENTS_AUTOFILL_CORE_COMMON_SAVE_PASSWORD_PROGRESS_LOGGER_H_ 136