diff --git a/atom/browser/api/atom_api_protocol.cc b/atom/browser/api/atom_api_protocol.cc index 7571ee0e8377..9170f16b482c 100644 --- a/atom/browser/api/atom_api_protocol.cc +++ b/atom/browser/api/atom_api_protocol.cc @@ -56,7 +56,8 @@ mate::ObjectTemplateBuilder Protocol::GetObjectTemplateBuilder( &Protocol::RegisterProtocol) .SetMethod("registerHttpProtocol", &Protocol::RegisterProtocol) - .SetMethod("unregisterProtocol", &Protocol::UnregisterProtocol); + .SetMethod("unregisterProtocol", &Protocol::UnregisterProtocol) + .SetMethod("isHandledProtocol", &Protocol::IsHandledProtocol); } void Protocol::RegisterStandardSchemes( @@ -84,6 +85,19 @@ Protocol::ProtocolError Protocol::UnregisterProtocolInIO( 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. diff --git a/atom/browser/api/atom_api_protocol.h b/atom/browser/api/atom_api_protocol.h index c409d34c434d..05e3f6073932 100644 --- a/atom/browser/api/atom_api_protocol.h +++ b/atom/browser/api/atom_api_protocol.h @@ -34,6 +34,7 @@ class Protocol : public mate::Wrappable { using Handler = base::Callback)>; using CompletionCallback = base::Callback)>; + using BooleanCallback = base::Callback; static mate::Handle Create( v8::Isolate* isolate, AtomBrowserContext* browser_context); @@ -118,10 +119,15 @@ class Protocol : public mate::Wrappable { 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);