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