当前位置: 首页 > news >正文

Chromium 中chrome.history扩展接口c++实现

一、前端 chrome.history定义

使用 chrome.history API 与浏览器的已访问网页的记录进行交互。您可以在浏览器的历史记录中添加、移除和查询网址。如需使用您自己的版本替换历史记录页面,请参阅覆盖网页。

更多参考:chrome.history  |  API  |  Chrome for Developers (google.cn)

示例

若要试用此 API,请安装 chrome-extension-samples 中的 history API 示例 存储库

二、history接口在c++定义

   chrome\common\extensions\api\history.json

out\Debug\gen\chrome\common\extensions\api\history.cc

src\out\Debug\gen\chrome\common\extensions\api\history.h

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.[{"namespace": "history","description": "Use the <code>chrome.history</code> API to interact with the browser's record of visited pages. You can add, remove, and query for URLs in the browser's history. To override the history page with your own version, see <a href='override'>Override Pages</a>.","types": [{"id": "TransitionType","type": "string","enum": ["link", "typed", "auto_bookmark", "auto_subframe", "manual_subframe", "generated", "auto_toplevel", "form_submit", "reload", "keyword", "keyword_generated"],"description": "The <a href='#transition_types'>transition type</a> for this visit from its referrer."},{"id": "HistoryItem","type": "object","description": "An object encapsulating one result of a history query.","properties": {"id": {"type": "string", "minimum": 0, "description": "The unique identifier for the item."},"url": {"type": "string", "optional": true, "description": "The URL navigated to by a user."},"title": {"type": "string", "optional": true, "description": "The title of the page when it was last loaded."},"lastVisitTime": {"type": "number", "optional": true, "description": "When this page was last loaded, represented in milliseconds since the epoch."},"visitCount": {"type": "integer", "optional": true, "description": "The number of times the user has navigated to this page."},"typedCount": {"type": "integer", "optional": true, "description": "The number of times the user has navigated to this page by typing in the address."}}},{"id": "VisitItem","type": "object","description": "An object encapsulating one visit to a URL.","properties": {"id": {"type": "string", "minimum": 0, "description": "The unique identifier for the corresponding $(ref:history.HistoryItem)."},"visitId": {"type": "string", "description": "The unique identifier for this visit."},"visitTime": {"type": "number", "optional": true, "description": "When this visit occurred, represented in milliseconds since the epoch."},"referringVisitId": {"type": "string", "description": "The visit ID of the referrer."},"transition": {"$ref": "TransitionType","description": "The <a href='#transition_types'>transition type</a> for this visit from its referrer."},"isLocal": { "type": "boolean", "description": "True if the visit originated on this device. False if it was synced from a different device." }}},{"id": "UrlDetails","type": "object","properties": {"url": {"type": "string", "description": "The URL for the operation. It must be in the format as returned from a call to history.search."}}}],"functions": [{"name": "search","type": "function","description": "Searches the history for the last visit time of each page matching the query.","parameters": [{"name": "query","type": "object","properties": {"text": {"type": "string", "description": "A free-text query to the history service.  Leave empty to retrieve all pages."},"startTime": {"type": "number", "optional": true, "description": "Limit results to those visited after this date, represented in milliseconds since the epoch. If not specified, this defaults to 24 hours in the past."},"endTime": {"type": "number", "optional": true, "description": "Limit results to those visited before this date, represented in milliseconds since the epoch."},"maxResults": {"type": "integer", "optional": true, "minimum": 0, "description": "The maximum number of results to retrieve.  Defaults to 100."}}}],"returns_async": {"name": "callback","parameters": [{ "name": "results", "type": "array", "items": { "$ref": "HistoryItem"} }]}},{"name": "getVisits","type": "function","description": "Retrieves information about visits to a URL.","parameters": [{"name": "details","$ref": "UrlDetails"}],"returns_async": {"name": "callback","parameters": [{ "name": "results", "type": "array", "items": { "$ref": "VisitItem"} }]}},{"name": "addUrl","type": "function","description": "Adds a URL to the history at the current time with a <a href='#transition_types'>transition type</a> of \"link\".","parameters": [{"name": "details","$ref": "UrlDetails"}],"returns_async": {"name": "callback","optional": true,"parameters": []}},{"name": "deleteUrl","type": "function","description": "Removes all occurrences of the given URL from the history.","parameters": [{"name": "details","$ref": "UrlDetails"}],"returns_async": {"name": "callback","optional": true,"parameters": []}},{"name": "deleteRange","type": "function","description": "Removes all items within the specified date range from the history.  Pages will not be removed from the history unless all visits fall within the range.","parameters": [{"name": "range","type": "object","properties": {"startTime": { "type": "number", "description": "Items added to history after this date, represented in milliseconds since the epoch." },"endTime": { "type": "number", "description": "Items added to history before this date, represented in milliseconds since the epoch." }}}],"returns_async": {"name": "callback","parameters": []}},{"name": "deleteAll","type": "function","description": "Deletes all items from the history.","parameters": [],"returns_async": {"name": "callback","parameters": []}}],"events": [{"name": "onVisited","type": "function","description": "Fired when a URL is visited, providing the HistoryItem data for that URL.  This event fires before the page has loaded.","parameters": [{ "name": "result", "$ref": "HistoryItem"}]},{"name": "onVisitRemoved","type": "function","description": "Fired when one or more URLs are removed from the history service.  When all visits have been removed the URL is purged from history.","parameters": [{"name": "removed","type": "object","properties": {"allHistory": { "type": "boolean", "description": "True if all history was removed.  If true, then urls will be empty." },"urls": { "type": "array", "items": { "type": "string" }, "optional": true}}}]}]}
]

三、history API接口定义文件:

     chrome\browser\extensions\api\bookmarks\bookmarks_api.h

     chrome\browser\extensions\api\bookmarks\bookmarks_api.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.#ifndef CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_#include <string>
#include <vector>#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/values.h"
#include "chrome/common/extensions/api/history.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/history_service_observer.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function.h"class Profile;namespace extensions {// Observes History service and routes the notifications as events to the
// extension system.
class HistoryEventRouter : public history::HistoryServiceObserver {public:HistoryEventRouter(Profile* profile,history::HistoryService* history_service);HistoryEventRouter(const HistoryEventRouter&) = delete;HistoryEventRouter& operator=(const HistoryEventRouter&) = delete;~HistoryEventRouter() override;private:// history::HistoryServiceObserver.void OnURLVisited(history::HistoryService* history_service,const history::URLRow& url_row,const history::VisitRow& new_visit) override;void OnURLsDeleted(history::HistoryService* history_service,const history::DeletionInfo& deletion_info) override;void DispatchEvent(Profile* profile,events::HistogramValue histogram_value,const std::string& event_name,base::Value::List event_args);raw_ptr<Profile> profile_;base::ScopedObservation<history::HistoryService,history::HistoryServiceObserver>history_service_observation_{this};
};class HistoryAPI : public BrowserContextKeyedAPI, public EventRouter::Observer {public:explicit HistoryAPI(content::BrowserContext* context);~HistoryAPI() override;// KeyedService implementation.void Shutdown() override;// BrowserContextKeyedAPI implementation.static BrowserContextKeyedAPIFactory<HistoryAPI>* GetFactoryInstance();// EventRouter::Observer implementation.void OnListenerAdded(const EventListenerInfo& details) override;private:friend class BrowserContextKeyedAPIFactory<HistoryAPI>;raw_ptr<content::BrowserContext> browser_context_;// BrowserContextKeyedAPI implementation.static const char* service_name() {return "HistoryAPI";}static const bool kServiceIsNULLWhileTesting = true;// Created lazily upon OnListenerAdded.std::unique_ptr<HistoryEventRouter> history_event_router_;
};template <>
void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies();// Base class for history function APIs.
class HistoryFunction : public ExtensionFunction {protected:~HistoryFunction() override {}bool ValidateUrl(const std::string& url_string,GURL* url,std::string* error);bool VerifyDeleteAllowed(std::string* error);base::Time GetTime(double ms_from_epoch);Profile* GetProfile() const;
};// Base class for history funciton APIs which require async interaction with
// chrome services and the extension thread.
class HistoryFunctionWithCallback : public HistoryFunction {public:HistoryFunctionWithCallback();protected:~HistoryFunctionWithCallback() override;// The task tracker for the HistoryService callbacks.base::CancelableTaskTracker task_tracker_;
};class HistoryGetVisitsFunction : public HistoryFunctionWithCallback {public:DECLARE_EXTENSION_FUNCTION("history.getVisits", HISTORY_GETVISITS)protected:~HistoryGetVisitsFunction() override {}// ExtensionFunction:ResponseAction Run() override;// Callback for the history function to provide results.void QueryComplete(history::QueryURLResult result);
};class HistorySearchFunction : public HistoryFunctionWithCallback {public:DECLARE_EXTENSION_FUNCTION("history.search", HISTORY_SEARCH)protected:~HistorySearchFunction() override {}// ExtensionFunction:ResponseAction Run() override;// Callback for the history function to provide results.void SearchComplete(history::QueryResults results);
};class HistoryAddUrlFunction : public HistoryFunction {public:DECLARE_EXTENSION_FUNCTION("history.addUrl", HISTORY_ADDURL)protected:~HistoryAddUrlFunction() override {}// ExtensionFunction:ResponseAction Run() override;
};class HistoryDeleteAllFunction : public HistoryFunctionWithCallback {public:DECLARE_EXTENSION_FUNCTION("history.deleteAll", HISTORY_DELETEALL)protected:~HistoryDeleteAllFunction() override {}// ExtensionFunction:ResponseAction Run() override;// Callback for the history service to acknowledge deletion.void DeleteComplete();
};class HistoryDeleteUrlFunction : public HistoryFunction {public:DECLARE_EXTENSION_FUNCTION("history.deleteUrl", HISTORY_DELETEURL)protected:~HistoryDeleteUrlFunction() override {}// ExtensionFunction:ResponseAction Run() override;
};class HistoryDeleteRangeFunction : public HistoryFunctionWithCallback {public:DECLARE_EXTENSION_FUNCTION("history.deleteRange", HISTORY_DELETERANGE)protected:~HistoryDeleteRangeFunction() override {}// ExtensionFunction:ResponseAction Run() override;// Callback for the history service to acknowledge deletion.void DeleteComplete();
};}  // namespace extensions#endif  // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_

四、看下扩展调用history.getVisits 堆栈:

 

总结:

相关文章:

Chromium 中chrome.history扩展接口c++实现

一、前端 chrome.history定义 使用 chrome.history API 与浏览器的已访问网页的记录进行交互。您可以在浏览器的历史记录中添加、移除和查询网址。如需使用您自己的版本替换历史记录页面&#xff0c;请参阅覆盖网页。 更多参考&#xff1a;chrome.history | API | Chrome…...

(Linux和数据库)1.Linux操作系统和常用命令

了解Linux操作系统介绍 除了办公和玩游戏之外不用Linux&#xff0c;其他地方都要使用Linux&#xff08;it相关&#xff09; iOS的本质是unix&#xff08;unix是付费版本的操作系统&#xff09; unix和Linux之间很相似 Linux文件系统和目录 bin目录--放工具使用的 操作Linux远程…...

Linux——echo-tail-重定向符

echo命令 类似printf 输出 反引号 重定向符 > 和 >> > 覆盖 >> 追加 tail命令 查看文件尾部内容&#xff0c;追踪文件最新更改 tail -num 从尾部往上读num行&#xff0c;默认10行 tail -f 持续跟踪...

GitHub Copilot 使用手册(一)--配置

一、 什么是GitHub Copilot GitHub Copilot 是GitHub和OpenAI合作开发的一个人工智能工具&#xff0c;在使用Visual Studio Code、Microsoft Visual Studio、Vim、Cursor或JetBrains等IDE时可以协助用户编写代码等工作&#xff0c;实现虚拟的结对编程。 二、 GitHub Copilot …...

【论文阅读】Cross Attention Network for Few-shot Classification

用于小样本分类的交叉注意力网络 引用&#xff1a;Hou, Ruibing, et al. “Cross attention network for few-shot classification.” Advances in neural information processing systems 32 (2019). 论文地址&#xff1a;下载地址 论文代码&#xff1a;https://github.com/bl…...

CV图像处理小工具——json文件转P格式mask

CV图像处理小工具——json文件转P格式mask import cv2 import json import numpy as np import osdef func(file_path: str) -> np.ndarray:try:with open(file_path, moder, encoding"utf-8") as f:configs json.load(f)# 检查JSON是否包含必要的字段if "…...

Typora 快捷键操作大全

Typora 是一款简洁的 Markdown 编辑器&#xff0c;它提供了一些快捷键来帮助用户更高效地编辑文档。以下是一些常用的 Typora 快捷键&#xff0c;这些快捷键可能会根据操作系统有所不同&#xff08;Windows 和 macOS&#xff09;&#xff1a; 常用格式化快捷键 加粗&#xff…...

<Project-8.1.1 pdf2tx-mm> Python 调用 ChatGPT API 翻译PDF内容 历程心得

原因 用ZhipuAI&#xff0c;测试用的PDF里&#xff0c;有国名西部省穆斯林&#xff0c;翻译结果返回 “系统检测到输入或生成内容可能包含不安全或敏感内容&#xff0c;请您避免输入易产生敏感内容的提 示语&#xff0c;感谢您的配合” 。想过先替换掉省名、民族名等&#xff…...

JDK1.1主要特性

JDK 1.1&#xff0c;也被称为Java Development Kit 1.1&#xff0c;是Java编程语言的第一个更新版本&#xff0c;由Sun Microsystems公司在1997年发布。JDK 1.1在JDK 1.0的基础上进行了许多重要的改进和扩展&#xff0c;进一步巩固了Java作为一种强大、安全的编程语言和平台的地…...

软件测试工作中-商城类项目所遇bug点

商城的 bug 1、跨设备同步问题 当用户在不同设备上使用同一个账户时&#xff0c;购物车数据无法正确同步这可能是由于购物车数据存储和同步机制不完善,导致购物车内容在设备之间无法实时更新。怎么解决:开发把同步机制代码修改了一下&#xff0c;就不会出现这个 bug 了。 2、数…...

Java多线程面试题

1.进程和线程的区别 程序由指令和数据组成&#xff0c;但这些指令要运行&#xff0c;数据要读写&#xff0c;就必须将指令加载至 CPU中&#xff0c;数据加载至内存。在指令运行过程中还需要用到磁盘、网络等设备。进程就是用来加载指令、管理内存、管理 IO 的。 当一个程序被运…...

安徽大学《2022年+2023年831自动控制原理真题》 (完整版)

本文内容&#xff0c;全部选自自动化考研联盟的&#xff1a;《安徽大学831自控考研资料》的真题篇。后续会持续更新更多学校&#xff0c;更多年份的真题&#xff0c;记得关注哦~ 目录 2022年真题 2023年真题 Part1&#xff1a;2022年2023年完整版真题 2022年真题 2023年真题…...

Vulnhub靶场案例渗透[6]- DC6

文章目录 1. 靶场搭建2. 信息收集2.1 确定靶机ip2.2 主机信息收集2.3 主机目录扫描2.4 网站用户名和密码爆破 3. 反弹shell4. 提权 1. 靶场搭建 靶场源地址 检验下载文件的检验码&#xff0c;对比没问题使用vmware打开 # windwos 命令 Get-FileHash <filePath> -Algori…...

FreeSWITCH 分机网关路由

不废话了&#xff0c;直接贴代码&#xff1a; --[[作用&#xff1a;分机网关呼叫第一个参数&#xff1a; 分机号码第二个参数&#xff1a; 被叫号码第三个参数&#xff1a; 主叫号码使用例子:<extension name"usergw"><condition><action applicatio…...

数据交换的金钟罩:合理利用安全数据交换系统,确保信息安全

政府单位为了保护网络不受外部威胁和内部误操作的影响&#xff0c;通常会进行网络隔离&#xff0c;隔离成内网和外网。安全数据交换系统是专门设计用于在不同的网络环境&#xff08;如内部不同网络&#xff0c;内部网络和外部网络&#xff09;之间安全传输数据的解决方案。 使用…...

区块链积分系统:重塑支付安全与商业创新的未来

在当今社会&#xff0c;数字化浪潮席卷全球&#xff0c;支付安全与风险管理议题日益凸显。随着交易频次与规模的不断扩大&#xff0c;传统支付体系正面临前所未有的效率、合规性和安全挑战。 区块链技术&#xff0c;凭借其去中心化、高透明度以及数据不可篡改的特性&#xff0c…...

Django学习笔记十三:优秀案例学习

Django CMS 是一个基于 Django 框架的开源内容管理系统&#xff0c;它允许开发者轻松地创建和管理网站内容。Django CMS 提供了一个易于使用的界面来实现动态网站的快速开发&#xff0c;并且具有丰富的内容管理功能和多种插件扩展。以下是 Django CMS 的一些核心特性和如何开始…...

SSH 公钥认证:从gitlab clone项目repo到本地

这篇文章的分割线以下文字内容由 ChatGPT 生成&#xff08;我稍微做了一些文字上的调整和截图的补充&#xff09;&#xff0c;我review并实践后觉得内容没有什么问题&#xff0c;由此和大家分享。 假如你想通过 git clone git10.12.5.19:your_project.git 命令将 git 服务器上…...

linux 搭建sentinel

1.下载 linux执行下面的命令下载包 wget https://github.com/alibaba/Sentinel/releases/download/1.8.6/sentinel-dashboard-1.8.6.jar2.启动 nohup java -Dserver.port9090 -Dcsp.sentinel.dashboard.serverlocalhost:9090 -Dproject.namesentinel-dashboard -jar sentin…...

微服务发展历程

服务架构演进 服务架构演进过程&#xff1a;抽取各个模块独立维护&#xff0c;独立部署的过程。 初创公司2 ~ 3个研发人员&#xff0c;ALL IN ONE 的框架开发效率最高。随着队伍的壮大&#xff0c;产品&#xff0c;用户&#xff0c;商品成立独立小组&#xff0c;拆出相应的模块…...

小说下载器终极指南:一站式解决100+网站小说保存难题

小说下载器终极指南&#xff1a;一站式解决100网站小说保存难题 【免费下载链接】novel-downloader 一个可扩展的通用型小说下载器。 项目地址: https://gitcode.com/gh_mirrors/no/novel-downloader 在数字阅读时代&#xff0c;你是否曾因小说突然下架、网站404或网络中…...

DeepSeek系统设计辅助效能断崖式下降的3个信号,第2个90%工程师至今未察觉!

更多请点击&#xff1a; https://kaifayun.com 第一章&#xff1a;DeepSeek系统设计辅助效能断崖式下降的3个信号&#xff0c;第2个90%工程师至今未察觉&#xff01; 当 DeepSeek 的系统设计辅助能力突然变“笨”——接口建议频繁失准、上下文感知错乱、生成代码无法通过基础编…...

Tftpd32/Tftpd64不止是TFTP!手把手教你玩转它的DHCP和Syslog服务器功能

Tftpd32/Tftpd64&#xff1a;解锁DHCP与Syslog服务的隐藏潜力当大多数人提起Tftpd32/Tftpd64时&#xff0c;第一反应往往是它作为TFTP服务器的功能。这款轻量级工具确实在文件传输领域表现出色&#xff0c;但它的能力远不止于此。今天&#xff0c;我们将深入探索这款软件中两个…...

Yokogawa AAI835-H50/K4A00模拟输入/输出模块

Yokogawa AAI835-H50/K4A00 模拟输入/输出模块产品特点&#xff1a;通道配置&#xff1a;共8个通道&#xff0c;含4路模拟输入和4路模拟输出。信号类型&#xff1a;所有通道均支持4-20mA标准电流信号。HART通信&#xff1a;支持HART协议&#xff0c;可与智能现场设备双向数字通…...

D3KeyHelper:暗黑3玩家的智能按键助手,告别重复操作疲劳

D3KeyHelper&#xff1a;暗黑3玩家的智能按键助手&#xff0c;告别重复操作疲劳 【免费下载链接】D3keyHelper D3KeyHelper是一个有图形界面&#xff0c;可自定义配置的暗黑3鼠标宏工具。 项目地址: https://gitcode.com/gh_mirrors/d3/D3keyHelper 你是否曾在《暗黑破坏…...

潮州东方轻奢风全屋高定找哪家

开篇引言根据《2026年中国全屋定制行业发展报告》&#xff0c;潮州市全屋定制市场规模同比增长38%&#xff0c;其中全屋高端定制细分市场同比增长52%。目前&#xff0c;潮州市家庭全屋定制需求占比72%&#xff0c;高端定制需求占比45%。为了帮助潮州市消费者选择合规、靠谱、差…...

半导体元件(二极管/三极管/MOS管/IC)损坏诊断全解

半导体元件&#xff08;二极管、三极管、MOS 管、集成电路&#xff09;是 PCB 的核心功能单元&#xff0c;对过压、过流、ESD、高温极度敏感&#xff0c;损坏后直接导致电路功能失效、短路烧板。很多工程师维修时盲目更换芯片&#xff0c;不仅成本高&#xff0c;还易误判。​一…...

WebSocket实时通信架构进阶:Room、命名空间与集群部署

WebSocket实时通信架构进阶:Room、命名空间与集群部署 作者:Crown_22 | AI Agent & Hermes Agent 桌面程序开发者 前言 WebSocket已经成为实时应用的标准技术,但大多数教程只停留在"建立连接、发送消息"的基础阶段。在生产环境中,你需要处理Room管理、命名空…...

如何快速掌握MoveIt2:面向ROS 2开发者的工业机器人运动规划完整指南

如何快速掌握MoveIt2&#xff1a;面向ROS 2开发者的工业机器人运动规划完整指南 【免费下载链接】moveit2 :robot: MoveIt for ROS 2 项目地址: https://gitcode.com/gh_mirrors/mo/moveit2 想要为你的机器人实现智能运动规划吗&#xff1f;MoveIt2作为ROS 2生态中最强大…...

终极指南:5步快速掌握免费的3D点云标注工具labelCloud

终极指南&#xff1a;5步快速掌握免费的3D点云标注工具labelCloud 【免费下载链接】labelCloud A lightweight tool for labeling 3D bounding boxes in point clouds. 项目地址: https://gitcode.com/gh_mirrors/la/labelCloud 想要为自动驾驶、机器人视觉或3D目标检测…...