Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc

Issue 11414230: Declarative Web Request: firstPartyForCookiesUrl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased + attribute description in JSON changed Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion_attribute.h" 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion_attribute.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 new WebRequestConditionAttributeResourceType(passed_types)); 145 new WebRequestConditionAttributeResourceType(passed_types));
146 } 146 }
147 147
148 int WebRequestConditionAttributeResourceType::GetStages() const { 148 int WebRequestConditionAttributeResourceType::GetStages() const {
149 return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS | 149 return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS |
150 ON_HEADERS_RECEIVED | ON_AUTH_REQUIRED | ON_BEFORE_REDIRECT | 150 ON_HEADERS_RECEIVED | ON_AUTH_REQUIRED | ON_BEFORE_REDIRECT |
151 ON_RESPONSE_STARTED | ON_COMPLETED | ON_ERROR; 151 ON_RESPONSE_STARTED | ON_COMPLETED | ON_ERROR;
152 } 152 }
153 153
154 bool WebRequestConditionAttributeResourceType::IsFulfilled( 154 bool WebRequestConditionAttributeResourceType::IsFulfilled(
155 const DeclarativeWebRequestData& request_data) const { 155 const WebRequestData& request_data) const {
156 if (!(request_data.stage & GetStages())) 156 if (!(request_data.stage & GetStages()))
157 return false; 157 return false;
158 const content::ResourceRequestInfo* info = 158 const content::ResourceRequestInfo* info =
159 content::ResourceRequestInfo::ForRequest(request_data.request); 159 content::ResourceRequestInfo::ForRequest(request_data.request);
160 if (!info) 160 if (!info)
161 return false; 161 return false;
162 return std::find(types_.begin(), types_.end(), info->GetResourceType()) != 162 return std::find(types_.begin(), types_.end(), info->GetResourceType()) !=
163 types_.end(); 163 types_.end();
164 } 164 }
165 165
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 return scoped_ptr<WebRequestConditionAttribute>( 216 return scoped_ptr<WebRequestConditionAttribute>(
217 new WebRequestConditionAttributeContentType( 217 new WebRequestConditionAttributeContentType(
218 content_types, name == keys::kContentTypeKey)); 218 content_types, name == keys::kContentTypeKey));
219 } 219 }
220 220
221 int WebRequestConditionAttributeContentType::GetStages() const { 221 int WebRequestConditionAttributeContentType::GetStages() const {
222 return ON_HEADERS_RECEIVED; 222 return ON_HEADERS_RECEIVED;
223 } 223 }
224 224
225 bool WebRequestConditionAttributeContentType::IsFulfilled( 225 bool WebRequestConditionAttributeContentType::IsFulfilled(
226 const DeclarativeWebRequestData& request_data) const { 226 const WebRequestData& request_data) const {
227 if (!(request_data.stage & GetStages())) 227 if (!(request_data.stage & GetStages()))
228 return false; 228 return false;
229 std::string content_type; 229 std::string content_type;
230 request_data.original_response_headers->GetNormalizedHeader( 230 request_data.original_response_headers->GetNormalizedHeader(
231 net::HttpRequestHeaders::kContentType, &content_type); 231 net::HttpRequestHeaders::kContentType, &content_type);
232 std::string mime_type; 232 std::string mime_type;
233 std::string charset; 233 std::string charset;
234 bool had_charset = false; 234 bool had_charset = false;
235 net::HttpUtil::ParseContentType( 235 net::HttpUtil::ParseContentType(
236 content_type, &mime_type, &charset, &had_charset, NULL); 236 content_type, &mime_type, &charset, &had_charset, NULL);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 561
562 int WebRequestConditionAttributeRequestHeaders::GetStages() const { 562 int WebRequestConditionAttributeRequestHeaders::GetStages() const {
563 // Currently we only allow matching against headers in the before-send-headers 563 // Currently we only allow matching against headers in the before-send-headers
564 // stage. The headers are accessible in other stages as well, but before 564 // stage. The headers are accessible in other stages as well, but before
565 // allowing to match against them in further stages, we should consider 565 // allowing to match against them in further stages, we should consider
566 // caching the match result. 566 // caching the match result.
567 return ON_BEFORE_SEND_HEADERS; 567 return ON_BEFORE_SEND_HEADERS;
568 } 568 }
569 569
570 bool WebRequestConditionAttributeRequestHeaders::IsFulfilled( 570 bool WebRequestConditionAttributeRequestHeaders::IsFulfilled(
571 const DeclarativeWebRequestData& request_data) const { 571 const WebRequestData& request_data) const {
572 if (!(request_data.stage & GetStages())) 572 if (!(request_data.stage & GetStages()))
573 return false; 573 return false;
574 574
575 const net::HttpRequestHeaders& headers = 575 const net::HttpRequestHeaders& headers =
576 request_data.request->extra_request_headers(); 576 request_data.request->extra_request_headers();
577 577
578 bool passed = false; // Did some header pass TestNameValue? 578 bool passed = false; // Did some header pass TestNameValue?
579 net::HttpRequestHeaders::Iterator it(headers); 579 net::HttpRequestHeaders::Iterator it(headers);
580 while (!passed && it.GetNext()) 580 while (!passed && it.GetNext())
581 passed |= header_matcher_->TestNameValue(it.name(), it.value()); 581 passed |= header_matcher_->TestNameValue(it.name(), it.value());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 return scoped_ptr<WebRequestConditionAttribute>( 625 return scoped_ptr<WebRequestConditionAttribute>(
626 new WebRequestConditionAttributeResponseHeaders( 626 new WebRequestConditionAttributeResponseHeaders(
627 header_matcher.Pass(), name == keys::kResponseHeadersKey)); 627 header_matcher.Pass(), name == keys::kResponseHeadersKey));
628 } 628 }
629 629
630 int WebRequestConditionAttributeResponseHeaders::GetStages() const { 630 int WebRequestConditionAttributeResponseHeaders::GetStages() const {
631 return ON_HEADERS_RECEIVED; 631 return ON_HEADERS_RECEIVED;
632 } 632 }
633 633
634 bool WebRequestConditionAttributeResponseHeaders::IsFulfilled( 634 bool WebRequestConditionAttributeResponseHeaders::IsFulfilled(
635 const DeclarativeWebRequestData& request_data) const { 635 const WebRequestData& request_data) const {
636 if (!(request_data.stage & GetStages())) 636 if (!(request_data.stage & GetStages()))
637 return false; 637 return false;
638 638
639 const net::HttpResponseHeaders* headers = 639 const net::HttpResponseHeaders* headers =
640 request_data.original_response_headers; 640 request_data.original_response_headers;
641 if (headers == NULL) { 641 if (headers == NULL) {
642 // Each header of an empty set satisfies (the negation of) everything; 642 // Each header of an empty set satisfies (the negation of) everything;
643 // OTOH, there is no header to satisfy even the most permissive test. 643 // OTOH, there is no header to satisfy even the most permissive test.
644 return !positive_; 644 return !positive_;
645 } 645 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 new WebRequestConditionAttributeThirdParty(third_party)); 696 new WebRequestConditionAttributeThirdParty(third_party));
697 } 697 }
698 698
699 int WebRequestConditionAttributeThirdParty::GetStages() const { 699 int WebRequestConditionAttributeThirdParty::GetStages() const {
700 return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS | 700 return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS |
701 ON_HEADERS_RECEIVED | ON_AUTH_REQUIRED | ON_BEFORE_REDIRECT | 701 ON_HEADERS_RECEIVED | ON_AUTH_REQUIRED | ON_BEFORE_REDIRECT |
702 ON_RESPONSE_STARTED | ON_COMPLETED | ON_ERROR; 702 ON_RESPONSE_STARTED | ON_COMPLETED | ON_ERROR;
703 } 703 }
704 704
705 bool WebRequestConditionAttributeThirdParty::IsFulfilled( 705 bool WebRequestConditionAttributeThirdParty::IsFulfilled(
706 const DeclarativeWebRequestData& request_data) const { 706 const WebRequestData& request_data) const {
707 if (!(request_data.stage & GetStages())) 707 if (!(request_data.stage & GetStages()))
708 return false; 708 return false;
709 709
710 // Request is "1st party" if it gets cookies under 3rd party-blocking policy. 710 // Request is "1st party" if it gets cookies under 3rd party-blocking policy.
711 const net::StaticCookiePolicy block_third_party_policy( 711 const net::StaticCookiePolicy block_third_party_policy(
712 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES); 712 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES);
713 const int can_get_cookies = block_third_party_policy.CanGetCookies( 713 const int can_get_cookies = block_third_party_policy.CanGetCookies(
714 request_data.request->url(), 714 request_data.request->url(),
715 request_data.request->first_party_for_cookies()); 715 request_data.request->first_party_for_cookies());
716 const bool is_first_party = (can_get_cookies == net::OK); 716 const bool is_first_party = (can_get_cookies == net::OK);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 791
792 return scoped_ptr<WebRequestConditionAttribute>( 792 return scoped_ptr<WebRequestConditionAttribute>(
793 new WebRequestConditionAttributeStages(allowed_stages)); 793 new WebRequestConditionAttributeStages(allowed_stages));
794 } 794 }
795 795
796 int WebRequestConditionAttributeStages::GetStages() const { 796 int WebRequestConditionAttributeStages::GetStages() const {
797 return allowed_stages_; 797 return allowed_stages_;
798 } 798 }
799 799
800 bool WebRequestConditionAttributeStages::IsFulfilled( 800 bool WebRequestConditionAttributeStages::IsFulfilled(
801 const DeclarativeWebRequestData& request_data) const { 801 const WebRequestData& request_data) const {
802 // Note: removing '!=' triggers warning C4800 on the VS compiler. 802 // Note: removing '!=' triggers warning C4800 on the VS compiler.
803 return (request_data.stage & GetStages()) != 0; 803 return (request_data.stage & GetStages()) != 0;
804 } 804 }
805 805
806 WebRequestConditionAttribute::Type 806 WebRequestConditionAttribute::Type
807 WebRequestConditionAttributeStages::GetType() const { 807 WebRequestConditionAttributeStages::GetType() const {
808 return CONDITION_STAGES; 808 return CONDITION_STAGES;
809 } 809 }
810 810
811 } // namespace extensions 811 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698