OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/custom_handlers/protocol_handler.h" | 5 #include "chrome/common/custom_handlers/protocol_handler.h" |
6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
7 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
10 | 11 |
11 | 12 |
12 ProtocolHandler::ProtocolHandler(const std::string& protocol, | 13 ProtocolHandler::ProtocolHandler(const std::string& protocol, |
13 const GURL& url) | 14 const GURL& url) |
14 : protocol_(protocol), | 15 : protocol_(protocol), |
15 url_(url) { | 16 url_(url) { |
16 } | 17 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 return ProtocolHandler::CreateProtocolHandler(protocol, GURL(url)); | 52 return ProtocolHandler::CreateProtocolHandler(protocol, GURL(url)); |
52 } | 53 } |
53 | 54 |
54 GURL ProtocolHandler::TranslateUrl(const GURL& url) const { | 55 GURL ProtocolHandler::TranslateUrl(const GURL& url) const { |
55 std::string translatedUrlSpec(url_.spec()); | 56 std::string translatedUrlSpec(url_.spec()); |
56 base::ReplaceSubstringsAfterOffset(&translatedUrlSpec, 0, "%s", | 57 base::ReplaceSubstringsAfterOffset(&translatedUrlSpec, 0, "%s", |
57 net::EscapeQueryParamValue(url.spec(), true)); | 58 net::EscapeQueryParamValue(url.spec(), true)); |
58 return GURL(translatedUrlSpec); | 59 return GURL(translatedUrlSpec); |
59 } | 60 } |
60 | 61 |
61 base::DictionaryValue* ProtocolHandler::Encode() const { | 62 std::unique_ptr<base::DictionaryValue> ProtocolHandler::Encode() const { |
62 base::DictionaryValue* d = new base::DictionaryValue(); | 63 auto d = base::MakeUnique<base::DictionaryValue>(); |
63 d->Set("protocol", new base::StringValue(protocol_)); | 64 d->Set("protocol", new base::StringValue(protocol_)); |
64 d->Set("url", new base::StringValue(url_.spec())); | 65 d->Set("url", new base::StringValue(url_.spec())); |
65 return d; | 66 return d; |
66 } | 67 } |
67 | 68 |
68 #if !defined(NDEBUG) | 69 #if !defined(NDEBUG) |
69 std::string ProtocolHandler::ToString() const { | 70 std::string ProtocolHandler::ToString() const { |
70 return "{ protocol=" + protocol_ + | 71 return "{ protocol=" + protocol_ + |
71 ", url=" + url_.spec() + | 72 ", url=" + url_.spec() + |
72 " }"; | 73 " }"; |
73 } | 74 } |
74 #endif | 75 #endif |
75 | 76 |
76 bool ProtocolHandler::operator==(const ProtocolHandler& other) const { | 77 bool ProtocolHandler::operator==(const ProtocolHandler& other) const { |
77 return protocol_ == other.protocol_ && url_ == other.url_; | 78 return protocol_ == other.protocol_ && url_ == other.url_; |
78 } | 79 } |
79 | 80 |
80 bool ProtocolHandler::IsEquivalent(const ProtocolHandler& other) const { | 81 bool ProtocolHandler::IsEquivalent(const ProtocolHandler& other) const { |
81 return protocol_ == other.protocol_ && url_ == other.url_; | 82 return protocol_ == other.protocol_ && url_ == other.url_; |
82 } | 83 } |
83 | 84 |
84 bool ProtocolHandler::operator<(const ProtocolHandler& other) const { | 85 bool ProtocolHandler::operator<(const ProtocolHandler& other) const { |
85 return url_ < other.url_; | 86 return url_ < other.url_; |
86 } | 87 } |
OLD | NEW |