Session::~Session() {
auto download_manager =
- content::BrowserContext::GetDownloadManager(browser_context_);
+ content::BrowserContext::GetDownloadManager(browser_context());
download_manager->RemoveObserver(this);
}
}
void Session::ResolveProxy(const GURL& url, ResolveProxyCallback callback) {
- new ResolveProxyHelper(browser_context_, url, callback);
+ new ResolveProxyHelper(browser_context(), url, callback);
}
void Session::ClearCache(const net::CompletionCallback& callback) {
}
auto storage_partition =
- content::BrowserContext::GetStoragePartition(browser_context_, nullptr);
+ content::BrowserContext::GetStoragePartition(browser_context(), nullptr);
storage_partition->ClearData(
options.storage_types, options.quota_types, options.origin,
content::StoragePartition::OriginMatcherFunction(),
v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {
if (cookies_.IsEmpty()) {
- auto handle = atom::api::Cookies::Create(isolate, browser_context_);
+ auto handle = atom::api::Cookies::Create(isolate, browser_context());
cookies_.Reset(isolate, handle.ToV8());
}
return v8::Local<v8::Value>::New(isolate, cookies_);
// static
mate::Handle<Session> Session::CreateFrom(
- v8::Isolate* isolate,
- AtomBrowserContext* browser_context) {
+ v8::Isolate* isolate, AtomBrowserContext* browser_context) {
auto existing = TrackableObject::FromWrappedClass(isolate, browser_context);
if (existing)
return mate::CreateHandle(isolate, static_cast<Session*>(existing));
return handle;
}
+// static
+mate::Handle<Session> Session::FromPartition(
+ v8::Isolate* isolate, const std::string& partition, bool in_memory) {
+ auto browser_context = brightray::BrowserContext::From(partition, in_memory);
+ return CreateFrom(isolate,
+ static_cast<AtomBrowserContext*>(browser_context.get()));
+}
+
void SetWrapSession(const WrapSessionCallback& callback) {
g_wrap_session = callback;
}
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
+ dict.SetMethod("fromPartition", &atom::api::Session::FromPartition);
dict.SetMethod("_setWrapSession", &atom::api::SetWrapSession);
dict.SetMethod("_clearWrapSession", &atom::api::ClearWrapSession);
}
static mate::Handle<Session> CreateFrom(
v8::Isolate* isolate, AtomBrowserContext* browser_context);
- AtomBrowserContext* browser_context() const { return browser_context_; }
+ // Gets the Session of |partition| and |in_memory|.
+ static mate::Handle<Session> FromPartition(
+ v8::Isolate* isolate, const std::string& partition, bool in_memory);
+
+ AtomBrowserContext* browser_context() const { return browser_context_.get(); }
protected:
explicit Session(AtomBrowserContext* browser_context);
v8::Global<v8::Value> cookies_;
- AtomBrowserContext* browser_context_; // weak ref
+ scoped_refptr<AtomBrowserContext> browser_context_;
DISALLOW_COPY_AND_ASSIGN(Session);
};
WebContents::WebContents(v8::Isolate* isolate,
const mate::Dictionary& options) {
+ // Whether it is a guest WebContents.
bool is_guest = false;
options.Get("isGuest", &is_guest);
-
type_ = is_guest ? WEB_VIEW : BROWSER_WINDOW;
- // TODO(zcbenz): Use host's BrowserContext when no partition is specified.
- content::BrowserContext* browser_context =
- AtomBrowserMainParts::Get()->browser_context();
+ // Obtain the session.
+ std::string partition;
+ mate::Handle<api::Session> session;
+ if (options.Get("session", &session)) {
+ } else if (options.Get("partition", &partition)) {
+ bool in_memory = true;
+ options.Get("inMemory", &in_memory);
+ session = Session::FromPartition(isolate, partition, in_memory);
+ } else {
+ // Use the default session if not specified.
+ session = Session::FromPartition(isolate, "", false);
+ }
+ session_.Reset(isolate, session.ToV8());
+
content::WebContents* web_contents;
if (is_guest) {
- std::string partition;
- bool in_memory = false;
- options.Get("partition", &partition);
- options.Get("inMemory", &in_memory);
- if (!partition.empty())
- browser_context = brightray::BrowserContext::From(partition, in_memory);
content::SiteInstance* site_instance = content::SiteInstance::CreateForURL(
- browser_context, GURL("chrome-guest://fake-host"));
- content::WebContents::CreateParams params(browser_context, site_instance);
+ session->browser_context(), GURL("chrome-guest://fake-host"));
+ content::WebContents::CreateParams params(
+ session->browser_context(), site_instance);
guest_delegate_.reset(new WebViewGuestDelegate);
params.guest_delegate = guest_delegate_.get();
web_contents = content::WebContents::Create(params);
} else {
- content::WebContents::CreateParams params(browser_context);
+ content::WebContents::CreateParams params(session->browser_context());
web_contents = content::WebContents::Create(params);
}
}
void WebContents::Destroy() {
+ session_.Reset();
if (type_ == WEB_VIEW && managed_web_contents()) {
// When force destroying the "destroyed" event is not emitted.
WebContentsDestroyed();
}
v8::Local<v8::Value> WebContents::Session(v8::Isolate* isolate) {
- if (session_.IsEmpty()) {
- auto handle = Session::CreateFrom(isolate, GetBrowserContext());
- session_.Reset(isolate, handle.ToV8());
- }
return v8::Local<v8::Value>::New(isolate, session_);
}
namespace brightray {
// static
-BrowserContext* BrowserContext::Create(const std::string& partition,
- bool in_memory) {
- return new atom::AtomBrowserContext(partition, in_memory);
+scoped_refptr<BrowserContext> BrowserContext::Create(
+ const std::string& partition, bool in_memory) {
+ return make_scoped_refptr(new atom::AtomBrowserContext(partition, in_memory));
}
} // namespace brightray
-Subproject commit b103a37d05335766421f4228fcb392cc57f8ea67
+Subproject commit 251521cb8c51670dbd08ab9fd2dd45e249cbb596