From de3ccc4b98fd2275b64e22fae41d19322ddc1b4b Mon Sep 17 00:00:00 2001 From: Robo Date: Fri, 17 Jul 2015 02:00:43 +0530 Subject: [PATCH] use current session when not defined --- atom/browser/api/atom_api_protocol.cc | 10 ++++++---- atom/browser/api/atom_api_protocol.h | 3 +++ atom/browser/api/atom_api_session.cc | 4 ---- atom/browser/api/atom_api_session.h | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/atom/browser/api/atom_api_protocol.cc b/atom/browser/api/atom_api_protocol.cc index 3b9eeb9fb783..d7af58802792 100644 --- a/atom/browser/api/atom_api_protocol.cc +++ b/atom/browser/api/atom_api_protocol.cc @@ -39,7 +39,7 @@ template<> struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Local val, net::URLRequestContextGetter** out) { - if (val->IsNull() || val->IsUndefined()) { + if (val->IsNull()) { *out = nullptr; return true; } @@ -47,7 +47,7 @@ struct Converter { atom::api::Session* session; if (!Converter::FromV8(isolate, val, &session)) return false; - *out = session->GetBrowserContext()->GetRequestContext(); + *out = session->browser_context()->GetRequestContext(); return true; } }; @@ -144,7 +144,8 @@ class CustomProtocolRequestJob : public AdapterRequestJob { } else if (name == "RequestHttpJob") { GURL url; std::string method, referrer; - net::URLRequestContextGetter* getter; + net::URLRequestContextGetter* getter = + registry_->browser_context()->GetRequestContext(); dict.Get("url", &url); dict.Get("method", &method); dict.Get("referrer", &referrer); @@ -231,7 +232,8 @@ std::string ConvertErrorCode(int error_code) { } // namespace Protocol::Protocol(AtomBrowserContext* browser_context) - : job_factory_(browser_context->job_factory()) { + : browser_context_(browser_context), + job_factory_(browser_context->job_factory()) { CHECK(job_factory_); } diff --git a/atom/browser/api/atom_api_protocol.h b/atom/browser/api/atom_api_protocol.h index 3e6f950241cb..b4d56018baf3 100644 --- a/atom/browser/api/atom_api_protocol.h +++ b/atom/browser/api/atom_api_protocol.h @@ -46,6 +46,8 @@ class Protocol : public mate::EventEmitter { JsProtocolHandler GetProtocolHandler(const std::string& scheme); + AtomBrowserContext* browser_context() const { return browser_context_; } + protected: explicit Protocol(AtomBrowserContext* browser_context); @@ -92,6 +94,7 @@ class Protocol : public mate::EventEmitter { const JsProtocolHandler& handler); int UninterceptProtocolInIO(const std::string& scheme); + AtomBrowserContext* browser_context_; AtomURLRequestJobFactory* job_factory_; ProtocolHandlersMap protocol_handlers_; diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index b489df4c44ef..93f8de52dd45 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -203,10 +203,6 @@ Session::Session(AtomBrowserContext* browser_context) Session::~Session() { } -AtomBrowserContext* Session::GetBrowserContext() const { - return browser_context_; -} - void Session::ResolveProxy(const GURL& url, ResolveProxyCallback callback) { new ResolveProxyHelper(browser_context_, url, callback); } diff --git a/atom/browser/api/atom_api_session.h b/atom/browser/api/atom_api_session.h index debe01ef9dbc..8e14c3a37834 100644 --- a/atom/browser/api/atom_api_session.h +++ b/atom/browser/api/atom_api_session.h @@ -31,7 +31,7 @@ class Session: public mate::TrackableObject { static mate::Handle CreateFrom( v8::Isolate* isolate, AtomBrowserContext* browser_context); - AtomBrowserContext* GetBrowserContext() const; + AtomBrowserContext* browser_context() const { return browser_context_; } protected: explicit Session(AtomBrowserContext* browser_context);