OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ios/chrome/browser/ui/omnibox/chrome_omnibox_client_ios.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/favicon/ios/web_favicon_driver.h" |
| 10 #include "components/omnibox/browser/omnibox_edit_controller.h" |
| 11 #include "components/search_engines/template_url_service.h" |
| 12 #include "ios/chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 13 #include "ios/chrome/browser/autocomplete/autocomplete_provider_client_impl.h" |
| 14 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
| 15 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" |
| 16 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 17 #include "ios/chrome/browser/chrome_url_constants.h" |
| 18 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" |
| 19 #include "ios/chrome/browser/sessions/ios_chrome_session_tab_helper.h" |
| 20 #include "ios/chrome/browser/ui/omnibox/web_omnibox_edit_controller.h" |
| 21 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 22 #import "ios/web/public/navigation_manager.h" |
| 23 #include "ios/web/public/web_state/web_state.h" |
| 24 #include "url/gurl.h" |
| 25 |
| 26 ChromeOmniboxClientIOS::ChromeOmniboxClientIOS( |
| 27 WebOmniboxEditController* controller, |
| 28 ios::ChromeBrowserState* browser_state) |
| 29 : controller_(controller), browser_state_(browser_state) {} |
| 30 |
| 31 ChromeOmniboxClientIOS::~ChromeOmniboxClientIOS() {} |
| 32 |
| 33 std::unique_ptr<AutocompleteProviderClient> |
| 34 ChromeOmniboxClientIOS::CreateAutocompleteProviderClient() { |
| 35 return base::MakeUnique<AutocompleteProviderClientImpl>(browser_state_); |
| 36 } |
| 37 |
| 38 std::unique_ptr<OmniboxNavigationObserver> |
| 39 ChromeOmniboxClientIOS::CreateOmniboxNavigationObserver( |
| 40 const base::string16& text, |
| 41 const AutocompleteMatch& match, |
| 42 const AutocompleteMatch& alternate_nav_match) { |
| 43 // TODO(blundell): Bring up an OmniboxNavigationObserver implementation on |
| 44 // iOS if/once iOS wants to start using the ShortcutsProvider. |
| 45 // crbug.com/511965 |
| 46 return nullptr; |
| 47 } |
| 48 |
| 49 bool ChromeOmniboxClientIOS::CurrentPageExists() const { |
| 50 return (controller_->GetWebState() != nullptr); |
| 51 } |
| 52 |
| 53 const GURL& ChromeOmniboxClientIOS::GetURL() const { |
| 54 return CurrentPageExists() ? controller_->GetWebState()->GetVisibleURL() |
| 55 : GURL::EmptyGURL(); |
| 56 } |
| 57 |
| 58 bool ChromeOmniboxClientIOS::IsLoading() const { |
| 59 return controller_->GetWebState()->IsLoading(); |
| 60 } |
| 61 |
| 62 bool ChromeOmniboxClientIOS::IsPasteAndGoEnabled() const { |
| 63 return false; |
| 64 } |
| 65 |
| 66 bool ChromeOmniboxClientIOS::IsInstantNTP() const { |
| 67 // This is currently only called by the OmniboxEditModel to determine if the |
| 68 // Google landing page is showing. |
| 69 // TODO(lliabraa): This should also check the user's default search engine |
| 70 // because if they're not using Google the Google landing page is not shown |
| 71 // (crbug/315563). |
| 72 GURL currentURL = controller_->GetWebState()->GetVisibleURL(); |
| 73 return currentURL == GURL(kChromeUINewTabURL); |
| 74 } |
| 75 |
| 76 bool ChromeOmniboxClientIOS::IsSearchResultsPage() const { |
| 77 ios::ChromeBrowserState* browser_state = |
| 78 ios::ChromeBrowserState::FromBrowserState( |
| 79 controller_->GetWebState()->GetBrowserState()); |
| 80 return ios::TemplateURLServiceFactory::GetForBrowserState(browser_state) |
| 81 ->IsSearchResultsPageFromDefaultSearchProvider(GetURL()); |
| 82 } |
| 83 |
| 84 bool ChromeOmniboxClientIOS::IsNewTabPage(const std::string& url) const { |
| 85 return url == kChromeUINewTabURL; |
| 86 } |
| 87 |
| 88 bool ChromeOmniboxClientIOS::IsHomePage(const std::string& url) const { |
| 89 // iOS does not have a notion of home page. |
| 90 return false; |
| 91 } |
| 92 |
| 93 const SessionID& ChromeOmniboxClientIOS::GetSessionID() const { |
| 94 return IOSChromeSessionTabHelper::FromWebState(controller_->GetWebState()) |
| 95 ->session_id(); |
| 96 } |
| 97 |
| 98 bookmarks::BookmarkModel* ChromeOmniboxClientIOS::GetBookmarkModel() { |
| 99 return ios::BookmarkModelFactory::GetForBrowserState(browser_state_); |
| 100 } |
| 101 |
| 102 TemplateURLService* ChromeOmniboxClientIOS::GetTemplateURLService() { |
| 103 return ios::TemplateURLServiceFactory::GetForBrowserState(browser_state_); |
| 104 } |
| 105 |
| 106 const AutocompleteSchemeClassifier& |
| 107 ChromeOmniboxClientIOS::GetSchemeClassifier() const { |
| 108 return scheme_classifier_; |
| 109 } |
| 110 |
| 111 AutocompleteClassifier* ChromeOmniboxClientIOS::GetAutocompleteClassifier() { |
| 112 return ios::AutocompleteClassifierFactory::GetForBrowserState(browser_state_); |
| 113 } |
| 114 |
| 115 gfx::Image ChromeOmniboxClientIOS::GetIconIfExtensionMatch( |
| 116 const AutocompleteMatch& match) const { |
| 117 // Extensions are not supported on iOS. |
| 118 return gfx::Image(); |
| 119 } |
| 120 |
| 121 bool ChromeOmniboxClientIOS::ProcessExtensionKeyword( |
| 122 TemplateURL* template_url, |
| 123 const AutocompleteMatch& match, |
| 124 WindowOpenDisposition disposition, |
| 125 OmniboxNavigationObserver* observer) { |
| 126 // Extensions are not supported on iOS. |
| 127 return false; |
| 128 } |
| 129 |
| 130 void ChromeOmniboxClientIOS::OnInputStateChanged() {} |
| 131 |
| 132 void ChromeOmniboxClientIOS::OnFocusChanged(OmniboxFocusState state, |
| 133 OmniboxFocusChangeReason reason) {} |
| 134 |
| 135 void ChromeOmniboxClientIOS::OnResultChanged( |
| 136 const AutocompleteResult& result, |
| 137 bool default_match_changed, |
| 138 const base::Callback<void(const SkBitmap& bitmap)>& on_bitmap_fetched) {} |
| 139 |
| 140 void ChromeOmniboxClientIOS::OnCurrentMatchChanged(const AutocompleteMatch&) {} |
| 141 |
| 142 void ChromeOmniboxClientIOS::OnURLOpenedFromOmnibox(OmniboxLog* log) {} |
| 143 |
| 144 void ChromeOmniboxClientIOS::OnBookmarkLaunched() { |
| 145 RecordBookmarkLaunch(BOOKMARK_LAUNCH_LOCATION_OMNIBOX); |
| 146 } |
| 147 |
| 148 void ChromeOmniboxClientIOS::DiscardNonCommittedNavigations() { |
| 149 controller_->GetWebState() |
| 150 ->GetNavigationManager() |
| 151 ->DiscardNonCommittedItems(); |
| 152 } |
| 153 |
| 154 const base::string16& ChromeOmniboxClientIOS::GetTitle() const { |
| 155 return controller_->GetWebState()->GetTitle(); |
| 156 } |
| 157 |
| 158 gfx::Image ChromeOmniboxClientIOS::GetFavicon() const { |
| 159 return favicon::WebFaviconDriver::FromWebState(controller_->GetWebState()) |
| 160 ->GetFavicon(); |
| 161 } |
| 162 |
| 163 void ChromeOmniboxClientIOS::OnTextChanged( |
| 164 const AutocompleteMatch& current_match, |
| 165 bool user_input_in_progress, |
| 166 base::string16& user_text, |
| 167 const AutocompleteResult& result, |
| 168 bool is_popup_open, |
| 169 bool has_focus) {} |
| 170 |
| 171 void ChromeOmniboxClientIOS::OnInputAccepted(const AutocompleteMatch& match) {} |
| 172 |
| 173 void ChromeOmniboxClientIOS::OnRevert() {} |
OLD | NEW |