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_
13 #include "base/basictypes.h"
14 #include "base/memory/ref_counted.h"
15 #include "content/common/content_export.h"
19 struct DefaultSingletonTraits
;
22 class HttpResponseHeaders
;
28 // This struct passes data about an imminent transition between threads.
29 struct TransitionLayerData
{
30 TransitionLayerData();
31 ~TransitionLayerData();
34 std::string css_selector
;
35 scoped_refptr
<net::HttpResponseHeaders
> response_headers
;
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
45 class TransitionRequestManager
{
47 // Returns the singleton instance.
48 CONTENT_EXPORT
static TransitionRequestManager
* GetInstance();
50 // Parses out any transition-entering-stylesheet link headers from the
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
,
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
,
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
,
78 class TransitionRequestData
{
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
);
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
;
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
),
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_