Upstream version 11.39.250.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / security_policy.h
1 // Copyright (c) 2014 Intel Corporation. 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 XWALK_APPLICATION_COMMON_SECURITY_POLICY_H_
6 #define XWALK_APPLICATION_COMMON_SECURITY_POLICY_H_
7
8 #include <vector>
9
10 #include "url/gurl.h"
11
12 namespace xwalk {
13 namespace application {
14
15 class Application;
16
17 // FIXME(Mikhail): Move to application/browser folder.
18 // Rename to ApplicationSecurityPolicy.
19 class SecurityPolicy {
20  public:
21   enum SecurityMode {
22     NoSecurity,
23     CSP,
24     WARP
25   };
26
27   explicit SecurityPolicy(Application* app);
28   virtual ~SecurityPolicy();
29
30   bool IsAccessAllowed(const GURL& url) const;
31
32   virtual void Enforce() = 0;
33
34  protected:
35   struct WhitelistEntry {
36     WhitelistEntry(const GURL& url, bool subdomains);
37     GURL url;
38     bool subdomains;
39
40     bool operator==(const WhitelistEntry& o) const {
41       return o.url == url && o.subdomains == subdomains;
42     }
43   };
44
45   void AddWhitelistEntry(const GURL& url, bool subdomains);
46
47   std::vector<WhitelistEntry> whitelist_entries_;
48   Application* app_;
49   bool enabled_;
50 };
51
52 class SecurityPolicyWARP : public SecurityPolicy {
53  public:
54   explicit SecurityPolicyWARP(Application* app);
55   virtual ~SecurityPolicyWARP();
56
57   virtual void Enforce() OVERRIDE;
58 };
59
60 class SecurityPolicyCSP : public SecurityPolicy {
61  public:
62   explicit SecurityPolicyCSP(Application* app);
63   virtual ~SecurityPolicyCSP();
64
65   virtual void Enforce() OVERRIDE;
66 };
67
68 }  // namespace application
69 }  // namespace xwalk
70
71 #endif  // XWALK_APPLICATION_COMMON_SECURITY_POLICY_H_