diff options
author | mukai <mukai@chromium.org> | 2014-10-10 14:07:50 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-10 21:08:08 +0000 |
commit | 2ba30fe7f0c4640d3007b3357f0d0ab89637919e (patch) | |
tree | a41089d1a6e4e1d6c1751c1be7092105e490ff82 /athena/extensions | |
parent | 3f6b84cd4ebdc209f3d607f2336e6f43aadcd2df (diff) | |
download | chromium_src-2ba30fe7f0c4640d3007b3357f0d0ab89637919e.zip chromium_src-2ba30fe7f0c4640d3007b3357f0d0ab89637919e.tar.gz chromium_src-2ba30fe7f0c4640d3007b3357f0d0ab89637919e.tar.bz2 |
Adds full-functional search results for Athena on Chrome.
BUG=380875, 421444
R=oshima@chromium.org, xiyuan@chromium.org
TBR=pkasting@chromium.org, jar@chromium.org
TEST=manually
Review URL: https://codereview.chromium.org/640103002
Cr-Commit-Position: refs/heads/master@{#299186}
Diffstat (limited to 'athena/extensions')
12 files changed, 728 insertions, 0 deletions
diff --git a/athena/extensions/chrome/app_list_controller_delegate_athena.cc b/athena/extensions/chrome/app_list_controller_delegate_athena.cc new file mode 100644 index 0000000..5dcef059 --- /dev/null +++ b/athena/extensions/chrome/app_list_controller_delegate_athena.cc @@ -0,0 +1,114 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "athena/extensions/chrome/app_list_controller_delegate_athena.h" + +#include "athena/activity/public/activity_factory.h" +#include "athena/extensions/public/extensions_delegate.h" +#include "chrome/browser/profiles/profile.h" +#include "extensions/common/extension.h" +#include "ui/app_list/views/app_list_view.h" + +namespace athena { + +AppListControllerDelegateAthena::AppListControllerDelegateAthena() { +} + +AppListControllerDelegateAthena::~AppListControllerDelegateAthena() { +} + +void AppListControllerDelegateAthena::DismissView() { +} + +gfx::NativeWindow AppListControllerDelegateAthena::GetAppListWindow() { + NOTIMPLEMENTED(); + return NULL; +} + +gfx::Rect AppListControllerDelegateAthena::GetAppListBounds() { + NOTIMPLEMENTED(); + return gfx::Rect(); +} + +gfx::ImageSkia AppListControllerDelegateAthena::GetWindowIcon() { + return gfx::ImageSkia(); +} + +bool AppListControllerDelegateAthena::IsAppPinned( + const std::string& extension_id) { + return false; +} + +void AppListControllerDelegateAthena::PinApp(const std::string& extension_id) { + NOTREACHED(); +} + +void AppListControllerDelegateAthena::UnpinApp( + const std::string& extension_id) { + NOTREACHED(); +} + +AppListControllerDelegate::Pinnable +AppListControllerDelegateAthena::GetPinnable() { + return NO_PIN; +} + +void AppListControllerDelegateAthena::OnShowChildDialog() { + NOTIMPLEMENTED(); +} + +void AppListControllerDelegateAthena::OnCloseChildDialog() { + NOTIMPLEMENTED(); +} + +bool AppListControllerDelegateAthena::CanDoCreateShortcutsFlow() { + return false; +} + +void AppListControllerDelegateAthena::DoCreateShortcutsFlow( + Profile* profile, + const std::string& extension_id) { + NOTREACHED(); +} + +void AppListControllerDelegateAthena::CreateNewWindow(Profile* profile, + bool incognito) { + // Nothing needs to be done. +} + +void AppListControllerDelegateAthena::OpenURL( + Profile* profile, + const GURL& url, + ui::PageTransition transition, + WindowOpenDisposition disposition) { + ActivityFactory::Get()->CreateWebActivity(profile, base::string16(), url); +} + +void AppListControllerDelegateAthena::ActivateApp( + Profile* profile, + const extensions::Extension* extension, + AppListSource source, + int event_flags) { + LaunchApp(profile, extension, source, event_flags); +} + +void AppListControllerDelegateAthena::LaunchApp( + Profile* profile, + const extensions::Extension* extension, + AppListSource source, + int event_flags) { + ExtensionsDelegate::Get(profile)->LaunchApp(extension->id()); +} + +void AppListControllerDelegateAthena::ShowForProfileByPath( + const base::FilePath& profile_path) { + // Ash doesn't have profile switching. + NOTREACHED(); +} + +bool AppListControllerDelegateAthena::ShouldShowUserIcon() { + return false; +} + +} // namespace athena diff --git a/athena/extensions/chrome/app_list_controller_delegate_athena.h b/athena/extensions/chrome/app_list_controller_delegate_athena.h new file mode 100644 index 0000000..78c6de1 --- /dev/null +++ b/athena/extensions/chrome/app_list_controller_delegate_athena.h @@ -0,0 +1,56 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ATHENA_EXTENSIONS_CHROME_APP_LIST_CONTROLLER_DELEGATE_ATHENA_H_ +#define ATHENA_EXTENSIONS_CHROME_APP_LIST_CONTROLLER_DELEGATE_ATHENA_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" + +namespace athena { + +class AppListControllerDelegateAthena : public AppListControllerDelegate { + public: + AppListControllerDelegateAthena(); + virtual ~AppListControllerDelegateAthena(); + + private: + // AppListControllerDelegate overrides: + virtual void DismissView() override; + virtual gfx::NativeWindow GetAppListWindow() override; + virtual gfx::Rect GetAppListBounds() override; + virtual gfx::ImageSkia GetWindowIcon() override; + virtual bool IsAppPinned(const std::string& extension_id) override; + virtual void PinApp(const std::string& extension_id) override; + virtual void UnpinApp(const std::string& extension_id) override; + virtual Pinnable GetPinnable() override; + virtual void OnShowChildDialog() override; + virtual void OnCloseChildDialog() override; + virtual bool CanDoCreateShortcutsFlow() override; + virtual void DoCreateShortcutsFlow(Profile* profile, + const std::string& extension_id) override; + virtual void CreateNewWindow(Profile* profile, bool incognito) override; + virtual void OpenURL(Profile* profile, + const GURL& url, + ui::PageTransition transition, + WindowOpenDisposition disposition) override; + virtual void ActivateApp(Profile* profile, + const extensions::Extension* extension, + AppListSource source, + int event_flags) override; + virtual void LaunchApp(Profile* profile, + const extensions::Extension* extension, + AppListSource source, + int event_flags) override; + virtual void ShowForProfileByPath( + const base::FilePath& profile_path) override; + virtual bool ShouldShowUserIcon() override; + + DISALLOW_COPY_AND_ASSIGN(AppListControllerDelegateAthena); +}; + +} // namespace athena + +#endif // ATHENA_EXTENSIONS_CHROME_APP_LIST_CONTROLLER_DELEGATE_ATHENA_H_ diff --git a/athena/extensions/chrome/chrome_search_controller_factory.cc b/athena/extensions/chrome/chrome_search_controller_factory.cc new file mode 100644 index 0000000..d39c798 --- /dev/null +++ b/athena/extensions/chrome/chrome_search_controller_factory.cc @@ -0,0 +1,37 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "athena/extensions/chrome/chrome_search_controller_factory.h" + +#include "athena/extensions/chrome/app_list_controller_delegate_athena.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/app_list/search/search_controller_factory.h" + +namespace athena { + +ChromeSearchControllerFactory::ChromeSearchControllerFactory( + content::BrowserContext* browser_context) + : browser_context_(browser_context) { +} + +ChromeSearchControllerFactory::~ChromeSearchControllerFactory() { +} + +scoped_ptr<app_list::SearchController> ChromeSearchControllerFactory::Create( + app_list::SearchBoxModel* search_box, + app_list::AppListModel::SearchResults* results) { + list_controller_.reset(new AppListControllerDelegateAthena()); + return app_list::CreateSearchController( + Profile::FromBrowserContext(browser_context_), + search_box, + results, + list_controller_.get()); +} + +scoped_ptr<SearchControllerFactory> CreateSearchControllerFactory( + content::BrowserContext* context) { + return make_scoped_ptr(new ChromeSearchControllerFactory(context)); +} + +} // namespace athena diff --git a/athena/extensions/chrome/chrome_search_controller_factory.h b/athena/extensions/chrome/chrome_search_controller_factory.h new file mode 100644 index 0000000..2525f79 --- /dev/null +++ b/athena/extensions/chrome/chrome_search_controller_factory.h @@ -0,0 +1,36 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ATHENA_EXTENSIONS_CHROME_CHROME_SEARCH_CONTROLLER_FACTORY_H_ +#define ATHENA_EXTENSIONS_CHROME_CHROME_SEARCH_CONTROLLER_FACTORY_H_ + +#include "athena/home/public/search_controller_factory.h" +#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" + +namespace content { +class BrowserContext; +} + +namespace athena { + +class ChromeSearchControllerFactory : public SearchControllerFactory { + public: + explicit ChromeSearchControllerFactory( + content::BrowserContext* browser_context); + virtual ~ChromeSearchControllerFactory(); + + virtual scoped_ptr<app_list::SearchController> Create( + app_list::SearchBoxModel* search_box, + app_list::AppListModel::SearchResults* results) override; + + private: + content::BrowserContext* browser_context_; + scoped_ptr<AppListControllerDelegate> list_controller_; + + DISALLOW_COPY_AND_ASSIGN(ChromeSearchControllerFactory); +}; + +} // namespace athena + +#endif // ATHENA_EXTENSIONS_CHROME_CHROME_SEARCH_CONTROLLER_FACTORY_H_ diff --git a/athena/extensions/public/apps_search_controller_factory.h b/athena/extensions/public/apps_search_controller_factory.h new file mode 100644 index 0000000..f17e490 --- /dev/null +++ b/athena/extensions/public/apps_search_controller_factory.h @@ -0,0 +1,22 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ATHENA_EXTENSIONS_PUBLIC_APPS_SEARCH_CONTROLLER_FACTORY_H_ +#define ATHENA_EXTENSIONS_PUBLIC_APPS_SEARCH_CONTROLLER_FACTORY_H_ + +#include "athena/athena_export.h" + +namespace content { +class BrowserContext; +} + +namespace athena { +class SearchControllerFactory; + +ATHENA_EXPORT scoped_ptr<SearchControllerFactory> CreateSearchControllerFactory( + content::BrowserContext* context); + +} // namespace athena + +#endif // ATHENA_EXTENSIONS_PUBLIC_APPS_SEARCH_CONTROLLER_FACTORY_H_ diff --git a/athena/extensions/shell/DEPS b/athena/extensions/shell/DEPS index a8a0f03..28836ad 100644 --- a/athena/extensions/shell/DEPS +++ b/athena/extensions/shell/DEPS @@ -1,3 +1,8 @@ include_rules = [ + "+components/metrics/proto", + "+components/omnibox", + "+components/search_engines", "+extensions/shell/browser", + "+net/url_request", + "+ui/app_list", ] diff --git a/athena/extensions/shell/athena_shell_scheme_classifier.cc b/athena/extensions/shell/athena_shell_scheme_classifier.cc new file mode 100644 index 0000000..a66d373 --- /dev/null +++ b/athena/extensions/shell/athena_shell_scheme_classifier.cc @@ -0,0 +1,27 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "athena/extensions/shell/athena_shell_scheme_classifier.h" + +#include "components/metrics/proto/omnibox_input_type.pb.h" +#include "net/url_request/url_request.h" + +using metrics::OmniboxInputType::Type; + +namespace athena { + +AthenaShellSchemeClassifier::AthenaShellSchemeClassifier() { +} + +AthenaShellSchemeClassifier::~AthenaShellSchemeClassifier() { +} + +Type AthenaShellSchemeClassifier::GetInputTypeForScheme( + const std::string& scheme) const { + if (net::URLRequest::IsHandledProtocol(scheme)) + return metrics::OmniboxInputType::URL; + return metrics::OmniboxInputType::INVALID; +} + +} // namespace athena diff --git a/athena/extensions/shell/athena_shell_scheme_classifier.h b/athena/extensions/shell/athena_shell_scheme_classifier.h new file mode 100644 index 0000000..4ab5dd7 --- /dev/null +++ b/athena/extensions/shell/athena_shell_scheme_classifier.h @@ -0,0 +1,29 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ATHENA_EXTENSIONS_SHELL_ATHENA_SHELL_SCHEME_CLASSIFIER_H_ +#define ATHENA_EXTENSIONS_SHELL_ATHENA_SHELL_SCHEME_CLASSIFIER_H_ + +#include "base/macros.h" +#include "components/omnibox/autocomplete_scheme_classifier.h" + +namespace athena { + +// The AutocompleteSchemeClassifier implementation for athena_main. +class AthenaShellSchemeClassifier : public AutocompleteSchemeClassifier { + public: + AthenaShellSchemeClassifier(); + virtual ~AthenaShellSchemeClassifier(); + + // AutocompleteSchemeClassifier: + virtual metrics::OmniboxInputType::Type GetInputTypeForScheme( + const std::string& scheme) const override; + + private: + DISALLOW_COPY_AND_ASSIGN(AthenaShellSchemeClassifier); +}; + +} // namespace athena + +#endif // ATHENA_EXTENSIONS_SHELL_ATHENA_SHELL_SCHEME_CLASSIFIER_H_ diff --git a/athena/extensions/shell/shell_search_controller_factory.cc b/athena/extensions/shell/shell_search_controller_factory.cc new file mode 100644 index 0000000..d8df1ec --- /dev/null +++ b/athena/extensions/shell/shell_search_controller_factory.cc @@ -0,0 +1,37 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "athena/extensions/shell/shell_search_controller_factory.h" + +#include "athena/extensions/shell/url_search_provider.h" +#include "ui/app_list/search_controller.h" + +namespace athena { + +ShellSearchControllerFactory::ShellSearchControllerFactory( + content::BrowserContext* browser_context) + : browser_context_(browser_context) { +} + +ShellSearchControllerFactory::~ShellSearchControllerFactory() { +} + +scoped_ptr<app_list::SearchController> ShellSearchControllerFactory::Create( + app_list::SearchBoxModel* search_box, + app_list::AppListModel::SearchResults* results) { + scoped_ptr<app_list::SearchController> controller( + new app_list::SearchController( + search_box, results, NULL /* no history */)); + controller->AddProvider(app_list::Mixer::MAIN_GROUP, + scoped_ptr<app_list::SearchProvider>( + new UrlSearchProvider(browser_context_))); + return controller.Pass(); +} + +scoped_ptr<SearchControllerFactory> CreateSearchControllerFactory( + content::BrowserContext* context) { + return make_scoped_ptr(new ShellSearchControllerFactory(context)); +} + +} // namespace athena diff --git a/athena/extensions/shell/shell_search_controller_factory.h b/athena/extensions/shell/shell_search_controller_factory.h new file mode 100644 index 0000000..971f540 --- /dev/null +++ b/athena/extensions/shell/shell_search_controller_factory.h @@ -0,0 +1,34 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ATHENA_EXTENSIONS_SHELL_SHELL_SEARCH_CONTROLLER_FACTORY_H_ +#define ATHENA_EXTENSIONS_SHELL_SHELL_SEARCH_CONTROLLER_FACTORY_H_ + +#include "athena/home/public/search_controller_factory.h" + +namespace content { +class BrowserContext; +} + +namespace athena { + +class ShellSearchControllerFactory : public SearchControllerFactory { + public: + explicit ShellSearchControllerFactory( + content::BrowserContext* browser_context); + virtual ~ShellSearchControllerFactory(); + + virtual scoped_ptr<app_list::SearchController> Create( + app_list::SearchBoxModel* search_box, + app_list::AppListModel::SearchResults* results) override; + + private: + content::BrowserContext* browser_context_; + + DISALLOW_COPY_AND_ASSIGN(ShellSearchControllerFactory); +}; + +} // namespace athena + +#endif // ATHENA_EXTENSIONS_SHELL_SHELL_SEARCH_CONTROLLER_FACTORY_H_ diff --git a/athena/extensions/shell/url_search_provider.cc b/athena/extensions/shell/url_search_provider.cc new file mode 100644 index 0000000..82dd2fa --- /dev/null +++ b/athena/extensions/shell/url_search_provider.cc @@ -0,0 +1,280 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "athena/extensions/shell/url_search_provider.h" + +#include "athena/activity/public/activity.h" +#include "athena/activity/public/activity_factory.h" +#include "athena/extensions/shell/athena_shell_scheme_classifier.h" +#include "base/strings/utf_string_conversions.h" +#include "base/values.h" +#include "components/metrics/proto/omnibox_event.pb.h" +#include "components/metrics/proto/omnibox_input_type.pb.h" +#include "components/omnibox/autocomplete_input.h" +#include "components/omnibox/autocomplete_provider_client.h" +#include "components/omnibox/search_provider.h" +#include "components/search_engines/search_terms_data.h" +#include "components/search_engines/template_url_service.h" +#include "components/search_engines/template_url_service_client.h" +#include "content/public/browser/browser_context.h" +#include "ui/app_list/search_result.h" +#include "ui/base/resource/resource_bundle.h" +#include "url/gurl.h" + +namespace athena { + +namespace { + +// This constant was copied from HistoryURLProvider. +// TODO(hashimoto): Componentize HistoryURLProvider and delete this. +const int kScoreForWhatYouTypedResult = 1203; + +// The SearchTermsData implementation for Athena. +class AthenaSearchTermsData : public SearchTermsData { + public: + // SearchTermsData: + virtual std::string GetSuggestClient() const override { return "chrome"; } +}; + +// The templateURLServiceClient for Athena. Mainly for the interaction with +// history module (see chrome/browser/search_engines for Chrome implementation). +// TODO(mukai): Implement the contents of this class when it's necessary. +class AthenaTemplateURLServiceClient : public TemplateURLServiceClient { + public: + AthenaTemplateURLServiceClient() {} + virtual ~AthenaTemplateURLServiceClient() {} + + private: + // TemplateURLServiceClient: + virtual void SetOwner(TemplateURLService* owner) override {} + virtual void DeleteAllSearchTermsForKeyword(TemplateURLID id) override {} + virtual void SetKeywordSearchTermsForURL( + const GURL& url, + TemplateURLID id, + const base::string16& term) override {} + virtual void AddKeywordGeneratedVisit(const GURL& url) override {} + virtual void RestoreExtensionInfoIfNecessary( + TemplateURL* template_url) override {} + + DISALLOW_COPY_AND_ASSIGN(AthenaTemplateURLServiceClient); +}; + +// The AutocompleteProviderClient for Athena. +class AthenaAutocompleteProviderClient : public AutocompleteProviderClient { + public: + explicit AthenaAutocompleteProviderClient( + content::BrowserContext* browser_context) + : browser_context_(browser_context) {} + virtual ~AthenaAutocompleteProviderClient() {} + + virtual net::URLRequestContextGetter* RequestContext() override { + return browser_context_->GetRequestContext(); + } + virtual bool IsOffTheRecord() override { + return browser_context_->IsOffTheRecord(); + } + virtual std::string AcceptLanguages() override { + // TODO(hashimoto): Return the value stored in the prefs. + return "en-US"; + } + virtual bool SearchSuggestEnabled() override { return true; } + virtual bool ShowBookmarkBar() override { return false; } + virtual const AutocompleteSchemeClassifier& SchemeClassifier() override { + return scheme_classifier_; + } + virtual void Classify( + const base::string16& text, + bool prefer_keyword, + bool allow_exact_keyword_match, + metrics::OmniboxEventProto::PageClassification page_classification, + AutocompleteMatch* match, + GURL* alternate_nav_url) override {} + virtual history::URLDatabase* InMemoryDatabase() override { return NULL; } + virtual void DeleteMatchingURLsForKeywordFromHistory( + history::KeywordID keyword_id, + const base::string16& term) override {} + virtual bool TabSyncEnabledAndUnencrypted() override { return false; } + virtual void PrefetchImage(const GURL& url) override {} + + private: + content::BrowserContext* browser_context_; + AthenaShellSchemeClassifier scheme_classifier_; + + DISALLOW_COPY_AND_ASSIGN(AthenaAutocompleteProviderClient); +}; + +int ACMatchStyleToTagStyle(int styles) { + int tag_styles = 0; + if (styles & ACMatchClassification::URL) + tag_styles |= app_list::SearchResult::Tag::URL; + if (styles & ACMatchClassification::MATCH) + tag_styles |= app_list::SearchResult::Tag::MATCH; + if (styles & ACMatchClassification::DIM) + tag_styles |= app_list::SearchResult::Tag::DIM; + + return tag_styles; +} + +// Translates ACMatchClassifications into SearchResult tags. +void ACMatchClassificationsToTags(const base::string16& text, + const ACMatchClassifications& text_classes, + app_list::SearchResult::Tags* tags) { + int tag_styles = app_list::SearchResult::Tag::NONE; + size_t tag_start = 0; + + for (size_t i = 0; i < text_classes.size(); ++i) { + const ACMatchClassification& text_class = text_classes[i]; + + // Closes current tag. + if (tag_styles != app_list::SearchResult::Tag::NONE) { + tags->push_back(app_list::SearchResult::Tag( + tag_styles, tag_start, text_class.offset)); + tag_styles = app_list::SearchResult::Tag::NONE; + } + + if (text_class.style == ACMatchClassification::NONE) + continue; + + tag_start = text_class.offset; + tag_styles = ACMatchStyleToTagStyle(text_class.style); + } + + if (tag_styles != app_list::SearchResult::Tag::NONE) { + tags->push_back( + app_list::SearchResult::Tag(tag_styles, tag_start, text.length())); + } +} + +class UrlSearchResult : public app_list::SearchResult { + public: + UrlSearchResult(content::BrowserContext* browser_context, + const AutocompleteMatch& match) + : browser_context_(browser_context), match_(match) { + set_id(match_.destination_url.spec()); + + // Derive relevance from omnibox relevance and normalize it to [0, 1]. + // The magic number 1500 is the highest score of an omnibox result. + // See comments in autocomplete_provider.h. + set_relevance(match_.relevance / 1500.0); + + UpdateIcon(); + UpdateTitleAndDetails(); + } + + virtual ~UrlSearchResult() {} + + private: + // Overridden from app_list::SearchResult: + virtual scoped_ptr<app_list::SearchResult> Duplicate() override { + return make_scoped_ptr(new UrlSearchResult(browser_context_, match_)); + } + + virtual void Open(int event_flags) override { + Activity* activity = ActivityFactory::Get()->CreateWebActivity( + browser_context_, base::string16(), match_.destination_url); + Activity::Show(activity); + } + + void UpdateIcon() { + SetIcon(*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( + AutocompleteMatch::TypeToIcon(match_.type))); + } + + void UpdateTitleAndDetails() { + set_title(match_.contents); + SearchResult::Tags title_tags; + ACMatchClassificationsToTags( + match_.contents, match_.contents_class, &title_tags); + set_title_tags(title_tags); + + set_details(match_.description); + SearchResult::Tags details_tags; + ACMatchClassificationsToTags( + match_.description, match_.description_class, &details_tags); + set_details_tags(details_tags); + } + + content::BrowserContext* browser_context_; + AutocompleteMatch match_; + + DISALLOW_COPY_AND_ASSIGN(UrlSearchResult); +}; + +} // namespace + +UrlSearchProvider::UrlSearchProvider(content::BrowserContext* browser_context) + : browser_context_(browser_context), + // TODO(mukai): introduce the real parameters when it's necessary. + template_url_service_(new TemplateURLService( + NULL /* prefs */, + scoped_ptr<SearchTermsData>(new AthenaSearchTermsData()), + NULL /* KeywordWebDataService */, + scoped_ptr<TemplateURLServiceClient>( + new AthenaTemplateURLServiceClient()), + NULL /*GoogleURLTracker */, + NULL /* RapporService */, + base::Closure() /* dsp_change_callback */)), + provider_(new ::SearchProvider( + this, + template_url_service_.get(), + scoped_ptr<AutocompleteProviderClient>( + new AthenaAutocompleteProviderClient(browser_context_)))) { + template_url_service_->Load(); +} + +UrlSearchProvider::~UrlSearchProvider() { +} + +void UrlSearchProvider::Start(const base::string16& query) { + const bool minimal_changes = query == input_.text(); + input_ = AutocompleteInput(query, + base::string16::npos /* cursor_position */, + std::string() /* desired_tld */, + GURL() /* current_url */, + metrics::OmniboxEventProto::INVALID_SPEC, + false /* prevent_inline_autocomplete */, + false /* prefer_keyword */, + true /* allow_extract_keyword_match */, + true /* want_asynchronous_matches */, + AthenaShellSchemeClassifier()); + + // Clearing results here may cause unexpected results. + // TODO(mukai): fix this by fixing crbug.com/415500 + if (!minimal_changes) + ClearResults(); + + if (input_.type() == metrics::OmniboxInputType::URL) { + // TODO(hashimoto): Componentize HistoryURLProvider and remove this code. + AutocompleteMatch what_you_typed_match( + NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED); + what_you_typed_match.destination_url = input_.canonicalized_url(); + what_you_typed_match.contents = input_.text(); + what_you_typed_match.relevance = kScoreForWhatYouTypedResult; + Add(scoped_ptr<app_list::SearchResult>( + new UrlSearchResult(browser_context_, what_you_typed_match))); + } + + provider_->Start(input_, minimal_changes); +} + +void UrlSearchProvider::Stop() { + provider_->Stop(false); +} + +void UrlSearchProvider::OnProviderUpdate(bool updated_matches) { + if (!updated_matches) + return; + + const ACMatches& matches = provider_->matches(); + for (ACMatches::const_iterator it = matches.begin(); it != matches.end(); + ++it) { + if (!it->destination_url.is_valid()) + continue; + + Add(scoped_ptr<app_list::SearchResult>( + new UrlSearchResult(browser_context_, *it))); + } +} + +} // namespace athena diff --git a/athena/extensions/shell/url_search_provider.h b/athena/extensions/shell/url_search_provider.h new file mode 100644 index 0000000..95026d9 --- /dev/null +++ b/athena/extensions/shell/url_search_provider.h @@ -0,0 +1,51 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ATHENA_EXTENSIONS_SHELL_URL_SEARCH_PROVIDER_H_ +#define ATHENA_EXTENSIONS_SHELL_URL_SEARCH_PROVIDER_H_ + +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "components/omnibox/autocomplete_input.h" +#include "components/omnibox/autocomplete_provider_listener.h" +#include "ui/app_list/search_provider.h" + +class AutocompleteProvider; +class TemplateURLService; + +namespace content { +class BrowserContext; +} + +namespace athena { + +// A sample search provider. +class UrlSearchProvider : public app_list::SearchProvider, + public AutocompleteProviderListener { + public: + UrlSearchProvider(content::BrowserContext* browser_context); + virtual ~UrlSearchProvider(); + + // Overridden from app_list::SearchProvider + virtual void Start(const base::string16& query) override; + virtual void Stop() override; + + // Overridden from AutocompleteProviderListener + virtual void OnProviderUpdate(bool updated_matches) override; + + private: + content::BrowserContext* browser_context_; + + // TODO(mukai): This should be provided through BrowserContextKeyedService. + scoped_ptr<TemplateURLService> template_url_service_; + + AutocompleteInput input_; + scoped_refptr<AutocompleteProvider> provider_; + + DISALLOW_COPY_AND_ASSIGN(UrlSearchProvider); +}; + +} // namespace athena + +#endif // ATHENA_EXTENSIONS_SHELL_URL_SEARCH_PROVIDER_H_ |