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

Side by Side Diff: extensions/browser/api/web_request/web_request_api_utils.cc

Issue 562913002: Move web_request_condition* files to extensions/browser/api/declarative_webrequest/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to master@294403 Created 6 years, 3 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
« no previous file with comments | « extensions/browser/api/web_request/web_request_api_utils.h ('k') | extensions/extensions.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "extensions/browser/api/web_request/web_request_api_utils.h"
6
7 #include <algorithm>
8
9 #include "base/macros.h"
10
11 namespace extension_web_request_api_utils {
12
13 namespace {
14
15 static const char* kResourceTypeStrings[] = {
16 "main_frame",
17 "sub_frame",
18 "stylesheet",
19 "script",
20 "image",
21 "object",
22 "xmlhttprequest",
23 "other",
24 "other",
25 };
26
27 static ResourceType kResourceTypeValues[] = {
28 content::RESOURCE_TYPE_MAIN_FRAME,
29 content::RESOURCE_TYPE_SUB_FRAME,
30 content::RESOURCE_TYPE_STYLESHEET,
31 content::RESOURCE_TYPE_SCRIPT,
32 content::RESOURCE_TYPE_IMAGE,
33 content::RESOURCE_TYPE_OBJECT,
34 content::RESOURCE_TYPE_XHR,
35 content::RESOURCE_TYPE_LAST_TYPE, // represents "other"
36 // TODO(jochen): We duplicate the last entry, so the array's size is not a
37 // power of two. If it is, this triggers a bug in gcc 4.4 in Release builds
38 // (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43949). Once we use a version
39 // of gcc with this bug fixed, or the array is changed so this duplicate
40 // entry is no longer required, this should be removed.
41 content::RESOURCE_TYPE_LAST_TYPE,
42 };
43
44 }
45
46 #define ARRAYEND(array) (array + arraysize(array))
47
48 bool IsRelevantResourceType(ResourceType type) {
49 ResourceType* iter =
50 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type);
51 return iter != ARRAYEND(kResourceTypeValues);
52 }
53
54 const char* ResourceTypeToString(ResourceType type) {
55 ResourceType* iter =
56 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type);
57 if (iter == ARRAYEND(kResourceTypeValues))
58 return "other";
59
60 return kResourceTypeStrings[iter - kResourceTypeValues];
61 }
62
63 bool ParseResourceType(const std::string& type_str,
64 ResourceType* type) {
65 const char** iter =
66 std::find(kResourceTypeStrings, ARRAYEND(kResourceTypeStrings), type_str);
67 if (iter == ARRAYEND(kResourceTypeStrings))
68 return false;
69 *type = kResourceTypeValues[iter - kResourceTypeStrings];
70 return true;
71 }
72
73 } // namespace extension_web_request_api_utils
OLDNEW
« no previous file with comments | « extensions/browser/api/web_request/web_request_api_utils.h ('k') | extensions/extensions.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698