summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/debugger_ui.cc148
-rw-r--r--chrome/browser/dom_ui/debugger_ui.h28
-rw-r--r--chrome/browser/dom_ui/dom_ui_contents.cc6
3 files changed, 179 insertions, 3 deletions
diff --git a/chrome/browser/dom_ui/debugger_ui.cc b/chrome/browser/dom_ui/debugger_ui.cc
new file mode 100644
index 0000000..3af0faa
--- /dev/null
+++ b/chrome/browser/dom_ui/debugger_ui.cc
@@ -0,0 +1,148 @@
+// Copyright (c) 2006-2008 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/dom_ui/debugger_ui.h"
+
+#include "base/command_line.h"
+#include "base/file_util.h"
+#include "base/string_util.h"
+#include "base/values.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/debugger/debugger_shell.h"
+#include "chrome/browser/debugger/debugger_wrapper.h"
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/resource_bundle.h"
+#include "chrome/common/url_constants.h"
+#include "net/base/mime_util.h"
+
+#include "grit/debugger_resources.h"
+
+class DebuggerHTMLSource : public ChromeURLDataManager::DataSource {
+ public:
+ // Creates our datasource and sets our user message to a specific message
+ // from our string bundle.
+ DebuggerHTMLSource()
+ : DataSource("debugger", MessageLoop::current()) { }
+
+ // Called when the network layer has requested a resource underneath
+ // the path we registered.
+ virtual void StartDataRequest(const std::string& path, int request_id) {
+ int resource_id = 0;
+
+ if (!path.length()) {
+ resource_id = IDR_DEBUGGER_HTML;
+ } else if (path == "debugger.js") {
+ resource_id = IDR_DEBUGGER_JS;
+ } else if (path == "debugger.css") {
+ resource_id = IDR_DEBUGGER_CSS;
+ } else {
+ SendResponse(request_id, NULL);
+ return;
+ }
+
+ std::wstring debugger_path =
+ CommandLine::ForCurrentProcess()->GetSwitchValue(
+ switches::kJavaScriptDebuggerPath);
+ std::string data_str;
+ if (!debugger_path.empty() && file_util::PathExists(debugger_path)) {
+ if (path.empty())
+ file_util::AppendToPath(&debugger_path, L"debugger.html");
+ else
+ file_util::AppendToPath(&debugger_path, UTF8ToWide(path));
+ if (!file_util::ReadFileToString(debugger_path, &data_str)) {
+ SendResponse(request_id, NULL);
+ return;
+ }
+ } else {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ data_str = rb.GetDataResource(resource_id);
+ }
+ scoped_refptr<RefCountedBytes> data_bytes(new RefCountedBytes);
+ data_bytes->data.resize(data_str.size());
+ std::copy(data_str.begin(), data_str.end(), data_bytes->data.begin());
+
+ SendResponse(request_id, data_bytes);
+ }
+
+ virtual std::string GetMimeType(const std::string& path) const {
+ // Currently but three choices {"", "debugger.js", "debugger.css"}.
+ // Map the extension to mime-type, defaulting to "text/html".
+ std::string mime_type("text/html");
+#if defined(OS_WIN)
+ FilePath file_path(ASCIIToWide(path));
+#elif defined(OS_POSIX)
+ FilePath file_path(path);
+#endif
+ net::GetMimeTypeFromFile(file_path, &mime_type);
+ return mime_type;
+ }
+
+ private:
+ DISALLOW_EVIL_CONSTRUCTORS(DebuggerHTMLSource);
+};
+
+
+class DebuggerHandler : public DOMMessageHandler {
+ public:
+ explicit DebuggerHandler(DOMUI* dom_ui) : DOMMessageHandler(dom_ui) {
+ dom_ui->RegisterMessageCallback("DebuggerHostMessage",
+ NewCallback(this, &DebuggerHandler::HandleDebuggerHostMessage));
+ }
+
+ void HandleDebuggerHostMessage(const Value* content) {
+ if (!content || !content->IsType(Value::TYPE_LIST)) {
+ NOTREACHED();
+ return;
+ }
+ const ListValue* args = static_cast<const ListValue*>(content);
+ if (args->GetSize() < 1) {
+ NOTREACHED();
+ return;
+ }
+
+#ifndef CHROME_DEBUGGER_DISABLED
+ DebuggerWrapper* wrapper = g_browser_process->debugger_wrapper();
+ DebuggerHost* debugger_host = wrapper->GetDebugger();
+ if (!debugger_host) {
+ NOTREACHED();
+ return;
+ }
+ debugger_host->OnDebuggerHostMsg(args);
+#endif
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DebuggerHandler);
+};
+
+
+DebuggerUI::DebuggerUI(DOMUIContents* contents)
+ : DOMUI(contents) {
+}
+
+void DebuggerUI::Init() {
+ AddMessageHandler(new DebuggerHandler(this));
+
+ DebuggerHTMLSource* html_source = new DebuggerHTMLSource();
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(&chrome_url_data_manager,
+ &ChromeURLDataManager::AddDataSource,
+ html_source));
+}
+
+// static
+bool DebuggerUI::IsDebuggerUrl(const GURL& url) {
+ return url.SchemeIs(chrome::kChromeUIScheme) &&
+ url.host() == chrome::kInspectorHost;
+}
+
+// static
+GURL DebuggerUI::GetBaseURL() {
+ // DebuggerUI is accessible from chrome-ui://inspector.
+ std::string url = chrome::kChromeUIScheme;
+ url += chrome::kStandardSchemeSeparator;
+ url += chrome::kInspectorHost;
+ return GURL(url);
+}
diff --git a/chrome/browser/dom_ui/debugger_ui.h b/chrome/browser/dom_ui/debugger_ui.h
new file mode 100644
index 0000000..3b12ec9
--- /dev/null
+++ b/chrome/browser/dom_ui/debugger_ui.h
@@ -0,0 +1,28 @@
+// Copyright (c) 2006-2008 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.
+//
+// This file defines utility functions for working with strings.
+
+#ifndef CHROME_BROWSER_DOM_UI_DEBUGGER_UI_H_
+#define CHROME_BROWSER_DOM_UI_DEBUGGER_UI_H_
+
+#include "chrome/browser/dom_ui/dom_ui.h"
+
+class DebuggerUI : public DOMUI {
+ public:
+ DebuggerUI(DOMUIContents* contents);
+
+ // DOMUI Implementation
+ virtual void Init();
+
+ // Return the URL for the front page of this UI.
+ static GURL GetBaseURL();
+
+ static bool IsDebuggerUrl(const GURL& url);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DebuggerUI);
+};
+
+#endif // CHROME_BROWSER_DOM_UI_DEBUGGER_UI_H_
diff --git a/chrome/browser/dom_ui/dom_ui_contents.cc b/chrome/browser/dom_ui/dom_ui_contents.cc
index 4fe32d1..4d5f7e3 100644
--- a/chrome/browser/dom_ui/dom_ui_contents.cc
+++ b/chrome/browser/dom_ui/dom_ui_contents.cc
@@ -4,7 +4,7 @@
#include "chrome/browser/dom_ui/dom_ui_contents.h"
-#include "chrome/browser/debugger/debugger_contents.h"
+#include "chrome/browser/dom_ui/debugger_ui.h"
#include "chrome/browser/dom_ui/dev_tools_ui.h"
#include "chrome/browser/dom_ui/dom_ui.h"
#include "chrome/browser/dom_ui/downloads_ui.h"
@@ -287,8 +287,8 @@ DOMUI* DOMUIContents::GetDOMUIForURL(const GURL &url) {
if (url.host() == ExtensionsUI::GetBaseURL().host()) {
return new ExtensionsUI(this);
}
- if (url.host() == DebuggerContents::GetBaseURL().host()) {
- return new DebuggerContents(this);
+ if (url.host() == DebuggerUI::GetBaseURL().host()) {
+ return new DebuggerUI(this);
}
if (url.host() == DevToolsUI::GetBaseURL().host()) {
return new DevToolsUI(this);