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 堆栈:

 

总结:

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

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

E. Expected Power (Codeforces 976 Div2)

这道题好难 原题 E. Expected Power 提示 Hint 1 试着找 f(S) 的期望值而不是 Hint 2 从f(S)的二进制表示中找规律来求 代码1 对答案代码做了注释 #include <bits/stdc.h> using namespace std;const int mod 1e97, N 2e5 10;// 最高只有1023, 小于等于2的10…

【论文阅读】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…

最新eclipse安装教程及安装包获取-附JDK安装

Eclipse简介 Eclipse 是一款开源的、功能强大、广泛应用的集成开发环境&#xff08;IDE&#xff09;&#xff0c;在软件开发领域占据着重要地位。 一、起源与发展 Eclipse 最初由 IBM 开发&#xff0c;2001 年以开源软件的形式发布。此后&#xff0c;它迅速吸引了全球众多开…

基于Python的在线音乐平台

作者&#xff1a;计算机学姐 开发技术&#xff1a;SpringBoot、SSM、Vue、MySQL、JSP、ElementUI、Python、小程序等&#xff0c;“文末源码”。 专栏推荐&#xff1a;前后端分离项目源码、SpringBoot项目源码、Vue项目源码、SSM项目源码、微信小程序源码 精品专栏&#xff1a;…

发送邮件和随机码的生成

类视图和方法视图区别&#xff1a; 不需要装饰器&#xff0c;只需要继承MethodView,需要使用什么方式就写对应的方法名称&#xff0c;它就能自动匹配 app.route("/delete/",methods["DELETE"])这些就不用写了 但是不写装饰器并不意味着不写路由了&#xff…

毕设分享 大数据用户画像分析系统(源码分享)

文章目录 0 前言2 用户画像分析概述2.1 用户画像构建的相关技术2.2 标签体系2.3 标签优先级 3 实站 - 百货商场用户画像描述与价值分析3.1 数据格式3.2 数据预处理3.3 会员年龄构成3.4 订单占比 消费画像3.5 季度偏好画像3.6 会员用户画像与特征3.6.1 构建会员用户业务特征标签…

Python入门笔记(四)

文章目录 第九章 集合set9.1 创建集合&#xff1a;set()、集合生成式9.2 集合性质9.3 一些函数&#xff1a;issubset()、issuperset()、isdisjoint()9.4 集合增加元素&#xff1a;add()、update()9.5 集合删除元素&#xff1a;remove()、discard()、pop()、clear()9.6 创建不能…

[论文笔记]SGPT: GPT Sentence Embeddings for Semantic Search

引言 解码器Transformer的规模不断壮大&#xff0c;轻松达到千亿级参数。同时由于该规模&#xff0c;基于提示或微调在各种NLP任务上达到SOTA结果。但目前为止解码器Transformer还无法应用在语义搜索或语句嵌入上。 为了简单&#xff0c;下文中以翻译的口吻记录&#xff0c;比…

企业如何制定适合自己的专利布局策略

在竞争激烈的市场环境中&#xff0c;专利布局对于企业的发展和竞争优势的建立至关重要。以下将分要点解析企业如何制定适合自己的专利布局策略。 1、明确企业的发展战略和市场定位 企业首先需要深入了解自身的长期发展规划和短期业务目标。明确是要通过技术创新来开拓新市场&am…

DSP CMD文件使用

背景描述: 在CCS编译代码时出现如下警告 解决方法: 找到cmd文件(这里是用的系统自动生成的)&#xff0c;在Section部分找到对应的核 #ifdef CORE7.text > CORE7_L2_SRAM.stack > CORE7_L2_SRAM.bss > CORE7_L2_SRAM.cio &g…

ARM base instruction -- umull

无符号乘法运算 Unsigned Multiply Long multiplies two 32-bit register values, and writes the result to the 64-bit destination register. 将两个32位寄存器值相乘&#xff0c;并将结果写入64位目标寄存器。 64-bit variant UMULL <Xd>, <Wn>, <Wm&g…

SQL第16课挑战题

1. 美国各州的缩写应始终用大写。更新所有美国地址&#xff0c;包括供应商状态&#xff08;Vendors表中的vend_state)和顾客状态&#xff08;customers表中的cust_state),使它们均为大写。 2. 第15课挑战题1要求将自己添加到customers表中&#xff0c;现在删除自己&#xff0c;…

AWS MySQL 升级(三)—— TAZ - 近0停机的小版本升级方案

与AWS交流了解到的新方案&#xff0c;没有实际试过&#xff0c;所以本篇主要是些原理 一、 TAZ的含义 TAZ实际上就是 3 AZ&#xff0c;扩展一些就是 Multi-AZ DB Cluster&#xff0c;即在3个可用区部署DB&#xff0c;具备两个只读备用实例。 二、 TAZ的主要用途 1. 近0停机的小…

Python和C++的差异在哪里

1.编程应用领域 C&#xff1a;广泛应用于系统级开发、嵌入式系统、游戏开发等领域。C的底层控制和高性能使其成为这些领域的理想选择。 Python&#xff1a;广泛应用于数据科学、Web开发、人工智能等领域。Python的简洁语法和强大库支持使其成为这些领域的首选语言。 2.语法风…

『网络游戏』制作提示弹窗UI【03】

将上一章的创建角色界面隐藏 创建一个空节点重命名为DynamicWnd 设置父物体为伸展 钉在中间创建一个Text文本组件 添加动画Animation组件 创建自定义动画Animation动画 点击创建 选择指定文件夹 拖拽至Animation 使用记录动画方式编辑动画首先点击红点录制 在第0帧设置文字透明…

文件夹访问被拒绝:深度解析、恢复策略与预防指南

一、文件夹访问被拒绝现象概述 在日常的电脑使用中&#xff0c;我们时常会遇到文件夹访问被拒绝的情况。这一现象通常表现为在尝试打开某个文件夹时&#xff0c;系统弹出权限不足的提示&#xff0c;阻止用户进行访问或操作。文件夹访问被拒绝不仅会影响用户的正常使用&#xf…

【YOLOv11】ultralytics最新作品yolov11 AND 模型的训练、推理、验证、导出 以及 使用

​目录 一 ultralytics公司的最新作品YOLOV11 1 yolov11的创新 2 安装YOLOv11 3 PYTHON Guide 二 训练 三 验证 四 推理 五 导出模型 六 使用 文档&#xff1a;https://docs.ultralytics.com/models/yolo11/ 代码链接&#xff1a;https://github.com/ultralytics/ult…

QT实现TCP通信

QT实现TCP通信案例 pro文件修改 QT core gui network 服务器端 widget.h代码 #ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include <QTcpServer> //服务器类 #include <QTcpSocket> //客户端类头文件 #include <QList> …

【Web】复现n00bzCTF2024 web题解(全)

目录 File Sharing Portal 方法一&#xff1a; 方法二&#xff1a; Focus-on-yourSELF Passwordless File Sharing Portal 附件的Dockerfile给了这么一段 # Add the cron job to the crontab RUN mkdir /etc/cron.custom RUN echo "*/5 * * * * root rm -rf /app…

uibot发送邮件:自动化邮件发送教程详解!

uibot发送邮件的操作指南&#xff1f;uibot发送邮件的两种方式&#xff1f; 在现代办公环境中&#xff0c;自动化流程的引入极大地提高了工作效率。uibot发送邮件功能成为了许多企业和个人实现邮件自动化发送的首选工具。AokSend将详细介绍如何使用uibot发送邮件。 uibot发送…