| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/ui/web_contents_set_background_color.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "content/public/browser/render_view_host.h" | |
| 9 #include "content/public/browser/render_widget_host.h" | |
| 10 #include "content/public/browser/render_widget_host_view.h" | |
| 11 | |
| 12 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chromeos::WebContentsSetBackgroundColor); | |
| 13 | |
| 14 namespace chromeos { | |
| 15 | |
| 16 // static | |
| 17 void WebContentsSetBackgroundColor::CreateForWebContentsWithColor( | |
| 18 content::WebContents* web_contents, | |
| 19 SkColor color) { | |
| 20 if (FromWebContents(web_contents)) | |
| 21 return; | |
| 22 | |
| 23 // SupportsUserData::Data takes ownership over the | |
| 24 // WebContentsSetBackgroundColor instance and will destroy it when the | |
| 25 // WebContents instance is destroyed. | |
| 26 web_contents->SetUserData( | |
| 27 UserDataKey(), | |
| 28 base::WrapUnique(new WebContentsSetBackgroundColor(web_contents, color))); | |
| 29 } | |
| 30 | |
| 31 WebContentsSetBackgroundColor::WebContentsSetBackgroundColor( | |
| 32 content::WebContents* web_contents, | |
| 33 SkColor color) | |
| 34 : content::WebContentsObserver(web_contents), color_(color) {} | |
| 35 | |
| 36 WebContentsSetBackgroundColor::~WebContentsSetBackgroundColor() {} | |
| 37 | |
| 38 void WebContentsSetBackgroundColor::RenderViewReady() { | |
| 39 web_contents() | |
| 40 ->GetRenderViewHost() | |
| 41 ->GetWidget() | |
| 42 ->GetView() | |
| 43 ->SetBackgroundColor(color_); | |
| 44 } | |
| 45 | |
| 46 void WebContentsSetBackgroundColor::RenderViewCreated( | |
| 47 content::RenderViewHost* render_view_host) { | |
| 48 render_view_host->GetWidget()->GetView()->SetBackgroundColor(color_); | |
| 49 } | |
| 50 | |
| 51 void WebContentsSetBackgroundColor::RenderViewHostChanged( | |
| 52 content::RenderViewHost* old_host, | |
| 53 content::RenderViewHost* new_host) { | |
| 54 new_host->GetWidget()->GetView()->SetBackgroundColor(color_); | |
| 55 } | |
| 56 | |
| 57 } // namespace chromeos | |
| OLD | NEW |