| OLD | NEW |
| (Empty) | |
| 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 // |
| 6 // This file contains the Extension App autocomplete provider. The provider |
| 7 // is responsible for keeping track of which Extension Apps are installed and |
| 8 // their URLs. An instance of it gets created and managed by the autocomplete |
| 9 // controller. |
| 10 // |
| 11 // For more information on the autocomplete system in general, including how |
| 12 // the autocomplete controller and autocomplete providers work, see |
| 13 // chrome/browser/autocomplete.h. |
| 14 |
| 15 #ifndef CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ |
| 16 #define CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ |
| 17 #pragma once |
| 18 |
| 19 #include <string> |
| 20 #include <utility> |
| 21 #include <vector> |
| 22 |
| 23 #include "base/compiler_specific.h" |
| 24 #include "chrome/browser/autocomplete/autocomplete.h" |
| 25 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 26 #include "content/common/notification_observer.h" |
| 27 #include "content/common/notification_registrar.h" |
| 28 |
| 29 class TemplateURLModel; |
| 30 |
| 31 class ExtensionAppProvider : public AutocompleteProvider, |
| 32 public NotificationObserver { |
| 33 public: |
| 34 ExtensionAppProvider(ACProviderListener* listener, Profile* profile); |
| 35 |
| 36 // AutocompleteProvider implementation: |
| 37 virtual void Start(const AutocompleteInput& input, |
| 38 bool minimal_changes) OVERRIDE; |
| 39 |
| 40 private: |
| 41 // An ExtensionApp is a pair of Extension Name and the Launch URL. |
| 42 typedef std::pair<std::string, std::string> ExtensionApp; |
| 43 typedef std::vector<ExtensionApp> ExtensionApps; |
| 44 |
| 45 virtual ~ExtensionAppProvider(); |
| 46 |
| 47 // Fetch the current app list and cache it locally. |
| 48 void RefreshAppList(); |
| 49 |
| 50 // Register for install/uninstall notification so we can update our cache. |
| 51 void RegisterForNotifications(); |
| 52 |
| 53 // Highlights a certain part of a match string within a certain match class. |
| 54 // |input| is the input we got from the user, |match_class| is the |
| 55 // AutoComplete match classification that keeps track of the highlighting |
| 56 // values, and |iter| is the location of the user input found within |
| 57 // |match_string|. |
| 58 void HighlightMatch(const AutocompleteInput& input, |
| 59 ACMatchClassifications* match_class, |
| 60 std::string::const_iterator iter, |
| 61 const std::string& match_string); |
| 62 |
| 63 // Calculate the relevance of the match. |
| 64 int CalculateRelevance(AutocompleteInput::Type type, |
| 65 int input_length, |
| 66 int target_length, |
| 67 const GURL& url); |
| 68 |
| 69 // NotificationObserver implementation: |
| 70 virtual void Observe(NotificationType type, |
| 71 const NotificationSource& source, |
| 72 const NotificationDetails& details) OVERRIDE; |
| 73 |
| 74 NotificationRegistrar registrar_; |
| 75 |
| 76 // Our cache of ExtensionApp objects (name + url) representing the extension |
| 77 // apps we know about. |
| 78 ExtensionApps extension_apps_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(ExtensionAppProvider); |
| 81 }; |
| 82 |
| 83 #endif // CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ |
| OLD | NEW |