Chromium 如何查找已经定义好的mojom函数实现c++

news2024/10/8 11:17:23

进程通信定义通常都是用.mojom文件或者idl文件格式

以content\common\frame.mojom里面的BeginNavigation函数为例。

一、如何查找BeginNavigation函数定义,在vscode里面直接搜索BeginNavigation,过滤条件

*.idl,*.mojom,*.cc

效果:

这样定义mojom找到了。

content\common\frame.mojom定义如下(截取部分):

  // Sent by the renderer to request a navigation.
  // |blob_url_token| should be non-null when this is a navigation to a blob:
  // URL. The token will then be used to look up the blob associated with the
  // blob URL. Without this by the time the navigation code starts fetching
  // the URL the blob URL might no longer be valid. |blob_url_token| is
  // not part of BeginNavigationParams because that struct needs to be
  // cloneable, and thus can't contain mojo interfaces.
  // If an invalid BlobURLToken is passed in, or if the token doesn't match the
  // url in |common_params|, the navigation will result in a network error.
  // |navigation_client| is passed to the renderer to allow for further control
  // of the navigation. Allows for Commit and Cancels/Aborts.
  // Passing the |initiator_policy_container_keep_alive_handle| is just a means
  // to ensure that the PolicyContainerHost of the initiator RenderFrameHost is
  // kept alive, even if the RenderFrameHost itself has already been deleted in
  // the meantime. If this can be ensured in other ways, it is safe to pass a
  // mojo::NullRemote. In particular, if the initiator LocalFrame is alive when
  // issuing this mojo call, there is no need to pass
  // |initiator_policy_container_keep_alive_handle|, since the initiator
  // PolicyContainerHost is kept alive by LocalFrame's PolicyContainer.
  // TODO(https://crbug.com/1467502): |navigation_client| should not be
  // optional. Make it mandatory.
  // |renderer_cancellation_listener| is a per-navigation interface used to
  // listen to the end of the renderer-initiated navigation cancelation window
  // for this navigation. See comment for NavigationRendererCancellationListener
  // for more details.
  BeginNavigation(
      blink.mojom.CommonNavigationParams common_params,
      blink.mojom.BeginNavigationParams begin_params,
      pending_remote<blink.mojom.BlobURLToken>? blob_url_token,
      pending_associated_remote<NavigationClient>? navigation_client,
      pending_remote<blink.mojom.PolicyContainerHostKeepAliveHandle>?
          initiator_policy_container_keep_alive_handle,
      pending_receiver<NavigationRendererCancellationListener>
          renderer_cancellation_listener);

注意mojom文件编译时候会自动生成以下两个文件

out\Debug\gen\content\common\frame.mojom.cc

out\Debug\gen\content\common\frame.mojom.h

二、在vscode搜索BeginNavigation实现代码

第一部分、out\Debug\gen\+对应mojom文件相对目录.h这样存放

 例子:  out\Debug\gen\content\common\frame.mojom.h

              out\Debug\gen\content\common\frame.mojom.cc

    1)、发送方会调用在 ::mojo::internal::SendMojoMessage前设置好message.set_method_name("BeginNavigation");

知道此处打断点即可,可以不用想继续搜索发送方是谁了。

   看下规律frame.mojom.cc

void FrameHostProxy::BeginNavigation(
    ::blink::mojom::CommonNavigationParamsPtr in_common_params, ::blink::mojom::BeginNavigationParamsPtr in_begin_params, ::mojo::PendingRemote<::blink::mojom::BlobURLToken> in_blob_url_token, ::mojo::PendingAssociatedRemote<::content::mojom::NavigationClient> in_navigation_client, ::mojo::PendingRemote<::blink::mojom::PolicyContainerHostKeepAliveHandle> in_initiator_policy_container_keep_alive_handle, ::mojo::PendingReceiver<NavigationRendererCancellationListener> in_renderer_cancellation_listener) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send content::mojom::FrameHost::BeginNavigation", "input_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("common_params"), in_common_params,
                        "<value of type ::blink::mojom::CommonNavigationParamsPtr>");
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("begin_params"), in_begin_params,
                        "<value of type ::blink::mojom::BeginNavigationParamsPtr>");
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("blob_url_token"), in_blob_url_token,
                        "<value of type ::mojo::PendingRemote<::blink::mojom::BlobURLToken>>");
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("navigation_client"), in_navigation_client,
                        "<value of type ::mojo::PendingAssociatedRemote<::content::mojom::NavigationClient>>");
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("initiator_policy_container_keep_alive_handle"), in_initiator_policy_container_keep_alive_handle,
                        "<value of type ::mojo::PendingRemote<::blink::mojom::PolicyContainerHostKeepAliveHandle>>");
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("renderer_cancellation_listener"), in_renderer_cancellation_listener,
                        "<value of type ::mojo::PendingReceiver<NavigationRendererCancellationListener>>");
   });
#endif

  const bool kExpectsResponse = false;
  const bool kIsSync = false;
  const bool kAllowInterrupt = true;
  const bool is_urgent = false;
  
  const uint32_t kFlags =
      ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
      ((kIsSync) ? mojo::Message::kFlagIsSync : 0) |
      ((kAllowInterrupt) ? 0 : mojo::Message::kFlagNoInterrupt) |
      ((is_urgent) ? mojo::Message::kFlagIsUrgent : 0);
  
  mojo::Message message(
      internal::kFrameHost_BeginNavigation_Name, kFlags, 0, 0, nullptr);
  mojo::internal::MessageFragment<
      ::content::mojom::internal::FrameHost_BeginNavigation_Params_Data> params(
          message);
  params.Allocate();
  mojo::internal::MessageFragment<
      typename decltype(params->common_params)::BaseType> common_params_fragment(
          params.message());
  mojo::internal::Serialize<::blink::mojom::CommonNavigationParamsDataView>(
      in_common_params, common_params_fragment);
  params->common_params.Set(
      common_params_fragment.is_null() ? nullptr : common_params_fragment.data());
  MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
      params->common_params.is_null(),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null common_params in FrameHost.BeginNavigation request");
  mojo::internal::MessageFragment<
      typename decltype(params->begin_params)::BaseType> begin_params_fragment(
          params.message());
  mojo::internal::Serialize<::blink::mojom::BeginNavigationParamsDataView>(
      in_begin_params, begin_params_fragment);
  params->begin_params.Set(
      begin_params_fragment.is_null() ? nullptr : begin_params_fragment.data());
  MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
      params->begin_params.is_null(),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null begin_params in FrameHost.BeginNavigation request");
  mojo::internal::Serialize<mojo::InterfacePtrDataView<::blink::mojom::BlobURLTokenInterfaceBase>>(
      in_blob_url_token, &params->blob_url_token, &params.message());
  mojo::internal::Serialize<::content::mojom::NavigationClientAssociatedPtrInfoDataView>(
      in_navigation_client, &params->navigation_client, &params.message());
  mojo::internal::Serialize<mojo::InterfacePtrDataView<::blink::mojom::PolicyContainerHostKeepAliveHandleInterfaceBase>>(
      in_initiator_policy_container_keep_alive_handle, &params->initiator_policy_container_keep_alive_handle, &params.message());
  mojo::internal::Serialize<mojo::InterfaceRequestDataView<::content::mojom::NavigationRendererCancellationListenerInterfaceBase>>(
      in_renderer_cancellation_listener, &params->renderer_cancellation_listener, &params.message());
  MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
      !mojo::internal::IsHandleOrInterfaceValid(params->renderer_cancellation_listener),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
      "invalid renderer_cancellation_listener in FrameHost.BeginNavigation request");

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(FrameHost::Name_);
  message.set_method_name("BeginNavigation");
#endif
  // This return value may be ignored as false implies the Connector has
  // encountered an error, which will be visible through other means.
  ::mojo::internal::SendMojoMessage(*receiver_, message);
}
2)、接收方BeginNavigation 定义如下out\Debug\gen\content\common\frame.mojom.cc
  有类似这样的字样就是实现方 impl->BeginNavigation
    case internal::kFrameHost_BeginNavigation_Name: {

      DCHECK(message->is_serialized());
      internal::FrameHost_BeginNavigation_Params_Data* params =
          reinterpret_cast<internal::FrameHost_BeginNavigation_Params_Data*>(
              message->mutable_payload());
      
      bool success = true;
      ::blink::mojom::CommonNavigationParamsPtr p_common_params{};
      ::blink::mojom::BeginNavigationParamsPtr p_begin_params{};
      ::mojo::PendingRemote<::blink::mojom::BlobURLToken> p_blob_url_token{};
      ::mojo::PendingAssociatedRemote<::content::mojom::NavigationClient> p_navigation_client{};
      ::mojo::PendingRemote<::blink::mojom::PolicyContainerHostKeepAliveHandle> p_initiator_policy_container_keep_alive_handle{};
      ::mojo::PendingReceiver<NavigationRendererCancellationListener> p_renderer_cancellation_listener{};
      FrameHost_BeginNavigation_ParamsDataView input_data_view(params, message);
      
      if (success && !input_data_view.ReadCommonParams(&p_common_params))
        success = false;
      if (success && !input_data_view.ReadBeginParams(&p_begin_params))
        success = false;
      if (success) {
        p_blob_url_token =
            input_data_view.TakeBlobUrlToken<decltype(p_blob_url_token)>();
      }
      if (success) {
        p_navigation_client =
            input_data_view.TakeNavigationClient<decltype(p_navigation_client)>();
      }
      if (success) {
        p_initiator_policy_container_keep_alive_handle =
            input_data_view.TakeInitiatorPolicyContainerKeepAliveHandle<decltype(p_initiator_policy_container_keep_alive_handle)>();
      }
      if (success) {
        p_renderer_cancellation_listener =
            input_data_view.TakeRendererCancellationListener<decltype(p_renderer_cancellation_listener)>();
      }
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            FrameHost::Name_, 5, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->BeginNavigation(
std::move(p_common_params), 
std::move(p_begin_params), 
std::move(p_blob_url_token), 
std::move(p_navigation_client), 
std::move(p_initiator_policy_container_keep_alive_handle), 
std::move(p_renderer_cancellation_listener));
      return true;
    }

  第二部分、子进程定义

                   content\renderer\render_frame_impl.cc

  GetFrameHost()->BeginNavigation(
      MakeCommonNavigationParams(frame_->GetSecurityOrigin(), std::move(info),
                                 load_flags, has_download_sandbox_flag, from_ad,
                                 is_history_navigation_in_new_child_frame,
                                 request_destination),
      std::move(begin_navigation_params), std::move(blob_url_token),
      std::move(navigation_client_remote),
      std::move(initiator_policy_container_keep_alive_handle),
      std::move(renderer_cancellation_listener_receiver));

其中GetFrameHost()和FrameHostProxy对应关系很是巧妙。

mojom::FrameHost* RenderFrameImpl::GetFrameHost() {

  if (!frame_host_remote_.is_bound())

    GetRemoteAssociatedInterfaces()->GetInterface(&frame_host_remote_);

  return frame_host_remote_.get();

}

FrameHost和FrameHostProxy是同一个类吗?

先看mojo::AssociatedRemote<mojom::FrameHost> frame_host_remote_;定义

其中用模板对象AssociatedRemote初始化,那么看下定义

template <typename Interface>

class AssociatedRemote {

 public:

  using InterfaceType = Interface;

  using PendingType = PendingAssociatedRemote<Interface>;

  using Proxy = typename Interface::Proxy_;

mojo::AssociatedRemote类的Proxy替换完之后是mojom::FrameHost::Proxy_;

那么在看FrameHost定义

class CONTENT_EXPORT FrameHost
    : public FrameHostInterfaceBase {
 public:
  using IPCStableHashFunction = uint32_t(*)();

  static const char Name_[];
  static IPCStableHashFunction MessageToMethodInfo_(mojo::Message& message);
  static const char* MessageToMethodName_(mojo::Message& message);
  static constexpr uint32_t Version_ = 0;
  static constexpr bool PassesAssociatedKinds_ = true;
  static inline constexpr uint32_t kSyncMethodOrdinals[] = {
    0
  };
  static constexpr bool HasUninterruptableMethods_ = false;

  using Base_ = FrameHostInterfaceBase;
  using Proxy_ = FrameHostProxy;

其中将using Proxy_ = FrameHostProxy;

至此FrameHost和FrameHostProxy完成了关联 其实是一个巧妙的用了模板和using。

这样在mojo::AssociatedRemote类带哦用get函数时候直接获取的是FrameHostProxy。

  typename Interface::Proxy_* get() const {

    DCHECK(is_bound())

        << "Cannot issue Interface method calls on an unbound AssociatedRemote";

    return internal_state_.instance();

  }

  第三部分、主进程定义

content\browser\renderer_host\render_frame_host_impl.cc

void RenderFrameHostImpl::BeginNavigation(
    blink::mojom::CommonNavigationParamsPtr unvalidated_common_params,
    blink::mojom::BeginNavigationParamsPtr begin_params,
    mojo::PendingRemote<blink::mojom::BlobURLToken> blob_url_token,
    mojo::PendingAssociatedRemote<mojom::NavigationClient> navigation_client,
    mojo::PendingRemote<blink::mojom::PolicyContainerHostKeepAliveHandle>
        initiator_policy_container_host_keep_alive_handle,
    mojo::PendingReceiver<mojom::NavigationRendererCancellationListener>
        renderer_cancellation_listener) {
  TRACE_EVENT("navigation", "RenderFrameHostImpl::BeginNavigation",
              ChromeTrackEvent::kRenderFrameHost, this, "url",
              unvalidated_common_params->url.possibly_invalid_spec());

  // Only active and prerendered documents are allowed to start navigation in
  // their frame.
  if (lifecycle_state() != LifecycleStateImpl::kPrerendering) {
    // If this is reached in case the RenderFrameHost is in BackForwardCache
    // evict the document from BackForwardCache.
    if (IsInactiveAndDisallowActivation(
            DisallowActivationReasonId::kBeginNavigation)) {
      return;
    }
  }

     

总结:搜索其他模块也是类似,debug/gen目录是mojom文件具体实现,其他的是发送和接收实现,找到对应参数定义函数即可。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2196215.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

YoloV9改进策略:BackBone改进|CAFormer在YoloV9中的创新应用,显著提升目标检测性能

摘要 在目标检测领域,模型性能的提升一直是研究者和开发者们关注的重点。近期,我们尝试将CAFormer模块引入YoloV9模型中,以替换其原有的主干网络,这一创新性的改进带来了显著的性能提升。 CAFormer,作为MetaFormer框架下的一个变体,结合了深度可分离卷积和普通自注意力…

Python网络爬虫从入门到实战

目录 引言 一、网络爬虫的概念 二、 网络爬虫的基本工作流程 &#xff08;一&#xff09;过程&#xff1a; &#xff08;二&#xff09;安装requests模块和beautifulsoup4模块 &#xff08;三&#xff09;requests库的使用 1、requests库的基本介绍 2、导入requests库的…

新手教学系列——curl_cffi异步Session使用注意事项

在现代编程中,网络请求是应用程序交互的重要组成部分,尤其在爬虫和数据采集领域,异步请求的能力显得尤为关键。curl_cffi作为一个强大的库,使得Python开发者可以使用C语言的curl库高效地进行异步HTTP请求。本文将带您深入探索curl_cffi异步Session的使用注意事项,帮助您避…

详解正确创建好SpringBoot项目后但是找不到Maven的问题

目录 问题 解决步骤&#xff1a; 找到File->Project Structure... 设置SDK 设置SDKs 问题 刚刚在使用IDEA专业版创建好SpringBoot项目后&#xff0c;发现上方导航栏的运行按钮是灰色的&#xff0c;而且左侧导航栏的pom.xml的图标颜色也不是正常的&#xff0c;与此同时我…

设计模式01-类图及设计原理(Java)

一、设计模式综述 1.设计模式基本概念 设计模式&#xff08;Design Pattern&#xff09;是前辈们对代码开发经验的总结&#xff0c;是解决特定问题的一系列套路。它不是语法规定&#xff0c;而是一套用来提高代码可复用性、可维护性、可读性、稳健性以及安全性的解决方案。 …

电商价格监测:开启品牌渠道管控新时代

在当今数字化高速发展的时代&#xff0c;电商领域如同一艘艘巨轮在浩瀚的网络海洋中破浪前行。然而&#xff0c;对于众多品牌而言&#xff0c;电商数据的庞大体量却犹如一片迷雾之海&#xff0c;要在其中准确找到自己需监测的 SKU&#xff0c;无异于大海捞针。 品牌的价格监测之…

Linux的启动流程、移植到开发板

1、linux驱动开发与裸机开发的区别 Linux系统驱动和裸机驱动的主要区别在于运行时的环境和依赖。Linux系统驱动依赖于Linux内核提供的API和服务&#xff0c;而裸机驱动则是在没有操作系统支持的情况下直接与硬件交互。因此&#xff0c;两者的开发和调试方法也有很大差异。 2、…

【Qt】控件概述(7)—— 布局管理器

布局管理器 1. 布局管理器2. QVBoxLayout——垂直布局3. QHBoxLayout——水平布局4. QGridLayout——网格布局5. QFormLayout——表单布局6. QSpacer 1. 布局管理器 在我们之前值ui界面进行拖拽设置控件时&#xff0c;都是通过手动的控制控件的位置的。同时每个控件的位置都是…

Spring Boot新闻推荐系统:用户体验优化

3系统分析 3.1可行性分析 通过对本新闻推荐系统实行的目的初步调查和分析&#xff0c;提出可行性方案并对其一一进行论证。我们在这里主要从技术可行性、经济可行性、操作可行性等方面进行分析。 3.1.1技术可行性 本新闻推荐系统采用JAVA作为开发语言&#xff0c;Spring Boot框…

STM32F407寄存器操作(DMA+SPI)

1.前言 前面看B站中有些小伙伴吐槽F4的SPIDMA没有硬件可控的CS引脚&#xff0c;那么今天我就来攻破这个问题 我这边暂时没有SPI的从机芯片&#xff0c;并且接收的过程与发送的过程类似&#xff0c;所以这里我就以发送的过程为例了。 2.理论 手册上给出了如下的描述 我们关注…

Graphviz是一个开源的图形可视化软件

官网没有给出代码示例&#xff0c;所以需要自己琢磨&#xff0c; 这里最底下给了一些简单的&#xff0c; 确实可以出很好看的图片 Graphviz介绍 Graphviz是一个开源的图形可视化软件&#xff0c;主要用于绘制各种类型的图表&#xff0c;如流程图、结构图、网络拓扑图等。它通…

【黑马点评】5 Redisson分布式锁

【黑马点评】5 Redisson分布式锁 5 分布式锁-redisson5.1 分布式锁-redission功能介绍5.2 分布式锁-Redission快速入门5.3 分布式锁-redission可重入锁原理5.4 分布式锁-redission锁重试和WatchDog机制5.5 分布式锁-redission锁的MutiLock原理5.6 总结 黑马点评跟做笔记之 5 Re…

如何使用ssm实现学生工作管理系统

TOC ssm794学生工作管理系统jsp 绪论 1.1 研究背景 当前社会各行业领域竞争压力非常大&#xff0c;随着当前时代的信息化&#xff0c;科学化发展&#xff0c;让社会各行业领域都争相使用新的信息技术&#xff0c;对行业内的各种相关数据进行科学化&#xff0c;规范化管理。…

Java爬虫技术:解锁1688商品搜索的新维度

Java爬虫技术简介 Java爬虫技术是指使用Java语言编写的程序&#xff0c;模拟浏览器行为&#xff0c;自动化地从互联网上获取信息。随着技术的发展&#xff0c;Java爬虫技术已经非常成熟&#xff0c;有多种框架和库可以使用&#xff0c;如Jsoup、HttpClient、WebMagic等。 1688…

LSTM-Transformer时间序列预测(单输入单预测)——基于Pytorch框架

1 介绍 在本篇文章中&#xff0c;将介绍如何使用Transformer和LSTM模型进行时间序列预测。这两种模型分别擅长处理序列数据和捕捉时间序列中的长短期依赖关系。我们将结合这两种模型的优势&#xff0c;构建一个强大的预测模型。单输入单输出预测&#xff0c;适合风电预测&…

与C++类和对象的宿命(下)

本文 1.取地址运算符重载const成员函数取地址成员函数的重载 2. 再探构造函数3. 类型转换1. 隐式类型转换注意事项&#xff1a; 2. 显式类型转换2.1 static_cast2.2 dynamic_cast2.3 const_cast2.4 reinterpret_cast 3. C风格类型转换4. 类型转换操作符5. 注意事项6. 总结 4.st…

MySQL 绪论

数据库相关概念 数据库&#xff08;DB&#xff09;&#xff1a;存储数据的仓库数据库管理系统&#xff08;DBMS&#xff09;&#xff1a;操纵和管理数据库的大型软件SQL&#xff1a;操纵关系型数据库的编程语言&#xff0c;定义了一套操作关系型数据库的统一标准主流的关系型数…

域渗透之: 域渗透环境搭建详解基于VMware

域控环境介绍 在域架构中&#xff0c;最核心的就是域控主机&#xff0c;域控主机分为三种: 普通域控额外域控只读域控 域控环境相关知识点介绍 创建域环境首先就是要创建域控主机。域控主机创建完成以后&#xff0c;需要把所有的计算机拉入域中&#xff0c;这样就形成了域控…

权威认证:中国信通院表彰上海斯歌信创成就!

颁奖现场&#xff1a;左二为上海斯歌业务副总裁陈娅香 2024年9月24日-25日&#xff0c;由中国通信标准化协会主办、中国信息通信研究院&#xff08;简称“中国信通院”&#xff09;承办、中国通信企业协会支持的“2024数字化转型发展大会”在北京召开。本届大会以“拥抱数智化无…

Network - Telnet协议

Telnet 是一种网络协议&#xff0c;允许用户使用基于文本的界面通过网络与远程设备通信。它在早期的网络应用中被广泛用于远程管理和故障诊断&#xff0c;使用户能够连接到远程机器和服务&#xff0c;通常是通过 TCP/IP 网络。 Telnet is a network protocol that allows a use…