Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h" | 5 #include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "build/build_config.h" | |
| 8 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 9 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search/search.h" | 11 #include "chrome/browser/search/search.h" |
| 11 #include "chrome/browser/ssl/security_state_tab_helper.h" | 12 #include "chrome/browser/ssl/security_state_tab_helper.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 14 #include "components/google/core/browser/google_util.h" | 15 #include "components/google/core/browser/google_util.h" |
| 15 #include "components/omnibox/browser/autocomplete_input.h" | 16 #include "components/omnibox/browser/autocomplete_input.h" |
| 16 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
| 17 #include "components/security_state/core/security_state.h" | 18 #include "components/security_state/core/security_state.h" |
| 18 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
| 19 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
| 20 #include "content/public/browser/ssl_status.h" | 21 #include "content/public/browser/ssl_status.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
| 23 #include "extensions/common/constants.h" | 24 #include "extensions/common/constants.h" |
| 24 | 25 |
| 25 #if !defined(OS_ANDROID) | 26 #if !defined(OS_ANDROID) |
| 26 #include "components/omnibox/browser/vector_icons.h" // nogncheck | 27 #include "components/omnibox/browser/vector_icons.h" // nogncheck |
| 27 #include "components/toolbar/vector_icons.h" // nogncheck | 28 #include "components/toolbar/vector_icons.h" // nogncheck |
| 28 #endif | 29 #endif |
| 29 | 30 |
| 31 #if defined(OS_ANDROID) | |
| 32 #include "chrome/browser/android/offline_pages/offline_page_utils.h" | |
| 33 #endif | |
| 34 | |
| 30 ChromeToolbarModelDelegate::ChromeToolbarModelDelegate() {} | 35 ChromeToolbarModelDelegate::ChromeToolbarModelDelegate() {} |
| 31 | 36 |
| 32 ChromeToolbarModelDelegate::~ChromeToolbarModelDelegate() {} | 37 ChromeToolbarModelDelegate::~ChromeToolbarModelDelegate() {} |
| 33 | 38 |
| 34 base::string16 ChromeToolbarModelDelegate::FormattedStringWithEquivalentMeaning( | 39 base::string16 ChromeToolbarModelDelegate::FormattedStringWithEquivalentMeaning( |
| 35 const GURL& url, | 40 const GURL& url, |
| 36 const base::string16& formatted_url) const { | 41 const base::string16& formatted_url) const { |
| 37 return AutocompleteInput::FormattedStringWithEquivalentMeaning( | 42 return AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 38 url, formatted_url, ChromeAutocompleteSchemeClassifier(GetProfile())); | 43 url, formatted_url, ChromeAutocompleteSchemeClassifier(GetProfile())); |
| 39 } | 44 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 if (url.SchemeIs(content::kChromeUIScheme)) | 124 if (url.SchemeIs(content::kChromeUIScheme)) |
| 120 return &toolbar::kProductIcon; | 125 return &toolbar::kProductIcon; |
| 121 | 126 |
| 122 if (url.SchemeIs(extensions::kExtensionScheme)) | 127 if (url.SchemeIs(extensions::kExtensionScheme)) |
| 123 return &omnibox::kExtensionAppIcon; | 128 return &omnibox::kExtensionAppIcon; |
| 124 #endif | 129 #endif |
| 125 | 130 |
| 126 return nullptr; | 131 return nullptr; |
| 127 } | 132 } |
| 128 | 133 |
| 134 bool ChromeToolbarModelDelegate::IsOfflinePage() const { | |
| 135 #if defined(OS_ANDROID) | |
| 136 content::WebContents* web_contents = GetActiveWebContents(); | |
| 137 if (!web_contents) | |
| 138 return false; | |
| 139 return offline_pages::OfflinePageUtils::GetOfflinePageFromWebContents( | |
| 140 web_contents) != nullptr; | |
|
Peter Kasting
2017/07/06 06:08:07
Nit: Simpler:
return web_contents &&
o
| |
| 141 #else | |
| 142 return false; | |
| 143 #endif | |
| 144 } | |
| 145 | |
| 129 content::NavigationController* | 146 content::NavigationController* |
| 130 ChromeToolbarModelDelegate::GetNavigationController() const { | 147 ChromeToolbarModelDelegate::GetNavigationController() const { |
| 131 // This |current_tab| can be null during the initialization of the toolbar | 148 // This |current_tab| can be null during the initialization of the toolbar |
| 132 // during window creation (i.e. before any tabs have been added to the | 149 // during window creation (i.e. before any tabs have been added to the |
| 133 // window). | 150 // window). |
| 134 content::WebContents* current_tab = GetActiveWebContents(); | 151 content::WebContents* current_tab = GetActiveWebContents(); |
| 135 return current_tab ? ¤t_tab->GetController() : nullptr; | 152 return current_tab ? ¤t_tab->GetController() : nullptr; |
| 136 } | 153 } |
| 137 | 154 |
| 138 content::NavigationEntry* ChromeToolbarModelDelegate::GetNavigationEntry() | 155 content::NavigationEntry* ChromeToolbarModelDelegate::GetNavigationEntry() |
| 139 const { | 156 const { |
| 140 content::NavigationController* controller = GetNavigationController(); | 157 content::NavigationController* controller = GetNavigationController(); |
| 141 return controller ? controller->GetVisibleEntry() : nullptr; | 158 return controller ? controller->GetVisibleEntry() : nullptr; |
| 142 } | 159 } |
| 143 | 160 |
| 144 Profile* ChromeToolbarModelDelegate::GetProfile() const { | 161 Profile* ChromeToolbarModelDelegate::GetProfile() const { |
| 145 content::NavigationController* controller = GetNavigationController(); | 162 content::NavigationController* controller = GetNavigationController(); |
| 146 return controller | 163 return controller |
| 147 ? Profile::FromBrowserContext(controller->GetBrowserContext()) | 164 ? Profile::FromBrowserContext(controller->GetBrowserContext()) |
| 148 : nullptr; | 165 : nullptr; |
| 149 } | 166 } |
| OLD | NEW |