Documentation
¶
Overview ¶
Package nativehost implements the native messaging host protocol for browser extensions. It provides stdin/stdout communication using Chrome/Firefox native messaging format: 4-byte little-endian length prefix followed by JSON payload.
Index ¶
- Constants
- func GenerateChromeManifest(hostPath, extensionID string) []byte
- func GenerateFirefoxManifest(hostPath, extensionID string) []byte
- func HasOfficialExtensions() bool
- func MakeErrorResponse(id int, err error) []byte
- func MakeSuccessResponse(id int, result any) []byte
- func ReadMessage(r io.Reader) ([]byte, error)
- func UninstallManifest(path string) error
- func WriteMessage(w io.Writer, msg []byte) error
- type Browser
- type ChromeManifest
- type Client
- type DownloadOptions
- type DownloadParams
- type FirefoxManifest
- type FlushParams
- type Host
- type ListOptions
- type ListParams
- type ManifestInstaller
- type Request
- type Response
- type ResumeOptions
- type ResumeParams
- type StopParams
Constants ¶
const HostName = "com.warpdl.host"
HostName is the native messaging host identifier. This must match the "name" field in the manifest and be used by browser extensions.
const MaxMessageSize = common.MaxMessageSize
MaxMessageSize limits native messaging payloads. Browser native messaging has a 1MB limit, but we use common.MaxMessageSize for consistency.
const OfficialChromeExtensionID = ""
OfficialChromeExtensionID is the official Chrome extension ID for WarpDL. This will be populated once the browser extension is published to the Chrome Web Store.
const OfficialFirefoxExtensionID = ""
OfficialFirefoxExtensionID is the official Firefox extension ID for WarpDL. This will be populated once the browser extension is published to Firefox Add-ons.
Variables ¶
This section is empty.
Functions ¶
func GenerateChromeManifest ¶
GenerateChromeManifest creates a Chrome/Chromium native messaging manifest.
func GenerateFirefoxManifest ¶
GenerateFirefoxManifest creates a Firefox native messaging manifest.
func HasOfficialExtensions ¶ added in v1.3.28
func HasOfficialExtensions() bool
HasOfficialExtensions returns true if at least one official extension ID is configured. Package manager hooks use this to determine if native host installation should proceed.
func MakeErrorResponse ¶
MakeErrorResponse creates a JSON-encoded error response.
func MakeSuccessResponse ¶
MakeSuccessResponse creates a JSON-encoded success response.
func ReadMessage ¶
ReadMessage reads a native messaging format message from the reader. Format: 4-byte little-endian length prefix followed by the message bytes.
func UninstallManifest ¶
UninstallManifest removes a manifest file.
Types ¶
type Browser ¶
type Browser string
Browser represents a supported browser for native messaging.
func SupportedBrowsers ¶
func SupportedBrowsers() []Browser
SupportedBrowsers returns all browsers that support native messaging.
type ChromeManifest ¶
type ChromeManifest struct {
Name string `json:"name"`
Description string `json:"description"`
Path string `json:"path"`
Type string `json:"type"`
AllowedOrigins []string `json:"allowed_origins"`
}
ChromeManifest represents Chrome/Chromium native messaging host manifest.
type Client ¶
type Client interface {
Download(url, fileName, downloadDirectory string, opts *DownloadOptions) (*common.DownloadResponse, error)
List(opts *ListOptions) (*common.ListResponse, error)
GetDaemonVersion() (*common.VersionResponse, error)
StopDownload(downloadId string) (bool, error)
Resume(downloadId string, opts *ResumeOptions) (*common.ResumeResponse, error)
Flush(downloadId string) (bool, error)
Close() error
}
Client interface defines the daemon client methods used by the native host. This allows mocking for tests and decouples from the concrete warpcli.Client.
type DownloadOptions ¶
type DownloadOptions struct {
Headers map[string]string `json:"headers,omitempty"`
ForceParts bool `json:"force_parts,omitempty"`
MaxConnections int32 `json:"max_connections,omitempty"`
MaxSegments int32 `json:"max_segments,omitempty"`
Overwrite bool `json:"overwrite,omitempty"`
Proxy string `json:"proxy,omitempty"`
Timeout int `json:"timeout,omitempty"`
SpeedLimit string `json:"speed_limit,omitempty"`
}
DownloadOptions mirrors warpcli.DownloadOpts
type DownloadParams ¶
type DownloadParams struct {
URL string `json:"url"`
FileName string `json:"fileName"`
DownloadDirectory string `json:"downloadDirectory"`
Headers map[string]string `json:"headers,omitempty"`
ForceParts bool `json:"forceParts,omitempty"`
MaxConnections int32 `json:"maxConnections,omitempty"`
MaxSegments int32 `json:"maxSegments,omitempty"`
Overwrite bool `json:"overwrite,omitempty"`
Proxy string `json:"proxy,omitempty"`
Timeout int `json:"timeout,omitempty"`
SpeedLimit string `json:"speedLimit,omitempty"`
}
DownloadParams represents parameters for a download request.
type FirefoxManifest ¶
type FirefoxManifest struct {
Name string `json:"name"`
Description string `json:"description"`
Path string `json:"path"`
Type string `json:"type"`
AllowedExtensions []string `json:"allowed_extensions"`
}
FirefoxManifest represents Firefox native messaging host manifest.
type FlushParams ¶
type FlushParams struct {
DownloadID string `json:"downloadId"`
}
FlushParams represents parameters for a flush request.
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host is the native messaging host that bridges browser extensions to the daemon.
type ListOptions ¶
type ListOptions struct {
IncludeHidden bool `json:"include_hidden,omitempty"`
IncludeMetadata bool `json:"include_metadata,omitempty"`
}
ListOptions mirrors warpcli.ListOpts
type ListParams ¶
type ListParams struct {
IncludeHidden bool `json:"includeHidden,omitempty"`
IncludeMetadata bool `json:"includeMetadata,omitempty"`
}
ListParams represents parameters for a list request.
type ManifestInstaller ¶
type ManifestInstaller struct {
HostPath string
ChromeExtensionID string
FirefoxExtensionID string
BaseDir string // Override for testing; empty uses real home dir
}
ManifestInstaller handles installation and removal of native messaging manifests.
func (*ManifestInstaller) InstallChrome ¶
func (m *ManifestInstaller) InstallChrome(browser Browser) (string, error)
InstallChrome installs a manifest for Chrome-based browsers.
func (*ManifestInstaller) InstallFirefox ¶
func (m *ManifestInstaller) InstallFirefox() (string, error)
InstallFirefox installs a manifest for Firefox.
func (*ManifestInstaller) Validate ¶
func (m *ManifestInstaller) Validate() error
Validate checks that all required fields are set.
type Request ¶
type Request struct {
ID int `json:"id"`
Method string `json:"method"`
Message json.RawMessage `json:"message,omitempty"`
}
Request represents an incoming native messaging request from a browser extension. It includes an ID for request-response correlation, which the daemon protocol lacks.
func ParseRequest ¶
ParseRequest parses a JSON byte slice into a Request struct.
type Response ¶
type Response struct {
ID int `json:"id"`
Ok bool `json:"ok"`
Error string `json:"error,omitempty"`
Result any `json:"result,omitempty"`
}
Response represents a native messaging response sent back to the browser extension.
type ResumeOptions ¶
type ResumeOptions struct {
Headers map[string]string `json:"headers,omitempty"`
ForceParts bool `json:"force_parts,omitempty"`
MaxConnections int32 `json:"max_connections,omitempty"`
MaxSegments int32 `json:"max_segments,omitempty"`
Proxy string `json:"proxy,omitempty"`
Timeout int `json:"timeout,omitempty"`
SpeedLimit string `json:"speed_limit,omitempty"`
}
ResumeOptions mirrors warpcli.ResumeOpts
type ResumeParams ¶
type ResumeParams struct {
DownloadID string `json:"downloadId"`
Headers map[string]string `json:"headers,omitempty"`
ForceParts bool `json:"forceParts,omitempty"`
MaxConnections int32 `json:"maxConnections,omitempty"`
MaxSegments int32 `json:"maxSegments,omitempty"`
Proxy string `json:"proxy,omitempty"`
Timeout int `json:"timeout,omitempty"`
SpeedLimit string `json:"speedLimit,omitempty"`
}
ResumeParams represents parameters for a resume request.
type StopParams ¶
type StopParams struct {
DownloadID string `json:"downloadId"`
}
StopParams represents parameters for a stop request.