OLD | NEW |
| (Empty) |
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_BROWSER_TRANSITION_REQUEST_MANAGER_H_ | |
6 #define CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 #include <utility> | |
11 #include <vector> | |
12 | |
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" | |
18 #include "url/gurl.h" | |
19 | |
20 template <typename T> | |
21 struct DefaultSingletonTraits; | |
22 | |
23 namespace net { | |
24 class HttpResponseHeaders; | |
25 } | |
26 class GURL; | |
27 | |
28 namespace content { | |
29 | |
30 // This struct passes data about an imminent transition between threads. | |
31 struct TransitionLayerData { | |
32 CONTENT_EXPORT TransitionLayerData(); | |
33 CONTENT_EXPORT ~TransitionLayerData(); | |
34 | |
35 std::string markup; | |
36 std::string css_selector; | |
37 std::vector<TransitionElement> elements; | |
38 scoped_refptr<net::HttpResponseHeaders> response_headers; | |
39 GURL request_url; | |
40 }; | |
41 | |
42 // TransitionRequestManager is used to handle bookkeeping for transition | |
43 // requests and responses. | |
44 // | |
45 // TransitionRequestManager is a singleton and should only be accessed on the IO | |
46 // thread. | |
47 // | |
48 class TransitionRequestManager { | |
49 public: | |
50 // Returns the singleton instance. | |
51 CONTENT_EXPORT static TransitionRequestManager* GetInstance(); | |
52 | |
53 // Parses out any transition-entering-stylesheet link headers from the | |
54 // response headers. | |
55 CONTENT_EXPORT static void ParseTransitionStylesheetsFromHeaders( | |
56 const scoped_refptr<net::HttpResponseHeaders>& headers, | |
57 std::vector<GURL>& entering_stylesheets, | |
58 const GURL& resolve_address); | |
59 | |
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 | |
63 // the data exists. | |
64 CONTENT_EXPORT bool GetPendingTransitionRequest( | |
65 int render_process_id, | |
66 int render_frame_id, | |
67 const GURL& request_url, | |
68 TransitionLayerData* transition_data); | |
69 | |
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, | |
74 int render_frame_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, | |
81 int render_frame_id); | |
82 | |
83 CONTENT_EXPORT void ClearPendingTransitionRequestData(int render_process_id, | |
84 int render_frame_id); | |
85 | |
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; | |
89 | |
90 private: | |
91 class TransitionRequestData { | |
92 public: | |
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); | |
101 | |
102 private: | |
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; | |
109 std::string markup; | |
110 std::vector<TransitionElement> elements; | |
111 | |
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); | |
116 ~AllowedEntry(); | |
117 }; | |
118 std::vector<AllowedEntry> allowed_entries_; | |
119 }; | |
120 | |
121 friend struct DefaultSingletonTraits<TransitionRequestManager>; | |
122 typedef std::map<std::pair<int, int>, TransitionRequestData> | |
123 RenderFrameRequestDataMap; | |
124 | |
125 TransitionRequestManager(); | |
126 ~TransitionRequestManager(); | |
127 | |
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_; | |
133 | |
134 DISALLOW_COPY_AND_ASSIGN(TransitionRequestManager); | |
135 }; | |
136 | |
137 } // namespace content | |
138 | |
139 #endif // CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_ | |
OLD | NEW |