Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: content/shell/renderer/shell_content_renderer_client.cc

Issue 2054303002: Kill child processes on bad Mojo messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bad-message
Patch Set: . Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/bind.h"
7 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h"
8 #include "components/web_cache/renderer/web_cache_impl.h" 10 #include "components/web_cache/renderer/web_cache_impl.h"
11 #include "content/public/common/service_registry.h"
12 #include "content/public/test/test_mojo_service.mojom.h"
9 #include "content/shell/common/shell_switches.h" 13 #include "content/shell/common/shell_switches.h"
10 #include "content/shell/renderer/shell_render_view_observer.h" 14 #include "content/shell/renderer/shell_render_view_observer.h"
15 #include "mojo/public/cpp/bindings/binding.h"
16 #include "mojo/public/cpp/system/message_pipe.h"
11 #include "third_party/WebKit/public/web/WebTestingSupport.h" 17 #include "third_party/WebKit/public/web/WebTestingSupport.h"
12 #include "third_party/WebKit/public/web/WebView.h" 18 #include "third_party/WebKit/public/web/WebView.h"
13 #include "v8/include/v8.h" 19 #include "v8/include/v8.h"
14 20
15 #if defined(ENABLE_PLUGINS) 21 #if defined(ENABLE_PLUGINS)
16 #include "ppapi/shared_impl/ppapi_switches.h" 22 #include "ppapi/shared_impl/ppapi_switches.h"
17 #endif 23 #endif
18 24
19 namespace content { 25 namespace content {
20 26
27 namespace {
28
29 // A test Mojo service which can be driven by browser tests for various reasons.
30 class TestMojoServiceImpl : public mojom::TestMojoService {
31 public:
32 TestMojoServiceImpl(mojom::TestMojoServiceRequest request)
33 : binding_(this, std::move(request)) {
34 binding_.set_connection_error_handler(
35 base::Bind(&TestMojoServiceImpl::OnConnectionError,
36 base::Unretained(this)));
37 }
38
39 ~TestMojoServiceImpl() override {}
40
41 private:
42 void OnConnectionError() { delete this; }
43
44 // mojom::TestMojoService:
45 void DoSomething(const DoSomethingCallback& callback) override {
46 // Instead of responding normally, unbind the pipe, write some garbage,
47 // and go away.
48 const std::string kBadMessage = "This is definitely not a valid response!";
49 mojo::ScopedMessagePipeHandle pipe = binding_.Unbind().PassMessagePipe();
50 MojoResult rv = mojo::WriteMessageRaw(
51 pipe.get(), kBadMessage.data(), kBadMessage.size(), nullptr, 0,
52 MOJO_WRITE_MESSAGE_FLAG_NONE);
53 DCHECK_EQ(rv, MOJO_RESULT_OK);
54
55 // Deletes this.
56 OnConnectionError();
57 }
58
59 void GetRequestorName(const GetRequestorNameCallback& callback) override {
60 callback.Run("Not implemented.");
61 }
62
63 mojo::Binding<mojom::TestMojoService> binding_;
64
65 DISALLOW_COPY_AND_ASSIGN(TestMojoServiceImpl);
66 };
67
68 void CreateTestMojoService(mojom::TestMojoServiceRequest request) {
69 // Owns itself.
70 new TestMojoServiceImpl(std::move(request));
71 }
72
73 } // namespace
74
21 ShellContentRendererClient::ShellContentRendererClient() {} 75 ShellContentRendererClient::ShellContentRendererClient() {}
22 76
23 ShellContentRendererClient::~ShellContentRendererClient() { 77 ShellContentRendererClient::~ShellContentRendererClient() {
24 } 78 }
25 79
26 void ShellContentRendererClient::RenderThreadStarted() { 80 void ShellContentRendererClient::RenderThreadStarted() {
27 web_cache_impl_.reset(new web_cache::WebCacheImpl()); 81 web_cache_impl_.reset(new web_cache::WebCacheImpl());
28 } 82 }
29 83
30 void ShellContentRendererClient::RenderViewCreated(RenderView* render_view) { 84 void ShellContentRendererClient::RenderViewCreated(RenderView* render_view) {
(...skipping 20 matching lines...) Expand all
51 } 105 }
52 106
53 void ShellContentRendererClient::DidInitializeWorkerContextOnWorkerThread( 107 void ShellContentRendererClient::DidInitializeWorkerContextOnWorkerThread(
54 v8::Local<v8::Context> context) { 108 v8::Local<v8::Context> context) {
55 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 109 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
56 switches::kExposeInternalsForTesting)) { 110 switches::kExposeInternalsForTesting)) {
57 blink::WebTestingSupport::injectInternalsObject(context); 111 blink::WebTestingSupport::injectInternalsObject(context);
58 } 112 }
59 } 113 }
60 114
115 void ShellContentRendererClient::RegisterProcessMojoServices(
116 ServiceRegistry* service_registry) {
117 service_registry->AddService<mojom::TestMojoService>(
118 base::Bind(&CreateTestMojoService));
119 }
120
61 } // namespace content 121 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698