history_provider.h revision f2477e01787aa58f445919b809d89e252beef54f
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. 4 5#ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_H_ 6#define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_H_ 7 8#include "base/compiler_specific.h" 9#include "chrome/browser/autocomplete/autocomplete_provider.h" 10#include "chrome/browser/history/in_memory_url_index_types.h" 11 12class AutocompleteInput; 13struct AutocompleteMatch; 14 15// This class is a base class for the history autocomplete providers and 16// provides functions useful to all derived classes. 17class HistoryProvider : public AutocompleteProvider { 18 public: 19 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; 20 21 protected: 22 HistoryProvider(AutocompleteProviderListener* listener, 23 Profile* profile, 24 AutocompleteProvider::Type type); 25 virtual ~HistoryProvider(); 26 27 // Finds and removes the match from the current collection of matches and 28 // backing data. 29 void DeleteMatchFromMatches(const AutocompleteMatch& match); 30 31 // Fixes up user URL input to make it more possible to match against. Among 32 // many other things, this takes care of the following: 33 // * Prepending file:// to file URLs 34 // * Converting drive letters in file URLs to uppercase 35 // * Converting case-insensitive parts of URLs (like the scheme and domain) 36 // to lowercase 37 // * Convert spaces to %20s 38 // Note that we don't do this in AutocompleteInput's constructor, because if 39 // e.g. we convert a Unicode hostname to punycode, other providers will show 40 // output that surprises the user ("Search Google for xn--6ca.com"). 41 // Returns false if the fixup attempt resulted in an empty string (which 42 // providers generally can't do anything with). 43 static bool FixupUserInput(AutocompleteInput* input); 44 45 // Trims "http:" and up to two subsequent slashes from |url|. Returns the 46 // number of characters that were trimmed. 47 // NOTE: For a view-source: URL, this will trim from after "view-source:" and 48 // return 0. 49 static size_t TrimHttpPrefix(string16* url); 50 51 // Returns true if inline autocompletion should be prevented. Use this instead 52 // of |input.prevent_inline_autocomplete| if the input is passed through 53 // FixupUserInput(). This method returns true if 54 // |input.prevent_inline_autocomplete()| is true or the input text contains 55 // trailing whitespace. 56 bool PreventInlineAutocomplete(const AutocompleteInput& input); 57 58 // Fill and return an ACMatchClassifications structure given the |matches| 59 // to highlight. 60 static ACMatchClassifications SpansFromTermMatch( 61 const history::TermMatches& matches, 62 size_t text_length, 63 bool is_url); 64}; 65 66#endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_H_ 67