Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: content/browser/transition_request_manager.cc

Issue 387703004: Navigation transitions: Parse out transition-entering-stylesheet link headers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit fix Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 #include "net/http/http_response_headers.h"
11 #include "net/http/http_util.h"
12
13 namespace {
14
15 // Enumerate all Link: headers with the specified relation in this
16 // response, and optionally returns the URL and any additional attributes of
17 // each one. See EnumerateHeaders for |iter| usage.
18 bool EnumerateLinkHeaders(
19 const scoped_refptr<net::HttpResponseHeaders>& headers,
20 void** iter,
21 const std::string& rel,
22 std::string* url,
23 std::vector<std::pair<std::string, std::string> >* attributes) {
24 std::string header_body;
25 bool rel_matched = false;
26 while (!rel_matched && headers->EnumerateHeader(iter, "link", &header_body)) {
27 const std::string::const_iterator begin = header_body.begin();
28 size_t url_start = header_body.find_first_of('<');
29 size_t url_end = header_body.find_first_of('>');
30 if (url_start == std::string::npos || url_end == std::string::npos ||
31 url_start > url_end) {
32 break;
33 }
34
35 if (attributes)
36 attributes->clear();
37
38 net::HttpUtil::NameValuePairsIterator param_iter(
39 begin + url_end + 1, header_body.end(), ';');
40
41 while (param_iter.GetNext()) {
42 if (LowerCaseEqualsASCII(
43 param_iter.name_begin(), param_iter.name_end(), "rel")) {
44 if (LowerCaseEqualsASCII(param_iter.value_begin(),
45 param_iter.value_end(),
46 rel.c_str())) {
47 if (url) {
48 url->assign(begin + url_start + 1, begin + url_end);
49 }
50 rel_matched = true;
51 } else {
52 break;
53 }
54 } else if (attributes) {
55 std::string attribute_name(param_iter.name_begin(),
56 param_iter.name_end());
57 std::string attribute_value(param_iter.value_begin(),
58 param_iter.value_end());
59 attributes->push_back(std::make_pair(attribute_name, attribute_value));
60 }
61 }
62 }
63
64 if (!rel_matched && attributes) {
65 attributes->clear();
66 }
67
68 return rel_matched;
69 }
70
71 } // namespace
9 72
10 namespace content { 73 namespace content {
11 74
75 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders(
76 const scoped_refptr<net::HttpResponseHeaders>& headers,
77 std::vector<GURL>& entering_stylesheets,
78 const GURL& resolve_address) {
79 if (headers == NULL)
80 return;
81
82 std::string transition_stylesheet;
83 std::vector<std::pair<std::string, std::string> > attributes;
84 void* header_iter = NULL;
85 while (EnumerateLinkHeaders(headers,
86 &header_iter,
87 "transition-entering-stylesheet",
88 &transition_stylesheet,
89 &attributes)) {
90 GURL stylesheet_url = resolve_address.Resolve(transition_stylesheet);
91 if (stylesheet_url.is_valid())
92 entering_stylesheets.push_back(stylesheet_url);
93 }
94 }
95
12 bool TransitionRequestManager::HasPendingTransitionRequest( 96 bool TransitionRequestManager::HasPendingTransitionRequest(
13 int process_id, 97 int process_id,
14 int render_frame_id) { 98 int render_frame_id) {
15 DCHECK_CURRENTLY_ON(BrowserThread::IO); 99 DCHECK_CURRENTLY_ON(BrowserThread::IO);
16 100
17 std::pair<int, int> key(process_id, render_frame_id); 101 std::pair<int, int> key(process_id, render_frame_id);
18 return (pending_transition_frames_.find(key) != 102 return (pending_transition_frames_.find(key) !=
19 pending_transition_frames_.end()); 103 pending_transition_frames_.end());
20 } 104 }
21 105
(...skipping 16 matching lines...) Expand all
38 122
39 TransitionRequestManager::~TransitionRequestManager() { 123 TransitionRequestManager::~TransitionRequestManager() {
40 } 124 }
41 125
42 // static 126 // static
43 TransitionRequestManager* TransitionRequestManager::GetInstance() { 127 TransitionRequestManager* TransitionRequestManager::GetInstance() {
44 return Singleton<TransitionRequestManager>::get(); 128 return Singleton<TransitionRequestManager>::get();
45 } 129 }
46 130
47 } // namespace content 131 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/transition_request_manager.h ('k') | content/browser/transition_request_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698