Home | History | Annotate | Download | only in search_engines
      1 // Copyright (c) 2010 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_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_
      6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 
     13 class TemplateURL;
     14 
     15 // TemplateURLParser, as the name implies, handling reading of TemplateURLs
     16 // from OpenSearch description documents.
     17 class TemplateURLParser {
     18  public:
     19   class ParameterFilter {
     20    public:
     21     // Invoked for each parameter of the template URL while parsing.  If this
     22     // methods returns false, the parameter is not included.
     23     virtual bool KeepParameter(const std::string& key,
     24                                const std::string& value) = 0;
     25 
     26    protected:
     27     virtual ~ParameterFilter() {}
     28   };
     29   // Decodes the chunk of data representing a TemplateURL. If data does
     30   // not describe a valid TemplateURL false is returned. Additionally, if the
     31   // URLs referenced do not point to valid http/https resources, false is
     32   // returned. |parameter_filter| can be used if you want to filter out some
     33   // parameters out of the URL. For example when importing from another browser
     34   // we remove any parameter identifying that browser.  If set to NULL, the URL
     35   // is not modified.
     36   //
     37   // NOTE: This does not clear all values of the supplied TemplateURL; it's
     38   // expected callers will supply a new TemplateURL to this method.
     39   static bool Parse(const unsigned char* data,
     40                     size_t length,
     41                     ParameterFilter* parameter_filter,
     42                     TemplateURL* url);
     43 
     44  private:
     45   // No one should create one of these.
     46   TemplateURLParser();
     47 
     48   DISALLOW_COPY_AND_ASSIGN(TemplateURLParser);
     49 };
     50 
     51 #endif  // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_
     52