summaryrefslogtreecommitdiffstats
path: root/chrome/browser/debugger
diff options
context:
space:
mode:
authoryurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 16:17:21 +0000
committeryurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 16:17:21 +0000
commit68b4d89935563f7009074cef5b7be8e0d8148bd4 (patch)
treef987689e2cc300230538482e7fa7b61b8dabd4bf /chrome/browser/debugger
parentdaeb1b6db0ddff328b2ed4bc839a9f15936c3496 (diff)
downloadchromium_src-68b4d89935563f7009074cef5b7be8e0d8148bd4.zip
chromium_src-68b4d89935563f7009074cef5b7be8e0d8148bd4.tar.gz
chromium_src-68b4d89935563f7009074cef5b7be8e0d8148bd4.tar.bz2
Create communication channel between developer tools UI implemented in JS and residing in a process different from inspected page renderer process. There is no direct IPC channel between the two processes so all messages are routed through browser process.
On the side of inspected page there is ToolsAgent existing in all renderers so that we can start inspecting the page at any moment by talking to this object. On the side of developer tools renderer there is ToolsClient which is created only for RenderView that host developer tools UI. This change is a slightly modified version of http://codereview.chromium.org/20221/show Review URL: http://codereview.chromium.org/20430 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9944 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/debugger')
-rw-r--r--chrome/browser/debugger/debugger.scons12
-rw-r--r--chrome/browser/debugger/debugger.vcproj24
-rw-r--r--chrome/browser/debugger/tools_contents.cc43
-rw-r--r--chrome/browser/debugger/tools_contents.h39
-rw-r--r--chrome/browser/debugger/tools_view.cc92
-rw-r--r--chrome/browser/debugger/tools_view.h75
-rw-r--r--chrome/browser/debugger/tools_window.cc54
-rw-r--r--chrome/browser/debugger/tools_window.h67
8 files changed, 406 insertions, 0 deletions
diff --git a/chrome/browser/debugger/debugger.scons b/chrome/browser/debugger/debugger.scons
index 30d1a65..f34a8f1 100644
--- a/chrome/browser/debugger/debugger.scons
+++ b/chrome/browser/debugger/debugger.scons
@@ -54,6 +54,12 @@ input_files = ChromeFileList([
'debugger_window.h',
'debugger_wrapper.cc',
'debugger_wrapper.h',
+ 'tools_contents.cc',
+ 'tools_contents.h',
+ 'tools_view.cc',
+ 'tools_view.h',
+ 'tools_window.cc',
+ 'tools_window.h',
])
if env.Bit('linux'):
@@ -62,6 +68,9 @@ if env.Bit('linux'):
'debugger_contents.cc',
'debugger_view.cc',
'debugger_window.cc',
+ 'tools_contents.cc',
+ 'tools_view.cc',
+ 'tools_window.cc',
)
if env.Bit('mac'):
@@ -72,6 +81,9 @@ if env.Bit('mac'):
'debugger_node.cc',
'debugger_view.cc',
'debugger_window.cc',
+ 'tools_contents.cc',
+ 'tools_view.cc',
+ 'tools_window.cc',
)
if not env.Bit('mac'):
diff --git a/chrome/browser/debugger/debugger.vcproj b/chrome/browser/debugger/debugger.vcproj
index d72b86a..e02dd18 100644
--- a/chrome/browser/debugger/debugger.vcproj
+++ b/chrome/browser/debugger/debugger.vcproj
@@ -213,6 +213,30 @@
RelativePath=".\debugger_wrapper.h"
>
</File>
+ <File
+ RelativePath=".\tools_contents.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\tools_contents.h"
+ >
+ </File>
+ <File
+ RelativePath=".\tools_view.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\tools_view.h"
+ >
+ </File>
+ <File
+ RelativePath=".\tools_window.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\tools_window.h"
+ >
+ </File>
</Files>
<Globals>
</Globals>
diff --git a/chrome/browser/debugger/tools_contents.cc b/chrome/browser/debugger/tools_contents.cc
new file mode 100644
index 0000000..b76913c
--- /dev/null
+++ b/chrome/browser/debugger/tools_contents.cc
@@ -0,0 +1,43 @@
+// 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/tools_contents.h"
+
+#include "base/singleton.h"
+
+ToolsContents::ToolsContents(Profile* profile, SiteInstance* instance)
+ : WebContents(profile,
+ instance,
+ NULL,
+ MSG_ROUTING_NONE,
+ NULL) {
+ set_type(TAB_CONTENTS_TOOLS);
+}
+
+void ToolsContents::RendererCreated(RenderViewHost* render_view_host) {
+ std::pair<int, int>* render_view_info =
+ ToolsContents::GetInspectedViewInfoAccessor()->GetProperty(
+ property_bag());
+ DCHECK(render_view_info);
+ if (!render_view_info)
+ return;
+
+ render_view_host->SetUpToolsClient(render_view_info->first,
+ render_view_info->second);
+ ToolsContents::GetInspectedViewInfoAccessor()->DeleteProperty(property_bag());
+}
+
+// static
+bool ToolsContents::IsToolsUrl(const GURL& url) {
+ // TODO(yurys): implement
+ return (url.SchemeIs("chrome-ui") && url.host() == "inspector" &&
+ url.path() == "/debugger-oop.html");
+}
+
+// static
+PropertyAccessor<std::pair<int, int> >*
+ ToolsContents::GetInspectedViewInfoAccessor() {
+ return Singleton<PropertyAccessor<std::pair<int, int> > >().get();
+}
+
diff --git a/chrome/browser/debugger/tools_contents.h b/chrome/browser/debugger/tools_contents.h
new file mode 100644
index 0000000..9a9743d
--- /dev/null
+++ b/chrome/browser/debugger/tools_contents.h
@@ -0,0 +1,39 @@
+// 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.
+
+#ifndef CHROME_BROWSER_DEBUGGER_TOOLS_CONTENTS_H_
+#define CHROME_BROWSER_DEBUGGER_TOOLS_CONTENTS_H_
+
+#include <utility>
+
+#include "chrome/browser/tab_contents/web_contents.h"
+#include "chrome/common/property_bag.h"
+
+// TODO(yurys): it may be made into DOMUI if the latter supports RendererCreated
+// notification.
+class ToolsContents : public WebContents {
+ public:
+ ToolsContents(Profile* profile, SiteInstance* instance);
+
+ static bool IsToolsUrl(const GURL& url);
+
+ // (render process id, render view id)
+ static PropertyAccessor<std::pair<int, int> >* GetInspectedViewInfoAccessor();
+
+ protected:
+ // WebContents overrides:
+ // We override updating history with a no-op so these pages
+ // are not saved to history.
+ virtual void UpdateHistoryForNavigation(const GURL& url,
+ const ViewHostMsg_FrameNavigate_Params& params) { }
+
+ // Will notify just created renderer that it's going to host developer
+ // tools UI.
+ virtual void RendererCreated(RenderViewHost* render_view_host);
+
+ DISALLOW_COPY_AND_ASSIGN(ToolsContents);
+};
+
+#endif // CHROME_BROWSER_DEBUGGER_TOOLS_CONTENTS_H_
+
diff --git a/chrome/browser/debugger/tools_view.cc b/chrome/browser/debugger/tools_view.cc
new file mode 100644
index 0000000..3281029
--- /dev/null
+++ b/chrome/browser/debugger/tools_view.cc
@@ -0,0 +1,92 @@
+// 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/tools_view.h"
+
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/debugger/tools_contents.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"
+
+ToolsView::ToolsView(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_);
+}
+
+ToolsView::~ToolsView() {
+}
+
+void ToolsView::SendToolsClientMessage(int tools_message_type,
+ const std::wstring& body) {
+ if (!web_contents_) {
+ NOTREACHED();
+ return;
+ }
+ int routing_id = web_contents_->render_view_host()->routing_id();
+ web_contents_->render_view_host()->Send(
+ new ViewMsg_ToolsClientMsg(routing_id, tools_message_type, body));
+}
+
+std::string ToolsView::GetClassName() const {
+ return "ToolsView";
+}
+
+gfx::Size ToolsView::GetPreferredSize() {
+ return gfx::Size(700, 400);
+}
+
+void ToolsView::Layout() {
+ web_container_->SetBounds(0, 0, width(), height());
+}
+
+void ToolsView::ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) {
+ if (is_add && child == this) {
+ DCHECK(GetWidget());
+ Init();
+ }
+}
+
+void ToolsView::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_TOOLS, 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();
+
+ ToolsContents::GetInspectedViewInfoAccessor()->SetProperty(
+ web_contents_->property_bag(),
+ std::pair<int, int>(inspected_process_id_, inspected_view_id_));
+
+ GURL contents("chrome-ui://inspector/debugger-oop.html");
+ // this will call CreateRenderView to create renderer process
+ web_contents_->controller()->LoadURL(contents, GURL(),
+ PageTransition::START_PAGE);
+}
+
+void ToolsView::OnWindowClosing() {
+ web_container_->SetTabContents(NULL); // detach last (and only) tab
+ web_contents_->CloseContents(); // destroy the tab and navigation controller
+}
+
+void ToolsView::OpenURLFromTab(TabContents* source,
+ const GURL& url, const GURL& referrer,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition) {
+ NOTREACHED();
+}
+
diff --git a/chrome/browser/debugger/tools_view.h b/chrome/browser/debugger/tools_view.h
new file mode 100644
index 0000000..8d26267
--- /dev/null
+++ b/chrome/browser/debugger/tools_view.h
@@ -0,0 +1,75 @@
+// 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.
+
+#ifndef CHROME_BROWSER_DEBUGGER_TOOLS_VIEW_H_
+#define CHROME_BROWSER_DEBUGGER_TOOLS_VIEW_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/gfx/size.h"
+#include "chrome/browser/tab_contents/tab_contents_delegate.h"
+#include "chrome/views/view.h"
+
+class TabContentsContainerView;
+class WebContents;
+
+class ToolsView : public views::View,
+ public TabContentsDelegate {
+ public:
+ explicit ToolsView(int inspected_process_id, int inspected_view_id);
+ virtual ~ToolsView();
+
+ void SendToolsClientMessage(int tools_message_type, const std::wstring& body);
+
+ // Destroy content views when the window is closing.
+ void OnWindowClosing();
+
+ private:
+ // Overridden from TabContentsDelegate:
+ virtual void NavigationStateChanged(const TabContents* source,
+ unsigned changed_flags) {}
+ virtual void ReplaceContents(TabContents* source,
+ TabContents* new_contents) {}
+ virtual void AddNewContents(TabContents* source,
+ TabContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture) {}
+ virtual void ActivateContents(TabContents* contents) {}
+ virtual void LoadingStateChanged(TabContents* source) {}
+ virtual void CloseContents(TabContents* source) {}
+ virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {}
+ virtual bool IsPopup(TabContents* source) { return false; }
+ virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {}
+ virtual void URLStarredChanged(TabContents* source, bool) {}
+ virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
+ virtual bool CanBlur() const { return false; }
+ // Opens a new URL inside the passed in TabContents, if source is 0 open
+ // in the current front-most tab.
+ virtual void OpenURLFromTab(TabContents* source,
+ const GURL& url, const GURL& referrer,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition);
+
+ // Overridden from views::View:
+ virtual std::string GetClassName() const;
+ virtual gfx::Size GetPreferredSize();
+ virtual void Layout();
+ virtual void ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child);
+
+ void Init();
+
+ const int inspected_process_id_;
+ const int inspected_view_id_;
+ WebContents* web_contents_;
+ TabContentsContainerView* web_container_;
+
+ DISALLOW_COPY_AND_ASSIGN(ToolsView);
+};
+
+#endif // CHROME_BROWSER_DEBUGGER_TOOLS_VIEW_H_
+
diff --git a/chrome/browser/debugger/tools_window.cc b/chrome/browser/debugger/tools_window.cc
new file mode 100644
index 0000000..19c602fb
--- /dev/null
+++ b/chrome/browser/debugger/tools_window.cc
@@ -0,0 +1,54 @@
+// 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/tools_window.h"
+
+#include "chrome/browser/debugger/tools_view.h"
+#include "chrome/views/window.h"
+
+ToolsWindow::ToolsWindow() : window_(NULL), tools_view_(NULL) {
+}
+
+ToolsWindow::~ToolsWindow() {
+}
+
+void ToolsWindow::Show(int inspected_process_id,
+ int inspected_view_id) {
+ if (window_) {
+ window_->Show();
+ return;
+ }
+
+ tools_view_ = new ToolsView(inspected_process_id, inspected_view_id);
+ window_ = views::Window::CreateChromeWindow(NULL, gfx::Rect(), this);
+ window_->Show();
+}
+
+void ToolsWindow::SendToolsClientMessage(int tools_message_type,
+ const std::wstring& body) {
+ if (!tools_view_)
+ return;
+ tools_view_->SendToolsClientMessage(tools_message_type, body);
+}
+
+std::wstring ToolsWindow::GetWindowTitle() const {
+ return L"Developer Tools";
+}
+
+void ToolsWindow::WindowClosing() {
+ if (tools_view_) {
+ tools_view_->OnWindowClosing();
+ tools_view_ = NULL;
+ window_ = NULL;
+ }
+}
+
+bool ToolsWindow::CanResize() const {
+ return true;
+}
+
+views::View* ToolsWindow::GetContentsView() {
+ return tools_view_;
+}
+
diff --git a/chrome/browser/debugger/tools_window.h b/chrome/browser/debugger/tools_window.h
new file mode 100644
index 0000000..738ec38
--- /dev/null
+++ b/chrome/browser/debugger/tools_window.h
@@ -0,0 +1,67 @@
+// 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.
+
+#ifndef CHROME_BROWSER_DEBUGGER_TOOLS_WINDOW_H_
+#define CHROME_BROWSER_DEBUGGER_TOOLS_WINDOW_H_
+
+#include "base/basictypes.h"
+
+// TODO(yurys): port to other platforms
+#if defined(OS_WIN)
+
+#include "chrome/views/window_delegate.h"
+
+namespace views {
+class Window;
+}
+class ToolsView;
+class TabContents;
+
+class ToolsWindow : public views::WindowDelegate {
+ public:
+ ToolsWindow();
+ virtual ~ToolsWindow();
+
+ // Show inspector window for the tab
+ void Show(int inspected_process_id,
+ int inspected_view_id);
+
+ void SendToolsClientMessage(int tools_message_type,
+ const std::wstring& body);
+
+ private:
+ // views::WindowDelegate methods:
+ virtual std::wstring GetWindowTitle() const;
+ virtual void WindowClosing();
+ virtual bool CanResize() const;
+ virtual views::View* GetContentsView();
+
+ views::Window* window_;
+ ToolsView* tools_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(ToolsWindow);
+};
+
+#else // defined(OS_WIN)
+
+class ToolsWindow {
+ public:
+ ToolsWindow() {}
+ virtual ~ToolsWindow() {}
+
+ // Show inspector window for the tab
+ void Show(int inspected_process_id,
+ int inspected_view_id) {}
+
+ void SendToolsClientMessage(int tools_message_type,
+ const std::wstring& body) {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ToolsWindow);
+};
+
+#endif // OS_WIN
+
+#endif // CHROME_BROWSER_DEBUGGER_TOOLS_WINDOW_H_
+