Implement protocol.isHandledProtocol
This commit is contained in:
parent
05fd81ebdc
commit
374d83ed9c
2 changed files with 22 additions and 2 deletions
|
@ -56,7 +56,8 @@ mate::ObjectTemplateBuilder Protocol::GetObjectTemplateBuilder(
|
||||||
&Protocol::RegisterProtocol<UrlRequestAsyncAsarJob>)
|
&Protocol::RegisterProtocol<UrlRequestAsyncAsarJob>)
|
||||||
.SetMethod("registerHttpProtocol",
|
.SetMethod("registerHttpProtocol",
|
||||||
&Protocol::RegisterProtocol<URLRequestFetchJob>)
|
&Protocol::RegisterProtocol<URLRequestFetchJob>)
|
||||||
.SetMethod("unregisterProtocol", &Protocol::UnregisterProtocol);
|
.SetMethod("unregisterProtocol", &Protocol::UnregisterProtocol)
|
||||||
|
.SetMethod("isHandledProtocol", &Protocol::IsHandledProtocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Protocol::RegisterStandardSchemes(
|
void Protocol::RegisterStandardSchemes(
|
||||||
|
@ -84,6 +85,19 @@ Protocol::ProtocolError Protocol::UnregisterProtocolInIO(
|
||||||
return PROTOCOL_OK;
|
return PROTOCOL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Protocol::IsHandledProtocol(const std::string& scheme,
|
||||||
|
const BooleanCallback& callback) {
|
||||||
|
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||||
|
content::BrowserThread::IO, FROM_HERE,
|
||||||
|
base::Bind(&Protocol::IsHandledProtocolInIO,
|
||||||
|
base::Unretained(this), scheme),
|
||||||
|
callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Protocol::IsHandledProtocolInIO(const std::string& scheme) {
|
||||||
|
return job_factory_->IsHandledProtocol(scheme);
|
||||||
|
}
|
||||||
|
|
||||||
void Protocol::OnIOCompleted(
|
void Protocol::OnIOCompleted(
|
||||||
const CompletionCallback& callback, ProtocolError error) {
|
const CompletionCallback& callback, ProtocolError error) {
|
||||||
// The completion callback is optional.
|
// The completion callback is optional.
|
||||||
|
|
|
@ -34,6 +34,7 @@ class Protocol : public mate::Wrappable {
|
||||||
using Handler =
|
using Handler =
|
||||||
base::Callback<void(const net::URLRequest*, v8::Local<v8::Value>)>;
|
base::Callback<void(const net::URLRequest*, v8::Local<v8::Value>)>;
|
||||||
using CompletionCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
using CompletionCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
||||||
|
using BooleanCallback = base::Callback<void(bool)>;
|
||||||
|
|
||||||
static mate::Handle<Protocol> Create(
|
static mate::Handle<Protocol> Create(
|
||||||
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||||
|
@ -118,10 +119,15 @@ class Protocol : public mate::Wrappable {
|
||||||
return PROTOCOL_FAIL;
|
return PROTOCOL_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unregistered the protocol handler that handles |scheme|.
|
// Unregister the protocol handler that handles |scheme|.
|
||||||
void UnregisterProtocol(const std::string& scheme, mate::Arguments* args);
|
void UnregisterProtocol(const std::string& scheme, mate::Arguments* args);
|
||||||
ProtocolError UnregisterProtocolInIO(const std::string& scheme);
|
ProtocolError UnregisterProtocolInIO(const std::string& scheme);
|
||||||
|
|
||||||
|
// Whether the protocol has handler registered.
|
||||||
|
void IsHandledProtocol(const std::string& scheme,
|
||||||
|
const BooleanCallback& callback);
|
||||||
|
bool IsHandledProtocolInIO(const std::string& scheme);
|
||||||
|
|
||||||
// Convert error code to JS exception and call the callback.
|
// Convert error code to JS exception and call the callback.
|
||||||
void OnIOCompleted(const CompletionCallback& callback, ProtocolError error);
|
void OnIOCompleted(const CompletionCallback& callback, ProtocolError error);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue