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

news2024/11/28 17:49:10

进程通信定义通常都是用.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/2206458.html

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

相关文章

HECTOR:一种新型多模态深度学习模型用于预测子宫内膜癌复发风险|顶刊精析·24-10-12

小罗碎碎念 这篇文章是关于一项名为HECTOR&#xff08;histopathology-based endometrial cancer tailored outcome risk&#xff09;的研究&#xff0c;它是一个基于多模态深度学习的预测模型&#xff0c;用于预测子宫内膜癌&#xff08;EC&#xff09;的复发风险。 作者角色作…

threejs-加载gltf模型

一、介绍 1.概念 glTF&#xff08;gl传输格式&#xff09;是一种开放格式的规范 &#xff08;open format specification&#xff09;&#xff0c; 用于更高效地传输、加载3D内容。该类文件以JSON&#xff08;.gltf&#xff09;格式或二进制&#xff08;.glb&#xff09;格式提…

常用的web服务器简述

一.Web服务器介绍 ‌Web服务器是一种运行于互联网上的计算机硬件或软件&#xff0c;用于存储、处理和传输网页和其他网站内容。‌ 它通常运行在服务器上&#xff0c;绑定服务器的IP地址并监听某一个TCP端口&#xff0c;接收来自客户端的请求&#xff0c;然后向客户端发送所请求…

中国地级市生态韧性数据及城市生态韧性数据(2000-2022年)

一测算方式&#xff1a; 参考C刊《管理学刊》楚尔鸣&#xff08;2023&#xff09;老师的做法&#xff0c;城市生态韧性主要衡量一个城市在面临生态环境系统压力或突发冲击时&#xff0c;约束污染排放、维护生态环境状态和治理能力提升的综合水平。 参考郭海红和刘新民的研究&a…

JavaScript操作DOM对象

DOM 是 JavaScript 操作网页的接口&#xff0c;全称为“文档对象模型” &#xff08;Document Object Model&#xff09;。它的作用是将网页转为一个 JavaScript 对象&#xff0c;从而可以用脚本进行各种操作&#xff08;比如对元素增删 内容&#xff09; 节点的类型有七…

基于STM32的智能家居--硬件接线

分配GPIO 1.首先分配串口通讯引脚&#xff0c;该开发板中有三组串口引脚分别分配如图所示。 2.分配SPI。 3.其他为普通GPIO口&#xff0c;B8,B9模拟IIC协议与OLED屏幕进行通讯。

GEE数据集:美国玉米、大豆和冬小麦 QDANN 30m 产量图/数据集

目录 QDANN 30m Yield Map for Corn, Soy, and Winter Wheat in the U.S美国玉米、大豆和冬小麦 QDANN 30m 产量图 简介 数据集预处理 代码 引用 许可 QDANN 30m Yield Map for Corn, Soy, and Winter Wheat in the U.S美国玉米、大豆和冬小麦 QDANN 30m 产量图 简介 …

指针——数组(指针)传参

&#xff08;一&#xff09;前文问题答案解析 1、代码 int(*pa[10])[5] 的解析 某人&#xff1a;嗯&#xff0c;有*pa&#xff0c;这不很明显是个指针嘛&#xff0c;然后 [5] 说明是个数组指针&#xff0c;int类型&#xff0c;[10]。。。。 这这这&#xff0c;很明显不是指针。…

【笔记】Day2.3.3自定义异常+2.3.4resource注入

此项目一共写了两个自定义异常 因为&#xff1a; 1.前后端交互的响应码&#xff08;如200&#xff0c;401&#xff09;大差不差 区别几乎只在于响应结果中的msg和code表达是否成功 2.而微服务的接口之间调用采用restful方式 状态码要使用标准的http状态码 如&#xff1a;200…

【Linux探索学习】第四弹——Linux权限管理详解:理解用户、组和权限之间的关系

前言&#xff1a; 在前面我们已经学习了Linux的基础指令&#xff0c;相信大家对Linux已经有了一定的认识&#xff0c;今天我们来学习Linux权限的相关知识点&#xff0c;Linux权限是Linux初学者必须要掌握的内容 目录 一、Linux下用户类型 二、权限基本概念 三、权限的表示 四…

SpringBoot整合web中使用jsp

1、在pom.xml文件中导入jsp依赖的jar包&#xff0c;一个是jstl标签&#xff0c;一个是jsp的引擎 <dependency><groupId>org.apache.taglibs</groupId><artifactId>taglibs-standard-spec</artifactId><version>1.2.5</version> <…

窗口售票系统1.0版本

本窗口售票系统实现了三个售票窗口的随机售票&#xff0c;实现随机到某一个窗口买票&#xff0c;总票余量都会减少&#xff0c;即三个窗口共享同一个票余量。若票余量小于一次性购票量&#xff0c;则提示报错&#xff1b;若车票售罄&#xff0c;则代码结束运行。 代码实现&…

代码随想录算法训练营第三十天|491. 非递减子序列,46. 全排列,47. 全排列 II,332. 重新安排行程,51. N 皇后,37. 解数独

491. 非递减子序列&#xff0c;46. 全排列&#xff0c;47. 全排列 II&#xff0c;332. 重新安排行程&#xff0c;51. N 皇后&#xff0c;37. 解数独 491. 非递减子序列46. 全排列47. 全排列 II332. 重新安排行程51. N 皇后37. 解数独 491. 非递减子序列 给你一个整数数组 nums…

技术成神之路:设计模式(二十)装饰模式

介绍 装饰模式&#xff08;Decorator Pattern&#xff09;是一种结构型设计模式&#xff0c;它允许在不改变对象自身的情况下&#xff0c;动态地为对象添加额外的职责。这个模式通常用于增强或改变对象的功能。 1.定义 装饰模式通过创建一个装饰类&#xff0c;将功能动态地添加…

网站设计公司怎么评估?2024网站定制公司哪家好

在选择一家网站建设公司时&#xff0c;需要采取一些筛选方法来评估其能力和专业性。可以通过查看公司的案例展示、项目经验、团队规模等方面来评估公司的实力。同时&#xff0c;需要了解公司是否有与自己业务相似的项目经验&#xff0c;以便更好地满足自己的需求。在选择公司时…

win0删除 Windows.old

参考&#xff1a;https://blog.csdn.net/xitongzhijia_abc/article/details/126270452 win10如下所示&#xff1a; 打开 设置–>系统—>存储

Ps:PDF 演示文稿

Ps菜单&#xff1a;文件/自动/PDF 演示文稿 Automate/PDF Presentation PDF 演示文稿 PDF Presentation命令提供了创建 PDF 演示文稿的多种选项&#xff0c;用户可以添加当前打开的文件或手动选择文件&#xff0c;选择背景颜色、字体大小等&#xff0c;设置演示文稿的页面切换间…

哪个牌子充电宝性价比高?2024年精选性价比排行榜充电宝推荐

在数字化生活日益普及的今天&#xff0c;充电宝作为我们移动设备的“能量加油站”&#xff0c;其重要性不言而喻。无论是商务出行、旅行探险还是日常通勤&#xff0c;一款性价比高、安全可靠的充电宝都是不可或缺的伴侣。然而&#xff0c;面对市场上琳琅满目的充电宝品牌与型号…

芯课堂 | Synwit_UI_Creator(μgui)平台之图像处理篇

今天小编给大家介绍的是UI_Creator&#xff08;μgui&#xff09;平台下关于图像处理的选项。 UI_Creator&#xff08;μgui&#xff09;平台图片类控件有图像控件和分级图像控件&#xff0c;均包含以下选项&#xff1a; 1、消除水波纹&#xff1a; 由于16位真彩色&#xff08…