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/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/metrics/field_trial.h" |
8 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
9 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/common/content_switches.h" |
10 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
11 #include "net/http/http_util.h" | 14 #include "net/http/http_util.h" |
12 | 15 |
13 namespace { | 16 namespace { |
14 | 17 |
15 // Enumerate all Link: headers with the specified relation in this | 18 // Enumerate all Link: headers with the specified relation in this |
16 // response, and optionally returns the URL and any additional attributes of | 19 // response, and optionally returns the URL and any additional attributes of |
17 // each one. See EnumerateHeaders for |iter| usage. | 20 // each one. See EnumerateHeaders for |iter| usage. |
18 bool EnumerateLinkHeaders( | 21 bool EnumerateLinkHeaders( |
19 const scoped_refptr<net::HttpResponseHeaders>& headers, | 22 const scoped_refptr<net::HttpResponseHeaders>& headers, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 attributes->clear(); | 68 attributes->clear(); |
66 } | 69 } |
67 | 70 |
68 return rel_matched; | 71 return rel_matched; |
69 } | 72 } |
70 | 73 |
71 } // namespace | 74 } // namespace |
72 | 75 |
73 namespace content { | 76 namespace content { |
74 | 77 |
| 78 TransitionLayerData::TransitionLayerData() { |
| 79 } |
| 80 |
| 81 TransitionLayerData::~TransitionLayerData() { |
| 82 } |
| 83 |
75 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( | 84 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( |
76 const scoped_refptr<net::HttpResponseHeaders>& headers, | 85 const scoped_refptr<net::HttpResponseHeaders>& headers, |
77 std::vector<GURL>& entering_stylesheets, | 86 std::vector<GURL>& entering_stylesheets, |
78 const GURL& resolve_address) { | 87 const GURL& resolve_address) { |
79 if (headers == NULL) | 88 if (headers == NULL) |
80 return; | 89 return; |
81 | 90 |
82 std::string transition_stylesheet; | 91 std::string transition_stylesheet; |
83 std::vector<std::pair<std::string, std::string> > attributes; | 92 std::vector<std::pair<std::string, std::string> > attributes; |
84 void* header_iter = NULL; | 93 void* header_iter = NULL; |
85 while (EnumerateLinkHeaders(headers, | 94 while (EnumerateLinkHeaders(headers, |
86 &header_iter, | 95 &header_iter, |
87 "transition-entering-stylesheet", | 96 "transition-entering-stylesheet", |
88 &transition_stylesheet, | 97 &transition_stylesheet, |
89 &attributes)) { | 98 &attributes)) { |
90 GURL stylesheet_url = resolve_address.Resolve(transition_stylesheet); | 99 GURL stylesheet_url = resolve_address.Resolve(transition_stylesheet); |
91 if (stylesheet_url.is_valid()) | 100 if (stylesheet_url.is_valid()) |
92 entering_stylesheets.push_back(stylesheet_url); | 101 entering_stylesheets.push_back(stylesheet_url); |
93 } | 102 } |
94 } | 103 } |
95 | 104 |
| 105 TransitionRequestManager::TransitionRequestData::TransitionRequestData() { |
| 106 } |
| 107 |
| 108 TransitionRequestManager::TransitionRequestData::~TransitionRequestData() { |
| 109 } |
| 110 |
| 111 void TransitionRequestManager::TransitionRequestData::AddEntry( |
| 112 const std::string& allowed_destination_host_pattern, |
| 113 const std::string& css_selector, |
| 114 const std::string& markup) { |
| 115 allowed_entries_.push_back(AllowedEntry(allowed_destination_host_pattern, |
| 116 css_selector, |
| 117 markup)); |
| 118 } |
| 119 |
| 120 bool TransitionRequestManager::TransitionRequestData::FindEntry( |
| 121 const GURL& request_url, |
| 122 TransitionLayerData* transition_data) { |
| 123 DCHECK(!allowed_entries_.empty()); |
| 124 CHECK(transition_data); |
| 125 // TODO(oysteine): Add CSP check to validate the host pattern and the |
| 126 // request_url. Must be done before this feature is moved out from the flag. |
| 127 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
| 128 switches::kEnableExperimentalWebPlatformFeatures) || |
| 129 base::FieldTrialList::FindFullName("NavigationTransitions") == |
| 130 "Enabled"); |
| 131 |
| 132 const AllowedEntry& allowed_entry = allowed_entries_[0]; |
| 133 transition_data->markup = allowed_entry.markup; |
| 134 transition_data->css_selector = allowed_entry.css_selector; |
| 135 return true; |
| 136 } |
| 137 |
96 bool TransitionRequestManager::HasPendingTransitionRequest( | 138 bool TransitionRequestManager::HasPendingTransitionRequest( |
97 int process_id, | 139 int render_process_id, |
98 int render_frame_id) { | 140 int render_frame_id, |
| 141 const GURL& request_url, |
| 142 TransitionLayerData* transition_data) { |
| 143 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 144 DCHECK(transition_data); |
| 145 std::pair<int, int> key(render_process_id, render_frame_id); |
| 146 RenderFrameRequestDataMap::iterator iter = |
| 147 pending_transition_frames_.find(key); |
| 148 return iter != pending_transition_frames_.end() && |
| 149 iter->second.FindEntry(request_url, transition_data); |
| 150 } |
| 151 |
| 152 void TransitionRequestManager::AddPendingTransitionRequestData( |
| 153 int render_process_id, |
| 154 int render_frame_id, |
| 155 const std::string& allowed_destination_host_pattern, |
| 156 const std::string& css_selector, |
| 157 const std::string& markup) { |
99 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 158 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
100 | 159 |
101 std::pair<int, int> key(process_id, render_frame_id); | 160 std::pair<int, int> key(render_process_id, render_frame_id); |
102 return (pending_transition_frames_.find(key) != | 161 pending_transition_frames_[key].AddEntry(allowed_destination_host_pattern, |
103 pending_transition_frames_.end()); | 162 css_selector, |
| 163 markup); |
104 } | 164 } |
105 | 165 |
106 void TransitionRequestManager::SetHasPendingTransitionRequest( | 166 void TransitionRequestManager::ClearPendingTransitionRequestData( |
107 int process_id, | 167 int render_process_id, int render_frame_id) { |
108 int render_frame_id, | |
109 bool has_pending) { | |
110 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 168 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
111 | 169 std::pair<int, int> key(render_process_id, render_frame_id); |
112 std::pair<int, int> key(process_id, render_frame_id); | 170 pending_transition_frames_.erase(key); |
113 if (has_pending) { | |
114 pending_transition_frames_.insert(key); | |
115 } else { | |
116 pending_transition_frames_.erase(key); | |
117 } | |
118 } | 171 } |
119 | 172 |
120 TransitionRequestManager::TransitionRequestManager() { | 173 TransitionRequestManager::TransitionRequestManager() { |
121 } | 174 } |
122 | 175 |
123 TransitionRequestManager::~TransitionRequestManager() { | 176 TransitionRequestManager::~TransitionRequestManager() { |
124 } | 177 } |
125 | 178 |
126 // static | 179 // static |
127 TransitionRequestManager* TransitionRequestManager::GetInstance() { | 180 TransitionRequestManager* TransitionRequestManager::GetInstance() { |
128 return Singleton<TransitionRequestManager>::get(); | 181 return Singleton<TransitionRequestManager>::get(); |
129 } | 182 } |
130 | 183 |
131 } // namespace content | 184 } // namespace content |
OLD | NEW |