diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-29 02:16:06 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-29 02:16:06 +0000 |
commit | b46442d7e2e8cccf5f9bcafb2e1e3b7cf23d424b (patch) | |
tree | e1e0f0d2fc3653d71e93b4cca71cce5ea2cb7223 /chrome/browser/debugger | |
parent | 75a4e77f6c2c21706c09948269c45d98db28757b (diff) | |
download | chromium_src-b46442d7e2e8cccf5f9bcafb2e1e3b7cf23d424b.zip chromium_src-b46442d7e2e8cccf5f9bcafb2e1e3b7cf23d424b.tar.gz chromium_src-b46442d7e2e8cccf5f9bcafb2e1e3b7cf23d424b.tar.bz2 |
Wholesale move of debugger sources to content.
Other references are modified only to point to the new
location. Follow-up changes will move build rules for the debugger
into content.
This adds a somewhat permissive DEPS file to
content/browser/debugger. Follow-up work will whittle that down to
zero dependencies on chrome/.
BUG=84078
TEST=existing
Review URL: http://codereview.chromium.org/7274031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90912 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/debugger')
71 files changed, 0 insertions, 6886 deletions
diff --git a/chrome/browser/debugger/browser_list_tabcontents_provider.cc b/chrome/browser/debugger/browser_list_tabcontents_provider.cc deleted file mode 100644 index 65addd8..0000000 --- a/chrome/browser/debugger/browser_list_tabcontents_provider.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2011 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/browser_list_tabcontents_provider.h" - -#include "chrome/browser/tabs/tab_strip_model.h" -#include "chrome/browser/ui/browser_list.h" - -DevToolsHttpProtocolHandler::InspectableTabs -BrowserListTabContentsProvider::GetInspectableTabs() { - DevToolsHttpProtocolHandler::InspectableTabs tabs; - for (BrowserList::const_iterator it = BrowserList::begin(), - end = BrowserList::end(); it != end; ++it) { - TabStripModel* model = (*it)->tabstrip_model(); - for (int i = 0, size = model->count(); i < size; ++i) - tabs.push_back(model->GetTabContentsAt(i)); - } - return tabs; -} diff --git a/chrome/browser/debugger/browser_list_tabcontents_provider.h b/chrome/browser/debugger/browser_list_tabcontents_provider.h deleted file mode 100644 index f7fd61e..0000000 --- a/chrome/browser/debugger/browser_list_tabcontents_provider.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2011 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_BROWSER_LIST_TABCONTENTS_PROVIDER_H_ -#define CHROME_BROWSER_DEBUGGER_BROWSER_LIST_TABCONTENTS_PROVIDER_H_ - -#include "chrome/browser/debugger/devtools_http_protocol_handler.h" - -class BrowserListTabContentsProvider : - public DevToolsHttpProtocolHandler::TabContentsProvider { - public: - BrowserListTabContentsProvider() {} - virtual ~BrowserListTabContentsProvider() {} - - virtual DevToolsHttpProtocolHandler::InspectableTabs GetInspectableTabs(); - private: - DISALLOW_COPY_AND_ASSIGN(BrowserListTabContentsProvider); -}; - -#endif // CHROME_BROWSER_DEBUGGER_BROWSER_LIST_TABCONTENTS_PROVIDER_H_ diff --git a/chrome/browser/debugger/debugger_host.h b/chrome/browser/debugger/debugger_host.h deleted file mode 100644 index 6177c16..0000000 --- a/chrome/browser/debugger/debugger_host.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2011 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. - -// A part of browser-side server debugger exposed to DebuggerWrapper. - -#ifndef CHROME_BROWSER_DEBUGGER_DEBUGGER_HOST_H_ -#define CHROME_BROWSER_DEBUGGER_DEBUGGER_HOST_H_ -#pragma once - -#include <string> - -#include "base/basictypes.h" -#include "base/memory/ref_counted.h" - -class ListValue; - -class DebuggerHost : public base::RefCountedThreadSafe<DebuggerHost> { - public: - DebuggerHost() {} - virtual ~DebuggerHost() {} - - // call before other methods - virtual void Start() = 0; - - // A message from the V8 debugger in the renderer being debugged via - // RenderViewHost - virtual void DebugMessage(const std::wstring& msg) = 0; - // We've been successfully attached to a renderer. - virtual void OnDebugAttach() = 0; - // The renderer we're attached to is gone. - virtual void OnDebugDisconnect() = 0; - - virtual void DidDisconnect() = 0; - virtual void DidConnect() {} - virtual void ProcessCommand(const std::wstring& data) {} - - // Handles messages from debugger UI. - virtual void OnDebuggerHostMsg(const ListValue* args) {} - - // Shows the debugger UI and returns true if it has any. - virtual bool ShowWindow() { return false; } - - private: - - DISALLOW_COPY_AND_ASSIGN(DebuggerHost); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEBUGGER_HOST_H_ diff --git a/chrome/browser/debugger/debugger_remote_service.cc b/chrome/browser/debugger/debugger_remote_service.cc deleted file mode 100644 index 47ccdae..0000000 --- a/chrome/browser/debugger/debugger_remote_service.cc +++ /dev/null @@ -1,336 +0,0 @@ -// Copyright (c) 2011 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 contains implementations of the DebuggerRemoteService methods, -// defines DebuggerRemoteService and DebuggerRemoteServiceCommand constants. - -#include "chrome/browser/debugger/debugger_remote_service.h" - -#include "base/json/json_reader.h" -#include "base/json/json_writer.h" -#include "base/stringprintf.h" -#include "base/string_number_conversions.h" -#include "base/utf_string_conversions.h" -#include "base/values.h" -#include "chrome/browser/debugger/devtools_manager.h" -#include "chrome/browser/debugger/devtools_protocol_handler.h" -#include "chrome/browser/debugger/devtools_remote_message.h" -#include "chrome/browser/debugger/inspectable_tab_proxy.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/render_messages.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/common/devtools_messages.h" - -namespace { - -// Constants for the "data", "result", and "command" JSON message fields. -const char kDataKey[] = "data"; -const char kResultKey[] = "result"; -const char kCommandKey[] = "command"; - -} // namespace - -const std::string DebuggerRemoteServiceCommand::kAttach = "attach"; -const std::string DebuggerRemoteServiceCommand::kDetach = "detach"; -const std::string DebuggerRemoteServiceCommand::kDebuggerCommand = - "debugger_command"; -const std::string DebuggerRemoteServiceCommand::kEvaluateJavascript = - "evaluate_javascript"; -const std::string DebuggerRemoteServiceCommand::kFrameNavigate = - "navigated"; -const std::string DebuggerRemoteServiceCommand::kTabClosed = - "closed"; - -const std::string DebuggerRemoteService::kToolName = "V8Debugger"; - -DebuggerRemoteService::DebuggerRemoteService(DevToolsProtocolHandler* delegate) - : delegate_(delegate) {} - -DebuggerRemoteService::~DebuggerRemoteService() {} - -// This method handles the V8Debugger tool commands which are -// retrieved from the request "command" field. If an operation result -// is ready off-hand (synchronously), it is sent back to the remote debugger. -// Otherwise the corresponding response is received through IPC from the -// V8 debugger via DevToolsClientHost. -void DebuggerRemoteService::HandleMessage( - const DevToolsRemoteMessage& message) { - const std::string destination = message.destination(); - scoped_ptr<Value> request(base::JSONReader::Read(message.content(), true)); - if (request.get() == NULL) { - // Bad JSON - NOTREACHED(); - return; - } - DictionaryValue* content; - if (!request->IsType(Value::TYPE_DICTIONARY)) { - NOTREACHED(); // Broken protocol :( - return; - } - content = static_cast<DictionaryValue*>(request.get()); - if (!content->HasKey(kCommandKey)) { - NOTREACHED(); // Broken protocol :( - return; - } - std::string command; - DictionaryValue response; - - content->GetString(kCommandKey, &command); - response.SetString(kCommandKey, command); - bool send_response = true; - if (destination.empty()) { - // Unknown command (bad format?) - NOTREACHED(); - response.SetInteger(kResultKey, RESULT_UNKNOWN_COMMAND); - SendResponse(response, message.tool(), message.destination()); - return; - } - int32 tab_uid = -1; - base::StringToInt(destination, &tab_uid); - - if (command == DebuggerRemoteServiceCommand::kAttach) { - // TODO(apavlov): handle 0 for a new tab - response.SetString(kCommandKey, DebuggerRemoteServiceCommand::kAttach); - AttachToTab(destination, &response); - } else if (command == DebuggerRemoteServiceCommand::kDetach) { - response.SetString(kCommandKey, DebuggerRemoteServiceCommand::kDetach); - DetachFromTab(destination, &response); - } else if (command == DebuggerRemoteServiceCommand::kDebuggerCommand) { - send_response = DispatchDebuggerCommand(tab_uid, content, &response); - } else if (command == DebuggerRemoteServiceCommand::kEvaluateJavascript) { - send_response = DispatchEvaluateJavascript(tab_uid, content, &response); - } else { - // Unknown command - NOTREACHED(); - response.SetInteger(kResultKey, RESULT_UNKNOWN_COMMAND); - } - - if (send_response) { - SendResponse(response, message.tool(), message.destination()); - } -} - -void DebuggerRemoteService::OnConnectionLost() { - delegate_->inspectable_tab_proxy()->OnRemoteDebuggerDetached(); -} - -// Sends a JSON response to the remote debugger using |response| as content, -// |tool| and |destination| as the respective header values. -void DebuggerRemoteService::SendResponse(const Value& response, - const std::string& tool, - const std::string& destination) { - std::string response_content; - base::JSONWriter::Write(&response, false, &response_content); - scoped_ptr<DevToolsRemoteMessage> response_message( - DevToolsRemoteMessageBuilder::instance().Create(tool, - destination, - response_content)); - delegate_->Send(*response_message.get()); -} - -// Gets a TabContents instance corresponding to the |tab_uid| using the -// InspectableTabProxy controllers map, or NULL if none found. -TabContents* DebuggerRemoteService::ToTabContents(int32 tab_uid) { - const InspectableTabProxy::TabMap& tab_map = - delegate_->inspectable_tab_proxy()->tab_map(); - InspectableTabProxy::TabMap::const_iterator it = tab_map.find(tab_uid); - if (it != tab_map.end()) { - TabContents* tab_contents = it->second->tab_contents(); - if (tab_contents == NULL) { - return NULL; - } else { - return tab_contents; - } - } else { - return NULL; - } -} - -// Gets invoked from a DevToolsClientHost callback whenever -// a message from the V8 VM debugger corresponding to |tab_id| is received. -// Composes a Chrome Developer Tools Protocol JSON response and sends it -// to the remote debugger. -void DebuggerRemoteService::DebuggerOutput(int32 tab_uid, - const std::string& message) { - std::string content = StringPrintf( - "{\"command\":\"%s\",\"result\":%s,\"data\":%s}", - DebuggerRemoteServiceCommand::kDebuggerCommand.c_str(), - base::IntToString(RESULT_OK).c_str(), - message.c_str()); - scoped_ptr<DevToolsRemoteMessage> response_message( - DevToolsRemoteMessageBuilder::instance().Create( - kToolName, - base::IntToString(tab_uid), - content)); - delegate_->Send(*(response_message.get())); -} - -// Gets invoked from a DevToolsClientHost callback whenever -// a tab corresponding to |tab_id| changes its URL. |url| is the new -// URL of the tab (may be the same as the previous one if the tab is reloaded). -// Sends the corresponding message to the remote debugger. -void DebuggerRemoteService::FrameNavigate(int32 tab_uid, - const std::string& url) { - DictionaryValue value; - value.SetString(kCommandKey, DebuggerRemoteServiceCommand::kFrameNavigate); - value.SetInteger(kResultKey, RESULT_OK); - value.SetString(kDataKey, url); - SendResponse(value, kToolName, base::IntToString(tab_uid)); -} - -// Gets invoked from a DevToolsClientHost callback whenever -// a tab corresponding to |tab_id| gets closed. -// Sends the corresponding message to the remote debugger. -void DebuggerRemoteService::TabClosed(int32 tab_id) { - DictionaryValue value; - value.SetString(kCommandKey, DebuggerRemoteServiceCommand::kTabClosed); - value.SetInteger(kResultKey, RESULT_OK); - SendResponse(value, kToolName, base::IntToString(tab_id)); -} - -// Attaches a remote debugger to the target tab specified by |destination| -// by posting the DevToolsAgentMsg_Attach message and sends a response -// to the remote debugger immediately. -void DebuggerRemoteService::AttachToTab(const std::string& destination, - DictionaryValue* response) { - int32 tab_uid = -1; - base::StringToInt(destination, &tab_uid); - if (tab_uid < 0) { - // Bad tab_uid received from remote debugger (perhaps NaN) - response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); - return; - } - if (tab_uid == 0) { // single tab_uid - // We've been asked to open a new tab with URL - // TODO(apavlov): implement - NOTIMPLEMENTED(); - response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); - return; - } - TabContents* tab_contents = ToTabContents(tab_uid); - if (tab_contents == NULL) { - // No active tab contents with tab_uid - response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); - return; - } - RenderViewHost* target_host = tab_contents->render_view_host(); - DevToolsClientHost* client_host = - delegate_->inspectable_tab_proxy()->ClientHostForTabId(tab_uid); - if (client_host == NULL) { - client_host = - delegate_->inspectable_tab_proxy()->NewClientHost(tab_uid, this); - DevToolsManager* manager = DevToolsManager::GetInstance(); - if (manager != NULL) { - manager->RegisterDevToolsClientHostFor(target_host, client_host); - response->SetInteger(kResultKey, RESULT_OK); - } else { - response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR); - } - } else { - // DevToolsClientHost for this tab is already registered - response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE); - } -} - -// Detaches a remote debugger from the target tab specified by |destination| -// by posting the DevToolsAgentMsg_Detach message and sends a response -// to the remote debugger immediately. -void DebuggerRemoteService::DetachFromTab(const std::string& destination, - DictionaryValue* response) { - int32 tab_uid = -1; - base::StringToInt(destination, &tab_uid); - if (tab_uid == -1) { - // Bad tab_uid received from remote debugger (NaN) - if (response != NULL) { - response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); - } - return; - } - int result_code; - DevToolsClientHostImpl* client_host = - delegate_->inspectable_tab_proxy()->ClientHostForTabId(tab_uid); - if (client_host != NULL) { - client_host->Close(); - result_code = RESULT_OK; - } else { - // No client host registered for |tab_uid|. - result_code = RESULT_UNKNOWN_TAB; - } - if (response != NULL) { - response->SetInteger(kResultKey, result_code); - } -} - -// Sends a V8 debugger command to the target tab V8 debugger. -// Does not send back a response (which is received asynchronously -// through IPC) unless an error occurs before the command has actually -// been sent. -bool DebuggerRemoteService::DispatchDebuggerCommand(int tab_uid, - DictionaryValue* content, - DictionaryValue* response) { - if (tab_uid == -1) { - // Invalid tab_uid from remote debugger (perhaps NaN) - response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); - return true; - } - DevToolsManager* manager = DevToolsManager::GetInstance(); - if (manager == NULL) { - response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR); - return true; - } - TabContents* tab_contents = ToTabContents(tab_uid); - if (tab_contents == NULL) { - // Unknown tab_uid from remote debugger - response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); - return true; - } - DevToolsClientHost* client_host = - manager->GetDevToolsClientHostFor(tab_contents->render_view_host()); - if (client_host == NULL) { - // tab_uid is not being debugged (Attach has not been invoked) - response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE); - return true; - } - std::string v8_command; - DictionaryValue* v8_command_value; - content->GetDictionary(kDataKey, &v8_command_value); - base::JSONWriter::Write(v8_command_value, false, &v8_command); - manager->ForwardToDevToolsAgent( - client_host, DevToolsAgentMsg_DebuggerCommand(v8_command)); - // Do not send the response right now, as the JSON will be received from - // the V8 debugger asynchronously. - return false; -} - -// Sends the immediate "evaluate Javascript" command to the V8 debugger. -// The evaluation result is not sent back to the client as this command -// is in fact needed to invoke processing of queued debugger commands. -bool DebuggerRemoteService::DispatchEvaluateJavascript( - int tab_uid, - DictionaryValue* content, - DictionaryValue* response) { - if (tab_uid == -1) { - // Invalid tab_uid from remote debugger (perhaps NaN) - response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); - return true; - } - TabContents* tab_contents = ToTabContents(tab_uid); - if (tab_contents == NULL) { - // Unknown tab_uid from remote debugger - response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); - return true; - } - RenderViewHost* render_view_host = tab_contents->render_view_host(); - if (render_view_host == NULL) { - // No RenderViewHost - response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); - return true; - } - std::string javascript; - content->GetString(kDataKey, &javascript); - render_view_host->ExecuteJavascriptInWebFrame(string16(), - UTF8ToUTF16(javascript)); - return false; -} diff --git a/chrome/browser/debugger/debugger_remote_service.h b/chrome/browser/debugger/debugger_remote_service.h deleted file mode 100644 index 83b1f40..0000000 --- a/chrome/browser/debugger/debugger_remote_service.h +++ /dev/null @@ -1,124 +0,0 @@ -// 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. - -// This file declares the DebuggerRemoteServiceCommand struct and the -// DebuggerRemoteService class which handles commands directed to the -// "V8Debugger" tool. -#ifndef CHROME_BROWSER_DEBUGGER_DEBUGGER_REMOTE_SERVICE_H_ -#define CHROME_BROWSER_DEBUGGER_DEBUGGER_REMOTE_SERVICE_H_ -#pragma once - -#include <string> - -#include "base/basictypes.h" -#include "chrome/browser/debugger/devtools_remote.h" - -class DevToolsProtocolHandler; -class DevToolsRemoteMessage; -class DictionaryValue; -class Value; -class TabContents; - -// Contains constants for DebuggerRemoteService tool protocol commands -// (V8-related only). -struct DebuggerRemoteServiceCommand { - static const std::string kAttach; - static const std::string kDetach; - static const std::string kDebuggerCommand; - static const std::string kEvaluateJavascript; - static const std::string kFrameNavigate; // navigation event - static const std::string kTabClosed; // tab closing event -}; - -// Handles V8 debugger-related messages from the remote debugger (like -// attach to V8 debugger, detach from V8 debugger, send command to V8 debugger) -// and proxies JSON messages from V8 debugger to the remote debugger. -class DebuggerRemoteService : public DevToolsRemoteListener { - public: - // |delegate| (never NULL) is the protocol handler instance - // which dispatches messages to this service. The responses from the - // V8 VM debugger are routed back to |delegate|. - // The ownership of |delegate| is NOT transferred to this class. - explicit DebuggerRemoteService(DevToolsProtocolHandler* delegate); - - // Handles a JSON message from the tab_uid-associated V8 debugger. - void DebuggerOutput(int32 tab_uid, const std::string& message); - - // Handles a frame navigation event. - void FrameNavigate(int32 tab_uid, const std::string& url); - - // Handles a tab closing event. - void TabClosed(int32 tab_uid); - - // Detaches the remote debugger from the tab specified by |destination|. - // It is public so that we can detach from the tab on the remote debugger - // connection loss. - // If |response| is not NULL, the operation result will be written - // as the "result" field in |response|, otherwise the result - // will not be propagated back to the caller. - void DetachFromTab(const std::string& destination, - DictionaryValue* response); - - // DevToolsRemoteListener interface. - - // Processes |message| from the remote debugger, where the tool is - // "V8Debugger". Either sends the reply immediately or waits for an - // asynchronous response from the V8 debugger. - virtual void HandleMessage(const DevToolsRemoteMessage& message); - - // Gets invoked on the remote debugger [socket] connection loss. - // Notifies the InspectableTabProxy of the remote debugger detachment. - virtual void OnConnectionLost(); - - // Specifies a tool name ("V8Debugger") handled by this class. - static const std::string kToolName; - - private: - // Operation result returned in the "result" field. - typedef enum { - RESULT_OK = 0, - RESULT_ILLEGAL_TAB_STATE, - RESULT_UNKNOWN_TAB, - RESULT_DEBUGGER_ERROR, - RESULT_UNKNOWN_COMMAND - } Result; - - virtual ~DebuggerRemoteService(); - - // Attaches a remote debugger to the tab specified by |destination|. - // Writes the attachment result (one of Result enum values) into |response|. - void AttachToTab(const std::string& destination, - DictionaryValue* response); - - // Retrieves a WebContents instance for the specified |tab_uid| - // or NULL if no such tab is found or no WebContents instance - // corresponds to that tab. - TabContents* ToTabContents(int32 tab_uid); - - // Sends a JSON message with the |response| to the remote debugger. - // |tool| and |destination| are used as the respective header values. - void SendResponse(const Value& response, - const std::string& tool, - const std::string& destination); - - // Redirects a V8 debugger command from |content| to a V8 debugger associated - // with the |tab_uid| and writes the result into |response| if it becomes - // known immediately. - bool DispatchDebuggerCommand(int tab_uid, - DictionaryValue* content, - DictionaryValue* response); - - // Redirects a Javascript evaluation command from |content| to - // a V8 debugger associated with the |tab_uid| and writes the result - // into |response| if it becomes known immediately. - bool DispatchEvaluateJavascript(int tab_uid, - DictionaryValue* content, - DictionaryValue* response); - - // The delegate is used to get an InspectableTabProxy instance. - DevToolsProtocolHandler* delegate_; - DISALLOW_COPY_AND_ASSIGN(DebuggerRemoteService); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEBUGGER_REMOTE_SERVICE_H_ diff --git a/chrome/browser/debugger/devtools_client_host.cc b/chrome/browser/debugger/devtools_client_host.cc deleted file mode 100644 index f619bfb..0000000 --- a/chrome/browser/debugger/devtools_client_host.cc +++ /dev/null @@ -1,16 +0,0 @@ -// 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/devtools_client_host.h" - -DevToolsWindow* DevToolsClientHost::AsDevToolsWindow() { - return NULL; -} - -void DevToolsClientHost::NotifyCloseListener() { - if (close_listener_) { - close_listener_->ClientHostClosing(this); - close_listener_ = NULL; - } -} diff --git a/chrome/browser/debugger/devtools_client_host.h b/chrome/browser/debugger/devtools_client_host.h deleted file mode 100644 index 4c81e87..0000000 --- a/chrome/browser/debugger/devtools_client_host.h +++ /dev/null @@ -1,69 +0,0 @@ -// 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_DEVTOOLS_CLIENT_HOST_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_CLIENT_HOST_H_ -#pragma once - -#include <string> - -#include "base/basictypes.h" - -namespace IPC { -class Message; -} - -class DevToolsWindow; -class TabContentsWrapper; - -// Describes interface for managing devtools clients from browser process. There -// are currently two types of clients: devtools windows and TCP socket -// debuggers. -class DevToolsClientHost { - public: - class CloseListener { - public: - CloseListener() {} - virtual ~CloseListener() {} - virtual void ClientHostClosing(DevToolsClientHost* host) = 0; - private: - DISALLOW_COPY_AND_ASSIGN(CloseListener); - }; - - virtual ~DevToolsClientHost() {} - - // This method is called when tab inspected by this devtools client is - // closing. - virtual void InspectedTabClosing() = 0; - - // This method is called when tab inspected by this devtools client is - // navigating to |url|. - virtual void FrameNavigating(const std::string& url) = 0; - - // Sends the message to the devtools client hosted by this object. - virtual void SendMessageToClient(const IPC::Message& msg) = 0; - - void set_close_listener(CloseListener* listener) { - close_listener_ = listener; - } - - virtual DevToolsWindow* AsDevToolsWindow(); - - // Invoked when a tab is replaced by another tab. This is triggered by - // TabStripModel::ReplaceTabContentsAt. - virtual void TabReplaced(TabContentsWrapper* new_tab) = 0; - - protected: - DevToolsClientHost() : close_listener_(NULL) {} - - // Should be called when the devtools client is going to die and this - // DevToolsClientHost should not be used anymore. - void NotifyCloseListener(); - - private: - CloseListener* close_listener_; - DISALLOW_COPY_AND_ASSIGN(DevToolsClientHost); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_CLIENT_HOST_H_ diff --git a/chrome/browser/debugger/devtools_file_util.cc b/chrome/browser/debugger/devtools_file_util.cc deleted file mode 100644 index 1e4217d..0000000 --- a/chrome/browser/debugger/devtools_file_util.cc +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) 2011 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/devtools_file_util.h" - -#include "base/file_util.h" -#include "base/memory/ref_counted.h" - -#include "chrome/browser/browser_process.h" -#include "chrome/browser/download/download_prefs.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/shell_dialogs.h" - -namespace { - -class SaveAsDialog : public SelectFileDialog::Listener, - public base::RefCounted<SaveAsDialog> { - public: - SaveAsDialog() { - select_file_dialog_ = SelectFileDialog::Create(this); - } - - void Show(Profile* profile, - const std::string& suggested_file_name, - const std::string& content) { - AddRef(); // Balanced in the three listener outcomes. - - content_ = content; - - FilePath default_path; - - std::string file_name; - if (suggested_file_name.length() > 20) - file_name = suggested_file_name.substr(0, 20); - else - file_name = suggested_file_name; - - if (!last_save_path_.empty()) { - default_path = last_save_path_.DirName().AppendASCII(suggested_file_name); - } else { - DownloadPrefs prefs(profile->GetPrefs()); - default_path = prefs.download_path().AppendASCII(suggested_file_name); - } - - select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, - string16(), - default_path, - NULL, - 0, - FILE_PATH_LITERAL(""), - NULL, - NULL, - NULL); - } - - // SelectFileDialog::Listener implementation. - virtual void FileSelected(const FilePath& path, - int index, void* params) { - last_save_path_ = path; - - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - NewRunnableFunction( - &SaveAsDialog::WriteFile, - path, - content_)); - Release(); // Balanced in ::Show. - } - - virtual void MultiFilesSelected( - const std::vector<FilePath>& files, void* params) { - Release(); // Balanced in ::Show. - NOTREACHED() << "Should not be able to select multiple files"; - } - - virtual void FileSelectionCanceled(void* params) { - Release(); // Balanced in ::Show. - } - - private: - friend class base::RefCounted<SaveAsDialog>; - virtual ~SaveAsDialog() {} - - static void WriteFile(FilePath path, const std::string& content) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - DCHECK(!path.empty()); - - file_util::WriteFile(path, content.c_str(), content.length()); - } - scoped_refptr<SelectFileDialog> select_file_dialog_; - static FilePath last_save_path_; - std::string content_; -}; - -// static -FilePath SaveAsDialog::last_save_path_; - -} // namespace - -// static -void DevToolsFileUtil::SaveAs(Profile* profile, - const std::string& suggested_file_name, - const std::string& content) { - scoped_refptr<SaveAsDialog> dialog = new SaveAsDialog(); - dialog->Show(profile, suggested_file_name, content); -} diff --git a/chrome/browser/debugger/devtools_file_util.h b/chrome/browser/debugger/devtools_file_util.h deleted file mode 100644 index a70c8af..0000000 --- a/chrome/browser/debugger/devtools_file_util.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2011 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_DEVTOOLS_FILE_UTIL_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_FILE_UTIL_H_ -#pragma once - -#include <string> - -#include "base/basictypes.h" - -class Profile; - -class DevToolsFileUtil { - public: - - // Shows Save As dialog using default save location from the |profile| prefs, - // |suggested_file_name| as the default name and saves |content| to the given - // location. - static void SaveAs(Profile* profile, - const std::string& suggested_file_name, - const std::string& content); - - private: - DISALLOW_COPY_AND_ASSIGN(DevToolsFileUtil); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_FILE_UTIL_H_ diff --git a/chrome/browser/debugger/devtools_handler.cc b/chrome/browser/debugger/devtools_handler.cc deleted file mode 100644 index 3627954..0000000 --- a/chrome/browser/debugger/devtools_handler.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2011 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/devtools_handler.h" - -#include "chrome/browser/debugger/devtools_file_util.h" -#include "chrome/browser/debugger/devtools_manager.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/common/devtools_messages.h" - -DevToolsHandler::DevToolsHandler(RenderViewHost* render_view_host) - : RenderViewHostObserver(render_view_host) { -} - -DevToolsHandler::~DevToolsHandler() { -} - -bool DevToolsHandler::OnMessageReceived(const IPC::Message& message) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(DevToolsHandler, message) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_ForwardToAgent, OnForwardToAgent) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_ForwardToClient, OnForwardToClient) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_ActivateWindow, OnActivateWindow) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_CloseWindow, OnCloseWindow) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_RequestDockWindow, OnRequestDockWindow) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_RequestUndockWindow, - OnRequestUndockWindow) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAs, - OnSaveAs) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_RuntimePropertyChanged, - OnRuntimePropertyChanged) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void DevToolsHandler::OnForwardToAgent(const IPC::Message& message) { - DevToolsManager::GetInstance()->ForwardToDevToolsAgent( - render_view_host(), message); -} - -void DevToolsHandler::OnForwardToClient(const IPC::Message& message) { - DevToolsManager::GetInstance()->ForwardToDevToolsClient( - render_view_host(), message); -} - -void DevToolsHandler::OnActivateWindow() { - DevToolsManager::GetInstance()->ActivateWindow(render_view_host()); -} - -void DevToolsHandler::OnCloseWindow() { - DevToolsManager::GetInstance()->CloseWindow(render_view_host()); -} - -void DevToolsHandler::OnRequestDockWindow() { - DevToolsManager::GetInstance()->RequestDockWindow(render_view_host()); -} - -void DevToolsHandler::OnRequestUndockWindow() { - DevToolsManager::GetInstance()->RequestUndockWindow(render_view_host()); -} - -void DevToolsHandler::OnSaveAs(const std::string& file_name, - const std::string& content) { - TabContents* tab_contents = render_view_host()->delegate() ? - render_view_host()->delegate()->GetAsTabContents() : NULL; - DCHECK(tab_contents); - if (!tab_contents) - return; - - DevToolsFileUtil::SaveAs(tab_contents->profile(), file_name, content); -} - -void DevToolsHandler::OnRuntimePropertyChanged(const std::string& name, - const std::string& value) { - DevToolsManager::GetInstance()->RuntimePropertyChanged( - render_view_host(), name, value); -} diff --git a/chrome/browser/debugger/devtools_handler.h b/chrome/browser/debugger/devtools_handler.h deleted file mode 100644 index fbc93ec..0000000 --- a/chrome/browser/debugger/devtools_handler.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2011 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_DEVTOOLS_HANDLER_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_HANDLER_H_ -#pragma once - -#include "content/browser/renderer_host/render_view_host_observer.h" - -class DevToolsHandler : public RenderViewHostObserver { - public: - explicit DevToolsHandler(RenderViewHost* render_view_host); - virtual ~DevToolsHandler(); - - // RenderViewHostObserver overrides. - virtual bool OnMessageReceived(const IPC::Message& message); - - private: - void OnForwardToAgent(const IPC::Message& message); - void OnForwardToClient(const IPC::Message& message); - void OnActivateWindow(); - void OnCloseWindow(); - void OnRequestDockWindow(); - void OnRequestUndockWindow(); - void OnSaveAs(const std::string& file_name, - const std::string& content); - void OnRuntimePropertyChanged(const std::string& name, - const std::string& value); - - DISALLOW_COPY_AND_ASSIGN(DevToolsHandler); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_HANDLER_H_ diff --git a/chrome/browser/debugger/devtools_http_protocol_handler.cc b/chrome/browser/debugger/devtools_http_protocol_handler.cc deleted file mode 100644 index 1c67f8d..0000000 --- a/chrome/browser/debugger/devtools_http_protocol_handler.cc +++ /dev/null @@ -1,531 +0,0 @@ -// Copyright (c) 2011 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/devtools_http_protocol_handler.h" - -#include <utility> - -#include "base/compiler_specific.h" -#include "base/json/json_writer.h" -#include "base/logging.h" -#include "base/message_loop_proxy.h" -#include "base/stringprintf.h" -#include "base/string_number_conversions.h" -#include "base/threading/thread.h" -#include "base/utf_string_conversions.h" -#include "base/values.h" -#include "chrome/browser/debugger/devtools_client_host.h" -#include "chrome/browser/debugger/devtools_manager.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sessions/restore_tab_helper.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/browser/ui/webui/devtools_ui.h" -#include "content/browser/browser_thread.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/common/devtools_messages.h" -#include "grit/devtools_frontend_resources.h" -#include "googleurl/src/gurl.h" -#include "net/base/escape.h" -#include "net/base/io_buffer.h" -#include "net/server/http_server_request_info.h" -#include "net/url_request/url_request_context.h" -#include "net/url_request/url_request_context_getter.h" -#include "ui/base/resource/resource_bundle.h" - -const int kBufferSize = 16 * 1024; - -namespace { - -// An internal implementation of DevToolsClientHost that delegates -// messages sent for DevToolsClient to a DebuggerShell instance. -class DevToolsClientHostImpl : public DevToolsClientHost { - public: - DevToolsClientHostImpl( - net::HttpServer* server, - int connection_id) - : server_(server), - connection_id_(connection_id) { - } - ~DevToolsClientHostImpl() {} - - // DevToolsClientHost interface - virtual void InspectedTabClosing() { - BrowserThread::PostTask( - BrowserThread::IO, - FROM_HERE, - NewRunnableMethod(server_, - &net::HttpServer::Close, - connection_id_)); - } - - virtual void SendMessageToClient(const IPC::Message& msg) { - IPC_BEGIN_MESSAGE_MAP(DevToolsClientHostImpl, msg) - IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, - OnDispatchOnInspectorFrontend); - IPC_MESSAGE_UNHANDLED_ERROR() - IPC_END_MESSAGE_MAP() - } - - virtual void TabReplaced(TabContentsWrapper* new_tab) { - } - - void NotifyCloseListener() { - DevToolsClientHost::NotifyCloseListener(); - } - private: - // Message handling routines - void OnDispatchOnInspectorFrontend(const std::string& data) { - BrowserThread::PostTask( - BrowserThread::IO, - FROM_HERE, - NewRunnableMethod(server_, - &net::HttpServer::SendOverWebSocket, - connection_id_, - data)); - } - - virtual void FrameNavigating(const std::string& url) {} - net::HttpServer* server_; - int connection_id_; -}; - -} // namespace - - -// static -scoped_refptr<DevToolsHttpProtocolHandler> DevToolsHttpProtocolHandler::Start( - const std::string& ip, - int port, - const std::string& frontend_url, - TabContentsProvider* provider) { - scoped_refptr<DevToolsHttpProtocolHandler> http_handler = - new DevToolsHttpProtocolHandler(ip, port, frontend_url, provider); - http_handler->Start(); - return http_handler; -} - -DevToolsHttpProtocolHandler::~DevToolsHttpProtocolHandler() { - // Stop() must be called prior to this being called - DCHECK(server_.get() == NULL); -} - -void DevToolsHttpProtocolHandler::Start() { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, &DevToolsHttpProtocolHandler::Init)); -} - -void DevToolsHttpProtocolHandler::Stop() { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, &DevToolsHttpProtocolHandler::Teardown)); -} - -void DevToolsHttpProtocolHandler::OnHttpRequest( - int connection_id, - const net::HttpServerRequestInfo& info) { - if (info.path == "/json") { - // Pages discovery json request. - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - NewRunnableMethod(this, - &DevToolsHttpProtocolHandler::OnJsonRequestUI, - connection_id, - info)); - return; - } - - // Proxy static files from chrome-devtools://devtools/*. - if (!Profile::GetDefaultRequestContext()) { - server_->Send404(connection_id); - return; - } - - if (info.path == "" || info.path == "/") { - const base::StringPiece frontend_html( - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_DEVTOOLS_FRONTEND_HTML)); - std::string response(frontend_html.data(), frontend_html.length()); - server_->Send200(connection_id, response, "text/html; charset=UTF-8"); - return; - } - - net::URLRequest* request; - - if (info.path.find("/devtools/") == 0) { - request = new net::URLRequest(GURL("chrome-devtools:/" + info.path), this); - } else if (info.path.find("/thumb/") == 0) { - request = new net::URLRequest(GURL("chrome:/" + info.path), this); - } else { - server_->Send404(connection_id); - return; - } - - // Make sure DevTools data source is registered. - DevToolsUI::RegisterDevToolsDataSource(); - Bind(request, connection_id); - request->set_context( - Profile::GetDefaultRequestContext()->GetURLRequestContext()); - request->Start(); -} - -void DevToolsHttpProtocolHandler::OnWebSocketRequest( - int connection_id, - const net::HttpServerRequestInfo& request) { - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - NewRunnableMethod( - this, - &DevToolsHttpProtocolHandler::OnWebSocketRequestUI, - connection_id, - request)); -} - -void DevToolsHttpProtocolHandler::OnWebSocketMessage( - int connection_id, - const std::string& data) { - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - NewRunnableMethod( - this, - &DevToolsHttpProtocolHandler::OnWebSocketMessageUI, - connection_id, - data)); -} - -void DevToolsHttpProtocolHandler::OnClose(int connection_id) { - ConnectionToRequestsMap::iterator it = - connection_to_requests_io_.find(connection_id); - if (it != connection_to_requests_io_.end()) { - // Dispose delegating socket. - for (std::set<net::URLRequest*>::iterator it2 = it->second.begin(); - it2 != it->second.end(); ++it2) { - net::URLRequest* request = *it2; - request->Cancel(); - request_to_connection_io_.erase(request); - request_to_buffer_io_.erase(request); - delete request; - } - connection_to_requests_io_.erase(connection_id); - } - - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - NewRunnableMethod( - this, - &DevToolsHttpProtocolHandler::OnCloseUI, - connection_id)); -} - -struct PageInfo -{ - int id; - std::string url; - bool attached; - std::string title; - std::string thumbnail_url; - std::string favicon_url; -}; -typedef std::vector<PageInfo> PageList; - -static PageList GeneratePageList( - DevToolsHttpProtocolHandler::TabContentsProvider* tab_contents_provider, - int connection_id, - const net::HttpServerRequestInfo& info) { - typedef DevToolsHttpProtocolHandler::InspectableTabs Tabs; - Tabs inspectable_tabs = tab_contents_provider->GetInspectableTabs(); - - PageList page_list; - for (Tabs::iterator it = inspectable_tabs.begin(); - it != inspectable_tabs.end(); ++it) { - - TabContentsWrapper* tab_contents = *it; - NavigationController& controller = tab_contents->controller(); - - NavigationEntry* entry = controller.GetActiveEntry(); - if (entry == NULL || !entry->url().is_valid()) - continue; - - DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> - GetDevToolsClientHostFor(tab_contents->tab_contents()-> - render_view_host()); - PageInfo page_info; - page_info.id = tab_contents->restore_tab_helper()->session_id().id(); - page_info.attached = client_host != NULL; - page_info.url = entry->url().spec(); - page_info.title = UTF16ToUTF8(EscapeForHTML(entry->title())); - page_info.thumbnail_url = "/thumb/" + entry->url().spec(); - page_info.favicon_url = entry->favicon().url().spec(); - page_list.push_back(page_info); - } - return page_list; -} - -void DevToolsHttpProtocolHandler::OnJsonRequestUI( - int connection_id, - const net::HttpServerRequestInfo& info) { - PageList page_list = GeneratePageList(tab_contents_provider_.get(), - connection_id, info); - ListValue json_pages_list; - std::string host = info.headers["Host"]; - for (PageList::iterator i = page_list.begin(); - i != page_list.end(); ++i) { - - DictionaryValue* page_info = new DictionaryValue; - json_pages_list.Append(page_info); - page_info->SetString("title", i->title); - page_info->SetString("url", i->url); - page_info->SetString("thumbnailUrl", i->thumbnail_url); - page_info->SetString("faviconUrl", i->favicon_url); - if (!i->attached) { - page_info->SetString("webSocketDebuggerUrl", - StringPrintf("ws://%s/devtools/page/%d", - host.c_str(), - i->id)); - page_info->SetString("devtoolsFrontendUrl", - StringPrintf("%s?host=%s&page=%d", - overridden_frontend_url_.c_str(), - host.c_str(), - i->id)); - } - } - - std::string response; - base::JSONWriter::Write(&json_pages_list, true, &response); - Send200(connection_id, response, "application/json; charset=UTF-8"); -} - -void DevToolsHttpProtocolHandler::OnWebSocketRequestUI( - int connection_id, - const net::HttpServerRequestInfo& request) { - std::string prefix = "/devtools/page/"; - size_t pos = request.path.find(prefix); - if (pos != 0) { - Send404(connection_id); - return; - } - std::string page_id = request.path.substr(prefix.length()); - int id = 0; - if (!base::StringToInt(page_id, &id)) { - Send500(connection_id, "Invalid page id: " + page_id); - return; - } - - TabContents* tab_contents = GetTabContents(id); - if (tab_contents == NULL) { - Send500(connection_id, "No such page id: " + page_id); - return; - } - - DevToolsManager* manager = DevToolsManager::GetInstance(); - if (manager->GetDevToolsClientHostFor(tab_contents->render_view_host())) { - Send500(connection_id, "Page with given id is being inspected: " + page_id); - return; - } - - DevToolsClientHostImpl* client_host = - new DevToolsClientHostImpl(server_, connection_id); - connection_to_client_host_ui_[connection_id] = client_host; - - manager->RegisterDevToolsClientHostFor( - tab_contents->render_view_host(), - client_host); - manager->ForwardToDevToolsAgent( - client_host, - DevToolsAgentMsg_FrontendLoaded()); - - AcceptWebSocket(connection_id, request); -} - -void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( - int connection_id, - const std::string& data) { - ConnectionToClientHostMap::iterator it = - connection_to_client_host_ui_.find(connection_id); - if (it == connection_to_client_host_ui_.end()) - return; - - DevToolsManager* manager = DevToolsManager::GetInstance(); - manager->ForwardToDevToolsAgent( - it->second, - DevToolsAgentMsg_DispatchOnInspectorBackend(data)); -} - -void DevToolsHttpProtocolHandler::OnCloseUI(int connection_id) { - ConnectionToClientHostMap::iterator it = - connection_to_client_host_ui_.find(connection_id); - if (it != connection_to_client_host_ui_.end()) { - DevToolsClientHostImpl* client_host = - static_cast<DevToolsClientHostImpl*>(it->second); - client_host->NotifyCloseListener(); - delete client_host; - connection_to_client_host_ui_.erase(connection_id); - } -} - -void DevToolsHttpProtocolHandler::OnResponseStarted(net::URLRequest* request) { - RequestToSocketMap::iterator it = request_to_connection_io_.find(request); - if (it == request_to_connection_io_.end()) - return; - - int connection_id = it->second; - - std::string content_type; - request->GetMimeType(&content_type); - - if (request->status().is_success()) { - server_->Send(connection_id, StringPrintf("HTTP/1.1 200 OK\r\n" - "Content-Type:%s\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n", - content_type.c_str())); - } else { - server_->Send404(connection_id); - } - - int bytes_read = 0; - // Some servers may treat HEAD requests as GET requests. To free up the - // network connection as soon as possible, signal that the request has - // completed immediately, without trying to read any data back (all we care - // about is the response code and headers, which we already have). - net::IOBuffer* buffer = request_to_buffer_io_[request].get(); - if (request->status().is_success()) - request->Read(buffer, kBufferSize, &bytes_read); - OnReadCompleted(request, bytes_read); -} - -void DevToolsHttpProtocolHandler::OnReadCompleted(net::URLRequest* request, - int bytes_read) { - RequestToSocketMap::iterator it = request_to_connection_io_.find(request); - if (it == request_to_connection_io_.end()) - return; - - int connection_id = it->second; - - net::IOBuffer* buffer = request_to_buffer_io_[request].get(); - do { - if (!request->status().is_success() || bytes_read <= 0) - break; - std::string chunk_size = StringPrintf("%X\r\n", bytes_read); - server_->Send(connection_id, chunk_size); - server_->Send(connection_id, buffer->data(), bytes_read); - server_->Send(connection_id, "\r\n"); - } while (request->Read(buffer, kBufferSize, &bytes_read)); - - - // See comments re: HEAD requests in OnResponseStarted(). - if (!request->status().is_io_pending()) { - server_->Send(connection_id, "0\r\n\r\n"); - RequestCompleted(request); - } -} - -DevToolsHttpProtocolHandler::DevToolsHttpProtocolHandler( - const std::string& ip, - int port, - const std::string& frontend_host, - TabContentsProvider* provider) - : ip_(ip), - port_(port), - overridden_frontend_url_(frontend_host), - tab_contents_provider_(provider) { - if (overridden_frontend_url_.empty()) - overridden_frontend_url_ = "/devtools/devtools.html"; -} - -void DevToolsHttpProtocolHandler::Init() { - server_ = new net::HttpServer(ip_, port_, this); -} - -// Run on I/O thread -void DevToolsHttpProtocolHandler::Teardown() { - server_ = NULL; -} - -void DevToolsHttpProtocolHandler::Bind(net::URLRequest* request, - int connection_id) { - request_to_connection_io_[request] = connection_id; - ConnectionToRequestsMap::iterator it = - connection_to_requests_io_.find(connection_id); - if (it == connection_to_requests_io_.end()) { - std::pair<int, std::set<net::URLRequest*> > value( - connection_id, - std::set<net::URLRequest*>()); - it = connection_to_requests_io_.insert(value).first; - } - it->second.insert(request); - request_to_buffer_io_[request] = new net::IOBuffer(kBufferSize); -} - -void DevToolsHttpProtocolHandler::RequestCompleted(net::URLRequest* request) { - RequestToSocketMap::iterator it = request_to_connection_io_.find(request); - if (it == request_to_connection_io_.end()) - return; - - int connection_id = it->second; - request_to_connection_io_.erase(request); - ConnectionToRequestsMap::iterator it2 = - connection_to_requests_io_.find(connection_id); - it2->second.erase(request); - request_to_buffer_io_.erase(request); - delete request; -} - -void DevToolsHttpProtocolHandler::Send200(int connection_id, - const std::string& data, - const std::string& mime_type) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(server_.get(), - &net::HttpServer::Send200, - connection_id, - data, - mime_type)); -} - -void DevToolsHttpProtocolHandler::Send404(int connection_id) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(server_.get(), - &net::HttpServer::Send404, - connection_id)); -} - -void DevToolsHttpProtocolHandler::Send500(int connection_id, - const std::string& message) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(server_.get(), - &net::HttpServer::Send500, - connection_id, - message)); -} - -void DevToolsHttpProtocolHandler::AcceptWebSocket( - int connection_id, - const net::HttpServerRequestInfo& request) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(server_.get(), - &net::HttpServer::AcceptWebSocket, - connection_id, - request)); -} - -TabContents* DevToolsHttpProtocolHandler::GetTabContents(int session_id) { - InspectableTabs inspectable_tabs = - tab_contents_provider_->GetInspectableTabs(); - - for (InspectableTabs::iterator it = inspectable_tabs.begin(); - it != inspectable_tabs.end(); ++it) { - TabContentsWrapper* tab = *it; - if (tab->restore_tab_helper()->session_id().id() == session_id) - return tab->tab_contents(); - } - return NULL; -} diff --git a/chrome/browser/debugger/devtools_http_protocol_handler.h b/chrome/browser/debugger/devtools_http_protocol_handler.h deleted file mode 100644 index dcbdb3b..0000000 --- a/chrome/browser/debugger/devtools_http_protocol_handler.h +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) 2011 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_DEVTOOLS_HTTP_PROTOCOL_HANDLER_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_HTTP_PROTOCOL_HANDLER_H_ -#pragma once - -#include <set> -#include <string> -#include <vector> - -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "net/server/http_server.h" -#include "net/url_request/url_request.h" - -class DevToolsClientHost; -class DevToolsHttpServer; -class TabContents; -class TabContentsWrapper; - -class DevToolsHttpProtocolHandler - : public net::HttpServer::Delegate, - public net::URLRequest::Delegate, - public base::RefCountedThreadSafe<DevToolsHttpProtocolHandler> { - public: - typedef std::vector<TabContentsWrapper*> InspectableTabs; - class TabContentsProvider { - public: - TabContentsProvider() {} - virtual ~TabContentsProvider() {} - virtual InspectableTabs GetInspectableTabs() = 0; - private: - DISALLOW_COPY_AND_ASSIGN(TabContentsProvider); - }; - - // Takes ownership over |provider|. - static scoped_refptr<DevToolsHttpProtocolHandler> Start( - const std::string& ip, - int port, - const std::string& frontend_url, - TabContentsProvider* provider); - - // Called from the main thread in order to stop protocol handler. - // Will schedule tear down task on IO thread. - void Stop(); - - private: - friend class base::RefCountedThreadSafe<DevToolsHttpProtocolHandler>; - - DevToolsHttpProtocolHandler(const std::string& ip, - int port, - const std::string& frontend_url, - TabContentsProvider* provider); - virtual ~DevToolsHttpProtocolHandler(); - void Start(); - - // net::HttpServer::Delegate implementation. - virtual void OnHttpRequest(int connection_id, - const net::HttpServerRequestInfo& info); - virtual void OnWebSocketRequest(int connection_id, - const net::HttpServerRequestInfo& info); - virtual void OnWebSocketMessage(int connection_id, - const std::string& data); - virtual void OnClose(int connection_id); - - virtual void OnJsonRequestUI(int connection_id, - const net::HttpServerRequestInfo& info); - virtual void OnWebSocketRequestUI(int connection_id, - const net::HttpServerRequestInfo& info); - virtual void OnWebSocketMessageUI(int connection_id, - const std::string& data); - virtual void OnCloseUI(int connection_id); - - // net::URLRequest::Delegate implementation. - virtual void OnResponseStarted(net::URLRequest* request); - virtual void OnReadCompleted(net::URLRequest* request, int bytes_read); - - void Init(); - void Teardown(); - void Bind(net::URLRequest* request, int connection_id); - void RequestCompleted(net::URLRequest* request); - - void Send200(int connection_id, - const std::string& data, - const std::string& mime_type = "text/html"); - void Send404(int connection_id); - void Send500(int connection_id, - const std::string& message); - void AcceptWebSocket(int connection_id, - const net::HttpServerRequestInfo& request); - - TabContents* GetTabContents(int session_id); - - std::string ip_; - int port_; - std::string overridden_frontend_url_; - scoped_refptr<net::HttpServer> server_; - typedef std::map<net::URLRequest*, int> - RequestToSocketMap; - RequestToSocketMap request_to_connection_io_; - typedef std::map<int, std::set<net::URLRequest*> > - ConnectionToRequestsMap; - ConnectionToRequestsMap connection_to_requests_io_; - typedef std::map<net::URLRequest*, scoped_refptr<net::IOBuffer> > - BuffersMap; - BuffersMap request_to_buffer_io_; - typedef std::map<int, DevToolsClientHost*> - ConnectionToClientHostMap; - ConnectionToClientHostMap connection_to_client_host_ui_; - scoped_ptr<TabContentsProvider> tab_contents_provider_; - DISALLOW_COPY_AND_ASSIGN(DevToolsHttpProtocolHandler); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_HTTP_PROTOCOL_HANDLER_H_ diff --git a/chrome/browser/debugger/devtools_manager.cc b/chrome/browser/debugger/devtools_manager.cc deleted file mode 100644 index 0f4180b..0000000 --- a/chrome/browser/debugger/devtools_manager.cc +++ /dev/null @@ -1,466 +0,0 @@ -// Copyright (c) 2011 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/devtools_manager.h" - -#include <vector> - -#include "base/auto_reset.h" -#include "base/message_loop.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/debugger/devtools_client_host.h" -#include "chrome/browser/debugger/devtools_netlog_observer.h" -#include "chrome/browser/debugger/devtools_window.h" -#include "chrome/browser/io_thread.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/pref_names.h" -#include "content/browser/browsing_instance.h" -#include "content/browser/child_process_security_policy.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/site_instance.h" -#include "content/common/devtools_messages.h" -#include "content/common/notification_service.h" -#include "googleurl/src/gurl.h" - -// static -DevToolsManager* DevToolsManager::GetInstance() { - // http://crbug.com/47806 this method may be called when BrowserProcess - // has already been destroyed. - if (!g_browser_process) - return NULL; - return g_browser_process->devtools_manager(); -} - -// static -void DevToolsManager::RegisterUserPrefs(PrefService* prefs) { - prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked, - true, - PrefService::UNSYNCABLE_PREF); -} - -DevToolsManager::DevToolsManager() - : inspected_rvh_for_reopen_(NULL), - in_initial_show_(false), - last_orphan_cookie_(0) { - registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED, - NotificationService::AllSources()); -} - -DevToolsManager::~DevToolsManager() { - DCHECK(inspected_rvh_to_client_host_.empty()); - DCHECK(client_host_to_inspected_rvh_.empty()); - // By the time we destroy devtools manager, all orphan client hosts should - // have been delelted, no need to notify them upon tab closing. - DCHECK(orphan_client_hosts_.empty()); -} - -DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( - RenderViewHost* inspected_rvh) { - InspectedRvhToClientHostMap::iterator it = - inspected_rvh_to_client_host_.find(inspected_rvh); - if (it != inspected_rvh_to_client_host_.end()) - return it->second; - return NULL; -} - -void DevToolsManager::RegisterDevToolsClientHostFor( - RenderViewHost* inspected_rvh, - DevToolsClientHost* client_host) { - DCHECK(!GetDevToolsClientHostFor(inspected_rvh)); - - DevToolsRuntimeProperties initial_properties; - BindClientHost(inspected_rvh, client_host, initial_properties); - client_host->set_close_listener(this); - SendAttachToAgent(inspected_rvh); -} - -void DevToolsManager::ForwardToDevToolsAgent( - RenderViewHost* client_rvh, - const IPC::Message& message) { - DevToolsClientHost* client_host = FindOwnerDevToolsClientHost(client_rvh); - if (client_host) - ForwardToDevToolsAgent(client_host, message); -} - -void DevToolsManager::ForwardToDevToolsAgent(DevToolsClientHost* from, - const IPC::Message& message) { - RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(from); - if (!inspected_rvh) { - // TODO(yurys): notify client that the agent is no longer available - NOTREACHED(); - return; - } - - IPC::Message* m = new IPC::Message(message); - m->set_routing_id(inspected_rvh->routing_id()); - inspected_rvh->Send(m); -} - -void DevToolsManager::ForwardToDevToolsClient(RenderViewHost* inspected_rvh, - const IPC::Message& message) { - DevToolsClientHost* client_host = GetDevToolsClientHostFor(inspected_rvh); - if (!client_host) { - // Client window was closed while there were messages - // being sent to it. - return; - } - client_host->SendMessageToClient(message); -} - -void DevToolsManager::ActivateWindow(RenderViewHost* client_rvh) { - DevToolsClientHost* client_host = FindOwnerDevToolsClientHost(client_rvh); - if (!client_host) - return; - - DevToolsWindow* window = client_host->AsDevToolsWindow(); - DCHECK(window); - window->Activate(); -} - -void DevToolsManager::CloseWindow(RenderViewHost* client_rvh) { - DevToolsClientHost* client_host = FindOwnerDevToolsClientHost(client_rvh); - if (client_host) { - RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(client_host); - DCHECK(inspected_rvh); - UnregisterDevToolsClientHostFor(inspected_rvh); - } -} - -void DevToolsManager::RequestDockWindow(RenderViewHost* client_rvh) { - ReopenWindow(client_rvh, true); -} - -void DevToolsManager::RequestUndockWindow(RenderViewHost* client_rvh) { - ReopenWindow(client_rvh, false); -} - -void DevToolsManager::OpenDevToolsWindow(RenderViewHost* inspected_rvh) { - ToggleDevToolsWindow( - inspected_rvh, - true, - DEVTOOLS_TOGGLE_ACTION_NONE); -} - -void DevToolsManager::ToggleDevToolsWindow( - RenderViewHost* inspected_rvh, - DevToolsToggleAction action) { - ToggleDevToolsWindow(inspected_rvh, false, action); -} - -void DevToolsManager::RuntimePropertyChanged(RenderViewHost* inspected_rvh, - const std::string& name, - const std::string& value) { - RuntimePropertiesMap::iterator it = - runtime_properties_map_.find(inspected_rvh); - if (it == runtime_properties_map_.end()) { - std::pair<RenderViewHost*, DevToolsRuntimeProperties> value( - inspected_rvh, - DevToolsRuntimeProperties()); - it = runtime_properties_map_.insert(value).first; - } - it->second[name] = value; -} - -void DevToolsManager::InspectElement(RenderViewHost* inspected_rvh, - int x, - int y) { - IPC::Message* m = new DevToolsAgentMsg_InspectElement(x, y); - m->set_routing_id(inspected_rvh->routing_id()); - inspected_rvh->Send(m); - // TODO(loislo): we should initiate DevTools window opening from within - // renderer. Otherwise, we still can hit a race condition here. - OpenDevToolsWindow(inspected_rvh); -} - -void DevToolsManager::ClientHostClosing(DevToolsClientHost* host) { - RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(host); - if (!inspected_rvh) { - // It might be in the list of orphan client hosts, remove it from there. - for (OrphanClientHosts::iterator it = orphan_client_hosts_.begin(); - it != orphan_client_hosts_.end(); ++it) { - if (it->second.first == host) { - orphan_client_hosts_.erase(it->first); - return; - } - } - return; - } - - NotificationService::current()->Notify( - NotificationType::DEVTOOLS_WINDOW_CLOSING, - Source<Profile>(inspected_rvh->site_instance()->GetProcess()->profile()), - Details<RenderViewHost>(inspected_rvh)); - - UnbindClientHost(inspected_rvh, host); -} - -void DevToolsManager::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - DCHECK(type == NotificationType::RENDER_VIEW_HOST_DELETED); - UnregisterDevToolsClientHostFor(Source<RenderViewHost>(source).ptr()); -} - -RenderViewHost* DevToolsManager::GetInspectedRenderViewHost( - DevToolsClientHost* client_host) { - ClientHostToInspectedRvhMap::iterator it = - client_host_to_inspected_rvh_.find(client_host); - if (it != client_host_to_inspected_rvh_.end()) - return it->second; - return NULL; -} - -void DevToolsManager::UnregisterDevToolsClientHostFor( - RenderViewHost* inspected_rvh) { - DevToolsClientHost* host = GetDevToolsClientHostFor(inspected_rvh); - if (!host) - return; - UnbindClientHost(inspected_rvh, host); - host->InspectedTabClosing(); -} - -void DevToolsManager::OnNavigatingToPendingEntry(RenderViewHost* rvh, - RenderViewHost* dest_rvh, - const GURL& gurl) { - if (in_initial_show_) { - // Mute this even in case it is caused by the initial show routines. - return; - } - - int cookie = DetachClientHost(rvh); - if (cookie != -1) { - // Navigating to URL in the inspected window. - AttachClientHost(cookie, dest_rvh); - - DevToolsClientHost* client_host = GetDevToolsClientHostFor(dest_rvh); - client_host->FrameNavigating(gurl.spec()); - - return; - } - - // Iterate over client hosts and if there is one that has render view host - // changing, reopen entire client window (this must be caused by the user - // manually refreshing its content). - for (ClientHostToInspectedRvhMap::iterator it = - client_host_to_inspected_rvh_.begin(); - it != client_host_to_inspected_rvh_.end(); ++it) { - DevToolsWindow* window = it->first->AsDevToolsWindow(); - if (window && window->GetRenderViewHost() == rvh) { - inspected_rvh_for_reopen_ = it->second; - MessageLoop::current()->PostTask(FROM_HERE, - NewRunnableMethod(this, - &DevToolsManager::ForceReopenWindow)); - return; - } - } -} - -void DevToolsManager::TabReplaced(TabContentsWrapper* old_tab, - TabContentsWrapper* new_tab) { - RenderViewHost* old_rvh = old_tab->tab_contents()->render_view_host(); - DevToolsClientHost* client_host = GetDevToolsClientHostFor(old_rvh); - if (!client_host) - return; // Didn't know about old_tab. - int cookie = DetachClientHost(old_rvh); - if (cookie == -1) - return; // Didn't know about old_tab. - - client_host->TabReplaced(new_tab); - AttachClientHost(cookie, new_tab->tab_contents()->render_view_host()); -} - -int DevToolsManager::DetachClientHost(RenderViewHost* from_rvh) { - DevToolsClientHost* client_host = GetDevToolsClientHostFor(from_rvh); - if (!client_host) - return -1; - - int cookie = last_orphan_cookie_++; - orphan_client_hosts_[cookie] = - std::pair<DevToolsClientHost*, DevToolsRuntimeProperties>( - client_host, runtime_properties_map_[from_rvh]); - - UnbindClientHost(from_rvh, client_host); - return cookie; -} - -void DevToolsManager::AttachClientHost(int client_host_cookie, - RenderViewHost* to_rvh) { - OrphanClientHosts::iterator it = orphan_client_hosts_.find( - client_host_cookie); - if (it == orphan_client_hosts_.end()) - return; - - DevToolsClientHost* client_host = (*it).second.first; - BindClientHost(to_rvh, client_host, (*it).second.second); - SendAttachToAgent(to_rvh); - - orphan_client_hosts_.erase(client_host_cookie); -} - -void DevToolsManager::SendAttachToAgent(RenderViewHost* inspected_rvh) { - if (inspected_rvh) { - ChildProcessSecurityPolicy::GetInstance()->GrantReadRawCookies( - inspected_rvh->process()->id()); - - DevToolsRuntimeProperties properties; - RuntimePropertiesMap::iterator it = - runtime_properties_map_.find(inspected_rvh); - if (it != runtime_properties_map_.end()) { - properties = DevToolsRuntimeProperties(it->second.begin(), - it->second.end()); - } - IPC::Message* m = new DevToolsAgentMsg_Attach(properties); - m->set_routing_id(inspected_rvh->routing_id()); - inspected_rvh->Send(m); - } -} - -void DevToolsManager::SendDetachToAgent(RenderViewHost* inspected_rvh) { - if (inspected_rvh) { - IPC::Message* m = new DevToolsAgentMsg_Detach(); - m->set_routing_id(inspected_rvh->routing_id()); - inspected_rvh->Send(m); - } -} - -void DevToolsManager::ForceReopenWindow() { - if (inspected_rvh_for_reopen_) { - RenderViewHost* inspected_rvn = inspected_rvh_for_reopen_; - UnregisterDevToolsClientHostFor(inspected_rvn); - OpenDevToolsWindow(inspected_rvn); - } -} - -DevToolsClientHost* DevToolsManager::FindOwnerDevToolsClientHost( - RenderViewHost* client_rvh) { - for (InspectedRvhToClientHostMap::iterator it = - inspected_rvh_to_client_host_.begin(); - it != inspected_rvh_to_client_host_.end(); - ++it) { - DevToolsWindow* win = it->second->AsDevToolsWindow(); - if (!win) - continue; - if (client_rvh == win->GetRenderViewHost()) - return it->second; - } - return NULL; -} - -void DevToolsManager::ReopenWindow(RenderViewHost* client_rvh, bool docked) { - DevToolsClientHost* client_host = FindOwnerDevToolsClientHost(client_rvh); - if (!client_host) - return; - RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(client_host); - DCHECK(inspected_rvh); - inspected_rvh->process()->profile()->GetPrefs()->SetBoolean( - prefs::kDevToolsOpenDocked, docked); - - DevToolsWindow* window = client_host->AsDevToolsWindow(); - DCHECK(window); - window->SetDocked(docked); -} - -void DevToolsManager::ToggleDevToolsWindow( - RenderViewHost* inspected_rvh, - bool force_open, - DevToolsToggleAction action) { - bool do_open = force_open; - DevToolsClientHost* host = GetDevToolsClientHostFor(inspected_rvh); - - if (host != NULL && host->AsDevToolsWindow() == NULL) { - // Break remote debugging / extension debugging session. - UnregisterDevToolsClientHostFor(inspected_rvh); - host = NULL; - } - - if (!host) { - bool docked = inspected_rvh->process()->profile()->GetPrefs()-> - GetBoolean(prefs::kDevToolsOpenDocked); - host = new DevToolsWindow( - inspected_rvh->site_instance()->browsing_instance()->profile(), - inspected_rvh, - docked); - RegisterDevToolsClientHostFor(inspected_rvh, host); - do_open = true; - } - - DevToolsWindow* window = host->AsDevToolsWindow(); - // If window is docked and visible, we hide it on toggle. If window is - // undocked, we show (activate) it. - if (!window->is_docked() || do_open) { - AutoReset<bool> auto_reset_in_initial_show(&in_initial_show_, true); - window->Show(action); - } else { - UnregisterDevToolsClientHostFor(inspected_rvh); - } -} - -void DevToolsManager::BindClientHost( - RenderViewHost* inspected_rvh, - DevToolsClientHost* client_host, - const DevToolsRuntimeProperties& runtime_properties) { - DCHECK(inspected_rvh_to_client_host_.find(inspected_rvh) == - inspected_rvh_to_client_host_.end()); - DCHECK(client_host_to_inspected_rvh_.find(client_host) == - client_host_to_inspected_rvh_.end()); - - if (client_host_to_inspected_rvh_.empty()) { - BrowserThread::PostTask( - BrowserThread::IO, - FROM_HERE, - NewRunnableFunction(&DevToolsNetLogObserver::Attach, - g_browser_process->io_thread())); - } - inspected_rvh_to_client_host_[inspected_rvh] = client_host; - client_host_to_inspected_rvh_[client_host] = inspected_rvh; - runtime_properties_map_[inspected_rvh] = runtime_properties; -} - -void DevToolsManager::UnbindClientHost(RenderViewHost* inspected_rvh, - DevToolsClientHost* client_host) { - DCHECK(inspected_rvh_to_client_host_.find(inspected_rvh)->second == - client_host); - DCHECK(client_host_to_inspected_rvh_.find(client_host)->second == - inspected_rvh); - - inspected_rvh_to_client_host_.erase(inspected_rvh); - client_host_to_inspected_rvh_.erase(client_host); - runtime_properties_map_.erase(inspected_rvh); - - if (client_host_to_inspected_rvh_.empty()) { - BrowserThread::PostTask( - BrowserThread::IO, - FROM_HERE, - NewRunnableFunction(&DevToolsNetLogObserver::Detach)); - } - SendDetachToAgent(inspected_rvh); - if (inspected_rvh_for_reopen_ == inspected_rvh) - inspected_rvh_for_reopen_ = NULL; - - int process_id = inspected_rvh->process()->id(); - for (InspectedRvhToClientHostMap::iterator it = - inspected_rvh_to_client_host_.begin(); - it != inspected_rvh_to_client_host_.end(); - ++it) { - if (it->first->process()->id() == process_id) - return; - } - // We've disconnected from the last renderer -> revoke cookie permissions. - ChildProcessSecurityPolicy::GetInstance()->RevokeReadRawCookies(process_id); -} - -void DevToolsManager::CloseAllClientHosts() { - std::vector<RenderViewHost*> rhvs; - for (InspectedRvhToClientHostMap::iterator it = - inspected_rvh_to_client_host_.begin(); - it != inspected_rvh_to_client_host_.end(); ++it) { - rhvs.push_back(it->first); - } - for (std::vector<RenderViewHost*>::iterator it = rhvs.begin(); - it != rhvs.end(); ++it) { - UnregisterDevToolsClientHostFor(*it); - } -} diff --git a/chrome/browser/debugger/devtools_manager.h b/chrome/browser/debugger/devtools_manager.h deleted file mode 100644 index ae44f76..0000000 --- a/chrome/browser/debugger/devtools_manager.h +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright (c) 2011 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_DEVTOOLS_MANAGER_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ -#pragma once - -#include <map> -#include <string> - -#include "base/memory/ref_counted.h" -#include "chrome/browser/debugger/devtools_client_host.h" -#include "chrome/browser/debugger/devtools_toggle_action.h" -#include "content/common/notification_observer.h" -#include "content/common/notification_registrar.h" -#include "webkit/glue/resource_loader_bridge.h" - -namespace IPC { -class Message; -} - -class DevToolsNetLogObserver; -class GURL; -class IOThread; -class PrefService; -class RenderViewHost; -class TabContentsWraper; - -using webkit_glue::ResourceLoaderBridge; - -typedef std::map<std::string, std::string> DevToolsRuntimeProperties; - -// This class is a singleton that manages DevToolsClientHost instances and -// routes messages between developer tools clients and agents. -class DevToolsManager : public DevToolsClientHost::CloseListener, - public NotificationObserver, - public base::RefCounted<DevToolsManager> { - public: - static DevToolsManager* GetInstance(); - - static void RegisterUserPrefs(PrefService* prefs); - - DevToolsManager(); - - // Returns DevToolsClientHost registered for |inspected_rvh| or NULL if - // there is no alive DevToolsClientHost registered for |inspected_rvh|. - DevToolsClientHost* GetDevToolsClientHostFor(RenderViewHost* inspected_rvh); - - // Registers new DevToolsClientHost for |inspected_rvh|. There must be no - // other DevToolsClientHosts registered for the RenderViewHost at the moment. - void RegisterDevToolsClientHostFor(RenderViewHost* inspected_rvh, - DevToolsClientHost* client_host); - void UnregisterDevToolsClientHostFor(RenderViewHost* inspected_rvh); - - void ForwardToDevToolsAgent(RenderViewHost* client_rvh, - const IPC::Message& message); - void ForwardToDevToolsAgent(DevToolsClientHost* from, - const IPC::Message& message); - void ForwardToDevToolsClient(RenderViewHost* inspected_rvh, - const IPC::Message& message); - - void ActivateWindow(RenderViewHost* client_rvn); - void CloseWindow(RenderViewHost* client_rvn); - void RequestDockWindow(RenderViewHost* client_rvn); - void RequestUndockWindow(RenderViewHost* client_rvn); - - void OpenDevToolsWindow(RenderViewHost* inspected_rvh); - void ToggleDevToolsWindow(RenderViewHost* inspected_rvh, - DevToolsToggleAction action); - void RuntimePropertyChanged(RenderViewHost* inspected_rvh, - const std::string& name, - const std::string& value); - - // Starts element inspection in the devtools client. - // Creates one by means of OpenDevToolsWindow if no client - // exists. - void InspectElement(RenderViewHost* inspected_rvh, int x, int y); - - // Sends 'Attach' message to the agent using |dest_rvh| in case - // there is a DevToolsClientHost registered for the |inspected_rvh|. - void OnNavigatingToPendingEntry(RenderViewHost* inspected_rvh, - RenderViewHost* dest_rvh, - const GURL& gurl); - - // Invoked when a tab is replaced by another tab. This is triggered by - // TabStripModel::ReplaceTabContentsAt. - void TabReplaced(TabContentsWrapper* old_tab, TabContentsWrapper* new_tab); - - // Detaches client host and returns cookie that can be used in - // AttachClientHost. - int DetachClientHost(RenderViewHost* from_rvh); - - // Attaches orphan client host to new render view host. - void AttachClientHost(int client_host_cookie, - RenderViewHost* to_rvh); - - // Closes all open developer tools windows. - void CloseAllClientHosts(); - - private: - friend class base::RefCounted<DevToolsManager>; - - virtual ~DevToolsManager(); - - // DevToolsClientHost::CloseListener override. - // This method will remove all references from the manager to the - // DevToolsClientHost and unregister all listeners related to the - // DevToolsClientHost. - virtual void ClientHostClosing(DevToolsClientHost* host); - - // Overridden from NotificationObserver: - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - // Returns RenderViewHost for the tab that is inspected by devtools - // client hosted by DevToolsClientHost. - RenderViewHost* GetInspectedRenderViewHost(DevToolsClientHost* client_host); - - void SendAttachToAgent(RenderViewHost* inspected_rvh); - void SendDetachToAgent(RenderViewHost* inspected_rvh); - - void ForceReopenWindow(); - - DevToolsClientHost* FindOwnerDevToolsClientHost(RenderViewHost* client_rvh); - - void ToggleDevToolsWindow(RenderViewHost* inspected_rvh, - bool force_open, - DevToolsToggleAction action); - - void ReopenWindow(RenderViewHost* client_rvh, bool docked); - - void BindClientHost(RenderViewHost* inspected_rvh, - DevToolsClientHost* client_host, - const DevToolsRuntimeProperties& runtime_properties); - - void UnbindClientHost(RenderViewHost* inspected_rvh, - DevToolsClientHost* client_host); - - // These two maps are for tracking dependencies between inspected tabs and - // their DevToolsClientHosts. They are useful for routing devtools messages - // and allow us to have at most one devtools client host per tab. - // - // DevToolsManager start listening to DevToolsClientHosts when they are put - // into these maps and removes them when they are closing. - typedef std::map<RenderViewHost*, DevToolsClientHost*> - InspectedRvhToClientHostMap; - InspectedRvhToClientHostMap inspected_rvh_to_client_host_; - - typedef std::map<DevToolsClientHost*, RenderViewHost*> - ClientHostToInspectedRvhMap; - ClientHostToInspectedRvhMap client_host_to_inspected_rvh_; - - typedef std::map<RenderViewHost*, DevToolsRuntimeProperties> - RuntimePropertiesMap; - RuntimePropertiesMap runtime_properties_map_; - - RenderViewHost* inspected_rvh_for_reopen_; - bool in_initial_show_; - - typedef std::map<int, - std::pair<DevToolsClientHost*, DevToolsRuntimeProperties> > - OrphanClientHosts; - OrphanClientHosts orphan_client_hosts_; - int last_orphan_cookie_; - - NotificationRegistrar registrar_; - - DISALLOW_COPY_AND_ASSIGN(DevToolsManager); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ diff --git a/chrome/browser/debugger/devtools_manager_unittest.cc b/chrome/browser/debugger/devtools_manager_unittest.cc deleted file mode 100644 index b2a7d2a..0000000 --- a/chrome/browser/debugger/devtools_manager_unittest.cc +++ /dev/null @@ -1,115 +0,0 @@ -// 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 "base/basictypes.h" -#include "chrome/browser/debugger/devtools_client_host.h" -#include "chrome/browser/debugger/devtools_manager.h" -#include "chrome/browser/debugger/devtools_window.h" -#include "chrome/common/render_messages.h" -#include "content/browser/renderer_host/test_render_view_host.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class TestDevToolsClientHost : public DevToolsClientHost { - public: - TestDevToolsClientHost() - : last_sent_message(NULL), - closed_(false) { - } - - virtual ~TestDevToolsClientHost() { - EXPECT_TRUE(closed_); - } - - virtual void Close() { - EXPECT_FALSE(closed_); - close_counter++; - NotifyCloseListener(); - closed_ = true; - } - virtual void InspectedTabClosing() { - Close(); - } - - virtual void SetInspectedTabUrl(const std::string& url) { - } - - virtual void SendMessageToClient(const IPC::Message& message) { - last_sent_message = &message; - } - - virtual void TabReplaced(TabContentsWrapper* new_tab) { - } - - static void ResetCounters() { - close_counter = 0; - } - - static int close_counter; - - const IPC::Message* last_sent_message; - - private: - bool closed_; - - virtual void FrameNavigating(const std::string& url) {} - - DISALLOW_COPY_AND_ASSIGN(TestDevToolsClientHost); -}; - -int TestDevToolsClientHost::close_counter = 0; - -} // namespace - -class DevToolsManagerTest : public RenderViewHostTestHarness { - public: - DevToolsManagerTest() : RenderViewHostTestHarness() { - } - - protected: - virtual void SetUp() { - RenderViewHostTestHarness::SetUp(); - TestDevToolsClientHost::ResetCounters(); - } -}; - -TEST_F(DevToolsManagerTest, OpenAndManuallyCloseDevToolsClientHost) { - scoped_refptr<DevToolsManager> manager(new DevToolsManager()); - - DevToolsClientHost* host = manager->GetDevToolsClientHostFor(rvh()); - EXPECT_TRUE(NULL == host); - - TestDevToolsClientHost client_host; - manager->RegisterDevToolsClientHostFor(rvh(), &client_host); - // Test that just registered devtools host is returned. - host = manager->GetDevToolsClientHostFor(rvh()); - EXPECT_TRUE(&client_host == host); - EXPECT_EQ(0, TestDevToolsClientHost::close_counter); - - // Test that the same devtools host is returned. - host = manager->GetDevToolsClientHostFor(rvh()); - EXPECT_TRUE(&client_host == host); - EXPECT_EQ(0, TestDevToolsClientHost::close_counter); - - client_host.Close(); - EXPECT_EQ(1, TestDevToolsClientHost::close_counter); - host = manager->GetDevToolsClientHostFor(rvh()); - EXPECT_TRUE(NULL == host); -} - -TEST_F(DevToolsManagerTest, ForwardMessageToClient) { - scoped_refptr<DevToolsManager> manager(new DevToolsManager()); - - TestDevToolsClientHost client_host; - manager->RegisterDevToolsClientHostFor(rvh(), &client_host); - EXPECT_EQ(0, TestDevToolsClientHost::close_counter); - - IPC::Message m; - manager->ForwardToDevToolsClient(rvh(), m); - EXPECT_TRUE(&m == client_host.last_sent_message); - - client_host.Close(); - EXPECT_EQ(1, TestDevToolsClientHost::close_counter); -} diff --git a/chrome/browser/debugger/devtools_netlog_observer.cc b/chrome/browser/debugger/devtools_netlog_observer.cc deleted file mode 100644 index e70b044..0000000 --- a/chrome/browser/debugger/devtools_netlog_observer.cc +++ /dev/null @@ -1,294 +0,0 @@ -// Copyright (c) 2011 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/devtools_netlog_observer.h" - -#include "base/string_tokenizer.h" -#include "base/string_util.h" -#include "base/values.h" -#include "chrome/browser/io_thread.h" -#include "content/common/resource_response.h" -#include "net/base/load_flags.h" -#include "net/http/http_net_log_params.h" -#include "net/http/http_response_headers.h" -#include "net/http/http_util.h" -#include "net/url_request/url_request.h" -#include "net/url_request/url_request_netlog_params.h" -#include "webkit/glue/resource_loader_bridge.h" - -const size_t kMaxNumEntries = 1000; - -DevToolsNetLogObserver* DevToolsNetLogObserver::instance_ = NULL; - -DevToolsNetLogObserver::DevToolsNetLogObserver(ChromeNetLog* chrome_net_log) - : ChromeNetLog::ThreadSafeObserver(net::NetLog::LOG_ALL_BUT_BYTES), - chrome_net_log_(chrome_net_log) { - chrome_net_log_->AddObserver(this); -} - -DevToolsNetLogObserver::~DevToolsNetLogObserver() { - chrome_net_log_->RemoveObserver(this); -} - -DevToolsNetLogObserver::ResourceInfo* -DevToolsNetLogObserver::GetResourceInfo(uint32 id) { - RequestToInfoMap::iterator it = request_to_info_.find(id); - if (it != request_to_info_.end()) - return it->second; - return NULL; -} - -void DevToolsNetLogObserver::OnAddEntry(net::NetLog::EventType type, - const base::TimeTicks& time, - const net::NetLog::Source& source, - net::NetLog::EventPhase phase, - net::NetLog::EventParameters* params) { - // The events that the Observer is interested in only occur on the IO thread. - if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) - return; - - // The events that the Observer is interested in only occur on the IO thread. - if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) - return; - if (source.type == net::NetLog::SOURCE_URL_REQUEST) - OnAddURLRequestEntry(type, time, source, phase, params); - else if (source.type == net::NetLog::SOURCE_HTTP_STREAM_JOB) - OnAddHTTPStreamJobEntry(type, time, source, phase, params); - else if (source.type == net::NetLog::SOURCE_SOCKET) - OnAddSocketEntry(type, time, source, phase, params); -} - -void DevToolsNetLogObserver::OnAddURLRequestEntry( - net::NetLog::EventType type, - const base::TimeTicks& time, - const net::NetLog::Source& source, - net::NetLog::EventPhase phase, - net::NetLog::EventParameters* params) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - bool is_begin = phase == net::NetLog::PHASE_BEGIN; - bool is_end = phase == net::NetLog::PHASE_END; - - if (type == net::NetLog::TYPE_URL_REQUEST_START_JOB) { - if (is_begin) { - int load_flags = static_cast< - net::URLRequestStartEventParameters*>(params)->load_flags(); - if (!(load_flags & net::LOAD_REPORT_RAW_HEADERS)) - return; - - if (request_to_info_.size() > kMaxNumEntries) { - LOG(WARNING) << "The raw headers observer url request count has grown " - "larger than expected, resetting"; - request_to_info_.clear(); - } - - request_to_info_[source.id] = new ResourceInfo(); - - if (request_to_encoded_data_length_.size() > kMaxNumEntries) { - LOG(WARNING) << "The encoded data length observer url request count " - "has grown larger than expected, resetting"; - request_to_encoded_data_length_.clear(); - } - - request_to_encoded_data_length_[source.id] = 0; - } - return; - } else if (type == net::NetLog::TYPE_REQUEST_ALIVE) { - // Cleanup records based on the TYPE_REQUEST_ALIVE entry. - if (is_end) { - request_to_info_.erase(source.id); - request_to_encoded_data_length_.erase(source.id); - } - return; - } - - ResourceInfo* info = GetResourceInfo(source.id); - if (!info) - return; - - switch (type) { - case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS: { - net::NetLogHttpRequestParameter* request_parameter = - static_cast<net::NetLogHttpRequestParameter*>(params); - const net::HttpRequestHeaders &request_headers = - request_parameter->GetHeaders(); - - // We need to clear headers in case the same url_request is reused for - // several http requests (e.g. see http://crbug.com/80157). - info->request_headers.clear(); - - for (net::HttpRequestHeaders::Iterator it(request_headers); - it.GetNext();) { - info->request_headers.push_back(std::make_pair(it.name(), - it.value())); - } - info->request_headers_text = - request_parameter->GetLine() + - request_parameter->GetHeaders().ToString(); - break; - } - case net::NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS: { - const net::HttpResponseHeaders& response_headers = - static_cast<net::NetLogHttpResponseParameter*>(params)->GetHeaders(); - info->http_status_code = response_headers.response_code(); - info->http_status_text = response_headers.GetStatusText(); - std::string name, value; - - // We need to clear headers in case the same url_request is reused for - // several http requests (e.g. see http://crbug.com/80157). - info->response_headers.clear(); - - for (void* it = NULL; - response_headers.EnumerateHeaderLines(&it, &name, &value); ) { - info->response_headers.push_back(std::make_pair(name, value)); - } - info->response_headers_text = - net::HttpUtil::ConvertHeadersBackToHTTPResponse( - response_headers.raw_headers()); - break; - } - case net::NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB: { - uint32 http_stream_job_id = static_cast<net::NetLogSourceParameter*>( - params)->value().id; - HTTPStreamJobToSocketMap::iterator it = - http_stream_job_to_socket_.find(http_stream_job_id); - if (it == http_stream_job_to_socket_.end()) - return; - uint32 socket_id = it->second; - - if (socket_to_request_.size() > kMaxNumEntries) { - LOG(WARNING) << "The url request observer socket count has grown " - "larger than expected, resetting"; - socket_to_request_.clear(); - } - - socket_to_request_[socket_id] = source.id; - http_stream_job_to_socket_.erase(http_stream_job_id); - break; - } - default: - break; - } -} - -void DevToolsNetLogObserver::OnAddHTTPStreamJobEntry( - net::NetLog::EventType type, - const base::TimeTicks& time, - const net::NetLog::Source& source, - net::NetLog::EventPhase phase, - net::NetLog::EventParameters* params) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - if (type == net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET) { - uint32 socket_id = static_cast<net::NetLogSourceParameter*>( - params)->value().id; - - // Prevents us from passively growing the memory unbounded in - // case something went wrong. Should not happen. - if (http_stream_job_to_socket_.size() > kMaxNumEntries) { - LOG(WARNING) << "The load timing observer http stream job count " - "has grown larger than expected, resetting"; - http_stream_job_to_socket_.clear(); - } - http_stream_job_to_socket_[source.id] = socket_id; - } -} - -void DevToolsNetLogObserver::OnAddSocketEntry( - net::NetLog::EventType type, - const base::TimeTicks& time, - const net::NetLog::Source& source, - net::NetLog::EventPhase phase, - net::NetLog::EventParameters* params) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - bool is_end = phase == net::NetLog::PHASE_END; - - SocketToRequestMap::iterator it = socket_to_request_.find(source.id); - if (it == socket_to_request_.end()) - return; - uint32 request_id = it->second; - - if (type == net::NetLog::TYPE_SOCKET_IN_USE) { - if (is_end) - socket_to_request_.erase(source.id); - return; - } - - RequestToEncodedDataLengthMap::iterator encoded_data_length_it = - request_to_encoded_data_length_.find(request_id); - if (encoded_data_length_it == request_to_encoded_data_length_.end()) - return; - - if (net::NetLog::TYPE_SOCKET_BYTES_RECEIVED == type) { - int byte_count = 0; - scoped_ptr<Value> value(params->ToValue()); - if (!value->IsType(Value::TYPE_DICTIONARY)) - return; - - DictionaryValue* dValue = static_cast<DictionaryValue*>(value.get()); - if (!dValue->GetInteger("byte_count", &byte_count)) - return; - - encoded_data_length_it->second += byte_count; - } -} - -void DevToolsNetLogObserver::Attach(IOThread* io_thread) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK(!instance_); - - instance_ = new DevToolsNetLogObserver(io_thread->net_log()); -} - -void DevToolsNetLogObserver::Detach() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK(instance_); - - delete instance_; - instance_ = NULL; -} - -DevToolsNetLogObserver* DevToolsNetLogObserver::GetInstance() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - return instance_; -} - -// static -void DevToolsNetLogObserver::PopulateResponseInfo(net::URLRequest* request, - ResourceResponse* response) { - if (!(request->load_flags() & net::LOAD_REPORT_RAW_HEADERS)) - return; - - uint32 source_id = request->net_log().source().id; - DevToolsNetLogObserver* dev_tools_net_log_observer = - DevToolsNetLogObserver::GetInstance(); - if (dev_tools_net_log_observer == NULL) - return; - response->response_head.devtools_info = - dev_tools_net_log_observer->GetResourceInfo(source_id); -} - -// static -int DevToolsNetLogObserver::GetAndResetEncodedDataLength( - net::URLRequest* request) { - if (!(request->load_flags() & net::LOAD_REPORT_RAW_HEADERS)) - return -1; - - uint32 source_id = request->net_log().source().id; - DevToolsNetLogObserver* dev_tools_net_log_observer = - DevToolsNetLogObserver::GetInstance(); - if (dev_tools_net_log_observer == NULL) - return -1; - - RequestToEncodedDataLengthMap::iterator it = - dev_tools_net_log_observer->request_to_encoded_data_length_.find( - source_id); - if (it == dev_tools_net_log_observer->request_to_encoded_data_length_.end()) - return -1; - int encoded_data_length = it->second; - it->second = 0; - return encoded_data_length; -} diff --git a/chrome/browser/debugger/devtools_netlog_observer.h b/chrome/browser/debugger/devtools_netlog_observer.h deleted file mode 100644 index 75efa8e..0000000 --- a/chrome/browser/debugger/devtools_netlog_observer.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) 2011 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_DEVTOOLS_NETLOG_OBSERVER_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_NETLOG_OBSERVER_H_ -#pragma once - -#include "base/hash_tables.h" -#include "base/memory/ref_counted.h" -#include "chrome/browser/net/chrome_net_log.h" -#include "webkit/glue/resource_loader_bridge.h" - -namespace net { -class URLRequest; -} // namespace net - -class IOThread; -struct ResourceResponse; - -// DevToolsNetLogObserver watches the NetLog event stream and collects the -// stuff that may be of interest to DevTools. Currently, this only includes -// actual HTTP/SPDY headers sent and received over the network. -// -// As DevToolsNetLogObserver shares live data with objects that live on the -// IO Thread, it must also reside on the IO Thread. Only OnAddEntry can be -// called from other threads. -class DevToolsNetLogObserver: public ChromeNetLog::ThreadSafeObserver { - typedef webkit_glue::ResourceDevToolsInfo ResourceInfo; - - public: - // ThreadSafeObserver implementation: - virtual void OnAddEntry(net::NetLog::EventType type, - const base::TimeTicks& time, - const net::NetLog::Source& source, - net::NetLog::EventPhase phase, - net::NetLog::EventParameters* params); - - void OnAddURLRequestEntry(net::NetLog::EventType type, - const base::TimeTicks& time, - const net::NetLog::Source& source, - net::NetLog::EventPhase phase, - net::NetLog::EventParameters* params); - - void OnAddHTTPStreamJobEntry(net::NetLog::EventType type, - const base::TimeTicks& time, - const net::NetLog::Source& source, - net::NetLog::EventPhase phase, - net::NetLog::EventParameters* params); - - void OnAddSocketEntry(net::NetLog::EventType type, - const base::TimeTicks& time, - const net::NetLog::Source& source, - net::NetLog::EventPhase phase, - net::NetLog::EventParameters* params); - - static void Attach(IOThread* thread); - static void Detach(); - - // Must be called on the IO thread. May return NULL if no observers - // are active. - static DevToolsNetLogObserver* GetInstance(); - static void PopulateResponseInfo(net::URLRequest*, ResourceResponse*); - static int GetAndResetEncodedDataLength(net::URLRequest* request); - - private: - static DevToolsNetLogObserver* instance_; - - explicit DevToolsNetLogObserver(ChromeNetLog* chrome_net_log); - virtual ~DevToolsNetLogObserver(); - - ResourceInfo* GetResourceInfo(uint32 id); - - ChromeNetLog* chrome_net_log_; - typedef base::hash_map<uint32, scoped_refptr<ResourceInfo> > RequestToInfoMap; - typedef base::hash_map<uint32, int> RequestToEncodedDataLengthMap; - typedef base::hash_map<uint32, uint32> HTTPStreamJobToSocketMap; - typedef base::hash_map<uint32, uint32> SocketToRequestMap; - RequestToInfoMap request_to_info_; - RequestToEncodedDataLengthMap request_to_encoded_data_length_; - HTTPStreamJobToSocketMap http_stream_job_to_socket_; - SocketToRequestMap socket_to_request_; - - DISALLOW_COPY_AND_ASSIGN(DevToolsNetLogObserver); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_NETLOG_OBSERVER_H_ diff --git a/chrome/browser/debugger/devtools_protocol_handler.cc b/chrome/browser/debugger/devtools_protocol_handler.cc deleted file mode 100644 index 2245a96..0000000 --- a/chrome/browser/debugger/devtools_protocol_handler.cc +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (c) 2011 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/devtools_protocol_handler.h" - -#include "base/logging.h" -#include "chrome/browser/debugger/inspectable_tab_proxy.h" -#include "chrome/browser/debugger/debugger_remote_service.h" -#include "chrome/browser/debugger/devtools_remote_message.h" -#include "chrome/browser/debugger/devtools_remote_listen_socket.h" -#include "chrome/browser/debugger/devtools_remote_service.h" -#include "chrome/browser/debugger/extension_ports_remote_service.h" -#include "content/browser/browser_thread.h" - -// static -scoped_refptr<DevToolsProtocolHandler> DevToolsProtocolHandler::Start( - int port) { - scoped_refptr<DevToolsProtocolHandler> proto_handler = - new DevToolsProtocolHandler(port); - proto_handler->RegisterDestination( - new DevToolsRemoteService(proto_handler), - DevToolsRemoteService::kToolName); - proto_handler->RegisterDestination( - new DebuggerRemoteService(proto_handler), - DebuggerRemoteService::kToolName); - proto_handler->RegisterDestination( - new ExtensionPortsRemoteService(proto_handler), - ExtensionPortsRemoteService::kToolName); - proto_handler->Start(); - return proto_handler; -} - -DevToolsProtocolHandler::DevToolsProtocolHandler(int port) - : port_(port), - connection_(NULL), - server_(NULL) { - inspectable_tab_proxy_.reset(new InspectableTabProxy); -} - -DevToolsProtocolHandler::~DevToolsProtocolHandler() { - // Stop() must be called prior to this being called - DCHECK(server_.get() == NULL); - DCHECK(connection_.get() == NULL); -} - -void DevToolsProtocolHandler::Start() { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, &DevToolsProtocolHandler::Init)); -} - -void DevToolsProtocolHandler::Init() { - server_ = DevToolsRemoteListenSocket::Listen( - "127.0.0.1", port_, this); -} - -void DevToolsProtocolHandler::Stop() { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, &DevToolsProtocolHandler::Teardown)); - tool_to_listener_map_.clear(); // Releases all scoped_refptr's to listeners -} - -// Run in I/O thread -void DevToolsProtocolHandler::Teardown() { - connection_ = NULL; - server_ = NULL; -} - -void DevToolsProtocolHandler::RegisterDestination( - DevToolsRemoteListener* listener, - const std::string& tool_name) { - DCHECK(tool_to_listener_map_.find(tool_name) == tool_to_listener_map_.end()); - tool_to_listener_map_.insert(std::make_pair(tool_name, listener)); -} - -void DevToolsProtocolHandler::UnregisterDestination( - DevToolsRemoteListener* listener, - const std::string& tool_name) { - DCHECK(tool_to_listener_map_.find(tool_name) != tool_to_listener_map_.end()); - DCHECK(tool_to_listener_map_.find(tool_name)->second == listener); - tool_to_listener_map_.erase(tool_name); -} - -void DevToolsProtocolHandler::HandleMessage( - const DevToolsRemoteMessage& message) { - std::string tool = message.GetHeaderWithEmptyDefault( - DevToolsRemoteMessageHeaders::kTool); - ToolToListenerMap::const_iterator it = tool_to_listener_map_.find(tool); - if (it == tool_to_listener_map_.end()) { - NOTREACHED(); // an unsupported tool, bail out - return; - } - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - it->second.get(), &DevToolsRemoteListener::HandleMessage, message)); -} - -void DevToolsProtocolHandler::Send(const DevToolsRemoteMessage& message) { - if (connection_ != NULL) { - connection_->Send(message.ToString()); - } -} - -void DevToolsProtocolHandler::OnAcceptConnection( - net::ListenSocket *connection) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - connection_ = connection; -} - -void DevToolsProtocolHandler::OnConnectionLost() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - connection_ = NULL; - for (ToolToListenerMap::const_iterator it = tool_to_listener_map_.begin(), - end = tool_to_listener_map_.end(); - it != end; - ++it) { - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - it->second.get(), &DevToolsRemoteListener::OnConnectionLost)); - } -} diff --git a/chrome/browser/debugger/devtools_protocol_handler.h b/chrome/browser/debugger/devtools_protocol_handler.h deleted file mode 100644 index b1b9158d..0000000 --- a/chrome/browser/debugger/devtools_protocol_handler.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2011 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_DEVTOOLS_PROTOCOL_HANDLER_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_PROTOCOL_HANDLER_H_ -#pragma once - -#include <string> - -#include "base/hash_tables.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/debugger/devtools_remote.h" -#include "net/base/listen_socket.h" - -class InspectableTabProxy; -class DevToolsRemoteListenSocket; -class DevToolsRemoteMessage; - -// Dispatches DevToolsRemoteMessages to their appropriate handlers (Tools) -// based on the "Tool" message header value. -class DevToolsProtocolHandler - : public DevToolsRemoteListener, - public OutboundSocketDelegate { - public: - typedef base::hash_map< std::string, scoped_refptr<DevToolsRemoteListener> > - ToolToListenerMap; - - static scoped_refptr<DevToolsProtocolHandler> Start(int port); - - // Called from the main thread in order to stop protocol handler. - // Will schedule tear down task on IO thread. - void Stop(); - - // Registers a |listener| to handle messages for a certain |tool_name| Tool. - // |listener| is the new message handler to register. - // As DevToolsRemoteListener inherits base::RefCountedThreadSafe, - // you should have no problems with ownership and destruction. - // |tool_name| is the name of the Tool to associate the listener with. - void RegisterDestination(DevToolsRemoteListener* listener, - const std::string& tool_name); - - // Unregisters a |listener| so that it will no longer handle messages - // directed to the specified |tool_name| tool. - void UnregisterDestination(DevToolsRemoteListener* listener, - const std::string& tool_name); - - InspectableTabProxy* inspectable_tab_proxy() { - return inspectable_tab_proxy_.get(); - } - - // DevToolsRemoteListener interface - virtual void HandleMessage(const DevToolsRemoteMessage& message); - virtual void OnAcceptConnection(net::ListenSocket *connection); - virtual void OnConnectionLost(); - - // OutboundSocketDelegate interface - virtual void Send(const DevToolsRemoteMessage& message); - - private: - explicit DevToolsProtocolHandler(int port); - virtual ~DevToolsProtocolHandler(); - void Start(); - - void Init(); - void Teardown(); - int port_; - ToolToListenerMap tool_to_listener_map_; - scoped_refptr<net::ListenSocket> connection_; - scoped_refptr<DevToolsRemoteListenSocket> server_; - scoped_ptr<InspectableTabProxy> inspectable_tab_proxy_; - DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolHandler); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_PROTOCOL_HANDLER_H_ diff --git a/chrome/browser/debugger/devtools_remote.h b/chrome/browser/debugger/devtools_remote.h deleted file mode 100644 index 78b1d13..0000000 --- a/chrome/browser/debugger/devtools_remote.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2011 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_DEVTOOLS_REMOTE_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/memory/ref_counted.h" - -class DevToolsRemoteMessage; - -namespace net { -class ListenSocket; -} - -// This interface should be implemented by a class that wants to handle -// DevToolsRemoteMessages dispatched by some entity. It must extend -class DevToolsRemoteListener - : public base::RefCountedThreadSafe<DevToolsRemoteListener> { - public: - DevToolsRemoteListener() {} - virtual void HandleMessage(const DevToolsRemoteMessage& message) = 0; - // This method is invoked on the UI thread whenever the debugger connection - // has been lost. - virtual void OnConnectionLost() = 0; - virtual void OnAcceptConnection(net::ListenSocket* connection) {} - - protected: - friend class base::RefCountedThreadSafe<DevToolsRemoteListener>; - - virtual ~DevToolsRemoteListener() {} - - private: - DISALLOW_COPY_AND_ASSIGN(DevToolsRemoteListener); -}; - -// Interface exposed by DevToolsProtocolHandler to receive reply messages -// from registered tools. -class OutboundSocketDelegate { - public: - virtual ~OutboundSocketDelegate() {} - virtual void Send(const DevToolsRemoteMessage& message) = 0; -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_H_ diff --git a/chrome/browser/debugger/devtools_remote_listen_socket.cc b/chrome/browser/debugger/devtools_remote_listen_socket.cc deleted file mode 100644 index 0ec9e32..0000000 --- a/chrome/browser/debugger/devtools_remote_listen_socket.cc +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright (c) 2011 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/devtools_remote_listen_socket.h" - -#include "build/build_config.h" - -#include <stdlib.h> - -#if defined(OS_WIN) -// winsock2.h must be included first in order to ensure it is included before -// windows.h. -#include <winsock2.h> -#elif defined(OS_POSIX) -#include <errno.h> -#include <sys/socket.h> -#endif - -#include "base/compiler_specific.h" -#include "base/eintr_wrapper.h" -#include "base/string_number_conversions.h" -#include "base/threading/platform_thread.h" -#include "chrome/browser/debugger/devtools_remote.h" -#include "chrome/browser/debugger/devtools_remote_message.h" - -#define CONSUME_BUFFER_CHAR \ - pBuf++;\ - len-- - -#if defined(OS_POSIX) -// Used same name as in Windows to avoid #ifdef where refrenced -#define SOCKET int -const int INVALID_SOCKET = -1; -const int SOCKET_ERROR = -1; -#endif - -const int kReadBufSize = 200; - -DevToolsRemoteListenSocket::DevToolsRemoteListenSocket( - SOCKET s, - DevToolsRemoteListener* message_listener) - : ALLOW_THIS_IN_INITIALIZER_LIST(net::ListenSocket(s, this)), - state_(HANDSHAKE), - remaining_payload_length_(0), - message_listener_(message_listener), - cr_received_(false) {} - -void DevToolsRemoteListenSocket::StartNextField() { - switch (state_) { - case INVALID: - state_ = HANDSHAKE; - break; - case HANDSHAKE: - state_ = HEADERS; - break; - case HEADERS: - if (protocol_field_.empty()) { // empty line - end of headers - const std::string& payload_length_string = GetHeader( - DevToolsRemoteMessageHeaders::kContentLength, "0"); - base::StringToInt(payload_length_string, &remaining_payload_length_); - state_ = PAYLOAD; - if (remaining_payload_length_ == 0) { // no payload - DispatchField(); - return; - } - } - break; - case PAYLOAD: - header_map_.clear(); - payload_.clear(); - state_ = HEADERS; - break; - default: - NOTREACHED(); - break; - } - protocol_field_.clear(); -} - -DevToolsRemoteListenSocket::~DevToolsRemoteListenSocket() {} - -DevToolsRemoteListenSocket* - DevToolsRemoteListenSocket::Listen(const std::string& ip, - int port, - DevToolsRemoteListener* listener) { - SOCKET s = net::ListenSocket::Listen(ip, port); - if (s == INVALID_SOCKET) { - // TODO(apavlov): error handling - } else { - DevToolsRemoteListenSocket* sock = - new DevToolsRemoteListenSocket(s, listener); - sock->Listen(); - return sock; - } - return NULL; -} - -void DevToolsRemoteListenSocket::DidAccept(net::ListenSocket *server, - net::ListenSocket *connection) { - connection->AddRef(); - message_listener_->OnAcceptConnection(connection); -} - -// Dispatches data from socket to socket_delegate_, extracting messages -// delimited by newlines. -void DevToolsRemoteListenSocket::DidRead(net::ListenSocket* connection, - const char* pBuf, - int len) { - while (len > 0) { - if (state_ != PAYLOAD) { - if (cr_received_ && *pBuf == '\n') { - cr_received_ = false; - CONSUME_BUFFER_CHAR; - } else { - while (*pBuf != '\r' && len > 0) { - protocol_field_.push_back(*pBuf); - CONSUME_BUFFER_CHAR; - } - if (*pBuf == '\r') { - cr_received_ = true; - CONSUME_BUFFER_CHAR; - } - continue; - } - switch (state_) { - case HANDSHAKE: - case HEADERS: - DispatchField(); - break; - default: - NOTREACHED(); - break; - } - } else { // PAYLOAD - while (remaining_payload_length_ > 0 && len > 0) { - protocol_field_.push_back(*pBuf); - CONSUME_BUFFER_CHAR; - remaining_payload_length_--; - } - if (remaining_payload_length_ == 0) { - DispatchField(); - } - } - } -} - -void DevToolsRemoteListenSocket::DidClose(net::ListenSocket *connection) { - message_listener_->OnConnectionLost(); - connection->Release(); -} - -void DevToolsRemoteListenSocket::DispatchField() { - static const std::string kHandshakeString = "ChromeDevToolsHandshake"; - switch (state_) { - case HANDSHAKE: - if (protocol_field_.compare(kHandshakeString)) { - state_ = INVALID; - } else { - Send(kHandshakeString, true); - } - break; - case HEADERS: { - if (!protocol_field_.empty()) { // not end-of-headers - std::string::size_type colon_pos = protocol_field_.find_first_of(":"); - if (colon_pos == std::string::npos) { - // TODO(apavlov): handle the error (malformed header) - } else { - const std::string header_name = protocol_field_.substr(0, colon_pos); - std::string header_val = protocol_field_.substr(colon_pos + 1); - header_map_[header_name] = header_val; - } - } - break; - } - case PAYLOAD: - payload_ = protocol_field_; - HandleMessage(); - break; - default: - NOTREACHED(); - break; - } - StartNextField(); -} - -const std::string& DevToolsRemoteListenSocket::GetHeader( - const std::string& header_name, - const std::string& default_value) const { - DevToolsRemoteMessage::HeaderMap::const_iterator it = - header_map_.find(header_name); - if (it == header_map_.end()) { - return default_value; - } - return it->second; -} - -// Handle header_map_ and payload_ -void DevToolsRemoteListenSocket::HandleMessage() { - if (message_listener_ != NULL) { - DevToolsRemoteMessage message(header_map_, payload_); - message_listener_->HandleMessage(message); - } -} - -void DevToolsRemoteListenSocket::Listen() { - net::ListenSocket::Listen(); -} - -void DevToolsRemoteListenSocket::Accept() { - SOCKET conn = net::ListenSocket::Accept(socket_); - if (conn != INVALID_SOCKET) { - scoped_refptr<DevToolsRemoteListenSocket> sock( - new DevToolsRemoteListenSocket(conn, - message_listener_)); - // it's up to the delegate to AddRef if it wants to keep it around -#if defined(OS_POSIX) - sock->WatchSocket(WAITING_READ); -#endif - socket_delegate_->DidAccept(this, sock); - } else { - // TODO(apavlov): some error handling required here - } -} - -void DevToolsRemoteListenSocket::SendInternal(const char* bytes, int len) { - char* send_buf = const_cast<char *>(bytes); - int len_left = len; - while (true) { - int sent = HANDLE_EINTR(send(socket_, send_buf, len_left, 0)); - if (sent == len_left) { // A shortcut to avoid extraneous checks. - break; - } - if (sent == kSocketError) { -#if defined(OS_WIN) - if (WSAGetLastError() != WSAEWOULDBLOCK) { - LOG(ERROR) << "send failed: WSAGetLastError()==" << WSAGetLastError(); -#elif defined(OS_POSIX) - if (errno != EWOULDBLOCK && errno != EAGAIN) { - LOG(ERROR) << "send failed: errno==" << errno; -#endif - break; - } - // Otherwise we would block, and now we have to wait for a retry. - // Fall through to PlatformThread::YieldCurrentThread() - } else { - // sent != len_left according to the shortcut above. - // Shift the buffer start and send the remainder after a short while. - send_buf += sent; - len_left -= sent; - } - base::PlatformThread::YieldCurrentThread(); - } -} - -void DevToolsRemoteListenSocket::Close() { - net::ListenSocket::Close(); -} diff --git a/chrome/browser/debugger/devtools_remote_listen_socket.h b/chrome/browser/debugger/devtools_remote_listen_socket.h deleted file mode 100644 index 40212f4..0000000 --- a/chrome/browser/debugger/devtools_remote_listen_socket.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) 2011 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_DEVTOOLS_REMOTE_LISTEN_SOCKET_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_LISTEN_SOCKET_H_ -#pragma once - -#include <string> - -#include "chrome/browser/debugger/devtools_remote_message.h" -#include "net/base/listen_socket.h" - -class DevToolsRemoteListener; - -// Listens to remote debugger incoming connections, handles the V8ARDP protocol -// socket input and invokes the message handler when appropriate. -class DevToolsRemoteListenSocket - : public net::ListenSocket, - public net::ListenSocket::ListenSocketDelegate { - public: - // Listen on port for the specified IP address. Use 127.0.0.1 to only - // accept local connections. - static DevToolsRemoteListenSocket* Listen( - const std::string& ip, - int port, - DevToolsRemoteListener* message_listener); - - protected: - virtual void Listen(); - virtual void Accept(); - virtual void Close(); - virtual void SendInternal(const char* bytes, int len); - - private: - virtual ~DevToolsRemoteListenSocket(); - - // net::ListenSocket::ListenSocketDelegate interface - virtual void DidAccept(net::ListenSocket *server, - net::ListenSocket *connection); - virtual void DidRead(net::ListenSocket *connection, - const char* data, int len); - virtual void DidClose(net::ListenSocket *connection); - - // The protocol states while reading socket input - enum State { - INVALID = 0, // Bad handshake message received, retry - HANDSHAKE = 1, // Receiving handshake message - HEADERS = 2, // Receiving protocol headers - PAYLOAD = 3 // Receiving payload - }; - - DevToolsRemoteListenSocket(SOCKET s, - DevToolsRemoteListener *listener); - void StartNextField(); - void HandleMessage(); - void DispatchField(); - const std::string& GetHeader(const std::string& header_name, - const std::string& default_value) const; - - State state_; - DevToolsRemoteMessage::HeaderMap header_map_; - std::string protocol_field_; - std::string payload_; - int32 remaining_payload_length_; - DevToolsRemoteListener* message_listener_; - bool cr_received_; - - DISALLOW_COPY_AND_ASSIGN(DevToolsRemoteListenSocket); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_LISTEN_SOCKET_H_ diff --git a/chrome/browser/debugger/devtools_remote_listen_socket_unittest.cc b/chrome/browser/debugger/devtools_remote_listen_socket_unittest.cc deleted file mode 100644 index 9821b59..0000000 --- a/chrome/browser/debugger/devtools_remote_listen_socket_unittest.cc +++ /dev/null @@ -1,383 +0,0 @@ -// Copyright (c) 2011 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/devtools_remote_listen_socket_unittest.h" - -#include <fcntl.h> -#if defined(OS_POSIX) -#include <netinet/in.h> -#endif - -#include "base/eintr_wrapper.h" -#include "base/test/test_timeouts.h" -#include "base/threading/platform_thread.h" -#include "net/base/net_util.h" -#include "testing/platform_test.h" - -const int DevToolsRemoteListenSocketTester::kTestPort = 9999; - -static const int kReadBufSize = 1024; -static const char* kChromeDevToolsHandshake = "ChromeDevToolsHandshake\r\n"; -static const char* kSimpleMessagePart1 = - "Tool:V8Debugger\r\n" - "Destination:2\r"; -static const char* kSimpleMessagePart2 = - "\n" - "Content-Length:0\r\n" - "\r\n"; -static const char* kTwoMessages = - "Tool:DevToolsService\r\n" - "Content-Length:300\r\n" - "\r\n" - "00000000000000000000000000000000000000000000000000" - "00000000000000000000000000000000000000000000000000" - "00000000000000000000000000000000000000000000000000" - "00000000000000000000000000000000000000000000000000" - "00000000000000000000000000000000000000000000000000" - "00000000000000000000000000000000000000000000000000" - "Tool:V8Debugger\r\n" - "Destination:1\r\n" - "Content-Length:0\r\n" - "\r\n"; - -static const int kMaxQueueSize = 20; -static const char* kLoopback = "127.0.0.1"; -#if defined(OS_POSIX) -static const char* kSemaphoreName = "chromium.listen_socket"; -#endif - - -ListenSocketTestAction::ListenSocketTestAction() : action_(ACTION_NONE) {} - -ListenSocketTestAction::ListenSocketTestAction(ActionType action) - : action_(action) {} - -ListenSocketTestAction::ListenSocketTestAction(ActionType action, - std::string data) - : action_(action), - data_(data) {} - -ListenSocketTestAction::ListenSocketTestAction( - ActionType action, - const DevToolsRemoteMessage& message) - : action_(action), - message_(message) {} - -ListenSocketTestAction::~ListenSocketTestAction() {} - -net::ListenSocket* DevToolsRemoteListenSocketTester::DoListen() { - return DevToolsRemoteListenSocket::Listen(kLoopback, kTestPort, this); -} - -DevToolsRemoteListenSocketTester::DevToolsRemoteListenSocketTester() - : semaphore_(NULL), - thread_(NULL), - loop_(NULL), - server_(NULL), - connection_(NULL), - test_socket_(INVALID_SOCKET) { - memset(&lock_, 0, sizeof(lock_)); -} - -void DevToolsRemoteListenSocketTester::SetUp() { -#if defined(OS_WIN) - InitializeCriticalSection(&lock_); - semaphore_ = CreateSemaphore(NULL, 0, kMaxQueueSize, NULL); - server_ = NULL; - net::EnsureWinsockInit(); -#elif defined(OS_POSIX) - ASSERT_EQ(0, pthread_mutex_init(&lock_, NULL)); - sem_unlink(kSemaphoreName); - semaphore_ = sem_open(kSemaphoreName, O_CREAT, 0, 0); - ASSERT_NE(SEM_FAILED, semaphore_); -#endif - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - thread_.reset(new base::Thread("socketio_test")); - thread_->StartWithOptions(options); - loop_ = static_cast<MessageLoopForIO*>(thread_->message_loop()); - - loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &DevToolsRemoteListenSocketTester::Listen)); - - // verify Listen succeeded - ASSERT_TRUE(NextAction(TestTimeouts::action_timeout_ms())); - ASSERT_FALSE(server_ == NULL); - ASSERT_EQ(ACTION_LISTEN, last_action_.type()); - - // verify the connect/accept and setup test_socket_ - test_socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - ASSERT_NE(INVALID_SOCKET, test_socket_); - struct sockaddr_in client; - client.sin_family = AF_INET; - client.sin_addr.s_addr = inet_addr(kLoopback); - client.sin_port = htons(kTestPort); - int ret = HANDLE_EINTR(connect(test_socket_, - reinterpret_cast<sockaddr*>(&client), - sizeof(client))); - ASSERT_NE(ret, SOCKET_ERROR); - - net::SetNonBlocking(test_socket_); - ASSERT_TRUE(NextAction(TestTimeouts::action_timeout_ms())); - ASSERT_EQ(ACTION_ACCEPT, last_action_.type()); -} - -void DevToolsRemoteListenSocketTester::TearDown() { - // verify close -#if defined(OS_WIN) - closesocket(test_socket_); -#elif defined(OS_POSIX) - int ret = HANDLE_EINTR(close(test_socket_)); - ASSERT_EQ(ret, 0); -#endif - ASSERT_TRUE(NextAction(TestTimeouts::action_timeout_ms())); - ASSERT_EQ(ACTION_CLOSE, last_action_.type()); - - loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &DevToolsRemoteListenSocketTester::Shutdown)); - ASSERT_TRUE(NextAction(TestTimeouts::action_timeout_ms())); - ASSERT_EQ(ACTION_SHUTDOWN, last_action_.type()); - -#if defined(OS_WIN) - CloseHandle(semaphore_); - semaphore_ = 0; - DeleteCriticalSection(&lock_); -#elif defined(OS_POSIX) - ASSERT_EQ(0, pthread_mutex_lock(&lock_)); - semaphore_ = NULL; - ASSERT_EQ(0, pthread_mutex_unlock(&lock_)); - ASSERT_EQ(0, sem_unlink(kSemaphoreName)); - ASSERT_EQ(0, pthread_mutex_destroy(&lock_)); -#endif - - thread_.reset(); - loop_ = NULL; -} - -void DevToolsRemoteListenSocketTester::ReportAction( - const ListenSocketTestAction& action) { -#if defined(OS_WIN) - EnterCriticalSection(&lock_); - queue_.push_back(action); - LeaveCriticalSection(&lock_); - ReleaseSemaphore(semaphore_, 1, NULL); -#elif defined(OS_POSIX) - ASSERT_EQ(0, pthread_mutex_lock(&lock_)); - queue_.push_back(action); - ASSERT_EQ(0, pthread_mutex_unlock(&lock_)); - ASSERT_EQ(0, sem_post(semaphore_)); -#endif -} - -bool DevToolsRemoteListenSocketTester::NextAction(int timeout) { -#if defined(OS_WIN) - DWORD ret = ::WaitForSingleObject(semaphore_, timeout); - if (ret != WAIT_OBJECT_0) - return false; - EnterCriticalSection(&lock_); - if (queue_.empty()) { - LeaveCriticalSection(&lock_); - return false; - } - last_action_ = queue_.front(); - queue_.pop_front(); - LeaveCriticalSection(&lock_); - return true; -#elif defined(OS_POSIX) - if (semaphore_ == SEM_FAILED) - return false; - while (true) { - int result = sem_trywait(semaphore_); - base::PlatformThread::Sleep(1); // 1MS sleep - timeout--; - if (timeout <= 0) - return false; - if (result == 0) - break; - } - pthread_mutex_lock(&lock_); - if (queue_.empty()) { - pthread_mutex_unlock(&lock_); - return false; - } - last_action_ = queue_.front(); - queue_.pop_front(); - pthread_mutex_unlock(&lock_); - return true; -#endif -} - -int DevToolsRemoteListenSocketTester::ClearTestSocket() { - char buf[kReadBufSize]; - int len_ret = 0; - int time_out = 0; - do { - int len = HANDLE_EINTR(recv(test_socket_, buf, kReadBufSize, 0)); -#if defined(OS_WIN) - if (len == SOCKET_ERROR) { - int err = WSAGetLastError(); - if (err == WSAEWOULDBLOCK) { -#elif defined(OS_POSIX) - if (len == SOCKET_ERROR) { - if (errno == EWOULDBLOCK || errno == EAGAIN) { -#endif - base::PlatformThread::Sleep(1); - time_out++; - if (time_out > 10) - break; - continue; // still trying - } - } else if (len == 0) { - // socket closed - break; - } else { - time_out = 0; - len_ret += len; - } - } while (true); - return len_ret; -} - -void DevToolsRemoteListenSocketTester::Shutdown() { - server_->Release(); - server_ = NULL; - ReportAction(ListenSocketTestAction(ACTION_SHUTDOWN)); -} - -void DevToolsRemoteListenSocketTester::Listen() { - server_ = DoListen(); - server_->AddRef(); - ReportAction(ListenSocketTestAction(ACTION_LISTEN)); -} - -void DevToolsRemoteListenSocketTester::SendFromTester() { - connection_->Send(kChromeDevToolsHandshake); - ReportAction(ListenSocketTestAction(ACTION_SEND)); -} - -void DevToolsRemoteListenSocketTester::OnAcceptConnection( - net::ListenSocket* connection) { - connection_ = connection; - ReportAction(ListenSocketTestAction(ACTION_ACCEPT)); -} - -void DevToolsRemoteListenSocketTester::OnConnectionLost() { - connection_ = NULL; - ReportAction(ListenSocketTestAction(ACTION_CLOSE)); -} - -void DevToolsRemoteListenSocketTester::HandleMessage( - const DevToolsRemoteMessage& message) { - ReportAction(ListenSocketTestAction(ACTION_READ_MESSAGE, message)); -} - -bool DevToolsRemoteListenSocketTester::Send(SOCKET sock, - const std::string& str) { - int len = static_cast<int>(str.length()); - int send_len = HANDLE_EINTR(send(sock, str.data(), len, 0)); - if (send_len == SOCKET_ERROR) { - LOG(ERROR) << "send failed: " << errno; - return false; - } else if (send_len != len) { - return false; - } - return true; -} - -void DevToolsRemoteListenSocketTester::TestClientSend() { - ASSERT_TRUE(Send(test_socket_, kChromeDevToolsHandshake)); - { - ASSERT_TRUE(Send(test_socket_, kSimpleMessagePart1)); - // sleep for 10ms to test message split between \r and \n - base::PlatformThread::Sleep(10); - ASSERT_TRUE(Send(test_socket_, kSimpleMessagePart2)); - ASSERT_TRUE(NextAction(TestTimeouts::action_timeout_ms())); - ASSERT_EQ(ACTION_READ_MESSAGE, last_action_.type()); - const DevToolsRemoteMessage& message = last_action_.message(); - ASSERT_STREQ("V8Debugger", message.GetHeaderWithEmptyDefault( - DevToolsRemoteMessageHeaders::kTool).c_str()); - ASSERT_STREQ("2", message.GetHeaderWithEmptyDefault( - DevToolsRemoteMessageHeaders::kDestination).c_str()); - ASSERT_STREQ("0", message.GetHeaderWithEmptyDefault( - DevToolsRemoteMessageHeaders::kContentLength).c_str()); - ASSERT_EQ(0, static_cast<int>(message.content().size())); - } - ASSERT_TRUE(Send(test_socket_, kTwoMessages)); - { - ASSERT_TRUE(NextAction(TestTimeouts::action_timeout_ms())); - ASSERT_EQ(ACTION_READ_MESSAGE, last_action_.type()); - const DevToolsRemoteMessage& message = last_action_.message(); - ASSERT_STREQ("DevToolsService", message.tool().c_str()); - ASSERT_STREQ("", message.destination().c_str()); - ASSERT_EQ(300, message.content_length()); - const std::string& content = message.content(); - ASSERT_EQ(300, static_cast<int>(content.size())); - for (int i = 0; i < 300; ++i) { - ASSERT_EQ('0', content[i]); - } - } - { - ASSERT_TRUE(NextAction(TestTimeouts::action_timeout_ms())); - ASSERT_EQ(ACTION_READ_MESSAGE, last_action_.type()); - const DevToolsRemoteMessage& message = last_action_.message(); - ASSERT_STREQ("V8Debugger", message.GetHeaderWithEmptyDefault( - DevToolsRemoteMessageHeaders::kTool).c_str()); - ASSERT_STREQ("1", message.GetHeaderWithEmptyDefault( - DevToolsRemoteMessageHeaders::kDestination).c_str()); - ASSERT_STREQ("0", message.GetHeaderWithEmptyDefault( - DevToolsRemoteMessageHeaders::kContentLength).c_str()); - const std::string& content = message.content(); - ASSERT_EQ(0, static_cast<int>(content.size())); - } -} - -void DevToolsRemoteListenSocketTester::TestServerSend() { - loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &DevToolsRemoteListenSocketTester::SendFromTester)); - ASSERT_TRUE(NextAction(TestTimeouts::action_timeout_ms())); - ASSERT_EQ(ACTION_SEND, last_action_.type()); - // TODO(erikkay): Without this sleep, the recv seems to fail a small amount - // of the time. I could fix this by making the socket blocking, but then - // this test might hang in the case of errors. It would be nice to do - // something that felt more reliable here. - base::PlatformThread::Sleep(10); // sleep for 10ms - const int buf_len = 200; - char buf[buf_len+1]; - int recv_len = HANDLE_EINTR(recv(test_socket_, buf, buf_len, 0)); - ASSERT_NE(recv_len, SOCKET_ERROR); - buf[recv_len] = 0; - ASSERT_STREQ(buf, kChromeDevToolsHandshake); -} - -DevToolsRemoteListenSocketTester::~DevToolsRemoteListenSocketTester() {} - -class DevToolsRemoteListenSocketTest: public PlatformTest { - public: - DevToolsRemoteListenSocketTest() { - tester_ = NULL; - } - - virtual void SetUp() { - PlatformTest::SetUp(); - tester_ = new DevToolsRemoteListenSocketTester(); - tester_->SetUp(); - } - - virtual void TearDown() { - PlatformTest::TearDown(); - tester_->TearDown(); - tester_ = NULL; - } - - scoped_refptr<DevToolsRemoteListenSocketTester> tester_; -}; - -// This test is flaky; see comment in ::TestServerSend. -TEST_F(DevToolsRemoteListenSocketTest, ServerSend) { - tester_->TestServerSend(); -} - -TEST_F(DevToolsRemoteListenSocketTest, ClientSend) { - tester_->TestClientSend(); -} diff --git a/chrome/browser/debugger/devtools_remote_listen_socket_unittest.h b/chrome/browser/debugger/devtools_remote_listen_socket_unittest.h deleted file mode 100644 index 0b9b36b..0000000 --- a/chrome/browser/debugger/devtools_remote_listen_socket_unittest.h +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) 2011 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_DEVTOOLS_REMOTE_LISTEN_SOCKET_UNITTEST_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_LISTEN_SOCKET_UNITTEST_H_ -#pragma once - -#include "build/build_config.h" - -#include <deque> -#include <string> - -#if defined(OS_WIN) -#include <winsock2.h> -#elif defined(OS_POSIX) -#include <sys/socket.h> -#include <errno.h> -#include <semaphore.h> -#include <arpa/inet.h> -#endif - -#include "base/threading/thread.h" -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "base/message_loop.h" -#include "base/string_util.h" -#include "base/threading/thread.h" -#include "chrome/browser/debugger/devtools_remote.h" -#include "chrome/browser/debugger/devtools_remote_listen_socket.h" -#include "chrome/browser/debugger/devtools_remote_message.h" -#include "net/base/net_util.h" -#include "net/base/listen_socket.h" -#include "net/base/winsock_init.h" -#include "testing/gtest/include/gtest/gtest.h" - -#if defined(OS_POSIX) -// Used same name as in Windows to avoid #ifdef where refrenced -#define SOCKET int -const int INVALID_SOCKET = -1; -const int SOCKET_ERROR = -1; -#endif - -enum ActionType { - ACTION_NONE = 0, - ACTION_LISTEN = 1, - ACTION_ACCEPT = 2, - ACTION_READ = 3, - ACTION_READ_MESSAGE = 4, - ACTION_SEND = 5, - ACTION_CLOSE = 6, - ACTION_SHUTDOWN = 7 -}; - -class ListenSocketTestAction { - public: - ListenSocketTestAction(); - explicit ListenSocketTestAction(ActionType action); - ListenSocketTestAction(ActionType action, std::string data); - ListenSocketTestAction(ActionType action, - const DevToolsRemoteMessage& message); - ~ListenSocketTestAction(); - - const std::string data() const { return data_; } - const DevToolsRemoteMessage message() { return message_; } - ActionType type() const { return action_; } - - private: - ActionType action_; - std::string data_; - DevToolsRemoteMessage message_; -}; - - -// This had to be split out into a separate class because I couldn't -// make a the testing::Test class refcounted. -class DevToolsRemoteListenSocketTester : - public DevToolsRemoteListener { - public: - DevToolsRemoteListenSocketTester(); - - virtual void SetUp(); - virtual void TearDown(); - - void ReportAction(const ListenSocketTestAction& action); - bool NextAction(int timeout); - - // DevToolsRemoteMessageHandler interface - virtual void HandleMessage(const DevToolsRemoteMessage& message); - virtual void OnAcceptConnection(net::ListenSocket* connection); - virtual void OnConnectionLost(); - - // read all pending data from the test socket - int ClearTestSocket(); - // Release the connection and server sockets - void Shutdown(); - void Listen(); - void SendFromTester(); - virtual bool Send(SOCKET sock, const std::string& str); - // verify the send/read from client to server - void TestClientSend(); - // verify a send/read from server to client - void TestServerSend(); - -#if defined(OS_WIN) - CRITICAL_SECTION lock_; - HANDLE semaphore_; -#elif defined(OS_POSIX) - pthread_mutex_t lock_; - sem_t* semaphore_; -#endif - - scoped_ptr<base::Thread> thread_; - MessageLoopForIO* loop_; - net::ListenSocket* server_; - net::ListenSocket* connection_; - ListenSocketTestAction last_action_; - std::deque<ListenSocketTestAction> queue_; - SOCKET test_socket_; - static const int kTestPort; - - protected: - virtual net::ListenSocket* DoListen(); - - private: - virtual ~DevToolsRemoteListenSocketTester(); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_LISTEN_SOCKET_UNITTEST_H_ diff --git a/chrome/browser/debugger/devtools_remote_message.cc b/chrome/browser/debugger/devtools_remote_message.cc deleted file mode 100644 index 6d82a28..0000000 --- a/chrome/browser/debugger/devtools_remote_message.cc +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) 2010 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/devtools_remote_message.h" - -#include "base/string_number_conversions.h" - -const char DevToolsRemoteMessageHeaders::kContentLength[] = "Content-Length"; -const char DevToolsRemoteMessageHeaders::kTool[] = "Tool"; -const char DevToolsRemoteMessageHeaders::kDestination[] = "Destination"; - -const char DevToolsRemoteMessage::kEmptyValue[] = ""; - -DevToolsRemoteMessageBuilder& DevToolsRemoteMessageBuilder::instance() { - static DevToolsRemoteMessageBuilder instance_; - return instance_; -} - -DevToolsRemoteMessage::DevToolsRemoteMessage() {} - -DevToolsRemoteMessage::DevToolsRemoteMessage(const HeaderMap& headers, - const std::string& content) - : header_map_(headers), - content_(content) { -} - -DevToolsRemoteMessage::~DevToolsRemoteMessage() {} - -const std::string DevToolsRemoteMessage::GetHeader( - const std::string& header_name, - const std::string& default_value) const { - HeaderMap::const_iterator it = header_map_.find(header_name); - if (it == header_map_.end()) { - return default_value; - } - return it->second; -} - -const std::string DevToolsRemoteMessage::GetHeaderWithEmptyDefault( - const std::string& header_name) const { - return GetHeader(header_name, DevToolsRemoteMessage::kEmptyValue); -} - -const std::string DevToolsRemoteMessage::ToString() const { - std::string result; - for (HeaderMap::const_iterator it = header_map_.begin(), - end = header_map_.end(); it != end; ++it) { - result.append(it->first).append(":").append(it->second).append("\r\n"); - } - result.append("\r\n").append(content_); - return result; -} - -DevToolsRemoteMessage* DevToolsRemoteMessageBuilder::Create( - const std::string& tool, - const std::string& destination, - const std::string& content) { - DevToolsRemoteMessage::HeaderMap headers; - headers[DevToolsRemoteMessageHeaders::kContentLength] = - base::IntToString(content.size()); - headers[DevToolsRemoteMessageHeaders::kTool] = tool; - headers[DevToolsRemoteMessageHeaders::kDestination] = destination; - return new DevToolsRemoteMessage(headers, content); -} diff --git a/chrome/browser/debugger/devtools_remote_message.h b/chrome/browser/debugger/devtools_remote_message.h deleted file mode 100644 index e836164..0000000 --- a/chrome/browser/debugger/devtools_remote_message.h +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) 2010 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_DEVTOOLS_REMOTE_MESSAGE_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_MESSAGE_H_ -#pragma once - -#include <string> - -#include "base/basictypes.h" -#include "base/hash_tables.h" - -// Contains DevTools protocol message header names -// and the Flags header bit field constants. -struct DevToolsRemoteMessageHeaders { - // The content length in decimal. - static const char kContentLength[]; - // The tool that should handle the message. - static const char kTool[]; - // The destination (inspected) object identifier (if any), like a TabID. - static const char kDestination[]; -}; - -// Represents a Chrome remote debugging protocol message transferred -// over the wire between the remote debugger and a Chrome instance. -// Consider using DevToolsRemoteMessageBuilder (see end of this file) for easy -// construction of outbound (Chrome -> remote debugger) messages. -class DevToolsRemoteMessage { - public: - typedef base::hash_map<std::string, std::string> HeaderMap; - - // Use this as the second parameter in a |GetHeader| call to use - // an empty string as the default value. - static const char kEmptyValue[]; - - // Constructs an empty message with no content or headers. - DevToolsRemoteMessage(); - DevToolsRemoteMessage(const HeaderMap& headers, const std::string& content); - virtual ~DevToolsRemoteMessage(); - - const HeaderMap& headers() const { - return header_map_; - } - - const std::string& content() const { - return content_; - } - - int content_length() const { - return content_.size(); - } - - const std::string tool() const { - return GetHeaderWithEmptyDefault(DevToolsRemoteMessageHeaders::kTool); - } - - const std::string destination() const { - return GetHeaderWithEmptyDefault( - DevToolsRemoteMessageHeaders::kDestination); - } - - // Returns the header value providing default_value if the header is absent. - const std::string GetHeader(const std::string& header_name, - const std::string& default_value) const; - - // Returns the header value providing an empty string if the header is absent. - const std::string GetHeaderWithEmptyDefault( - const std::string& header_name) const; - - // Returns a string representation of the message useful for the transfer to - // the remote debugger. - const std::string ToString() const; - - private: - HeaderMap header_map_; - std::string content_; - // Cannot DISALLOW_COPY_AND_ASSIGN(DevToolsRemoteMessage) since it is passed - // as an IPC message argument and needs to be copied. -}; - -// Facilitates easy construction of outbound (Chrome -> remote debugger) -// DevToolsRemote messages. -class DevToolsRemoteMessageBuilder { - public: - // A singleton instance getter. - static DevToolsRemoteMessageBuilder& instance(); - // Creates a message given the certain header values and a payload. - DevToolsRemoteMessage* Create(const std::string& tool, - const std::string& destination, - const std::string& payload); - - private: - DevToolsRemoteMessageBuilder() {} - virtual ~DevToolsRemoteMessageBuilder() {} - DISALLOW_COPY_AND_ASSIGN(DevToolsRemoteMessageBuilder); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_MESSAGE_H_ diff --git a/chrome/browser/debugger/devtools_remote_message_unittest.cc b/chrome/browser/debugger/devtools_remote_message_unittest.cc deleted file mode 100644 index 670cd79..0000000 --- a/chrome/browser/debugger/devtools_remote_message_unittest.cc +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2011 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 <string> - -#include "base/memory/scoped_ptr.h" -#include "base/string_number_conversions.h" -#include "chrome/browser/debugger/devtools_remote.h" -#include "chrome/browser/debugger/devtools_remote_message.h" -#include "testing/gtest/include/gtest/gtest.h" - -class DevToolsRemoteMessageTest : public testing::Test { - public: - DevToolsRemoteMessageTest() : testing::Test() {} - - protected: - virtual void SetUp() { - testing::Test::SetUp(); - } -}; - -TEST_F(DevToolsRemoteMessageTest, ConstructInstanceManually) { - DevToolsRemoteMessage::HeaderMap headers; - std::string content = "{\"command\":\"ping\"}"; - headers[DevToolsRemoteMessageHeaders::kTool] = "DevToolsService"; - headers[DevToolsRemoteMessageHeaders::kContentLength] = - base::IntToString(content.size()); - - DevToolsRemoteMessage message(headers, content); - ASSERT_STREQ("DevToolsService", - message.GetHeaderWithEmptyDefault( - DevToolsRemoteMessageHeaders::kTool).c_str()); - ASSERT_STREQ("DevToolsService", message.tool().c_str()); - ASSERT_STREQ(content.c_str(), message.content().c_str()); - ASSERT_EQ(content.size(), - static_cast<std::string::size_type>(message.content_length())); - ASSERT_EQ(static_cast<DevToolsRemoteMessage::HeaderMap::size_type>(2), - message.headers().size()); -} - -TEST_F(DevToolsRemoteMessageTest, ConstructWithBuilder) { - std::string content = "Responsecontent"; - scoped_ptr<DevToolsRemoteMessage> message( - DevToolsRemoteMessageBuilder::instance().Create( - "V8Debugger", // tool - "2", // destination - content)); // content - - ASSERT_EQ(static_cast<DevToolsRemoteMessage::HeaderMap::size_type>(3), - message->headers().size()); - ASSERT_STREQ( - "V8Debugger", - message->GetHeaderWithEmptyDefault( - DevToolsRemoteMessageHeaders::kTool).c_str()); - ASSERT_STREQ( - "V8Debugger", - message->tool().c_str()); - ASSERT_STREQ( - "2", - message->GetHeaderWithEmptyDefault( - DevToolsRemoteMessageHeaders::kDestination).c_str()); - ASSERT_STREQ( - "2", - message->destination().c_str()); - ASSERT_EQ(content.size(), - static_cast<DevToolsRemoteMessage::HeaderMap::size_type>( - message->content_length())); - ASSERT_STREQ(content.c_str(), message->content().c_str()); -} diff --git a/chrome/browser/debugger/devtools_remote_service.cc b/chrome/browser/debugger/devtools_remote_service.cc deleted file mode 100644 index a8f57a3..0000000 --- a/chrome/browser/debugger/devtools_remote_service.cc +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2011 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/devtools_remote_service.h" - -#include <string> - -#include "base/json/json_reader.h" -#include "base/json/json_writer.h" -#include "base/memory/scoped_ptr.h" -#include "base/values.h" -#include "chrome/browser/debugger/devtools_manager.h" -#include "chrome/browser/debugger/devtools_protocol_handler.h" -#include "chrome/browser/debugger/devtools_remote_message.h" -#include "chrome/browser/debugger/inspectable_tab_proxy.h" -#include "chrome/browser/sessions/restore_tab_helper.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "content/browser/tab_contents/navigation_controller.h" -#include "content/browser/tab_contents/navigation_entry.h" -#include "content/common/devtools_messages.h" - -const char DevToolsRemoteServiceCommand::kPing[] = "ping"; -const char DevToolsRemoteServiceCommand::kVersion[] = "version"; -const char DevToolsRemoteServiceCommand::kListTabs[] = "list_tabs"; - -const char DevToolsRemoteService::kToolName[] = "DevToolsService"; - -namespace { -const char kCommandKey[] = "command"; -const char kDataKey[] = "data"; -const char kResultKey[] = "result"; -} // namespace - -DevToolsRemoteService::DevToolsRemoteService(DevToolsProtocolHandler* delegate) - : delegate_(delegate) {} - -DevToolsRemoteService::~DevToolsRemoteService() {} - -void DevToolsRemoteService::HandleMessage( - const DevToolsRemoteMessage& message) { - scoped_ptr<Value> request(base::JSONReader::Read(message.content(), false)); - if (request.get() == NULL) { - // Bad JSON - NOTREACHED(); - return; - } - DictionaryValue* json; - if (request->IsType(Value::TYPE_DICTIONARY)) { - json = static_cast<DictionaryValue*>(request.get()); - if (!json->HasKey(kCommandKey)) { - NOTREACHED(); // Broken protocol - no "command" specified - return; - } - } else { - NOTREACHED(); // Broken protocol - not a JS object - return; - } - ProcessJson(json, message); -} - -void DevToolsRemoteService::ProcessJson(DictionaryValue* json, - const DevToolsRemoteMessage& message) { - static const std::string kOkResponse = "ok"; // "Ping" response - static const std::string kVersion = "0.1"; // Current protocol version - std::string command; - DictionaryValue response; - - json->GetString(kCommandKey, &command); - response.SetString(kCommandKey, command); - - if (command == DevToolsRemoteServiceCommand::kPing) { - response.SetInteger(kResultKey, Result::kOk); - response.SetString(kDataKey, kOkResponse); - } else if (command == DevToolsRemoteServiceCommand::kVersion) { - response.SetInteger(kResultKey, Result::kOk); - response.SetString(kDataKey, kVersion); - } else if (command == DevToolsRemoteServiceCommand::kListTabs) { - ListValue* data = new ListValue(); - const InspectableTabProxy::TabMap& tab_map = - delegate_->inspectable_tab_proxy()->tab_map(); - for (InspectableTabProxy::TabMap::const_iterator it = - tab_map.begin(), end = tab_map.end(); it != end; ++it) { - NavigationEntry* entry = it->second->controller().GetActiveEntry(); - if (entry == NULL) { - continue; - } - if (entry->url().is_valid()) { - ListValue* tab = new ListValue(); - tab->Append(Value::CreateIntegerValue( - it->second->restore_tab_helper()->session_id().id())); - tab->Append(Value::CreateStringValue(entry->url().spec())); - data->Append(tab); - } - } - response.SetInteger(kResultKey, Result::kOk); - response.Set(kDataKey, data); - } else { - // Unknown protocol command. - NOTREACHED(); - response.SetInteger(kResultKey, Result::kUnknownCommand); - } - std::string response_json; - base::JSONWriter::Write(&response, false, &response_json); - scoped_ptr<DevToolsRemoteMessage> response_message( - DevToolsRemoteMessageBuilder::instance().Create(message.tool(), - message.destination(), - response_json)); - delegate_->Send(*response_message.get()); -} diff --git a/chrome/browser/debugger/devtools_remote_service.h b/chrome/browser/debugger/devtools_remote_service.h deleted file mode 100644 index bd813bd..0000000 --- a/chrome/browser/debugger/devtools_remote_service.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2010 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_DEVTOOLS_REMOTE_SERVICE_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_SERVICE_H_ -#pragma once - -#include "base/basictypes.h" -#include "chrome/browser/debugger/devtools_remote.h" - -class DevToolsRemoteMessage; -class DevToolsProtocolHandler; -class DictionaryValue; -class Value; - -// Contains constants for DevToolsRemoteService tool protocol commands. -struct DevToolsRemoteServiceCommand { - static const char kPing[]; - static const char kVersion[]; - static const char kListTabs[]; -}; - -// Handles Chrome remote debugger protocol service commands. -class DevToolsRemoteService : public DevToolsRemoteListener { - public: - explicit DevToolsRemoteService(DevToolsProtocolHandler* delegate); - - // DevToolsRemoteListener interface - virtual void HandleMessage(const DevToolsRemoteMessage& message); - virtual void OnConnectionLost() {} - - static const char kToolName[]; - - private: - // Operation result returned in the "result" field. - struct Result { - static const int kOk = 0; - static const int kUnknownCommand = 1; - }; - virtual ~DevToolsRemoteService(); - void ProcessJson(DictionaryValue* json, const DevToolsRemoteMessage& message); - DevToolsProtocolHandler* delegate_; - DISALLOW_COPY_AND_ASSIGN(DevToolsRemoteService); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_SERVICE_H_ diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc deleted file mode 100644 index e07f06c..0000000 --- a/chrome/browser/debugger/devtools_sanity_unittest.cc +++ /dev/null @@ -1,329 +0,0 @@ -// Copyright (c) 2011 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 "base/command_line.h" -#include "base/path_service.h" -#include "base/stringprintf.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/debugger/devtools_client_host.h" -#include "chrome/browser/debugger/devtools_manager.h" -#include "chrome/browser/debugger/devtools_window.h" -#include "chrome/browser/extensions/extension_host.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/test/in_process_browser_test.h" -#include "chrome/test/ui_test_utils.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/common/notification_registrar.h" -#include "content/common/notification_service.h" -#include "net/test/test_server.h" - -namespace { - -// Used to block until a dev tools client window's browser is closed. -class BrowserClosedObserver : public NotificationObserver { - public: - explicit BrowserClosedObserver(Browser* browser) { - registrar_.Add(this, NotificationType::BROWSER_CLOSED, - Source<Browser>(browser)); - ui_test_utils::RunMessageLoop(); - } - - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - MessageLoopForUI::current()->Quit(); - } - - private: - NotificationRegistrar registrar_; - DISALLOW_COPY_AND_ASSIGN(BrowserClosedObserver); -}; - -// The delay waited in some cases where we don't have a notifications for an -// action we take. -const int kActionDelayMs = 500; - -const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html"; -const char kPauseWhenLoadingDevTools[] = - "files/devtools/pause_when_loading_devtools.html"; -const char kPauseWhenScriptIsRunning[] = - "files/devtools/pause_when_script_is_running.html"; -const char kPageWithContentScript[] = - "files/devtools/page_with_content_script.html"; -const char kChunkedTestPage[] = "chunked"; -const char kSlowTestPage[] = - "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; - - -class DevToolsSanityTest : public InProcessBrowserTest { - public: - DevToolsSanityTest() { - set_show_window(true); - EnableDOMAutomation(); - } - - protected: - void RunTest(const std::string& test_name, const std::string& test_page) { - OpenDevToolsWindow(test_page); - std::string result; - - // At first check that JavaScript part of the front-end is loaded by - // checking that global variable uiTests exists(it's created after all js - // files have been loaded) and has runTest method. - ASSERT_TRUE( - ui_test_utils::ExecuteJavaScriptAndExtractString( - client_contents_->render_view_host(), - L"", - L"window.domAutomationController.send(" - L"'' + (window.uiTests && (typeof uiTests.runTest)));", - &result)); - - if (result == "function") { - ASSERT_TRUE( - ui_test_utils::ExecuteJavaScriptAndExtractString( - client_contents_->render_view_host(), - L"", - UTF8ToWide(base::StringPrintf("uiTests.runTest('%s')", - test_name.c_str())), - &result)); - EXPECT_EQ("[OK]", result); - } else { - FAIL() << "DevTools front-end is broken."; - } - CloseDevToolsWindow(); - } - - void OpenDevToolsWindow(const std::string& test_page) { - ASSERT_TRUE(test_server()->Start()); - GURL url = test_server()->GetURL(test_page); - ui_test_utils::NavigateToURL(browser(), url); - - inspected_rvh_ = GetInspectedTab()->render_view_host(); - DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); - devtools_manager->OpenDevToolsWindow(inspected_rvh_); - - DevToolsClientHost* client_host = - devtools_manager->GetDevToolsClientHostFor(inspected_rvh_); - window_ = client_host->AsDevToolsWindow(); - RenderViewHost* client_rvh = window_->GetRenderViewHost(); - client_contents_ = client_rvh->delegate()->GetAsTabContents(); - ui_test_utils::WaitForNavigation(&client_contents_->controller()); - } - - TabContents* GetInspectedTab() { - return browser()->GetTabContentsAt(0); - } - - void CloseDevToolsWindow() { - DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); - // UnregisterDevToolsClientHostFor may destroy window_ so store the browser - // first. - Browser* browser = window_->browser(); - devtools_manager->UnregisterDevToolsClientHostFor(inspected_rvh_); - - // Wait only when DevToolsWindow has a browser. For docked DevTools, this - // is NULL and we skip the wait. - if (browser) - BrowserClosedObserver close_observer(browser); - } - - TabContents* client_contents_; - DevToolsWindow* window_; - RenderViewHost* inspected_rvh_; -}; - - -class CancelableQuitTask : public Task { - public: - explicit CancelableQuitTask(const std::string& timeout_message) - : timeout_message_(timeout_message), - cancelled_(false) { - } - - void cancel() { - cancelled_ = true; - } - - virtual void Run() { - if (cancelled_) { - return; - } - FAIL() << timeout_message_; - MessageLoop::current()->Quit(); - } - - private: - std::string timeout_message_; - bool cancelled_; -}; - - -// Base class for DevTools tests that test devtools functionality for -// extensions and content scripts. -class DevToolsExtensionDebugTest : public DevToolsSanityTest, - public NotificationObserver { - public: - DevToolsExtensionDebugTest() : DevToolsSanityTest() { - PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_); - test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools"); - test_extensions_dir_ = test_extensions_dir_.AppendASCII("extensions"); - } - - protected: - // Load an extention from test\data\devtools\extensions\<extension_name> - void LoadExtension(const char* extension_name) { - FilePath path = test_extensions_dir_.AppendASCII(extension_name); - ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension."; - } - - private: - bool LoadExtensionFromPath(const FilePath& path) { - ExtensionService* service = browser()->profile()->GetExtensionService(); - size_t num_before = service->extensions()->size(); - { - NotificationRegistrar registrar; - registrar.Add(this, NotificationType::EXTENSION_LOADED, - NotificationService::AllSources()); - CancelableQuitTask* delayed_quit = - new CancelableQuitTask("Extension load timed out."); - MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit, - 4*1000); - service->LoadExtension(path); - ui_test_utils::RunMessageLoop(); - delayed_quit->cancel(); - } - size_t num_after = service->extensions()->size(); - if (num_after != (num_before + 1)) - return false; - - return WaitForExtensionHostsToLoad(); - } - - bool WaitForExtensionHostsToLoad() { - // Wait for all the extension hosts that exist to finish loading. - // NOTE: This assumes that the extension host list is not changing while - // this method is running. - - NotificationRegistrar registrar; - registrar.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING, - NotificationService::AllSources()); - CancelableQuitTask* delayed_quit = - new CancelableQuitTask("Extension host load timed out."); - MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit, - 4*1000); - - ExtensionProcessManager* manager = - browser()->profile()->GetExtensionProcessManager(); - for (ExtensionProcessManager::const_iterator iter = manager->begin(); - iter != manager->end();) { - if ((*iter)->did_stop_loading()) - ++iter; - else - ui_test_utils::RunMessageLoop(); - } - - delayed_quit->cancel(); - return true; - } - - void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - switch (type.value) { - case NotificationType::EXTENSION_LOADED: - case NotificationType::EXTENSION_HOST_DID_STOP_LOADING: - MessageLoopForUI::current()->Quit(); - break; - default: - NOTREACHED(); - break; - } - } - - FilePath test_extensions_dir_; -}; - -// Tests scripts panel showing. -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestShowScriptsTab) { - RunTest("testShowScriptsTab", kDebuggerTestPage); -} - -// Tests that scripts tab is populated with inspected scripts even if it -// hadn't been shown by the moment inspected paged refreshed. -// @see http://crbug.com/26312 -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, - TestScriptsTabIsPopulatedOnInspectedPageRefresh) { - // Clear inspector settings to ensure that Elements will be - // current panel when DevTools window is open. - GetInspectedTab()->render_view_host()->delegate()->ClearInspectorSettings(); - RunTest("testScriptsTabIsPopulatedOnInspectedPageRefresh", - kDebuggerTestPage); -} - -// Tests that a content script is in the scripts list. -// This test is disabled, see bug 28961. -IN_PROC_BROWSER_TEST_F(DevToolsExtensionDebugTest, - TestContentScriptIsPresent) { - LoadExtension("simple_content_script"); - RunTest("testContentScriptIsPresent", kPageWithContentScript); -} - -// Tests that scripts are not duplicated after Scripts Panel switch. -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, - TestNoScriptDuplicatesOnPanelSwitch) { - RunTest("testNoScriptDuplicatesOnPanelSwitch", kDebuggerTestPage); -} - -// Tests that debugger works correctly if pause event occurs when DevTools -// frontend is being loaded. -// Flaky - http://crbug.com/69719. -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, FLAKY_TestPauseWhenLoadingDevTools) { - RunTest("testPauseWhenLoadingDevTools", kPauseWhenLoadingDevTools); -} - -// Tests that pressing 'Pause' will pause script execution if the script -// is already running. -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, FLAKY_TestPauseWhenScriptIsRunning) { - RunTest("testPauseWhenScriptIsRunning", kPauseWhenScriptIsRunning); -} - -// Tests network timing. -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkTiming) { - RunTest("testNetworkTiming", kSlowTestPage); -} - -// Tests network size. -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSize) { - RunTest("testNetworkSize", kChunkedTestPage); -} - -// Tests raw headers text. -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSyncSize) { - RunTest("testNetworkSyncSize", kChunkedTestPage); -} - -// Tests raw headers text. -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkRawHeadersText) { - RunTest("testNetworkRawHeadersText", kChunkedTestPage); -} - -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestPageWithNoJavaScript) { - OpenDevToolsWindow("about:blank"); - std::string result; - ASSERT_TRUE( - ui_test_utils::ExecuteJavaScriptAndExtractString( - client_contents_->render_view_host(), - L"", - L"window.domAutomationController.send(" - L"'' + (window.uiTests && (typeof uiTests.runTest)));", - &result)); - ASSERT_EQ("function", result) << "DevTools front-end is broken."; - CloseDevToolsWindow(); -} - -} // namespace diff --git a/chrome/browser/debugger/devtools_toggle_action.h b/chrome/browser/debugger/devtools_toggle_action.h deleted file mode 100644 index 33b0321..0000000 --- a/chrome/browser/debugger/devtools_toggle_action.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2010 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_DEVTOOLS_TOGGLE_ACTION_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_TOGGLE_ACTION_H_ -#pragma once - -enum DevToolsToggleAction { - DEVTOOLS_TOGGLE_ACTION_NONE, - DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE, - DEVTOOLS_TOGGLE_ACTION_INSPECT -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_TOGGLE_ACTION_H_ diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc deleted file mode 100644 index dd24777..0000000 --- a/chrome/browser/debugger/devtools_window.cc +++ /dev/null @@ -1,474 +0,0 @@ -// Copyright (c) 2011 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 "base/command_line.h" -#include "base/json/json_writer.h" -#include "base/stringprintf.h" -#include "base/string_number_conversions.h" -#include "base/utf_string_conversions.h" -#include "base/values.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/debugger/devtools_manager.h" -#include "chrome/browser/debugger/devtools_window.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/prefs/scoped_user_pref_update.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sessions/restore_tab_helper.h" -#include "chrome/browser/tabs/tab_strip_model.h" -#include "chrome/browser/themes/theme_service.h" -#include "chrome/browser/themes/theme_service_factory.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/url_constants.h" -#include "content/browser/in_process_webkit/session_storage_namespace.h" -#include "content/browser/load_notification_details.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/navigation_controller.h" -#include "content/browser/tab_contents/navigation_entry.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/browser/tab_contents/tab_contents_view.h" -#include "content/common/bindings_policy.h" -#include "content/common/notification_service.h" -#include "grit/generated_resources.h" - -const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; - -// static -TabContentsWrapper* DevToolsWindow::GetDevToolsContents( - TabContents* inspected_tab) { - if (!inspected_tab) { - return NULL; - } - - if (!DevToolsManager::GetInstance()) - return NULL; // Happens only in tests. - - DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> - GetDevToolsClientHostFor(inspected_tab->render_view_host()); - if (!client_host) { - return NULL; - } - - DevToolsWindow* window = client_host->AsDevToolsWindow(); - if (!window || !window->is_docked()) { - return NULL; - } - return window->tab_contents(); -} - -DevToolsWindow::DevToolsWindow(Profile* profile, - RenderViewHost* inspected_rvh, - bool docked) - : profile_(profile), - inspected_tab_(NULL), - browser_(NULL), - docked_(docked), - is_loaded_(false), - action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) { - // Create TabContents with devtools. - tab_contents_ = - Browser::TabContentsFactory(profile, NULL, MSG_ROUTING_NONE, NULL, NULL); - tab_contents_->tab_contents()-> - render_view_host()->AllowBindings(BindingsPolicy::WEB_UI); - tab_contents_->controller().LoadURL( - GetDevToolsUrl(), GURL(), PageTransition::START_PAGE); - - // Wipe out page icon so that the default application icon is used. - NavigationEntry* entry = tab_contents_->controller().GetActiveEntry(); - entry->favicon().set_bitmap(SkBitmap()); - entry->favicon().set_is_valid(true); - - // Register on-load actions. - registrar_.Add(this, - NotificationType::LOAD_STOP, - Source<NavigationController>(&tab_contents_->controller())); - registrar_.Add(this, - NotificationType::TAB_CLOSING, - Source<NavigationController>(&tab_contents_->controller())); - registrar_.Add( - this, - NotificationType::BROWSER_THEME_CHANGED, - Source<ThemeService>(ThemeServiceFactory::GetForProfile(profile_))); - TabContents* tab = inspected_rvh->delegate()->GetAsTabContents(); - if (tab) - inspected_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); -} - -DevToolsWindow::~DevToolsWindow() { -} - -DevToolsWindow* DevToolsWindow::AsDevToolsWindow() { - return this; -} - -void DevToolsWindow::SendMessageToClient(const IPC::Message& message) { - RenderViewHost* target_host = - tab_contents_->tab_contents()->render_view_host(); - IPC::Message* m = new IPC::Message(message); - m->set_routing_id(target_host->routing_id()); - target_host->Send(m); -} - -void DevToolsWindow::InspectedTabClosing() { - if (docked_) { - // Update dev tools to reflect removed dev tools window. - - BrowserWindow* inspected_window = GetInspectedBrowserWindow(); - if (inspected_window) - inspected_window->UpdateDevTools(); - // In case of docked tab_contents we own it, so delete here. - delete tab_contents_; - - delete this; - } else { - // First, initiate self-destruct to free all the registrars. - // Then close all tabs. Browser will take care of deleting tab_contents - // for us. - Browser* browser = browser_; - delete this; - browser->CloseAllTabs(); - } -} - -void DevToolsWindow::TabReplaced(TabContentsWrapper* new_tab) { - DCHECK_EQ(profile_, new_tab->profile()); - inspected_tab_ = new_tab; -} - -void DevToolsWindow::Show(DevToolsToggleAction action) { - if (docked_) { - Browser* inspected_browser; - int inspected_tab_index; - // Tell inspected browser to update splitter and switch to inspected panel. - if (!IsInspectedBrowserPopupOrPanel() && - FindInspectedBrowserAndTabIndex(&inspected_browser, - &inspected_tab_index)) { - BrowserWindow* inspected_window = inspected_browser->window(); - tab_contents_->tab_contents()->set_delegate(this); - inspected_window->UpdateDevTools(); - tab_contents_->view()->SetInitialFocus(); - inspected_window->Show(); - TabStripModel* tabstrip_model = inspected_browser->tabstrip_model(); - tabstrip_model->ActivateTabAt(inspected_tab_index, true); - ScheduleAction(action); - return; - } else { - // Sometimes we don't know where to dock. Stay undocked. - docked_ = false; - UpdateFrontendAttachedState(); - } - } - - // Avoid consecutive window switching if the devtools window has been opened - // and the Inspect Element shortcut is pressed in the inspected tab. - bool should_show_window = - !browser_ || action != DEVTOOLS_TOGGLE_ACTION_INSPECT; - - if (!browser_) - CreateDevToolsBrowser(); - - if (should_show_window) { - browser_->window()->Show(); - tab_contents_->view()->SetInitialFocus(); - } - - ScheduleAction(action); -} - -void DevToolsWindow::Activate() { - if (!docked_) { - if (!browser_->window()->IsActive()) { - browser_->window()->Activate(); - } - } else { - BrowserWindow* inspected_window = GetInspectedBrowserWindow(); - if (inspected_window) - tab_contents_->view()->Focus(); - } -} - -void DevToolsWindow::SetDocked(bool docked) { - if (docked_ == docked) - return; - if (docked && (!GetInspectedBrowserWindow() || - IsInspectedBrowserPopupOrPanel())) { - // Cannot dock, avoid window flashing due to close-reopen cycle. - return; - } - docked_ = docked; - - if (docked) { - // Detach window from the external devtools browser. It will lead to - // the browser object's close and delete. Remove observer first. - TabStripModel* tabstrip_model = browser_->tabstrip_model(); - tabstrip_model->DetachTabContentsAt( - tabstrip_model->GetIndexOfTabContents(tab_contents_)); - browser_ = NULL; - } else { - // Update inspected window to hide split and reset it. - BrowserWindow* inspected_window = GetInspectedBrowserWindow(); - if (inspected_window) { - inspected_window->UpdateDevTools(); - inspected_window = NULL; - } - } - Show(DEVTOOLS_TOGGLE_ACTION_NONE); -} - -RenderViewHost* DevToolsWindow::GetRenderViewHost() { - return tab_contents_->render_view_host(); -} - -void DevToolsWindow::CreateDevToolsBrowser() { - // TODO(pfeldman): Make browser's getter for this key static. - std::string wp_key; - wp_key.append(prefs::kBrowserWindowPlacement); - wp_key.append("_"); - wp_key.append(kDevToolsApp); - - PrefService* prefs = profile_->GetPrefs(); - if (!prefs->FindPreference(wp_key.c_str())) { - prefs->RegisterDictionaryPref(wp_key.c_str(), PrefService::UNSYNCABLE_PREF); - } - - const DictionaryValue* wp_pref = prefs->GetDictionary(wp_key.c_str()); - if (!wp_pref || wp_pref->empty()) { - DictionaryPrefUpdate update(prefs, wp_key.c_str()); - DictionaryValue* defaults = update.Get(); - defaults->SetInteger("left", 100); - defaults->SetInteger("top", 100); - defaults->SetInteger("right", 740); - defaults->SetInteger("bottom", 740); - defaults->SetBoolean("maximized", false); - defaults->SetBoolean("always_on_top", false); - } - - browser_ = Browser::CreateForDevTools(profile_); - browser_->tabstrip_model()->AddTabContents( - tab_contents_, -1, PageTransition::START_PAGE, TabStripModel::ADD_ACTIVE); -} - -bool DevToolsWindow::FindInspectedBrowserAndTabIndex(Browser** browser, - int* tab) { - if (!inspected_tab_) - return false; - - const NavigationController& controller = inspected_tab_->controller(); - for (BrowserList::const_iterator it = BrowserList::begin(); - it != BrowserList::end(); ++it) { - int tab_index = (*it)->GetIndexOfController(&controller); - if (tab_index != TabStripModel::kNoTab) { - *browser = *it; - *tab = tab_index; - return true; - } - } - return false; -} - -BrowserWindow* DevToolsWindow::GetInspectedBrowserWindow() { - Browser* browser = NULL; - int tab; - return FindInspectedBrowserAndTabIndex(&browser, &tab) ? - browser->window() : NULL; -} - -bool DevToolsWindow::IsInspectedBrowserPopupOrPanel() { - Browser* browser = NULL; - int tab; - if (!FindInspectedBrowserAndTabIndex(&browser, &tab)) - return false; - - return browser->is_type_popup() || browser->is_type_panel(); -} - -void DevToolsWindow::UpdateFrontendAttachedState() { - tab_contents_->render_view_host()->ExecuteJavascriptInWebFrame( - string16(), - docked_ ? ASCIIToUTF16("WebInspector.setAttachedWindow(true);") - : ASCIIToUTF16("WebInspector.setAttachedWindow(false);")); -} - - -void DevToolsWindow::AddDevToolsExtensionsToClient() { - if (inspected_tab_) { - FundamentalValue tabId( - inspected_tab_->restore_tab_helper()->session_id().id()); - CallClientFunction(ASCIIToUTF16("WebInspector.setInspectedTabId"), tabId); - } - ListValue results; - const ExtensionService* extension_service = - tab_contents_->tab_contents()->profile()-> - GetOriginalProfile()->GetExtensionService(); - if (!extension_service) - return; - - const ExtensionList* extensions = extension_service->extensions(); - - for (ExtensionList::const_iterator extension = extensions->begin(); - extension != extensions->end(); ++extension) { - if ((*extension)->devtools_url().is_empty()) - continue; - DictionaryValue* extension_info = new DictionaryValue(); - extension_info->Set("startPage", - new StringValue((*extension)->devtools_url().spec())); - results.Append(extension_info); - } - CallClientFunction(ASCIIToUTF16("WebInspector.addExtensions"), results); -} - -void DevToolsWindow::OpenURLFromTab(TabContents* source, - const GURL& url, - const GURL& referrer, - WindowOpenDisposition disposition, - PageTransition::Type transition) { - if (inspected_tab_) { - inspected_tab_->tab_contents()->OpenURL( - url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); - } -} - -void DevToolsWindow::CallClientFunction(const string16& function_name, - const Value& arg) { - std::string json; - base::JSONWriter::Write(&arg, false, &json); - string16 javascript = function_name + char16('(') + UTF8ToUTF16(json) + - ASCIIToUTF16(");"); - tab_contents_->render_view_host()-> - ExecuteJavascriptInWebFrame(string16(), javascript); -} - -void DevToolsWindow::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::LOAD_STOP && !is_loaded_) { - is_loaded_ = true; - UpdateTheme(); - DoAction(); - AddDevToolsExtensionsToClient(); - } else if (type == NotificationType::TAB_CLOSING) { - if (Source<NavigationController>(source).ptr() == - &tab_contents_->controller()) { - // This happens when browser closes all of its tabs as a result - // of window.Close event. - // Notify manager that this DevToolsClientHost no longer exists and - // initiate self-destuct here. - NotifyCloseListener(); - delete this; - } - } else if (type == NotificationType::BROWSER_THEME_CHANGED) { - UpdateTheme(); - } -} - -void DevToolsWindow::ScheduleAction(DevToolsToggleAction action) { - action_on_load_ = action; - if (is_loaded_) - DoAction(); -} - -void DevToolsWindow::DoAction() { - UpdateFrontendAttachedState(); - // TODO: these messages should be pushed through the WebKit API instead. - switch (action_on_load_) { - case DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE: - tab_contents_->render_view_host()->ExecuteJavascriptInWebFrame( - string16(), ASCIIToUTF16("WebInspector.showConsole();")); - break; - case DEVTOOLS_TOGGLE_ACTION_INSPECT: - tab_contents_->render_view_host()->ExecuteJavascriptInWebFrame( - string16(), ASCIIToUTF16("WebInspector.toggleSearchingForNode();")); - case DEVTOOLS_TOGGLE_ACTION_NONE: - // Do nothing. - break; - default: - NOTREACHED(); - } - action_on_load_ = DEVTOOLS_TOGGLE_ACTION_NONE; -} - -std::string SkColorToRGBAString(SkColor color) { - // We convert the alpha using DoubleToString because StringPrintf will use - // locale specific formatters (e.g., use , instead of . in German). - return StringPrintf("rgba(%d,%d,%d,%s)", SkColorGetR(color), - SkColorGetG(color), SkColorGetB(color), - base::DoubleToString(SkColorGetA(color) / 255.0).c_str()); -} - -GURL DevToolsWindow::GetDevToolsUrl() { - ThemeService* tp = ThemeServiceFactory::GetForProfile(profile_); - CHECK(tp); - - SkColor color_toolbar = - tp->GetColor(ThemeService::COLOR_TOOLBAR); - SkColor color_tab_text = - tp->GetColor(ThemeService::COLOR_BOOKMARK_TEXT); - - std::string url_string = StringPrintf( - "%sdevtools.html?docked=%s&toolbar_color=%s&text_color=%s", - chrome::kChromeUIDevToolsURL, - docked_ ? "true" : "false", - SkColorToRGBAString(color_toolbar).c_str(), - SkColorToRGBAString(color_tab_text).c_str()); - return GURL(url_string); -} - -void DevToolsWindow::UpdateTheme() { - ThemeService* tp = ThemeServiceFactory::GetForProfile(profile_); - CHECK(tp); - - SkColor color_toolbar = - tp->GetColor(ThemeService::COLOR_TOOLBAR); - SkColor color_tab_text = - tp->GetColor(ThemeService::COLOR_BOOKMARK_TEXT); - std::string command = StringPrintf( - "WebInspector.setToolbarColors(\"%s\", \"%s\")", - SkColorToRGBAString(color_toolbar).c_str(), - SkColorToRGBAString(color_tab_text).c_str()); - tab_contents_->render_view_host()-> - ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(command)); -} - -void DevToolsWindow::AddNewContents(TabContents* source, - TabContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture) { - if (inspected_tab_) { - inspected_tab_->tab_contents()->delegate()->AddNewContents( - source, new_contents, disposition, initial_pos, user_gesture); - } -} - -bool DevToolsWindow::CanReloadContents(TabContents* source) const { - return false; -} - -bool DevToolsWindow::PreHandleKeyboardEvent( - const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { - if (docked_) { - BrowserWindow* inspected_window = GetInspectedBrowserWindow(); - if (inspected_window) - return inspected_window->PreHandleKeyboardEvent( - event, is_keyboard_shortcut); - } - return false; -} - -void DevToolsWindow::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { - if (docked_) { - if (event.windowsKeyCode == 0x08) { - // Do not navigate back in history on Windows (http://crbug.com/74156). - return; - } - BrowserWindow* inspected_window = GetInspectedBrowserWindow(); - if (inspected_window) - inspected_window->HandleKeyboardEvent(event); - } -} diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h deleted file mode 100644 index 23c724b..0000000 --- a/chrome/browser/debugger/devtools_window.h +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2011 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_DEVTOOLS_WINDOW_H_ -#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_WINDOW_H_ -#pragma once - -#include <string> - -#include "base/basictypes.h" -#include "chrome/browser/debugger/devtools_client_host.h" -#include "chrome/browser/debugger/devtools_toggle_action.h" -#include "content/browser/tab_contents/tab_contents_delegate.h" -#include "content/common/notification_observer.h" -#include "content/common/notification_registrar.h" - -namespace IPC { -class Message; -} - -class Browser; -class BrowserWindow; -class Profile; -class RenderViewHost; -class Value; - -class DevToolsWindow - : public DevToolsClientHost, - public NotificationObserver, - public TabContentsDelegate { - public: - static const char kDevToolsApp[]; - static TabContentsWrapper* GetDevToolsContents(TabContents* inspected_tab); - - DevToolsWindow(Profile* profile, RenderViewHost* inspected_rvh, bool docked); - virtual ~DevToolsWindow(); - - // Overridden from DevToolsClientHost. - virtual DevToolsWindow* AsDevToolsWindow(); - virtual void SendMessageToClient(const IPC::Message& message); - virtual void InspectedTabClosing(); - virtual void TabReplaced(TabContentsWrapper* new_tab); - - void Show(DevToolsToggleAction action); - void Activate(); - void SetDocked(bool docked); - RenderViewHost* GetRenderViewHost(); - - TabContentsWrapper* tab_contents() { return tab_contents_; } - Browser* browser() { return browser_; } // For tests. - bool is_docked() { return docked_; } - - private: - void CreateDevToolsBrowser(); - bool FindInspectedBrowserAndTabIndex(Browser**, int* tab); - BrowserWindow* GetInspectedBrowserWindow(); - bool IsInspectedBrowserPopupOrPanel(); - void UpdateFrontendAttachedState(); - - // Overridden from NotificationObserver. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - void ScheduleAction(DevToolsToggleAction action); - void DoAction(); - GURL GetDevToolsUrl(); - void UpdateTheme(); - void AddDevToolsExtensionsToClient(); - void CallClientFunction(const string16& function_name, - const Value& arg); - // Overridden from TabContentsDelegate. - virtual void OpenURLFromTab(TabContents* source, - const GURL& url, - const GURL& referrer, - WindowOpenDisposition disposition, - PageTransition::Type transition); - virtual void NavigationStateChanged(const TabContents* source, - unsigned changed_flags) {} - 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 DeactivateContents(TabContents* contents) {} - virtual void LoadingStateChanged(TabContents* source) {} - virtual void CloseContents(TabContents* source) {} - virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} - virtual bool CanReloadContents(TabContents* source) const; - virtual void UpdateTargetURL(TabContents* source, const GURL& url) {} - virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, - bool* is_keyboard_shortcut); - virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); - - virtual void FrameNavigating(const std::string& url) {} - - Profile* profile_; - TabContentsWrapper* inspected_tab_; - TabContentsWrapper* tab_contents_; - Browser* browser_; - bool docked_; - bool is_loaded_; - DevToolsToggleAction action_on_load_; - NotificationRegistrar registrar_; - DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); -}; - -#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_WINDOW_H_ diff --git a/chrome/browser/debugger/extension_ports_remote_service.cc b/chrome/browser/debugger/extension_ports_remote_service.cc deleted file mode 100644 index bf960e3..0000000 --- a/chrome/browser/debugger/extension_ports_remote_service.cc +++ /dev/null @@ -1,385 +0,0 @@ -// Copyright (c) 2011 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. - -// Implementation of the ExtensionPortsRemoteService. - -// Inspired significantly from debugger_remote_service -// and ../automation/extension_port_container. - -#include "chrome/browser/debugger/extension_ports_remote_service.h" - -#include "base/json/json_reader.h" -#include "base/json/json_writer.h" -#include "base/message_loop.h" -#include "base/string_number_conversions.h" -#include "base/values.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/debugger/devtools_manager.h" -#include "chrome/browser/debugger/devtools_protocol_handler.h" -#include "chrome/browser/debugger/devtools_remote_message.h" -#include "chrome/browser/debugger/inspectable_tab_proxy.h" -#include "chrome/browser/profiles/profile_manager.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/extensions/extension_messages.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/common/devtools_messages.h" - -namespace { - -// Protocol is as follows: -// -// From external client: -// {"command": "connect", -// "data": { -// "extensionId": "<extension_id string>", -// "channelName": "<port name string>", (optional) -// "tabId": <numerical tab ID> (optional) -// } -// } -// To connect to a background page or tool strip, the tabId should be omitted. -// Tab IDs can be enumerated with the list_tabs DevToolsService command. -// -// Response: -// {"command": "connect", -// "result": 0, (assuming success) -// "data": { -// "portId": <numerical port ID> -// } -// } -// -// Posting a message from external client: -// Put the target message port ID in the devtools destination field. -// {"command": "postMessage", -// "data": <message body - arbitrary JSON> -// } -// Response: -// {"command": "postMessage", -// "result": 0 (Assuming success) -// } -// Note this is a confirmation from the devtools protocol layer, not -// a response from the extension. -// -// Message from an extension to the external client: -// The message port ID is in the devtools destination field. -// {"command": "onMessage", -// "result": 0, (Always 0) -// "data": <message body - arbitrary JSON> -// } -// -// The "disconnect" command from the external client, and -// "onDisconnect" notification from the ExtensionMessageService, are -// similar: with the message port ID in the destination field, but no -// "data" field in this case. - -// Commands: -const char kConnect[] = "connect"; -const char kDisconnect[] = "disconnect"; -const char kPostMessage[] = "postMessage"; -// Events: -const char kOnMessage[] = "onMessage"; -const char kOnDisconnect[] = "onDisconnect"; - -// Constants for the JSON message fields. -// The type is wstring because the constant is used to get a -// DictionaryValue field (which requires a wide string). - -// Mandatory. -const char kCommandKey[] = "command"; - -// Always present in messages sent to the external client. -const char kResultKey[] = "result"; - -// Field for command-specific parameters. Not strictly necessary, but -// makes it more similar to the remote debugger protocol, which should -// allow easier reuse of client code. -const char kDataKey[] = "data"; - -// Fields within the "data" dictionary: - -// Required for "connect": -const char kExtensionIdKey[] = "extensionId"; -// Optional in "connect": -const char kChannelNameKey[] = "channelName"; -const char kTabIdKey[] = "tabId"; - -// Present under "data" in replies to a successful "connect" . -const char kPortIdKey[] = "portId"; - -} // namespace - -const std::string ExtensionPortsRemoteService::kToolName = "ExtensionPorts"; - -ExtensionPortsRemoteService::ExtensionPortsRemoteService( - DevToolsProtocolHandler* delegate) - : delegate_(delegate), service_(NULL) { - // We need an ExtensionMessageService instance. It hangs off of - // |profile|. But we do not have a particular tab or RenderViewHost - // as context. I'll just use the first active profile not in - // incognito mode. But this is probably not the right way. - ProfileManager* profile_manager = g_browser_process->profile_manager(); - if (!profile_manager) { - LOG(WARNING) << "No profile manager for ExtensionPortsRemoteService"; - return; - } - - std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); - for (size_t i = 0; i < profiles.size(); ++i) { - if (!profiles[i]->IsOffTheRecord()) { - service_ = profiles[i]->GetExtensionMessageService(); - break; - } - } - if (!service_) - LOG(WARNING) << "No usable profile for ExtensionPortsRemoteService"; -} - -ExtensionPortsRemoteService::~ExtensionPortsRemoteService() { -} - -void ExtensionPortsRemoteService::HandleMessage( - const DevToolsRemoteMessage& message) { - DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); - const std::string destinationString = message.destination(); - scoped_ptr<Value> request(base::JSONReader::Read(message.content(), true)); - if (request.get() == NULL) { - // Bad JSON - NOTREACHED(); - return; - } - DictionaryValue* content; - if (!request->IsType(Value::TYPE_DICTIONARY)) { - NOTREACHED(); // Broken protocol :( - return; - } - content = static_cast<DictionaryValue*>(request.get()); - if (!content->HasKey(kCommandKey)) { - NOTREACHED(); // Broken protocol :( - return; - } - std::string command; - DictionaryValue response; - - content->GetString(kCommandKey, &command); - response.SetString(kCommandKey, command); - - if (!service_) { - // This happens if we failed to obtain an ExtensionMessageService - // during initialization. - NOTREACHED(); - response.SetInteger(kResultKey, RESULT_NO_SERVICE); - SendResponse(response, message.tool(), message.destination()); - return; - } - - int destination = -1; - if (!destinationString.empty()) - base::StringToInt(destinationString, &destination); - - if (command == kConnect) { - if (destination != -1) // destination should be empty for this command. - response.SetInteger(kResultKey, RESULT_UNKNOWN_COMMAND); - else - ConnectCommand(content, &response); - } else if (command == kDisconnect) { - if (destination == -1) // Destination required for this command. - response.SetInteger(kResultKey, RESULT_UNKNOWN_COMMAND); - else - DisconnectCommand(destination, &response); - } else if (command == kPostMessage) { - if (destination == -1) // Destination required for this command. - response.SetInteger(kResultKey, RESULT_UNKNOWN_COMMAND); - else - PostMessageCommand(destination, content, &response); - } else { - // Unknown command - NOTREACHED(); - response.SetInteger(kResultKey, RESULT_UNKNOWN_COMMAND); - } - SendResponse(response, message.tool(), message.destination()); -} - -void ExtensionPortsRemoteService::OnConnectionLost() { - VLOG(1) << "OnConnectionLost"; - DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); - DCHECK(service_); - for (PortIdSet::iterator it = openPortIds_.begin(); - it != openPortIds_.end(); - ++it) - service_->CloseChannel(*it); - openPortIds_.clear(); -} - -void ExtensionPortsRemoteService::SendResponse( - const Value& response, const std::string& tool, - const std::string& destination) { - std::string response_content; - base::JSONWriter::Write(&response, false, &response_content); - scoped_ptr<DevToolsRemoteMessage> response_message( - DevToolsRemoteMessageBuilder::instance().Create( - tool, destination, response_content)); - delegate_->Send(*response_message.get()); -} - -bool ExtensionPortsRemoteService::Send(IPC::Message *message) { - DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); - - IPC_BEGIN_MESSAGE_MAP(ExtensionPortsRemoteService, *message) - IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) - IPC_MESSAGE_UNHANDLED_ERROR() - IPC_END_MESSAGE_MAP() - - delete message; - return true; -} - -void ExtensionPortsRemoteService::OnExtensionMessageInvoke( - const std::string& extension_id, - const std::string& function_name, - const ListValue& args, - const GURL& event_url) { - if (function_name == ExtensionMessageService::kDispatchOnMessage) { - DCHECK_EQ(args.GetSize(), 2u); - std::string message; - int port_id; - if (args.GetString(0, &message) && args.GetInteger(1, &port_id)) - OnExtensionMessage(message, port_id); - } else if (function_name == ExtensionMessageService::kDispatchOnDisconnect) { - DCHECK_EQ(args.GetSize(), 1u); - int port_id; - if (args.GetInteger(0, &port_id)) - OnExtensionPortDisconnected(port_id); - } else if (function_name == ExtensionMessageService::kDispatchOnConnect) { - // There is no way for this service to be addressed and receive - // connections. - NOTREACHED() << function_name << " shouldn't be called."; - } else { - NOTREACHED() << function_name << " shouldn't be called."; - } -} - -void ExtensionPortsRemoteService::OnExtensionMessage( - const std::string& message, int port_id) { - VLOG(1) << "Message event: from port " << port_id << ", < " << message << ">"; - // Transpose the information into a JSON message for the external client. - DictionaryValue content; - content.SetString(kCommandKey, kOnMessage); - content.SetInteger(kResultKey, RESULT_OK); - // Turn the stringified message body back into JSON. - Value* data = base::JSONReader::Read(message, false); - if (!data) { - NOTREACHED(); - return; - } - content.Set(kDataKey, data); - SendResponse(content, kToolName, base::IntToString(port_id)); -} - -void ExtensionPortsRemoteService::OnExtensionPortDisconnected(int port_id) { - VLOG(1) << "Disconnect event for port " << port_id; - openPortIds_.erase(port_id); - DictionaryValue content; - content.SetString(kCommandKey, kOnDisconnect); - content.SetInteger(kResultKey, RESULT_OK); - SendResponse(content, kToolName, base::IntToString(port_id)); -} - -void ExtensionPortsRemoteService::ConnectCommand( - DictionaryValue* content, DictionaryValue* response) { - // Parse out the parameters. - DictionaryValue* data; - if (!content->GetDictionary(kDataKey, &data)) { - response->SetInteger(kResultKey, RESULT_PARAMETER_ERROR); - return; - } - std::string extension_id; - if (!data->GetString(kExtensionIdKey, &extension_id)) { - response->SetInteger(kResultKey, RESULT_PARAMETER_ERROR); - return; - } - std::string channel_name = ""; - data->GetString(kChannelNameKey, &channel_name); // optional. - int tab_id = -1; - data->GetInteger(kTabIdKey, &tab_id); // optional. - int port_id; - if (tab_id != -1) { // Resolve the tab ID. - const InspectableTabProxy::TabMap& tab_map = - delegate_->inspectable_tab_proxy()->tab_map(); - InspectableTabProxy::TabMap::const_iterator it = tab_map.find(tab_id); - TabContents* tab_contents = NULL; - if (it != tab_map.end()) - tab_contents = it->second->tab_contents(); - if (!tab_contents) { - VLOG(1) << "tab not found: " << tab_id; - response->SetInteger(kResultKey, RESULT_TAB_NOT_FOUND); - return; - } - // Ask the ExtensionMessageService to open the channel. - VLOG(1) << "Connect: extension_id <" << extension_id - << ">, channel_name <" << channel_name - << ">, tab " << tab_id; - DCHECK(service_); - port_id = service_->OpenSpecialChannelToTab( - extension_id, channel_name, tab_contents, this); - } else { // no tab: channel to an extension' background page / toolstrip. - // Ask the ExtensionMessageService to open the channel. - VLOG(1) << "Connect: extension_id <" << extension_id - << ">, channel_name <" << channel_name << ">"; - DCHECK(service_); - port_id = service_->OpenSpecialChannelToExtension( - extension_id, channel_name, "null", this); - } - if (port_id == -1) { - // Failure: probably the extension ID doesn't exist. - VLOG(1) << "Connect failed"; - response->SetInteger(kResultKey, RESULT_CONNECT_FAILED); - return; - } - VLOG(1) << "Connected: port " << port_id; - openPortIds_.insert(port_id); - // Reply to external client with the port ID assigned to the new channel. - DictionaryValue* reply_data = new DictionaryValue(); - reply_data->SetInteger(kPortIdKey, port_id); - response->Set(kDataKey, reply_data); - response->SetInteger(kResultKey, RESULT_OK); -} - -void ExtensionPortsRemoteService::DisconnectCommand( - int port_id, DictionaryValue* response) { - VLOG(1) << "Disconnect port " << port_id; - PortIdSet::iterator portEntry = openPortIds_.find(port_id); - if (portEntry == openPortIds_.end()) { // unknown port ID. - VLOG(1) << "unknown port: " << port_id; - response->SetInteger(kResultKey, RESULT_UNKNOWN_PORT); - return; - } - DCHECK(service_); - service_->CloseChannel(port_id); - openPortIds_.erase(portEntry); - response->SetInteger(kResultKey, RESULT_OK); -} - -void ExtensionPortsRemoteService::PostMessageCommand( - int port_id, DictionaryValue* content, DictionaryValue* response) { - Value* data; - if (!content->Get(kDataKey, &data)) { - response->SetInteger(kResultKey, RESULT_PARAMETER_ERROR); - return; - } - std::string message; - // Stringified the JSON message body. - base::JSONWriter::Write(data, false, &message); - VLOG(1) << "postMessage: port " << port_id - << ", message: <" << message << ">"; - PortIdSet::iterator portEntry = openPortIds_.find(port_id); - if (portEntry == openPortIds_.end()) { // Unknown port ID. - VLOG(1) << "unknown port: " << port_id; - response->SetInteger(kResultKey, RESULT_UNKNOWN_PORT); - return; - } - // Post the message through the ExtensionMessageService. - DCHECK(service_); - service_->PostMessageFromRenderer(port_id, message); - // Confirm to the external client that we sent its message. - response->SetInteger(kResultKey, RESULT_OK); -} diff --git a/chrome/browser/debugger/extension_ports_remote_service.h b/chrome/browser/debugger/extension_ports_remote_service.h deleted file mode 100644 index 4904e98..0000000 --- a/chrome/browser/debugger/extension_ports_remote_service.h +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2011 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. - -// ExtensionsPorts service: wires extension message ports through the -// devtools remote protocol, allowing an external client program to -// exchange messages with Chrome extensions. - -#ifndef CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ -#define CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ -#pragma once - -#include <set> -#include <string> - -#include "base/basictypes.h" -#include "base/memory/ref_counted.h" -#include "chrome/browser/debugger/devtools_remote.h" -#include "chrome/browser/extensions/extension_message_service.h" -#include "ipc/ipc_message.h" - -class DevToolsProtocolHandler; -class DevToolsRemoteMessage; -class DictionaryValue; -class GURL; -class ListValue; -class Value; - -class ExtensionPortsRemoteService : public DevToolsRemoteListener, - public IPC::Message::Sender { - public: - // Specifies a tool name ("ExtensionPorts") handled by this class. - static const std::string kToolName; - - // |delegate| (never NULL) is the protocol handler instance which - // dispatches messages to this service. - // The ownership of |delegate| is NOT transferred to this class. - explicit ExtensionPortsRemoteService(DevToolsProtocolHandler* delegate); - - // DevToolsRemoteListener methods: - - // Processes |message| from the external client (where the tool is - // "ExtensionPorts"). - virtual void HandleMessage(const DevToolsRemoteMessage& message); - - // Gets invoked on the external client socket connection loss. - // Closes open message ports. - virtual void OnConnectionLost(); - - // IPC::Message::Sender methods: - - // This is the callback through which the ExtensionMessageService - // passes us messages from extensions as well as disconnect events. - virtual bool Send(IPC::Message* msg); - - private: - // Operation result returned in the "result" field in messages sent - // to the external client. - typedef enum { - RESULT_OK = 0, - RESULT_UNKNOWN_COMMAND, - RESULT_NO_SERVICE, - RESULT_PARAMETER_ERROR, - RESULT_UNKNOWN_PORT, - RESULT_TAB_NOT_FOUND, - RESULT_CONNECT_FAILED, // probably extension ID not found. - } Result; - - virtual ~ExtensionPortsRemoteService(); - - // Sends a JSON message with the |response| to the external client. - // |tool| and |destination| are used as the respective header values. - void SendResponse(const Value& response, - const std::string& tool, - const std::string& destination); - - // Handles a message from the ExtensionMessageService. - void OnExtensionMessageInvoke(const std::string& extension_id, - const std::string& function_name, - const ListValue& args, - const GURL& event_url); - // Handles a message sent from an extension through the - // ExtensionMessageService, to be passed to the external client. - void OnExtensionMessage(const std::string& message, int port_id); - // Handles a disconnect event sent from the ExtensionMessageService. - void OnExtensionPortDisconnected(int port_id); - - // Implementation for the commands we can receive from the external client. - // Opens a channel to an extension. - void ConnectCommand(DictionaryValue* content, DictionaryValue* response); - // Disconnects a message port. - void DisconnectCommand(int port_id, DictionaryValue* response); - // Sends a message to an extension through an established message port. - void PostMessageCommand(int port_id, DictionaryValue* content, - DictionaryValue* response); - - // The delegate is used to send responses and events back to the - // external client, and to resolve tab IDs. - DevToolsProtocolHandler* delegate_; - - // Set of message port IDs we successfully opened. - typedef std::set<int> PortIdSet; - PortIdSet openPortIds_; - - scoped_refptr<ExtensionMessageService> service_; - - DISALLOW_COPY_AND_ASSIGN(ExtensionPortsRemoteService); -}; - -#endif // CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ diff --git a/chrome/browser/debugger/frontend/devtools_frontend.html b/chrome/browser/debugger/frontend/devtools_frontend.html deleted file mode 100644 index 85c03b8..0000000 --- a/chrome/browser/debugger/frontend/devtools_frontend.html +++ /dev/null @@ -1,142 +0,0 @@ -<html> -<head> -<title>Inspectable pages</title> -<style> -body { - background-color: rgb(245, 245, 245); - font-family: Helvetica, Arial, sans-serif; - text-shadow: rgba(255, 255, 255, 0.496094) 0px 1px 0px; -} - -#caption { - text-align: left; - color: black; - font-size: 16px; - margin-top: 30px; - margin-bottom: 0px; - margin-left: 70px; - height: 20px; -} - -#items { - display: -webkit-box; - -webkit-box-orient: horizontal; - -webkit-box-lines: multiple; - margin-left: 60px; - margin-right: 60px; -} - -.frontend_ref { - color: black; - text-decoration: initial; -} - -.thumbnail { - height: 132px; - width: 212px; - background-attachment: scroll; - background-origin: padding-box; - background-repeat: no-repeat; - border: 4px solid rgba(184, 184, 184, 1); - border-radius: 5px; - -webkit-transition-property: background-color, border-color; - -webkit-transition: background-color 0.15s, 0.15s; - -webkit-transition-delay: 0, 0; -} - -.thumbnail:hover { - background-color: rgba(242, 242, 242, 1); - border-color: rgba(110, 116, 128, 1); - color: black; -} - -.thumbnail.connected { - opacity: 0.5; -} - -.thumbnail.connected:hover { - border-color: rgba(184, 184, 184, 1); - color: rgb(110, 116, 128); -} - -.item { - display: inline-block; - margin: 5px; - margin-top: 15px; - height: 162px; - width: 222px; - vertical-align: top; -} - -.text { - text-align: left; - font-size: 12px; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; - background: no-repeat 0; - background-size: 16px; - padding: 2px 0px 0px 20px; - margin: 4px 0px 0px 4px; -} -</style> - -<script> -function onLoad() { - var tabsListRequest = new XMLHttpRequest(); - tabsListRequest.open("GET", "/json", true); - tabsListRequest.onreadystatechange = onReady; - tabsListRequest.send(); -} - -function onReady() { - if(this.readyState == 4 && this.status == 200) { - if(this.response != null) - var responseJSON = JSON.parse(this.response); - for (var i = 0; i < responseJSON.length; ++i) - appendItem(responseJSON[i]); - } -} - -function appendItem(item_object) { - var frontend_ref; - if (item_object.devtoolsFrontendUrl) { - frontend_ref = document.createElement("a"); - frontend_ref.href = item_object.devtoolsFrontendUrl; - frontend_ref.title = item_object.title; - } else { - frontend_ref = document.createElement("div"); - frontend_ref.title = "The tab already has an active debug session"; - } - frontend_ref.className = "frontend_ref"; - - var thumbnail = document.createElement("div"); - thumbnail.className = item_object.devtoolsFrontendUrl ? - "thumbnail" : "thumbnail connected"; - thumbnail.style.cssText = "background-image:url(" + - item_object.thumbnailUrl + - ")"; - frontend_ref.appendChild(thumbnail); - - var text = document.createElement("div"); - text.className = "text"; - text.innerText = item_object.title; - text.style.cssText = "background-image:url(" + - item_object.faviconUrl + ")"; - frontend_ref.appendChild(text); - - var item = document.createElement("p"); - item.className = "item"; - item.appendChild(frontend_ref); - - document.getElementById("items").appendChild(item); -} -</script> -</head> -<body onload='onLoad()'> - <div id='caption'>Inspectable pages</div> - <div id='items'> - </div> - <hr> -</body> -</html> diff --git a/chrome/browser/debugger/frontend/devtools_frontend_resources.grd b/chrome/browser/debugger/frontend/devtools_frontend_resources.grd deleted file mode 100644 index 0351cac..0000000 --- a/chrome/browser/debugger/frontend/devtools_frontend_resources.grd +++ /dev/null @@ -1,21 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<grit current_release="1" latest_public_release="0"> - <outputs> - <output filename="grit/devtools_frontend_resources.h" - type="rc_header"> - <emit emit_type="prepend"/> - </output> - <output filename="grit/devtools_frontend_resources_map.cc" - type="resource_file_map_source"/> - <output filename="grit/devtools_frontend_resources_map.h" - type="resource_map_header"/> - <output filename="devtools_frontend_resources.pak" - type="data_package"/> - </outputs> - <release seq="1"> - <includes> - <include file="devtools_frontend.html" - name="IDR_DEVTOOLS_FRONTEND_HTML" - type="BINDATA"/></includes> - </release> -</grit> diff --git a/chrome/browser/debugger/inspectable_tab_proxy.cc b/chrome/browser/debugger/inspectable_tab_proxy.cc deleted file mode 100644 index ccbb0ec..0000000 --- a/chrome/browser/debugger/inspectable_tab_proxy.cc +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) 2011 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/inspectable_tab_proxy.h" - -#include "base/string_number_conversions.h" -#include "base/string_util.h" -#include "chrome/browser/debugger/debugger_remote_service.h" -#include "chrome/browser/debugger/devtools_client_host.h" -#include "chrome/browser/sessions/restore_tab_helper.h" -#include "chrome/browser/sessions/session_id.h" -#include "chrome/browser/tabs/tab_strip_model.h" -#include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/common/devtools_messages.h" - -DevToolsClientHostImpl::DevToolsClientHostImpl( - int32 id, - DebuggerRemoteService* service, - InspectableTabProxy::IdToClientHostMap* map) - : id_(id), - service_(service), - map_(map) {} - -DevToolsClientHostImpl::~DevToolsClientHostImpl() { - map_->erase(this->id_); -} - -// The debugged tab has closed. -void DevToolsClientHostImpl::InspectedTabClosing() { - TabClosed(); - delete this; -} - -// The remote debugger has detached. -void DevToolsClientHostImpl::Close() { - NotifyCloseListener(); - delete this; -} - -void DevToolsClientHostImpl::SendMessageToClient( - const IPC::Message& msg) { - // TODO(prybin): Restore FrameNavigate. - IPC_BEGIN_MESSAGE_MAP(DevToolsClientHostImpl, msg) - IPC_MESSAGE_HANDLER(DevToolsClientMsg_DebuggerOutput, OnDebuggerOutput); - IPC_MESSAGE_UNHANDLED_ERROR() - IPC_END_MESSAGE_MAP() -} - -void DevToolsClientHostImpl::TabReplaced(TabContentsWrapper* new_tab) { - map_->erase(id_); - id_ = new_tab->restore_tab_helper()->session_id().id(); - (*map_)[id_] = this; -} - -void DevToolsClientHostImpl::OnDebuggerOutput(const std::string& data) { - service_->DebuggerOutput(id_, data); -} - -void DevToolsClientHostImpl::FrameNavigating(const std::string& url) { - service_->FrameNavigate(id_, url); -} - -void DevToolsClientHostImpl::TabClosed() { - service_->TabClosed(id_); -} - -InspectableTabProxy::InspectableTabProxy() {} - -InspectableTabProxy::~InspectableTabProxy() {} - -const InspectableTabProxy::TabMap& InspectableTabProxy::tab_map() { - tab_map_.clear(); - for (BrowserList::const_iterator it = BrowserList::begin(), - end = BrowserList::end(); it != end; ++it) { - TabStripModel* model = (*it)->tabstrip_model(); - for (int i = 0, size = model->count(); i < size; ++i) { - TabContentsWrapper* tab = model->GetTabContentsAt(i); - tab_map_[tab->restore_tab_helper()->session_id().id()] = tab; - } - } - return tab_map_; -} - -DevToolsClientHostImpl* InspectableTabProxy::ClientHostForTabId( - int32 id) { - InspectableTabProxy::IdToClientHostMap::const_iterator it = - id_to_client_host_map_.find(id); - if (it == id_to_client_host_map_.end()) { - return NULL; - } - return it->second; -} - -DevToolsClientHost* InspectableTabProxy::NewClientHost( - int32 id, - DebuggerRemoteService* service) { - DevToolsClientHostImpl* client_host = - new DevToolsClientHostImpl(id, service, &id_to_client_host_map_); - id_to_client_host_map_[id] = client_host; - return client_host; -} - -void InspectableTabProxy::OnRemoteDebuggerDetached() { - while (!id_to_client_host_map_.empty()) { - IdToClientHostMap::iterator it = id_to_client_host_map_.begin(); - it->second->debugger_remote_service()->DetachFromTab( - base::IntToString(it->first), NULL); - } -} diff --git a/chrome/browser/debugger/inspectable_tab_proxy.h b/chrome/browser/debugger/inspectable_tab_proxy.h deleted file mode 100644 index 1b6e336..0000000 --- a/chrome/browser/debugger/inspectable_tab_proxy.h +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) 2011 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_INSPECTABLE_TAB_PROXY_H_ -#define CHROME_BROWSER_DEBUGGER_INSPECTABLE_TAB_PROXY_H_ -#pragma once - -#include <string> - -#include "base/basictypes.h" -#include "base/hash_tables.h" -#include "chrome/browser/debugger/devtools_client_host.h" - -class DebuggerRemoteService; -class DevToolsClientHost; -class DevToolsClientHostImpl; -struct DevToolsMessageData; -class TabContentsWrapper; - -// Proxies debugged tabs' TabContentsWrapper using their UIDs. -// Keeps track of tabs being debugged so that we can detach from -// them on remote debugger connection loss. -class InspectableTabProxy { - public: - typedef base::hash_map<int32, TabContentsWrapper*> TabMap; - typedef base::hash_map<int32, DevToolsClientHostImpl*> IdToClientHostMap; - - InspectableTabProxy(); - virtual ~InspectableTabProxy(); - - // Returns a map of SessionID to TabContentsWrapper for all Browser - // instances. Clients should not keep the result around for extended periods - // of time as tabs might get closed thus invalidating the map. - const TabMap& tab_map(); - - // Returns a DevToolsClientHostImpl for the given tab |id|. - DevToolsClientHostImpl* ClientHostForTabId(int32 id); - - // Creates a new DevToolsClientHost implementor instance. - // |id| is the UID of the tab to debug. - // |service| is the DebuggerRemoteService instance the DevToolsClient - // messages shall be dispatched to. - DevToolsClientHost* NewClientHost(int32 id, - DebuggerRemoteService* service); - - // Gets invoked when a remote debugger is detached. In this case we should - // send the corresponding message to the V8 debugger for each of the tabs - // the debugger is attached to, and invoke InspectedTabClosing(). - void OnRemoteDebuggerDetached(); - - private: - TabMap tab_map_; - IdToClientHostMap id_to_client_host_map_; - DISALLOW_COPY_AND_ASSIGN(InspectableTabProxy); -}; - - -// An internal implementation of DevToolsClientHost that delegates -// messages sent for DevToolsClient to a DebuggerShell instance. -class DevToolsClientHostImpl : public DevToolsClientHost { - public: - DevToolsClientHostImpl( - int32 id, - DebuggerRemoteService* service, - InspectableTabProxy::IdToClientHostMap* map); - virtual ~DevToolsClientHostImpl(); - - DebuggerRemoteService* debugger_remote_service() { - return service_; - } - - void Close(); - - // DevToolsClientHost interface - virtual void InspectedTabClosing(); - virtual void SendMessageToClient(const IPC::Message& msg); - virtual void TabReplaced(TabContentsWrapper* new_tab); - - private: - // Message handling routines - void OnDebuggerOutput(const std::string& msg); - virtual void FrameNavigating(const std::string& url); - void TabClosed(); - - int32 id_; - DebuggerRemoteService* service_; - InspectableTabProxy::IdToClientHostMap* map_; -}; - -#endif // CHROME_BROWSER_DEBUGGER_INSPECTABLE_TAB_PROXY_H_ diff --git a/chrome/browser/debugger/manual_tests/console-call-line-numbers.html b/chrome/browser/debugger/manual_tests/console-call-line-numbers.html deleted file mode 100644 index 98bb918..0000000 --- a/chrome/browser/debugger/manual_tests/console-call-line-numbers.html +++ /dev/null @@ -1,15 +0,0 @@ -<script> - console.info("Test console.info"); - console.log("Test console.log"); - console.warn("Test console.warn"); - console.error("Test console.error"); - console.time("Test console.time"); - console.timeEnd("Test console.time"); - console.count("Test console.count"); - console.assert(false, "Test console.assert"); -</script> -<script src="resources/script-console-calls.js"></script> - -<p>To test, open the DevTools's Console (Ctrl+Shift+J) and verify that all console messages have correct -resource URLs and line numbers. Also verify that errors and warnings show up inline as bubbles in the -Resource panel file list and each individual resource view.</p> diff --git a/chrome/browser/debugger/manual_tests/debugger-exception-on-load.html b/chrome/browser/debugger/manual_tests/debugger-exception-on-load.html deleted file mode 100644 index ef2384f..0000000 --- a/chrome/browser/debugger/manual_tests/debugger-exception-on-load.html +++ /dev/null @@ -1,5 +0,0 @@ -<script> -debugger; // You should see this code and execution line in the Scripts panel. Click Resume (Play/Pause button to the right). -</script> - -<p>To test, open the DevTools (Ctrl+Shift+I) and reload the page. You should see this file and execution line in the Scripts panel.</p> diff --git a/chrome/browser/debugger/manual_tests/debugger-execution-while-paused.html b/chrome/browser/debugger/manual_tests/debugger-execution-while-paused.html deleted file mode 100644 index f33abea..0000000 --- a/chrome/browser/debugger/manual_tests/debugger-execution-while-paused.html +++ /dev/null @@ -1,17 +0,0 @@ -<script> -function stepOne() -{ - console.log(1); -} - -function stepTwo() -{ - alert("Test failed. The second button event still fired."); -} -</script> - -<p>To test, open the DevTools (Ctrl+Shift+I) and reload the page. Set a break point inside the stepOne() function. -Now click the Step One button in the page. The breakpoint should be hit. While paused at the breakpoint -click on the Step Two button. You should not see an alert dialog. Continue script.</p> -<button onclick="stepOne()">Step One</button><br><br> -<button onclick="stepTwo()">Step Two</button> diff --git a/chrome/browser/debugger/manual_tests/debugger-fake-workers.html b/chrome/browser/debugger/manual_tests/debugger-fake-workers.html deleted file mode 100644 index 6a7cb03..0000000 --- a/chrome/browser/debugger/manual_tests/debugger-fake-workers.html +++ /dev/null @@ -1,102 +0,0 @@ -<html> -<body onload="onLoad()"> -<script> - -function log(message) { - var div = document.createElement('div'); - div.innerText = message; - document.getElementById('console').appendChild(div); -} - -function strike(id) { - document.getElementById(id).style.textDecoration = "line-through" -} - -function onLoad() { - if (!Worker.prototype.postMessage) { // fake workers - strike('s1'); - strike('s2'); - log('[using fake workers]'); - } else { - log('[using real workers]'); - } -} - -var primeWorker; -var invalidWorker; -var count; -var timer; - -function startWorkers() { - startButton.disabled = true; - - primeWorker = new Worker('resources/worker-primes.js'); - primeWorker.onmessage = onMessage; - primeWorker.onerror = onError; - primeWorker.postMessage(2); - count = 3; - - timer = setInterval(onTimer, 1000); - try { - invalidWorker = new Worker('non-existent-worker.js'); - } catch(e) { - } - log('Started worker'); -} - -function onTimer() { - primeWorker.postMessage(count); - count+=2; -} - -function onMessage(event) { - if (event.data[1]) { - log(event.data[0]); - if (event.data[0] === 5) - strike('s6'); - } -} - -function onError(event) { - log('Error in worker: ' + event.message); - strike('s8'); -} - -function causeError() { - primeWorker.postMessage('forty two'); -} - -function stopWorker() { - log('Stopping worker...'); - if (timer) { - clearInterval(timer); - timer = 0; - } - primeWorker.terminate(); - startButton.disabled = false; -} - -</script> - -<h1>Tests debugging of HTML5 Workers</h1> - -<ol> - -<li id="s1">Open DevTools, Scripts Panel; Tick Debug on Workers sidebar.</li> -<li id="s2">Reload the page.</li> -<li id="s3"><button onclick="startWorkers()" id="startButton">Start Worker</button></li> -<li id="s4">Observe 2 workers appear in the worker sidebar pane (including non-existent-worker.js)"</li> -<li id="s5">Observe worker-primes.js and primes.js appear in scripts drop-down box.</li> -<li id="s6">Assure primes are being logged to test console below.</li> -<li id="s7">Set a breakpoint on one of worker scripts, assure it's hit.</li> -<li id="s8">Try causing an error in worker, observe it's logged in DevTools console and in test console below. - <button onclick="causeError()">Cause Error</button> -<li id="s9"><button onclick="stopWorker()">Stop Worker</button></li> - -</ol> - -<div id="console" style="font-family: courier; background-color: black; color: green; width: 80em; height: 25em; overflow: scroll"> -</div> - -</body> -</html> diff --git a/chrome/browser/debugger/manual_tests/debugger-pause-on-else-statements.html b/chrome/browser/debugger/manual_tests/debugger-pause-on-else-statements.html deleted file mode 100644 index 3c80a43..0000000 --- a/chrome/browser/debugger/manual_tests/debugger-pause-on-else-statements.html +++ /dev/null @@ -1,16 +0,0 @@ -<script> -function test() -{ - debugger; -} - -if (false) - debugger; // This should not be hit. -else - test(); -</script> - -<p>To test, open the DevTools (Ctrl+Shift+I) and reload the page. When the debugger breaks, select the (anonymous function) node -in the call stack, you should see the execution line on the call to test().</p> -<br><br> -Also set a breakpoint on the call to test(), and reload. It should break before the test() function is called. diff --git a/chrome/browser/debugger/manual_tests/debugger-pause-on-for-in-statements.html b/chrome/browser/debugger/manual_tests/debugger-pause-on-for-in-statements.html deleted file mode 100644 index 79f7983..0000000 --- a/chrome/browser/debugger/manual_tests/debugger-pause-on-for-in-statements.html +++ /dev/null @@ -1,16 +0,0 @@ -<script> -function test() -{ - debugger; -} - -var object = { test: 1 }; - -for (var property in object) - test(); -</script> - -<p>To test, open the DevTools (Ctrl+Shift+I) and reload the page. When the debugger breaks, select -the (anonymous function) node in the call stack, you should see the execution line on the call to test(). -<br><br> -Also set a breakpoint on the call to test(), and reload. It should break before the test() function is called. diff --git a/chrome/browser/debugger/manual_tests/debugger-pause-on-for-statements.html b/chrome/browser/debugger/manual_tests/debugger-pause-on-for-statements.html deleted file mode 100644 index 1a9e274..0000000 --- a/chrome/browser/debugger/manual_tests/debugger-pause-on-for-statements.html +++ /dev/null @@ -1,14 +0,0 @@ -<script> -function test() -{ - debugger; -} - -for (var i = 0; i < 1; ++i) - test(); -</script> - -<p>To test, open the DevTools (Ctrl+Shift+I) and reload the page. When the debugger breaks, select the -(anonymous function) node in the call stack, you should see the execution line on the call to test().</p> -<br><br> -Also set a breakpoint on the call to test(), and reload. It should break before the test() function is called. diff --git a/chrome/browser/debugger/manual_tests/debugger-step-on-do-while-statements.html b/chrome/browser/debugger/manual_tests/debugger-step-on-do-while-statements.html deleted file mode 100644 index f60dd6a..0000000 --- a/chrome/browser/debugger/manual_tests/debugger-step-on-do-while-statements.html +++ /dev/null @@ -1,27 +0,0 @@ -<script src="resources/loop-statements.js"></script> -<script> -function runDoWhile() -{ - /* place breakpoint on next line and click continue */ debugger; - do { - statement(); - increment(); - } while (condition()); -} - -</script> -<p>To test, open the DevTools (Ctrl+Shift+I) and reload the page. -<br><br> -Before running the tests please perform the following: -Make sure the execution is not paused in the debugger.<br> -Click the button and when the debugger breaks, set a breakpoint on the first line in the loop -(as indicated by the comment), and click continue.<br> -The debugger should stop at the beggining of the loop.<br> -The above actions should be performed before <b>each</b> of the following tests.</p> -<br><br> -<input type="button" value="run do-while" onclick="initialize();runDoWhile()"/> -<br><br> -TEST 1: Click 'continue'. Execution should continue without stopping on the loop breakpoint again.<br> -TEST 2: Click 'Step into'. Debugger should step inside each function.<br> -TEST 3: 'Step over' to the end of the loop (and 'while' statement) and step over again. Debugger -should go to the beggining of the loop.<br> diff --git a/chrome/browser/debugger/manual_tests/debugger-step-on-for-in-statements.html b/chrome/browser/debugger/manual_tests/debugger-step-on-for-in-statements.html deleted file mode 100644 index e360394..0000000 --- a/chrome/browser/debugger/manual_tests/debugger-step-on-for-in-statements.html +++ /dev/null @@ -1,35 +0,0 @@ -<script> -var myObj = {test : 1}; -function getObject() -{ - return myObj; -} - -function statement() { - ; -} - -function runForIn() -{ - /* place breakpoint on next line and click continue */ debugger; - for (var property in getObject()) - statement(); -} - -</script> -<p>To test, open the DevTools (Ctrl+Shift+I) and reload the page. -<br><br> -Before running the tests please perform the following: -Make sure the execution is not paused in the debugger.<br> -Click the button and when the debugger breaks, set a breakpoint on the first line in the loop -(as indicated by the comment), and click continue.<br> -The debugger should stop at the beggining of the loop.<br> -The above actions should be performed before <b>each</b> of the following tests.</p> -<br><br> -<input type="button" value="run for-in" onclick="runForIn()"/> -<br><br> -TEST 1: Click 'continue'. Execution should continue without stopping on the loop breakpoint again.<br> -TEST 2: Click 'Step over'. Debugger should step inside the loop to the next statement line.<br> -TEST 3: Click 'Step into'. Debugger should step into 'getObject' function.<br> -TEST 4: 'Step over' to the statement line and then 'Step over' again. Debugger should pause on -the for-in loop again.<br> diff --git a/chrome/browser/debugger/manual_tests/debugger-step-on-for-statements.html b/chrome/browser/debugger/manual_tests/debugger-step-on-for-statements.html deleted file mode 100644 index 75289e5f..0000000 --- a/chrome/browser/debugger/manual_tests/debugger-step-on-for-statements.html +++ /dev/null @@ -1,25 +0,0 @@ -<script src="resources/loop-statements.js"></script> -<script> -function runFor() -{ - /* place breakpoint on next line and click continue */ debugger; - for (initialize(); condition(); increment()) - statement(); -} -</script> -<p>To test, open the DevTools (Ctrl+Shift+I) and reload the page. -<br><br> -Before running the tests please perform the following: -Make sure the execution is not paused in the debugger.<br> -Click the button and when the debugger breaks, set a breakpoint on the first line in the loop -(as indicated by the comment), and click continue.<br> -The debugger should stop at the beggining of the loop.<br> -The above actions should be performed before <b>each</b> of the following tests.</p> -<br><br> -<input type="button" value="run for" onclick="runFor()"/> -<br><br> -TEST 1: Click 'continue'. Execution should continue without stopping on the loop breakpoint again.<br> -TEST 2: Click 'Step over'. Debugger should step inside the loop to the next statement line.<br> -TEST 3: Click 'Step into'. Debugger should step into 'initialize' function. Click 'Step into' until -outside of the 'initialize' function - debugger should enter the 'condition' function.<br> -function.<br> diff --git a/chrome/browser/debugger/manual_tests/debugger-step-on-while-statements.html b/chrome/browser/debugger/manual_tests/debugger-step-on-while-statements.html deleted file mode 100644 index 7967172..0000000 --- a/chrome/browser/debugger/manual_tests/debugger-step-on-while-statements.html +++ /dev/null @@ -1,28 +0,0 @@ -<script src="resources/loop-statements.js"></script> -<script> -function runWhile() -{ - /* place breakpoint on next line and click continue */ debugger; - while (condition()) { - statement(); - increment(); - } -} - -</script> -<p>To test, open the DevTools (Ctrl+Shift+I) and reload the page. -<br><br> -Before running the tests please perform the following: -Make sure the execution is not paused in the debugger.<br> -Click the button and when the debugger breaks, set a breakpoint on the first line in the loop -(as indicated by the comment), and click continue.<br> -The debugger should stop at the beggining of the loop.<br> -The above actions should be performed before <b>each</b> of the following tests.</p> -<br><br> -<input type="button" value="run while" onclick="initialize();runWhile()"/> -<br><br> -TEST 1: Click 'continue'. Execution should continue without stopping on the loop breakpoint again.<br> -TEST 2: Click 'Step over'. Debugger should step inside the loop to the next statement line.<br> -TEST 3: Click 'Step into'. Debugger should step into 'condition' function.<br> -step over to the beggingin of the while loop again. Click 'Step into'. Debugger should step into -the 'condition' function.<br> diff --git a/chrome/browser/debugger/manual_tests/debugger-watch-expressions.html b/chrome/browser/debugger/manual_tests/debugger-watch-expressions.html deleted file mode 100644 index a2e9258..0000000 --- a/chrome/browser/debugger/manual_tests/debugger-watch-expressions.html +++ /dev/null @@ -1,79 +0,0 @@ -<p>Test for watched expression</p> - -<p>To begin test, open DevTools, go the Scripts Panel -and then click this link: <a href="javascript:runTest()">[begin test]</a>. - -<p>Perform the following steps, and note the expected results: - -<ol> - -<li><p>After clicking the link above, you should now be paused in the body of -the test method, thanks to the <code>debugger</code> statement. - -<li><p>Add the following expressions to the "Watch Expressions" section of the -Scripts panel sidebar pane: "<code>this</code>", "<code>a</code>", -"<code>b</code>", "<code>c</code>" and "<code>d</code>". Do <b>NOT</b> enter the quotes. - -<li><p>The values of the expressions as shown in the window should be -<code>Object</code> for <code>this</code>, <code>undefined</code> for -the <code>a</code>, <code>b</code>, and <code>c</code> variables, and a -value of <code>ReferenceError: d is not defined</code> -for the <code>d</code> variable. - -<li><p>Note that the value for <code>d</code> should not change for the life of -the test, as the variable <code>d</code> is never introduced in the program. - -<li><p>Step through the code, and you'll see the values of <code>a</code>, -<code>b</code>, and <code>c</code> change, as the variables are assigned. -Also note that as the scope changes due to the function invocation, values -will be changed to refer to their current scope. The <code>this</code> -expression will change when the method is invoked on the object constructed by -the test. - -<li><p>Click different stack frames in the Call Stack section to ensure the -expressions change value appropriately as the current stack frame changes. - -</ol> - -<script> -function runTest() { - - // a nested function - function subFunction() { - debugger; - var a = "a in subFunction()"; - - subSubFunction(); - - // another nested function - function subSubFunction() { - debugger; - var b = "b in subSubFunction()"; - } - } - - // a class - function aClass() { - this.x = "xxx"; - this.y = "yyy"; - } - - aClass.prototype.aMethod = function() { - debugger; - var c = "c in aMethod()"; - } - - // main logic - debugger; - - var a = "a in runTest()"; - var b = "b in runTest()"; - var c = "c in runTest()"; - - subFunction(); - - var object = new aClass(); - object.aMethod(); - -} -</script> diff --git a/chrome/browser/debugger/manual_tests/dom-mutation.html b/chrome/browser/debugger/manual_tests/dom-mutation.html deleted file mode 100644 index a03b03c..0000000 --- a/chrome/browser/debugger/manual_tests/dom-mutation.html +++ /dev/null @@ -1,32 +0,0 @@ -<script> -function test1() { - document.getElementById("test").src = "resources/mutate-frame.html"; -} - -function test2() { - document.getElementById("test").src = "resources/mutate-frame-2.html"; -} - -var count = 1; -function run() { - var container = document.getElementById("test2"); - var div = document.createElement("div"); - div.textContent = "Testing " + (count++); - container.appendChild(div); - if (count > 10) - container.removeChild(container.firstChild); -} - -setInterval(run, 1000); -</script> -<p>To begin test, open DevTools, Elements Panel and watch the DOM change to match the page. -Clicking the buttons will navigate the subframe, and the all the subframe child nodes should change. -Expand DOM nodes in the Elements Panel to see new nodes appearing in the list live.</p> -<div style="clear: both"> -<button onclick="test1()">Test Frame 1</button> -<button onclick="test2()">Test Frame 2</button> -</div> -<div style="float: left"> -<iframe id="test" src="resources/mutate-frame.html" width="200" height="300"></iframe> -</div> -<div style="float: left; margin-left: 10px;" id="test2"></div> diff --git a/chrome/browser/debugger/manual_tests/element-styles.html b/chrome/browser/debugger/manual_tests/element-styles.html deleted file mode 100644 index cb33919..0000000 --- a/chrome/browser/debugger/manual_tests/element-styles.html +++ /dev/null @@ -1,40 +0,0 @@ -<style>
-.classTest {
- -webkit-transform:skew(-10deg,-3deg);
- color: green;
- background: #CCC;
- border: 2px solid blue;
- padding: 5px 6px 7px 8px;
-}
-</style>
-<p>To begin test, open DevTools, select the Elements panel. Expand the Styles pane in the sidebar.</p>
-<ul>
- <li>Choose the <b><div class="classTest"...></b> element in the DOM tree.
-You should see the following element styles in the ".classTest (inline stylesheet)" section:
-<pre>
- -webkit-transform:skew(-10deg,-3deg);
- color: green;
- background: #CCC;
- border: 2px solid blue;
- padding: 5px 6px 7px 8px;
-</pre>
- While changing all the property values, you should see corresponding live page changes.
- <li>Double click the "-webkit-transform" rule and place the cursor at the second argument (-3deg).
- <li>Press Up/Down keys do see the argument value change in 1.0 steps (0.1 steps in the [-1; 1] range).
- <li>Press Shift+Up/Down keys to see the argument value change in 10.0 steps.
- <li>Press Alt(Cmd)+Up/Downkeys to see the argument value change in 0.1 steps (1.0 steps in the [-1; 1] range).
- <li>Move the mouse pointer within the section to display checkboxes to the right of the property values.
- <li>Click the checkboxes to disable/enable the corresponding style properties and observe the page changes.
-You can disable the "-webkit-transform" property if the element overlaps the instructions.
- <li>Double-click the "background" rule and alter the color to "#FFF". The text background should turn white.
- <li>Double-click the "color" rule and alter the color to "black". The text background should turn black.
- <li>Expand the "padding" shorthand property using the arrow at the left. You should see the following
-property values beneath: padding-top: 5px; padding-right: 6px; padding-bottom: 7px; padding-left: 8px;
- <li>In the "Styles" pane titlebar click the gear button and choose "New Style Rule". In the editbox that appears, type:
-<pre>
-font-family: monospace;
-</pre>
- The font of the test string should alter to a monospaced one.
-</ul>
-
-<div class="classTest">CLASS_TEST CLASS_TEST CLASS_TEST CLASS_TEST CLASS_TEST CLASS_TEST CLASS_TEST</div>
\ No newline at end of file diff --git a/chrome/browser/debugger/manual_tests/error-warning-count.html b/chrome/browser/debugger/manual_tests/error-warning-count.html deleted file mode 100644 index 3296742..0000000 --- a/chrome/browser/debugger/manual_tests/error-warning-count.html +++ /dev/null @@ -1,58 +0,0 @@ -<script> - function clickHandler(errors, warnings) - { - return function() - { - for (var i = 0; i < errors; ++i) - console.error("Error " + (i + 1)); - for (var i = 0; i < warnings; ++i) - console.warn("Warning " + (i + 1)); - } - } - - function loaded() - { - var tests = [ - { errors: 0, warnings: 0 }, - { errors: 1, warnings: 0 }, - { errors: 2, warnings: 0 }, - { errors: 0, warnings: 1 }, - { errors: 0, warnings: 2 }, - { errors: 1, warnings: 1 }, - { errors: 1, warnings: 2 }, - { errors: 2, warnings: 1 }, - { errors: 2, warnings: 2 }, - { errors: 100, warnings: 100 }, - ]; - - for (var i in tests) { - var test = tests[i]; - - var button = document.createElement("button"); - var content = ""; - if (!test.errors && !test.warnings) - content = "(nothing)"; - else { - if (test.errors > 0) - content += test.errors + " error" + (test.errors != 1 ? "s" : ""); - if (test.warnings > 0) { - if (content.length) - content += ", "; - content += test.warnings + " warning" + (test.warnings != 1 ? "s" : "") - } - } - button.innerText = content; - button.onclick = clickHandler(test.errors, test.warnings); - var p = document.createElement("p"); - p.appendChild(button); - document.body.appendChild(p); - } - } -</script> -<body onload="loaded()"> -<p>To begin test, open DevTools and click one of the buttons below. You should -see an error and/or warning count in the Inspector's status bar. Clicking on -the error/warning count should open the Console. Hovering over the -error/warning count should show you a tooltip that matches the text in the -button you clicked.</p> -<p>Note: You must reload the page between each button press.</p> diff --git a/chrome/browser/debugger/manual_tests/event-listeners.html b/chrome/browser/debugger/manual_tests/event-listeners.html deleted file mode 100644 index 4dff96d..0000000 --- a/chrome/browser/debugger/manual_tests/event-listeners.html +++ /dev/null @@ -1,30 +0,0 @@ -<head>
- <script>
- function attachListener() {
- document.getElementById("target").addEventListener("click", listenerFunction, true);
- document.getElementById("targetParent").addEventListener("click", listenerFunctionParent, true);
- }
- function listenerFunctionParent(event) {
- event.target.textContent = "event handled";
- }
- function listenerFunction(event) {
- event.target.textContent = "event handled";
- }
- </script>
-</head>
-<body onload="attachListener()">
-<div id="targetParent">
- <div id="target"></div>
-</div>
-<p>To begin test, open DevTools, select the Elements panel. Expand the Event Listeners
-pane in the sidebar.
-<ul>
- <li>Choose the <b><div id="targetParent"...></b> element.
-You should see the "click" section in the Event Listeners pane. Expand the section to see
-the "listenerFunctionParent" function (at "div#targetParent") under it.
- <li>Expand the targetParent node in the tree and choose the <b><div id="target"...></b>
-element. You should see the "click" section in the Event Listeners pane. Expand the section
-to see two functions, "listenerFunctionParent" (at "div#targetParent") and
-"listenerFunction" (at "div#target") under it.
-</ul>
-</body>
diff --git a/chrome/browser/debugger/manual_tests/heap-profiler-test-basic-grid-functionality.html b/chrome/browser/debugger/manual_tests/heap-profiler-test-basic-grid-functionality.html deleted file mode 100644 index 5aa4555..0000000 --- a/chrome/browser/debugger/manual_tests/heap-profiler-test-basic-grid-functionality.html +++ /dev/null @@ -1,32 +0,0 @@ -<html> - <head> - <title>Heap Profiler: basic grid functionality test</title> - </head> - <body> - This is the test for basic functionality of heap snapshot view grid. - <br> - <br> - To use this test: - <ul> - <li>load file in the browser; - <li>open DevTools (Ctrl+Shift+I on Win/Linux, Command+Option+I on Mac); - <li>go to 'Profiles' page; - <li>press 'Take heap snapshot' button - (eye icon on the left side of status bar); - </ul> - <br> - On the left pane under 'Heap snapshots' section, an item called - 'Snapshot 1' must appear, and a grid with snapshot data must - appear on the right. Now test the following functionality in the grid: - <ul> - <li>change sorting order in each column by clicking on its header; - <li>resize each column; - <li>toggle between showing absolute times and percents - (button with percent sign on the status bar); - <li>double-click on numbers in 'Count' and - 'Size' columns to toggle between times and percents for - this column only; - <li>expanding and collapsing tree nodes. - </ul> - </body> -</html> diff --git a/chrome/browser/debugger/manual_tests/heap-profiler-test-snapshots-comparison.html b/chrome/browser/debugger/manual_tests/heap-profiler-test-snapshots-comparison.html deleted file mode 100644 index 3a419d4e..0000000 --- a/chrome/browser/debugger/manual_tests/heap-profiler-test-snapshots-comparison.html +++ /dev/null @@ -1,83 +0,0 @@ -<html> - <head> - <title>Heap Profiler: heap snapshots comparison test</title> - <script type="text/javascript"> - var aHolder = [], bHolder = [], cHolder = [], dHolder = []; - - function A(x) { - this.x = x; - } - - function B(x) { - this.x = x; - } - - function C() {} - - var i; - for (i = 0; i < 100; ++i) { - var b = new B('hello'); - bHolder.push(b); - aHolder.push(new A(b)); - b = null; - } - for (i = 0; i < 25; ++i) { - cHolder.push(new C()); - } - - function D() {} - - function changeStuff() { - if (aHolder.length > 0) { - aHolder.splice(aHolder.length - 25, 25); - } - for (i = 0; i < 25; ++i) { - bHolder.push(new B('hello')); - } - cHolder = []; - for (i = 0; i < 25; ++i) { - dHolder.push(new D()); - } - } - </script> - </head> - <body> - This is the test for heap snapshot comparison functionality. - <br> - <br> - To use this test: - <ul> - <li>load file in the browser; - <li>open DevTools (Ctrl+Shift+I on Win/Linux, Command+Option+I on Mac); - <li>go to 'Profiles' page; - <li>press 'Take heap snapshot' button - (eye icon on the left side of the status bar); - <li>press - <input type="button" name="changeStuff" value="this button" onclick="changeStuff()" />; - <li>press 'Take heap snapshot' button again; - </ul> - <br> - On the left pane under 'Heap snapshots' section, items called - 'Snapshot 1' and 'Snapshot 2' must appear. Select 'Snapshot 2'. - Ensure that absolute values are shown (not percents). - <br> - <br> - TEST 1. Verify the following: - <ul> - <li>the value in '+/- Count' column for 'A' must be '-25'; - <li>after expanding 'A' item, the value in '+/- Count' column - for 'Array' child entry must also be '-25'; - <li>the value in '+/- Count' column for 'B' must be '+25'; - <li>after expanding 'B' item, the value in '+/- Count' column - for 'Array' child entry must also be '+25'; the value for 'A' - child must be '-25'; - </ul> - <br> - TEST 2. Change display to percent view (using the percent button on the - status bar). Verify the following: - <ul> - <li>values in '+/- Count' and '+/- Size' columns for 'C' must be 'deleted'; - <li>values in '+/- Count' and '+/- Size' columns for 'D' must be 'new'; - </ul> - </body> -</html> diff --git a/chrome/browser/debugger/manual_tests/highlight-nodes.html b/chrome/browser/debugger/manual_tests/highlight-nodes.html deleted file mode 100644 index cbeae6f..0000000 --- a/chrome/browser/debugger/manual_tests/highlight-nodes.html +++ /dev/null @@ -1,23 +0,0 @@ -<style> -.skewed { - -webkit-transform:skew(-5deg,-5deg); -} -</style> -<p>This page has basic tests of node highlighting in the inspected page. To test, load this page, open the DevTools and mouseover the nodes in the treeview of the inspector. You should see the highlights happen with the appropriate padding/border/margin/content highlights.</p> -<div style="padding:10px; border: 10px solid; margin: 10px;">padding:10px; border: 10px; margin: 10px;</div> -<div style="padding:10px; border: 10px solid;">padding:10px; border: 10px;</div> -<div style="padding:10px; margin: 10px;">padding:10px; margin: 10px;</div> -<div style="border: 10px solid; margin: 10px;">border: 10px; margin: 10px;</div> -<div style="padding:10px">padding:10px;</div> -<div style="border: 10px solid;">border: 10px;</div> -<div style="margin: 10px;">margin: 10px;</div> -<div>no padding, border, or margin</div> -<div class=skewed style="padding:10px; border: 10px solid; margin: 10px;">-webkit-transform:skew(-5deg,-5deg); padding:10px; border: 10px; margin: 10px;</div> -<div class=skewed style="padding:10px; border: 10px solid;">-webkit-transform:skew(-5deg,-5deg); padding:10px; border: 10px;</div> -<div class=skewed style="padding:10px; margin: 10px;">-webkit-transform:skew(-5deg,-5deg); padding:10px; margin: 10px;</div> -<div class=skewed style="border: 10px solid; margin: 10px;">-webkit-transform:skew(-5deg,-5deg); border: 10px; margin: 10px;</div> -<div class=skewed style="padding:10px">-webkit-transform:skew(-5deg,-5deg); padding:10px;</div> -<div class=skewed style="border: 10px solid;">-webkit-transform:skew(-5deg,-5deg); border: 10px;</div> -<div class=skewed style="margin: 10px;">-webkit-transform:skew(-5deg,-5deg); margin: 10px;</div> -<div class=skewed >-webkit-transform:skew(-5deg,-5deg); no padding, border, or margin</div> - diff --git a/chrome/browser/debugger/manual_tests/highlight-source-line.html b/chrome/browser/debugger/manual_tests/highlight-source-line.html deleted file mode 100644 index a56ed97..0000000 --- a/chrome/browser/debugger/manual_tests/highlight-source-line.html +++ /dev/null @@ -1,3 +0,0 @@ -<p>To test, open the DevTools and reload this page. Then open the Console and click the link for the markup error. You should see the line containing the error briefly highlighted in the source view.</p> - -<p>This line contains a markup error</i>.</p> diff --git a/chrome/browser/debugger/manual_tests/profiler-test-basic-grid-functionality.html b/chrome/browser/debugger/manual_tests/profiler-test-basic-grid-functionality.html deleted file mode 100644 index 1841715..0000000 --- a/chrome/browser/debugger/manual_tests/profiler-test-basic-grid-functionality.html +++ /dev/null @@ -1,38 +0,0 @@ -<html> - <head> - <title>Profiler: basic grid functionality test</title> - <script type="text/javascript" src="resources/fib.js"></script> - </head> - <body onload="run_fib()"> - This test runs a simple looped computation to test basic - functionality of profile view grid. - <br> - <br> - To use this test: - <ul> - <li>load file in the browser; - <li>open DevTools (Ctrl+Shift+I on Win/Linux, Command+Option+I on Mac); - <li>go to 'Profiles' page; - <li>press 'Start profiling' button - (gray dot on the left side of status bar); - <li>wait for 5 seconds; - <li>press 'Stop profiling' button - (red dot on the left side of status bar); - </ul> - <br> - On the left pane under 'CPU profiles' section, an item called - 'Profile 1' must appear, and a grid with profile data must - appear on the right. Now test the following functionality in the grid: - <ul> - <li>change sorting order in each column by clicking on its header; - <li>resize each column; - <li>toggle between showing absolute times and percents - (button with percent sign on the status bar); - <li>double-click on numbers in 'Self' and - 'Total' columns to toggle between times and percents for - this column only; - <li>expanding and collapsing tree nodes; - <li>toggling between "Heavy" and "Tree" views. - </ul> - </body> -</html> diff --git a/chrome/browser/debugger/manual_tests/profiler-test-console-control.html b/chrome/browser/debugger/manual_tests/profiler-test-console-control.html deleted file mode 100644 index 4f2001a..0000000 --- a/chrome/browser/debugger/manual_tests/profiler-test-console-control.html +++ /dev/null @@ -1,27 +0,0 @@ -<html> - <head> - <title>Profiler: test console controlling of CPU profiling</title> - <script type="text/javascript" src="resources/fib.js"></script> - <script type="text/javascript"> - function profile_fib() { - console.profile(); - run_fib(); - window.setTimeout('console.profileEnd();', 5000); - } - </script> - </head> - <body onload="profile_fib()"> - This test runs and profiles a simple looped computation. - <br> - <br> - TEST - <ul> - <li>load file in the browser; - <li>open DevTools with console (Ctrl+Shift+I on Win/Linux, Command+Option+I on Mac); - <li>go to 'Profiles' page; - <li>observe that 'Profile 1' item has appeared under 'CPU profiles' section; - <li>check for presence of 'eternal_fib' entry in the profile view. - </ul> - <br> - </body> -</html> diff --git a/chrome/browser/debugger/manual_tests/profiler-test-focus-and-exclude.html b/chrome/browser/debugger/manual_tests/profiler-test-focus-and-exclude.html deleted file mode 100644 index d33e3eb..0000000 --- a/chrome/browser/debugger/manual_tests/profiler-test-focus-and-exclude.html +++ /dev/null @@ -1,71 +0,0 @@ -<html> - <head> - <title>Profiler: focusing and exclusion test</title> - <script type="text/javascript" src="resources/fib.js"></script> - </head> - <body onload="run_fib()"> - This test runs a simple looped computation to test focusing and - exclusion functionality of profile view grid. - <br> - <br> - To use this test: - <ul> - <li>load file in the browser; - <li>open DevTools (Ctrl+Shift+I on Win/Linux, Command+Option+I on Mac); - <li>go to 'Profiles' page; - <li>press 'Start profiling' button - (gray dot on the left side of status bar); - <li>wait for 5 seconds; - <li>press 'Stop profiling' button - (red dot on the left side of status bar); - </ul> - <br> - On the left pane under 'CPU profiles' section, an item called - 'Profile 1' must appear, and a grid with profile data must - appear on the right. Now test the following functionality in the grid: - <br> - TEST 1: - <ul> - <li>select 'eternal_fib' function entry (without expanding it), - press 'Focus - on selected function' button (eye on the right of the status bar); - <li>ensure that only 'eternal_fib' function and its children are - left in the tree, and 'Total' column for the function shows - '100%' value; - <li>expand 'eternal_fib' function node; - <li>press 'Restore all functions' button; - <li>verify that the value in 'Total' column is less than 100%; - <li>verify that 'eternal_fib' function node is can still be - collapsed and expanded back; - </ul> - <br> - TEST 2: - <ul> - <li>expand two levels of 'Script:' node, select the second-level - node; - <li>repeat the same steps for the selected node (in this case, immediate - parent nodes of the focused node must also remain visible after - focusing); - </ul> - <br> - TEST 3: - <ul> - <li>by expanding 'Script:' node, make sure that at least 3 - 'eternal_fib' function nodes are visible; - <li>select any of 'eternal_fib' nodes and press - 'Exclude selected function' (cross) button on the status bar; - <li>verify that all 'eternal_fib' nodes are no more visible; - <li>expand more 'Script:' node levels, verify that no new - 'eternal_fib' nodes appear with expansion; - <li>press 'Restore all functions' button; - <li>verify that 'eternal_fib' nodes are now visible; - </ul> - <br> - TESTS 4 and 5: - <br> - Now switch to 'Tree (Top Down)' view and repeat testing steps. - For the 'Exclude selected function' function test, use - 'Script:' function node, as 'eternal_fib' has only - one entry in this view. - </body> -</html> diff --git a/chrome/browser/debugger/manual_tests/profiler-test-re-opening.html b/chrome/browser/debugger/manual_tests/profiler-test-re-opening.html deleted file mode 100644 index a615afa..0000000 --- a/chrome/browser/debugger/manual_tests/profiler-test-re-opening.html +++ /dev/null @@ -1,37 +0,0 @@ -<html> - <head> - <title>Profiler: test profiles population on DevTools re-opening</title> - <script type="text/javascript" src="resources/fib.js"></script> - <script type="text/javascript"> - function profile_fib() { - console.profile(); - run_fib(); - window.setTimeout('console.profileEnd();', 5000); - } - </script> - </head> - <body onload="profile_fib()"> - This test runs and profiles a simple looped computation. - <br> - <br> - TEST - <ul> - <li>load file in the browser; - <li>open DevTools with console (Ctrl+Shift+I on Win/Linux, Command+Option+I on Mac); - <li>go to 'Profiles' page; - <li>observe that 'Profile 1' item has appeared under 'CPU profiles' section; - <li>reload page in browser; - <li>observe that after 5 seconds, 'Profile 2' item has appeared under - 'CPU profiles' section; - <li>take a couple of heap snapshots by pressing 'Take heap snapshot.' - button (eye icon on the left of the status bar); - <li>close DevTools window; - <li>re-open DevTools window; - <li>go to 'Profiles' page; - <li>verify that CPU profiles 'Profile 1' and 'Profile 2', and heap profiles - taken previously are restored back (<b>Warning:</b> it may take some - time to re-process them). - </ul> - <br> - </body> -</html> diff --git a/chrome/browser/debugger/manual_tests/resources/fib.js b/chrome/browser/debugger/manual_tests/resources/fib.js deleted file mode 100644 index 804c866..0000000 --- a/chrome/browser/debugger/manual_tests/resources/fib.js +++ /dev/null @@ -1,20 +0,0 @@ -function fib(n) { - return n < 2 ? 1 : fib(n - 1) + fib(n - 2); -} - -function eternal_fib() { - var started = Date.now(); - while(true) { - fib(20); - // Make page responsive by making a break every 100 ms. - if (Date.now() - started >= 100) { - setTimeout(eternal_fib, 0); - return; - } - } -} - -function run_fib() { - // Let the page do initial rendering, then go. - setTimeout(eternal_fib, 200); -} diff --git a/chrome/browser/debugger/manual_tests/resources/loop-statements.js b/chrome/browser/debugger/manual_tests/resources/loop-statements.js deleted file mode 100644 index cbb4e0d..0000000 --- a/chrome/browser/debugger/manual_tests/resources/loop-statements.js +++ /dev/null @@ -1,22 +0,0 @@ -var i; -var a; - -function initialize() -{ - i = false; -} - -function condition() -{ - return !i; -} - -function increment() -{ - i = !i; -} - -function statement() -{ - a = i; -} diff --git a/chrome/browser/debugger/manual_tests/resources/mutate-frame-2.html b/chrome/browser/debugger/manual_tests/resources/mutate-frame-2.html deleted file mode 100644 index 9d413b9..0000000 --- a/chrome/browser/debugger/manual_tests/resources/mutate-frame-2.html +++ /dev/null @@ -1,12 +0,0 @@ -<script> -var count = 1; -function run() { - var div = document.createElement("div"); - div.textContent = "Testing " + (count++); - document.body.appendChild(div); - if (count > 10) - document.body.removeChild(document.body.firstChild); -} - -setInterval(run, 1000); -</script> diff --git a/chrome/browser/debugger/manual_tests/resources/mutate-frame.html b/chrome/browser/debugger/manual_tests/resources/mutate-frame.html deleted file mode 100644 index 08fc656..0000000 --- a/chrome/browser/debugger/manual_tests/resources/mutate-frame.html +++ /dev/null @@ -1,10 +0,0 @@ -<script> -var count = 1; -function run() { - var div = document.createElement("div"); - div.textContent = "Testing " + (count++); - document.body.appendChild(div); -} - -setInterval(run, 1000); -</script> diff --git a/chrome/browser/debugger/manual_tests/resources/primes.js b/chrome/browser/debugger/manual_tests/resources/primes.js deleted file mode 100644 index 64d38dc..0000000 --- a/chrome/browser/debugger/manual_tests/resources/primes.js +++ /dev/null @@ -1,13 +0,0 @@ -function Primes() { - this.primes_ = {}; -} - -Primes.prototype.test = function(p) { - for (var divisor in this.primes_) { - if (p % divisor === 0) return false; - if (divisor * divisor > p) - break; - } - this.primes_[p] = 1; - return true; -} diff --git a/chrome/browser/debugger/manual_tests/resources/script-console-calls.js b/chrome/browser/debugger/manual_tests/resources/script-console-calls.js deleted file mode 100644 index 9c7bc35..0000000 --- a/chrome/browser/debugger/manual_tests/resources/script-console-calls.js +++ /dev/null @@ -1,8 +0,0 @@ -console.info("Test console.info"); -console.log("Test console.log"); -console.warn("Test console.warn"); -console.error("Test console.error"); -console.time("Test console.time"); -console.timeEnd("Test console.time"); -console.count("Test console.count"); -console.assert(false, "Test console.assert"); diff --git a/chrome/browser/debugger/manual_tests/resources/worker-primes.js b/chrome/browser/debugger/manual_tests/resources/worker-primes.js deleted file mode 100644 index 8be021f..0000000 --- a/chrome/browser/debugger/manual_tests/resources/worker-primes.js +++ /dev/null @@ -1,10 +0,0 @@ -importScripts('primes.js'); - -var primes = new Primes(); - -onmessage = function(event) { - var p = event.data; - if (p != parseInt(p)) - throw 'invalid argument'; - postMessage([p, primes.test(p)]); -} |