Commit 955fcacb authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Add PhishGuard pings and responses to chrome://safe-browsing.

Rename "resued_password_type" to "reused_password_type".

Render: https://screenshot.googleplex.com/rRa1W6cEQqr

Bug: 84935, 857503

Change-Id: I13a2724548ce317788b49eb48e7ec345b98385eb
Reviewed-on: https://chromium-review.googlesource.com/1120872Reviewed-by: default avatarJialiu Lin <jialiul@chromium.org>
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571621}
parent ffceec4a
......@@ -13,6 +13,7 @@
#include "components/password_manager/core/browser/password_reuse_detector.h"
#include "components/safe_browsing/db/whitelist_checker_client.h"
#include "components/safe_browsing/password_protection/password_protection_navigation_throttle.h"
#include "components/safe_browsing/web_ui/safe_browsing_ui.h"
#include "content/public/browser/web_contents.h"
#include "net/base/escape.h"
#include "net/base/load_flags.h"
......@@ -206,7 +207,7 @@ void PasswordProtectionRequest::FillRequestProto() {
clicked_through_interstitial);
reuse_event->set_sync_account_type(
password_protection_service_->GetSyncAccountType());
reuse_event->set_resued_password_type(reused_password_type_);
reuse_event->set_reused_password_type(reused_password_type_);
UMA_HISTOGRAM_ENUMERATION(
"PasswordProtection.PasswordReuseSyncAccountType",
reuse_event->sync_account_type(),
......@@ -239,6 +240,9 @@ void PasswordProtectionRequest::SendRequest() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
FillRequestProto();
web_ui_token_ =
WebUIInfoSingleton::GetInstance()->AddToPGPings(*request_proto_);
std::string serialized_request;
if (!request_proto_->SerializeToString(&serialized_request)) {
Finish(PasswordProtectionService::REQUEST_MALFORMED, nullptr);
......@@ -332,10 +336,13 @@ void PasswordProtectionRequest::OnURLLoaderComplete(
url_loader_.reset(); // We don't need it anymore.
UMA_HISTOGRAM_TIMES("PasswordProtection.RequestNetworkDuration",
base::TimeTicks::Now() - request_start_time_);
if (response_body && response->ParseFromString(*response_body))
if (response_body && response->ParseFromString(*response_body)) {
WebUIInfoSingleton::GetInstance()->AddToPGResponses(web_ui_token_,
*response);
Finish(PasswordProtectionService::SUCCEEDED, std::move(response));
else
} else {
Finish(PasswordProtectionService::RESPONSE_MALFORMED, nullptr);
}
}
void PasswordProtectionRequest::Finish(
......
......@@ -204,6 +204,9 @@ class PasswordProtectionRequest
// Whether there is a modal warning triggered by this request.
bool is_modal_warning_showing_;
// If a request is sent, this is the token returned by the WebUI.
int web_ui_token_;
base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PasswordProtectionRequest);
};
......
......@@ -278,7 +278,7 @@ message LoginReputationClientRequest {
// Non-Gaia enterprise password captured from enterprise login page.
ENTERPRISE_PASSWORD = 4;
}
optional ReusedPasswordType resued_password_type = 5
optional ReusedPasswordType reused_password_type = 5
[default = REUSED_PASSWORD_TYPE_UNKNOWN];
}
......
......@@ -24,3 +24,12 @@ h1, h2, h3, p {
font-weight: normal;
line-height: 1.5;
}
table.request-response {
table-layout:fixed;
width: 100%;
word-break:break-all;
white-space:pre-wrap;
}
table.request-response td {
width: 50%;
}
......@@ -47,6 +47,8 @@
<div class="content">
<p id="saved-passwords"></p>
</div>
<h2>PhishGuard Pings</h2>
<table id="pg-ping-list" class="request-response"></table>
<script src="chrome://resources/js/i18n_template.js"></script>
</body>
</html>
......@@ -51,6 +51,22 @@ cr.define('safe_browsing', function() {
cr.addWebUIListener('sent-pg-event', function(result) {
addPGEvent(result);
});
cr.sendWithPromise('getPGPings', [])
.then((pgPings) => { pgPings.forEach(function (pgPing) {
addPGPing(pgPing);
})});
cr.addWebUIListener('pg-pings-update', function(result) {
addPGPing(result);
});
cr.sendWithPromise('getPGResponses', [])
.then((pgResponses) => { pgResponses.forEach(function (pgResponse) {
addPGResponse(pgResponse);
})});
cr.addWebUIListener('pg-responses-update', function(result) {
addPGResponse(result);
});
}
function addExperiments(result) {
......@@ -124,6 +140,38 @@ cr.define('safe_browsing', function() {
appendChildWithInnerText(logDiv, eventFormatted);
}
function addPGPingRow(token) {
var row = $('pg-ping-list').insertRow();
row.className = 'content';
row.id = 'pg-ping-list-' + token;
row.insertCell();
row.insertCell();
}
function addPGPing(result) {
var token = result[0];
var request = result[1];
if ($('pg-ping-list-'+token) == undefined) {
addPGPingRow(token);
}
var cell = $('pg-ping-list-'+token).cells[0];
appendChildWithInnerText(cell, request);
}
function addPGResponse(result) {
var token = result[0];
var response = result[1];
if ($('pg-ping-list-'+token) == undefined) {
addPGPingRow(token);
}
var cell = $('pg-ping-list-'+token).cells[1];
appendChildWithInnerText(cell, response);
}
function appendChildWithInnerText(logDiv, text) {
if (!logDiv)
return;
......@@ -136,6 +184,8 @@ cr.define('safe_browsing', function() {
addSentCSBRRsInfo: addSentCSBRRsInfo,
addSentClientDownloadRequestsInfo: addSentClientDownloadRequestsInfo,
addPGEvent: addPGEvent,
addPGPing: addPGPing,
addPGResponse: addPGResponse,
initialize: initialize,
};
});
......
......@@ -18,7 +18,7 @@ namespace base {
class ListValue;
template <typename T>
struct DefaultSingletonTraits;
}
} // namespace base
namespace safe_browsing {
class WebUIInfoSingleton;
......@@ -53,6 +53,14 @@ class SafeBrowsingUIHandler : public content::WebUIMessageHandler {
// currently open chrome://safe-browsing tab was opened.
void GetPGEvents(const base::ListValue* args);
// Get the PhishGuard pings that have been sent since the oldest currently
// open chrome://safe-browsing tab was opened.
void GetPGPings(const base::ListValue* args);
// Get the PhishGuard responses that have been received since the oldest
// currently open chrome://safe-browsing tab was opened.
void GetPGResponses(const base::ListValue* args);
// Register callbacks for WebUI messages.
void RegisterMessages() override;
......@@ -72,6 +80,17 @@ class SafeBrowsingUIHandler : public content::WebUIMessageHandler {
// are open.
void NotifyPGEventJsListener(const sync_pb::UserEventSpecifics& event);
// Called when any new PhishGuard pings are sent while one or more WebUI tabs
// are open.
void NotifyPGPingJsListener(int token,
const LoginReputationClientRequest& request);
// Called when any new PhishGuard responses are received while one or more
// WebUI tabs are open.
void NotifyPGResponseJsListener(
int token,
const LoginReputationClientResponse& response);
content::BrowserContext* browser_context_;
// List that keeps all the WebUI listener objects.
......@@ -118,6 +137,19 @@ class WebUIInfoSingleton {
// Clear the list of sent PhishGuard events.
void ClearPGEvents();
// Add the new ping to |pg_pings_| and send it to all the open
// chrome://safe-browsing tabs. Returns a token that can be used in
// |AddToPGReponses| to correlate a ping and response.
int AddToPGPings(const LoginReputationClientRequest& request);
// Add the new response to |pg_responses_| and send it to all the open
// chrome://safe-browsing tabs.
void AddToPGResponses(int token,
const LoginReputationClientResponse& response);
// Clear the list of sent PhishGuard pings and responses.
void ClearPGPings();
// Register the new WebUI listener object.
void RegisterWebUIInstance(SafeBrowsingUIHandler* webui);
......@@ -144,10 +176,24 @@ class WebUIInfoSingleton {
return webui_instances_;
}
// Get the list of PhishGuard events since the oldest currently open
// chrome://safe-browsing tab was opened.
const std::vector<sync_pb::UserEventSpecifics>& pg_event_log() const {
return pg_event_log_;
}
// Get the list of PhishGuard pings since the oldest currently open
// chrome://safe-browsing tab was opened.
const std::vector<LoginReputationClientRequest>& pg_pings() const {
return pg_pings_;
}
// Get the list of PhishGuard pings since the oldest currently open
// chrome://safe-browsing tab was opened.
const std::map<int, LoginReputationClientResponse>& pg_responses() const {
return pg_responses_;
}
private:
WebUIInfoSingleton();
~WebUIInfoSingleton();
......@@ -171,6 +217,14 @@ class WebUIInfoSingleton {
// chrome://safe-browsing tab was opened.
std::vector<sync_pb::UserEventSpecifics> pg_event_log_;
// List of PhishGuard pings sent since the oldest currently open
// chrome://safe-browsing tab was opened.
std::vector<LoginReputationClientRequest> pg_pings_;
// List of PhishGuard responses received since the oldest currently open
// chrome://safe-browsing tab was opened.
std::map<int, LoginReputationClientResponse> pg_responses_;
// List of WebUI listener objects. "SafeBrowsingUIHandler*" cannot be const,
// due to being used by functions that call AllowJavascript(), which is not
// marked const.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment