feat: migrate protocol module to NetworkService (Part 9) (#18374)
* Compare final data instead of url The behavior of did-finish-load and getURL has changed for redirects when using NetworkService, so the test fails for NetworkService. Comparing the finally received data makes the test more reliable. * Implement intercept APIs * Setting mimeType should set "content-type" header * Passing no argument should not throw JS error * Don't access api namespace in ProxyingURLLoaderFactory * No need to create AtomURLLoaderFactory every time * No use of weak factory
This commit is contained in:
parent
646f572b77
commit
54cbe5f749
8 changed files with 120 additions and 38 deletions
|
@ -5,9 +5,7 @@
|
|||
#ifndef ATOM_BROWSER_API_ATOM_API_PROTOCOL_NS_H_
|
||||
#define ATOM_BROWSER_API_ATOM_API_PROTOCOL_NS_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/net/atom_url_loader_factory.h"
|
||||
|
@ -43,6 +41,8 @@ class ProtocolNS : public mate::TrackableObject<ProtocolNS> {
|
|||
void RegisterURLLoaderFactories(
|
||||
content::ContentBrowserClient::NonNetworkURLLoaderFactoryMap* factories);
|
||||
|
||||
const HandlersMap& intercept_handlers() const { return intercept_handlers_; }
|
||||
|
||||
private:
|
||||
ProtocolNS(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||
~ProtocolNS() override;
|
||||
|
@ -56,7 +56,12 @@ class ProtocolNS : public mate::TrackableObject<ProtocolNS> {
|
|||
const ProtocolHandler& handler);
|
||||
void UnregisterProtocol(const std::string& scheme, mate::Arguments* args);
|
||||
bool IsProtocolRegistered(const std::string& scheme);
|
||||
|
||||
ProtocolError InterceptProtocol(ProtocolType type,
|
||||
const std::string& scheme,
|
||||
const ProtocolHandler& handler);
|
||||
void UninterceptProtocol(const std::string& scheme, mate::Arguments* args);
|
||||
bool IsProtocolIntercepted(const std::string& scheme);
|
||||
|
||||
// Old async version of IsProtocolRegistered.
|
||||
v8::Local<v8::Promise> IsProtocolHandled(const std::string& scheme);
|
||||
|
@ -68,12 +73,18 @@ class ProtocolNS : public mate::TrackableObject<ProtocolNS> {
|
|||
mate::Arguments* args) {
|
||||
HandleOptionalCallback(args, RegisterProtocol(type, scheme, handler));
|
||||
}
|
||||
template <ProtocolType type>
|
||||
void InterceptProtocolFor(const std::string& scheme,
|
||||
const ProtocolHandler& handler,
|
||||
mate::Arguments* args) {
|
||||
HandleOptionalCallback(args, InterceptProtocol(type, scheme, handler));
|
||||
}
|
||||
|
||||
// Be compatible with old interface, which accepts optional callback.
|
||||
void HandleOptionalCallback(mate::Arguments* args, ProtocolError error);
|
||||
|
||||
// scheme => (type, handler).
|
||||
std::map<std::string, std::pair<ProtocolType, ProtocolHandler>> handlers_;
|
||||
HandlersMap handlers_;
|
||||
HandlersMap intercept_handlers_;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue