#endif
#include "atom/browser/api/atom_api_menu.h"
+#include "atom/browser/api/atom_api_session.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/browser/browser.h"
#endif
}
+v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
+ if (default_session_.IsEmpty()) {
+ auto browser_context = static_cast<AtomBrowserContext*>(
+ AtomBrowserMainParts::Get()->browser_context());
+ auto handle = Session::Create(isolate, browser_context);
+ default_session_.Reset(isolate, handle.ToV8());
+ }
+ return v8::Local<v8::Value>::New(isolate, default_session_);
+}
+
mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
auto browser = base::Unretained(Browser::Get());
.SetMethod("getPath", &App::GetPath)
.SetMethod("resolveProxy", &App::ResolveProxy)
.SetMethod("setDesktopName", &App::SetDesktopName)
- .SetMethod("setAppUserModelId", &App::SetAppUserModelId);
+ .SetMethod("setAppUserModelId", &App::SetAppUserModelId)
+ .SetProperty("defaultSession", &App::DefaultSession);
}
// static
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
void SetDesktopName(const std::string& desktop_name);
void SetAppUserModelId(const std::string& app_id);
+ v8::Local<v8::Value> DefaultSession(v8::Isolate* isolate);
+
+ v8::Global<v8::Value> default_session_;
DISALLOW_COPY_AND_ASSIGN(App);
};
#include "atom/browser/api/atom_api_session.h"
#include "atom/browser/api/atom_api_cookies.h"
-#include "content/public/browser/browser_context.h"
+#include "atom/browser/atom_browser_context.h"
#include "native_mate/callback.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
namespace api {
-Session::Session(content::BrowserContext* browser_context):
- browser_context_(browser_context) {
+Session::Session(AtomBrowserContext* browser_context)
+ : browser_context_(browser_context) {
}
Session::~Session() {
// static
mate::Handle<Session> Session::Create(
v8::Isolate* isolate,
- content::BrowserContext* browser_context) {
+ AtomBrowserContext* browser_context) {
return mate::CreateHandle(isolate, new Session(browser_context));
}
#include "native_mate/handle.h"
#include "native_mate/wrappable.h"
-namespace content {
-class BrowserContext;
-}
-
namespace atom {
+class AtomBrowserContext;
+
namespace api {
class Session: public mate::Wrappable {
public:
static mate::Handle<Session> Create(v8::Isolate* isolate,
- content::BrowserContext* browser_context);
+ AtomBrowserContext* browser_context);
protected:
- explicit Session(content::BrowserContext* browser_context);
+ explicit Session(AtomBrowserContext* browser_context);
~Session();
// mate::Wrappable implementations:
v8::Global<v8::Value> cookies_;
- // The webContents which owns the Sesssion.
- content::BrowserContext* browser_context_;
+ AtomBrowserContext* browser_context_; // weak ref
DISALLOW_COPY_AND_ASSIGN(Session);
};
v8::Local<v8::Value> WebContents::Session(v8::Isolate* isolate) {
if (session_.IsEmpty()) {
- auto handle = Session::Create(isolate, web_contents()->GetBrowserContext());
+ mate::Handle<api::Session> handle = Session::Create(
+ isolate,
+ static_cast<AtomBrowserContext*>(web_contents()->GetBrowserContext()));
session_.Reset(isolate, handle.ToV8());
}
return v8::Local<v8::Value>::New(isolate, session_);