Move the code to native
This commit is contained in:
parent
d23d9dcf01
commit
ffed3e9c0c
2 changed files with 11 additions and 6 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_session.h"
|
#include "atom/browser/api/atom_api_session.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -173,6 +174,9 @@ const char kPersistPrefix[] = "persist:";
|
||||||
using WrapSessionCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
using WrapSessionCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
||||||
WrapSessionCallback g_wrap_session;
|
WrapSessionCallback g_wrap_session;
|
||||||
|
|
||||||
|
// Referenced session objects.
|
||||||
|
std::map<uint32_t, v8::Global<v8::Object>> g_sessions;
|
||||||
|
|
||||||
class ResolveProxyHelper {
|
class ResolveProxyHelper {
|
||||||
public:
|
public:
|
||||||
ResolveProxyHelper(AtomBrowserContext* browser_context,
|
ResolveProxyHelper(AtomBrowserContext* browser_context,
|
||||||
|
@ -346,6 +350,7 @@ Session::Session(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||||
Session::~Session() {
|
Session::~Session() {
|
||||||
content::BrowserContext::GetDownloadManager(browser_context())->
|
content::BrowserContext::GetDownloadManager(browser_context())->
|
||||||
RemoveObserver(this);
|
RemoveObserver(this);
|
||||||
|
g_sessions.erase(weak_map_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::OnDownloadCreated(content::DownloadManager* manager,
|
void Session::OnDownloadCreated(content::DownloadManager* manager,
|
||||||
|
@ -537,6 +542,12 @@ mate::Handle<Session> Session::CreateFrom(
|
||||||
auto handle = mate::CreateHandle(
|
auto handle = mate::CreateHandle(
|
||||||
isolate, new Session(isolate, browser_context));
|
isolate, new Session(isolate, browser_context));
|
||||||
g_wrap_session.Run(handle.ToV8());
|
g_wrap_session.Run(handle.ToV8());
|
||||||
|
|
||||||
|
// The Sessions should never be garbage collected, since the common pattern is
|
||||||
|
// to use partition strings, instead of using the Session object directly.
|
||||||
|
g_sessions[handle->weak_map_id()] =
|
||||||
|
v8::Global<v8::Object>(isolate, handle.ToV8());
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,15 +14,9 @@ Object.defineProperties(exports, {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const sessions = []
|
|
||||||
|
|
||||||
// Wraps native Session class.
|
// Wraps native Session class.
|
||||||
_setWrapSession(function (session) {
|
_setWrapSession(function (session) {
|
||||||
// Session is an EventEmitter.
|
// Session is an EventEmitter.
|
||||||
Object.setPrototypeOf(session, EventEmitter.prototype)
|
Object.setPrototypeOf(session, EventEmitter.prototype)
|
||||||
app.emit('session-created', session)
|
app.emit('session-created', session)
|
||||||
|
|
||||||
// The Sessions should never be garbage collected, since the common pattern is
|
|
||||||
// to use partition strings, instead of using the Session object directly.
|
|
||||||
sessions.push(session)
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue