Fix use-after-free in ExtensionHost::DidStopLoading.
[chromium-blink-merge.git] / chrome / common / custom_handlers / protocol_handler.h
blob745a3f52d5a67caaff9d1b19b11f83cc9b45f7c1
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_
8 #include <string>
10 #include "base/values.h"
11 #include "url/gurl.h"
13 // A single tuple of (protocol, url) that indicates how URLs of the
14 // given protocol should be rewritten to be handled.
16 class ProtocolHandler {
17 public:
18 static ProtocolHandler CreateProtocolHandler(const std::string& protocol,
19 const GURL& url);
21 // Creates a ProtocolHandler with fields from the dictionary. Returns an
22 // empty ProtocolHandler if the input is invalid.
23 static ProtocolHandler CreateProtocolHandler(
24 const base::DictionaryValue* value);
26 // Returns true if the dictionary value has all the necessary fields to
27 // define a ProtocolHandler.
28 static bool IsValidDict(const base::DictionaryValue* value);
30 // Returns true if this handler's url has the same origin as the given one.
31 bool IsSameOrigin(const ProtocolHandler& handler) const;
33 // Canonical empty ProtocolHandler.
34 static const ProtocolHandler& EmptyProtocolHandler();
36 // Interpolates the given URL into the URL template of this handler.
37 GURL TranslateUrl(const GURL& url) const;
39 // Returns true if the handlers are considered equivalent when determining
40 // if both handlers can be registered, or if a handler has previously been
41 // ignored.
42 bool IsEquivalent(const ProtocolHandler& other) const;
44 // Encodes this protocol handler as a DictionaryValue. The caller is
45 // responsible for deleting the returned value.
46 base::DictionaryValue* Encode() const;
48 const std::string& protocol() const { return protocol_; }
49 const GURL& url() const { return url_;}
51 bool IsEmpty() const {
52 return protocol_.empty();
55 #if !defined(NDEBUG)
56 // Returns a string representation suitable for use in debugging.
57 std::string ToString() const;
58 #endif
61 bool operator==(const ProtocolHandler& other) const;
62 bool operator<(const ProtocolHandler& other) const;
64 private:
65 ProtocolHandler(const std::string& protocol,
66 const GURL& url);
67 ProtocolHandler();
69 std::string protocol_;
70 GURL url_;
73 #endif // CHROME_COMMON_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_