Commit b2a9cbbf authored by Thoren Paulson's avatar Thoren Paulson Committed by Commit Bot

[Chromecast] Add background color flag.

Adds a flag (--cast-app-background-color) that changes the background
color used when displaying web apps. This color is often shown briefly
before Chromium renders a web app.

Bug: internal b/70181260
Test: use flag on ATV
Change-Id: I3bc0989aeabbf639116c1b30fffb11f66b56c4cd
Reviewed-on: https://chromium-review.googlesource.com/897466
Commit-Queue: Thoren Paulson <thoren@chromium.org>
Reviewed-by: default avatarStephen Lanham <slan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540340}
parent 2d070936
......@@ -294,6 +294,7 @@ if (is_android) {
# TODO(sanfin): Move these files to another target.
"$java_src_dir/org/chromium/chromecast/base/CastSettingsManager.java",
"$java_src_dir/org/chromium/chromecast/base/CastSwitches.java",
"$java_src_dir/org/chromium/chromecast/base/ChromecastConfigAndroid.java",
"$java_src_dir/org/chromium/chromecast/base/DumpstateWriter.java",
"$java_src_dir/org/chromium/chromecast/base/SystemTimeChangeNotifierAndroid.java",
......
......@@ -133,6 +133,9 @@ const char kDesktopWindow1080p[] = "desktop-window-1080p";
// Enables input event handling by the window manager.
const char kEnableInput[] = "enable-input";
// Background color used when Chromium hasn't rendered anything yet.
const char kCastAppBackgroundColor[] = "cast-app-background-color";
} // namespace switches
namespace chromecast {
......@@ -187,4 +190,24 @@ int GetSwitchValueNonNegativeInt(const std::string& switch_name,
return value;
}
uint32_t GetSwitchValueColor(const std::string& switch_name,
const uint32_t default_value) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(switch_name)) {
return default_value;
}
uint32_t arg_value = 0;
if (!base::HexStringToUInt(
command_line->GetSwitchValueASCII(switch_name).substr(1),
&arg_value)) {
LOG(ERROR) << "Invalid value for " << switch_name << " ("
<< command_line->GetSwitchValueASCII(switch_name)
<< "), using default.";
return default_value;
}
return arg_value;
}
} // namespace chromecast
......@@ -5,6 +5,7 @@
#ifndef CHROMECAST_BASE_CHROMECAST_SWITCHES_H_
#define CHROMECAST_BASE_CHROMECAST_SWITCHES_H_
#include <cstdint>
#include <string>
#include "build/build_config.h"
......@@ -73,6 +74,9 @@ extern const char kDesktopWindow1080p[];
// UI switches
extern const char kEnableInput[];
// Background color used when Chromium hasn't rendered anything yet.
extern const char kCastAppBackgroundColor[];
} // namespace switches
namespace chromecast {
......@@ -96,6 +100,10 @@ int GetSwitchValueInt(const std::string& switch_name, const int default_value);
int GetSwitchValueNonNegativeInt(const std::string& switch_name,
const int default_value);
// Gets a color value from the format "#AARRGGBB" (hex).
uint32_t GetSwitchValueColor(const std::string& switch_name,
const uint32_t default_value);
} // namespace chromecast
#endif // CHROMECAST_BASE_CHROMECAST_SWITCHES_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chromecast.base;
import android.graphics.Color;
import org.chromium.base.CommandLine;
import org.chromium.base.Log;
/**
* Contains all of the command line switches that are specific to Chromecast on
* on Android.
*/
public abstract class CastSwitches {
private static final String TAG = "cr_CastSwitches";
// Background color to use when chromium hasn't rendered anything yet. This will often be
// displayed briefly when loading a Cast app. Format is a #ARGB in hex. (Black: #FF000000,
// Green: #FF009000, and so on)
public static final String CAST_APP_BACKGROUND_COLOR = "cast-app-background-color";
public static int getSwitchValueColor(String switchName, int defaultValue) {
String colorString = CommandLine.getInstance().getSwitchValue(switchName);
try {
if (colorString != null) {
return Color.parseColor(colorString);
}
} catch (IllegalArgumentException e) {
Log.e(TAG, "Invalid value for %s (%s). Using default.",
CastSwitches.CAST_APP_BACKGROUND_COLOR, colorString);
}
return defaultValue;
}
// Prevent instantiation
private CastSwitches() {}
}
......@@ -17,6 +17,7 @@ import android.widget.FrameLayout;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chromecast.base.CastSwitches;
import org.chromium.chromecast.base.Controller;
import org.chromium.chromecast.base.Unit;
import org.chromium.components.content_view.ContentView;
......@@ -76,6 +77,8 @@ class CastWebContentsSurfaceHelper {
mHostActivity = hostActivity;
mShowInFragment = showInFragment;
mCastWebContentsLayout = castWebContentsLayout;
mCastWebContentsLayout.setBackgroundColor(CastSwitches.getSwitchValueColor(
CastSwitches.CAST_APP_BACKGROUND_COLOR, Color.BLACK));
mHandler = new Handler();
mAudioManager = CastAudioManager.getAudioManager(getActivity());
mAudioManager.requestAudioFocusWhen(
......@@ -178,9 +181,10 @@ class CastWebContentsSurfaceHelper {
}
};
mContentViewRenderView.onNativeLibraryLoaded(mWindow);
// Setting the background color to black avoids rendering a white splash screen
// Setting the background color avoids rendering a white splash screen
// before the players are loaded. See https://crbug/307113 for details.
mContentViewRenderView.setSurfaceViewBackgroundColor(Color.BLACK);
mContentViewRenderView.setSurfaceViewBackgroundColor(CastSwitches.getSwitchValueColor(
CastSwitches.CAST_APP_BACKGROUND_COLOR, Color.BLACK));
mCastWebContentsLayout.addView(mContentViewRenderView,
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
......
......@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chromecast/base/cast_features.h"
#include "chromecast/base/chromecast_switches.h"
#include "chromecast/base/metrics/cast_metrics_helper.h"
#include "chromecast/browser/cast_browser_process.h"
#include "chromecast/browser/cast_web_contents_manager.h"
......@@ -267,8 +268,10 @@ void CastWebViewDefault::RenderViewCreated(
content::RenderWidgetHostView* view =
render_view_host->GetWidget()->GetView();
if (view) {
view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT
: SK_ColorBLACK);
view->SetBackgroundColor(
transparent_ ? SK_ColorTRANSPARENT
: chromecast::GetSwitchValueColor(
switches::kCastAppBackgroundColor, SK_ColorBLACK));
}
}
......
......@@ -57,14 +57,6 @@
namespace chromecast {
namespace shell {
namespace {
// Default background color to set for WebViews. WebColor is in ARGB format
// though the comment of WebColor says it is in RGBA.
const blink::WebColor kColorBlack = 0xFF000000;
} // namespace
CastContentRendererClient::CastContentRendererClient()
: supported_profiles_(new media::SupportedCodecProfileLevelsMemo()),
app_media_capabilities_observer_binding_(this),
......@@ -146,7 +138,8 @@ void CastContentRendererClient::RenderViewCreated(
blink::WebView* webview = render_view->GetWebView();
if (webview) {
if (auto* web_frame_widget = render_view->GetWebFrameWidget())
web_frame_widget->SetBaseBackgroundColor(kColorBlack);
web_frame_widget->SetBaseBackgroundColor(chromecast::GetSwitchValueColor(
switches::kCastAppBackgroundColor, SK_ColorBLACK));
// Disable application cache as Chromecast doesn't support off-line
// application running.
......
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