| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/shell/renderer/shell_content_renderer_client.h" | 5 #include "content/shell/renderer/shell_content_renderer_client.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" |
| 9 #include "base/macros.h" | 12 #include "base/macros.h" |
| 10 #include "components/web_cache/renderer/web_cache_impl.h" | 13 #include "components/web_cache/renderer/web_cache_impl.h" |
| 11 #include "content/public/common/service_registry.h" | 14 #include "content/public/common/service_registry.h" |
| 12 #include "content/public/test/test_mojo_service.mojom.h" | 15 #include "content/public/test/test_mojo_service.mojom.h" |
| 13 #include "content/shell/common/shell_switches.h" | 16 #include "content/shell/common/shell_switches.h" |
| 14 #include "content/shell/renderer/shell_render_view_observer.h" | 17 #include "content/shell/renderer/shell_render_view_observer.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" | 18 #include "mojo/public/cpp/bindings/binding.h" |
| 16 #include "mojo/public/cpp/system/message_pipe.h" | 19 #include "mojo/public/cpp/system/message_pipe.h" |
| 17 #include "third_party/WebKit/public/web/WebTestingSupport.h" | 20 #include "third_party/WebKit/public/web/WebTestingSupport.h" |
| 18 #include "third_party/WebKit/public/web/WebView.h" | 21 #include "third_party/WebKit/public/web/WebView.h" |
| 19 #include "v8/include/v8.h" | 22 #include "v8/include/v8.h" |
| 20 | 23 |
| 21 #if defined(ENABLE_PLUGINS) | 24 #if defined(ENABLE_PLUGINS) |
| 22 #include "ppapi/shared_impl/ppapi_switches.h" | 25 #include "ppapi/shared_impl/ppapi_switches.h" |
| 23 #endif | 26 #endif |
| 24 | 27 |
| 25 namespace content { | 28 namespace content { |
| 26 | 29 |
| 27 namespace { | 30 namespace { |
| 28 | 31 |
| 29 // A test Mojo service which can be driven by browser tests for various reasons. | 32 // A test Mojo service which can be driven by browser tests for various reasons. |
| 30 class TestMojoServiceImpl : public mojom::TestMojoService { | 33 class TestMojoServiceImpl : public mojom::TestMojoService { |
| 31 public: | 34 public: |
| 32 TestMojoServiceImpl(mojom::TestMojoServiceRequest request) | 35 explicit TestMojoServiceImpl(mojom::TestMojoServiceRequest request) |
| 33 : binding_(this, std::move(request)) { | 36 : binding_(this, std::move(request)) { |
| 34 binding_.set_connection_error_handler( | 37 binding_.set_connection_error_handler( |
| 35 base::Bind(&TestMojoServiceImpl::OnConnectionError, | 38 base::Bind(&TestMojoServiceImpl::OnConnectionError, |
| 36 base::Unretained(this))); | 39 base::Unretained(this))); |
| 37 } | 40 } |
| 38 | 41 |
| 39 ~TestMojoServiceImpl() override {} | 42 ~TestMojoServiceImpl() override {} |
| 40 | 43 |
| 41 private: | 44 private: |
| 42 void OnConnectionError() { delete this; } | 45 void OnConnectionError() { delete this; } |
| 43 | 46 |
| 44 // mojom::TestMojoService: | 47 // mojom::TestMojoService: |
| 45 void DoSomething(const DoSomethingCallback& callback) override { | 48 void DoSomething(const DoSomethingCallback& callback) override { |
| 46 // Instead of responding normally, unbind the pipe, write some garbage, | 49 // Instead of responding normally, unbind the pipe, write some garbage, |
| 47 // and go away. | 50 // and go away. |
| 48 const std::string kBadMessage = "This is definitely not a valid response!"; | 51 const std::string kBadMessage = "This is definitely not a valid response!"; |
| 49 mojo::ScopedMessagePipeHandle pipe = binding_.Unbind().PassMessagePipe(); | 52 mojo::ScopedMessagePipeHandle pipe = binding_.Unbind().PassMessagePipe(); |
| 50 MojoResult rv = mojo::WriteMessageRaw( | 53 MojoResult rv = mojo::WriteMessageRaw( |
| 51 pipe.get(), kBadMessage.data(), kBadMessage.size(), nullptr, 0, | 54 pipe.get(), kBadMessage.data(), kBadMessage.size(), nullptr, 0, |
| 52 MOJO_WRITE_MESSAGE_FLAG_NONE); | 55 MOJO_WRITE_MESSAGE_FLAG_NONE); |
| 53 DCHECK_EQ(rv, MOJO_RESULT_OK); | 56 DCHECK_EQ(rv, MOJO_RESULT_OK); |
| 54 | 57 |
| 55 // Deletes this. | 58 // Deletes this. |
| 56 OnConnectionError(); | 59 OnConnectionError(); |
| 57 } | 60 } |
| 58 | 61 |
| 62 void DoTerminateProcess(const DoTerminateProcessCallback& callback) override { |
| 63 NOTREACHED(); |
| 64 } |
| 65 |
| 66 void CreateFolder(const CreateFolderCallback& callback) override { |
| 67 NOTREACHED(); |
| 68 } |
| 69 |
| 59 void GetRequestorName(const GetRequestorNameCallback& callback) override { | 70 void GetRequestorName(const GetRequestorNameCallback& callback) override { |
| 60 callback.Run("Not implemented."); | 71 callback.Run("Not implemented."); |
| 61 } | 72 } |
| 62 | 73 |
| 63 mojo::Binding<mojom::TestMojoService> binding_; | 74 mojo::Binding<mojom::TestMojoService> binding_; |
| 64 | 75 |
| 65 DISALLOW_COPY_AND_ASSIGN(TestMojoServiceImpl); | 76 DISALLOW_COPY_AND_ASSIGN(TestMojoServiceImpl); |
| 66 }; | 77 }; |
| 67 | 78 |
| 68 void CreateTestMojoService(mojom::TestMojoServiceRequest request) { | 79 void CreateTestMojoService(mojom::TestMojoServiceRequest request) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 123 } |
| 113 } | 124 } |
| 114 | 125 |
| 115 void ShellContentRendererClient::RegisterProcessMojoServices( | 126 void ShellContentRendererClient::RegisterProcessMojoServices( |
| 116 ServiceRegistry* service_registry) { | 127 ServiceRegistry* service_registry) { |
| 117 service_registry->AddService<mojom::TestMojoService>( | 128 service_registry->AddService<mojom::TestMojoService>( |
| 118 base::Bind(&CreateTestMojoService)); | 129 base::Bind(&CreateTestMojoService)); |
| 119 } | 130 } |
| 120 | 131 |
| 121 } // namespace content | 132 } // namespace content |
| OLD | NEW |