Commit f07f828e authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

RemoteRWHVMac: Instantiate content::NSViewBridgeFactoryImpl in app shim

Add to chrome::mojom::AppShim a CreateContentNSViewBridgeFactory
method. This will instantiate a content::NSViewBridgeFactoryImpl.

The caller of this method (AppShimHost, in the browser), creates
a content::NSViewBridgeFactoryHost to manage this interface. This
may be used (e.g, by content::RenderWidgetHostViewMac::
MigrateNSViewBridge), to create NSViews in an app shim process.

Add content/browser as a dependency of app_shim.

R=dominickn
TBR=avi

Bug: 821651
Change-Id: Ice2b46f2d75a9725f5e8e8ad7d2c05e3d70b18eb
Reviewed-on: https://chromium-review.googlesource.com/1240154
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594987}
parent 75ac0e69
......@@ -18,6 +18,7 @@ source_set("app_shim") {
"//chrome:strings",
"//chrome/common",
"//chrome/common:mojo_bindings",
"//content/public/browser",
"//ipc",
"//mojo/core/embedder",
"//ui/accelerated_widget_mac",
......
include_rules = [
"+chrome/grit/generated_resources.h",
"+chrome/installer/launcher_support",
"+content/public/browser",
"+mojo/core/embedder",
]
......@@ -37,6 +37,8 @@
#include "chrome/common/mac/app_shim.mojom.h"
#include "chrome/common/mac/app_shim_param_traits.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/ns_view_bridge_factory_impl.h"
#include "content/public/common/ns_view_bridge_factory.mojom.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/core/embedder/scoped_ipc_support.h"
#include "mojo/public/cpp/bindings/binding.h"
......@@ -132,6 +134,8 @@ class AppShimController : public chrome::mojom::AppShim {
void LaunchAppDone(apps::AppShimLaunchResult result) override;
void CreateViewsBridgeFactory(
views_bridge_mac::mojom::BridgeFactoryRequest request) override;
void CreateContentNSViewBridgeFactory(
content::mojom::NSViewBridgeFactoryAssociatedRequest request) override;
void Hide() override;
void UnhideWithoutActivation() override;
void SetUserAttention(apps::AppShimAttentionType attention_type) override;
......@@ -314,6 +318,11 @@ void AppShimController::CreateViewsBridgeFactory(
views_bridge_mac::BridgeFactoryImpl::Get()->BindRequest(std::move(request));
}
void AppShimController::CreateContentNSViewBridgeFactory(
content::mojom::NSViewBridgeFactoryAssociatedRequest request) {
content::NSViewBridgeFactoryImpl::Get()->BindRequest(std::move(request));
}
void AppShimController::Hide() {
[NSApp hide:nil];
}
......
......@@ -11,7 +11,10 @@
#include "base/logging.h"
#include "chrome/browser/apps/app_shim/app_shim_handler_mac.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/ns_view_bridge_factory_host.h"
#include "content/public/common/ns_view_bridge_factory.mojom.h"
#include "ui/base/ui_base_features.h"
#include "ui/views/cocoa/bridge_factory_host.h"
#include "ui/views_bridge_mac/mojo/bridge_factory.mojom.h"
AppShimHost::AppShimHost()
......@@ -65,14 +68,25 @@ void AppShimHost::LaunchApp(chrome::mojom::AppShimPtr app_shim_ptr,
return;
app_shim_ = std::move(app_shim_ptr);
// Create the interface that will be used by views::NativeWidgetMac to create
// NSWindows hosted in the app shim process.
if (features::HostWindowsInAppShimProcess()) {
// Create the interface that will be used by views::NativeWidgetMac to
// create NSWindows hosted in the app shim process.
views_bridge_mac::mojom::BridgeFactoryRequest views_bridge_factory_request;
views_bridge_factory_host_ = std::make_unique<views::BridgeFactoryHost>(
&views_bridge_factory_request);
app_shim_->CreateViewsBridgeFactory(
std::move(views_bridge_factory_request));
// Create the interface that will be used content::RenderWidgetHostView to
// create NSViews hosted in the app shim process.
content::mojom::NSViewBridgeFactoryAssociatedRequest
content_bridge_factory_request;
content_bridge_factory_ =
std::make_unique<content::NSViewBridgeFactoryHost>(
&content_bridge_factory_request,
views_bridge_factory_host_->GetHostId());
app_shim_->CreateContentNSViewBridgeFactory(
std::move(content_bridge_factory_request));
}
profile_path_ = profile_dir;
app_id_ = app_id;
......
......@@ -16,7 +16,14 @@
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/platform/platform_channel_endpoint.h"
#include "mojo/public/cpp/system/isolated_connection.h"
#include "ui/views/cocoa/bridge_factory_host.h"
namespace content {
class NSViewBridgeFactoryHost;
} // namespace content
namespace views {
class BridgeFactoryHost;
} // namespace views
// This is the counterpart to AppShimController in
// chrome/app/chrome_main_app_mode_mac.mm. The AppShimHost owns itself, and is
......@@ -64,6 +71,7 @@ class AppShimHost : public chrome::mojom::AppShimHost,
mojo::IsolatedConnection mojo_connection_;
chrome::mojom::AppShimPtr app_shim_;
std::unique_ptr<views::BridgeFactoryHost> views_bridge_factory_host_;
std::unique_ptr<content::NSViewBridgeFactoryHost> content_bridge_factory_;
mojo::Binding<chrome::mojom::AppShimHost> host_binding_;
std::string app_id_;
base::FilePath profile_path_;
......
......@@ -10,6 +10,8 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h"
#include "base/test/scoped_task_environment.h"
#include "base/test/test_simple_task_runner.h"
#include "chrome/common/mac/app_shim_param_traits.h"
#include "ipc/ipc_message.h"
......@@ -46,6 +48,8 @@ class TestingAppShim : public chrome::mojom::AppShim {
}
void CreateViewsBridgeFactory(
views_bridge_mac::mojom::BridgeFactoryRequest request) override {}
void CreateContentNSViewBridgeFactory(
content::mojom::NSViewBridgeFactoryAssociatedRequest request) override {}
void Hide() override {}
void UnhideWithoutActivation() override {}
void SetUserAttention(apps::AppShimAttentionType attention_type) override {}
......@@ -83,9 +87,7 @@ const char kTestProfileDir[] = "Profile 1";
class AppShimHostTest : public testing::Test,
public apps::AppShimHandler {
public:
AppShimHostTest()
: task_runner_(new base::TestSimpleTaskRunner),
task_runner_handle_(task_runner_) {}
AppShimHostTest() { task_runner_ = base::ThreadTaskRunnerHandle::Get(); }
~AppShimHostTest() override {
if (host_)
......@@ -93,7 +95,8 @@ class AppShimHostTest : public testing::Test,
DCHECK(!host_);
}
scoped_refptr<base::TestSimpleTaskRunner> task_runner() {
void RunUntilIdle() { scoped_task_environment_.RunUntilIdle(); }
scoped_refptr<base::SingleThreadTaskRunner> task_runner() {
return task_runner_;
}
TestingAppShimHost* host() { return host_.get(); }
......@@ -106,7 +109,7 @@ class AppShimHostTest : public testing::Test,
}
apps::AppShimLaunchResult GetLaunchResult() {
task_runner_->RunUntilIdle();
RunUntilIdle();
return shim_->GetLaunchResult();
}
......@@ -149,8 +152,8 @@ class AppShimHostTest : public testing::Test,
host_ = host->GetWeakPtr();
}
scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
base::ThreadTaskRunnerHandle task_runner_handle_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<TestingAppShim> shim_;
......@@ -182,15 +185,15 @@ TEST_F(AppShimHostTest, TestLaunchAppWithHandler) {
GetMojoHost()->FocusApp(apps::APP_SHIM_FOCUS_NORMAL,
std::vector<base::FilePath>());
task_runner()->RunUntilIdle();
RunUntilIdle();
EXPECT_EQ(1, focus_count_);
GetMojoHost()->QuitApp();
task_runner()->RunUntilIdle();
RunUntilIdle();
EXPECT_EQ(1, quit_count_);
SimulateDisconnect();
task_runner()->RunUntilIdle();
RunUntilIdle();
EXPECT_EQ(1, close_count_);
EXPECT_EQ(nullptr, host());
apps::AppShimHandler::RemoveHandler(kTestAppId);
......
......@@ -51,6 +51,8 @@ class TestShimClient : public chrome::mojom::AppShim {
void LaunchAppDone(apps::AppShimLaunchResult result) override {}
void CreateViewsBridgeFactory(
views_bridge_mac::mojom::BridgeFactoryRequest request) override {}
void CreateContentNSViewBridgeFactory(
content::mojom::NSViewBridgeFactoryAssociatedRequest request) override {}
void Hide() override {}
void UnhideWithoutActivation() override {}
void SetUserAttention(apps::AppShimAttentionType attention_type) override {}
......
......@@ -4,6 +4,7 @@
module chrome.mojom;
import "content/public/common/ns_view_bridge_factory.mojom";
import "mojo/public/mojom/base/file_path.mojom";
import "ui/views_bridge_mac/mojo/bridge_factory.mojom";
......@@ -26,6 +27,13 @@ interface AppShim {
CreateViewsBridgeFactory(
views_bridge_mac.mojom.BridgeFactory& views_bridge_factory);
// Create the interface through which a content structure
// (RenderWidgetHostView or WebContentsView) may create an NSView that exists
// in the app shim process.
CreateContentNSViewBridgeFactory(
associated content.mojom.NSViewBridgeFactory&
content_ns_views_bridge_factory);
// Signals that a previous LaunchApp message has been processed, and lets the
// app shim process know whether it was registered successfully.
LaunchAppDone(AppShimLaunchResult launch_result);
......
......@@ -4,10 +4,18 @@
#include "ui/views/cocoa/bridge_factory_host.h"
#include "mojo/public/cpp/bindings/interface_request.h"
namespace views {
namespace {
// Start the ids at something far from zero to help in debugging.
uint64_t g_next_bridge_factory_host_id_ = 0x1000;
} // namespace
BridgeFactoryHost::BridgeFactoryHost(
views_bridge_mac::mojom::BridgeFactoryRequest* request) {
views_bridge_mac::mojom::BridgeFactoryRequest* request)
: host_id_(g_next_bridge_factory_host_id_++) {
*request = mojo::MakeRequest(&bridge_factory_ptr_);
}
......
......@@ -24,11 +24,18 @@ class VIEWS_EXPORT BridgeFactoryHost {
BridgeFactoryHost(views_bridge_mac::mojom::BridgeFactoryRequest* request);
~BridgeFactoryHost();
// Return an id for the host process. This can be used to look up other
// factories to create NSViews (e.g in content).
uint64_t GetHostId() const { return host_id_; }
views_bridge_mac::mojom::BridgeFactory* GetFactory();
void AddObserver(Observer* observer);
void RemoveObserver(const Observer* observer);
private:
const uint64_t host_id_;
views_bridge_mac::mojom::BridgeFactoryPtr bridge_factory_ptr_;
base::ObserverList<Observer> observers_;
};
......
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