| 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 #ifndef CHROME_COMMON_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_ | 5 #ifndef CHROME_COMMON_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_ |
| 6 #define CHROME_COMMON_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_ | 6 #define CHROME_COMMON_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 // A single tuple of (protocol, url, title) that indicates how URLs of the | 13 // A single tuple of (protocol, url, title) that indicates how URLs of the |
| 14 // given protocol should be rewritten to be handled. | 14 // given protocol should be rewritten to be handled. |
| 15 | 15 |
| 16 class ProtocolHandler { | 16 class ProtocolHandler { |
| 17 public: | 17 public: |
| 18 static ProtocolHandler CreateProtocolHandler(const std::string& protocol, | 18 static ProtocolHandler CreateProtocolHandler(const std::string& protocol, |
| 19 const GURL& url, | 19 const GURL& url, |
| 20 const string16& title); | 20 const base::string16& title); |
| 21 | 21 |
| 22 // Creates a ProtocolHandler with fields from the dictionary. Returns an | 22 // Creates a ProtocolHandler with fields from the dictionary. Returns an |
| 23 // empty ProtocolHandler if the input is invalid. | 23 // empty ProtocolHandler if the input is invalid. |
| 24 static ProtocolHandler CreateProtocolHandler( | 24 static ProtocolHandler CreateProtocolHandler( |
| 25 const base::DictionaryValue* value); | 25 const base::DictionaryValue* value); |
| 26 | 26 |
| 27 // Returns true if the dictionary value has all the necessary fields to | 27 // Returns true if the dictionary value has all the necessary fields to |
| 28 // define a ProtocolHandler. | 28 // define a ProtocolHandler. |
| 29 static bool IsValidDict(const base::DictionaryValue* value); | 29 static bool IsValidDict(const base::DictionaryValue* value); |
| 30 | 30 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 // if both handlers can be registered, or if a handler has previously been | 41 // if both handlers can be registered, or if a handler has previously been |
| 42 // ignored. | 42 // ignored. |
| 43 bool IsEquivalent(const ProtocolHandler& other) const; | 43 bool IsEquivalent(const ProtocolHandler& other) const; |
| 44 | 44 |
| 45 // Encodes this protocol handler as a DictionaryValue. The caller is | 45 // Encodes this protocol handler as a DictionaryValue. The caller is |
| 46 // responsible for deleting the returned value. | 46 // responsible for deleting the returned value. |
| 47 base::DictionaryValue* Encode() const; | 47 base::DictionaryValue* Encode() const; |
| 48 | 48 |
| 49 const std::string& protocol() const { return protocol_; } | 49 const std::string& protocol() const { return protocol_; } |
| 50 const GURL& url() const { return url_;} | 50 const GURL& url() const { return url_;} |
| 51 const string16& title() const { return title_; } | 51 const base::string16& title() const { return title_; } |
| 52 | 52 |
| 53 bool IsEmpty() const { | 53 bool IsEmpty() const { |
| 54 return protocol_.empty(); | 54 return protocol_.empty(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 #if !defined(NDEBUG) | 57 #if !defined(NDEBUG) |
| 58 // Returns a string representation suitable for use in debugging. | 58 // Returns a string representation suitable for use in debugging. |
| 59 std::string ToString() const; | 59 std::string ToString() const; |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 | 62 |
| 63 bool operator==(const ProtocolHandler& other) const; | 63 bool operator==(const ProtocolHandler& other) const; |
| 64 bool operator<(const ProtocolHandler& other) const; | 64 bool operator<(const ProtocolHandler& other) const; |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 ProtocolHandler(const std::string& protocol, | 67 ProtocolHandler(const std::string& protocol, |
| 68 const GURL& url, | 68 const GURL& url, |
| 69 const string16& title); | 69 const base::string16& title); |
| 70 ProtocolHandler(); | 70 ProtocolHandler(); |
| 71 | 71 |
| 72 std::string protocol_; | 72 std::string protocol_; |
| 73 GURL url_; | 73 GURL url_; |
| 74 string16 title_; | 74 base::string16 title_; |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 #endif // CHROME_COMMON_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_ | 77 #endif // CHROME_COMMON_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_ |
| OLD | NEW |