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/custom_handlers/protocol_handler.h" | |
6 | |
7 #include "base/string_util.h" | |
8 #include "net/base/escape.h" | |
9 | |
10 | |
jam
2011/02/16 18:29:37
nit: extra line
koz (OOO until 15th September)
2011/02/17 03:32:03
Removed, cheers.
| |
11 ProtocolHandler::ProtocolHandler(const std::string& protocol, | |
12 const GURL& url, | |
13 const string16& title) | |
14 : protocol_(protocol), | |
15 url_(url), | |
16 title_(title) { | |
17 } | |
18 | |
19 ProtocolHandler* ProtocolHandler::CreateProtocolHandler( | |
20 const std::string& protocol, | |
21 const GURL& url, | |
22 const string16& title) { | |
23 std::string lower_protocol(protocol); | |
24 lower_protocol = StringToLowerASCII(protocol); | |
25 return new ProtocolHandler(lower_protocol, url, title); | |
26 } | |
27 | |
28 ProtocolHandler* ProtocolHandler::CreateProtocolHandler( | |
29 const DictionaryValue* value) { | |
30 std::string protocol, url; | |
31 string16 title; | |
32 value->GetString("protocol", &protocol); | |
33 value->GetString("url", &url); | |
34 value->GetString("title", &title); | |
35 return ProtocolHandler::CreateProtocolHandler(protocol, GURL(url), title); | |
36 } | |
37 | |
38 GURL ProtocolHandler::TranslateUrl(const GURL& url) { | |
39 std::string translatedUrlSpec(url_.spec()); | |
40 ReplaceSubstringsAfterOffset(&translatedUrlSpec, 0, "%s", | |
41 EscapeQueryParamValue(url.spec(), true)); | |
42 return GURL(translatedUrlSpec); | |
43 } | |
44 | |
45 Value* ProtocolHandler::Encode() { | |
46 DictionaryValue* d = new DictionaryValue(); | |
47 d->Set("protocol", Value::CreateStringValue(protocol_)); | |
48 d->Set("url", Value::CreateStringValue(url_.spec())); | |
49 d->Set("title", Value::CreateStringValue(title_)); | |
50 return d; | |
51 } | |
52 | |
53 bool ProtocolHandler::operator==(const ProtocolHandler &other) const { | |
54 return protocol_ == other.protocol_ && | |
55 url_ == other.url_ && | |
56 title_ == other.title_; | |
57 } | |
58 | |
OLD | NEW |