diff --git a/atom/browser/api/atom_api_cookies.cc b/atom/browser/api/atom_api_cookies.cc index 4a0060efa53..be11df8888c 100644 --- a/atom/browser/api/atom_api_cookies.cc +++ b/atom/browser/api/atom_api_cookies.cc @@ -10,7 +10,6 @@ #include "base/time/time.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/web_contents.h" #include "native_mate/callback.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" @@ -22,11 +21,13 @@ #include "atom/common/node_includes.h" +using atom::api::Cookies; using content::BrowserThread; namespace { -bool GetCookieListFromStore(net::CookieStore* cookie_store, +bool GetCookieListFromStore( + net::CookieStore* cookie_store, const std::string& url, const net::CookieMonster::GetCookieListCallback& callback) { DCHECK(cookie_store); @@ -46,8 +47,8 @@ bool GetCookieListFromStore(net::CookieStore* cookie_store, } void RunGetCookiesCallbackOnUIThread(const std::string& error_message, - const net::CookieList& cookie_list, - const atom::api::Cookies::CookiesCallback& callback) { + const net::CookieList& cookie_list, + const Cookies::CookiesCallback& callback) { DCHECK_CURRENTLY_ON(BrowserThread::UI); v8::Isolate* isolate = v8::Isolate::GetCurrent(); @@ -63,8 +64,9 @@ void RunGetCookiesCallbackOnUIThread(const std::string& error_message, callback.Run(v8::Null(isolate), mate::ConvertToV8(isolate, cookie_list)); } -void RunRemoveCookiesCallbackOnUIThread(const std::string& error_message, - const atom::api::Cookies::CookiesCallback& callback) { +void RunRemoveCookiesCallbackOnUIThread( + const std::string& error_message, + const Cookies::CookiesCallback& callback) { DCHECK_CURRENTLY_ON(BrowserThread::UI); v8::Isolate* isolate = v8::Isolate::GetCurrent(); @@ -82,7 +84,8 @@ void RunRemoveCookiesCallbackOnUIThread(const std::string& error_message, } void RunSetCookiesCallbackOnUIThread(const std::string& error_message, - bool set_success, const atom::api::Cookies::CookiesCallback& callback) { + bool set_success, + const Cookies::CookiesCallback& callback) { DCHECK_CURRENTLY_ON(BrowserThread::UI); v8::Isolate* isolate = v8::Isolate::GetCurrent(); @@ -132,7 +135,7 @@ bool MatchesDomain(const base::DictionaryValue* filter, } bool MatchesCookie(const base::DictionaryValue* filter, - const net::CanonicalCookie& cookie) { + const net::CanonicalCookie& cookie) { std::string name, domain, path; bool is_secure, session; if (filter->GetString("name", &name) && name != cookie.Name()) @@ -157,7 +160,7 @@ namespace mate { template<> struct Converter { static v8::Local ToV8(v8::Isolate* isolate, - const net::CanonicalCookie& val) { + const net::CanonicalCookie& val) { mate::Dictionary dict(isolate, v8::Object::New(isolate)); dict.Set("name", val.Name()); dict.Set("value", val.Value()); @@ -179,8 +182,8 @@ namespace atom { namespace api { -Cookies::Cookies(content::WebContents* web_contents): - web_contents_(web_contents) { +Cookies::Cookies(content::BrowserContext* browser_context) : + browser_context_(browser_context) { } Cookies::~Cookies() { @@ -198,8 +201,7 @@ void Cookies::Get(const base::DictionaryValue& options, void Cookies::GetCookiesOnIOThread(scoped_ptr filter, const CookiesCallback& callback) { - net::CookieStore* cookie_store = - web_contents_->GetBrowserContext()->GetRequestContext() + net::CookieStore* cookie_store = browser_context_->GetRequestContext() ->GetURLRequestContext()->cookie_store(); std::string url; filter->GetString("url", &url); @@ -245,9 +247,8 @@ void Cookies::Remove(const mate::Dictionary& details, } void Cookies::RemoveCookiesOnIOThread(const GURL& url, const std::string& name, - const CookiesCallback& callback) { - net::CookieStore* cookie_store = - web_contents_->GetBrowserContext()->GetRequestContext() + const CookiesCallback& callback) { + net::CookieStore* cookie_store = browser_context_->GetRequestContext() ->GetURLRequestContext()->cookie_store(); cookie_store->DeleteCookieAsync(url, name, base::Bind(&Cookies::OnRemoveCookies, base::Unretained(this), callback)); @@ -288,8 +289,7 @@ void Cookies::SetCookiesOnIOThread(scoped_ptr details, const GURL& url, const CookiesCallback& callback) { DCHECK_CURRENTLY_ON(BrowserThread::IO); - net::CookieStore* cookie_store = - web_contents_->GetBrowserContext()->GetRequestContext() + net::CookieStore* cookie_store = browser_context_->GetRequestContext() ->GetURLRequestContext()->cookie_store(); std::string name, value, domain, path; @@ -340,9 +340,10 @@ mate::ObjectTemplateBuilder Cookies::GetObjectTemplateBuilder( } // static -mate::Handle Cookies::Create(v8::Isolate* isolate, - content::WebContents* web_contents) { - return CreateHandle(isolate, new Cookies(web_contents)); +mate::Handle Cookies::Create( + v8::Isolate* isolate, + content::BrowserContext* browser_context) { + return CreateHandle(isolate, new Cookies(browser_context)); } } // namespace api diff --git a/atom/browser/api/atom_api_cookies.h b/atom/browser/api/atom_api_cookies.h index 4ed1dc8cb32..61357f05d75 100644 --- a/atom/browser/api/atom_api_cookies.h +++ b/atom/browser/api/atom_api_cookies.h @@ -16,7 +16,7 @@ #include "net/cookies/canonical_cookie.h" namespace content { -class WebContents; +class BrowserContext; } namespace atom { @@ -30,10 +30,10 @@ class Cookies : public mate::Wrappable { CookiesCallback; static mate::Handle Create(v8::Isolate* isolate, - content::WebContents* web_contents); + content::BrowserContext* browser_context); protected: - explicit Cookies(content::WebContents* web_contents); + explicit Cookies(content::BrowserContext* browser_context); ~Cookies(); void Get(const base::DictionaryValue& options, @@ -66,7 +66,7 @@ class Cookies : public mate::Wrappable { v8::Isolate* isolate) override; private: - content::WebContents* web_contents_; + content::BrowserContext* browser_context_; DISALLOW_COPY_AND_ASSIGN(Cookies); }; diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index 6fa2c28f84c..744accd7d1c 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -5,7 +5,7 @@ #include "atom/browser/api/atom_api_session.h" #include "atom/browser/api/atom_api_cookies.h" -#include "content/public/browser/web_contents.h" +#include "content/public/browser/browser_context.h" #include "native_mate/callback.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" @@ -16,8 +16,8 @@ namespace atom { namespace api { -Session::Session(content::WebContents* web_contents): - web_contents_(web_contents) { +Session::Session(content::BrowserContext* browser_context): + browser_context_(browser_context) { } Session::~Session() { @@ -25,7 +25,7 @@ Session::~Session() { v8::Local Session::Cookies(v8::Isolate* isolate) { if (cookies_.IsEmpty()) { - auto handle = atom::api::Cookies::Create(isolate, web_contents_); + auto handle = atom::api::Cookies::Create(isolate, browser_context_); cookies_.Reset(isolate, handle.ToV8()); } return v8::Local::New(isolate, cookies_); @@ -38,9 +38,10 @@ mate::ObjectTemplateBuilder Session::GetObjectTemplateBuilder( } // static -mate::Handle Session::Create(v8::Isolate* isolate, - content::WebContents* web_contents) { - return CreateHandle(isolate, new Session(web_contents)); +mate::Handle Session::Create( + v8::Isolate* isolate, + content::BrowserContext* browser_context) { + return CreateHandle(isolate, new Session(browser_context)); } } // namespace api diff --git a/atom/browser/api/atom_api_session.h b/atom/browser/api/atom_api_session.h index 35b3329ffe3..4bdab075770 100644 --- a/atom/browser/api/atom_api_session.h +++ b/atom/browser/api/atom_api_session.h @@ -9,7 +9,7 @@ #include "native_mate/wrappable.h" namespace content { -class WebContents; +class BrowserContext; } namespace atom { @@ -19,10 +19,10 @@ namespace api { class Session: public mate::Wrappable { public: static mate::Handle Create(v8::Isolate* isolate, - content::WebContents* web_contents); + content::BrowserContext* browser_context); protected: - explicit Session(content::WebContents* web_contents); + explicit Session(content::BrowserContext* browser_context); ~Session(); // mate::Wrappable implementations: @@ -35,7 +35,7 @@ class Session: public mate::Wrappable { v8::Global cookies_; // The webContents which owns the Sesssion. - content::WebContents* web_contents_; + content::BrowserContext* browser_context_; DISALLOW_COPY_AND_ASSIGN(Session); }; diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 16988d46c45..8b26b724fa0 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -587,7 +587,7 @@ void WebContents::InspectServiceWorker() { v8::Local WebContents::Session(v8::Isolate* isolate) { if (session_.IsEmpty()) { - auto handle = Session::Create(isolate, web_contents()); + auto handle = Session::Create(isolate, web_contents()->GetBrowserContext()); session_.Reset(isolate, handle.ToV8()); } return v8::Local::New(isolate, session_);