1 // Copyright 2015 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.
5 #include "components/devtools_service/devtools_service_delegate.h"
7 #include "base/logging.h"
8 #include "components/devtools_service/devtools_registry_impl.h"
9 #include "components/devtools_service/devtools_service.h"
10 #include "mojo/application/public/cpp/application_connection.h"
11 #include "mojo/application/public/cpp/application_impl.h"
12 #include "mojo/common/url_type_converters.h"
15 namespace devtools_service
{
19 bool IsShell(const GURL
& requestor_url
) {
20 // TODO(yzshen): http://crbug.com/491656 "mojo://shell/" has to be used
21 // instead of "mojo:shell" because "mojo" is not treated as a standard scheme.
22 return requestor_url
== GURL("mojo://shell/");
27 DevToolsServiceDelegate::DevToolsServiceDelegate() {
30 DevToolsServiceDelegate::~DevToolsServiceDelegate() {
33 void DevToolsServiceDelegate::Initialize(mojo::ApplicationImpl
* app
) {
34 service_
.reset(new DevToolsService(app
));
37 bool DevToolsServiceDelegate::ConfigureIncomingConnection(
38 mojo::ApplicationConnection
* connection
) {
39 connection
->AddService
<DevToolsRegistry
>(this);
41 // DevToolsCoordinator is a privileged interface and only allowed for the
43 if (IsShell(GURL(connection
->GetRemoteApplicationURL())))
44 connection
->AddService
<DevToolsCoordinator
>(this);
48 void DevToolsServiceDelegate::Quit() {
52 void DevToolsServiceDelegate::Create(
53 mojo::ApplicationConnection
* connection
,
54 mojo::InterfaceRequest
<DevToolsRegistry
> request
) {
55 if (service_
->IsInitialized())
56 service_
->registry()->BindToRegistryRequest(request
.Pass());
59 void DevToolsServiceDelegate::Create(
60 mojo::ApplicationConnection
* connection
,
61 mojo::InterfaceRequest
<DevToolsCoordinator
> request
) {
62 service_
->BindToCoordinatorRequest(request
.Pass());
65 } // namespace devtools_service