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

content / browser / devtools / protocol / inspector_handler.cc [blame]

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/devtools/protocol/inspector_handler.h"

#include <memory>

#include "content/browser/devtools/devtools_agent_host_impl.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"

namespace content {
namespace protocol {

InspectorHandler::InspectorHandler()
    : DevToolsDomainHandler(Inspector::Metainfo::domainName) {}

InspectorHandler::~InspectorHandler() = default;

// static
std::vector<InspectorHandler*> InspectorHandler::ForAgentHost(
    DevToolsAgentHostImpl* host) {
  return host->HandlersByName<InspectorHandler>(
      Inspector::Metainfo::domainName);
}

void InspectorHandler::Wire(UberDispatcher* dispatcher) {
  frontend_ = std::make_unique<Inspector::Frontend>(dispatcher->channel());
  Inspector::Dispatcher::wire(dispatcher, this);
}

void InspectorHandler::SetRenderer(int process_host_id,
                                   RenderFrameHostImpl* frame_host) {
  host_ = frame_host;
}

void InspectorHandler::TargetCrashed() {
  target_crashed_ = true;
  frontend_->TargetCrashed();
}

void InspectorHandler::TargetReloadedAfterCrash() {
  // Only send the event if targetCrashed was previously sent in this session.
  if (!target_crashed_)
    return;
  frontend_->TargetReloadedAfterCrash();
}

void InspectorHandler::TargetDetached(const std::string& reason) {
  frontend_->Detached(reason);
}

Response InspectorHandler::Enable() {
  if (host_ && !host_->IsRenderFrameLive())
    TargetCrashed();
  return Response::Success();
}

Response InspectorHandler::Disable() {
  return Response::Success();
}

}  // namespace protocol
}  // namespace content