From 741c8f3d983c4625c8b8b6b51b20dfce7768f7b2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 13 Aug 2015 20:19:02 +0800 Subject: [PATCH] Implement protocol.uninterceptProtocol --- atom/browser/api/atom_api_protocol.cc | 24 +++++++++++++++++++++++- atom/browser/api/atom_api_protocol.h | 4 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_protocol.cc b/atom/browser/api/atom_api_protocol.cc index f190bae..e2f5364 100644 --- a/atom/browser/api/atom_api_protocol.cc +++ b/atom/browser/api/atom_api_protocol.cc @@ -65,7 +65,8 @@ mate::ObjectTemplateBuilder Protocol::GetObjectTemplateBuilder( .SetMethod("interceptFileProtocol", &Protocol::InterceptProtocol) .SetMethod("interceptHttpProtocol", - &Protocol::InterceptProtocol); + &Protocol::InterceptProtocol) + .SetMethod("uninterceptProtocol", &Protocol::UninterceptProtocol); } void Protocol::RegisterStandardSchemes( @@ -106,6 +107,27 @@ bool Protocol::IsHandledProtocolInIO(const std::string& scheme) { return job_factory_->IsHandledProtocol(scheme); } +void Protocol::UninterceptProtocol( + const std::string& scheme, mate::Arguments* args) { + CompletionCallback callback; + args->GetNext(&callback); + content::BrowserThread::PostTaskAndReplyWithResult( + content::BrowserThread::IO, FROM_HERE, + base::Bind(&Protocol::UninterceptProtocolInIO, + base::Unretained(this), scheme), + base::Bind(&Protocol::OnIOCompleted, + base::Unretained(this), callback)); +} + +Protocol::ProtocolError Protocol::UninterceptProtocolInIO( + const std::string& scheme) { + if (!original_protocols_.contains(scheme)) + return PROTOCOL_NOT_INTERCEPTED; + job_factory_->ReplaceProtocol(scheme, + original_protocols_.take_and_erase(scheme)); + return PROTOCOL_OK; +} + 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 ce8f087..2e706c4 100644 --- a/atom/browser/api/atom_api_protocol.h +++ b/atom/browser/api/atom_api_protocol.h @@ -162,6 +162,10 @@ class Protocol : public mate::Wrappable { return PROTOCOL_OK; } + // Restore the |scheme| to its original protocol handler. + void UninterceptProtocol(const std::string& scheme, mate::Arguments* args); + ProtocolError UninterceptProtocolInIO(const std::string& scheme); + // Convert error code to JS exception and call the callback. void OnIOCompleted(const CompletionCallback& callback, ProtocolError error); -- 2.7.4