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/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 attributes->clear(); | 65 attributes->clear(); |
66 } | 66 } |
67 | 67 |
68 return rel_matched; | 68 return rel_matched; |
69 } | 69 } |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 namespace content { | 73 namespace content { |
74 | 74 |
75 TransitionLayerData::TransitionLayerData() { | |
76 } | |
77 | |
78 TransitionLayerData::~TransitionLayerData() { | |
79 } | |
80 | |
75 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( | 81 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( |
76 const scoped_refptr<net::HttpResponseHeaders>& headers, | 82 const scoped_refptr<net::HttpResponseHeaders>& headers, |
77 std::vector<GURL>& entering_stylesheets, | 83 std::vector<GURL>& entering_stylesheets, |
78 const GURL& resolve_address) { | 84 const GURL& resolve_address) { |
79 if (headers == NULL) | 85 if (headers == NULL) |
80 return; | 86 return; |
81 | 87 |
82 std::string transition_stylesheet; | 88 std::string transition_stylesheet; |
83 std::vector<std::pair<std::string, std::string> > attributes; | 89 std::vector<std::pair<std::string, std::string> > attributes; |
84 void* header_iter = NULL; | 90 void* header_iter = NULL; |
85 while (EnumerateLinkHeaders(headers, | 91 while (EnumerateLinkHeaders(headers, |
86 &header_iter, | 92 &header_iter, |
87 "transition-entering-stylesheet", | 93 "transition-entering-stylesheet", |
88 &transition_stylesheet, | 94 &transition_stylesheet, |
89 &attributes)) { | 95 &attributes)) { |
90 GURL stylesheet_url = resolve_address.Resolve(transition_stylesheet); | 96 GURL stylesheet_url = resolve_address.Resolve(transition_stylesheet); |
91 if (stylesheet_url.is_valid()) | 97 if (stylesheet_url.is_valid()) |
92 entering_stylesheets.push_back(stylesheet_url); | 98 entering_stylesheets.push_back(stylesheet_url); |
93 } | 99 } |
94 } | 100 } |
95 | 101 |
102 TransitionRequestManager::TransitionRequestData::TransitionRequestData() { | |
103 } | |
104 | |
105 TransitionRequestManager::TransitionRequestData::~TransitionRequestData() { | |
106 } | |
107 | |
108 void TransitionRequestManager::TransitionRequestData::AddEntry( | |
109 const std::string& origin, | |
110 const std::string& css_selector, | |
111 const std::string& markup) { | |
112 allowed_entries_.push_back(AllowedEntry(origin, css_selector, markup)); | |
113 } | |
114 | |
115 bool TransitionRequestManager::TransitionRequestData::FindEntry( | |
116 const GURL& request_url, | |
117 TransitionLayerData* transition_data) { | |
118 DCHECK(!allowed_entries_.empty()); | |
119 DCHECK(transition_data); | |
120 // FIXME(oysteine): Add CSP check to validate the origin and the request_url. | |
Charlie Reis
2014/08/05 20:07:20
nit: We use TODO(username): in the Chrome repo.
oystein (OOO til 10th of July)
2014/08/05 20:50:53
Done.
| |
121 const AllowedEntry& allowed_entry = allowed_entries_[0]; | |
122 transition_data->markup = allowed_entry.markup; | |
123 transition_data->css_selector = allowed_entry.css_selector; | |
124 return true; | |
125 } | |
126 | |
96 bool TransitionRequestManager::HasPendingTransitionRequest( | 127 bool TransitionRequestManager::HasPendingTransitionRequest( |
97 int process_id, | 128 int render_process_id, |
98 int render_frame_id) { | 129 int render_frame_id, |
130 const GURL& request_url, | |
131 TransitionLayerData* transition_data) { | |
132 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
133 DCHECK(transition_data); | |
134 std::pair<int, int> key(render_process_id, render_frame_id); | |
135 RenderFrameRequestDataMap::iterator iter = | |
136 pending_transition_frames_.find(key); | |
137 return iter != pending_transition_frames_.end() && | |
138 iter->second.FindEntry(request_url, transition_data); | |
139 } | |
140 | |
141 void TransitionRequestManager::AddPendingTransitionRequestData( | |
142 int render_process_id, | |
143 int render_frame_id, | |
144 const std::string& origin, | |
145 const std::string& css_selector, | |
146 const std::string& markup) { | |
99 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 147 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
100 | 148 |
101 std::pair<int, int> key(process_id, render_frame_id); | 149 std::pair<int, int> key(render_process_id, render_frame_id); |
102 return (pending_transition_frames_.find(key) != | 150 pending_transition_frames_[key].AddEntry(origin, css_selector, markup); |
103 pending_transition_frames_.end()); | |
104 } | 151 } |
105 | 152 |
106 void TransitionRequestManager::SetHasPendingTransitionRequest( | 153 void TransitionRequestManager::ClearPendingTransitionRequestData( |
107 int process_id, | 154 int render_process_id, int render_frame_id) { |
108 int render_frame_id, | |
109 bool has_pending) { | |
110 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 155 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
111 | 156 std::pair<int, int> key(render_process_id, render_frame_id); |
112 std::pair<int, int> key(process_id, render_frame_id); | 157 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 } | 158 } |
119 | 159 |
120 TransitionRequestManager::TransitionRequestManager() { | 160 TransitionRequestManager::TransitionRequestManager() { |
121 } | 161 } |
122 | 162 |
123 TransitionRequestManager::~TransitionRequestManager() { | 163 TransitionRequestManager::~TransitionRequestManager() { |
124 } | 164 } |
125 | 165 |
126 // static | 166 // static |
127 TransitionRequestManager* TransitionRequestManager::GetInstance() { | 167 TransitionRequestManager* TransitionRequestManager::GetInstance() { |
128 return Singleton<TransitionRequestManager>::get(); | 168 return Singleton<TransitionRequestManager>::get(); |
129 } | 169 } |
130 | 170 |
131 } // namespace content | 171 } // namespace content |
OLD | NEW |