| 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_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 13 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 14 #include "net/http/http_util.h" | 15 #include "net/http/http_util.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 // Enumerate all Link: headers with the specified relation in this | 19 // Enumerate all Link: headers with the specified relation in this |
| 19 // response, and optionally returns the URL and any additional attributes of | 20 // response, and optionally returns the URL and any additional attributes of |
| 20 // each one. See EnumerateHeaders for |iter| usage. | 21 // each one. See EnumerateHeaders for |iter| usage. |
| 21 bool EnumerateLinkHeaders( | 22 bool EnumerateLinkHeaders( |
| 22 const scoped_refptr<net::HttpResponseHeaders>& headers, | 23 const scoped_refptr<net::HttpResponseHeaders>& headers, |
| 23 void** iter, | 24 void** iter, |
| 24 const std::string& rel, | 25 const std::string& rel, |
| 25 std::string* url, | 26 std::string* url, |
| 26 std::vector<std::pair<std::string, std::string> >* attributes) { | 27 base::StringPairs* attributes) { |
| 27 std::string header_body; | 28 std::string header_body; |
| 28 bool rel_matched = false; | 29 bool rel_matched = false; |
| 29 while (!rel_matched && headers->EnumerateHeader(iter, "link", &header_body)) { | 30 while (!rel_matched && headers->EnumerateHeader(iter, "link", &header_body)) { |
| 30 const std::string::const_iterator begin = header_body.begin(); | 31 const std::string::const_iterator begin = header_body.begin(); |
| 31 size_t url_start = header_body.find_first_of('<'); | 32 size_t url_start = header_body.find_first_of('<'); |
| 32 size_t url_end = header_body.find_first_of('>'); | 33 size_t url_end = header_body.find_first_of('>'); |
| 33 if (url_start == std::string::npos || url_end == std::string::npos || | 34 if (url_start == std::string::npos || url_end == std::string::npos || |
| 34 url_start > url_end) { | 35 url_start > url_end) { |
| 35 break; | 36 break; |
| 36 } | 37 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 83 } |
| 83 | 84 |
| 84 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( | 85 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( |
| 85 const scoped_refptr<net::HttpResponseHeaders>& headers, | 86 const scoped_refptr<net::HttpResponseHeaders>& headers, |
| 86 std::vector<GURL>& entering_stylesheets, | 87 std::vector<GURL>& entering_stylesheets, |
| 87 const GURL& resolve_address) { | 88 const GURL& resolve_address) { |
| 88 if (headers.get() == NULL) | 89 if (headers.get() == NULL) |
| 89 return; | 90 return; |
| 90 | 91 |
| 91 std::string transition_stylesheet; | 92 std::string transition_stylesheet; |
| 92 std::vector<std::pair<std::string, std::string> > attributes; | 93 base::StringPairs attributes; |
| 93 void* header_iter = NULL; | 94 void* header_iter = NULL; |
| 94 while (EnumerateLinkHeaders(headers, | 95 while (EnumerateLinkHeaders(headers, |
| 95 &header_iter, | 96 &header_iter, |
| 96 "transition-entering-stylesheet", | 97 "transition-entering-stylesheet", |
| 97 &transition_stylesheet, | 98 &transition_stylesheet, |
| 98 &attributes)) { | 99 &attributes)) { |
| 99 GURL stylesheet_url = resolve_address.Resolve(transition_stylesheet); | 100 GURL stylesheet_url = resolve_address.Resolve(transition_stylesheet); |
| 100 if (stylesheet_url.is_valid()) | 101 if (stylesheet_url.is_valid()) |
| 101 entering_stylesheets.push_back(stylesheet_url); | 102 entering_stylesheets.push_back(stylesheet_url); |
| 102 } | 103 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 176 |
| 176 TransitionRequestManager::~TransitionRequestManager() { | 177 TransitionRequestManager::~TransitionRequestManager() { |
| 177 } | 178 } |
| 178 | 179 |
| 179 // static | 180 // static |
| 180 TransitionRequestManager* TransitionRequestManager::GetInstance() { | 181 TransitionRequestManager* TransitionRequestManager::GetInstance() { |
| 181 return Singleton<TransitionRequestManager>::get(); | 182 return Singleton<TransitionRequestManager>::get(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 } // namespace content | 185 } // namespace content |
| OLD | NEW |