summaryrefslogtreecommitdiffstats
path: root/chrome/browser/debugger/dev_tools_view.cc
blob: f0f623494ccc0f745f947e012d179b2bb831752c (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
// Copyright (c) 2009 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 "chrome/browser/debugger/dev_tools_view.h"

#include <string>

#include "chrome/browser/browser_list.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/web_contents.h"
#include "chrome/browser/views/tab_contents_container_view.h"
#include "chrome/common/property_bag.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"

DevToolsView::DevToolsView(int inspected_process_id, int inspected_view_id)
    : inspected_process_id_(inspected_process_id),
      inspected_view_id_(inspected_view_id),
      web_contents_(NULL) {
  web_container_ = new TabContentsContainerView();
  AddChildView(web_container_);
}

DevToolsView::~DevToolsView() {
}

void DevToolsView::SendDevToolsClientMessage(const IPC::Message& message) {
  if (!web_contents_) {
    NOTREACHED();
    return;
  }
  IPC::Message* copy =  new IPC::Message(message);
  copy->set_routing_id(web_contents_->render_view_host()->routing_id());
  web_contents_->render_view_host()->Send(copy);
}

std::string DevToolsView::GetClassName() const {
  return "DevToolsView";
}

gfx::Size DevToolsView::GetPreferredSize() {
  return gfx::Size(700, 400);
}

void DevToolsView::Layout() {
  web_container_->SetBounds(0, 0, width(), height());
}

void DevToolsView::ViewHierarchyChanged(bool is_add,
                                     views::View* parent,
                                     views::View* child) {
  if (is_add && child == this) {
    DCHECK(GetWidget());
    Init();
  }
}

void DevToolsView::Init() {
  // We can't create the WebContents until we've actually been put into a real
  // view hierarchy somewhere.
  Profile* profile = BrowserList::GetLastActive()->profile();

  TabContents* tc = TabContents::CreateWithType(TAB_CONTENTS_DOM_UI, profile,
                                                NULL);
  web_contents_ = tc->AsWebContents();
  web_contents_->SetupController(profile);
  web_contents_->set_delegate(this);
  web_container_->SetTabContents(web_contents_);
  web_contents_->render_view_host()->AllowDOMUIBindings();
  web_contents_->render_view_host()->SetInspectedView(inspected_process_id_,
                                                      inspected_view_id_);

  // chrome-ui://devtools/tools.html
  GURL contents(std::string(chrome::kChromeUIScheme) + "://" +
                chrome::kDevToolsHost + "/tools.html");

  // this will call CreateRenderView to create renderer process
  web_contents_->controller()->LoadURL(contents, GURL(),
                                       PageTransition::START_PAGE);
}

void DevToolsView::OnWindowClosing() {
  web_container_->SetTabContents(NULL);  // detach last (and only) tab
  web_contents_->CloseContents();  // destroy the tab and navigation controller
}

void DevToolsView::OpenURLFromTab(TabContents* source,
                               const GURL& url, const GURL& referrer,
                               WindowOpenDisposition disposition,
                               PageTransition::Type transition) {
  NOTREACHED();
}