Commit 84326ff8 authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Add timestamps to chrome://safe-browsing/#tab-deep-scan

This CL adds timestamps for the response and request to the Deep Scans
tab on chrome://safe-browsing, for easier debugging purposes.

Change-Id: I3edce358dc09fb9138180c71e1924468bac2c5ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2138594
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757149}
parent 399251e0
...@@ -132,22 +132,13 @@ cr.define('safe_browsing', function() { ...@@ -132,22 +132,13 @@ cr.define('safe_browsing', function() {
addReportingEvent(reportingEvent); addReportingEvent(reportingEvent);
}); });
cr.sendWithPromise('getDeepScanRequests', []).then((requests) => { cr.sendWithPromise('getDeepScans', []).then((requests) => {
requests.forEach(function(request) { requests.forEach(function(request) {
addDeepScanRequest(request); addDeepScan(request);
}); });
}); });
cr.addWebUIListener('deep-scan-request-update', function(result) { cr.addWebUIListener('deep-scan-request-update', function(result) {
addDeepScanRequest(result); addDeepScan(result);
});
cr.sendWithPromise('getDeepScanResponses', []).then((responses) => {
responses.forEach(function(response) {
addDeepScanResponse(response);
});
});
cr.addWebUIListener('deep-scan-response-update', function(result) {
addDeepScanResponse(result);
}); });
$('get-referrer-chain-form').addEventListener('submit', addReferrerChain); $('get-referrer-chain-form').addEventListener('submit', addReferrerChain);
...@@ -265,45 +256,53 @@ cr.define('safe_browsing', function() { ...@@ -265,45 +256,53 @@ cr.define('safe_browsing', function() {
row.insertCell().className = 'content'; row.insertCell().className = 'content';
} }
function addResultToTable(tableId, result, position) { function addResultToTable(tableId, token, result, position) {
const token = result[0];
const request = result[1];
if ($(tableId + '-' + token) === null) { if ($(tableId + '-' + token) === null) {
insertTokenToTable(tableId, token); insertTokenToTable(tableId, token);
} }
const cell = $(tableId + '-' + token).cells[position]; const cell = $(tableId + '-' + token).cells[position];
appendChildWithInnerText(cell, request); cell.innerText = result;
} }
function addPGPing(result) { function addPGPing(result) {
addResultToTable('pg-ping-list', result, 0); addResultToTable('pg-ping-list', result[0], result[1], 0);
} }
function addPGResponse(result) { function addPGResponse(result) {
addResultToTable('pg-ping-list', result, 1); addResultToTable('pg-ping-list', result[0], result[1], 1);
} }
function addRTLookupPing(result) { function addRTLookupPing(result) {
addResultToTable('rt-lookup-ping-list', result, 0); addResultToTable('rt-lookup-ping-list', result[0], result[1], 0);
} }
function addRTLookupResponse(result) { function addRTLookupResponse(result) {
addResultToTable('rt-lookup-ping-list', result, 1); addResultToTable('rt-lookup-ping-list', result[0], result[1], 1);
} }
function addDeepScanRequest(result) { function addDeepScan(result) {
addResultToTable('deep-scan-list', result, 0); if (result['request_time'] != null) {
const requestFormatted = '[' +
(new Date(result['request_time'])).toLocaleString() + ']\n' +
result['request'];
addResultToTable('deep-scan-list', result['token'], requestFormatted, 0);
} }
function addDeepScanResponse(result) { if (result['response_time'] != null) {
if (result[1] === 'SUCCESS') { if (result['response_status'] == 'SUCCESS') {
// Display the response instead // Display the response instead
addResultToTable('deep-scan-list', [result[0], result[2]], 1); const resultFormatted = '[' +
(new Date(result['response_time'])).toLocaleString() + ']\n' +
result['response'];
addResultToTable('deep-scan-list', result['token'], resultFormatted, 1);
} else { } else {
// Display the error code // Display the error
addResultToTable('deep-scan-list', [result[0], result[1]], 1); const resultFormatted = '[' +
(new Date(result['response_time'])).toLocaleString() + ']\n' +
result['response_status'];
addResultToTable('deep-scan-list', result['token'], resultFormatted, 1);
}
} }
} }
......
...@@ -255,13 +255,18 @@ void WebUIInfoSingleton::AddToDeepScanRequests( ...@@ -255,13 +255,18 @@ void WebUIInfoSingleton::AddToDeepScanRequests(
if (!HasListener()) if (!HasListener())
return; return;
// Only update the request time the first time we see a token.
if (deep_scan_requests_.find(request.request_token()) == if (deep_scan_requests_.find(request.request_token()) ==
deep_scan_requests_.end()) { deep_scan_requests_.end()) {
for (auto* webui_listener : webui_instances_) deep_scan_requests_[request.request_token()].request_time =
webui_listener->NotifyDeepScanRequestJsListener(request); base::Time::Now();
} }
deep_scan_requests_[request.request_token()] = request; deep_scan_requests_[request.request_token()].request = request;
for (auto* webui_listener : webui_instances_)
webui_listener->NotifyDeepScanJsListener(
request.request_token(), deep_scan_requests_[request.request_token()]);
} }
void WebUIInfoSingleton::AddToDeepScanResponses( void WebUIInfoSingleton::AddToDeepScanResponses(
...@@ -271,15 +276,16 @@ void WebUIInfoSingleton::AddToDeepScanResponses( ...@@ -271,15 +276,16 @@ void WebUIInfoSingleton::AddToDeepScanResponses(
if (!HasListener()) if (!HasListener())
return; return;
for (auto* webui_listener : webui_instances_) deep_scan_requests_[token].response_time = base::Time::Now();
webui_listener->NotifyDeepScanResponseJsListener(token, status, response); deep_scan_requests_[token].response_status = status;
deep_scan_requests_[token].response = response;
deep_scan_responses_[token] = std::make_pair(status, response); for (auto* webui_listener : webui_instances_)
webui_listener->NotifyDeepScanJsListener(token, deep_scan_requests_[token]);
} }
void WebUIInfoSingleton::ClearDeepScans() { void WebUIInfoSingleton::ClearDeepScans() {
DeepScanningRequestMap().swap(deep_scan_requests_); base::flat_map<std::string, DeepScanDebugData>().swap(deep_scan_requests_);
StatusAndDeepScanningResponseMap().swap(deep_scan_responses_);
} }
#endif #endif
void WebUIInfoSingleton::RegisterWebUIInstance(SafeBrowsingUIHandler* webui) { void WebUIInfoSingleton::RegisterWebUIInstance(SafeBrowsingUIHandler* webui) {
...@@ -337,6 +343,12 @@ void WebUIInfoSingleton::MaybeClearData() { ...@@ -337,6 +343,12 @@ void WebUIInfoSingleton::MaybeClearData() {
} }
} }
#if BUILDFLAG(FULL_SAFE_BROWSING)
DeepScanDebugData::DeepScanDebugData() = default;
DeepScanDebugData::DeepScanDebugData(const DeepScanDebugData&) = default;
DeepScanDebugData::~DeepScanDebugData() = default;
#endif
namespace { namespace {
#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
...@@ -1442,6 +1454,37 @@ std::string SerializeDeepScanningResponse( ...@@ -1442,6 +1454,37 @@ std::string SerializeDeepScanningResponse(
serializer.Serialize(response_dict); serializer.Serialize(response_dict);
return response_serialized; return response_serialized;
} }
base::Value SerializeDeepScanDebugData(const std::string& token,
const DeepScanDebugData& data) {
base::DictionaryValue value;
value.SetStringKey("token", token);
if (!data.request_time.is_null()) {
value.SetDoubleKey("request_time", data.request_time.ToJsTime());
}
if (data.request.has_value()) {
value.SetStringKey("request",
SerializeDeepScanningRequest(data.request.value()));
}
if (!data.response_time.is_null()) {
value.SetDoubleKey("response_time", data.response_time.ToJsTime());
}
if (!data.response_status.empty()) {
value.SetStringKey("response_status", data.response_status);
}
if (data.response.has_value()) {
value.SetStringKey("response",
SerializeDeepScanningResponse(data.response.value()));
}
return std::move(value);
}
#endif #endif
} // namespace } // namespace
...@@ -1821,15 +1864,12 @@ void SafeBrowsingUIHandler::GetLogMessages(const base::ListValue* args) { ...@@ -1821,15 +1864,12 @@ void SafeBrowsingUIHandler::GetLogMessages(const base::ListValue* args) {
} }
#if BUILDFLAG(FULL_SAFE_BROWSING) #if BUILDFLAG(FULL_SAFE_BROWSING)
void SafeBrowsingUIHandler::GetDeepScanRequests(const base::ListValue* args) { void SafeBrowsingUIHandler::GetDeepScans(const base::ListValue* args) {
base::ListValue pings_sent; base::ListValue pings_sent;
for (const auto& token_and_request : for (const auto& token_and_data :
WebUIInfoSingleton::GetInstance()->deep_scan_requests()) { WebUIInfoSingleton::GetInstance()->deep_scan_requests()) {
base::ListValue ping_entry; pings_sent.Append(SerializeDeepScanDebugData(token_and_data.first,
ping_entry.Append(base::Value(token_and_request.first)); token_and_data.second));
ping_entry.Append(
base::Value(SerializeDeepScanningRequest(token_and_request.second)));
pings_sent.Append(std::move(ping_entry));
} }
AllowJavascript(); AllowJavascript();
...@@ -1837,31 +1877,8 @@ void SafeBrowsingUIHandler::GetDeepScanRequests(const base::ListValue* args) { ...@@ -1837,31 +1877,8 @@ void SafeBrowsingUIHandler::GetDeepScanRequests(const base::ListValue* args) {
args->GetString(0, &callback_id); args->GetString(0, &callback_id);
ResolveJavascriptCallback(base::Value(callback_id), pings_sent); ResolveJavascriptCallback(base::Value(callback_id), pings_sent);
} }
void SafeBrowsingUIHandler::GetDeepScanResponses(const base::ListValue* args) {
const WebUIInfoSingleton::StatusAndDeepScanningResponseMap& responses =
WebUIInfoSingleton::GetInstance()->deep_scan_responses();
base::ListValue responses_sent;
for (const auto& token_and_status_and_response : responses) {
const std::string& token = token_and_status_and_response.first;
const std::string& status = token_and_status_and_response.second.first;
const DeepScanningClientResponse& response =
token_and_status_and_response.second.second;
base::ListValue response_entry;
response_entry.Append(base::Value(token));
response_entry.Append(base::Value(status));
response_entry.Append(base::Value(SerializeDeepScanningResponse(response)));
responses_sent.Append(std::move(response_entry));
}
AllowJavascript();
std::string callback_id;
args->GetString(0, &callback_id);
ResolveJavascriptCallback(base::Value(callback_id), responses_sent);
}
#endif #endif
void SafeBrowsingUIHandler::NotifyClientDownloadRequestJsListener( void SafeBrowsingUIHandler::NotifyClientDownloadRequestJsListener(
ClientDownloadRequest* client_download_request) { ClientDownloadRequest* client_download_request) {
AllowJavascript(); AllowJavascript();
...@@ -1955,27 +1972,12 @@ void SafeBrowsingUIHandler::NotifyReportingEventJsListener( ...@@ -1955,27 +1972,12 @@ void SafeBrowsingUIHandler::NotifyReportingEventJsListener(
} }
#if BUILDFLAG(FULL_SAFE_BROWSING) #if BUILDFLAG(FULL_SAFE_BROWSING)
void SafeBrowsingUIHandler::NotifyDeepScanRequestJsListener( void SafeBrowsingUIHandler::NotifyDeepScanJsListener(
const DeepScanningClientRequest& request) {
base::ListValue request_list;
request_list.Append(base::Value(request.request_token()));
request_list.Append(base::Value(SerializeDeepScanningRequest(request)));
AllowJavascript();
FireWebUIListener("deep-scan-request-update", request_list);
}
void SafeBrowsingUIHandler::NotifyDeepScanResponseJsListener(
const std::string& token, const std::string& token,
const std::string& status, const DeepScanDebugData& deep_scan_data) {
const DeepScanningClientResponse& response) {
base::ListValue response_list;
response_list.Append(base::Value(token));
response_list.Append(base::Value(status));
response_list.Append(base::Value(SerializeDeepScanningResponse(response)));
AllowJavascript(); AllowJavascript();
FireWebUIListener("deep-scan-response-update", response_list); FireWebUIListener("deep-scan-request-update",
SerializeDeepScanDebugData(token, deep_scan_data));
} }
#endif #endif
...@@ -2051,12 +2053,7 @@ void SafeBrowsingUIHandler::RegisterMessages() { ...@@ -2051,12 +2053,7 @@ void SafeBrowsingUIHandler::RegisterMessages() {
base::Unretained(this))); base::Unretained(this)));
#if BUILDFLAG(FULL_SAFE_BROWSING) #if BUILDFLAG(FULL_SAFE_BROWSING)
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"getDeepScanRequests", "getDeepScans", base::BindRepeating(&SafeBrowsingUIHandler::GetDeepScans,
base::BindRepeating(&SafeBrowsingUIHandler::GetDeepScanRequests,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getDeepScanResponses",
base::BindRepeating(&SafeBrowsingUIHandler::GetDeepScanResponses,
base::Unretained(this))); base::Unretained(this)));
#endif #endif
} }
......
...@@ -34,6 +34,21 @@ namespace safe_browsing { ...@@ -34,6 +34,21 @@ namespace safe_browsing {
class WebUIInfoSingleton; class WebUIInfoSingleton;
class ReferrerChainProvider; class ReferrerChainProvider;
#if BUILDFLAG(FULL_SAFE_BROWSING)
struct DeepScanDebugData {
DeepScanDebugData();
DeepScanDebugData(const DeepScanDebugData&);
~DeepScanDebugData();
base::Time request_time;
base::Optional<DeepScanningClientRequest> request;
base::Time response_time;
std::string response_status;
base::Optional<DeepScanningClientResponse> response;
};
#endif
class SafeBrowsingUIHandler : public content::WebUIMessageHandler { class SafeBrowsingUIHandler : public content::WebUIMessageHandler {
public: public:
SafeBrowsingUIHandler(content::BrowserContext* context); SafeBrowsingUIHandler(content::BrowserContext* context);
...@@ -115,12 +130,9 @@ class SafeBrowsingUIHandler : public content::WebUIMessageHandler { ...@@ -115,12 +130,9 @@ class SafeBrowsingUIHandler : public content::WebUIMessageHandler {
#if BUILDFLAG(FULL_SAFE_BROWSING) #if BUILDFLAG(FULL_SAFE_BROWSING)
// Get the deep scanning requests that have been collected since the oldest // Get the deep scanning requests that have been collected since the oldest
// currently open chrome://safe-browsing tab was opened. // currently open chrome://safe-browsing tab was opened.
void GetDeepScanRequests(const base::ListValue* args); void GetDeepScans(const base::ListValue* args);
// Get the deep scanning responses that have been collected since the oldest
// currently open chrome://safe-browsing tab was opened.
void GetDeepScanResponses(const base::ListValue* args);
#endif #endif
// Register callbacks for WebUI messages. // Register callbacks for WebUI messages.
void RegisterMessages() override; void RegisterMessages() override;
...@@ -182,18 +194,12 @@ class SafeBrowsingUIHandler : public content::WebUIMessageHandler { ...@@ -182,18 +194,12 @@ class SafeBrowsingUIHandler : public content::WebUIMessageHandler {
void NotifyReportingEventJsListener(const base::Value& event); void NotifyReportingEventJsListener(const base::Value& event);
#if BUILDFLAG(FULL_SAFE_BROWSING) #if BUILDFLAG(FULL_SAFE_BROWSING)
// Called when any new deep scan requests are sent while one or more WebUI // Called when any deep scans are updated while one or more WebUI
// tabs are open. // tabs are open.
void NotifyDeepScanRequestJsListener( void NotifyDeepScanJsListener(const std::string& token,
const DeepScanningClientRequest& request); const DeepScanDebugData& request);
// Called when any new PhishGuard responses are received while one or more
// WebUI tabs are open.
void NotifyDeepScanResponseJsListener(
const std::string& token,
const std::string& status,
const DeepScanningClientResponse& response);
#endif #endif
// Callback when the CookieManager has returned the cookie. // Callback when the CookieManager has returned the cookie.
void OnGetCookie(const std::string& callback_id, void OnGetCookie(const std::string& callback_id,
const std::vector<net::CanonicalCookie>& cookies); const std::vector<net::CanonicalCookie>& cookies);
...@@ -220,13 +226,6 @@ class SafeBrowsingUI : public content::WebUIController { ...@@ -220,13 +226,6 @@ class SafeBrowsingUI : public content::WebUIController {
class WebUIInfoSingleton { class WebUIInfoSingleton {
public: public:
#if BUILDFLAG(FULL_SAFE_BROWSING)
using DeepScanningRequestMap =
std::map<std::string, DeepScanningClientRequest>;
using StatusAndDeepScanningResponseMap =
std::map<std::string, std::pair<std::string, DeepScanningClientResponse>>;
#endif
static WebUIInfoSingleton* GetInstance(); static WebUIInfoSingleton* GetInstance();
// Returns true when there is a listening chrome://safe-browsing tab. // Returns true when there is a listening chrome://safe-browsing tab.
...@@ -318,7 +317,7 @@ class WebUIInfoSingleton { ...@@ -318,7 +317,7 @@ class WebUIInfoSingleton {
// and response. // and response.
void AddToDeepScanRequests(const DeepScanningClientRequest& request); void AddToDeepScanRequests(const DeepScanningClientRequest& request);
// Add the new response to |deep_scan_responses_| and send it to all the open // Add the new response to |deep_scan_requests_| and send it to all the open
// chrome://safe-browsing tabs. // chrome://safe-browsing tabs.
void AddToDeepScanResponses(const std::string& token, void AddToDeepScanResponses(const std::string& token,
const std::string& status, const std::string& status,
...@@ -400,15 +399,10 @@ class WebUIInfoSingleton { ...@@ -400,15 +399,10 @@ class WebUIInfoSingleton {
// Get the collection of deep scanning requests since the oldest currently // Get the collection of deep scanning requests since the oldest currently
// open chrome://safe-browsing tab was opened. Returns a map from a unique // open chrome://safe-browsing tab was opened. Returns a map from a unique
// token to the request proto. // token to the request proto.
const DeepScanningRequestMap& deep_scan_requests() const { const base::flat_map<std::string, DeepScanDebugData>& deep_scan_requests()
const {
return deep_scan_requests_; return deep_scan_requests_;
} }
// Get the list of deep scan responses since the oldest currently open
// chrome://safe-browsing tab was opened.
const StatusAndDeepScanningResponseMap& deep_scan_responses() const {
return deep_scan_responses_;
}
#endif #endif
ReferrerChainProvider* referrer_chain_provider() { ReferrerChainProvider* referrer_chain_provider() {
...@@ -507,12 +501,8 @@ class WebUIInfoSingleton { ...@@ -507,12 +501,8 @@ class WebUIInfoSingleton {
#if BUILDFLAG(FULL_SAFE_BROWSING) #if BUILDFLAG(FULL_SAFE_BROWSING)
// Map of deep scan requests sent since the oldest currently open // Map of deep scan requests sent since the oldest currently open
// chrome://safe-browsing tab was opened. Maps from the unique token per // chrome://safe-browsing tab was opened. Maps from the unique token per
// request to the request proto. // request to the data about the request.
DeepScanningRequestMap deep_scan_requests_; base::flat_map<std::string, DeepScanDebugData> deep_scan_requests_;
// List of deep scan responses received since the oldest currently open
// chrome://safe-browsing tab was opened.
StatusAndDeepScanningResponseMap deep_scan_responses_;
#endif #endif
// The current referrer chain provider, if any. Can be nullptr. // The current referrer chain provider, if any. Can be nullptr.
......
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