OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/prerender/prerender_util.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "googleurl/src/url_canon.h" |
| 9 #include "googleurl/src/url_parse.h" |
| 10 #include "googleurl/src/url_util.h" |
| 11 |
| 12 namespace prerender { |
| 13 |
| 14 bool MaybeGetQueryStringBasedAliasURL( |
| 15 const GURL& url, GURL* alias_url) { |
| 16 DCHECK(alias_url); |
| 17 url_parse::Parsed parsed; |
| 18 url_parse::ParseStandardURL(url.spec().c_str(), url.spec().length(), |
| 19 &parsed); |
| 20 url_parse::Component query = parsed.query; |
| 21 url_parse::Component key, value; |
| 22 while (url_parse::ExtractQueryKeyValue(url.spec().c_str(), &query, &key, |
| 23 &value)) { |
| 24 if (key.len != 3 || strncmp(url.spec().c_str() + key.begin, "url", key.len)) |
| 25 continue; |
| 26 // We found a url= query string component. |
| 27 if (value.len < 1) |
| 28 continue; |
| 29 url_canon::RawCanonOutputW<1024> decoded_url; |
| 30 url_util::DecodeURLEscapeSequences(url.spec().c_str() + value.begin, |
| 31 value.len, &decoded_url); |
| 32 GURL new_url(string16(decoded_url.data(), decoded_url.length())); |
| 33 if (!new_url.is_empty() && new_url.is_valid()) { |
| 34 *alias_url = new_url; |
| 35 return true; |
| 36 } |
| 37 return false; |
| 38 } |
| 39 return false; |
| 40 } |
| 41 |
| 42 uint8 GetQueryStringBasedExperiment(const GURL& url) { |
| 43 url_parse::Parsed parsed; |
| 44 url_parse::ParseStandardURL(url.spec().c_str(), url.spec().length(), |
| 45 &parsed); |
| 46 url_parse::Component query = parsed.query; |
| 47 url_parse::Component key, value; |
| 48 while (url_parse::ExtractQueryKeyValue(url.spec().c_str(), &query, &key, |
| 49 &value)) { |
| 50 if (key.len != 3 || strncmp(url.spec().c_str() + key.begin, "lpe", key.len)) |
| 51 continue; |
| 52 |
| 53 // We found a lpe= query string component. |
| 54 if (value.len != 1) |
| 55 continue; |
| 56 uint8 exp = *(url.spec().c_str() + value.begin) - '0'; |
| 57 if (exp < 1 || exp > 9) |
| 58 continue; |
| 59 return exp; |
| 60 } |
| 61 return kNoExperiment; |
| 62 } |
| 63 |
| 64 } // namespace prerender |
OLD | NEW |