resource_type.h revision 116680a4aac90f2aa7413d9095a592090648e557
1// Copyright 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#ifndef CONTENT_PUBLIC_COMMON_RESOURCE_TYPE_H_
6#define CONTENT_PUBLIC_COMMON_RESOURCE_TYPE_H_
7
8#include "base/macros.h"
9#include "content/common/content_export.h"
10#include "third_party/WebKit/public/platform/WebURLRequest.h"
11
12namespace content {
13
14class CONTENT_EXPORT ResourceType {
15 public:
16  // Used in histograms, so please add new types at the end, and rename unused
17  // entries to RESOURCETYPE_UNUSED_0, etc...
18  enum Type {
19    MAIN_FRAME = 0,  // top level page
20    SUB_FRAME,       // frame or iframe
21    STYLESHEET,      // a CSS stylesheet
22    SCRIPT,          // an external script
23    IMAGE,           // an image (jpg/gif/png/etc)
24    FONT_RESOURCE,   // a font
25    SUB_RESOURCE,    // an "other" subresource.
26    OBJECT,          // an object (or embed) tag for a plugin,
27                     // or a resource that a plugin requested.
28    MEDIA,           // a media resource.
29    WORKER,          // the main resource of a dedicated worker.
30    SHARED_WORKER,   // the main resource of a shared worker.
31    PREFETCH,        // an explicitly requested prefetch
32    FAVICON,         // a favicon
33    XHR,             // a XMLHttpRequest
34    PING,            // a ping request for <a ping>
35    SERVICE_WORKER,  // the main resource of a service worker.
36    LAST_TYPE        // Place holder so we don't need to change ValidType
37                     // everytime.
38  };
39
40  static Type FromTargetType(blink::WebURLRequest::TargetType type);
41
42  static bool ValidType(int32 type) {
43    return type >= MAIN_FRAME && type < LAST_TYPE;
44  }
45
46  static Type FromInt(int32 type) {
47    return static_cast<Type>(type);
48  }
49
50  static bool IsFrame(ResourceType::Type type) {
51    return type == MAIN_FRAME || type == SUB_FRAME;
52  }
53
54  static bool IsSharedWorker(ResourceType::Type type) {
55    return type == SHARED_WORKER;
56  }
57
58  static bool IsServiceWorker(ResourceType::Type type) {
59    return type == SERVICE_WORKER;
60  }
61
62  static bool IsSubresource(ResourceType::Type type) {
63    return type == STYLESHEET ||
64           type == SCRIPT ||
65           type == IMAGE ||
66           type == FONT_RESOURCE ||
67           type == SUB_RESOURCE ||
68           type == WORKER ||
69           type == XHR;
70  }
71
72 private:
73  DISALLOW_COPY_AND_ASSIGN(ResourceType);
74};
75
76}  // namespace content
77
78#endif  // CONTENT_PUBLIC_COMMON_RESOURCE_TYPE_H_
79