chromium/chrome/test/chromedriver/chrome/web_view_impl.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/test/chromedriver/chrome/web_view_impl.h"

#include <stddef.h>

#include <algorithm>
#include <cstring>
#include <memory>
#include <queue>
#include <utility>
#include <vector>

#include "base/check.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/strings/pattern.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/test/chromedriver/chrome/bidi_tracker.h"
#include "chrome/test/chromedriver/chrome/browser_info.h"
#include "chrome/test/chromedriver/chrome/cast_tracker.h"
#include "chrome/test/chromedriver/chrome/devtools_client.h"
#include "chrome/test/chromedriver/chrome/devtools_client_impl.h"
#include "chrome/test/chromedriver/chrome/download_directory_override_manager.h"
#include "chrome/test/chromedriver/chrome/fedcm_tracker.h"
#include "chrome/test/chromedriver/chrome/frame_tracker.h"
#include "chrome/test/chromedriver/chrome/geolocation_override_manager.h"
#include "chrome/test/chromedriver/chrome/heap_snapshot_taker.h"
#include "chrome/test/chromedriver/chrome/js.h"
#include "chrome/test/chromedriver/chrome/mobile_emulation_override_manager.h"
#include "chrome/test/chromedriver/chrome/navigation_tracker.h"
#include "chrome/test/chromedriver/chrome/network_conditions_override_manager.h"
#include "chrome/test/chromedriver/chrome/non_blocking_navigation_tracker.h"
#include "chrome/test/chromedriver/chrome/page_load_strategy.h"
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/chrome/ui_events.h"
#include "chrome/test/chromedriver/net/timeout.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/keyboard_code_conversion.h"

namespace {

const int kWaitForNavigationStopSeconds =;
const char kElementKey[] =;
const char kElementKeyW3C[] =;
const char kShadowRootKey[] =;

struct ElementId {};

std::optional<std::string> GetBackendNodeIdKey(const base::Value::Dict& element,
                                               bool w3c_compliant) {}

ElementId GetElementId(const base::Value::Dict& element, std::string key) {}

ElementId GetElementId(const base::Value::Dict& element, bool w3c_compliant) {}

Status GetContextIdForFrame(WebViewImpl* web_view,
                            const std::string& frame,
                            std::string* context_id) {}

const char* GetAsString(MouseEventType type) {}

const char* GetAsString(TouchEventType type) {}

const char* GetAsString(MouseButton button) {}

const char* GetAsString(KeyEventType type) {}

const char* GetAsString(PointerType type) {}

base::Value::Dict GenerateTouchPoint(const TouchEvent& event) {}

class ObjectGroup {};

Status DescribeNode(DevToolsClient* client,
                    int backend_node_id,
                    int depth,
                    bool pierce,
                    base::Value* result_node) {}

Status GetFrameIdForBackendNodeId(DevToolsClient* client,
                                  int backend_node_id,
                                  bool* found_node,
                                  std::string* frame_id) {}

Status ResolveWeakReferences(base::Value::List& nodes) {}

class BidiTrackerGuard {};

}  // namespace

std::unique_ptr<WebViewImpl> WebViewImpl::CreateServiceWorkerWebView(
    const std::string& id,
    const bool w3c_compliant,
    const BrowserInfo* browser_info,
    std::unique_ptr<DevToolsClient> client) {}

std::unique_ptr<WebViewImpl> WebViewImpl::CreateTopLevelWebView(
    const std::string& id,
    const bool w3c_compliant,
    const BrowserInfo* browser_info,
    std::unique_ptr<DevToolsClient> client,
    std::optional<MobileDevice> mobile_device,
    std::string page_load_strategy,
    bool autoaccept_beforeunload) {}

WebViewImpl::WebViewImpl(const std::string& id,
                         const bool w3c_compliant,
                         const WebViewImpl* parent,
                         const BrowserInfo* browser_info,
                         std::unique_ptr<DevToolsClient> client)
    :{}

WebViewImpl::WebViewImpl(const std::string& id,
                         const bool w3c_compliant,
                         const WebViewImpl* parent,
                         const BrowserInfo* browser_info,
                         std::unique_ptr<DevToolsClient> client,
                         std::optional<MobileDevice> mobile_device,
                         std::string page_load_strategy,
                         bool autoaccept_beforeunload)
    :{}

WebViewImpl::~WebViewImpl() = default;

std::unique_ptr<PageLoadStrategy> WebViewImpl::CreatePageLoadStrategy(
    const std::string& strategy) {}

WebView* WebViewImpl::GetTargetForFrame(const std::string& frame) {}

bool WebViewImpl::IsServiceWorker() const {}

std::unique_ptr<WebViewImpl> WebViewImpl::CreateChild(
    const std::string& session_id,
    const std::string& target_id) const {}

std::string WebViewImpl::GetId() {}

bool WebViewImpl::WasCrashed() {}

Status WebViewImpl::AttachTo(DevToolsClient* root_client) {}

Status WebViewImpl::AttachChildView(WebViewImpl* child) {}

Status WebViewImpl::HandleEventsUntil(const ConditionalFunc& conditional_func,
                                      const Timeout& timeout) {}

Status WebViewImpl::HandleReceivedEvents() {}

Status WebViewImpl::GetUrl(std::string* url) {}

Status WebViewImpl::Load(const std::string& url, const Timeout* timeout) {}

Status WebViewImpl::Reload(const Timeout* timeout) {}

Status WebViewImpl::Freeze(const Timeout* timeout) {}

Status WebViewImpl::Resume(const Timeout* timeout) {}

Status WebViewImpl::StartBidiServer(std::string bidi_mapper_script) {}

Status WebViewImpl::PostBidiCommand(base::Value::Dict command) {}

Status WebViewImpl::SendBidiCommand(base::Value::Dict command,
                                    const Timeout& timeout,
                                    base::Value::Dict& response) {}

Status WebViewImpl::SendCommand(const std::string& cmd,
                                const base::Value::Dict& params) {}

Status WebViewImpl::SendCommandFromWebSocket(const std::string& cmd,
                                             const base::Value::Dict& params,
                                             const int client_cmd_id) {}

Status WebViewImpl::SendCommandAndGetResult(
    const std::string& cmd,
    const base::Value::Dict& params,
    std::unique_ptr<base::Value>* value) {}

Status WebViewImpl::TraverseHistory(int delta, const Timeout* timeout) {}

Status WebViewImpl::GetLoaderId(const std::string& frame_id,
                                const Timeout& timeout,
                                std::string& loader_id) {}

Status WebViewImpl::CallFunctionWithTimeoutInternal(
    std::string frame,
    std::string function,
    base::Value::List args,
    const base::TimeDelta& timeout,
    std::unique_ptr<base::Value>* result) {}

Status WebViewImpl::EvaluateScript(const std::string& frame,
                                   const std::string& expression,
                                   const bool await_promise,
                                   std::unique_ptr<base::Value>* result) {}

Status WebViewImpl::CallFunctionWithTimeout(
    const std::string& frame,
    const std::string& function,
    const base::Value::List& args,
    const base::TimeDelta& timeout,
    std::unique_ptr<base::Value>* result) {}

Status WebViewImpl::CallFunction(const std::string& frame,
                                 const std::string& function,
                                 const base::Value::List& args,
                                 std::unique_ptr<base::Value>* result) {}

Status WebViewImpl::CallUserSyncScript(const std::string& frame,
                                       const std::string& script,
                                       const base::Value::List& args,
                                       const base::TimeDelta& timeout,
                                       std::unique_ptr<base::Value>* result) {}

Status WebViewImpl::CallUserAsyncFunction(
    const std::string& frame,
    const std::string& function,
    const base::Value::List& args,
    const base::TimeDelta& timeout,
    std::unique_ptr<base::Value>* result) {}

// TODO (crbug.com/chromedriver/4364): Simplify this function
Status WebViewImpl::GetFrameByFunction(const std::string& frame,
                                       const std::string& function,
                                       const base::Value::List& args,
                                       std::string* out_frame) {}

Status WebViewImpl::DispatchTouchEventsForMouseEvents(
    const std::vector<MouseEvent>& events,
    const std::string& frame) {}

Status WebViewImpl::DispatchMouseEvents(const std::vector<MouseEvent>& events,
                                        const std::string& frame,
                                        bool async_dispatch_events) {}

Status WebViewImpl::DispatchTouchEvent(const TouchEvent& event,
                                       bool async_dispatch_events) {}

Status WebViewImpl::DispatchTouchEvents(const std::vector<TouchEvent>& events,
                                        bool async_dispatch_events) {}

Status WebViewImpl::DispatchTouchEventWithMultiPoints(
    const std::vector<TouchEvent>& events,
    bool async_dispatch_events) {}

Status WebViewImpl::DispatchKeyEvents(const std::vector<KeyEvent>& events,
                                      bool async_dispatch_events) {}

Status WebViewImpl::GetCookies(base::Value* cookies,
                               const std::string& current_page_url) {}

Status WebViewImpl::DeleteCookie(const std::string& name,
                                 const std::string& url,
                                 const std::string& domain,
                                 const std::string& path) {}

Status WebViewImpl::AddCookie(const std::string& name,
                              const std::string& url,
                              const std::string& value,
                              const std::string& domain,
                              const std::string& path,
                              const std::string& same_site,
                              bool secure,
                              bool http_only,
                              double expiry) {}

Status WebViewImpl::WaitForPendingNavigations(const std::string& frame_id,
                                              const Timeout& timeout,
                                              bool stop_load_on_timeout) {}

Status WebViewImpl::IsPendingNavigation(const Timeout* timeout,
                                        bool* is_pending) const {}

MobileEmulationOverrideManager* WebViewImpl::GetMobileEmulationOverrideManager()
    const {}

Status WebViewImpl::OverrideGeolocation(const Geoposition& geoposition) {}

Status WebViewImpl::OverrideNetworkConditions(
    const NetworkConditions& network_conditions) {}

Status WebViewImpl::OverrideDownloadDirectoryIfNeeded(
    const std::string& download_directory) {}

Status WebViewImpl::CaptureScreenshot(std::string* screenshot,
                                      const base::Value::Dict& params) {}

Status WebViewImpl::PrintToPDF(const base::Value::Dict& params,
                               std::string* pdf) {}

Status WebViewImpl::GetBackendNodeIdByElement(const std::string& frame,
                                              const base::Value& element,
                                              int* backend_node_id) {}

Status WebViewImpl::SetFileInputFiles(const std::string& frame,
                                      const base::Value& element,
                                      const std::vector<base::FilePath>& files,
                                      const bool append) {}

Status WebViewImpl::TakeHeapSnapshot(std::unique_ptr<base::Value>* snapshot) {}

Status WebViewImpl::InitProfileInternal() {}

Status WebViewImpl::StopProfileInternal() {}

Status WebViewImpl::StartProfile() {}

Status WebViewImpl::EndProfile(std::unique_ptr<base::Value>* profile_data) {}

Status WebViewImpl::SynthesizeTapGesture(int x,
                                         int y,
                                         int tap_count,
                                         bool is_long_press) {}

Status WebViewImpl::SynthesizeScrollGesture(int x,
                                            int y,
                                            int xoffset,
                                            int yoffset) {}

Status WebViewImpl::CallAsyncFunctionInternal(
    const std::string& frame,
    const std::string& function,
    const base::Value::List& args,
    const base::TimeDelta& timeout,
    std::unique_ptr<base::Value>* result) {}

void WebViewImpl::SetFrame(const std::string& new_frame_id) {}

Status WebViewImpl::IsNotPendingNavigation(const std::string& frame_id,
                                           const Timeout* timeout,
                                           bool* is_not_pending) {}

bool WebViewImpl::IsNonBlocking() const {}

Status WebViewImpl::GetFedCmTracker(FedCmTracker** out_tracker) {}

FrameTracker* WebViewImpl::GetFrameTracker() const {}

const WebViewImpl* WebViewImpl::GetParent() const {}

bool WebViewImpl::Lock() {}

void WebViewImpl::Unlock() {}

bool WebViewImpl::IsLocked() const {}

void WebViewImpl::SetDetached() {}

bool WebViewImpl::IsDetached() const {}

std::unique_ptr<base::Value> WebViewImpl::GetCastSinks() {}

std::unique_ptr<base::Value> WebViewImpl::GetCastIssueMessage() {}

Status WebViewImpl::ResolveElementReferencesInPlace(
    const std::string& expected_frame_id,
    const std::string& context_id,
    const std::string& object_group_name,
    const std::string& expected_loader_id,
    bool w3c_compliant,
    const Timeout& timeout,
    base::Value::Dict& arg_dict,
    base::Value::List& nodes) {}

Status WebViewImpl::ResolveElementReferencesInPlace(
    const std::string& expected_frame_id,
    const std::string& context_id,
    const std::string& object_group_name,
    const std::string& expected_loader_id,
    bool w3c_compliant,
    const Timeout& timeout,
    base::Value::List& arg_list,
    base::Value::List& nodes) {}

Status WebViewImpl::ResolveElementReferencesInPlace(
    const std::string& expected_frame_id,
    const std::string& context_id,
    const std::string& object_group_name,
    const std::string& expected_loader_id,
    bool w3c_compliant,
    const Timeout& timeout,
    base::Value& arg,
    base::Value::List& nodes) {}

Status WebViewImpl::CreateElementReferences(const std::string& frame_id,
                                            const std::string& loader_id,
                                            const base::Value::List& nodes,
                                            base::Value& res) {}

bool WebViewImpl::IsDialogOpen() const {}

Status WebViewImpl::GetDialogMessage(std::string& message) const {}

Status WebViewImpl::GetTypeOfDialog(std::string& type) const {}

Status WebViewImpl::HandleDialog(bool accept,
                                 const std::optional<std::string>& text) {}

WebViewImplHolder::WebViewImplHolder(WebViewImpl* web_view) {}

WebViewImplHolder::~WebViewImplHolder() {}

namespace internal {

Status EvaluateScript(DevToolsClient* client,
                      const std::string& context_id,
                      const std::string& expression,
                      const base::TimeDelta& timeout,
                      const bool await_promise,
                      base::Value::Dict& result) {}

Status EvaluateScriptAndGetValue(DevToolsClient* client,
                                 const std::string& context_id,
                                 const std::string& expression,
                                 const base::TimeDelta& timeout,
                                 const bool await_promise,
                                 std::unique_ptr<base::Value>* result) {}

Status ParseCallFunctionResult(const base::Value& temp_result,
                               std::unique_ptr<base::Value>* result) {}

}  // namespace internal