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

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: 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"
9 12
10 namespace content { 13 namespace content {
11 14
15 TransitionLayerData::TransitionLayerData() { }
16
17 TransitionLayerData::~TransitionLayerData() { }
18
19 // Enumerate all Link: headers with the specified relation in this
20 // response, and optionally returns the URL and any additional attributes of
21 // each one. See EnumerateHeaders for |iter| usage.
22 bool EnumerateLinkHeaders(
jochen (gone - plz use gerrit) 2014/07/16 13:25:59 should be in an anon namespace
Zhen Wang 2014/07/18 00:56:35 Done.
23 scoped_refptr<net::HttpResponseHeaders> headers,
24 void** iter,
25 const std::string& rel,
26 std::string* url,
27 std::vector<std::pair<std::string, std::string> >* attributes) {
28 std::string header_body;
29 bool rel_matched = false;
30 while (headers->EnumerateHeader(
31 iter, "link", &header_body) && !rel_matched) {
32 const std::string::const_iterator begin = header_body.begin();
33 size_t url_start = header_body.find_first_of('<');
34 size_t url_end = header_body.find_first_of('>');
35 if (url_start == std::string::npos || url_end == std::string::npos ||
36 url_start > url_end) {
37 break;
38 }
39
40 if (attributes) {
jochen (gone - plz use gerrit) 2014/07/16 13:25:58 nit. no { } for single line bodies
Zhen Wang 2014/07/18 00:56:35 Done.
41 attributes->clear();
42 }
43
44 net::HttpUtil::NameValuePairsIterator param_iter(begin + url_end + 1,
45 header_body.end(), ';');
46
47 while (param_iter.GetNext()) {
48 if (LowerCaseEqualsASCII(param_iter.name_begin(),
49 param_iter.name_end(),
50 "rel")) {
51 if (LowerCaseEqualsASCII(param_iter.value_begin(),
52 param_iter.value_end(),
53 rel.c_str())) {
54 if (url) {
55 url->assign(begin + url_start + 1, begin + url_end);
56 }
57 rel_matched = true;
58 } else {
59 break;
60 }
61 } else if (attributes) {
62 std::string attribute_name(param_iter.name_begin(),
63 param_iter.name_end());
64 std::string attribute_value(param_iter.value_begin(),
65 param_iter.value_end());
66 attributes->push_back(std::make_pair(attribute_name,
67 attribute_value));
68 }
69 }
70 }
71
72 if (!rel_matched && attributes) {
73 attributes->clear();
74 }
75
76 return rel_matched;
77 }
78
79 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders(
80 scoped_refptr<net::HttpResponseHeaders> headers,
81 TransitionLayerData& transition_layer_data,
82 const GURL& resolve_address) {
83 std::string transition_stylesheet;
84 std::vector<std::pair<std::string, std::string> > attributes;
85 void* header_iter = NULL;
86 while (EnumerateLinkHeaders(
87 headers,
88 &header_iter,
89 "transition-entering-stylesheet",
90 &transition_stylesheet,
91 &attributes)) {
92 transition_layer_data.transition_stylesheets.push_back(
93 resolve_address.Resolve(transition_stylesheet));
94 }
95 }
jochen (gone - plz use gerrit) 2014/07/16 13:25:58 is this file clang formatted?
Zhen Wang 2014/07/18 00:56:34 Done.
96
12 bool TransitionRequestManager::HasPendingTransitionRequest( 97 bool TransitionRequestManager::HasPendingTransitionRequest(
13 int process_id, 98 int process_id,
14 int render_frame_id) { 99 int render_frame_id) {
15 DCHECK_CURRENTLY_ON(BrowserThread::IO); 100 DCHECK_CURRENTLY_ON(BrowserThread::IO);
16 101
17 std::pair<int, int> key(process_id, render_frame_id); 102 std::pair<int, int> key(process_id, render_frame_id);
18 return (pending_transition_frames_.find(key) != 103 return (pending_transition_frames_.find(key) !=
19 pending_transition_frames_.end()); 104 pending_transition_frames_.end());
20 } 105 }
21 106
(...skipping 16 matching lines...) Expand all
38 123
39 TransitionRequestManager::~TransitionRequestManager() { 124 TransitionRequestManager::~TransitionRequestManager() {
40 } 125 }
41 126
42 // static 127 // static
43 TransitionRequestManager* TransitionRequestManager::GetInstance() { 128 TransitionRequestManager* TransitionRequestManager::GetInstance() {
44 return Singleton<TransitionRequestManager>::get(); 129 return Singleton<TransitionRequestManager>::get();
45 } 130 }
46 131
47 } // namespace content 132 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698