Chromium Code Reviews| Index: chrome/browser/custom_handlers/protocol_handler.cc |
| diff --git a/chrome/browser/custom_handlers/protocol_handler.cc b/chrome/browser/custom_handlers/protocol_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7682c6ffded1cafacae50eb49a563e4bae18f1d9 |
| --- /dev/null |
| +++ b/chrome/browser/custom_handlers/protocol_handler.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright (c) 2011 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. |
| + |
| +#include "chrome/browser/custom_handlers/protocol_handler.h" |
| + |
| +#include "base/string_util.h" |
| +#include "net/base/escape.h" |
| + |
| + |
|
jam
2011/02/16 18:29:37
nit: extra line
koz (OOO until 15th September)
2011/02/17 03:32:03
Removed, cheers.
|
| +ProtocolHandler::ProtocolHandler(const std::string& protocol, |
| + const GURL& url, |
| + const string16& title) |
| + : protocol_(protocol), |
| + url_(url), |
| + title_(title) { |
| +} |
| + |
| +ProtocolHandler* ProtocolHandler::CreateProtocolHandler( |
| + const std::string& protocol, |
| + const GURL& url, |
| + const string16& title) { |
| + std::string lower_protocol(protocol); |
| + lower_protocol = StringToLowerASCII(protocol); |
| + return new ProtocolHandler(lower_protocol, url, title); |
| +} |
| + |
| +ProtocolHandler* ProtocolHandler::CreateProtocolHandler( |
| + const DictionaryValue* value) { |
| + std::string protocol, url; |
| + string16 title; |
| + value->GetString("protocol", &protocol); |
| + value->GetString("url", &url); |
| + value->GetString("title", &title); |
| + return ProtocolHandler::CreateProtocolHandler(protocol, GURL(url), title); |
| +} |
| + |
| +GURL ProtocolHandler::TranslateUrl(const GURL& url) { |
| + std::string translatedUrlSpec(url_.spec()); |
| + ReplaceSubstringsAfterOffset(&translatedUrlSpec, 0, "%s", |
| + EscapeQueryParamValue(url.spec(), true)); |
| + return GURL(translatedUrlSpec); |
| +} |
| + |
| +Value* ProtocolHandler::Encode() { |
| + DictionaryValue* d = new DictionaryValue(); |
| + d->Set("protocol", Value::CreateStringValue(protocol_)); |
| + d->Set("url", Value::CreateStringValue(url_.spec())); |
| + d->Set("title", Value::CreateStringValue(title_)); |
| + return d; |
| +} |
| + |
| +bool ProtocolHandler::operator==(const ProtocolHandler &other) const { |
| + return protocol_ == other.protocol_ && |
| + url_ == other.url_ && |
| + title_ == other.title_; |
| +} |
| + |