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

Side by Side Diff: chrome/browser/extensions/api/web_request/web_request_api_helpers.cc

Issue 10012004: Implemented proper support for checking schemes and requested resource types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed 'scheme' to 'schemes' Created 8 years, 8 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/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 13
14 namespace extension_web_request_api_helpers { 14 namespace extension_web_request_api_helpers {
15 15
16 namespace {
17
18 static const char* kResourceTypeStrings[] = {
19 "main_frame",
20 "sub_frame",
21 "stylesheet",
22 "script",
23 "image",
24 "object",
25 "xmlhttprequest",
26 "other",
27 "other",
28 };
29
30 static ResourceType::Type kResourceTypeValues[] = {
31 ResourceType::MAIN_FRAME,
32 ResourceType::SUB_FRAME,
33 ResourceType::STYLESHEET,
34 ResourceType::SCRIPT,
35 ResourceType::IMAGE,
36 ResourceType::OBJECT,
37 ResourceType::XHR,
38 ResourceType::LAST_TYPE, // represents "other"
39 // TODO(jochen): We duplicate the last entry, so the array's size is not a
40 // power of two. If it is, this triggers a bug in gcc 4.4 in Release builds
41 // (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43949). Once we use a version
42 // of gcc with this bug fixed, or the array is changed so this duplicate
43 // entry is no longer required, this should be removed.
44 ResourceType::LAST_TYPE,
45 };
46
47 COMPILE_ASSERT(
48 arraysize(kResourceTypeStrings) == arraysize(kResourceTypeValues),
49 keep_resource_types_in_sync);
50
51 } // namespace
52
16 53
17 EventResponseDelta::EventResponseDelta( 54 EventResponseDelta::EventResponseDelta(
18 const std::string& extension_id, const base::Time& extension_install_time) 55 const std::string& extension_id, const base::Time& extension_install_time)
19 : extension_id(extension_id), 56 : extension_id(extension_id),
20 extension_install_time(extension_install_time), 57 extension_install_time(extension_install_time),
21 cancel(false) { 58 cancel(false) {
22 } 59 }
23 60
24 EventResponseDelta::~EventResponseDelta() { 61 EventResponseDelta::~EventResponseDelta() {
25 } 62 }
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 url.SchemeIs(chrome::kHttpsScheme) || 625 url.SchemeIs(chrome::kHttpsScheme) ||
589 url.SchemeIs(chrome::kExtensionScheme)); 626 url.SchemeIs(chrome::kExtensionScheme));
590 } 627 }
591 628
592 } // namespace 629 } // namespace
593 630
594 bool HideRequestForURL(const GURL& url) { 631 bool HideRequestForURL(const GURL& url) {
595 return IsSensitiveURL(url) || !HasWebRequestScheme(url); 632 return IsSensitiveURL(url) || !HasWebRequestScheme(url);
596 } 633 }
597 634
635 #define ARRAYEND(array) (array + arraysize(array))
636
637 bool IsRelevantResourceType(ResourceType::Type type) {
638 ResourceType::Type* iter =
639 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type);
640 return iter != ARRAYEND(kResourceTypeValues);
641 }
642
643 const char* ResourceTypeToString(ResourceType::Type type) {
644 ResourceType::Type* iter =
645 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type);
646 if (iter == ARRAYEND(kResourceTypeValues))
647 return "other";
648
649 return kResourceTypeStrings[iter - kResourceTypeValues];
650 }
651
652 bool ParseResourceType(const std::string& type_str,
653 ResourceType::Type* type) {
654 const char** iter =
655 std::find(kResourceTypeStrings, ARRAYEND(kResourceTypeStrings), type_str);
656 if (iter == ARRAYEND(kResourceTypeStrings))
657 return false;
658 *type = kResourceTypeValues[iter - kResourceTypeStrings];
659 return true;
660 }
661
598 } // namespace extension_web_request_api_helpers 662 } // namespace extension_web_request_api_helpers
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/web_request/web_request_api_helpers.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698