Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / omnibox / omnibox_current_page_delegate_impl.cc
blob952497c7dfe296b4b6a536d245db211242a85dcd
1 // Copyright 2013 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.
5 #include "chrome/browser/ui/omnibox/omnibox_current_page_delegate_impl.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/autocomplete/autocomplete_match.h"
9 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
10 #include "chrome/browser/predictors/autocomplete_action_predictor.h"
11 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search/search.h"
14 #include "chrome/browser/search_engines/template_url_service.h"
15 #include "chrome/browser/search_engines/template_url_service_factory.h"
16 #include "chrome/browser/sessions/session_tab_helper.h"
17 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
18 #include "chrome/browser/ui/search/search_tab_helper.h"
19 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/web_contents.h"
21 #include "content/public/browser/web_contents_view.h"
22 #include "ui/base/window_open_disposition.h"
23 #include "url/gurl.h"
25 OmniboxCurrentPageDelegateImpl::OmniboxCurrentPageDelegateImpl(
26 OmniboxEditController* controller,
27 Profile* profile)
28 : controller_(controller),
29 profile_(profile) {}
31 OmniboxCurrentPageDelegateImpl::~OmniboxCurrentPageDelegateImpl() {}
33 bool OmniboxCurrentPageDelegateImpl::CurrentPageExists() const {
34 return (controller_->GetWebContents() != NULL);
37 const GURL& OmniboxCurrentPageDelegateImpl::GetURL() const {
38 return controller_->GetWebContents()->GetURL();
41 bool OmniboxCurrentPageDelegateImpl::IsInstantNTP() const {
42 return chrome::IsInstantNTP(controller_->GetWebContents());
45 bool OmniboxCurrentPageDelegateImpl::IsSearchResultsPage() const {
46 Profile* profile = Profile::FromBrowserContext(
47 controller_->GetWebContents()->GetBrowserContext());
48 return TemplateURLServiceFactory::GetForProfile(profile)->
49 IsSearchResultsPageFromDefaultSearchProvider(GetURL());
52 bool OmniboxCurrentPageDelegateImpl::IsLoading() const {
53 return controller_->GetWebContents()->IsLoading();
56 content::NavigationController&
57 OmniboxCurrentPageDelegateImpl::GetNavigationController() const {
58 return controller_->GetWebContents()->GetController();
61 const SessionID& OmniboxCurrentPageDelegateImpl::GetSessionID() const {
62 return SessionTabHelper::FromWebContents(
63 controller_->GetWebContents())->session_id();
66 bool OmniboxCurrentPageDelegateImpl::ProcessExtensionKeyword(
67 TemplateURL* template_url,
68 const AutocompleteMatch& match,
69 WindowOpenDisposition disposition) {
70 if (!template_url->IsExtensionKeyword())
71 return false;
73 // Strip the keyword + leading space off the input.
74 size_t prefix_length = match.keyword.length() + 1;
75 extensions::ExtensionOmniboxEventRouter::OnInputEntered(
76 controller_->GetWebContents(),
77 template_url->GetExtensionId(),
78 UTF16ToUTF8(match.fill_into_edit.substr(prefix_length)),
79 disposition);
81 return true;
84 void OmniboxCurrentPageDelegateImpl::NotifySearchTabHelper(
85 bool user_input_in_progress,
86 bool cancelling) {
87 if (!controller_->GetWebContents())
88 return;
89 SearchTabHelper::FromWebContents(
90 controller_->GetWebContents())->OmniboxEditModelChanged(
91 user_input_in_progress, cancelling);
94 void OmniboxCurrentPageDelegateImpl::DoPrerender(
95 const AutocompleteMatch& match) {
96 content::WebContents* web_contents = controller_->GetWebContents();
97 gfx::Rect container_bounds;
98 web_contents->GetView()->GetContainerBounds(&container_bounds);
99 predictors::AutocompleteActionPredictorFactory::GetForProfile(profile_)->
100 StartPrerendering(
101 match.destination_url,
102 web_contents->GetController().GetSessionStorageNamespaceMap(),
103 container_bounds.size());