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