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
3 // found in the LICENSE file.
5 #ifndef CHROME_COMMON_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_
6 #define CHROME_COMMON_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_
10 #include "base/values.h"
13 // A single tuple of (protocol, url, title) that indicates how URLs of the
14 // given protocol should be rewritten to be handled.
16 class ProtocolHandler
{
18 static ProtocolHandler
CreateProtocolHandler(const std::string
& protocol
,
20 const base::string16
& title
);
22 // Creates a ProtocolHandler with fields from the dictionary. Returns an
23 // empty ProtocolHandler if the input is invalid.
24 static ProtocolHandler
CreateProtocolHandler(
25 const base::DictionaryValue
* value
);
27 // Returns true if the dictionary value has all the necessary fields to
28 // define a ProtocolHandler.
29 static bool IsValidDict(const base::DictionaryValue
* value
);
31 // Returns true if this handler's url has the same origin as the given one.
32 bool IsSameOrigin(const ProtocolHandler
& handler
) const;
34 // Canonical empty ProtocolHandler.
35 static const ProtocolHandler
& EmptyProtocolHandler();
37 // Interpolates the given URL into the URL template of this handler.
38 GURL
TranslateUrl(const GURL
& url
) const;
40 // Returns true if the handlers are considered equivalent when determining
41 // if both handlers can be registered, or if a handler has previously been
43 bool IsEquivalent(const ProtocolHandler
& other
) const;
45 // Encodes this protocol handler as a DictionaryValue. The caller is
46 // responsible for deleting the returned value.
47 base::DictionaryValue
* Encode() const;
49 const std::string
& protocol() const { return protocol_
; }
50 const GURL
& url() const { return url_
;}
51 const base::string16
& title() const { return title_
; }
53 bool IsEmpty() const {
54 return protocol_
.empty();
58 // Returns a string representation suitable for use in debugging.
59 std::string
ToString() const;
63 bool operator==(const ProtocolHandler
& other
) const;
64 bool operator<(const ProtocolHandler
& other
) const;
67 ProtocolHandler(const std::string
& protocol
,
69 const base::string16
& title
);
72 std::string protocol_
;
74 base::string16 title_
;
77 #endif // CHROME_COMMON_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_