&Protocol::RegisterProtocol<UrlRequestAsyncAsarJob>)
.SetMethod("registerHttpProtocol",
&Protocol::RegisterProtocol<URLRequestFetchJob>)
- .SetMethod("unregisterProtocol", &Protocol::UnregisterProtocol);
+ .SetMethod("unregisterProtocol", &Protocol::UnregisterProtocol)
+ .SetMethod("isHandledProtocol", &Protocol::IsHandledProtocol);
}
void Protocol::RegisterStandardSchemes(
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(
const CompletionCallback& callback, ProtocolError error) {
// The completion callback is optional.
using Handler =
base::Callback<void(const net::URLRequest*, v8::Local<v8::Value>)>;
using CompletionCallback = base::Callback<void(v8::Local<v8::Value>)>;
+ using BooleanCallback = base::Callback<void(bool)>;
static mate::Handle<Protocol> Create(
v8::Isolate* isolate, AtomBrowserContext* browser_context);
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);
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.
void OnIOCompleted(const CompletionCallback& callback, ProtocolError error);