Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(655)

Unified Diff: athena/main/url_search_provider.cc

Issue 382683002: Add basic support of URL/search query to Athena home card. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git-cl format Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « athena/main/url_search_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: athena/main/url_search_provider.cc
diff --git a/athena/main/url_search_provider.cc b/athena/main/url_search_provider.cc
index ce386ea28682be29f6fea73d9e4f44397215cdae..cfa930ca167675e8fae5c7da2cb69cb6ac5f14c3 100644
--- a/athena/main/url_search_provider.cc
+++ b/athena/main/url_search_provider.cc
@@ -7,6 +7,15 @@
#include "athena/activity/public/activity_factory.h"
#include "athena/activity/public/activity_manager.h"
#include "base/strings/utf_string_conversions.h"
+#include "components/autocomplete/autocomplete_input.h"
+#include "components/autocomplete/autocomplete_scheme_classifier.h"
+#include "components/metrics/proto/omnibox_event.pb.h"
+#include "components/metrics/proto/omnibox_input_type.pb.h"
+#include "components/search_engines/search_terms_data.h"
+#include "components/search_engines/template_url.h"
+#include "components/search_engines/template_url_service.h"
+#include "components/search_engines/template_url_service_client.h"
+#include "net/url_request/url_request.h"
#include "ui/app_list/search_result.h"
#include "url/gurl.h"
@@ -14,15 +23,67 @@ namespace athena {
namespace {
+// The AutocompleteSchemeClassifier implementation for Athena.
+// TODO(mukai): Introduce supports of normal schemes like about: or blob:
+class AthenaSchemeClassifier : public AutocompleteSchemeClassifier {
+ public:
+ AthenaSchemeClassifier() {}
+
+ // AutocompleteSchemeClassifier:
+ virtual metrics::OmniboxInputType::Type GetInputTypeForScheme(
+ const std::string& scheme) const OVERRIDE {
+ if (net::URLRequest::IsHandledProtocol(scheme))
+ return metrics::OmniboxInputType::URL;
+ return metrics::OmniboxInputType::INVALID;
+ }
+};
+
+// 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 {}
+
+ DISALLOW_COPY_AND_ASSIGN(AthenaTemplateURLServiceClient);
+};
+
class UrlSearchResult : public app_list::SearchResult {
public:
UrlSearchResult(content::BrowserContext* browser_context,
+ TemplateURLService* template_url_service,
const base::string16& query)
- : browser_context_(browser_context), url_(query) {
+ : browser_context_(browser_context),
+ template_url_service_(template_url_service),
+ input_(query,
+ base::string16::npos /* cursor_position */,
+ base::string16() /* 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 */,
+ AthenaSchemeClassifier()) {
set_title(query);
app_list::SearchResult::Tags title_tags;
+ if (input_.type() == metrics::OmniboxInputType::URL) {
+ title_tags.push_back(app_list::SearchResult::Tag(
+ app_list::SearchResult::Tag::URL, 0, query.size()));
+ }
title_tags.push_back(app_list::SearchResult::Tag(
- app_list::SearchResult::Tag::URL, 0, query.size()));
+ app_list::SearchResult::Tag::MATCH, 0, query.size()));
set_title_tags(title_tags);
set_id(base::UTF16ToUTF8(query));
}
@@ -30,12 +91,24 @@ class UrlSearchResult : public app_list::SearchResult {
private:
// Overriddenn from app_list::SearchResult:
virtual void Open(int event_flags) OVERRIDE {
+ GURL url;
+ if (input_.type() == metrics::OmniboxInputType::URL) {
+ url = input_.canonicalized_url();
+ } else {
+ TemplateURL* template_url =
+ template_url_service_->GetDefaultSearchProvider();
+ const TemplateURLRef& search_url = template_url->url_ref();
+ TemplateURLRef::SearchTermsArgs search_terms_args(input_.text());
+ url = GURL(search_url.ReplaceSearchTerms(
+ search_terms_args, template_url_service_->search_terms_data()));
+ }
ActivityManager::Get()->AddActivity(
- ActivityFactory::Get()->CreateWebActivity(browser_context_, url_));
+ ActivityFactory::Get()->CreateWebActivity(browser_context_, url));
}
content::BrowserContext* browser_context_;
- const GURL url_;
+ TemplateURLService* template_url_service_;
+ AutocompleteInput input_;
DISALLOW_COPY_AND_ASSIGN(UrlSearchResult);
};
@@ -43,7 +116,18 @@ class UrlSearchResult : public app_list::SearchResult {
} // namespace
UrlSearchProvider::UrlSearchProvider(content::BrowserContext* browser_context)
- : browser_context_(browser_context) {
+ : browser_context_(browser_context),
+ // TODO(mukai): introduce the real parameters when it's necessary.
+ template_url_service_(
+ new TemplateURLService(NULL /* prefs */,
+ make_scoped_ptr(new SearchTermsData()),
+ NULL /* KeywordWebDataService */,
+ scoped_ptr<TemplateURLServiceClient>(
+ new AthenaTemplateURLServiceClient()),
+ NULL /*GoogleURLTracker */,
+ NULL /* RapporService */,
+ base::Closure() /* dsp_change_callback */)) {
+ template_url_service_->Load();
}
UrlSearchProvider::~UrlSearchProvider() {
@@ -51,8 +135,8 @@ UrlSearchProvider::~UrlSearchProvider() {
void UrlSearchProvider::Start(const base::string16& query) {
ClearResults();
- Add(scoped_ptr<app_list::SearchResult>(
- new UrlSearchResult(browser_context_, query)));
+ Add(scoped_ptr<app_list::SearchResult>(new UrlSearchResult(
+ browser_context_, template_url_service_.get(), query)));
}
void UrlSearchProvider::Stop() {
« no previous file with comments | « athena/main/url_search_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698