Index: chrome/browser/net/browser_url_util.cc |
diff --git a/chrome/browser/net/browser_url_util.cc b/chrome/browser/net/browser_url_util.cc |
index 4c33181b135497e73be760a63cf139a2b75c53cb..b3e967d7611352b0f2f560511075908f5593d393 100644 |
--- a/chrome/browser/net/browser_url_util.cc |
+++ b/chrome/browser/net/browser_url_util.cc |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -8,6 +8,7 @@ |
#include "base/utf_string_conversions.h" |
#include "chrome/common/url_constants.h" |
#include "googleurl/src/gurl.h" |
+#include "googleurl/src/url_util.h" |
#include "net/base/escape.h" |
#include "net/base/net_util.h" |
#include "ui/base/clipboard/scoped_clipboard_writer.h" |
@@ -44,4 +45,28 @@ GURL AppendQueryParameter(const GURL& url, |
return url.ReplaceComponents(replacements); |
} |
+bool GetValueForKeyInQuery(const GURL& url, |
+ const std::string& search_key, |
+ std::string* out_value) { |
+ url_parse::Component query = url.parsed_for_possibly_invalid_spec().query; |
+ url_parse::Component key, value; |
+ while (url_parse::ExtractQueryKeyValue( |
+ url.spec().c_str(), &query, &key, &value)) { |
+ if (key.is_nonempty()) { |
+ std::string key_string = url.spec().substr(key.begin, key.len); |
+ if (key_string == search_key) { |
+ if (value.is_nonempty()) { |
+ *out_value = net::UnescapeURLComponent( |
+ url.spec().substr(value.begin, value.len), |
+ net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); |
+ } else { |
+ *out_value = ""; |
+ } |
+ return true; |
+ } |
+ } |
+ } |
+ return false; |
+} |
+ |
} // namespace chrome_browser_net |