Commit 1e9060c2 authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Added DVLOGs to web_controller.

To provide human-readable status messages, several enums now support the output operator <<. String representations of enums are only compiled into debug builds. The same is true for logging string representations of selectors, because they might contain sensitive data.

Bug: 806868
Change-Id: I09de68f93a612cd4060761e8171b0bcd959df942
Reviewed-on: https://chromium-review.googlesource.com/c/1455901
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630716}
parent e2d80b38
...@@ -196,7 +196,7 @@ void Controller::EnterState(AutofillAssistantState state) { ...@@ -196,7 +196,7 @@ void Controller::EnterState(AutofillAssistantState state) {
return; return;
DCHECK_NE(state_, AutofillAssistantState::STOPPED) DCHECK_NE(state_, AutofillAssistantState::STOPPED)
<< "Unexpected transition from STOPPED to " << static_cast<int>(state); << "Unexpected transition from " << state_ << " to " << state;
state_ = state; state_ = state;
GetUiController()->OnStateChanged(state); GetUiController()->OnStateChanged(state);
...@@ -540,8 +540,8 @@ void Controller::GetTouchableArea(std::vector<RectF>* area) const { ...@@ -540,8 +540,8 @@ void Controller::GetTouchableArea(std::vector<RectF>* area) const {
void Controller::OnFatalError(const std::string& error_message, void Controller::OnFatalError(const std::string& error_message,
Metrics::DropOutReason reason) { Metrics::DropOutReason reason) {
LOG(ERROR) << "Autofill Assistant has encountered an error and is shutting " LOG(ERROR) << "Autofill Assistant has encountered an error and is shutting "
"down. Reason: " "down, reason="
<< static_cast<int>(reason); << reason;
if (state_ == AutofillAssistantState::STOPPED) if (state_ == AutofillAssistantState::STOPPED)
return; return;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_METRICS_H_ #ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_METRICS_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_METRICS_H_ #define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_METRICS_H_
#include <ostream>
namespace autofill_assistant { namespace autofill_assistant {
// A class to generate Autofill Assistant related histograms. // A class to generate Autofill Assistant related histograms.
...@@ -37,6 +39,76 @@ class Metrics { ...@@ -37,6 +39,76 @@ class Metrics {
}; };
static void RecordDropOut(DropOutReason reason); static void RecordDropOut(DropOutReason reason);
// Intended for debugging: writes string representation of |reason| to |out|.
friend std::ostream& operator<<(std::ostream& out,
const DropOutReason& reason) {
#ifdef NDEBUG
// Non-debugging builds write the enum number.
out << static_cast<int>(reason);
return out;
#else
// Debugging builds write a string representation of |reason|.
switch (reason) {
case AA_START:
out << "AA_START";
break;
case AUTOSTART_TIMEOUT:
out << "AUTOSTART_TIMEOUT";
break;
case NO_SCRIPTS:
out << "NO_SCRIPTS";
break;
case CUSTOM_TAB_CLOSED:
out << "CUSTOM_TAB_CLOSED";
break;
case DECLINED:
out << "DECLINED";
break;
case SHEET_CLOSED:
out << "SHEET_CLOSED";
break;
case SCRIPT_FAILED:
out << "SCRIPT_FAILED";
break;
case NAVIGATION:
out << "NAVIGATION";
break;
case OVERLAY_STOP:
out << "OVERLAY_STOP";
break;
case PR_FAILED:
out << "PR_FAILED";
break;
case CONTENT_DESTROYED:
out << "CONTENT_DESTROYED";
break;
case RENDER_PROCESS_GONE:
out << "RENDER_PROCESS_GONE";
break;
case INTERSTITIAL_PAGE:
out << "INTERSTITIAL_PAGE";
break;
case SCRIPT_SHUTDOWN:
out << "SCRIPT_SHUTDOWN";
break;
case SAFETY_NET_TERMINATE:
out << "SAFETY_NET_TERMINATE";
break;
case TAB_DETACHED:
out << "TAB_DETACHED";
break;
case TAB_CHANGED:
out << "TAB_CHANGED";
break;
case NUM_ENTRIES:
out << "NUM_ENTRIES";
// Intentionally no default case to make compilation fail if a new value
// was added to the enum but not to this list.
}
return out;
#endif // NDEBUG
}
}; };
} // namespace autofill_assistant } // namespace autofill_assistant
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "components/autofill_assistant/browser/selector.h" #include "components/autofill_assistant/browser/selector.h"
#include "base/strings/string_util.h"
namespace autofill_assistant { namespace autofill_assistant {
Selector::Selector() : pseudo_type(PseudoType::UNDEFINED) {} Selector::Selector() : pseudo_type(PseudoType::UNDEFINED) {}
...@@ -41,4 +43,14 @@ bool Selector::empty() const { ...@@ -41,4 +43,14 @@ bool Selector::empty() const {
return this->selectors.empty(); return this->selectors.empty();
} }
} // namespace autofill_assistant std::ostream& operator<<(std::ostream& out, const Selector& selector) {
\ No newline at end of file #ifdef NDEBUG
out << selector.selectors.size() << " element(s)";
return out;
#else
out << "elements=[" << base::JoinString(selector.selectors, ",") << "]";
return out;
#endif // NDEBUG
}
} // namespace autofill_assistant
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_SELECTOR_H_ #ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_SELECTOR_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_SELECTOR_H_ #define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_SELECTOR_H_
#include <ostream>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -39,6 +40,10 @@ struct Selector { ...@@ -39,6 +40,10 @@ struct Selector {
bool operator<(const Selector& other) const; bool operator<(const Selector& other) const;
bool operator==(const Selector& other) const; bool operator==(const Selector& other) const;
// The output operator. The actual selectors are only available in debug
// builds.
friend std::ostream& operator<<(std::ostream& out, const Selector& selector);
// Checks whether this selector is empty. // Checks whether this selector is empty.
bool empty() const; bool empty() const;
}; };
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_ #ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_ #define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_
#include <ostream>
namespace autofill_assistant { namespace autofill_assistant {
// High-level states the Autofill Assistant can be in. // High-level states the Autofill Assistant can be in.
...@@ -47,6 +49,43 @@ enum class AutofillAssistantState { ...@@ -47,6 +49,43 @@ enum class AutofillAssistantState {
STOPPED STOPPED
}; };
inline std::ostream& operator<<(std::ostream& out,
const AutofillAssistantState& state) {
#ifdef NDEBUG
// Non-debugging builds write the enum number.
out << static_cast<int>(state);
return out;
#else
// Debugging builds write a string representation of |state|.
switch (state) {
case AutofillAssistantState::INACTIVE:
out << "INACTIVE";
break;
case AutofillAssistantState::STARTING:
out << "STARTING";
break;
case AutofillAssistantState::RUNNING:
out << "RUNNING";
break;
case AutofillAssistantState::PROMPT:
out << "PROMPT";
break;
case AutofillAssistantState::AUTOSTART_FALLBACK_PROMPT:
out << "AUTOSTART_FALLBACK_PROMPT";
break;
case AutofillAssistantState::MODAL_DIALOG:
out << "MODAL_DIALOG";
break;
case AutofillAssistantState::STOPPED:
out << "STOPPED";
break;
// Intentionally no default case to make compilation fail if a new value
// was added to the enum but not to this list.
}
return out;
#endif // NDEBUG
}
} // namespace autofill_assistant } // namespace autofill_assistant
#endif // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_ #endif // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/i18n/char_iterator.h" #include "base/i18n/char_iterator.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -253,7 +254,7 @@ void WebController::ElementPositionGetter::GetAndWaitBoxModelStable() { ...@@ -253,7 +254,7 @@ void WebController::ElementPositionGetter::GetAndWaitBoxModelStable() {
void WebController::ElementPositionGetter::OnGetBoxModelForStableCheck( void WebController::ElementPositionGetter::OnGetBoxModelForStableCheck(
std::unique_ptr<dom::GetBoxModelResult> result) { std::unique_ptr<dom::GetBoxModelResult> result) {
if (!result || !result->GetModel() || !result->GetModel()->GetContent()) { if (!result || !result->GetModel() || !result->GetModel()->GetContent()) {
DVLOG(1) << "Failed to get box model."; DVLOG(1) << __func__ << " Failed to get box model.";
OnError(); OnError();
return; return;
} }
...@@ -324,7 +325,7 @@ void WebController::ElementPositionGetter::OnGetBoxModelForStableCheck( ...@@ -324,7 +325,7 @@ void WebController::ElementPositionGetter::OnGetBoxModelForStableCheck(
void WebController::ElementPositionGetter::OnScrollIntoView( void WebController::ElementPositionGetter::OnScrollIntoView(
std::unique_ptr<runtime::CallFunctionOnResult> result) { std::unique_ptr<runtime::CallFunctionOnResult> result) {
if (!result || result->HasExceptionDetails()) { if (!result || result->HasExceptionDetails()) {
DVLOG(1) << "Failed to scroll the element."; DVLOG(1) << __func__ << " Failed to scroll the element.";
OnError(); OnError();
return; return;
} }
...@@ -376,12 +377,14 @@ const GURL& WebController::GetUrl() { ...@@ -376,12 +377,14 @@ const GURL& WebController::GetUrl() {
} }
void WebController::LoadURL(const GURL& url) { void WebController::LoadURL(const GURL& url) {
DVLOG(3) << __func__ << " " << url;
web_contents_->GetController().LoadURLWithParams( web_contents_->GetController().LoadURLWithParams(
content::NavigationController::LoadURLParams(url)); content::NavigationController::LoadURLParams(url));
} }
void WebController::ClickOrTapElement(const Selector& selector, void WebController::ClickOrTapElement(const Selector& selector,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
DVLOG(3) << __func__ << " " << selector;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
TapElement(selector, std::move(callback)); TapElement(selector, std::move(callback));
#else #else
...@@ -415,7 +418,7 @@ void WebController::OnFindElementForClickOrTap( ...@@ -415,7 +418,7 @@ void WebController::OnFindElementForClickOrTap(
std::unique_ptr<FindElementResult> result) { std::unique_ptr<FindElementResult> result) {
// Found element must belong to a frame. // Found element must belong to a frame.
if (!result->container_frame_host || result->object_id.empty()) { if (!result->container_frame_host || result->object_id.empty()) {
DVLOG(1) << "Failed to find the element to click or tap."; DVLOG(1) << __func__ << " Failed to find the element to click or tap.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -449,7 +452,7 @@ void WebController::OnScrollIntoView( ...@@ -449,7 +452,7 @@ void WebController::OnScrollIntoView(
bool is_a_click, bool is_a_click,
std::unique_ptr<runtime::CallFunctionOnResult> result) { std::unique_ptr<runtime::CallFunctionOnResult> result) {
if (!result || result->HasExceptionDetails()) { if (!result || result->HasExceptionDetails()) {
DVLOG(1) << "Failed to scroll the element."; DVLOG(1) << __func__ << " Failed to scroll the element.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -472,7 +475,7 @@ void WebController::TapOrClickOnCoordinates( ...@@ -472,7 +475,7 @@ void WebController::TapOrClickOnCoordinates(
int x, int x,
int y) { int y) {
if (!has_coordinates) { if (!has_coordinates) {
DVLOG(1) << "Failed to get element position."; DVLOG(1) << __func__ << " Failed to get element position.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -511,7 +514,8 @@ void WebController::OnDispatchPressMouseEvent( ...@@ -511,7 +514,8 @@ void WebController::OnDispatchPressMouseEvent(
int y, int y,
std::unique_ptr<input::DispatchMouseEventResult> result) { std::unique_ptr<input::DispatchMouseEventResult> result) {
if (!result) { if (!result) {
DVLOG(1) << "Failed to dispatch mouse left button pressed event."; DVLOG(1) << __func__
<< " Failed to dispatch mouse left button pressed event.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -538,7 +542,7 @@ void WebController::OnDispatchTouchEventStart( ...@@ -538,7 +542,7 @@ void WebController::OnDispatchTouchEventStart(
base::OnceCallback<void(bool)> callback, base::OnceCallback<void(bool)> callback,
std::unique_ptr<input::DispatchTouchEventResult> result) { std::unique_ptr<input::DispatchTouchEventResult> result) {
if (!result) { if (!result) {
DVLOG(1) << "Failed to dispatch touch start event."; DVLOG(1) << __func__ << " Failed to dispatch touch start event.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -621,7 +625,7 @@ void WebController::OnGetDocumentElement( ...@@ -621,7 +625,7 @@ void WebController::OnGetDocumentElement(
element_result->container_frame_selector_index = 0; element_result->container_frame_selector_index = 0;
element_result->object_id = ""; element_result->object_id = "";
if (!result || !result->GetResult() || !result->GetResult()->HasObjectId()) { if (!result || !result->GetResult() || !result->GetResult()->HasObjectId()) {
DVLOG(1) << "Failed to get document root element."; DVLOG(1) << __func__ << " Failed to get document root element.";
std::move(callback).Run(std::move(element_result)); std::move(callback).Run(std::move(element_result));
return; return;
} }
...@@ -716,7 +720,7 @@ void WebController::OnDescribeNodeForPseudoElement( ...@@ -716,7 +720,7 @@ void WebController::OnDescribeNodeForPseudoElement(
FindElementCallback callback, FindElementCallback callback,
std::unique_ptr<dom::DescribeNodeResult> result) { std::unique_ptr<dom::DescribeNodeResult> result) {
if (!result || !result->GetNode()) { if (!result || !result->GetNode()) {
DVLOG(1) << "Failed to describe the node for pseudo element."; DVLOG(1) << __func__ << " Failed to describe the node for pseudo element.";
std::move(callback).Run(std::move(element_result)); std::move(callback).Run(std::move(element_result));
return; return;
} }
...@@ -762,7 +766,7 @@ void WebController::OnDescribeNode( ...@@ -762,7 +766,7 @@ void WebController::OnDescribeNode(
FindElementCallback callback, FindElementCallback callback,
std::unique_ptr<dom::DescribeNodeResult> result) { std::unique_ptr<dom::DescribeNodeResult> result) {
if (!result || !result->GetNode()) { if (!result || !result->GetNode()) {
DVLOG(1) << "Failed to describe the node."; DVLOG(1) << __func__ << " Failed to describe the node.";
std::move(callback).Run(std::move(element_result)); std::move(callback).Run(std::move(element_result));
return; return;
} }
...@@ -793,7 +797,7 @@ void WebController::OnDescribeNode( ...@@ -793,7 +797,7 @@ void WebController::OnDescribeNode(
element_result->container_frame_host = FindCorrespondingRenderFrameHost( element_result->container_frame_host = FindCorrespondingRenderFrameHost(
frame_name, node->GetContentDocument()->GetDocumentURL()); frame_name, node->GetContentDocument()->GetDocumentURL());
if (!element_result->container_frame_host) { if (!element_result->container_frame_host) {
DVLOG(1) << "Failed to find corresponding owner frame."; DVLOG(1) << __func__ << " Failed to find corresponding owner frame.";
std::move(callback).Run(std::move(element_result)); std::move(callback).Run(std::move(element_result));
return; return;
} }
...@@ -834,7 +838,7 @@ void WebController::OnResolveNode( ...@@ -834,7 +838,7 @@ void WebController::OnResolveNode(
FindElementCallback callback, FindElementCallback callback,
std::unique_ptr<dom::ResolveNodeResult> result) { std::unique_ptr<dom::ResolveNodeResult> result) {
if (!result || !result->GetObject() || !result->GetObject()->HasObjectId()) { if (!result || !result->GetObject() || !result->GetObject()->HasObjectId()) {
DVLOG(1) << "Failed to resolve object id from backend id."; DVLOG(1) << __func__ << " Failed to resolve object id from backend id.";
std::move(callback).Run(std::move(element_result)); std::move(callback).Run(std::move(element_result));
return; return;
} }
...@@ -875,7 +879,7 @@ void WebController::OnFindElementForFocusElement( ...@@ -875,7 +879,7 @@ void WebController::OnFindElementForFocusElement(
base::OnceCallback<void(bool)> callback, base::OnceCallback<void(bool)> callback,
std::unique_ptr<FindElementResult> element_result) { std::unique_ptr<FindElementResult> element_result) {
if (element_result->object_id.empty()) { if (element_result->object_id.empty()) {
DVLOG(1) << "Failed to find the element to focus on."; DVLOG(1) << __func__ << " Failed to find the element to focus on.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -899,7 +903,7 @@ void WebController::OnFocusElement( ...@@ -899,7 +903,7 @@ void WebController::OnFocusElement(
base::OnceCallback<void(bool)> callback, base::OnceCallback<void(bool)> callback,
std::unique_ptr<runtime::CallFunctionOnResult> result) { std::unique_ptr<runtime::CallFunctionOnResult> result) {
if (!result || result->HasExceptionDetails()) { if (!result || result->HasExceptionDetails()) {
DVLOG(1) << "Failed to focus on element."; DVLOG(1) << __func__ << " Failed to focus on element.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -909,6 +913,7 @@ void WebController::OnFocusElement( ...@@ -909,6 +913,7 @@ void WebController::OnFocusElement(
void WebController::FillAddressForm(const autofill::AutofillProfile* profile, void WebController::FillAddressForm(const autofill::AutofillProfile* profile,
const Selector& selector, const Selector& selector,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
DVLOG(3) << __func__ << selector;
auto data_to_autofill = std::make_unique<FillFormInputData>(); auto data_to_autofill = std::make_unique<FillFormInputData>();
data_to_autofill->profile = data_to_autofill->profile =
std::make_unique<autofill::AutofillProfile>(*profile); std::make_unique<autofill::AutofillProfile>(*profile);
...@@ -926,7 +931,7 @@ void WebController::OnFindElementForFillingForm( ...@@ -926,7 +931,7 @@ void WebController::OnFindElementForFillingForm(
base::OnceCallback<void(bool)> callback, base::OnceCallback<void(bool)> callback,
std::unique_ptr<FindElementResult> element_result) { std::unique_ptr<FindElementResult> element_result) {
if (element_result->object_id.empty()) { if (element_result->object_id.empty()) {
DVLOG(1) << "Failed to find the element for filling the form."; DVLOG(1) << __func__ << " Failed to find the element for filling the form.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -952,7 +957,7 @@ void WebController::OnGetFormAndFieldDataForFillingForm( ...@@ -952,7 +957,7 @@ void WebController::OnGetFormAndFieldDataForFillingForm(
const autofill::FormData& form_data, const autofill::FormData& form_data,
const autofill::FormFieldData& form_field) { const autofill::FormFieldData& form_field) {
if (form_data.fields.empty()) { if (form_data.fields.empty()) {
DVLOG(1) << "Failed to get form data to fill form."; DVLOG(1) << __func__ << " Failed to get form data to fill form.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -960,7 +965,7 @@ void WebController::OnGetFormAndFieldDataForFillingForm( ...@@ -960,7 +965,7 @@ void WebController::OnGetFormAndFieldDataForFillingForm(
ContentAutofillDriver* driver = ContentAutofillDriver* driver =
ContentAutofillDriver::GetForRenderFrameHost(container_frame_host); ContentAutofillDriver::GetForRenderFrameHost(container_frame_host);
if (!driver) { if (!driver) {
DVLOG(1) << "Failed to get the autofill driver."; DVLOG(1) << __func__ << " Failed to get the autofill driver.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -981,6 +986,7 @@ void WebController::FillCardForm(std::unique_ptr<autofill::CreditCard> card, ...@@ -981,6 +986,7 @@ void WebController::FillCardForm(std::unique_ptr<autofill::CreditCard> card,
const base::string16& cvc, const base::string16& cvc,
const Selector& selector, const Selector& selector,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
DVLOG(3) << __func__ << " " << selector;
auto data_to_autofill = std::make_unique<FillFormInputData>(); auto data_to_autofill = std::make_unique<FillFormInputData>();
data_to_autofill->card = std::move(card); data_to_autofill->card = std::move(card);
data_to_autofill->cvc = cvc; data_to_autofill->cvc = cvc;
...@@ -995,6 +1001,7 @@ void WebController::FillCardForm(std::unique_ptr<autofill::CreditCard> card, ...@@ -995,6 +1001,7 @@ void WebController::FillCardForm(std::unique_ptr<autofill::CreditCard> card,
void WebController::SelectOption(const Selector& selector, void WebController::SelectOption(const Selector& selector,
const std::string& selected_option, const std::string& selected_option,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
DVLOG(3) << __func__ << " " << selector << ", option=" << selected_option;
FindElement(selector, FindElement(selector,
/* strict_mode= */ true, /* strict_mode= */ true,
base::BindOnce(&WebController::OnFindElementForSelectOption, base::BindOnce(&WebController::OnFindElementForSelectOption,
...@@ -1008,7 +1015,7 @@ void WebController::OnFindElementForSelectOption( ...@@ -1008,7 +1015,7 @@ void WebController::OnFindElementForSelectOption(
std::unique_ptr<FindElementResult> element_result) { std::unique_ptr<FindElementResult> element_result) {
const std::string object_id = element_result->object_id; const std::string object_id = element_result->object_id;
if (object_id.empty()) { if (object_id.empty()) {
DVLOG(1) << "Failed to find the element to select an option."; DVLOG(1) << __func__ << " Failed to find the element to select an option.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -1033,7 +1040,7 @@ void WebController::OnSelectOption( ...@@ -1033,7 +1040,7 @@ void WebController::OnSelectOption(
base::OnceCallback<void(bool)> callback, base::OnceCallback<void(bool)> callback,
std::unique_ptr<runtime::CallFunctionOnResult> result) { std::unique_ptr<runtime::CallFunctionOnResult> result) {
if (!result || result->HasExceptionDetails()) { if (!result || result->HasExceptionDetails()) {
DVLOG(1) << "Failed to select option."; DVLOG(1) << __func__ << " Failed to select option.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -1045,6 +1052,7 @@ void WebController::OnSelectOption( ...@@ -1045,6 +1052,7 @@ void WebController::OnSelectOption(
void WebController::HighlightElement(const Selector& selector, void WebController::HighlightElement(const Selector& selector,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
DVLOG(3) << __func__ << " " << selector;
FindElement( FindElement(
selector, selector,
/* strict_mode= */ true, /* strict_mode= */ true,
...@@ -1057,7 +1065,7 @@ void WebController::OnFindElementForHighlightElement( ...@@ -1057,7 +1065,7 @@ void WebController::OnFindElementForHighlightElement(
std::unique_ptr<FindElementResult> element_result) { std::unique_ptr<FindElementResult> element_result) {
const std::string object_id = element_result->object_id; const std::string object_id = element_result->object_id;
if (object_id.empty()) { if (object_id.empty()) {
DVLOG(1) << "Failed to find the element to highlight."; DVLOG(1) << __func__ << " Failed to find the element to highlight.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -1080,7 +1088,7 @@ void WebController::OnHighlightElement( ...@@ -1080,7 +1088,7 @@ void WebController::OnHighlightElement(
base::OnceCallback<void(bool)> callback, base::OnceCallback<void(bool)> callback,
std::unique_ptr<runtime::CallFunctionOnResult> result) { std::unique_ptr<runtime::CallFunctionOnResult> result) {
if (!result || result->HasExceptionDetails()) { if (!result || result->HasExceptionDetails()) {
DVLOG(1) << "Failed to highlight element."; DVLOG(1) << __func__ << " Failed to highlight element.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -1091,6 +1099,7 @@ void WebController::OnHighlightElement( ...@@ -1091,6 +1099,7 @@ void WebController::OnHighlightElement(
void WebController::FocusElement(const Selector& selector, void WebController::FocusElement(const Selector& selector,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
DVLOG(3) << __func__ << " " << selector;
DCHECK(!selector.empty()); DCHECK(!selector.empty());
FindElement( FindElement(
selector, selector,
...@@ -1146,6 +1155,8 @@ void WebController::SetFieldValue(const Selector& selector, ...@@ -1146,6 +1155,8 @@ void WebController::SetFieldValue(const Selector& selector,
const std::string& value, const std::string& value,
bool simulate_key_presses, bool simulate_key_presses,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
DVLOG(3) << __func__ << " " << selector << ", value=" << value
<< ", simulate_key_presses=" << simulate_key_presses;
if (simulate_key_presses) { if (simulate_key_presses) {
std::vector<std::string> utf8_chars; std::vector<std::string> utf8_chars;
base::i18n::UTF8CharIterator iter(&value); base::i18n::UTF8CharIterator iter(&value);
...@@ -1153,7 +1164,8 @@ void WebController::SetFieldValue(const Selector& selector, ...@@ -1153,7 +1164,8 @@ void WebController::SetFieldValue(const Selector& selector,
wchar_t wide_char = iter.get(); wchar_t wide_char = iter.get();
std::string utf8_char; std::string utf8_char;
if (!base::WideToUTF8(&wide_char, 1, &utf8_char)) { if (!base::WideToUTF8(&wide_char, 1, &utf8_char)) {
DVLOG(1) << "Failed to convert character to UTF-8: " << wide_char; DVLOG(1) << __func__
<< " Failed to convert character to UTF-8: " << wide_char;
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
return; return;
} }
...@@ -1291,6 +1303,9 @@ void WebController::SetAttribute(const Selector& selector, ...@@ -1291,6 +1303,9 @@ void WebController::SetAttribute(const Selector& selector,
const std::vector<std::string>& attribute, const std::vector<std::string>& attribute,
const std::string& value, const std::string& value,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
DVLOG(3) << __func__ << " " << selector << ", attribute=["
<< base::JoinString(attribute, ",") << "], value=" << value;
DCHECK(!selector.empty()); DCHECK(!selector.empty());
DCHECK_GT(attribute.size(), 0u); DCHECK_GT(attribute.size(), 0u);
FindElement(selector, FindElement(selector,
...@@ -1345,6 +1360,8 @@ void WebController::SendKeyboardInput( ...@@ -1345,6 +1360,8 @@ void WebController::SendKeyboardInput(
const Selector& selector, const Selector& selector,
const std::vector<std::string>& utf8_chars, const std::vector<std::string>& utf8_chars,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
DVLOG(3) << __func__ << " " << selector
<< ", input=" << base::JoinString(utf8_chars, "");
DCHECK(!selector.empty()); DCHECK(!selector.empty());
FindElement(selector, FindElement(selector,
/* strict_mode= */ true, /* strict_mode= */ true,
...@@ -1367,6 +1384,7 @@ void WebController::OnFindElementForSendKeyboardInput( ...@@ -1367,6 +1384,7 @@ void WebController::OnFindElementForSendKeyboardInput(
void WebController::GetOuterHtml( void WebController::GetOuterHtml(
const Selector& selector, const Selector& selector,
base::OnceCallback<void(bool, const std::string&)> callback) { base::OnceCallback<void(bool, const std::string&)> callback) {
DVLOG(3) << __func__ << " " << selector;
FindElement( FindElement(
selector, selector,
/* strict_mode= */ true, /* strict_mode= */ true,
...@@ -1450,6 +1468,7 @@ void WebController::OnFindElementForGetOuterHtml( ...@@ -1450,6 +1468,7 @@ void WebController::OnFindElementForGetOuterHtml(
std::unique_ptr<FindElementResult> element_result) { std::unique_ptr<FindElementResult> element_result) {
const std::string object_id = element_result->object_id; const std::string object_id = element_result->object_id;
if (object_id.empty()) { if (object_id.empty()) {
DVLOG(2) << __func__ << " Failed to find element for GetOuterHtml";
OnResult(false, "", std::move(callback)); OnResult(false, "", std::move(callback));
return; return;
} }
...@@ -1468,6 +1487,7 @@ void WebController::OnGetOuterHtml( ...@@ -1468,6 +1487,7 @@ void WebController::OnGetOuterHtml(
base::OnceCallback<void(bool, const std::string&)> callback, base::OnceCallback<void(bool, const std::string&)> callback,
std::unique_ptr<runtime::CallFunctionOnResult> result) { std::unique_ptr<runtime::CallFunctionOnResult> result) {
if (!result || result->HasExceptionDetails()) { if (!result || result->HasExceptionDetails()) {
DVLOG(2) << __func__ << " Failed to find element for GetOuterHtml";
OnResult(false, "", std::move(callback)); OnResult(false, "", std::move(callback));
return; return;
} }
...@@ -1480,6 +1500,7 @@ void WebController::OnGetOuterHtml( ...@@ -1480,6 +1500,7 @@ void WebController::OnGetOuterHtml(
void WebController::SetCookie(const std::string& domain, void WebController::SetCookie(const std::string& domain,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
DVLOG(3) << __func__ << " domain=" << domain;
DCHECK(!domain.empty()); DCHECK(!domain.empty());
auto expires_seconds = auto expires_seconds =
std::chrono::seconds(std::time(nullptr)).count() + kCookieExpiresSeconds; std::chrono::seconds(std::time(nullptr)).count() + kCookieExpiresSeconds;
...@@ -1501,6 +1522,7 @@ void WebController::OnSetCookie( ...@@ -1501,6 +1522,7 @@ void WebController::OnSetCookie(
} }
void WebController::HasCookie(base::OnceCallback<void(bool)> callback) { void WebController::HasCookie(base::OnceCallback<void(bool)> callback) {
DVLOG(3) << __func__;
devtools_client_->GetNetwork()->GetCookies( devtools_client_->GetNetwork()->GetCookies(
base::BindOnce(&WebController::OnHasCookie, base::BindOnce(&WebController::OnHasCookie,
weak_ptr_factory_.GetWeakPtr(), std::move(callback))); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
...@@ -1526,6 +1548,7 @@ void WebController::OnHasCookie( ...@@ -1526,6 +1548,7 @@ void WebController::OnHasCookie(
} }
void WebController::ClearCookie() { void WebController::ClearCookie() {
DVLOG(3) << __func__;
devtools_client_->GetNetwork()->DeleteCookies(kAutofillAssistantCookieName, devtools_client_->GetNetwork()->DeleteCookies(kAutofillAssistantCookieName,
base::DoNothing()); base::DoNothing());
} }
......
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