| OLD | NEW |
| 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/web_request/web_request_api_helpers.h" | 5 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 12 #include "net/http/http_util.h" | 12 #include "net/http/http_util.h" |
| 13 #include "net/url_request/url_request.h" |
| 13 | 14 |
| 14 namespace extension_web_request_api_helpers { | 15 namespace extension_web_request_api_helpers { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 static const char* kResourceTypeStrings[] = { | 19 static const char* kResourceTypeStrings[] = { |
| 19 "main_frame", | 20 "main_frame", |
| 20 "sub_frame", | 21 "sub_frame", |
| 21 "stylesheet", | 22 "stylesheet", |
| 22 "script", | 23 "script", |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 } | 587 } |
| 587 return credentials_set; | 588 return credentials_set; |
| 588 } | 589 } |
| 589 | 590 |
| 590 namespace { | 591 namespace { |
| 591 | 592 |
| 592 // Returns true if the URL is sensitive and requests to this URL must not be | 593 // Returns true if the URL is sensitive and requests to this URL must not be |
| 593 // modified/canceled by extensions, e.g. because it is targeted to the webstore | 594 // modified/canceled by extensions, e.g. because it is targeted to the webstore |
| 594 // to check for updates, extension blacklisting, etc. | 595 // to check for updates, extension blacklisting, etc. |
| 595 bool IsSensitiveURL(const GURL& url) { | 596 bool IsSensitiveURL(const GURL& url) { |
| 597 // TODO(battre) Merge this, CanExtensionAccessURL of web_request_api.cc and |
| 598 // Extension::CanExecuteScriptOnPage into one function. |
| 596 bool is_webstore_gallery_url = | 599 bool is_webstore_gallery_url = |
| 597 StartsWithASCII(url.spec(), extension_urls::kGalleryBrowsePrefix, true); | 600 StartsWithASCII(url.spec(), extension_urls::kGalleryBrowsePrefix, true); |
| 598 bool sensitive_chrome_url = false; | 601 bool sensitive_chrome_url = false; |
| 599 if (EndsWith(url.host(), "google.com", true)) { | 602 if (EndsWith(url.host(), "google.com", true)) { |
| 600 sensitive_chrome_url |= (url.host() == "www.google.com") && | 603 sensitive_chrome_url |= (url.host() == "www.google.com") && |
| 601 StartsWithASCII(url.path(), "/chrome", true); | 604 StartsWithASCII(url.path(), "/chrome", true); |
| 602 sensitive_chrome_url |= (url.host() == "chrome.google.com"); | 605 sensitive_chrome_url |= (url.host() == "chrome.google.com"); |
| 603 if (StartsWithASCII(url.host(), "client", true)) { | 606 if (StartsWithASCII(url.host(), "client", true)) { |
| 604 for (int i = 0; i < 10; ++i) { | 607 for (int i = 0; i < 10; ++i) { |
| 605 sensitive_chrome_url |= | 608 sensitive_chrome_url |= |
| (...skipping 18 matching lines...) Expand all Loading... |
| 624 url.SchemeIs(chrome::kFileScheme) || | 627 url.SchemeIs(chrome::kFileScheme) || |
| 625 url.SchemeIs(chrome::kFileSystemScheme) || | 628 url.SchemeIs(chrome::kFileSystemScheme) || |
| 626 url.SchemeIs(chrome::kFtpScheme) || | 629 url.SchemeIs(chrome::kFtpScheme) || |
| 627 url.SchemeIs(chrome::kHttpScheme) || | 630 url.SchemeIs(chrome::kHttpScheme) || |
| 628 url.SchemeIs(chrome::kHttpsScheme) || | 631 url.SchemeIs(chrome::kHttpsScheme) || |
| 629 url.SchemeIs(chrome::kExtensionScheme)); | 632 url.SchemeIs(chrome::kExtensionScheme)); |
| 630 } | 633 } |
| 631 | 634 |
| 632 } // namespace | 635 } // namespace |
| 633 | 636 |
| 634 bool HideRequestForURL(const GURL& url) { | 637 bool HideRequest(net::URLRequest* request) { |
| 635 return IsSensitiveURL(url) || !HasWebRequestScheme(url); | 638 const GURL& url = request->url(); |
| 639 const GURL& first_party_url = request->first_party_for_cookies(); |
| 640 bool hide = false; |
| 641 if (first_party_url.is_valid()) { |
| 642 hide = IsSensitiveURL(first_party_url) || |
| 643 !HasWebRequestScheme(first_party_url); |
| 644 } |
| 645 if (!hide) |
| 646 hide = IsSensitiveURL(url) || !HasWebRequestScheme(url); |
| 647 return hide; |
| 636 } | 648 } |
| 637 | 649 |
| 638 #define ARRAYEND(array) (array + arraysize(array)) | 650 #define ARRAYEND(array) (array + arraysize(array)) |
| 639 | 651 |
| 640 bool IsRelevantResourceType(ResourceType::Type type) { | 652 bool IsRelevantResourceType(ResourceType::Type type) { |
| 641 ResourceType::Type* iter = | 653 ResourceType::Type* iter = |
| 642 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type); | 654 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type); |
| 643 return iter != ARRAYEND(kResourceTypeValues); | 655 return iter != ARRAYEND(kResourceTypeValues); |
| 644 } | 656 } |
| 645 | 657 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 656 ResourceType::Type* type) { | 668 ResourceType::Type* type) { |
| 657 const char** iter = | 669 const char** iter = |
| 658 std::find(kResourceTypeStrings, ARRAYEND(kResourceTypeStrings), type_str); | 670 std::find(kResourceTypeStrings, ARRAYEND(kResourceTypeStrings), type_str); |
| 659 if (iter == ARRAYEND(kResourceTypeStrings)) | 671 if (iter == ARRAYEND(kResourceTypeStrings)) |
| 660 return false; | 672 return false; |
| 661 *type = kResourceTypeValues[iter - kResourceTypeStrings]; | 673 *type = kResourceTypeValues[iter - kResourceTypeStrings]; |
| 662 return true; | 674 return true; |
| 663 } | 675 } |
| 664 | 676 |
| 665 } // namespace extension_web_request_api_helpers | 677 } // namespace extension_web_request_api_helpers |
| OLD | NEW |