Propagate theme color updates to the WebContentsDelegates.
When the theme color on a page changes after the first visually non-
empty paint, this should be propagated to the delegates so that the
browser UI can be updated accordingly.
BUG=474371
Review URL: https://codereview.chromium.org/1149073006
Cr-Commit-Position: refs/heads/master@{#332180}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index b9d8592..f92180f 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -315,6 +315,7 @@
has_accessed_initial_document_(false),
theme_color_(SK_ColorTRANSPARENT),
last_sent_theme_color_(SK_ColorTRANSPARENT),
+ did_first_visually_non_empty_paint_(false),
capturer_count_(0),
should_normally_be_visible_(true),
is_being_destroyed_(false),
@@ -2735,6 +2736,8 @@
if (rwhvb)
rwhvb->OnDidNavigateMainFrameToNewPage();
+ did_first_visually_non_empty_paint_ = false;
+
// Reset theme color on navigation to new page.
theme_color_ = SK_ColorTRANSPARENT;
}
@@ -2789,9 +2792,16 @@
}
void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
- // Update the theme color. This is to be published to observers on visually
- // non empty paint.
+ // Update the theme color. This is to be published to observers after the
+ // first visually non-empty paint.
theme_color_ = theme_color;
+
+ if (did_first_visually_non_empty_paint_ &&
+ last_sent_theme_color_ != theme_color_) {
+ FOR_EACH_OBSERVER(WebContentsObserver, observers_,
+ DidChangeThemeColor(theme_color_));
+ last_sent_theme_color_ = theme_color_;
+ }
}
void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
@@ -3190,6 +3200,8 @@
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidFirstVisuallyNonEmptyPaint());
+ did_first_visually_non_empty_paint_ = true;
+
if (theme_color_ != last_sent_theme_color_) {
// Theme color should have updated by now if there was one.
FOR_EACH_OBSERVER(WebContentsObserver, observers_,