Merge revision 574 changes:
- Add CefCookieManager::SetSupportedSchemes method which supports cookie storage for non-http(s) schemes (issue #567). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1025@575 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
7ab2a3b36a
commit
af17a1a12d
|
@ -55,6 +55,14 @@ typedef struct _cef_cookie_manager_t {
|
|||
///
|
||||
cef_base_t base;
|
||||
|
||||
///
|
||||
// Set the schemes supported by this manager. By default only "http" and
|
||||
// "https" schemes are supported. Must be called before any cookies are
|
||||
// accessed.
|
||||
///
|
||||
void (CEF_CALLBACK *set_supported_schemes)(struct _cef_cookie_manager_t* self,
|
||||
cef_string_list_t schemes);
|
||||
|
||||
///
|
||||
// Visit all cookies. The returned cookies are ordered by longest path, then
|
||||
// by earliest creation date. Returns false (0) if cookies cannot be accessed.
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "include/cef_base.h"
|
||||
#include <vector>
|
||||
|
||||
class CefCookieVisitor;
|
||||
|
||||
|
@ -64,6 +65,14 @@ class CefCookieManager : public virtual CefBase {
|
|||
/*--cef(optional_param=path)--*/
|
||||
static CefRefPtr<CefCookieManager> CreateManager(const CefString& path);
|
||||
|
||||
///
|
||||
// Set the schemes supported by this manager. By default only "http" and
|
||||
// "https" schemes are supported. Must be called before any cookies are
|
||||
// accessed.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void SetSupportedSchemes(const std::vector<CefString>& schemes) =0;
|
||||
|
||||
///
|
||||
// Visit all cookies. The returned cookies are ordered by longest path, then
|
||||
// by earliest creation date. Returns false if cookies cannot be accessed.
|
||||
|
|
|
@ -79,6 +79,33 @@ CefCookieManagerImpl::CefCookieManagerImpl(bool is_global)
|
|||
CefCookieManagerImpl::~CefCookieManagerImpl() {
|
||||
}
|
||||
|
||||
void CefCookieManagerImpl::SetSupportedSchemes(
|
||||
const std::vector<CefString>& schemes) {
|
||||
if (CefThread::CurrentlyOn(CefThread::IO)) {
|
||||
if (schemes.empty())
|
||||
return;
|
||||
|
||||
std::set<std::string> scheme_set;
|
||||
std::vector<CefString>::const_iterator it = schemes.begin();
|
||||
for (; it != schemes.end(); ++it)
|
||||
scheme_set.insert(*it);
|
||||
|
||||
const char** arr = new const char*[scheme_set.size()];
|
||||
std::set<std::string>::const_iterator it2 = scheme_set.begin();
|
||||
for (int i = 0; it2 != scheme_set.end(); ++it2, ++i)
|
||||
arr[i] = it2->c_str();
|
||||
|
||||
cookie_monster_->SetCookieableSchemes(arr, scheme_set.size());
|
||||
|
||||
delete [] arr;
|
||||
} else {
|
||||
// Execute on the IO thread.
|
||||
CefThread::PostTask(CefThread::IO, FROM_HERE,
|
||||
base::Bind(&CefCookieManagerImpl::SetSupportedSchemes,
|
||||
this, schemes));
|
||||
}
|
||||
}
|
||||
|
||||
bool CefCookieManagerImpl::VisitAllCookies(
|
||||
CefRefPtr<CefCookieVisitor> visitor) {
|
||||
if (CefThread::CurrentlyOn(CefThread::IO)) {
|
||||
|
|
|
@ -17,6 +17,8 @@ class CefCookieManagerImpl : public CefCookieManager {
|
|||
~CefCookieManagerImpl();
|
||||
|
||||
// CefCookieManager methods.
|
||||
virtual void SetSupportedSchemes(const std::vector<CefString>& schemes)
|
||||
OVERRIDE;
|
||||
virtual bool VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor) OVERRIDE;
|
||||
virtual bool VisitUrlCookies(const CefString& url, bool includeHttpOnly,
|
||||
CefRefPtr<CefCookieVisitor> visitor) OVERRIDE;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "libcef_dll/cpptoc/cookie_manager_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/cookie_visitor_ctocpp.h"
|
||||
#include "libcef_dll/transfer_util.h"
|
||||
|
||||
|
||||
// GLOBAL FUNCTIONS - Body may be edited by hand.
|
||||
|
@ -43,6 +44,27 @@ CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_create_manager(
|
|||
|
||||
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||
|
||||
void CEF_CALLBACK cookie_manager_set_supported_schemes(
|
||||
struct _cef_cookie_manager_t* self, cef_string_list_t schemes) {
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return;
|
||||
// Verify param: schemes; type: string_vec_byref_const
|
||||
DCHECK(schemes);
|
||||
if (!schemes)
|
||||
return;
|
||||
|
||||
// Translate param: schemes; type: string_vec_byref_const
|
||||
std::vector<CefString> schemesList;
|
||||
transfer_string_list_contents(schemes, schemesList);
|
||||
|
||||
// Execute
|
||||
CefCookieManagerCppToC::Get(self)->SetSupportedSchemes(
|
||||
schemesList);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK cookie_manager_visit_all_cookies(
|
||||
struct _cef_cookie_manager_t* self,
|
||||
struct _cef_cookie_visitor_t* visitor) {
|
||||
|
@ -163,6 +185,7 @@ int CEF_CALLBACK cookie_manager_set_storage_path(
|
|||
CefCookieManagerCppToC::CefCookieManagerCppToC(CefCookieManager* cls)
|
||||
: CefCppToC<CefCookieManagerCppToC, CefCookieManager, cef_cookie_manager_t>(
|
||||
cls) {
|
||||
struct_.struct_.set_supported_schemes = cookie_manager_set_supported_schemes;
|
||||
struct_.struct_.visit_all_cookies = cookie_manager_visit_all_cookies;
|
||||
struct_.struct_.visit_url_cookies = cookie_manager_visit_url_cookies;
|
||||
struct_.struct_.set_cookie = cookie_manager_set_cookie;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "libcef_dll/cpptoc/cookie_visitor_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/cookie_manager_ctocpp.h"
|
||||
#include "libcef_dll/transfer_util.h"
|
||||
|
||||
|
||||
// STATIC METHODS - Body may be edited by hand.
|
||||
|
@ -43,6 +44,28 @@ CefRefPtr<CefCookieManager> CefCookieManager::CreateManager(
|
|||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
void CefCookieManagerCToCpp::SetSupportedSchemes(
|
||||
const std::vector<CefString>& schemes) {
|
||||
if (CEF_MEMBER_MISSING(struct_, set_supported_schemes))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Translate param: schemes; type: string_vec_byref_const
|
||||
cef_string_list_t schemesList = cef_string_list_alloc();
|
||||
DCHECK(schemesList);
|
||||
if (schemesList)
|
||||
transfer_string_list_contents(schemes, schemesList);
|
||||
|
||||
// Execute
|
||||
struct_->set_supported_schemes(struct_,
|
||||
schemesList);
|
||||
|
||||
// Restore param:schemes; type: string_vec_byref_const
|
||||
if (schemesList)
|
||||
cef_string_list_free(schemesList);
|
||||
}
|
||||
|
||||
bool CefCookieManagerCToCpp::VisitAllCookies(
|
||||
CefRefPtr<CefCookieVisitor> visitor) {
|
||||
if (CEF_MEMBER_MISSING(struct_, visit_all_cookies))
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
|
||||
#else // USING_CEF_SHARED
|
||||
|
||||
#include <vector>
|
||||
#include "include/cef_cookie.h"
|
||||
#include "include/capi/cef_cookie_capi.h"
|
||||
#include "libcef_dll/ctocpp/ctocpp.h"
|
||||
|
@ -34,6 +35,8 @@ class CefCookieManagerCToCpp
|
|||
virtual ~CefCookieManagerCToCpp() {}
|
||||
|
||||
// CefCookieManager methods
|
||||
virtual void SetSupportedSchemes(
|
||||
const std::vector<CefString>& schemes) OVERRIDE;
|
||||
virtual bool VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor) OVERRIDE;
|
||||
virtual bool VisitUrlCookies(const CefString& url, bool includeHttpOnly,
|
||||
CefRefPtr<CefCookieVisitor> visitor) OVERRIDE;
|
||||
|
|
|
@ -686,15 +686,11 @@ TEST(CookieTest, GetCookieManagerJS) {
|
|||
|
||||
namespace {
|
||||
|
||||
const char* kCookieHttpUrl1 = "http://cookie-tests/cookie1.html";
|
||||
const char* kCookieHttpUrl2 = "http://cookie-tests/cookie2.html";
|
||||
const char* kCookieHttpUrl3 = "http://cookie-tests/cookie3.html";
|
||||
|
||||
class CookieTestHttpHandler : public TestHandler {
|
||||
class CookieTestSchemeHandler : public TestHandler {
|
||||
public:
|
||||
class SchemeHandler : public CefSchemeHandler {
|
||||
public:
|
||||
explicit SchemeHandler(CookieTestHttpHandler* handler)
|
||||
explicit SchemeHandler(CookieTestSchemeHandler* handler)
|
||||
: handler_(handler),
|
||||
offset_(0) {}
|
||||
|
||||
|
@ -702,15 +698,15 @@ class CookieTestHttpHandler : public TestHandler {
|
|||
CefRefPtr<CefSchemeHandlerCallback> callback)
|
||||
OVERRIDE {
|
||||
std::string url = request->GetURL();
|
||||
if (url == kCookieHttpUrl1) {
|
||||
if (url == handler_->url1_) {
|
||||
content_ = "<html><body>COOKIE TEST1</body></html>";
|
||||
cookie_ = "name1=value1";
|
||||
handler_->got_process_request1_.yes();
|
||||
} else if (url == kCookieHttpUrl2) {
|
||||
} else if (url == handler_->url2_) {
|
||||
content_ = "<html><body>COOKIE TEST2</body></html>";
|
||||
cookie_ = "name2=value2";
|
||||
handler_->got_process_request2_.yes();
|
||||
} else if (url == kCookieHttpUrl3) {
|
||||
} else if (url == handler_->url3_) {
|
||||
content_ = "<html><body>COOKIE TEST3</body></html>";
|
||||
handler_->got_process_request3_.yes();
|
||||
|
||||
|
@ -768,7 +764,7 @@ class CookieTestHttpHandler : public TestHandler {
|
|||
}
|
||||
|
||||
private:
|
||||
CookieTestHttpHandler* handler_;
|
||||
CookieTestSchemeHandler* handler_;
|
||||
std::string content_;
|
||||
size_t offset_;
|
||||
std::string cookie_;
|
||||
|
@ -778,7 +774,7 @@ class CookieTestHttpHandler : public TestHandler {
|
|||
|
||||
class SchemeHandlerFactory : public CefSchemeHandlerFactory {
|
||||
public:
|
||||
explicit SchemeHandlerFactory(CookieTestHttpHandler* handler)
|
||||
explicit SchemeHandlerFactory(CookieTestSchemeHandler* handler)
|
||||
: handler_(handler) {}
|
||||
|
||||
virtual CefRefPtr<CefSchemeHandler> Create(CefRefPtr<CefBrowser> browser,
|
||||
|
@ -786,7 +782,7 @@ class CookieTestHttpHandler : public TestHandler {
|
|||
CefRefPtr<CefRequest> request)
|
||||
OVERRIDE {
|
||||
std::string url = request->GetURL();
|
||||
if (url == kCookieHttpUrl3) {
|
||||
if (url == handler_->url3_) {
|
||||
// Verify that the cookie was not passed in.
|
||||
CefRequest::HeaderMap headerMap;
|
||||
request->GetHeaderMap(headerMap);
|
||||
|
@ -799,48 +795,64 @@ class CookieTestHttpHandler : public TestHandler {
|
|||
}
|
||||
|
||||
private:
|
||||
CookieTestHttpHandler* handler_;
|
||||
CookieTestSchemeHandler* handler_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(SchemeHandlerFactory);
|
||||
};
|
||||
|
||||
CookieTestHttpHandler() {}
|
||||
CookieTestSchemeHandler(const std::string& scheme) : scheme_(scheme) {
|
||||
url1_ = scheme + "://cookie-tests/cookie1.html";
|
||||
url2_ = scheme + "://cookie-tests/cookie2.html";
|
||||
url3_ = scheme + "://cookie-tests/cookie3.html";
|
||||
}
|
||||
|
||||
virtual void RunTest() OVERRIDE {
|
||||
// Create new in-memory managers.
|
||||
manager1_ = CefCookieManager::CreateManager(CefString());
|
||||
manager2_ = CefCookieManager::CreateManager(CefString());
|
||||
|
||||
if (scheme_ != "http") {
|
||||
CefRegisterCustomScheme(scheme_, true, false, false);
|
||||
|
||||
std::vector<CefString> schemes;
|
||||
schemes.push_back("http");
|
||||
schemes.push_back("https");
|
||||
schemes.push_back(scheme_);
|
||||
|
||||
manager1_->SetSupportedSchemes(schemes);
|
||||
manager2_->SetSupportedSchemes(schemes);
|
||||
}
|
||||
|
||||
// Register the scheme handler.
|
||||
CefRegisterSchemeHandlerFactory("http", "cookie-tests",
|
||||
CefRegisterSchemeHandlerFactory(scheme_, "cookie-tests",
|
||||
new SchemeHandlerFactory(this));
|
||||
|
||||
// Create the browser
|
||||
CreateBrowser(kCookieHttpUrl1);
|
||||
CreateBrowser(url1_);
|
||||
}
|
||||
|
||||
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) OVERRIDE {
|
||||
std::string url = frame->GetURL();
|
||||
if (url == kCookieHttpUrl1) {
|
||||
if (url == url1_) {
|
||||
got_load_end1_.yes();
|
||||
VerifyCookie(manager1_, url, "name1", "value1", got_cookie1_);
|
||||
|
||||
// Go to the next URL
|
||||
frame->LoadURL(kCookieHttpUrl2);
|
||||
} else if (url == kCookieHttpUrl2) {
|
||||
frame->LoadURL(url2_);
|
||||
} else if (url == url2_) {
|
||||
got_load_end2_.yes();
|
||||
VerifyCookie(manager2_, url, "name2", "value2", got_cookie2_);
|
||||
|
||||
// Go to the next URL
|
||||
frame->LoadURL(kCookieHttpUrl3);
|
||||
frame->LoadURL(url3_);
|
||||
} else {
|
||||
got_load_end3_.yes();
|
||||
VerifyCookie(manager2_, url, "name2", "value2", got_cookie3_);
|
||||
|
||||
// Unregister the scheme handler.
|
||||
CefRegisterSchemeHandlerFactory("http", "cookie-tests", NULL);
|
||||
CefRegisterSchemeHandlerFactory(scheme_, "cookie-tests", NULL);
|
||||
|
||||
DestroyTest();
|
||||
}
|
||||
|
@ -849,7 +861,7 @@ class CookieTestHttpHandler : public TestHandler {
|
|||
virtual CefRefPtr<CefCookieManager> GetCookieManager(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
const CefString& main_url) OVERRIDE {
|
||||
if (main_url == kCookieHttpUrl1) {
|
||||
if (main_url == url1_) {
|
||||
// Return the first cookie manager.
|
||||
got_cookie_manager1_.yes();
|
||||
return manager1_;
|
||||
|
@ -878,6 +890,11 @@ class CookieTestHttpHandler : public TestHandler {
|
|||
}
|
||||
}
|
||||
|
||||
std::string scheme_;
|
||||
std::string url1_;
|
||||
std::string url2_;
|
||||
std::string url3_;
|
||||
|
||||
CefRefPtr<CefCookieManager> manager1_;
|
||||
CefRefPtr<CefCookieManager> manager2_;
|
||||
|
||||
|
@ -898,9 +915,31 @@ class CookieTestHttpHandler : public TestHandler {
|
|||
|
||||
} // namespace
|
||||
|
||||
// Verify use of multiple cookie managers vis HTTP.
|
||||
// Verify use of multiple cookie managers via HTTP.
|
||||
TEST(CookieTest, GetCookieManagerHttp) {
|
||||
CefRefPtr<CookieTestHttpHandler> handler = new CookieTestHttpHandler();
|
||||
CefRefPtr<CookieTestSchemeHandler> handler =
|
||||
new CookieTestSchemeHandler("http");
|
||||
handler->ExecuteTest();
|
||||
|
||||
EXPECT_TRUE(handler->got_process_request1_);
|
||||
EXPECT_TRUE(handler->got_process_request2_);
|
||||
EXPECT_TRUE(handler->got_process_request3_);
|
||||
EXPECT_FALSE(handler->got_create_cookie_);
|
||||
EXPECT_TRUE(handler->got_process_request_cookie_);
|
||||
EXPECT_TRUE(handler->got_cookie_manager1_);
|
||||
EXPECT_TRUE(handler->got_cookie_manager2_);
|
||||
EXPECT_TRUE(handler->got_load_end1_);
|
||||
EXPECT_TRUE(handler->got_load_end2_);
|
||||
EXPECT_TRUE(handler->got_load_end3_);
|
||||
EXPECT_TRUE(handler->got_cookie1_);
|
||||
EXPECT_TRUE(handler->got_cookie2_);
|
||||
EXPECT_TRUE(handler->got_cookie3_);
|
||||
}
|
||||
|
||||
// Verify use of multiple cookie managers via a custom scheme.
|
||||
TEST(CookieTest, GetCookieManagerCustom) {
|
||||
CefRefPtr<CookieTestSchemeHandler> handler =
|
||||
new CookieTestSchemeHandler("ccustom");
|
||||
handler->ExecuteTest();
|
||||
|
||||
EXPECT_TRUE(handler->got_process_request1_);
|
||||
|
|
Loading…
Reference in New Issue