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