summaryrefslogtreecommitdiffstats
path: root/components/devtools_service/devtools_service_delegate.cc
blob: 5ba6adf6f4dc131eb30516fd7962500a352cb5da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/devtools_service/devtools_service_delegate.h"

#include <utility>

#include "base/logging.h"
#include "components/devtools_service/devtools_registry_impl.h"
#include "components/devtools_service/devtools_service.h"
#include "mojo/common/url_type_converters.h"
#include "mojo/shell/public/cpp/application_connection.h"
#include "mojo/shell/public/cpp/application_impl.h"
#include "url/gurl.h"

namespace devtools_service {

namespace {

bool IsShell(const GURL& requestor_url) {
  // TODO(yzshen): http://crbug.com/491656 "mojo://shell/" has to be used
  // instead of "mojo:shell" because "mojo" is not treated as a standard scheme.
  return requestor_url == GURL("mojo://shell/");
}

}  // namespace

DevToolsServiceDelegate::DevToolsServiceDelegate() {
}

DevToolsServiceDelegate::~DevToolsServiceDelegate() {
}

void DevToolsServiceDelegate::Initialize(mojo::ApplicationImpl* app) {
  service_.reset(new DevToolsService(app));
}

bool DevToolsServiceDelegate::ConfigureIncomingConnection(
    mojo::ApplicationConnection* connection) {
  connection->AddService<DevToolsRegistry>(this);

  // DevToolsCoordinator is a privileged interface and only allowed for the
  // shell.
  if (IsShell(GURL(connection->GetRemoteApplicationURL())))
    connection->AddService<DevToolsCoordinator>(this);
  return true;
}

void DevToolsServiceDelegate::Quit() {
  service_.reset();
}

void DevToolsServiceDelegate::Create(
    mojo::ApplicationConnection* connection,
    mojo::InterfaceRequest<DevToolsRegistry> request) {
  service_->registry()->BindToRegistryRequest(std::move(request));
}

void DevToolsServiceDelegate::Create(
    mojo::ApplicationConnection* connection,
    mojo::InterfaceRequest<DevToolsCoordinator> request) {
  service_->BindToCoordinatorRequest(std::move(request));
}

}  // namespace devtools_service