Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Unified Diff: content/shell/shell_render_view_observer.cc

Issue 9289045: Add option --dump-render-tree to content_shell to dump the render tree as text. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/shell/shell_render_view_observer.h ('k') | content/shell/shell_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/shell_render_view_observer.cc
diff --git a/content/shell/shell_render_view_observer.cc b/content/shell/shell_render_view_observer.cc
index 942f6019464624eaafe0a8d50e3feb433d55c2b2..065551ed81c0f0c978f150ddcd50cb3547fddecb 100644
--- a/content/shell/shell_render_view_observer.cc
+++ b/content/shell/shell_render_view_observer.cc
@@ -4,8 +4,54 @@
#include "content/shell/shell_render_view_observer.h"
+#include "content/public/renderer/render_view.h"
+#include "content/shell/shell_messages.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+
+using WebKit::WebFrame;
+using WebKit::WebElement;
+
namespace content {
+namespace {
+
+std::string DumpDocumentText(WebFrame* frame) {
+ // We use the document element's text instead of the body text here because
+ // not all documents have a body, such as XML documents.
+ WebElement documentElement = frame->document().documentElement();
+ if (documentElement.isNull())
+ return std::string();
+ return documentElement.innerText().utf8();
+}
+
+std::string DumpFramesAsText(WebFrame* frame, bool recursive) {
+ std::string result;
+
+ // Add header for all but the main frame. Skip emtpy frames.
+ if (frame->parent() && !frame->document().documentElement().isNull()) {
+ result.append("\n--------\nFrame: '");
+ result.append(frame->name().utf8().data());
+ result.append("'\n--------\n");
+ }
+
+ result.append(DumpDocumentText(frame));
+ result.append("\n");
+
+ if (recursive) {
+ for (WebFrame* child = frame->firstChild(); child;
+ child = child->nextSibling()) {
+ result.append(DumpFramesAsText(child, recursive));
+ }
+ }
+ return result;
+}
+
+} // namespace
ShellRenderViewObserver::ShellRenderViewObserver(RenderView* render_view)
: RenderViewObserver(render_view) {
}
@@ -14,7 +60,19 @@ ShellRenderViewObserver::~ShellRenderViewObserver() {
}
bool ShellRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
- return false;
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(ShellRenderViewObserver, message)
+ IPC_MESSAGE_HANDLER(ShellViewMsg_CaptureTextDump, OnCaptureTextDump)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
+}
+
+void ShellRenderViewObserver::OnCaptureTextDump(bool recursive) {
+ std::string dump =
+ DumpFramesAsText(render_view()->GetWebView()->mainFrame(), recursive);
+ Send(new ShellViewHostMsg_TextDump(routing_id(), dump));
}
} // namespace content
« no previous file with comments | « content/shell/shell_render_view_observer.h ('k') | content/shell/shell_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698