Skip to content

Commit

Permalink
[chromecast] Pack bindings resources into cast_shell.pak
Browse files Browse the repository at this point in the history
On Linux build, pack binding scripts into cast_shell_pak so that
binding resources can be accssed on device.

Bug: internal b/138813438, b/132986916
Test: CastShellBrowserTests, CQ
Change-Id: I1a75310fc19a1d292f1e7076f941f25244d60495
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1734997
Reviewed-by: Luke Halliwell <halliwell@chromium.org>
Reviewed-by: Sean Topping <seantopping@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Kevin Marshall <kmarshall@chromium.org>
Commit-Queue: Jiawei Li <lijiawei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#685705}
  • Loading branch information
Jiawei Li authored and Commit Bot committed Aug 9, 2019
1 parent 0ebe2d5 commit a94a4fa
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 22 deletions.
2 changes: 2 additions & 0 deletions chromecast/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ if (is_fuchsia) {
repack("cast_shell_pak") {
sources = [
"$root_gen_dir/chromecast/app/shell_resources.pak",
"$root_gen_dir/chromecast/bindings/bindings_resources.pak",
"$root_gen_dir/content/app/resources/content_resources_100_percent.pak",
"$root_gen_dir/content/app/strings/content_strings_en-US.pak",
"$root_gen_dir/content/content_resources.pak",
Expand All @@ -515,6 +516,7 @@ repack("cast_shell_pak") {

deps = [
"//chromecast/app:resources",
"//chromecast/bindings:bindings_resources_grit",
"//content:resources",
"//content/app/resources",
"//content/app/strings",
Expand Down
14 changes: 13 additions & 1 deletion chromecast/bindings/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//tools/grit/grit_rule.gni")

if (is_fuchsia) {
import("//build/config/fuchsia/rules.gni")
}

source_set("named_message_port_connector_resources") {
data = [
"named_message_port_connector.js",
"resources/named_message_port_connector.js",
]
}

grit("bindings_resources") {
source = "bindings_resources.grd"
outputs = [
"grit/resources.h",
"bindings_resources.pak",
]
resource_ids = ""
}

source_set("bindings_manager") {
Expand Down Expand Up @@ -53,6 +64,7 @@ if (is_linux) {
]

deps = [
":bindings_resources",
"//base",
"//chromecast/browser:public",
"//mojo/public/cpp/system",
Expand Down
1 change: 1 addition & 0 deletions chromecast/bindings/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ include_rules = [
"+net/test",
"+third_party/blink/public/common/messaging",
"+third_party/blink/public/mojom/messaging",
"+ui/base/resource",
]
24 changes: 5 additions & 19 deletions chromecast/bindings/bindings_manager_cast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,33 @@
#include <utility>
#include <vector>

#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chromecast/bindings/grit/resources.h"
#include "mojo/public/cpp/bindings/connector.h"
#include "third_party/blink/public/common/messaging/string_message_codec.h"
#include "third_party/blink/public/common/messaging/transferable_message.h"
#include "third_party/blink/public/common/messaging/transferable_message_mojom_traits.h"
#include "third_party/blink/public/mojom/messaging/transferable_message.mojom.h"
#include "ui/base/resource/resource_bundle.h"

namespace chromecast {
namespace bindings {

namespace {

const char kNamedMessagePortConnectorJsPath[] =
FILE_PATH_LITERAL("chromecast/bindings/named_message_port_connector.js");
const char kNamedMessagePortConnectorBindingsId[] =
"NAMED_MESSAGE_PORT_CONNECTOR";
const char kControlPortConnectMessage[] = "cast.master.connect";

} // namespace

BindingsManagerCast::BindingsManagerCast() : cast_web_contents_(nullptr) {
// Add the script providing the connection API into the Page.
base::FilePath named_message_port_connector_path;
bool path_service_result = base::PathService::Get(
base::DIR_SOURCE_ROOT, &named_message_port_connector_path);
DCHECK(path_service_result);

named_message_port_connector_path =
named_message_port_connector_path.AppendASCII(
kNamedMessagePortConnectorJsPath);

std::string port_connector_js;
CHECK(base::ReadFileToString(named_message_port_connector_path,
&port_connector_js));

// NamedMessagePortConnector binding will be injected into page first.
AddBinding(kNamedMessagePortConnectorBindingsId, port_connector_js);
AddBinding(kNamedMessagePortConnectorBindingsId,
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_PORT_CONNECTOR_JS));
}

BindingsManagerCast::~BindingsManagerCast() = default;
Expand Down
15 changes: 15 additions & 0 deletions chromecast/bindings/bindings_resources.grd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false">
<outputs>
<output filename="grit/resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="bindings_resources.pak" type="data_package" />
</outputs>
<translations />
<release seq="1">
<includes>
<include name="IDR_PORT_CONNECTOR_JS" file="resources\named_message_port_connector.js" type="BINDATA" />
</includes>
</release>
</grit>
4 changes: 2 additions & 2 deletions fuchsia/runners/cast/named_message_port_connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

namespace {

const char kBindingsJsPath[] =
FILE_PATH_LITERAL("chromecast/bindings/named_message_port_connector.js");
const char kBindingsJsPath[] = FILE_PATH_LITERAL(
"chromecast/bindings/resources/named_message_port_connector.js");
const char kControlPortConnectMessage[] = "cast.master.connect";

} // namespace
Expand Down

0 comments on commit a94a4fa

Please sign in to comment.