Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / autocomplete / keyword_extensions_delegate_impl.h
blob474c0205436d52ef4297a1d7899a16ff60bfbb89
1 // Copyright 2014 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 // KeywordExtensionsDelegateImpl contains the extensions-only logic used by
6 // KeywordProvider. Overrides KeywordExtensionsDelegate which does nothing.
8 #ifndef CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_EXTENSIONS_DELEGATE_IMPL_H_
9 #define CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_EXTENSIONS_DELEGATE_IMPL_H_
11 #include <vector>
13 #include "base/compiler_specific.h"
14 #include "components/omnibox/autocomplete_input.h"
15 #include "components/omnibox/autocomplete_match.h"
16 #include "components/omnibox/autocomplete_provider_listener.h"
17 #include "components/omnibox/keyword_extensions_delegate.h"
18 #include "components/omnibox/keyword_provider.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
22 #if !defined(ENABLE_EXTENSIONS)
23 #error "Should not be included when extensions are disabled"
24 #endif
26 class Profile;
28 class KeywordExtensionsDelegateImpl : public KeywordExtensionsDelegate,
29 public content::NotificationObserver {
30 public:
31 KeywordExtensionsDelegateImpl(Profile* profile, KeywordProvider* provider);
32 virtual ~KeywordExtensionsDelegateImpl();
34 private:
35 // KeywordExtensionsDelegate:
36 virtual void IncrementInputId() OVERRIDE;
37 virtual bool IsEnabledExtension(const std::string& extension_id) OVERRIDE;
38 virtual bool Start(const AutocompleteInput& input,
39 bool minimal_changes,
40 const TemplateURL* template_url,
41 const base::string16& remaining_input) OVERRIDE;
42 virtual void EnterExtensionKeywordMode(
43 const std::string& extension_id) OVERRIDE;
44 virtual void MaybeEndExtensionKeywordMode() OVERRIDE;
46 // content::NotificationObserver:
47 virtual void Observe(int type,
48 const content::NotificationSource& source,
49 const content::NotificationDetails& details) OVERRIDE;
51 ACMatches* matches() { return &provider_->matches_; }
52 void set_done(bool done) {
53 provider_->done_ = done;
56 // Notifies the KeywordProvider about asynchronous updates from the extension.
57 void OnProviderUpdate(bool updated_matches);
59 // Identifies the current input state. This is incremented each time the
60 // autocomplete edit's input changes in any way. It is used to tell whether
61 // suggest results from the extension are current.
62 int current_input_id_;
64 // The input state at the time we last asked the extension for suggest
65 // results.
66 AutocompleteInput extension_suggest_last_input_;
68 // We remember the last suggestions we've received from the extension in case
69 // we need to reset our matches without asking the extension again.
70 std::vector<AutocompleteMatch> extension_suggest_matches_;
72 // If non-empty, holds the ID of the extension whose keyword is currently in
73 // the URL bar while the autocomplete popup is open.
74 std::string current_keyword_extension_id_;
76 Profile* profile_;
78 // The owner of this class.
79 KeywordProvider* provider_;
81 content::NotificationRegistrar registrar_;
83 // We need our input IDs to be unique across all profiles, so we keep a global
84 // UID that each provider uses.
85 static int global_input_uid_;
87 DISALLOW_COPY_AND_ASSIGN(KeywordExtensionsDelegateImpl);
90 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_EXTENSIONS_DELEGATE_IMPL_H_