Commit 9476d8e2 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Fix null-dereference in GetOmniboxColor

GetThemeProvider() will return nullptr before the view is added to the widget,
so avoid using it in OmniboxTabSwitchButton and instead obtain the theme from
OmniboxResultView.

BUG=1004012
R=pkasting

Change-Id: I464b7a81b73df06fb18d6c2f6a9a9180f0d79079
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1804820
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696629}
parent 0f73014d
......@@ -99,12 +99,12 @@ void OmniboxResultView::SetMatch(const AutocompleteMatch& match) {
popup_contents_view_, this,
l10n_util::GetStringUTF16(IDS_OMNIBOX_TAB_SUGGEST_HINT),
l10n_util::GetStringUTF16(IDS_OMNIBOX_TAB_SUGGEST_SHORT_HINT),
omnibox::kSwitchIcon);
omnibox::kSwitchIcon, theme_provider_);
} else {
suggestion_tab_switch_button_ = std::make_unique<OmniboxTabSwitchButton>(
// TODO(krb): Make official strings when we accept the feature.
popup_contents_view_, this, base::ASCIIToUTF16("Open in this tab"),
base::ASCIIToUTF16("Open"), omnibox::kSwitchIcon);
base::ASCIIToUTF16("Open"), omnibox::kSwitchIcon, theme_provider_);
}
suggestion_tab_switch_button_->set_owned_by_client();
......
......@@ -31,14 +31,16 @@ OmniboxTabSwitchButton::OmniboxTabSwitchButton(
OmniboxResultView* result_view,
const base::string16& hint,
const base::string16& hint_short,
const gfx::VectorIcon& icon)
const gfx::VectorIcon& icon,
const ui::ThemeProvider* theme_provider)
: MdTextButton(result_view, views::style::CONTEXT_BUTTON_MD),
popup_contents_view_(popup_contents_view),
result_view_(result_view),
initialized_(false),
animation_(new gfx::SlideAnimation(this)),
hint_(hint),
hint_short_(hint_short) {
hint_short_(hint_short),
theme_provider_(theme_provider) {
SetBgColorOverride(GetBackgroundColor());
SetImage(STATE_NORMAL, gfx::CreateVectorIcon(
icon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE),
......@@ -181,14 +183,14 @@ SkPath OmniboxTabSwitchButton::GetFocusRingPath() const {
}
SkColor OmniboxTabSwitchButton::GetBackgroundColor() const {
return GetOmniboxColor(GetThemeProvider(), OmniboxPart::RESULTS_BACKGROUND,
return GetOmniboxColor(theme_provider_, OmniboxPart::RESULTS_BACKGROUND,
state() == STATE_HOVERED ? OmniboxPartState::HOVERED
: OmniboxPartState::NORMAL);
}
void OmniboxTabSwitchButton::SetPressed() {
SetBgColorOverride(color_utils::AlphaBlend(
GetOmniboxColor(GetThemeProvider(), OmniboxPart::RESULTS_BACKGROUND,
GetOmniboxColor(theme_provider_, OmniboxPart::RESULTS_BACKGROUND,
OmniboxPartState::SELECTED),
SK_ColorBLACK, 0.8f));
}
......
......@@ -20,7 +20,8 @@ class OmniboxTabSwitchButton : public views::MdTextButton {
OmniboxResultView* result_view,
const base::string16& hint,
const base::string16& hint_short,
const gfx::VectorIcon& icon);
const gfx::VectorIcon& icon,
const ui::ThemeProvider* theme_provider);
~OmniboxTabSwitchButton() override;
......@@ -86,6 +87,8 @@ class OmniboxTabSwitchButton : public views::MdTextButton {
base::string16 hint_;
base::string16 hint_short_;
const ui::ThemeProvider* theme_provider_;
DISALLOW_COPY_AND_ASSIGN(OmniboxTabSwitchButton);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment