summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-31 18:49:42 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-31 18:49:42 +0000
commit9678cb44a6bf820fb86dbc782869baa1757e7909 (patch)
tree86953b14a8c46f86707fd933b74ab52d70ddc369
parentcc9350ce9c2a5bddb341d1b76f8f29f7d8a46cef (diff)
downloadchromium_src-9678cb44a6bf820fb86dbc782869baa1757e7909.zip
chromium_src-9678cb44a6bf820fb86dbc782869baa1757e7909.tar.gz
chromium_src-9678cb44a6bf820fb86dbc782869baa1757e7909.tar.bz2
DevTools: introduce tab contents list provider for remote debugging.
BUG= TEST= Review URL: http://codereview.chromium.org/6409013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73168 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_process_impl.cc5
-rw-r--r--chrome/browser/debugger/browser_list_tabcontents_provider.cc20
-rw-r--r--chrome/browser/debugger/browser_list_tabcontents_provider.h21
-rw-r--r--chrome/browser/debugger/devtools_http_protocol_handler.cc79
-rw-r--r--chrome/browser/debugger/devtools_http_protocol_handler.h22
-rw-r--r--chrome/chrome.gyp2
6 files changed, 108 insertions, 41 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index a8efdb4..849ac7d 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/browser_process_sub_thread.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/browser_trial.h"
+#include "chrome/browser/debugger/browser_list_tabcontents_provider.h"
#include "chrome/browser/debugger/devtools_http_protocol_handler.h"
#include "chrome/browser/debugger/devtools_manager.h"
#include "chrome/browser/debugger/devtools_protocol_handler.h"
@@ -464,7 +465,9 @@ void BrowserProcessImpl::InitDevToolsHttpProtocolHandler(
const std::string& frontend_url) {
DCHECK(CalledOnValidThread());
devtools_http_handler_ =
- DevToolsHttpProtocolHandler::Start(port, frontend_url);
+ DevToolsHttpProtocolHandler::Start(port,
+ frontend_url,
+ new BrowserListTabContentsProvider());
}
void BrowserProcessImpl::InitDevToolsLegacyProtocolHandler(int port) {
diff --git a/chrome/browser/debugger/browser_list_tabcontents_provider.cc b/chrome/browser/debugger/browser_list_tabcontents_provider.cc
new file mode 100644
index 0000000..9321241
--- /dev/null
+++ b/chrome/browser/debugger/browser_list_tabcontents_provider.cc
@@ -0,0 +1,20 @@
+// 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/browser_list.h"
+#include "chrome/browser/tabs/tab_strip_model.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
new file mode 100644
index 0000000..5db5f3d
--- /dev/null
+++ b/chrome/browser/debugger/browser_list_tabcontents_provider.h
@@ -0,0 +1,21 @@
+// 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() {}
+ ~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/devtools_http_protocol_handler.cc b/chrome/browser/debugger/devtools_http_protocol_handler.cc
index 5d63cb1..4fe3a02 100644
--- a/chrome/browser/debugger/devtools_http_protocol_handler.cc
+++ b/chrome/browser/debugger/devtools_http_protocol_handler.cc
@@ -12,13 +12,11 @@
#include "base/string_number_conversions.h"
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_thread.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/tab_contents/tab_contents.h"
-#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/devtools_messages.h"
#include "chrome/common/net/url_request_context_getter.h"
@@ -75,9 +73,10 @@ class DevToolsClientHostImpl : public DevToolsClientHost {
// static
scoped_refptr<DevToolsHttpProtocolHandler> DevToolsHttpProtocolHandler::Start(
int port,
- const std::string& frontend_url) {
+ const std::string& frontend_url,
+ TabContentsProvider* provider) {
scoped_refptr<DevToolsHttpProtocolHandler> http_handler =
- new DevToolsHttpProtocolHandler(port, frontend_url);
+ new DevToolsHttpProtocolHandler(port, frontend_url, provider);
http_handler->Start();
return http_handler;
}
@@ -197,30 +196,32 @@ void DevToolsHttpProtocolHandler::OnHttpRequestUI(
" document.body.appendChild(document.createElement('br'));"
"}";
- 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_contents = model->GetTabContentsAt(i);
- NavigationController& controller = tab_contents->controller();
- NavigationEntry* entry = controller.GetActiveEntry();
- if (entry == NULL)
- continue;
-
- if (!entry->url().is_valid())
- continue;
-
- DevToolsClientHost* client_host = DevToolsManager::GetInstance()->
- GetDevToolsClientHostFor(tab_contents->tab_contents()->
+ InspectableTabs inspectable_tabs =
+ tab_contents_provider_->GetInspectableTabs();
+
+ for (InspectableTabs::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)
+ continue;
+
+ if (!entry->url().is_valid())
+ continue;
+
+ DevToolsClientHost* client_host = DevToolsManager::GetInstance()->
+ GetDevToolsClientHostFor(tab_contents->tab_contents()->
render_view_host());
- response += StringPrintf(
- "addTab(%d, '%s', %s, '%s');\n",
- controller.session_id().id(),
- entry->url().spec().c_str(),
- client_host ? "true" : "false",
- overriden_frontend_url_.c_str());
- }
+ response += StringPrintf(
+ "addTab(%d, '%s', %s, '%s');\n",
+ controller.session_id().id(),
+ entry->url().spec().c_str(),
+ client_host ? "true" : "false",
+ overriden_frontend_url_.c_str());
}
+
response += "</script></body></html>";
Send200(socket, response, "text/html; charset=UTF-8");
}
@@ -362,10 +363,12 @@ void DevToolsHttpProtocolHandler::OnReadCompleted(net::URLRequest* request,
DevToolsHttpProtocolHandler::DevToolsHttpProtocolHandler(
int port,
- const std::string& frontend_host)
+ const std::string& frontend_host,
+ TabContentsProvider* provider)
: port_(port),
overriden_frontend_url_(frontend_host),
- server_(NULL) {
+ server_(NULL),
+ tab_contents_provider_(provider) {
if (overriden_frontend_url_.empty())
overriden_frontend_url_ = "/devtools/devtools.html";
}
@@ -449,16 +452,16 @@ void DevToolsHttpProtocolHandler::ReleaseSocket(
}
TabContents* DevToolsHttpProtocolHandler::GetTabContents(int session_id) {
- 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_contents = model->GetTabContentsAt(i);
- NavigationController& controller =
- tab_contents->controller();
- if (controller.session_id().id() == session_id)
- return controller.tab_contents();
- }
+ InspectableTabs inspectable_tabs =
+ tab_contents_provider_->GetInspectableTabs();
+
+ for (InspectableTabs::iterator it = inspectable_tabs.begin();
+ it != inspectable_tabs.end(); ++it) {
+ TabContentsWrapper* tab_contents = *it;
+ NavigationController& controller =
+ tab_contents->controller();
+ if (controller.session_id().id() == session_id)
+ return controller.tab_contents();
}
return NULL;
}
diff --git a/chrome/browser/debugger/devtools_http_protocol_handler.h b/chrome/browser/debugger/devtools_http_protocol_handler.h
index e28da6a..1bb4726 100644
--- a/chrome/browser/debugger/devtools_http_protocol_handler.h
+++ b/chrome/browser/debugger/devtools_http_protocol_handler.h
@@ -8,23 +8,38 @@
#include <set>
#include <string>
+#include <vector>
#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
#include "net/server/http_listen_socket.h"
#include "net/url_request/url_request.h"
class DevToolsClientHost;
class DevToolsHttpServer;
class TabContents;
+class TabContentsWrapper;
class DevToolsHttpProtocolHandler
: public HttpListenSocket::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(
int port,
- const std::string& frontend_url);
+ 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.
@@ -33,7 +48,9 @@ class DevToolsHttpProtocolHandler
private:
friend class base::RefCountedThreadSafe<DevToolsHttpProtocolHandler>;
- DevToolsHttpProtocolHandler(int port, const std::string& frontend_url);
+ DevToolsHttpProtocolHandler(int port,
+ const std::string& frontend_url,
+ TabContentsProvider* provider);
virtual ~DevToolsHttpProtocolHandler();
void Start();
@@ -90,6 +107,7 @@ class DevToolsHttpProtocolHandler
typedef std::map<HttpListenSocket*, DevToolsClientHost*>
SocketToClientHostMap;
SocketToClientHostMap socket_to_client_host_ui_;
+ scoped_ptr<TabContentsProvider> tab_contents_provider_;
DISALLOW_COPY_AND_ASSIGN(DevToolsHttpProtocolHandler);
};
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 775a4a9..dbd1e42 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -508,6 +508,8 @@
'..',
],
'sources': [
+ 'browser/debugger/browser_list_tabcontents_provider.cc',
+ 'browser/debugger/browser_list_tabcontents_provider.h',
'browser/debugger/debugger_remote_service.cc',
'browser/debugger/debugger_remote_service.h',
'browser/debugger/devtools_client_host.cc',