OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/transition_request_manager.h" | 5 #include "content/browser/transition_request_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 TransitionLayerData::TransitionLayerData() { | 79 TransitionLayerData::TransitionLayerData() { |
80 } | 80 } |
81 | 81 |
82 TransitionLayerData::~TransitionLayerData() { | 82 TransitionLayerData::~TransitionLayerData() { |
83 } | 83 } |
84 | 84 |
85 TransitionRequestManager::TransitionRequestData::AllowedEntry::AllowedEntry( | 85 TransitionRequestManager::TransitionRequestData::AllowedEntry::AllowedEntry( |
86 const std::string& allowed_destination_host_pattern, | 86 const std::string& allowed_destination_host_pattern, |
87 const std::string& css_selector, | 87 const std::string& css_selector, |
88 const std::string& markup, | 88 const std::string& markup, |
89 const std::vector<std::string>& names, | 89 const std::vector<TransitionElement>& elements) |
90 const std::vector<gfx::Rect>& rects) | |
91 : allowed_destination_host_pattern(allowed_destination_host_pattern), | 90 : allowed_destination_host_pattern(allowed_destination_host_pattern), |
92 css_selector(css_selector), | 91 css_selector(css_selector), |
93 markup(markup), | 92 markup(markup), |
94 names(names), | 93 elements(elements) { |
95 rects(rects) { | |
96 } | 94 } |
97 | 95 |
98 TransitionRequestManager::TransitionRequestData::AllowedEntry::~AllowedEntry() { | 96 TransitionRequestManager::TransitionRequestData::AllowedEntry::~AllowedEntry() { |
99 } | 97 } |
100 | 98 |
101 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( | 99 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( |
102 const scoped_refptr<net::HttpResponseHeaders>& headers, | 100 const scoped_refptr<net::HttpResponseHeaders>& headers, |
103 std::vector<GURL>& entering_stylesheets, | 101 std::vector<GURL>& entering_stylesheets, |
104 const GURL& resolve_address) { | 102 const GURL& resolve_address) { |
105 if (headers.get() == NULL) | 103 if (headers.get() == NULL) |
(...skipping 16 matching lines...) Expand all Loading... |
122 TransitionRequestManager::TransitionRequestData::TransitionRequestData() { | 120 TransitionRequestManager::TransitionRequestData::TransitionRequestData() { |
123 } | 121 } |
124 | 122 |
125 TransitionRequestManager::TransitionRequestData::~TransitionRequestData() { | 123 TransitionRequestManager::TransitionRequestData::~TransitionRequestData() { |
126 } | 124 } |
127 | 125 |
128 void TransitionRequestManager::TransitionRequestData::AddEntry( | 126 void TransitionRequestManager::TransitionRequestData::AddEntry( |
129 const std::string& allowed_destination_host_pattern, | 127 const std::string& allowed_destination_host_pattern, |
130 const std::string& css_selector, | 128 const std::string& css_selector, |
131 const std::string& markup, | 129 const std::string& markup, |
132 const std::vector<std::string>& names, | 130 const std::vector<TransitionElement>& elements) { |
133 const std::vector<gfx::Rect>& rects) { | |
134 allowed_entries_.push_back(AllowedEntry(allowed_destination_host_pattern, | 131 allowed_entries_.push_back(AllowedEntry(allowed_destination_host_pattern, |
135 css_selector, | 132 css_selector, |
136 markup, | 133 markup, |
137 names, | 134 elements)); |
138 rects)); | |
139 } | 135 } |
140 | 136 |
141 bool TransitionRequestManager::TransitionRequestData::FindEntry( | 137 bool TransitionRequestManager::TransitionRequestData::FindEntry( |
142 const GURL& request_url, | 138 const GURL& request_url, |
143 TransitionLayerData* transition_data) { | 139 TransitionLayerData* transition_data) { |
144 DCHECK(!allowed_entries_.empty()); | 140 DCHECK(!allowed_entries_.empty()); |
145 CHECK(transition_data); | 141 CHECK(transition_data); |
146 // TODO(oysteine): Add CSP check to validate the host pattern and the | 142 // TODO(oysteine): Add CSP check to validate the host pattern and the |
147 // request_url. Must be done before this feature is moved out from the flag. | 143 // request_url. Must be done before this feature is moved out from the flag. |
148 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 144 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
149 switches::kEnableExperimentalWebPlatformFeatures) || | 145 switches::kEnableExperimentalWebPlatformFeatures) || |
150 base::FieldTrialList::FindFullName("NavigationTransitions") == | 146 base::FieldTrialList::FindFullName("NavigationTransitions") == |
151 "Enabled"); | 147 "Enabled"); |
152 | 148 |
153 const AllowedEntry& allowed_entry = allowed_entries_[0]; | 149 const AllowedEntry& allowed_entry = allowed_entries_[0]; |
154 transition_data->markup = allowed_entry.markup; | 150 transition_data->markup = allowed_entry.markup; |
155 transition_data->css_selector = allowed_entry.css_selector; | 151 transition_data->css_selector = allowed_entry.css_selector; |
156 transition_data->names = allowed_entry.names; | 152 transition_data->elements = allowed_entry.elements; |
157 transition_data->rects = allowed_entry.rects; | |
158 return true; | 153 return true; |
159 } | 154 } |
160 | 155 |
161 bool TransitionRequestManager::HasPendingTransitionRequest( | 156 bool TransitionRequestManager::GetPendingTransitionRequest( |
162 int render_process_id, | 157 int render_process_id, |
163 int render_frame_id, | 158 int render_frame_id, |
164 const GURL& request_url, | 159 const GURL& request_url, |
165 TransitionLayerData* transition_data) { | 160 TransitionLayerData* transition_data) { |
166 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 161 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
167 DCHECK(transition_data); | 162 DCHECK(transition_data); |
168 std::pair<int, int> key(render_process_id, render_frame_id); | 163 std::pair<int, int> key(render_process_id, render_frame_id); |
169 RenderFrameRequestDataMap::iterator iter = | 164 RenderFrameRequestDataMap::iterator iter = |
170 pending_transition_frames_.find(key); | 165 pending_transition_frames_.find(key); |
171 return iter != pending_transition_frames_.end() && | 166 return iter != pending_transition_frames_.end() && |
172 iter->second.FindEntry(request_url, transition_data); | 167 iter->second.FindEntry(request_url, transition_data); |
173 } | 168 } |
174 | 169 |
175 void TransitionRequestManager::AddPendingTransitionRequestData( | 170 void TransitionRequestManager::AddPendingTransitionRequestData( |
176 int render_process_id, | 171 int render_process_id, |
177 int render_frame_id, | 172 int render_frame_id, |
178 const std::string& allowed_destination_host_pattern, | 173 const std::string& allowed_destination_host_pattern, |
179 const std::string& css_selector, | 174 const std::string& css_selector, |
180 const std::string& markup, | 175 const std::string& markup, |
181 const std::vector<std::string>& names, | 176 const std::vector<TransitionElement>& elements) { |
182 const std::vector<gfx::Rect>& rects) { | |
183 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 177 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
184 | 178 |
185 std::pair<int, int> key(render_process_id, render_frame_id); | 179 std::pair<int, int> key(render_process_id, render_frame_id); |
186 pending_transition_frames_[key].AddEntry( | 180 pending_transition_frames_[key].AddEntry( |
187 allowed_destination_host_pattern, css_selector, markup, names, rects); | 181 allowed_destination_host_pattern, css_selector, markup, elements); |
188 } | 182 } |
189 | 183 |
190 void TransitionRequestManager::AddPendingTransitionRequestDataForTesting( | 184 void TransitionRequestManager::AddPendingTransitionRequestDataForTesting( |
191 int render_process_id, | 185 int render_process_id, |
192 int render_frame_id) { | 186 int render_frame_id) { |
193 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 187 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
194 | 188 |
195 std::pair<int, int> key(render_process_id, render_frame_id); | 189 std::pair<int, int> key(render_process_id, render_frame_id); |
196 pending_transition_frames_[key].AddEntry( | 190 pending_transition_frames_[key].AddEntry( |
197 "*", /* allowed_destination_host_pattern */ | 191 "*", /* allowed_destination_host_pattern */ |
198 "", /* css_selector */ | 192 "", /* css_selector */ |
199 "", /* markup */ | 193 "", /* markup */ |
200 std::vector<std::string>(), /* names */ | 194 std::vector<TransitionElement>()); /* elements */ |
201 std::vector<gfx::Rect>()); /* rects */ | |
202 } | 195 } |
203 | 196 |
204 void TransitionRequestManager::ClearPendingTransitionRequestData( | 197 void TransitionRequestManager::ClearPendingTransitionRequestData( |
205 int render_process_id, int render_frame_id) { | 198 int render_process_id, int render_frame_id) { |
206 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 199 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
207 std::pair<int, int> key(render_process_id, render_frame_id); | 200 std::pair<int, int> key(render_process_id, render_frame_id); |
208 pending_transition_frames_.erase(key); | 201 pending_transition_frames_.erase(key); |
209 } | 202 } |
210 | 203 |
211 TransitionRequestManager::TransitionRequestManager() { | 204 TransitionRequestManager::TransitionRequestManager() { |
212 } | 205 } |
213 | 206 |
214 TransitionRequestManager::~TransitionRequestManager() { | 207 TransitionRequestManager::~TransitionRequestManager() { |
215 } | 208 } |
216 | 209 |
217 // static | 210 // static |
218 TransitionRequestManager* TransitionRequestManager::GetInstance() { | 211 TransitionRequestManager* TransitionRequestManager::GetInstance() { |
219 return Singleton<TransitionRequestManager>::get(); | 212 return Singleton<TransitionRequestManager>::get(); |
220 } | 213 } |
221 | 214 |
222 } // namespace content | 215 } // namespace content |
OLD | NEW |