diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-31 16:25:09 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-31 16:25:09 +0000 |
commit | 5ced5eb46be9e6c2d2b72a421d930cee6d7fcf89 (patch) | |
tree | ffccdfbb0ccd8a7f2663d0144e7684c8ffee0194 /chrome/browser/debugger/debugger_contents.cc | |
parent | f18953d3c2a4eae2bc33b1eecce96e28f0815a64 (diff) | |
download | chromium_src-5ced5eb46be9e6c2d2b72a421d930cee6d7fcf89.zip chromium_src-5ced5eb46be9e6c2d2b72a421d930cee6d7fcf89.tar.gz chromium_src-5ced5eb46be9e6c2d2b72a421d930cee6d7fcf89.tar.bz2 |
Initial cleanup and refactoring to make debugger UI use DHTML and get rid of the last of its native UI. This is done using a DOMUIHost subclass and a new TabContents type.
This checkin also fixes a few minor issues:
* hitting the keyboard accelerator brings the current debugger window to front
* text is grayed out when in "running" mode rather than "paused"
* up/down arrows have command-line history (transient)
* some text used to get eaten when you first bring up the window ("attached to <tabname>"), this is now handled
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/debugger/debugger_contents.cc')
-rw-r--r-- | chrome/browser/debugger/debugger_contents.cc | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/chrome/browser/debugger/debugger_contents.cc b/chrome/browser/debugger/debugger_contents.cc new file mode 100644 index 0000000..7b2e0a3 --- /dev/null +++ b/chrome/browser/debugger/debugger_contents.cc @@ -0,0 +1,131 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// This file defines utility functions for working with strings. + +#include "chrome/browser/browser_process.h" +#include "chrome/browser/debugger/debugger_contents.h" +#include "chrome/browser/debugger/debugger_shell.h" +#include "chrome/browser/debugger/debugger_wrapper.h" +#include "chrome/browser/debugger/resources/debugger_resources.h" +#include "chrome/browser/dom_ui/chrome_url_data_manager.h" +#include "chrome/common/resource_bundle.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) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + 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; + } + const std::string& 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); + } + + private: + DISALLOW_EVIL_CONSTRUCTORS(DebuggerHTMLSource); +}; + + +class DebuggerHandler : public DOMMessageHandler { + public: + explicit DebuggerHandler(DOMUIHost* host) { + host->RegisterMessageCallback("command", + NewCallback(this, &DebuggerHandler::HandleCommand)); + } + + void HandleCommand(const Value* content) { + // Extract the parameters out of the input list. + if (!content || !content->IsType(Value::TYPE_LIST)) { + NOTREACHED(); + return; + } + const ListValue* args = static_cast<const ListValue*>(content); + if (args->GetSize() != 1) { + NOTREACHED(); + return; + } + std::wstring command; + Value* value = NULL; + if (!args->Get(0, &value) || !value->GetAsString(&command)) { + NOTREACHED(); + return; + } +#ifndef CHROME_DEBUGGER_DISABLED + DebuggerWrapper* wrapper = g_browser_process->debugger_wrapper(); + DebuggerShell* shell = wrapper->GetDebugger(); + shell->ProcessCommand(command); +#endif + } + private: + DISALLOW_EVIL_CONSTRUCTORS(DebuggerHandler); +}; + + +DebuggerContents::DebuggerContents(Profile* profile, SiteInstance* instance) + : DOMUIHost(profile, instance, NULL) { + type_ = TAB_CONTENTS_DEBUGGER; +} + +void DebuggerContents::AttachMessageHandlers() { + 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 DebuggerContents::IsDebuggerUrl(const GURL& url) { + if (url.SchemeIs("chrome-resource") && url.host() == "debugger") + return true; + return false; +} |