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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } // namespace | 75 } // namespace |
76 | 76 |
77 namespace content { | 77 namespace content { |
78 | 78 |
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( |
| 86 const std::string& allowed_destination_host_pattern, |
| 87 const std::string& css_selector, |
| 88 const std::string& markup, |
| 89 const std::vector<std::string>& names, |
| 90 const std::vector<gfx::Rect>& rects) |
| 91 : allowed_destination_host_pattern(allowed_destination_host_pattern), |
| 92 css_selector(css_selector), |
| 93 markup(markup), |
| 94 names(names), |
| 95 rects(rects) { |
| 96 } |
| 97 |
| 98 TransitionRequestManager::TransitionRequestData::AllowedEntry::~AllowedEntry() { |
| 99 } |
| 100 |
85 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( | 101 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( |
86 const scoped_refptr<net::HttpResponseHeaders>& headers, | 102 const scoped_refptr<net::HttpResponseHeaders>& headers, |
87 std::vector<GURL>& entering_stylesheets, | 103 std::vector<GURL>& entering_stylesheets, |
88 const GURL& resolve_address) { | 104 const GURL& resolve_address) { |
89 if (headers.get() == NULL) | 105 if (headers.get() == NULL) |
90 return; | 106 return; |
91 | 107 |
92 std::string transition_stylesheet; | 108 std::string transition_stylesheet; |
93 base::StringPairs attributes; | 109 base::StringPairs attributes; |
94 void* header_iter = NULL; | 110 void* header_iter = NULL; |
(...skipping 10 matching lines...) Expand all Loading... |
105 | 121 |
106 TransitionRequestManager::TransitionRequestData::TransitionRequestData() { | 122 TransitionRequestManager::TransitionRequestData::TransitionRequestData() { |
107 } | 123 } |
108 | 124 |
109 TransitionRequestManager::TransitionRequestData::~TransitionRequestData() { | 125 TransitionRequestManager::TransitionRequestData::~TransitionRequestData() { |
110 } | 126 } |
111 | 127 |
112 void TransitionRequestManager::TransitionRequestData::AddEntry( | 128 void TransitionRequestManager::TransitionRequestData::AddEntry( |
113 const std::string& allowed_destination_host_pattern, | 129 const std::string& allowed_destination_host_pattern, |
114 const std::string& css_selector, | 130 const std::string& css_selector, |
115 const std::string& markup) { | 131 const std::string& markup, |
| 132 const std::vector<std::string>& names, |
| 133 const std::vector<gfx::Rect>& rects) { |
116 allowed_entries_.push_back(AllowedEntry(allowed_destination_host_pattern, | 134 allowed_entries_.push_back(AllowedEntry(allowed_destination_host_pattern, |
117 css_selector, | 135 css_selector, |
118 markup)); | 136 markup, |
| 137 names, |
| 138 rects)); |
119 } | 139 } |
120 | 140 |
121 bool TransitionRequestManager::TransitionRequestData::FindEntry( | 141 bool TransitionRequestManager::TransitionRequestData::FindEntry( |
122 const GURL& request_url, | 142 const GURL& request_url, |
123 TransitionLayerData* transition_data) { | 143 TransitionLayerData* transition_data) { |
124 DCHECK(!allowed_entries_.empty()); | 144 DCHECK(!allowed_entries_.empty()); |
125 CHECK(transition_data); | 145 CHECK(transition_data); |
126 // TODO(oysteine): Add CSP check to validate the host pattern and the | 146 // TODO(oysteine): Add CSP check to validate the host pattern and the |
127 // request_url. Must be done before this feature is moved out from the flag. | 147 // request_url. Must be done before this feature is moved out from the flag. |
128 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 148 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
129 switches::kEnableExperimentalWebPlatformFeatures) || | 149 switches::kEnableExperimentalWebPlatformFeatures) || |
130 base::FieldTrialList::FindFullName("NavigationTransitions") == | 150 base::FieldTrialList::FindFullName("NavigationTransitions") == |
131 "Enabled"); | 151 "Enabled"); |
132 | 152 |
133 const AllowedEntry& allowed_entry = allowed_entries_[0]; | 153 const AllowedEntry& allowed_entry = allowed_entries_[0]; |
134 transition_data->markup = allowed_entry.markup; | 154 transition_data->markup = allowed_entry.markup; |
135 transition_data->css_selector = allowed_entry.css_selector; | 155 transition_data->css_selector = allowed_entry.css_selector; |
| 156 transition_data->names = allowed_entry.names; |
| 157 transition_data->rects = allowed_entry.rects; |
136 return true; | 158 return true; |
137 } | 159 } |
138 | 160 |
139 bool TransitionRequestManager::HasPendingTransitionRequest( | 161 bool TransitionRequestManager::HasPendingTransitionRequest( |
140 int render_process_id, | 162 int render_process_id, |
141 int render_frame_id, | 163 int render_frame_id, |
142 const GURL& request_url, | 164 const GURL& request_url, |
143 TransitionLayerData* transition_data) { | 165 TransitionLayerData* transition_data) { |
144 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 166 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
145 DCHECK(transition_data); | 167 DCHECK(transition_data); |
146 std::pair<int, int> key(render_process_id, render_frame_id); | 168 std::pair<int, int> key(render_process_id, render_frame_id); |
147 RenderFrameRequestDataMap::iterator iter = | 169 RenderFrameRequestDataMap::iterator iter = |
148 pending_transition_frames_.find(key); | 170 pending_transition_frames_.find(key); |
149 return iter != pending_transition_frames_.end() && | 171 return iter != pending_transition_frames_.end() && |
150 iter->second.FindEntry(request_url, transition_data); | 172 iter->second.FindEntry(request_url, transition_data); |
151 } | 173 } |
152 | 174 |
153 void TransitionRequestManager::AddPendingTransitionRequestData( | 175 void TransitionRequestManager::AddPendingTransitionRequestData( |
154 int render_process_id, | 176 int render_process_id, |
155 int render_frame_id, | 177 int render_frame_id, |
156 const std::string& allowed_destination_host_pattern, | 178 const std::vector<std::string>& data, |
157 const std::string& css_selector, | 179 const std::vector<std::string>& names, |
158 const std::string& markup) { | 180 const std::vector<gfx::Rect>& rects) { |
159 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 181 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
160 | 182 |
161 std::pair<int, int> key(render_process_id, render_frame_id); | 183 std::pair<int, int> key(render_process_id, render_frame_id); |
162 pending_transition_frames_[key].AddEntry(allowed_destination_host_pattern, | 184 |
163 css_selector, | 185 // data[0]: allowed_destination_host_pattern |
164 markup); | 186 // data[1]: selector |
| 187 // data[2]: markup |
| 188 if (data.size() == 3) { |
| 189 pending_transition_frames_[key].AddEntry( |
| 190 data[0], data[1], data[2], names, rects); |
| 191 } else { |
| 192 // for testing |
| 193 pending_transition_frames_[key].AddEntry("*", "", "", names, rects); |
| 194 } |
165 } | 195 } |
166 | 196 |
167 void TransitionRequestManager::ClearPendingTransitionRequestData( | 197 void TransitionRequestManager::ClearPendingTransitionRequestData( |
168 int render_process_id, int render_frame_id) { | 198 int render_process_id, int render_frame_id) { |
169 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 199 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
170 std::pair<int, int> key(render_process_id, render_frame_id); | 200 std::pair<int, int> key(render_process_id, render_frame_id); |
171 pending_transition_frames_.erase(key); | 201 pending_transition_frames_.erase(key); |
172 } | 202 } |
173 | 203 |
174 TransitionRequestManager::TransitionRequestManager() { | 204 TransitionRequestManager::TransitionRequestManager() { |
175 } | 205 } |
176 | 206 |
177 TransitionRequestManager::~TransitionRequestManager() { | 207 TransitionRequestManager::~TransitionRequestManager() { |
178 } | 208 } |
179 | 209 |
180 // static | 210 // static |
181 TransitionRequestManager* TransitionRequestManager::GetInstance() { | 211 TransitionRequestManager* TransitionRequestManager::GetInstance() { |
182 return Singleton<TransitionRequestManager>::get(); | 212 return Singleton<TransitionRequestManager>::get(); |
183 } | 213 } |
184 | 214 |
185 } // namespace content | 215 } // namespace content |
OLD | NEW |