Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / transition_request_manager.h
blob65b57924134e790207ed6297c7abdd13741e77eb
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 "content/public/common/transition_element.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "url/gurl.h"
20 template <typename T>
21 struct DefaultSingletonTraits;
23 namespace net {
24 class HttpResponseHeaders;
26 class GURL;
28 namespace content {
30 // This struct passes data about an imminent transition between threads.
31 struct TransitionLayerData {
32 CONTENT_EXPORT TransitionLayerData();
33 CONTENT_EXPORT ~TransitionLayerData();
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;
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
46 // thread.
48 class TransitionRequestManager {
49 public:
50 // Returns the singleton instance.
51 CONTENT_EXPORT static TransitionRequestManager* GetInstance();
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);
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);
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);
83 CONTENT_EXPORT void ClearPendingTransitionRequestData(int render_process_id,
84 int render_frame_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;
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);
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;
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();
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_