Home | History | Annotate | Download | only in custom_handlers
      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 #ifndef CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_
      6 #define CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/values.h"
     12 #include "googleurl/src/gurl.h"
     13 
     14 // A single tuple of (protocol, url, title) that indicates how URLs of the
     15 // given protocol should be rewritten to be handled.
     16 
     17 class ProtocolHandler {
     18  public:
     19   static ProtocolHandler* CreateProtocolHandler(const std::string& protocol,
     20                                                 const GURL& url,
     21                                                 const string16& title);
     22   static ProtocolHandler* CreateProtocolHandler(const DictionaryValue* value);
     23 
     24   // Interpolates the given URL into the URL template of this handler.
     25   GURL TranslateUrl(const GURL& url);
     26 
     27   // Encodes this protocol handler as a Value. The caller is responsible for
     28   // deleting the returned value.
     29   Value* Encode();
     30 
     31   std::string protocol() const { return protocol_; }
     32   GURL url() const { return url_;}
     33   string16 title() const { return title_; }
     34 
     35   bool operator==(const ProtocolHandler &other) const;
     36 
     37  private:
     38   ProtocolHandler(const std::string& protocol,
     39                   const GURL& url,
     40                   const string16& title);
     41   const std::string protocol_;
     42   const GURL url_;
     43   const string16 title_;
     44 };
     45 
     46 #endif  // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_
     47 
     48