Implement SSLKEYLOGFILE for OpenSSL.
[chromium-blink-merge.git] / content / browser / transition_request_manager.h
blob0a01878eb1a5f6d3f7a0e3bbacaf8ae3216bce3f
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.
5 #ifndef CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_
6 #define CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_
8 #include <map>
9 #include <string>
10 #include <utility>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/memory/ref_counted.h"
15 #include "content/common/content_export.h"
16 #include "url/gurl.h"
18 template <typename T>
19 struct DefaultSingletonTraits;
21 namespace net {
22 class HttpResponseHeaders;
24 class GURL;
26 namespace content {
28 // This struct passes data about an imminent transition between threads.
29 struct TransitionLayerData {
30 TransitionLayerData();
31 ~TransitionLayerData();
33 std::string markup;
34 std::string css_selector;
35 scoped_refptr<net::HttpResponseHeaders> response_headers;
36 GURL request_url;
39 // TransitionRequestManager is used to handle bookkeeping for transition
40 // requests and responses.
42 // TransitionRequestManager is a singleton and should only be accessed on the IO
43 // thread.
45 class TransitionRequestManager {
46 public:
47 // Returns the singleton instance.
48 CONTENT_EXPORT static TransitionRequestManager* GetInstance();
50 // Parses out any transition-entering-stylesheet link headers from the
51 // response headers.
52 CONTENT_EXPORT static void ParseTransitionStylesheetsFromHeaders(
53 const scoped_refptr<net::HttpResponseHeaders>& headers,
54 std::vector<GURL>& entering_stylesheets,
55 const GURL& resolve_address);
57 // Returns whether the RenderFrameHost specified by the given IDs currently
58 // has any pending transition request data. If so, we will have to delay the
59 // response until the embedder resumes the request.
60 bool HasPendingTransitionRequest(int render_process_id,
61 int render_frame_id,
62 const GURL& request_url,
63 TransitionLayerData* transition_data);
65 // Adds pending request data for a transition navigation for the
66 // RenderFrameHost specified by the given IDs.
67 CONTENT_EXPORT void AddPendingTransitionRequestData(
68 int render_process_id,
69 int render_frame_id,
70 const std::string& allowed_destination_host_pattern,
71 const std::string& css_selector,
72 const std::string& markup);
74 void ClearPendingTransitionRequestData(int render_process_id,
75 int render_frame_id);
77 private:
78 class TransitionRequestData {
79 public:
80 TransitionRequestData();
81 ~TransitionRequestData();
82 void AddEntry(const std::string& allowed_destination_host_pattern,
83 const std::string& selector,
84 const std::string& markup);
85 bool FindEntry(const GURL& request_url,
86 TransitionLayerData* transition_data);
88 private:
89 struct AllowedEntry {
90 // These strings could have originated from a compromised renderer,
91 // and should not be trusted or assumed safe. They are only used within
92 // a sandboxed iframe with scripts disabled.
93 std::string allowed_destination_host_pattern;
94 std::string css_selector;
95 std::string markup;
97 AllowedEntry(const std::string& allowed_destination_host_pattern,
98 const std::string& css_selector,
99 const std::string& markup) :
100 allowed_destination_host_pattern(allowed_destination_host_pattern),
101 css_selector(css_selector),
102 markup(markup) {}
104 std::vector<AllowedEntry> allowed_entries_;
107 friend struct DefaultSingletonTraits<TransitionRequestManager>;
108 typedef std::map<std::pair<int, int>, TransitionRequestData>
109 RenderFrameRequestDataMap;
111 TransitionRequestManager();
112 ~TransitionRequestManager();
114 // Map of (render_process_host_id, render_frame_id) pairs of all
115 // RenderFrameHosts that have pending cross-site requests and their data.
116 // Used to pass information to the CrossSiteResourceHandler without doing a
117 // round-trip between IO->UI->IO threads.
118 RenderFrameRequestDataMap pending_transition_frames_;
120 DISALLOW_COPY_AND_ASSIGN(TransitionRequestManager);
123 } // namespace content
125 #endif // CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_