summaryrefslogtreecommitdiffstats
path: root/content/browser/devtools/devtools_frontend_host.cc
blob: fe7e82d10d02647b860cf2ec9b79663230705ed9 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (c) 2012 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 "content/browser/devtools/devtools_frontend_host.h"

#include "content/browser/devtools/devtools_manager_impl.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/devtools_messages.h"
#include "content/public/browser/devtools_client_host.h"
#include "content/public/browser/devtools_frontend_host_delegate.h"

namespace content {

// static
DevToolsClientHost* DevToolsClientHost::CreateDevToolsFrontendHost(
    WebContents* client_web_contents,
    DevToolsFrontendHostDelegate* delegate) {
  return new DevToolsFrontendHost(
      static_cast<WebContentsImpl*>(client_web_contents), delegate);
}

// static
void DevToolsClientHost::SetupDevToolsFrontendClient(
    RenderViewHost* frontend_rvh) {
  frontend_rvh->Send(new DevToolsMsg_SetupDevToolsClient(
      frontend_rvh->GetRoutingID()));
}

DevToolsFrontendHost::DevToolsFrontendHost(
    WebContentsImpl* web_contents,
    DevToolsFrontendHostDelegate* delegate)
    : RenderViewHostObserver(web_contents->GetRenderViewHost()),
      web_contents_(web_contents),
      delegate_(delegate) {
}

DevToolsFrontendHost::~DevToolsFrontendHost() {
  DevToolsManager::GetInstance()->ClientHostClosing(this);
}

void DevToolsFrontendHost::DispatchOnInspectorFrontend(
    const std::string& message) {
  RenderViewHostImpl* target_host =
      static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost());
  target_host->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend(
      target_host->GetRoutingID(),
      message));
}

void DevToolsFrontendHost::InspectedContentsClosing() {
  delegate_->InspectedContentsClosing();
}

void DevToolsFrontendHost::FrameNavigating(const std::string& url) {
  delegate_->FrameNavigating(url);
}

void DevToolsFrontendHost::ContentsReplaced(WebContents* new_contents) {
  delegate_->ContentsReplaced(new_contents);
}

void DevToolsFrontendHost::ReplacedWithAnotherClient() {
}

bool DevToolsFrontendHost::OnMessageReceived(
    const IPC::Message& message) {
  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP(DevToolsFrontendHost, message)
    IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend,
                        OnDispatchOnInspectorBackend)
    IPC_MESSAGE_HANDLER(DevToolsHostMsg_ActivateWindow, OnActivateWindow)
    IPC_MESSAGE_HANDLER(DevToolsHostMsg_CloseWindow, OnCloseWindow)
    IPC_MESSAGE_HANDLER(DevToolsHostMsg_MoveWindow, OnMoveWindow)
    IPC_MESSAGE_HANDLER(DevToolsHostMsg_RequestSetDockSide,
                        OnRequestSetDockSide)
    IPC_MESSAGE_HANDLER(DevToolsHostMsg_OpenInNewTab, OnOpenInNewTab)
    IPC_MESSAGE_HANDLER(DevToolsHostMsg_Save, OnSave)
    IPC_MESSAGE_HANDLER(DevToolsHostMsg_Append, OnAppend)
    IPC_MESSAGE_UNHANDLED(handled = false)
  IPC_END_MESSAGE_MAP()
  return handled;
}

void DevToolsFrontendHost::OnDispatchOnInspectorBackend(
    const std::string& message) {
  DevToolsManagerImpl::GetInstance()->DispatchOnInspectorBackend(this, message);
//  delegate_->DispatchOnInspectorBackend(message);
}

void DevToolsFrontendHost::OnActivateWindow() {
  delegate_->ActivateWindow();
}

void DevToolsFrontendHost::OnCloseWindow() {
  delegate_->CloseWindow();
}

void DevToolsFrontendHost::OnMoveWindow(int x, int y) {
  delegate_->MoveWindow(x, y);
}

void DevToolsFrontendHost::OnOpenInNewTab(const std::string& url) {
  delegate_->OpenInNewTab(url);
}

void DevToolsFrontendHost::OnSave(
    const std::string& url,
    const std::string& content,
    bool save_as) {
  delegate_->SaveToFile(url, content, save_as);
}

void DevToolsFrontendHost::OnAppend(
    const std::string& url,
    const std::string& content) {
  delegate_->AppendToFile(url, content);
}

void DevToolsFrontendHost::OnRequestSetDockSide(const std::string& side) {
  delegate_->SetDockSide(side);
}

}  // namespace content