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/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "net/base/escape.h" | 9 #include "net/base/escape.h" |
10 | 10 |
11 | 11 |
12 ProtocolHandler::ProtocolHandler(const std::string& protocol, | 12 ProtocolHandler::ProtocolHandler(const std::string& protocol, |
13 const GURL& url, | 13 const GURL& url, |
14 const string16& title) | 14 const base::string16& title) |
15 : protocol_(protocol), | 15 : protocol_(protocol), |
16 url_(url), | 16 url_(url), |
17 title_(title) { | 17 title_(title) { |
18 } | 18 } |
19 | 19 |
20 ProtocolHandler ProtocolHandler::CreateProtocolHandler( | 20 ProtocolHandler ProtocolHandler::CreateProtocolHandler( |
21 const std::string& protocol, | 21 const std::string& protocol, |
22 const GURL& url, | 22 const GURL& url, |
23 const string16& title) { | 23 const base::string16& title) { |
24 std::string lower_protocol = StringToLowerASCII(protocol); | 24 std::string lower_protocol = StringToLowerASCII(protocol); |
25 return ProtocolHandler(lower_protocol, url, title); | 25 return ProtocolHandler(lower_protocol, url, title); |
26 } | 26 } |
27 | 27 |
28 ProtocolHandler::ProtocolHandler() { | 28 ProtocolHandler::ProtocolHandler() { |
29 } | 29 } |
30 | 30 |
31 bool ProtocolHandler::IsValidDict(const base::DictionaryValue* value) { | 31 bool ProtocolHandler::IsValidDict(const base::DictionaryValue* value) { |
32 return value->HasKey("protocol") && value->HasKey("url") && | 32 return value->HasKey("protocol") && value->HasKey("url") && |
33 value->HasKey("title"); | 33 value->HasKey("title"); |
34 } | 34 } |
35 | 35 |
36 bool ProtocolHandler::IsSameOrigin( | 36 bool ProtocolHandler::IsSameOrigin( |
37 const ProtocolHandler& handler) const { | 37 const ProtocolHandler& handler) const { |
38 return handler.url().GetOrigin() == url_.GetOrigin(); | 38 return handler.url().GetOrigin() == url_.GetOrigin(); |
39 } | 39 } |
40 | 40 |
41 const ProtocolHandler& ProtocolHandler::EmptyProtocolHandler() { | 41 const ProtocolHandler& ProtocolHandler::EmptyProtocolHandler() { |
42 static const ProtocolHandler* const kEmpty = new ProtocolHandler(); | 42 static const ProtocolHandler* const kEmpty = new ProtocolHandler(); |
43 return *kEmpty; | 43 return *kEmpty; |
44 } | 44 } |
45 | 45 |
46 ProtocolHandler ProtocolHandler::CreateProtocolHandler( | 46 ProtocolHandler ProtocolHandler::CreateProtocolHandler( |
47 const base::DictionaryValue* value) { | 47 const base::DictionaryValue* value) { |
48 if (!IsValidDict(value)) { | 48 if (!IsValidDict(value)) { |
49 return EmptyProtocolHandler(); | 49 return EmptyProtocolHandler(); |
50 } | 50 } |
51 std::string protocol, url; | 51 std::string protocol, url; |
52 string16 title; | 52 base::string16 title; |
53 value->GetString("protocol", &protocol); | 53 value->GetString("protocol", &protocol); |
54 value->GetString("url", &url); | 54 value->GetString("url", &url); |
55 value->GetString("title", &title); | 55 value->GetString("title", &title); |
56 return ProtocolHandler::CreateProtocolHandler(protocol, GURL(url), title); | 56 return ProtocolHandler::CreateProtocolHandler(protocol, GURL(url), title); |
57 } | 57 } |
58 | 58 |
59 GURL ProtocolHandler::TranslateUrl(const GURL& url) const { | 59 GURL ProtocolHandler::TranslateUrl(const GURL& url) const { |
60 std::string translatedUrlSpec(url_.spec()); | 60 std::string translatedUrlSpec(url_.spec()); |
61 ReplaceSubstringsAfterOffset(&translatedUrlSpec, 0, "%s", | 61 ReplaceSubstringsAfterOffset(&translatedUrlSpec, 0, "%s", |
62 net::EscapeQueryParamValue(url.spec(), true)); | 62 net::EscapeQueryParamValue(url.spec(), true)); |
(...skipping 23 matching lines...) Expand all Loading... |
86 title_ == other.title_; | 86 title_ == other.title_; |
87 } | 87 } |
88 | 88 |
89 bool ProtocolHandler::IsEquivalent(const ProtocolHandler& other) const { | 89 bool ProtocolHandler::IsEquivalent(const ProtocolHandler& other) const { |
90 return protocol_ == other.protocol_ && url_ == other.url_; | 90 return protocol_ == other.protocol_ && url_ == other.url_; |
91 } | 91 } |
92 | 92 |
93 bool ProtocolHandler::operator<(const ProtocolHandler& other) const { | 93 bool ProtocolHandler::operator<(const ProtocolHandler& other) const { |
94 return title_ < other.title_; | 94 return title_ < other.title_; |
95 } | 95 } |
OLD | NEW |