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"
16 #include "content/public/common/transition_element.h"
17 #include "ui/gfx/geometry/rect.h"
21 struct DefaultSingletonTraits
;
24 class HttpResponseHeaders
;
30 // This struct passes data about an imminent transition between threads.
31 struct TransitionLayerData
{
32 CONTENT_EXPORT
TransitionLayerData();
33 CONTENT_EXPORT
~TransitionLayerData();
36 std::string css_selector
;
37 std::vector
<TransitionElement
> elements
;
38 scoped_refptr
<net::HttpResponseHeaders
> response_headers
;
42 // TransitionRequestManager is used to handle bookkeeping for transition
43 // requests and responses.
45 // TransitionRequestManager is a singleton and should only be accessed on the IO
48 class TransitionRequestManager
{
50 // Returns the singleton instance.
51 CONTENT_EXPORT
static TransitionRequestManager
* GetInstance();
53 // Parses out any transition-entering-stylesheet link headers from the
55 CONTENT_EXPORT
static void ParseTransitionStylesheetsFromHeaders(
56 const scoped_refptr
<net::HttpResponseHeaders
>& headers
,
57 std::vector
<GURL
>& entering_stylesheets
,
58 const GURL
& resolve_address
);
60 // Get pending transition request data from RenderFrameHost specified by the
61 // given IDs and return true if the data exists. For web to web transition, we
62 // will have to delay the response until the embedder resumes the request if
64 CONTENT_EXPORT
bool GetPendingTransitionRequest(
65 int render_process_id
,
67 const GURL
& request_url
,
68 TransitionLayerData
* transition_data
);
70 // Adds pending request data for a transition navigation for the
71 // RenderFrameHost specified by the given IDs.
72 CONTENT_EXPORT
void AddPendingTransitionRequestData(
73 int render_process_id
,
75 const std::string
& allowed_destination_host_pattern
,
76 const std::string
& css_selector
,
77 const std::string
& markup
,
78 const std::vector
<TransitionElement
>& elements
);
79 CONTENT_EXPORT
void AddPendingTransitionRequestDataForTesting(
80 int render_process_id
,
83 CONTENT_EXPORT
void ClearPendingTransitionRequestData(int render_process_id
,
86 // The maximum number of elements is meant to avoid passing arbitrarily large
87 // amount of objects across the IPC boundary.
88 static const int kMaxNumOfElements
= 1024;
91 class TransitionRequestData
{
93 TransitionRequestData();
94 ~TransitionRequestData();
95 void AddEntry(const std::string
& allowed_destination_host_pattern
,
96 const std::string
& selector
,
97 const std::string
& markup
,
98 const std::vector
<TransitionElement
>& elements
);
99 bool FindEntry(const GURL
& request_url
,
100 TransitionLayerData
* transition_data
);
103 struct AllowedEntry
{
104 // These strings could have originated from a compromised renderer,
105 // and should not be trusted or assumed safe. They are only used within
106 // a sandboxed iframe with scripts disabled.
107 std::string allowed_destination_host_pattern
;
108 std::string css_selector
;
110 std::vector
<TransitionElement
> elements
;
112 AllowedEntry(const std::string
& allowed_destination_host_pattern
,
113 const std::string
& css_selector
,
114 const std::string
& markup
,
115 const std::vector
<TransitionElement
>& elements
);
118 std::vector
<AllowedEntry
> allowed_entries_
;
121 friend struct DefaultSingletonTraits
<TransitionRequestManager
>;
122 typedef std::map
<std::pair
<int, int>, TransitionRequestData
>
123 RenderFrameRequestDataMap
;
125 TransitionRequestManager();
126 ~TransitionRequestManager();
128 // Map of (render_process_host_id, render_frame_id) pairs of all
129 // RenderFrameHosts that have pending cross-site requests and their data.
130 // Used to pass information to the CrossSiteResourceHandler without doing a
131 // round-trip between IO->UI->IO threads.
132 RenderFrameRequestDataMap pending_transition_frames_
;
134 DISALLOW_COPY_AND_ASSIGN(TransitionRequestManager
);
137 } // namespace content
139 #endif // CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_