Chromium 中chrome.downloads扩展接口c++
一、前端chrome.downloads
使用 chrome.downloads
API 以编程方式启动、监控、操作和搜索下载内容。
权限
downloads
您必须在扩展程序清单中声明 "downloads"
权限,才能使用此 API。
{"name": "My extension",..."permissions": ["downloads"],
}
示例
您可以在 examples/api/downloads 中找到使用 chrome.downloads
API 的简单示例 目录。如需获取其他示例以及查看源代码方面的帮助,请参阅示例。
chrome.downloads | API | Chrome for Developers (google.cn)
二、downloads.idl接口定义:chrome\common\extensions\api\downloads.idl
// 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.// Use the <code>chrome.downloads</code> API to programmatically initiate,
// monitor, manipulate, and search for downloads.
[permissions=downloads]
namespace downloads {[inline_doc] dictionary HeaderNameValuePair {// Name of the HTTP header.DOMString name;// Value of the HTTP header.DOMString value;};// <dl><dt>uniquify</dt>// <dd>To avoid duplication, the <code>filename</code> is changed to// include a counter before the filename extension.</dd>// <dt>overwrite</dt>// <dd>The existing file will be overwritten with the new file.</dd>// <dt>prompt</dt>// <dd>The user will be prompted with a file chooser dialog.</dd>// </dl>enum FilenameConflictAction {uniquify, overwrite, prompt};[inline_doc] dictionary FilenameSuggestion {// The $(ref:DownloadItem)'s new target $(ref:DownloadItem.filename), as a path// relative to the user's default Downloads directory, possibly containing// subdirectories. Absolute paths, empty paths, and paths containing// back-references ".." will be ignored. <code>filename</code> is ignored if// there are any $(ref:onDeterminingFilename) listeners registered by any// extensions.DOMString filename;// The action to take if <code>filename</code> already exists.FilenameConflictAction? conflictAction;};[inline_doc] enum HttpMethod {GET, POST};enum InterruptReason {FILE_FAILED,FILE_ACCESS_DENIED,FILE_NO_SPACE,FILE_NAME_TOO_LONG,FILE_TOO_LARGE,FILE_VIRUS_INFECTED,FILE_TRANSIENT_ERROR,FILE_BLOCKED,FILE_SECURITY_CHECK_FAILED,FILE_TOO_SHORT,FILE_HASH_MISMATCH,FILE_SAME_AS_SOURCE,NETWORK_FAILED,NETWORK_TIMEOUT,NETWORK_DISCONNECTED,NETWORK_SERVER_DOWN,NETWORK_INVALID_REQUEST,SERVER_FAILED,SERVER_NO_RANGE,SERVER_BAD_CONTENT,SERVER_UNAUTHORIZED,SERVER_CERT_PROBLEM,SERVER_FORBIDDEN,SERVER_UNREACHABLE,SERVER_CONTENT_LENGTH_MISMATCH,SERVER_CROSS_ORIGIN_REDIRECT,USER_CANCELED,USER_SHUTDOWN,CRASH};[inline_doc] dictionary DownloadOptions {// The URL to download.DOMString url;// A file path relative to the Downloads directory to contain the downloaded// file, possibly containing subdirectories. Absolute paths, empty paths,// and paths containing back-references ".." will cause an error.// $(ref:onDeterminingFilename) allows suggesting a filename after the file's// MIME type and a tentative filename have been determined.DOMString? filename;// The action to take if <code>filename</code> already exists.FilenameConflictAction? conflictAction;// Use a file-chooser to allow the user to select a filename regardless of// whether <code>filename</code> is set or already exists.boolean? saveAs;// The HTTP method to use if the URL uses the HTTP[S] protocol.HttpMethod? method;// Extra HTTP headers to send with the request if the URL uses the HTTP[s]// protocol. Each header is represented as a dictionary containing the keys// <code>name</code> and either <code>value</code> or// <code>binaryValue</code>, restricted to those allowed by XMLHttpRequest.HeaderNameValuePair[]? headers;// Post body.DOMString? body;};// <dl><dt>file</dt>// <dd>The download's filename is suspicious.</dd>// <dt>url</dt>// <dd>The download's URL is known to be malicious.</dd>// <dt>content</dt>// <dd>The downloaded file is known to be malicious.</dd>// <dt>uncommon</dt>// <dd>The download's URL is not commonly downloaded and could be// dangerous.</dd>// <dt>host</dt>// <dd>The download came from a host known to distribute malicious// binaries and is likely dangerous.</dd>// <dt>unwanted</dt>// <dd>The download is potentially unwanted or unsafe. E.g. it could make// changes to browser or computer settings.</dd>// <dt>safe</dt>// <dd>The download presents no known danger to the user's computer.</dd>// <dt>accepted</dt>// <dd>The user has accepted the dangerous download.</dd>// </dl>enum DangerType {file,url,content,uncommon,host,unwanted,safe,accepted,allowlistedByPolicy,asyncScanning,asyncLocalPasswordScanning,passwordProtected,blockedTooLarge,sensitiveContentWarning,sensitiveContentBlock,unsupportedFileType,deepScannedFailed,deepScannedSafe,deepScannedOpenedDangerous,promptForScanning,promptForLocalPasswordScanning,accountCompromise};// <dl><dt>in_progress</dt>// <dd>The download is currently receiving data from the server.</dd>// <dt>interrupted</dt>// <dd>An error broke the connection with the file host.</dd>// <dt>complete</dt>// <dd>The download completed successfully.</dd>// </dl>enum State {in_progress, interrupted, complete};// The state of the process of downloading a file.dictionary DownloadItem {// An identifier that is persistent across browser sessions.long id;// The absolute URL that this download initiated from, before any// redirects.DOMString url;// The absolute URL that this download is being made from, after all// redirects.DOMString finalUrl;// Absolute URL.DOMString referrer;// Absolute local path.DOMString filename;// False if this download is recorded in the history, true if it is not// recorded.boolean incognito;// Indication of whether this download is thought to be safe or known to be// suspicious.DangerType danger;// The file's MIME type.DOMString mime;// The time when the download began in ISO 8601 format. May be passed// directly to the Date constructor: <code>chrome.downloads.search({},// function(items){items.forEach(function(item){console.log(new// Date(item.startTime))})})</code>DOMString startTime;// The time when the download ended in ISO 8601 format. May be passed// directly to the Date constructor: <code>chrome.downloads.search({},// function(items){items.forEach(function(item){if (item.endTime)// console.log(new Date(item.endTime))})})</code>DOMString? endTime;// Estimated time when the download will complete in ISO 8601 format. May be// passed directly to the Date constructor:// <code>chrome.downloads.search({},// function(items){items.forEach(function(item){if (item.estimatedEndTime)// console.log(new Date(item.estimatedEndTime))})})</code>DOMString? estimatedEndTime;// Indicates whether the download is progressing, interrupted, or complete.State state;// True if the download has stopped reading data from the host, but kept the// connection open.boolean paused;// True if the download is in progress and paused, or else if it is// interrupted and can be resumed starting from where it was interrupted.boolean canResume;// Why the download was interrupted. Several kinds of HTTP errors may be// grouped under one of the errors beginning with <code>SERVER_</code>.// Errors relating to the network begin with <code>NETWORK_</code>, errors// relating to the process of writing the file to the file system begin with// <code>FILE_</code>, and interruptions initiated by the user begin with// <code>USER_</code>.InterruptReason? error;// Number of bytes received so far from the host, without considering file// compression.double bytesReceived;// Number of bytes in the whole file, without considering file compression,// or -1 if unknown.double totalBytes;// Number of bytes in the whole file post-decompression, or -1 if unknown.double fileSize;// Whether the downloaded file still exists. This information may be out of// date because Chrome does not automatically watch for file removal. Call// $(ref:search)() in order to trigger the check for file existence. When the// existence check completes, if the file has been deleted, then an// $(ref:onChanged) event will fire. Note that $(ref:search)() does not wait// for the existence check to finish before returning, so results from// $(ref:search)() may not accurately reflect the file system. Also,// $(ref:search)() may be called as often as necessary, but will not check for// file existence any more frequently than once every 10 seconds.boolean exists;// The identifier for the extension that initiated this download if this// download was initiated by an extension. Does not change once it is set.DOMString? byExtensionId;// The localized name of the extension that initiated this download if this// download was initiated by an extension. May change if the extension// changes its name or if the user changes their locale.DOMString? byExtensionName;};[inline_doc] dictionary DownloadQuery {// This array of search terms limits results to $(ref:DownloadItem) whose// <code>filename</code> or <code>url</code> or <code>finalUrl</code>// contain all of the search terms that do not begin with a dash '-' and// none of the search terms that do begin with a dash.DOMString[]? query;// Limits results to $(ref:DownloadItem) that// started before the given ms since the epoch.DOMString? startedBefore;// Limits results to $(ref:DownloadItem) that// started after the given ms since the epoch.DOMString? startedAfter;// Limits results to $(ref:DownloadItem) that ended before the given ms since the// epoch.DOMString? endedBefore;// Limits results to $(ref:DownloadItem) that ended after the given ms since the// epoch.DOMString? endedAfter;// Limits results to $(ref:DownloadItem) whose// <code>totalBytes</code> is greater than the given integer.double? totalBytesGreater;// Limits results to $(ref:DownloadItem) whose// <code>totalBytes</code> is less than the given integer.double? totalBytesLess;// Limits results to $(ref:DownloadItem) whose// <code>filename</code> matches the given regular expression.DOMString? filenameRegex;// Limits results to $(ref:DownloadItem) whose// <code>url</code> matches the given regular expression.DOMString? urlRegex;// Limits results to $(ref:DownloadItem) whose// <code>finalUrl</code> matches the given regular expression.DOMString? finalUrlRegex;// The maximum number of matching $(ref:DownloadItem) returned. Defaults to// 1000. Set to 0 in order to return all matching $(ref:DownloadItem). See// $(ref:search) for how to page through results.long? limit;// Set elements of this array to $(ref:DownloadItem) properties in order to// sort search results. For example, setting// <code>orderBy=['startTime']</code> sorts the $(ref:DownloadItem) by their// start time in ascending order. To specify descending order, prefix with a// hyphen: '-startTime'.DOMString[]? orderBy;// The <code>id</code> of the $(ref:DownloadItem) to query.long? id;// The absolute URL that this download initiated from, before any// redirects.DOMString? url;// The absolute URL that this download is being made from, after all// redirects.DOMString? finalUrl;// Absolute local path.DOMString? filename;// Indication of whether this download is thought to be safe or known to be// suspicious.DangerType? danger;// The file's MIME type.DOMString? mime;// The time when the download began in ISO 8601 format.DOMString? startTime;// The time when the download ended in ISO 8601 format.DOMString? endTime;// Indicates whether the download is progressing, interrupted, or complete.State? state;// True if the download has stopped reading data from the host, but kept the// connection open.boolean? paused;// Why a download was interrupted.InterruptReason? error;// Number of bytes received so far from the host, without considering file// compression.double? bytesReceived;// Number of bytes in the whole file, without considering file compression,// or -1 if unknown.double? totalBytes;// Number of bytes in the whole file post-decompression, or -1 if unknown.double? fileSize;// Whether the downloaded file exists;boolean? exists;};dictionary StringDelta {DOMString? previous;DOMString? current;};dictionary DoubleDelta {double? previous;double? current;};dictionary BooleanDelta {boolean? previous;boolean? current;};// Encapsulates a change in a DownloadItem.[inline_doc] dictionary DownloadDelta {// The <code>id</code> of the $(ref:DownloadItem)// that changed.long id;// The change in <code>url</code>, if any.StringDelta? url;// The change in <code>finalUrl</code>, if any.StringDelta? finalUrl;// The change in <code>filename</code>, if any.StringDelta? filename;// The change in <code>danger</code>, if any.StringDelta? danger;// The change in <code>mime</code>, if any.StringDelta? mime;// The change in <code>startTime</code>, if any.StringDelta? startTime;// The change in <code>endTime</code>, if any.StringDelta? endTime;// The change in <code>state</code>, if any.StringDelta? state;// The change in <code>canResume</code>, if any.BooleanDelta? canResume;// The change in <code>paused</code>, if any.BooleanDelta? paused;// The change in <code>error</code>, if any.StringDelta? error;// The change in <code>totalBytes</code>, if any.DoubleDelta? totalBytes;// The change in <code>fileSize</code>, if any.DoubleDelta? fileSize;// The change in <code>exists</code>, if any.BooleanDelta? exists;};[inline_doc] dictionary GetFileIconOptions {// The size of the returned icon. The icon will be square with dimensions// size * size pixels. The default and largest size for the icon is 32x32// pixels. The only supported sizes are 16 and 32. It is an error to specify// any other size.[legalValues=(16,32)] long? size;};// Encapsulates a change in the download UI.[inline_doc] dictionary UiOptions {// Enable or disable the download UI.boolean enabled;};callback DownloadCallback = void(long downloadId);callback SearchCallback = void(DownloadItem[] results);callback EraseCallback = void(long[] erasedIds);callback NullCallback = void();callback GetFileIconCallback = void(optional DOMString iconURL);callback SuggestFilenameCallback = void(optional FilenameSuggestion suggestion);interface Functions {// Download a URL. If the URL uses the HTTP[S] protocol, then the request// will include all cookies currently set for its hostname. If both// <code>filename</code> and <code>saveAs</code> are specified, then the// Save As dialog will be displayed, pre-populated with the specified// <code>filename</code>. If the download started successfully,// <code>callback</code> will be called with the new $(ref:DownloadItem)'s// <code>downloadId</code>. If there was an error starting the download,// then <code>callback</code> will be called with// <code>downloadId=undefined</code> and $(ref:runtime.lastError) will contain// a descriptive string. The error strings are not guaranteed to remain// backwards compatible between releases. Extensions must not parse it.// |options|: What to download and how.// |callback|: Called with the id of the new $(ref:DownloadItem).[supportsPromises] static void download(DownloadOptions options,optional DownloadCallback callback);// Find $(ref:DownloadItem). Set <code>query</code> to the empty object to get// all $(ref:DownloadItem). To get a specific $(ref:DownloadItem), set only the// <code>id</code> field. To page through a large number of items, set// <code>orderBy: ['-startTime']</code>, set <code>limit</code> to the// number of items per page, and set <code>startedAfter</code> to the// <code>startTime</code> of the last item from the last page.[supportsPromises] static void search(DownloadQuery query,SearchCallback callback);// Pause the download. If the request was successful the download is in a// paused state. Otherwise $(ref:runtime.lastError) contains an error message.// The request will fail if the download is not active.// |downloadId|: The id of the download to pause.// |callback|: Called when the pause request is completed.[supportsPromises] static void pause(long downloadId,optional NullCallback callback);// Resume a paused download. If the request was successful the download is// in progress and unpaused. Otherwise $(ref:runtime.lastError) contains an// error message. The request will fail if the download is not active.// |downloadId|: The id of the download to resume.// |callback|: Called when the resume request is completed.[supportsPromises] static void resume(long downloadId,optional NullCallback callback);// Cancel a download. When <code>callback</code> is run, the download is// cancelled, completed, interrupted or doesn't exist anymore.// |downloadId|: The id of the download to cancel.// |callback|: Called when the cancel request is completed.[supportsPromises] static void cancel(long downloadId,optional NullCallback callback);// Retrieve an icon for the specified download. For new downloads, file// icons are available after the $(ref:onCreated) event has been received. The// image returned by this function while a download is in progress may be// different from the image returned after the download is complete. Icon// retrieval is done by querying the underlying operating system or toolkit// depending on the platform. The icon that is returned will therefore// depend on a number of factors including state of the download, platform,// registered file types and visual theme. If a file icon cannot be// determined, $(ref:runtime.lastError) will contain an error message.// |downloadId|: The identifier for the download.// |callback|: A URL to an image that represents the download.[supportsPromises] static void getFileIcon(long downloadId,optional GetFileIconOptions options,GetFileIconCallback callback);// Open the downloaded file now if the $(ref:DownloadItem) is complete;// otherwise returns an error through $(ref:runtime.lastError). Requires the// <code>"downloads.open"</code> permission in addition to the// <code>"downloads"</code> permission. An $(ref:onChanged) event will fire// when the item is opened for the first time.// |downloadId|: The identifier for the downloaded file.static void open(long downloadId);// Show the downloaded file in its folder in a file manager.// |downloadId|: The identifier for the downloaded file.static void show(long downloadId);// Show the default Downloads folder in a file manager.static void showDefaultFolder();// Erase matching $(ref:DownloadItem) from history without deleting the// downloaded file. An $(ref:onErased) event will fire for each// $(ref:DownloadItem) that matches <code>query</code>, then// <code>callback</code> will be called.[supportsPromises] static void erase(DownloadQuery query,optional EraseCallback callback);// Remove the downloaded file if it exists and the $(ref:DownloadItem) is// complete; otherwise return an error through $(ref:runtime.lastError).[supportsPromises] static void removeFile(long downloadId,optional NullCallback callback);// Prompt the user to accept a dangerous download. Can only be called from a// visible context (tab, window, or page/browser action popup). Does not// automatically accept dangerous downloads. If the download is accepted,// then an $(ref:onChanged) event will fire, otherwise nothing will happen.// When all the data is fetched into a temporary file and either the// download is not dangerous or the danger has been accepted, then the// temporary file is renamed to the target filename, the |state| changes to// 'complete', and $(ref:onChanged) fires.// |downloadId|: The identifier for the $(ref:DownloadItem).// |callback|: Called when the danger prompt dialog closes.[supportsPromises] static void acceptDanger(long downloadId,optional NullCallback callback);// Enable or disable the gray shelf at the bottom of every window associated// with the current browser profile. The shelf will be disabled as long as// at least one extension has disabled it. Enabling the shelf while at least// one other extension has disabled it will return an error through// $(ref:runtime.lastError). Requires the <code>"downloads.shelf"</code>// permission in addition to the <code>"downloads"</code> permission.[deprecated="Use $(ref:setUiOptions) instead."]static void setShelfEnabled(boolean enabled);// Change the download UI of every window associated with the current// browser profile. As long as at least one extension has set// $(ref:UiOptions.enabled) to false, the download UI will be hidden.// Setting $(ref:UiOptions.enabled) to true while at least one other// extension has disabled it will return an error through// $(ref:runtime.lastError). Requires the <code>"downloads.ui"</code>// permission in addition to the <code>"downloads"</code> permission.// |options|: Encapsulate a change to the download UI.// |callback|: Called when the UI update is completed.[supportsPromises] static void setUiOptions(UiOptions options,optional NullCallback callback);};interface Events {// This event fires with the $(ref:DownloadItem) object when a download// begins.static void onCreated(DownloadItem downloadItem);// Fires with the <code>downloadId</code> when a download is erased from// history.// |downloadId|: The <code>id</code> of the $(ref:DownloadItem) that was// erased.static void onErased(long downloadId);// When any of a $(ref:DownloadItem)'s properties except// <code>bytesReceived</code> and <code>estimatedEndTime</code> changes,// this event fires with the <code>downloadId</code> and an object// containing the properties that changed.static void onChanged(DownloadDelta downloadDelta);// During the filename determination process, extensions will be given the// opportunity to override the target $(ref:DownloadItem.filename). Each// extension may not register more than one listener for this event. Each// listener must call <code>suggest</code> exactly once, either// synchronously or asynchronously. If the listener calls// <code>suggest</code> asynchronously, then it must return// <code>true</code>. If the listener neither calls <code>suggest</code>// synchronously nor returns <code>true</code>, then <code>suggest</code>// will be called automatically. The $(ref:DownloadItem) will not complete// until all listeners have called <code>suggest</code>. Listeners may call// <code>suggest</code> without any arguments in order to allow the download// to use <code>downloadItem.filename</code> for its filename, or pass a// <code>suggestion</code> object to <code>suggest</code> in order to// override the target filename. If more than one extension overrides the// filename, then the last extension installed whose listener passes a// <code>suggestion</code> object to <code>suggest</code> wins. In order to// avoid confusion regarding which extension will win, users should not// install extensions that may conflict. If the download is initiated by// $(ref:download) and the target filename is known before the MIME type and// tentative filename have been determined, pass <code>filename</code> to// $(ref:download) instead.[maxListeners=1] static void onDeterminingFilename(DownloadItem downloadItem, SuggestFilenameCallback suggest);};
};
downloads.idl生成的文件
// GENERATED FROM THE API DEFINITION IN
// chrome/common/extensions/api/downloads.idl
// by tools/json_schema_compiler.
out\Debug\gen\chrome\common\extensions\api\downloads.h
out\Debug\gen\chrome\common\extensions\api\downloads.cc
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.// GENERATED FROM THE API DEFINITION IN
// chrome/common/extensions/api/downloads.idl
// by tools/json_schema_compiler.
// DO NOT EDIT.#ifndef CHROME_COMMON_EXTENSIONS_API_DOWNLOADS_H__
#define CHROME_COMMON_EXTENSIONS_API_DOWNLOADS_H__#include <stdint.h>#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>#include "base/values.h"
#include "base/strings/string_piece.h"namespace extensions {
namespace api {
namespace downloads {//
// Types
//struct HeaderNameValuePair {HeaderNameValuePair();~HeaderNameValuePair();HeaderNameValuePair(const HeaderNameValuePair&) = delete;HeaderNameValuePair& operator=(const HeaderNameValuePair&) = delete;HeaderNameValuePair(HeaderNameValuePair&& rhs) noexcept;HeaderNameValuePair& operator=(HeaderNameValuePair&& rhs) noexcept;// Populates a HeaderNameValuePair object from a base::Value& instance.// Returns whether |out| was successfully populated.static bool Populate(const base::Value& value, HeaderNameValuePair& out);// Populates a HeaderNameValuePair object from a Dict& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value::Dict& value, HeaderNameValuePair& out);// Creates a deep copy of HeaderNameValuePair.HeaderNameValuePair Clone() const;// Creates a HeaderNameValuePair object from a base::Value::Dict, or nullopt// on failure.static std::optional<HeaderNameValuePair> FromValue(const base::Value::Dict& value);// Creates a HeaderNameValuePair object from a base::Value, or nullopt on// failure.static std::optional<HeaderNameValuePair> FromValue(const base::Value& value);// Returns a new base::Value::Dict representing the serialized form of// thisHeaderNameValuePair object.base::Value::Dict ToValue() const;// Name of the HTTP header.std::string name;// Value of the HTTP header.std::string value;};// <dl><dt>uniquify</dt> <dd>To avoid duplication, the <code>filename</code>
// is changed to include a counter before the filename extension.</dd>
// <dt>overwrite</dt> <dd>The existing file will be overwritten with the new
// file.</dd> <dt>prompt</dt> <dd>The user will be prompted with a file
// chooser dialog.</dd> </dl>
enum class FilenameConflictAction {kNone = 0,kUniquify,kOverwrite,kPrompt,kMaxValue = kPrompt,
};const char* ToString(FilenameConflictAction as_enum);
FilenameConflictAction ParseFilenameConflictAction(base::StringPiece as_string);
std::u16string GetFilenameConflictActionParseError(base::StringPiece as_string);struct FilenameSuggestion {FilenameSuggestion();~FilenameSuggestion();FilenameSuggestion(const FilenameSuggestion&) = delete;FilenameSuggestion& operator=(const FilenameSuggestion&) = delete;FilenameSuggestion(FilenameSuggestion&& rhs) noexcept;FilenameSuggestion& operator=(FilenameSuggestion&& rhs) noexcept;// Populates a FilenameSuggestion object from a base::Value& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value& value, FilenameSuggestion& out);// Populates a FilenameSuggestion object from a Dict& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value::Dict& value, FilenameSuggestion& out);// Creates a deep copy of FilenameSuggestion.FilenameSuggestion Clone() const;// Creates a FilenameSuggestion object from a base::Value::Dict, or nullopt on// failure.static std::optional<FilenameSuggestion> FromValue(const base::Value::Dict& value);// Creates a FilenameSuggestion object from a base::Value, or nullopt on// failure.static std::optional<FilenameSuggestion> FromValue(const base::Value& value);// Returns a new base::Value::Dict representing the serialized form of// thisFilenameSuggestion object.base::Value::Dict ToValue() const;// The $(ref:DownloadItem)'s new target $(ref:DownloadItem.filename), as a path// relative to the user's default Downloads directory, possibly containing// subdirectories. Absolute paths, empty paths, and paths containing// back-references ".." will be ignored. <code>filename</code> is ignored if// there are any $(ref:onDeterminingFilename) listeners registered by any// extensions.std::string filename;// The action to take if <code>filename</code> already exists.FilenameConflictAction conflict_action;};enum class HttpMethod {kNone = 0,kGet,kPost,kMaxValue = kPost,
};const char* ToString(HttpMethod as_enum);
HttpMethod ParseHttpMethod(base::StringPiece as_string);
std::u16string GetHttpMethodParseError(base::StringPiece as_string);enum class InterruptReason {kNone = 0,kFileFailed,kFileAccessDenied,kFileNoSpace,kFileNameTooLong,kFileTooLarge,kFileVirusInfected,kFileTransientError,kFileBlocked,kFileSecurityCheckFailed,kFileTooShort,kFileHashMismatch,kFileSameAsSource,kNetworkFailed,kNetworkTimeout,kNetworkDisconnected,kNetworkServerDown,kNetworkInvalidRequest,kServerFailed,kServerNoRange,kServerBadContent,kServerUnauthorized,kServerCertProblem,kServerForbidden,kServerUnreachable,kServerContentLengthMismatch,kServerCrossOriginRedirect,kUserCanceled,kUserShutdown,kCrash,kMaxValue = kCrash,
};const char* ToString(InterruptReason as_enum);
InterruptReason ParseInterruptReason(base::StringPiece as_string);
std::u16string GetInterruptReasonParseError(base::StringPiece as_string);struct DownloadOptions {DownloadOptions();~DownloadOptions();DownloadOptions(const DownloadOptions&) = delete;DownloadOptions& operator=(const DownloadOptions&) = delete;DownloadOptions(DownloadOptions&& rhs) noexcept;DownloadOptions& operator=(DownloadOptions&& rhs) noexcept;// Populates a DownloadOptions object from a base::Value& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value& value, DownloadOptions& out);// Populates a DownloadOptions object from a Dict& instance. Returns whether// |out| was successfully populated.static bool Populate(const base::Value::Dict& value, DownloadOptions& out);// Creates a deep copy of DownloadOptions.DownloadOptions Clone() const;// Creates a DownloadOptions object from a base::Value::Dict, or nullopt on// failure.static std::optional<DownloadOptions> FromValue(const base::Value::Dict& value);// Creates a DownloadOptions object from a base::Value, or nullopt on failure.static std::optional<DownloadOptions> FromValue(const base::Value& value);// Returns a new base::Value::Dict representing the serialized form of// thisDownloadOptions object.base::Value::Dict ToValue() const;// The URL to download.std::string url;// A file path relative to the Downloads directory to contain the downloaded// file, possibly containing subdirectories. Absolute paths, empty paths, and// paths containing back-references ".." will cause an error.// $(ref:onDeterminingFilename) allows suggesting a filename after the file's// MIME type and a tentative filename have been determined.std::optional<std::string> filename;// The action to take if <code>filename</code> already exists.FilenameConflictAction conflict_action;// Use a file-chooser to allow the user to select a filename regardless of// whether <code>filename</code> is set or already exists.std::optional<bool> save_as;// The HTTP method to use if the URL uses the HTTP[S] protocol.HttpMethod method;// Extra HTTP headers to send with the request if the URL uses the HTTP[s]// protocol. Each header is represented as a dictionary containing the keys// <code>name</code> and either <code>value</code> or <code>binaryValue</code>,// restricted to those allowed by XMLHttpRequest.std::optional<std::vector<HeaderNameValuePair>> headers;// Post body.std::optional<std::string> body;};// <dl><dt>file</dt> <dd>The download's filename is suspicious.</dd>
// <dt>url</dt> <dd>The download's URL is known to be malicious.</dd>
// <dt>content</dt> <dd>The downloaded file is known to be malicious.</dd>
// <dt>uncommon</dt> <dd>The download's URL is not commonly downloaded and
// could be dangerous.</dd> <dt>host</dt> <dd>The download came from
// a host known to distribute malicious binaries and is likely
// dangerous.</dd> <dt>unwanted</dt> <dd>The download is potentially
// unwanted or unsafe. E.g. it could make changes to browser or computer
// settings.</dd> <dt>safe</dt> <dd>The download presents no known
// danger to the user's computer.</dd> <dt>accepted</dt> <dd>The user
// has accepted the dangerous download.</dd> </dl>
enum class DangerType {kNone = 0,kFile,kUrl,kContent,kUncommon,kHost,kUnwanted,kSafe,kAccepted,kAllowlistedByPolicy,kAsyncScanning,kAsyncLocalPasswordScanning,kPasswordProtected,kBlockedTooLarge,kSensitiveContentWarning,kSensitiveContentBlock,kUnsupportedFileType,kDeepScannedFailed,kDeepScannedSafe,kDeepScannedOpenedDangerous,kPromptForScanning,kPromptForLocalPasswordScanning,kAccountCompromise,kMaxValue = kAccountCompromise,
};const char* ToString(DangerType as_enum);
DangerType ParseDangerType(base::StringPiece as_string);
std::u16string GetDangerTypeParseError(base::StringPiece as_string);// <dl><dt>in_progress</dt> <dd>The download is currently receiving data
// from the server.</dd> <dt>interrupted</dt> <dd>An error broke the
// connection with the file host.</dd> <dt>complete</dt> <dd>The
// download completed successfully.</dd> </dl>
enum class State {kNone = 0,kInProgress,kInterrupted,kComplete,kMaxValue = kComplete,
};const char* ToString(State as_enum);
State ParseState(base::StringPiece as_string);
std::u16string GetStateParseError(base::StringPiece as_string);struct DownloadItem {DownloadItem();~DownloadItem();DownloadItem(const DownloadItem&) = delete;DownloadItem& operator=(const DownloadItem&) = delete;DownloadItem(DownloadItem&& rhs) noexcept;DownloadItem& operator=(DownloadItem&& rhs) noexcept;// Populates a DownloadItem object from a base::Value& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value& value, DownloadItem& out);// Populates a DownloadItem object from a Dict& instance. Returns whether// |out| was successfully populated.static bool Populate(const base::Value::Dict& value, DownloadItem& out);// Creates a deep copy of DownloadItem.DownloadItem Clone() const;// Creates a DownloadItem object from a base::Value::Dict, or nullopt on// failure.static std::optional<DownloadItem> FromValue(const base::Value::Dict& value);// Creates a DownloadItem object from a base::Value, or nullopt on failure.static std::optional<DownloadItem> FromValue(const base::Value& value);// Returns a new base::Value::Dict representing the serialized form of// thisDownloadItem object.base::Value::Dict ToValue() const;// An identifier that is persistent across browser sessions.int id;// The absolute URL that this download initiated from, before any redirects.std::string url;// The absolute URL that this download is being made from, after all redirects.std::string final_url;// Absolute URL.std::string referrer;// Absolute local path.std::string filename;// False if this download is recorded in the history, true if it is not// recorded.bool incognito;// Indication of whether this download is thought to be safe or known to be// suspicious.DangerType danger;// The file's MIME type.std::string mime;// The time when the download began in ISO 8601 format. May be passed directly// to the Date constructor: <code>chrome.downloads.search({},// function(items){items.forEach(function(item){console.log(new// Date(item.startTime))})})</code>std::string start_time;// The time when the download ended in ISO 8601 format. May be passed directly// to the Date constructor: <code>chrome.downloads.search({},// function(items){items.forEach(function(item){if (item.endTime)// console.log(new Date(item.endTime))})})</code>std::optional<std::string> end_time;// Estimated time when the download will complete in ISO 8601 format. May be// passed directly to the Date constructor: <code>chrome.downloads.search({},// function(items){items.forEach(function(item){if (item.estimatedEndTime)// console.log(new Date(item.estimatedEndTime))})})</code>std::optional<std::string> estimated_end_time;// Indicates whether the download is progressing, interrupted, or complete.State state;// True if the download has stopped reading data from the host, but kept the// connection open.bool paused;// True if the download is in progress and paused, or else if it is interrupted// and can be resumed starting from where it was interrupted.bool can_resume;// Why the download was interrupted. Several kinds of HTTP errors may be grouped// under one of the errors beginning with <code>SERVER_</code>. Errors relating// to the network begin with <code>NETWORK_</code>, errors relating to the// process of writing the file to the file system begin with <code>FILE_</code>,// and interruptions initiated by the user begin with <code>USER_</code>.InterruptReason error;// Number of bytes received so far from the host, without considering file// compression.double bytes_received;// Number of bytes in the whole file, without considering file compression, or// -1 if unknown.double total_bytes;// Number of bytes in the whole file post-decompression, or -1 if unknown.double file_size;// Whether the downloaded file still exists. This information may be out of date// because Chrome does not automatically watch for file removal. Call// $(ref:search)() in order to trigger the check for file existence. When the// existence check completes, if the file has been deleted, then an// $(ref:onChanged) event will fire. Note that $(ref:search)() does not wait for// the existence check to finish before returning, so results from// $(ref:search)() may not accurately reflect the file system. Also,// $(ref:search)() may be called as often as necessary, but will not check for// file existence any more frequently than once every 10 seconds.bool exists;// The identifier for the extension that initiated this download if this// download was initiated by an extension. Does not change once it is set.std::optional<std::string> by_extension_id;// The localized name of the extension that initiated this download if this// download was initiated by an extension. May change if the extension changes// its name or if the user changes their locale.std::optional<std::string> by_extension_name;};struct DownloadQuery {DownloadQuery();~DownloadQuery();DownloadQuery(const DownloadQuery&) = delete;DownloadQuery& operator=(const DownloadQuery&) = delete;DownloadQuery(DownloadQuery&& rhs) noexcept;DownloadQuery& operator=(DownloadQuery&& rhs) noexcept;// Populates a DownloadQuery object from a base::Value& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value& value, DownloadQuery& out);// Populates a DownloadQuery object from a Dict& instance. Returns whether// |out| was successfully populated.static bool Populate(const base::Value::Dict& value, DownloadQuery& out);// Creates a deep copy of DownloadQuery.DownloadQuery Clone() const;// Creates a DownloadQuery object from a base::Value::Dict, or nullopt on// failure.static std::optional<DownloadQuery> FromValue(const base::Value::Dict& value);// Creates a DownloadQuery object from a base::Value, or nullopt on failure.static std::optional<DownloadQuery> FromValue(const base::Value& value);// Returns a new base::Value::Dict representing the serialized form of// thisDownloadQuery object.base::Value::Dict ToValue() const;// This array of search terms limits results to $(ref:DownloadItem) whose// <code>filename</code> or <code>url</code> or <code>finalUrl</code> contain// all of the search terms that do not begin with a dash '-' and none of the// search terms that do begin with a dash.std::optional<std::vector<std::string>> query;// Limits results to $(ref:DownloadItem) that started before the given ms since// the epoch.std::optional<std::string> started_before;// Limits results to $(ref:DownloadItem) that started after the given ms since// the epoch.std::optional<std::string> started_after;// Limits results to $(ref:DownloadItem) that ended before the given ms since// the epoch.std::optional<std::string> ended_before;// Limits results to $(ref:DownloadItem) that ended after the given ms since the// epoch.std::optional<std::string> ended_after;// Limits results to $(ref:DownloadItem) whose <code>totalBytes</code> is// greater than the given integer.std::optional<double> total_bytes_greater;// Limits results to $(ref:DownloadItem) whose <code>totalBytes</code> is less// than the given integer.std::optional<double> total_bytes_less;// Limits results to $(ref:DownloadItem) whose <code>filename</code> matches the// given regular expression.std::optional<std::string> filename_regex;// Limits results to $(ref:DownloadItem) whose <code>url</code> matches the// given regular expression.std::optional<std::string> url_regex;// Limits results to $(ref:DownloadItem) whose <code>finalUrl</code> matches the// given regular expression.std::optional<std::string> final_url_regex;// The maximum number of matching $(ref:DownloadItem) returned. Defaults to// 1000. Set to 0 in order to return all matching $(ref:DownloadItem). See// $(ref:search) for how to page through results.std::optional<int> limit;// Set elements of this array to $(ref:DownloadItem) properties in order to sort// search results. For example, setting <code>orderBy=['startTime']</code> sorts// the $(ref:DownloadItem) by their start time in ascending order. To specify// descending order, prefix with a hyphen: '-startTime'.std::optional<std::vector<std::string>> order_by;// The <code>id</code> of the $(ref:DownloadItem) to query.std::optional<int> id;// The absolute URL that this download initiated from, before any redirects.std::optional<std::string> url;// The absolute URL that this download is being made from, after all redirects.std::optional<std::string> final_url;// Absolute local path.std::optional<std::string> filename;// Indication of whether this download is thought to be safe or known to be// suspicious.DangerType danger;// The file's MIME type.std::optional<std::string> mime;// The time when the download began in ISO 8601 format.std::optional<std::string> start_time;// The time when the download ended in ISO 8601 format.std::optional<std::string> end_time;// Indicates whether the download is progressing, interrupted, or complete.State state;// True if the download has stopped reading data from the host, but kept the// connection open.std::optional<bool> paused;// Why a download was interrupted.InterruptReason error;// Number of bytes received so far from the host, without considering file// compression.std::optional<double> bytes_received;// Number of bytes in the whole file, without considering file compression, or// -1 if unknown.std::optional<double> total_bytes;// Number of bytes in the whole file post-decompression, or -1 if unknown.std::optional<double> file_size;// Whether the downloaded file exists;std::optional<bool> exists;};struct StringDelta {StringDelta();~StringDelta();StringDelta(const StringDelta&) = delete;StringDelta& operator=(const StringDelta&) = delete;StringDelta(StringDelta&& rhs) noexcept;StringDelta& operator=(StringDelta&& rhs) noexcept;// Populates a StringDelta object from a base::Value& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value& value, StringDelta& out);// Populates a StringDelta object from a Dict& instance. Returns whether |out|// was successfully populated.static bool Populate(const base::Value::Dict& value, StringDelta& out);// Creates a deep copy of StringDelta.StringDelta Clone() const;// Creates a StringDelta object from a base::Value::Dict, or nullopt on// failure.static std::optional<StringDelta> FromValue(const base::Value::Dict& value);// Creates a StringDelta object from a base::Value, or nullopt on failure.static std::optional<StringDelta> FromValue(const base::Value& value);// Returns a new base::Value::Dict representing the serialized form of// thisStringDelta object.base::Value::Dict ToValue() const;std::optional<std::string> previous;std::optional<std::string> current;};struct DoubleDelta {DoubleDelta();~DoubleDelta();DoubleDelta(const DoubleDelta&) = delete;DoubleDelta& operator=(const DoubleDelta&) = delete;DoubleDelta(DoubleDelta&& rhs) noexcept;DoubleDelta& operator=(DoubleDelta&& rhs) noexcept;// Populates a DoubleDelta object from a base::Value& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value& value, DoubleDelta& out);// Populates a DoubleDelta object from a Dict& instance. Returns whether |out|// was successfully populated.static bool Populate(const base::Value::Dict& value, DoubleDelta& out);// Creates a deep copy of DoubleDelta.DoubleDelta Clone() const;// Creates a DoubleDelta object from a base::Value::Dict, or nullopt on// failure.static std::optional<DoubleDelta> FromValue(const base::Value::Dict& value);// Creates a DoubleDelta object from a base::Value, or nullopt on failure.static std::optional<DoubleDelta> FromValue(const base::Value& value);// Returns a new base::Value::Dict representing the serialized form of// thisDoubleDelta object.base::Value::Dict ToValue() const;std::optional<double> previous;std::optional<double> current;};struct BooleanDelta {BooleanDelta();~BooleanDelta();BooleanDelta(const BooleanDelta&) = delete;BooleanDelta& operator=(const BooleanDelta&) = delete;BooleanDelta(BooleanDelta&& rhs) noexcept;BooleanDelta& operator=(BooleanDelta&& rhs) noexcept;// Populates a BooleanDelta object from a base::Value& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value& value, BooleanDelta& out);// Populates a BooleanDelta object from a Dict& instance. Returns whether// |out| was successfully populated.static bool Populate(const base::Value::Dict& value, BooleanDelta& out);// Creates a deep copy of BooleanDelta.BooleanDelta Clone() const;// Creates a BooleanDelta object from a base::Value::Dict, or nullopt on// failure.static std::optional<BooleanDelta> FromValue(const base::Value::Dict& value);// Creates a BooleanDelta object from a base::Value, or nullopt on failure.static std::optional<BooleanDelta> FromValue(const base::Value& value);// Returns a new base::Value::Dict representing the serialized form of// thisBooleanDelta object.base::Value::Dict ToValue() const;std::optional<bool> previous;std::optional<bool> current;};struct DownloadDelta {DownloadDelta();~DownloadDelta();DownloadDelta(const DownloadDelta&) = delete;DownloadDelta& operator=(const DownloadDelta&) = delete;DownloadDelta(DownloadDelta&& rhs) noexcept;DownloadDelta& operator=(DownloadDelta&& rhs) noexcept;// Populates a DownloadDelta object from a base::Value& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value& value, DownloadDelta& out);// Populates a DownloadDelta object from a Dict& instance. Returns whether// |out| was successfully populated.static bool Populate(const base::Value::Dict& value, DownloadDelta& out);// Creates a deep copy of DownloadDelta.DownloadDelta Clone() const;// Creates a DownloadDelta object from a base::Value::Dict, or nullopt on// failure.static std::optional<DownloadDelta> FromValue(const base::Value::Dict& value);// Creates a DownloadDelta object from a base::Value, or nullopt on failure.static std::optional<DownloadDelta> FromValue(const base::Value& value);// Returns a new base::Value::Dict representing the serialized form of// thisDownloadDelta object.base::Value::Dict ToValue() const;// The <code>id</code> of the $(ref:DownloadItem) that changed.int id;// The change in <code>url</code>, if any.std::optional<StringDelta> url;// The change in <code>finalUrl</code>, if any.std::optional<StringDelta> final_url;// The change in <code>filename</code>, if any.std::optional<StringDelta> filename;// The change in <code>danger</code>, if any.std::optional<StringDelta> danger;// The change in <code>mime</code>, if any.std::optional<StringDelta> mime;// The change in <code>startTime</code>, if any.std::optional<StringDelta> start_time;// The change in <code>endTime</code>, if any.std::optional<StringDelta> end_time;// The change in <code>state</code>, if any.std::optional<StringDelta> state;// The change in <code>canResume</code>, if any.std::optional<BooleanDelta> can_resume;// The change in <code>paused</code>, if any.std::optional<BooleanDelta> paused;// The change in <code>error</code>, if any.std::optional<StringDelta> error;// The change in <code>totalBytes</code>, if any.std::optional<DoubleDelta> total_bytes;// The change in <code>fileSize</code>, if any.std::optional<DoubleDelta> file_size;// The change in <code>exists</code>, if any.std::optional<BooleanDelta> exists;};struct GetFileIconOptions {GetFileIconOptions();~GetFileIconOptions();GetFileIconOptions(const GetFileIconOptions&) = delete;GetFileIconOptions& operator=(const GetFileIconOptions&) = delete;GetFileIconOptions(GetFileIconOptions&& rhs) noexcept;GetFileIconOptions& operator=(GetFileIconOptions&& rhs) noexcept;// Populates a GetFileIconOptions object from a base::Value& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value& value, GetFileIconOptions& out);// Populates a GetFileIconOptions object from a Dict& instance. Returns// whether |out| was successfully populated.static bool Populate(const base::Value::Dict& value, GetFileIconOptions& out);// Creates a deep copy of GetFileIconOptions.GetFileIconOptions Clone() const;// Creates a GetFileIconOptions object from a base::Value::Dict, or nullopt on// failure.static std::optional<GetFileIconOptions> FromValue(const base::Value::Dict& value);// Creates a GetFileIconOptions object from a base::Value, or nullopt on// failure.static std::optional<GetFileIconOptions> FromValue(const base::Value& value);// Returns a new base::Value::Dict representing the serialized form of// thisGetFileIconOptions object.base::Value::Dict ToValue() const;// The size of the returned icon. The icon will be square with dimensions size *// size pixels. The default and largest size for the icon is 32x32 pixels. The// only supported sizes are 16 and 32. It is an error to specify any other size.std::optional<int> size;};struct UiOptions {UiOptions();~UiOptions();UiOptions(const UiOptions&) = delete;UiOptions& operator=(const UiOptions&) = delete;UiOptions(UiOptions&& rhs) noexcept;UiOptions& operator=(UiOptions&& rhs) noexcept;// Populates a UiOptions object from a base::Value& instance. Returns whether// |out| was successfully populated.static bool Populate(const base::Value& value, UiOptions& out);// Populates a UiOptions object from a Dict& instance. Returns whether |out|// was successfully populated.static bool Populate(const base::Value::Dict& value, UiOptions& out);// Creates a deep copy of UiOptions.UiOptions Clone() const;// Creates a UiOptions object from a base::Value::Dict, or nullopt on failure.static std::optional<UiOptions> FromValue(const base::Value::Dict& value);// Creates a UiOptions object from a base::Value, or nullopt on failure.static std::optional<UiOptions> FromValue(const base::Value& value);// Returns a new base::Value::Dict representing the serialized form of// thisUiOptions object.base::Value::Dict ToValue() const;// Enable or disable the download UI.bool enabled;};//
// Functions
//namespace Download {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();// What to download and how.DownloadOptions options;private:Params();
};namespace Results {base::Value::List Create(int download_id);
} // namespace Results} // namespace Downloadnamespace Search {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();DownloadQuery query;private:Params();
};namespace Results {base::Value::List Create(const std::vector<DownloadItem>& results);
} // namespace Results} // namespace Searchnamespace Pause {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();// The id of the download to pause.int download_id;private:Params();
};namespace Results {base::Value::List Create();
} // namespace Results} // namespace Pausenamespace Resume {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();// The id of the download to resume.int download_id;private:Params();
};namespace Results {base::Value::List Create();
} // namespace Results} // namespace Resumenamespace Cancel {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();// The id of the download to cancel.int download_id;private:Params();
};namespace Results {base::Value::List Create();
} // namespace Results} // namespace Cancelnamespace GetFileIcon {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();// The identifier for the download.int download_id;std::optional<GetFileIconOptions> options;private:Params();
};namespace Results {base::Value::List Create(const std::string& icon_url);
} // namespace Results} // namespace GetFileIconnamespace Open {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();// The identifier for the downloaded file.int download_id;private:Params();
};} // namespace Opennamespace Show {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();// The identifier for the downloaded file.int download_id;private:Params();
};} // namespace Shownamespace ShowDefaultFolder {} // namespace ShowDefaultFoldernamespace Erase {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();DownloadQuery query;private:Params();
};namespace Results {base::Value::List Create(const std::vector<int>& erased_ids);
} // namespace Results} // namespace Erasenamespace RemoveFile {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();int download_id;private:Params();
};namespace Results {base::Value::List Create();
} // namespace Results} // namespace RemoveFilenamespace AcceptDanger {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();// The identifier for the $(ref:DownloadItem).int download_id;private:Params();
};namespace Results {base::Value::List Create();
} // namespace Results} // namespace AcceptDangernamespace SetShelfEnabled {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();bool enabled;private:Params();
};} // namespace SetShelfEnablednamespace SetUiOptions {struct Params {static std::optional<Params> Create(const base::Value::List& args);Params(const Params&) = delete;Params& operator=(const Params&) = delete;Params(Params&& rhs) noexcept;Params& operator=(Params&& rhs) noexcept;~Params();// Encapsulate a change to the download UI.UiOptions options;private:Params();
};namespace Results {base::Value::List Create();
} // namespace Results} // namespace SetUiOptions//
// Events
//namespace OnCreated {extern const char kEventName[]; // "downloads.onCreated"base::Value::List Create(const DownloadItem& download_item);
} // namespace OnCreatednamespace OnErased {extern const char kEventName[]; // "downloads.onErased"// The <code>id</code> of the $(ref:DownloadItem) that was erased.
base::Value::List Create(int download_id);
} // namespace OnErasednamespace OnChanged {extern const char kEventName[]; // "downloads.onChanged"base::Value::List Create(const DownloadDelta& download_delta);
} // namespace OnChangednamespace OnDeterminingFilename {extern const char kEventName[]; // "downloads.onDeterminingFilename"base::Value::List Create(const DownloadItem& download_item);
} // namespace OnDeterminingFilename} // namespace downloads
} // namespace api
} // namespace extensions#endif // CHROME_COMMON_EXTENSIONS_API_DOWNLOADS_H__
三、downloads.idl接口对应扩展调用
chrome\browser\extensions\api\downloads\downloads_api.h
chrome\browser\extensions\api\downloads\downloads_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_DOWNLOADS_DOWNLOADS_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_#include <memory>
#include <set>
#include <string>#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "chrome/browser/download/download_danger_prompt.h"
#include "chrome/common/extensions/api/downloads.h"
#include "components/download/content/public/all_download_item_notifier.h"
#include "components/download/public/common/download_path_reservation_tracker.h"
#include "content/public/browser/download_manager.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/warning_set.h"class DownloadFileIconExtractor;
class DownloadOpenPrompt;
class Profile;// Functions in the chrome.downloads namespace facilitate
// controlling downloads from extensions. See the full API doc at
// http://goo.gl/6hO1nnamespace download_extension_errors {// Errors that can be returned through chrome.runtime.lastError.message.
extern const char kEmptyFile[];
extern const char kFileAlreadyDeleted[];
extern const char kFileNotRemoved[];
extern const char kIconNotFound[];
extern const char kInvalidDangerType[];
extern const char kInvalidFilename[];
extern const char kInvalidFilter[];
extern const char kInvalidHeaderName[];
extern const char kInvalidHeaderValue[];
extern const char kInvalidHeaderUnsafe[];
extern const char kInvalidId[];
extern const char kInvalidOrderBy[];
extern const char kInvalidQueryLimit[];
extern const char kInvalidState[];
extern const char kInvalidURL[];
extern const char kInvisibleContext[];
extern const char kNotComplete[];
extern const char kNotDangerous[];
extern const char kNotInProgress[];
extern const char kNotResumable[];
extern const char kOpenPermission[];
extern const char kShelfDisabled[];
extern const char kShelfPermission[];
extern const char kTooManyListeners[];
extern const char kUiDisabled[];
extern const char kUiPermission[];
extern const char kUnexpectedDeterminer[];
extern const char kUserGesture[];} // namespace download_extension_errorsnamespace extensions {class DownloadedByExtension : public base::SupportsUserData::Data {public:static DownloadedByExtension* Get(download::DownloadItem* item);DownloadedByExtension(download::DownloadItem* item,const std::string& id,const std::string& name);DownloadedByExtension(const DownloadedByExtension&) = delete;DownloadedByExtension& operator=(const DownloadedByExtension&) = delete;const std::string& id() const { return id_; }const std::string& name() const { return name_; }private:static const char kKey[];std::string id_;std::string name_;
};class DownloadsDownloadFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.download", DOWNLOADS_DOWNLOAD)DownloadsDownloadFunction();DownloadsDownloadFunction(const DownloadsDownloadFunction&) = delete;DownloadsDownloadFunction& operator=(const DownloadsDownloadFunction&) =delete;ResponseAction Run() override;protected:~DownloadsDownloadFunction() override;private:void OnStarted(const base::FilePath& creator_suggested_filename,extensions::api::downloads::FilenameConflictActioncreator_conflict_action,download::DownloadItem* item,download::DownloadInterruptReason interrupt_reason);
};class DownloadsSearchFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.search", DOWNLOADS_SEARCH)DownloadsSearchFunction();DownloadsSearchFunction(const DownloadsSearchFunction&) = delete;DownloadsSearchFunction& operator=(const DownloadsSearchFunction&) = delete;ResponseAction Run() override;protected:~DownloadsSearchFunction() override;
};class DownloadsPauseFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.pause", DOWNLOADS_PAUSE)DownloadsPauseFunction();DownloadsPauseFunction(const DownloadsPauseFunction&) = delete;DownloadsPauseFunction& operator=(const DownloadsPauseFunction&) = delete;ResponseAction Run() override;protected:~DownloadsPauseFunction() override;
};class DownloadsResumeFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.resume", DOWNLOADS_RESUME)DownloadsResumeFunction();DownloadsResumeFunction(const DownloadsResumeFunction&) = delete;DownloadsResumeFunction& operator=(const DownloadsResumeFunction&) = delete;ResponseAction Run() override;protected:~DownloadsResumeFunction() override;
};class DownloadsCancelFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.cancel", DOWNLOADS_CANCEL)DownloadsCancelFunction();DownloadsCancelFunction(const DownloadsCancelFunction&) = delete;DownloadsCancelFunction& operator=(const DownloadsCancelFunction&) = delete;ResponseAction Run() override;protected:~DownloadsCancelFunction() override;
};class DownloadsEraseFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.erase", DOWNLOADS_ERASE)DownloadsEraseFunction();DownloadsEraseFunction(const DownloadsEraseFunction&) = delete;DownloadsEraseFunction& operator=(const DownloadsEraseFunction&) = delete;ResponseAction Run() override;protected:~DownloadsEraseFunction() override;
};class DownloadsRemoveFileFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.removeFile", DOWNLOADS_REMOVEFILE)DownloadsRemoveFileFunction();DownloadsRemoveFileFunction(const DownloadsRemoveFileFunction&) = delete;DownloadsRemoveFileFunction& operator=(const DownloadsRemoveFileFunction&) =delete;ResponseAction Run() override;protected:~DownloadsRemoveFileFunction() override;private:void Done(bool success);
};class DownloadsAcceptDangerFunction : public ExtensionFunction {public:using OnPromptCreatedCallback =base::OnceCallback<void(DownloadDangerPrompt*)>;static void OnPromptCreatedForTesting(OnPromptCreatedCallback* callback) {on_prompt_created_ = callback;}DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER)DownloadsAcceptDangerFunction();DownloadsAcceptDangerFunction(const DownloadsAcceptDangerFunction&) = delete;DownloadsAcceptDangerFunction& operator=(const DownloadsAcceptDangerFunction&) = delete;ResponseAction Run() override;protected:~DownloadsAcceptDangerFunction() override;void DangerPromptCallback(int download_id,DownloadDangerPrompt::Action action);private:void PromptOrWait(int download_id, int retries);static OnPromptCreatedCallback* on_prompt_created_;
};class DownloadsShowFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.show", DOWNLOADS_SHOW)DownloadsShowFunction();DownloadsShowFunction(const DownloadsShowFunction&) = delete;DownloadsShowFunction& operator=(const DownloadsShowFunction&) = delete;ResponseAction Run() override;protected:~DownloadsShowFunction() override;
};class DownloadsShowDefaultFolderFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.showDefaultFolder", DOWNLOADS_SHOWDEFAULTFOLDER)DownloadsShowDefaultFolderFunction();DownloadsShowDefaultFolderFunction(const DownloadsShowDefaultFolderFunction&) = delete;DownloadsShowDefaultFolderFunction& operator=(const DownloadsShowDefaultFolderFunction&) = delete;ResponseAction Run() override;protected:~DownloadsShowDefaultFolderFunction() override;
};class DownloadsOpenFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.open", DOWNLOADS_OPEN)DownloadsOpenFunction();DownloadsOpenFunction(const DownloadsOpenFunction&) = delete;DownloadsOpenFunction& operator=(const DownloadsOpenFunction&) = delete;ResponseAction Run() override;using OnPromptCreatedCallback = base::OnceCallback<void(DownloadOpenPrompt*)>;static void set_on_prompt_created_cb_for_testing(OnPromptCreatedCallback* on_prompt_created_cb) {on_prompt_created_cb_ = on_prompt_created_cb;}protected:~DownloadsOpenFunction() override;private:void OpenPromptDone(int download_id, bool accept);static OnPromptCreatedCallback* on_prompt_created_cb_;
};class DownloadsSetShelfEnabledFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.setShelfEnabled",DOWNLOADS_SETSHELFENABLED)DownloadsSetShelfEnabledFunction();DownloadsSetShelfEnabledFunction(const DownloadsSetShelfEnabledFunction&) =delete;DownloadsSetShelfEnabledFunction& operator=(const DownloadsSetShelfEnabledFunction&) = delete;ResponseAction Run() override;protected:~DownloadsSetShelfEnabledFunction() override;
};class DownloadsSetUiOptionsFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.setUiOptions", DOWNLOADS_SETUIOPTIONS)DownloadsSetUiOptionsFunction();DownloadsSetUiOptionsFunction(const DownloadsSetUiOptionsFunction&) = delete;DownloadsSetUiOptionsFunction& operator=(const DownloadsSetUiOptionsFunction&) = delete;ResponseAction Run() override;protected:~DownloadsSetUiOptionsFunction() override;
};class DownloadsGetFileIconFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("downloads.getFileIcon", DOWNLOADS_GETFILEICON)DownloadsGetFileIconFunction();DownloadsGetFileIconFunction(const DownloadsGetFileIconFunction&) = delete;DownloadsGetFileIconFunction& operator=(const DownloadsGetFileIconFunction&) =delete;ResponseAction Run() override;void SetIconExtractorForTesting(DownloadFileIconExtractor* extractor);protected:~DownloadsGetFileIconFunction() override;private:void OnIconURLExtracted(const std::string& url);base::FilePath path_;std::unique_ptr<DownloadFileIconExtractor> icon_extractor_;
};// Observes a single DownloadManager and many DownloadItems and dispatches
// onCreated and onErased events.
class ExtensionDownloadsEventRouter: public extensions::EventRouter::Observer,public extensions::ExtensionRegistryObserver,public download::AllDownloadItemNotifier::Observer {public:typedef base::OnceCallback<void(const base::FilePath& changed_filename,download::DownloadPathReservationTracker::FilenameConflictAction)>FilenameChangedCallback;static void SetDetermineFilenameTimeoutSecondsForTesting(int s);// The logic for how to handle conflicting filename suggestions from multiple// extensions is split out here for testing.static void DetermineFilenameInternal(const base::FilePath& filename,extensions::api::downloads::FilenameConflictAction conflict_action,const std::string& suggesting_extension_id,const base::Time& suggesting_install_time,const std::string& incumbent_extension_id,const base::Time& incumbent_install_time,std::string* winner_extension_id,base::FilePath* determined_filename,extensions::api::downloads::FilenameConflictAction*determined_conflict_action,extensions::WarningSet* warnings);// A downloads.onDeterminingFilename listener has returned. If the extension// wishes to override the download's filename, then |filename| will be// non-empty. |filename| will be interpreted as a relative path, appended to// the default downloads directory. If the extension wishes to overwrite any// existing files, then |overwrite| will be true. Returns true on success,// false otherwise.static bool DetermineFilename(content::BrowserContext* browser_context,bool include_incognito,const std::string& ext_id,int download_id,const base::FilePath& filename,extensions::api::downloads::FilenameConflictAction conflict_action,std::string* error);explicit ExtensionDownloadsEventRouter(Profile* profile, content::DownloadManager* manager);ExtensionDownloadsEventRouter(const ExtensionDownloadsEventRouter&) = delete;ExtensionDownloadsEventRouter& operator=(const ExtensionDownloadsEventRouter&) = delete;~ExtensionDownloadsEventRouter() override;void SetUiEnabled(const extensions::Extension* extension, bool enabled);bool IsUiEnabled() const;// Called by ChromeDownloadManagerDelegate during the filename determination// process, allows extensions to change the item's target filename. If no// extension wants to change the target filename, then |filename_changed| will// be called with an empty filename and the filename determination process// will continue as normal. If an extension wants to change the target// filename, then |filename_changed| will be called with the new filename and// a flag indicating whether the new file should overwrite any old files of// the same name.void OnDeterminingFilename(download::DownloadItem* item,const base::FilePath& suggested_path,FilenameChangedCallback filename_changed);// AllDownloadItemNotifier::Observer.void OnDownloadCreated(content::DownloadManager* manager,download::DownloadItem* download_item) override;void OnDownloadUpdated(content::DownloadManager* manager,download::DownloadItem* download_item) override;void OnDownloadRemoved(content::DownloadManager* manager,download::DownloadItem* download_item) override;// extensions::EventRouter::Observer.void OnListenerRemoved(const extensions::EventListenerInfo& details) override;void CheckForHistoryFilesRemoval();private:void DispatchEvent(events::HistogramValue histogram_value,const std::string& event_name,bool include_incognito,Event::WillDispatchCallback will_dispatch_callback,base::Value json_arg);// extensions::ExtensionRegistryObserver.void OnExtensionUnloaded(content::BrowserContext* browser_context,const extensions::Extension* extension,extensions::UnloadedExtensionReason reason) override;raw_ptr<Profile> profile_;download::AllDownloadItemNotifier notifier_;std::set<const extensions::Extension*> ui_disabling_extensions_;base::Time last_checked_removal_;// Listen to extension unloaded notifications.base::ScopedObservation<extensions::ExtensionRegistry,extensions::ExtensionRegistryObserver>extension_registry_observation_{this};
};} // namespace extensions#endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_
四、最后读者可以加载examples/api/downloads
扩展在chrome\browser\extensions\api\downloads\downloads_api.cc 打断点看下调用堆栈 。
相关文章:

Chromium 中chrome.downloads扩展接口c++
一、前端chrome.downloads 使用 chrome.downloads API 以编程方式启动、监控、操作和搜索下载内容。 权限 downloads 您必须在扩展程序清单中声明 "downloads" 权限,才能使用此 API。 {"name": "My extension",..."permiss…...

微信小程序常见问题
一、编译报错 [ app.json 文件内容错误] app.json: 在项目根目录未找到 app.json 解决办法: 微信开发者工具中打开设置->安全设置->打开服务端口用HBuilder X打开小程序文件夹,点击“运行到小程序模拟器”,生成配置文件,…...

进程的理解
进程的理解 目录: 什么是进程主要特征主要组成部分进程状态进程优先级 1.什么是进程 概念: 在操作系统中,**进程(Process)**是一个正在执行的程序实例。可以将进程理解为一个动态的实体,它不仅包括静态…...

LeetCode494:目标和
题目链接:494. 目标和 - 力扣(LeetCode) 代码如下 class Solution { public:int findTargetSumWays(vector<int>& nums, int target) {int sum 0;for(int i 0; i < nums.size(); i){sum nums[i];}if(abs(target) > sum)…...

vue3中自定义校验函数密码不生效问题
vue3中自定义校验函数密码不生效问题 由于在自定义的校验规则中只校验了有数据的情况,以至于在没输入时,校验不生效 (1)用户不输入校验不生效 const validateSurePassword (rule, value, callback) > {if (value ! ) {if (…...

RabbitMQ(死信队列)
一、本文抒写背景 前面我也在延迟队列篇章提到过死信队列,也提到过一些应用场景! 今天呢,这篇文章,主要就是实战一个业务场景的小Demo流程,哈哈,那就是延迟关闭订单。 二、开始啦!letgo! 首…...

HTTP代理的优点和局限性
在这个信息爆炸的时代,网络已成为我们获取知识、交流思想、开展商务的重要平台。但随之而来的隐私泄露、网络安全威胁、以及无处不在的网络监控,却让我们的每一次在线活动都充满了风险。 在这样的背景下,HTTP代理技术应运而生,它不…...

大厂面试真题-如果通过JVM自带的工具排查和解决线上CPU100%的问题
通过JVM自带的工具去定位和解决线上CPU 100%的问题,可以遵循以下步骤: 一、使用top和jps定位Java进程 使用top命令: 在Linux服务器上执行top命令,查看所有进程的CPU使用情况。找到CPU使用率最高的进程,并记录其PID&a…...

kubernetes中微服务部署
微服务 问:用控制器来完成集群的工作负载,那么应用如何暴漏出去? 答:需要通过微服务暴漏出去后才能被访问 Service 是一组提供相同服务的Pod对外开放的接口借助Service,应用可以实现服务发现和负载均衡Service 默认只…...

基于 Java 的天气预报系统设计与实现
随着互联网的飞速发展,天气预报系统变得越来越重要。它可以帮助用户了解未来几天的天气情况,便于出行、活动安排。本文将介绍如何使用 Java 构建一个简单的天气预报系统,涉及系统架构设计、核心功能开发以及完整的代码实现。 1. 系统架构设计…...

思迅商云8前台打开提示上传日志信息失败
请按照以下步骤核实处理: 1、重启sql服务后测试。 2、请先备份前台安装目录,之后删除安装目录下的log文件和localdate下的log文件,之后重新打开软件,若依旧不行则说明前台文件有损坏,需要重新安装客户端,…...

webstorm的缩进设置(过度缩进解释)
在编写前端代码时 缩进规范一般被认为是2个空格 而非默认的4个空格 当我们通过webstorm去编写前端代码时 我们可以通过setting->Code Style->html/css/js指定的界面中去设置tab/indent/continuation indent 具体的话 我们将html/css/js操作界面中的tab/indent设置为2个空…...

与ZoomEye功能类似的搜索引擎还有哪些?(渗透课作业)
与ZoomEye功能类似的搜索引擎有: Shodan:被誉为“物联网的搜索引擎”,专注于扫描和索引连接到互联网的各种设备,如智能家居设备、工业控制系统、摄像头、数据库等。它提供全球互联网设备的可视化视图,帮助用户了解网络…...

Java 计数排序
计数排序(Counting Sort)是一种非比较型排序算法,适用于一定范围内的整数排序。它的基本思想是通过计数输入元素中每个值出现的次数,然后计算每个值的起始位置,最终将元素放到正确的位置上。计数排序的时间复杂度为 O(…...

error: RPC failed; curl 16 Error in the HTTP2 framing layer
yschai@LAPTOP-F2L146JK:~$ git clone https://github.com/Chyusen/yschai.git Cloning into ‘yschai’… error: RPC failed; curl 16 Error in the HTTP2 framing layer fatal: expected flush after ref listing 使用Ubuntu在git clone github上的项目的时候,遇到以上报错…...

Python脚本分类和代码举例
Python是一种强大且灵活的编程语言,被广泛应用于数据分析、Web开发、自动化、人工智能等领域。在不同的应用场景下,Python脚本可以被分类为多种类型。本文将深入分析Python脚本的分类,同时提供相关代码示例,帮助读者理解和应用这些…...

【Redis十二】Redis的典型应用(缓存和分布式锁)
目录 Redis作为缓存 1.什么是缓存? 2.缓存的更新策略 3.缓存预热,缓存穿透,缓存雪崩和缓存击穿 Redis作为分布式锁 1.什么是分布式锁? 2.分布式锁的实现过程 Redis是目前后端开发中非常热门的组件之一,本篇文章…...

C++入门基础知识107—【关于C++continue 语句】
成长路上不孤单😊😊😊😊😊😊 【14后😊///C爱好者😊///持续分享所学😊///如有需要欢迎收藏转发///😊】 今日分享关于C continue 语句的相关内容!…...

【AI大模型】《多模态持续学习》最新进展综述
摘要—持续学习(CL)旨在使机器学习模型能够从新数据中不断学习,同时在不遗忘已获得知识的基础上进行扩展。随着机器学习模型从小规模到大规模预训练架构的演变,以及从支持单一模态数据到支持多模态数据,多模态持续学习…...

大厂面试真题-CPU飙升问题怎么定位
CPU使用率飙升是开发者和系统管理员常遇到的问题,定位CPU飙升问题通常涉及以下步骤: 一、使用系统监控工具 查看CPU使用图表:利用任务管理器(Windows系统)或top、htop(Linux系统)等工具&#…...

【每日刷题】Day137
【每日刷题】Day137 🥕个人主页:开敲🍉 🔥所属专栏:每日刷题🍍 🌼文章目录🌼 1. 1576. 替换所有的问号 - 力扣(LeetCode) 2. 495. 提莫攻击 - 力扣…...

24.4 基于consul服务发现模式
本节重点介绍 : consul 安装consul go代码注册服务,注销服务,获取服务node_exporter改造为consul服务发现在数量比较大时,在注册服务的时候,关闭check,可以降低consul的压力 consul 安装 准备工作 # 下载consul wge…...

[红队apt]快捷方式病毒攻击流程
免责声明:本文整理攻击者操作,帮助了解攻击原理,提高防范能力 前言 欢迎来到我的博客 个人主页:北岭敲键盘的荒漠猫-CSDN博客 本文整理攻击者是如何用快捷方式进行攻击的流程 快捷方式攻击原理 快捷方式可以指向执行某个程序。 我们利用快捷方式攻击的…...

一个架构师的职业素养:四种常用的权限模型
你好,我是看山。 本文收录在《一个架构师的职业素养》专栏。日拱一卒,功不唐捐。 今天咱们一起聊聊权限系统。 以大家熟知的电商场景举例: 用户可以分为普通用户、VIP用户:我们需要控制不同角色用户的访问范围。比如,京东的PLUS会员,可以进入会员专区,而且能够使用礼金…...

说起来很简单,做起来很复杂:解密Chat GPT背后的原理与技术
你或许已经体验过ChatGPT,它能快速回答各种问题,生成文案、编写代码,甚至陪你聊些有趣的话题。看似简单易用,背后却隐藏着强大的技术支持。 输入几句话,ChatGPT仿佛“理解”了你的问题,立即给出准确的回答…...

tcpdump-arm平台移植
准备工作 下载并解压 972 mkdir tcpdump973 cd tcpdump/974 ls975 wget https://www.tcpdump.org/release/tcpdump-4.99.5.tar.xz976 wget https://www.tcpdump.org/release/libpcap-1.10.5.tar.xz977 tar -xvf libpcap-1.10.5.tar.xz978...

LabVIEW中的非阻塞定时器
在LabVIEW编程中,通常需要在某些任务执行过程中进行非阻塞的延时操作。例如,显示某条信息一段时间,同时继续执行其他任务,并在延时时间结束后停止显示该信息。这类需求通常用于处理优先级不同的信息显示,如错误信息需要…...

MIDIPLUS 50周年丨中国国际乐器展览会首日盛况
10月10日,由中国乐器协会、上海国展展览中心有限公司、法兰克福展览(上海)有限公司共同主办的中国(上海)国际乐器展览会在上海新国际博览中心(上海市浦东新区龙阳路2345号)盛大开幕。 2024上海…...

基于springboot的家政服务管理系统(含源码+sql+视频导入教程+文档+PPT)
👉文末查看项目功能视频演示获取源码sql脚本视频导入教程视频 1 、功能描述 基于springboot的家政服务管理系统1拥有三种角色 管理员:用户管理、服务管理、评价管理、预约管理、分配管理等 用户:登录注册、预约服务、取消服务、评价等 服…...

第十四届单片机嵌入式蓝桥杯
一、CubeMx配置 (1)LED配置 (1)LED灯里面用到了SN74HC573ADWR锁存器,这个锁存器有一个LE引脚,这个是我们芯片的锁存引脚(使能引脚),由PD2这个端口来控制的 (2ÿ…...