OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/mojo/browser_shell_connection.h" | 5 #include "content/browser/mojo/browser_shell_connection.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "content/browser/mojo/constants.h" | 8 #include "content/browser/mojo/constants.h" |
8 #include "services/shell/public/interfaces/connector.mojom.h" | 9 #include "services/shell/public/interfaces/connector.mojom.h" |
9 | 10 |
10 namespace content { | 11 namespace content { |
11 | 12 |
| 13 BrowserShellConnection::BrowserShellConnection() {} |
| 14 |
12 BrowserShellConnection::BrowserShellConnection( | 15 BrowserShellConnection::BrowserShellConnection( |
13 shell::mojom::ShellClientRequest request) | 16 shell::mojom::ShellClientRequest request) |
14 : shell_connection_(new shell::ShellConnection(this, std::move(request))) {} | 17 : shell_connection_(new shell::ShellConnection(this, std::move(request))) {} |
15 | 18 |
16 BrowserShellConnection::~BrowserShellConnection() {} | 19 BrowserShellConnection::~BrowserShellConnection() {} |
17 | 20 |
18 shell::Connector* BrowserShellConnection::GetConnector() { | 21 shell::Connector* BrowserShellConnection::GetConnector() { |
| 22 DCHECK(shell_connection_); |
19 return shell_connection_->connector(); | 23 return shell_connection_->connector(); |
20 } | 24 } |
21 | 25 |
22 void BrowserShellConnection::AddEmbeddedApplication( | 26 void BrowserShellConnection::AddEmbeddedApplication( |
23 const base::StringPiece& name, | 27 const base::StringPiece& name, |
24 const EmbeddedApplicationRunner::FactoryCallback& callback, | 28 const EmbeddedApplicationRunner::FactoryCallback& callback, |
25 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 29 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
26 std::unique_ptr<EmbeddedApplicationRunner> app( | 30 std::unique_ptr<EmbeddedApplicationRunner> app( |
27 new EmbeddedApplicationRunner(callback, task_runner)); | 31 new EmbeddedApplicationRunner(callback, task_runner)); |
| 32 AddShellClientRequestHandler( |
| 33 name, base::Bind(&EmbeddedApplicationRunner::BindShellClientRequest, |
| 34 base::Unretained(app.get()))); |
28 auto result = embedded_apps_.insert( | 35 auto result = embedded_apps_.insert( |
29 std::make_pair(name.as_string(), std::move(app))); | 36 std::make_pair(name.as_string(), std::move(app))); |
30 DCHECK(result.second); | 37 DCHECK(result.second); |
31 } | 38 } |
32 | 39 |
| 40 void BrowserShellConnection::AddShellClientRequestHandler( |
| 41 const base::StringPiece& name, |
| 42 const ShellClientRequestHandler& handler) { |
| 43 auto result = request_handlers_.insert( |
| 44 std::make_pair(name.as_string(), handler)); |
| 45 DCHECK(result.second); |
| 46 } |
| 47 |
33 bool BrowserShellConnection::AcceptConnection(shell::Connection* connection) { | 48 bool BrowserShellConnection::AcceptConnection(shell::Connection* connection) { |
34 std::string remote_app = connection->GetRemoteIdentity().name(); | 49 std::string remote_app = connection->GetRemoteIdentity().name(); |
35 if (remote_app == "mojo:shell") { | 50 if (remote_app == "mojo:shell") { |
36 // Only expose the SCF interface to the shell. | 51 // Only expose the SCF interface to the shell. |
37 connection->AddInterface<shell::mojom::ShellClientFactory>(this); | 52 connection->AddInterface<shell::mojom::ShellClientFactory>(this); |
38 return true; | 53 return true; |
39 } | 54 } |
40 | 55 |
41 // Allow connections from the root browser application. | 56 // Allow connections from the root browser application. |
42 if (remote_app == kBrowserMojoApplicationName && | 57 if (remote_app == kBrowserMojoApplicationName && |
43 connection->GetRemoteIdentity().user_id() == shell::mojom::kRootUserID) | 58 connection->GetRemoteIdentity().user_id() == shell::mojom::kRootUserID) |
44 return true; | 59 return true; |
45 | 60 |
46 // Reject all other connections to this application. | 61 // Reject all other connections to this application. |
47 return false; | 62 return false; |
48 } | 63 } |
49 | 64 |
50 void BrowserShellConnection::Create( | 65 void BrowserShellConnection::Create( |
51 shell::Connection* connection, | 66 shell::Connection* connection, |
52 shell::mojom::ShellClientFactoryRequest request) { | 67 shell::mojom::ShellClientFactoryRequest request) { |
53 factory_bindings_.AddBinding(this, std::move(request)); | 68 factory_bindings_.AddBinding(this, std::move(request)); |
54 } | 69 } |
55 | 70 |
56 void BrowserShellConnection::CreateShellClient( | 71 void BrowserShellConnection::CreateShellClient( |
57 shell::mojom::ShellClientRequest request, | 72 shell::mojom::ShellClientRequest request, |
58 const mojo::String& name) { | 73 const mojo::String& name) { |
59 auto it = embedded_apps_.find(name); | 74 auto it = request_handlers_.find(name); |
60 if (it != embedded_apps_.end()) | 75 if (it != request_handlers_.end()) |
61 it->second->BindShellClientRequest(std::move(request)); | 76 it->second.Run(std::move(request)); |
62 } | 77 } |
63 | 78 |
64 } // namespace content | 79 } // namespace content |
OLD | NEW |