| Index: content/shell/renderer/shell_content_renderer_client.cc
|
| diff --git a/content/shell/renderer/shell_content_renderer_client.cc b/content/shell/renderer/shell_content_renderer_client.cc
|
| index 33a04d3c42621a8e26cc404a30f25cbd8fae928e..98195872bec61e48068a23aabfcaf8b5dd5e0c01 100644
|
| --- a/content/shell/renderer/shell_content_renderer_client.cc
|
| +++ b/content/shell/renderer/shell_content_renderer_client.cc
|
| @@ -4,10 +4,16 @@
|
|
|
| #include "content/shell/renderer/shell_content_renderer_client.h"
|
|
|
| +#include "base/bind.h"
|
| #include "base/command_line.h"
|
| +#include "base/macros.h"
|
| #include "components/web_cache/renderer/web_cache_impl.h"
|
| +#include "content/public/common/service_registry.h"
|
| +#include "content/public/test/test_mojo_service.mojom.h"
|
| #include "content/shell/common/shell_switches.h"
|
| #include "content/shell/renderer/shell_render_view_observer.h"
|
| +#include "mojo/public/cpp/bindings/binding.h"
|
| +#include "mojo/public/cpp/system/message_pipe.h"
|
| #include "third_party/WebKit/public/web/WebTestingSupport.h"
|
| #include "third_party/WebKit/public/web/WebView.h"
|
| #include "v8/include/v8.h"
|
| @@ -18,6 +24,54 @@
|
|
|
| namespace content {
|
|
|
| +namespace {
|
| +
|
| +// A test Mojo service which can be driven by browser tests for various reasons.
|
| +class TestMojoServiceImpl : public mojom::TestMojoService {
|
| + public:
|
| + TestMojoServiceImpl(mojom::TestMojoServiceRequest request)
|
| + : binding_(this, std::move(request)) {
|
| + binding_.set_connection_error_handler(
|
| + base::Bind(&TestMojoServiceImpl::OnConnectionError,
|
| + base::Unretained(this)));
|
| + }
|
| +
|
| + ~TestMojoServiceImpl() override {}
|
| +
|
| + private:
|
| + void OnConnectionError() { delete this; }
|
| +
|
| + // mojom::TestMojoService:
|
| + void DoSomething(const DoSomethingCallback& callback) override {
|
| + // Instead of responding normally, unbind the pipe, write some garbage,
|
| + // and go away.
|
| + const std::string kBadMessage = "This is definitely not a valid response!";
|
| + mojo::ScopedMessagePipeHandle pipe = binding_.Unbind().PassMessagePipe();
|
| + MojoResult rv = mojo::WriteMessageRaw(
|
| + pipe.get(), kBadMessage.data(), kBadMessage.size(), nullptr, 0,
|
| + MOJO_WRITE_MESSAGE_FLAG_NONE);
|
| + DCHECK_EQ(rv, MOJO_RESULT_OK);
|
| +
|
| + // Deletes this.
|
| + OnConnectionError();
|
| + }
|
| +
|
| + void GetRequestorName(const GetRequestorNameCallback& callback) override {
|
| + callback.Run("Not implemented.");
|
| + }
|
| +
|
| + mojo::Binding<mojom::TestMojoService> binding_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestMojoServiceImpl);
|
| +};
|
| +
|
| +void CreateTestMojoService(mojom::TestMojoServiceRequest request) {
|
| + // Owns itself.
|
| + new TestMojoServiceImpl(std::move(request));
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| ShellContentRendererClient::ShellContentRendererClient() {}
|
|
|
| ShellContentRendererClient::~ShellContentRendererClient() {
|
| @@ -58,4 +112,10 @@ void ShellContentRendererClient::DidInitializeWorkerContextOnWorkerThread(
|
| }
|
| }
|
|
|
| +void ShellContentRendererClient::RegisterProcessMojoServices(
|
| + ServiceRegistry* service_registry) {
|
| + service_registry->AddService<mojom::TestMojoService>(
|
| + base::Bind(&CreateTestMojoService));
|
| +}
|
| +
|
| } // namespace content
|
|
|