chromium - 将webui的资源和实现文件放入子目录

前言

第一次做web-ui实验时,看官方文档上并没有特别说明,如何将资源文件和实现文件放入子目录,方便维护。
这2天在看chrome://download-internals/的实现,这个web-ui是2017年加入的,算是比较新的web-ui.
download-internals的资源文件和实现文件虽然没放在一起,但是也分别放入了不同类别父目录的同名子目录下。
对照git和以前做的实验,发现只要改下列文件,就可以实现将自己的web-ui统一放入子目录,方便维护。
chrome/browser/browser_resources.grd
chrome/browser/ui/BUILD.gn
chrome/browser/ui/BUILD.gn
实现文件中的头文件引用
因为建立了新文件夹,资源文件和实现文件移动了位置,需要将修改git add和提交,工程也需要增量编译一下。

实验

  • chrome/browser/browser_resources.grd
    </structures>
    <includes>
      <include name="IDR_HELLO_WORLD_HTML" file="resources\my_page\my_hello_world.html" type="BINDATA" />
      <include name="IDR_HELLO_WORLD_CSS" file="resources\my_page\my_hello_world.css" type="BINDATA" />
      <include name="IDR_HELLO_WORLD_JS" file="resources\my_page\my_hello_world.js" type="BINDATA" />
      
      <if expr="is_win or is_macosx or desktop_linux or chromeos">
        <include name="IDR_ABOUT_DISCARDS_CSS" file="resources\discards\discards.css" type="BINDATA" />

chrome/browser/resources/my_page/中可以放入自己web-ui的资源文件(.html, .csss, .js)

  • chrome/browser/ui/BUILD.gn
  sources = [
    "accelerator_utils.h",
    "app_list/app_list_util.cc",
    "app_list/app_list_util.h",

    # All other browser/ui/app_list files go under enable_app_list below.
    "webui/my_page/hello_world_ui.cc",
    "webui/my_page/hello_world_ui.h",

    "autofill/autofill_dialog_models.cc",

  • Z:\chromium\src\chrome\browser\ui\webui\hello_world_ui.cc
// @file Z:\chromium\src\chrome\browser\ui\webui\hello_world_ui.cc

#include "chrome/browser/ui/webui/my_page/hello_world_ui.h"

#include "content/public/browser/browser_context.h"

  • chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"

#include <stddef.h>

#include <vector>

#include "base/bind.h"
#include "base/feature_list.h"
#include "base/location.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "chrome/browser/about_flags.h"
#include "chrome/browser/devtools/devtools_ui_bindings.h"
#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
#include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/media/media_engagement_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/search/suggestions/suggestions_ui.h"

#include "chrome/browser/ui/webui/my_page/hello_world_ui.h"

#include "chrome/browser/ui/history_ui.h"

猜你喜欢

转载自blog.csdn.net/LostSpeed/article/details/84988505
今日推荐