public final class BrowserContext
extends java.lang.Object
Browser
instance. Provides path to the directory where Chromium data files such as cookies, history, cache will be stored and provides access to context level functionality such as
NetworkService
. Two
Browser
instances with same
BrowserContext
will share session cookies and cache files.
Constructor and Description |
---|
BrowserContext(BrowserContextParams params)
Constructs a new
BrowserContext instance with specified
params .
|
Modifier and Type | Method and Description |
---|---|
static BrowserContext |
defaultContext()
Returns default browser context.
返回默认浏览器上下文。 |
java.lang.String |
getAcceptLanguage()
Returns a string that represents Accept-Language request-header field.
返回一个表示“接受语言”请求标头字段的字符串。 |
AutofillService |
getAutofillService()
Returns
返回与当前上下文关联的AutofillService。 AutofillService associated with the current context.
|
java.lang.String |
getCacheDir()
Returns absolute path to the directory where cache files will be stored.
返回将要存储缓存文件的目录的绝对路径。 |
java.lang.String |
getDataDir()
Returns absolute path to the directory where user data files will be stored.
返回将要存储用户数据文件的目录的绝对路径。 |
int |
getIdentifier()
Returns global unique identifier of the current context.
返回当前上下文的全局唯一标识符。 |
java.lang.String |
getMemoryDir()
Returns absolute path to the directory where shared memory files will be stored.
返回将存储共享内存文件的目录的绝对路径。 |
NetworkService |
getNetworkService()
Returns
返回与当前上下文关联的NetworkService。 NetworkService associated with the current context.
|
NotificationService |
getNotificationService()
Returns
返回与当前上下文关联的NotificationService。 NotificationService associated with the current context.
|
ProtocolService |
getProtocolService()
Returns
返回与当前上下文关联的ProtocolService。 ProtocolService associated with the current context.
|
ProxyConfig |
getProxyConfig()
Returns proxy configuration of the current browser instance or
返回当前浏览器实例的代理配置;如果在浏览器实例实例化期间未提供代理配置,则返回null。 null if no proxy configuration was provided during Browser instance instantiation.
|
ProxyService |
getProxyService()
Returns
返回与当前上下文关联的ProxySerivce。 ProxySerivce associated with the current context.
|
SpellCheckerService |
getSpellCheckerService()
Returns
返回与当前上下文关联的SpellCheckerService。 SpellCheckerService associated with the current context.
|
StorageType |
getStorageType()
Returns Chromium data storage type for the current context provided via the
返回通过BrowserContextParams.setStorageType(StorageType)方法提供的当前上下文的Chromium数据存储类型。 BrowserContextParams.setStorageType(StorageType) method.
|
ZoomService |
getZoomService()
Returns
返回与当前上下文关联的ZoomService。 ZoomService associated with the current context.
|
void |
setAcceptLanguage(java.lang.String acceptLanguage)
Configures the accept language.
配置接受语言。 |
public BrowserContext(BrowserContextParams params)
BrowserContext
instance with specified
params
.
params
- represents parameters for the current context such as absolute path to the directory where user data files will be stored (e.g. history, cookies, cache), proxy settings, etc. Cannot be
null
.
-表示当前上下文的参数,例如将存储用户数据文件的目录的绝对路径(例如历史记录,Cookie,缓存),代理设置等。不能为。
java.lang.IllegalArgumentException
- when
params
is
null
.
public static BrowserContext defaultContext()
public java.lang.String getDataDir()
public java.lang.String getCacheDir()
public java.lang.String getMemoryDir()
public java.lang.String getAcceptLanguage()
"da, en-gb;q=0.8, en;q=0.7"
.
The default Accept-Language is "en-us"
.
public void setAcceptLanguage(java.lang.String acceptLanguage)
en-us
.
For example, fr, en-gb;q=0.8, en;q=0.7
would mean: "I prefer French, but will accept British English and other types of English." Note, that all languages which are assigned a quality factor greater than 0 are acceptable.
acceptLanguage
- a new string that represents the "Accept-Language" HTTP header value.
-代表“ Accept-Language” HTTP标头值的新字符串。
java.lang.IllegalArgumentException
- when
acceptLanguage
is
null
or empty.
public StorageType getStorageType()
BrowserContextParams.setStorageType(StorageType)
method.
public ProxyConfig getProxyConfig()
null
if no proxy configuration was provided during Browser instance instantiation.
public NetworkService getNetworkService()
NetworkService
associated with the current context.
public ZoomService getZoomService()
ZoomService
associated with the current context.
public SpellCheckerService getSpellCheckerService()
SpellCheckerService
associated with the current context.
public AutofillService getAutofillService()
AutofillService
associated with the current context.
public ProtocolService getProtocolService()
ProtocolService
associated with the current context.
public ProxyService getProxyService()
ProxySerivce
associated with the current context.
public int getIdentifier()
public NotificationService getNotificationService()
NotificationService
associated with the current context.