diff options
Diffstat (limited to 'chrome/browser/extensions/api/cookies')
3 files changed, 54 insertions, 33 deletions
diff --git a/chrome/browser/extensions/api/cookies/cookies_api.cc b/chrome/browser/extensions/api/cookies/cookies_api.cc index f3a4a35..c35b830 100644 --- a/chrome/browser/extensions/api/cookies/cookies_api.cc +++ b/chrome/browser/extensions/api/cookies/cookies_api.cc @@ -203,8 +203,9 @@ bool CookiesGetFunction::RunImpl() { if (!ParseUrl(parsed_args_->details.url, &url_, true)) return false; - std::string store_id = parsed_args_->details.store_id.get() ? - *parsed_args_->details.store_id : ""; + std::string store_id = + parsed_args_->details.store_id.get() ? *parsed_args_->details.store_id + : std::string(); net::URLRequestContextGetter* store_context = NULL; if (!ParseStoreContext(&store_id, &store_context)) return false; @@ -276,8 +277,9 @@ bool CookiesGetAllFunction::RunImpl() { return false; } - std::string store_id = parsed_args_->details.store_id.get() ? - *parsed_args_->details.store_id : ""; + std::string store_id = + parsed_args_->details.store_id.get() ? *parsed_args_->details.store_id + : std::string(); net::URLRequestContextGetter* store_context = NULL; if (!ParseStoreContext(&store_id, &store_context)) return false; @@ -339,8 +341,9 @@ bool CookiesSetFunction::RunImpl() { if (!ParseUrl(parsed_args_->details.url, &url_, true)) return false; - std::string store_id = parsed_args_->details.store_id.get() ? - *parsed_args_->details.store_id : ""; + std::string store_id = + parsed_args_->details.store_id.get() ? *parsed_args_->details.store_id + : std::string(); net::URLRequestContextGetter* store_context = NULL; if (!ParseStoreContext(&store_id, &store_context)) return false; @@ -374,17 +377,19 @@ void CookiesSetFunction::SetCookieOnIOThread() { cookie_monster->SetCookieWithDetailsAsync( url_, - parsed_args_->details.name.get() ? *parsed_args_->details.name : "", - parsed_args_->details.value.get() ? *parsed_args_->details.value : "", - parsed_args_->details.domain.get() ? *parsed_args_->details.domain : "", - parsed_args_->details.path.get() ? *parsed_args_->details.path : "", + parsed_args_->details.name.get() ? *parsed_args_->details.name + : std::string(), + parsed_args_->details.value.get() ? *parsed_args_->details.value + : std::string(), + parsed_args_->details.domain.get() ? *parsed_args_->details.domain + : std::string(), + parsed_args_->details.path.get() ? *parsed_args_->details.path + : std::string(), expiration_time, - parsed_args_->details.secure.get() ? - *parsed_args_->details.secure.get() : - false, - parsed_args_->details.http_only.get() ? - *parsed_args_->details.http_only : - false, + parsed_args_->details.secure.get() ? *parsed_args_->details.secure.get() + : false, + parsed_args_->details.http_only.get() ? *parsed_args_->details.http_only + : false, base::Bind(&CookiesSetFunction::PullCookie, this)); } @@ -406,8 +411,9 @@ void CookiesSetFunction::PullCookieCallback( // Return the first matching cookie. Relies on the fact that the // CookieMonster returns them in canonical order (longest path, then // earliest creation time). - std::string name = parsed_args_->details.name.get() ? - *parsed_args_->details.name : ""; + std::string name = + parsed_args_->details.name.get() ? *parsed_args_->details.name + : std::string(); if (it->Name() == name) { scoped_ptr<Cookie> cookie( cookies_helpers::CreateCookie(*it, *parsed_args_->details.store_id)); @@ -425,10 +431,10 @@ void CookiesSetFunction::PullCookieCallback( void CookiesSetFunction::RespondOnUIThread() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); if (!success_) { - std::string name = parsed_args_->details.name.get() ? - *parsed_args_->details.name : ""; - error_ = ErrorUtils::FormatErrorMessage( - keys::kCookieSetFailedError, name); + std::string name = + parsed_args_->details.name.get() ? *parsed_args_->details.name + : std::string(); + error_ = ErrorUtils::FormatErrorMessage(keys::kCookieSetFailedError, name); } SendResponse(success_); } @@ -447,8 +453,9 @@ bool CookiesRemoveFunction::RunImpl() { if (!ParseUrl(parsed_args_->details.url, &url_, true)) return false; - std::string store_id = parsed_args_->details.store_id.get() ? - *parsed_args_->details.store_id : ""; + std::string store_id = + parsed_args_->details.store_id.get() ? *parsed_args_->details.store_id + : std::string(); net::URLRequestContextGetter* store_context = NULL; if (!ParseStoreContext(&store_id, &store_context)) return false; diff --git a/chrome/browser/extensions/api/cookies/cookies_helpers.cc b/chrome/browser/extensions/api/cookies/cookies_helpers.cc index d9866f2..c61e729 100644 --- a/chrome/browser/extensions/api/cookies/cookies_helpers.cc +++ b/chrome/browser/extensions/api/cookies/cookies_helpers.cc @@ -74,8 +74,8 @@ scoped_ptr<Cookie> CreateCookie( cookie->host_only = net::cookie_util::DomainIsHostOnly( canonical_cookie.Domain()); // A non-UTF8 path is invalid, so we just replace it with an empty string. - cookie->path = IsStringUTF8(canonical_cookie.Path()) ? - canonical_cookie.Path() : ""; + cookie->path = IsStringUTF8(canonical_cookie.Path()) ? canonical_cookie.Path() + : std::string(); cookie->secure = canonical_cookie.IsSecure(); cookie->http_only = canonical_cookie.IsHttpOnly(); cookie->session = !canonical_cookie.IsPersistent(); diff --git a/chrome/browser/extensions/api/cookies/cookies_unittest.cc b/chrome/browser/extensions/api/cookies/cookies_unittest.cc index f1bd93d..0844b83 100644 --- a/chrome/browser/extensions/api/cookies/cookies_unittest.cc +++ b/chrome/browser/extensions/api/cookies/cookies_unittest.cc @@ -195,22 +195,36 @@ TEST_F(ExtensionCookiesTest, DomainMatching) { scoped_ptr<GetAll::Params> params(GetAll::Params::Create(args)); cookies_helpers::MatchFilter filter(¶ms->details); - net::CanonicalCookie cookie(GURL(), "", "", tests[i].domain,"", - base::Time(), base::Time(), base::Time(), - false, false); + net::CanonicalCookie cookie(GURL(), + std::string(), + std::string(), + tests[i].domain, + std::string(), + base::Time(), + base::Time(), + base::Time(), + false, + false); EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie)); } } TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { - net::CanonicalCookie canonical_cookie( - GURL(), "", "011Q255bNX_1!yd\203e+", "test.com", "/path\203", - base::Time(), base::Time(), base::Time(), false, false); + net::CanonicalCookie canonical_cookie(GURL(), + std::string(), + "011Q255bNX_1!yd\203e+", + "test.com", + "/path\203", + base::Time(), + base::Time(), + base::Time(), + false, + false); scoped_ptr<Cookie> cookie( cookies_helpers::CreateCookie( canonical_cookie, "some cookie store")); EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); - EXPECT_EQ(std::string(""), cookie->path); + EXPECT_EQ(std::string(), cookie->path); } } // namespace extensions |