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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/shell/shell_render_view_observer.h ('k') | content/shell/shell_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/shell/shell_render_view_observer.h" 5 #include "content/shell/shell_render_view_observer.h"
6 6
7 #include "content/public/renderer/render_view.h"
8 #include "content/shell/shell_messages.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h "
10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
15
16 using WebKit::WebFrame;
17 using WebKit::WebElement;
18
7 namespace content { 19 namespace content {
8 20
21 namespace {
22
23 std::string DumpDocumentText(WebFrame* frame) {
24 // We use the document element's text instead of the body text here because
25 // not all documents have a body, such as XML documents.
26 WebElement documentElement = frame->document().documentElement();
27 if (documentElement.isNull())
28 return std::string();
29 return documentElement.innerText().utf8();
30 }
31
32 std::string DumpFramesAsText(WebFrame* frame, bool recursive) {
33 std::string result;
34
35 // Add header for all but the main frame. Skip emtpy frames.
36 if (frame->parent() && !frame->document().documentElement().isNull()) {
37 result.append("\n--------\nFrame: '");
38 result.append(frame->name().utf8().data());
39 result.append("'\n--------\n");
40 }
41
42 result.append(DumpDocumentText(frame));
43 result.append("\n");
44
45 if (recursive) {
46 for (WebFrame* child = frame->firstChild(); child;
47 child = child->nextSibling()) {
48 result.append(DumpFramesAsText(child, recursive));
49 }
50 }
51 return result;
52 }
53
54 } // namespace
9 ShellRenderViewObserver::ShellRenderViewObserver(RenderView* render_view) 55 ShellRenderViewObserver::ShellRenderViewObserver(RenderView* render_view)
10 : RenderViewObserver(render_view) { 56 : RenderViewObserver(render_view) {
11 } 57 }
12 58
13 ShellRenderViewObserver::~ShellRenderViewObserver() { 59 ShellRenderViewObserver::~ShellRenderViewObserver() {
14 } 60 }
15 61
16 bool ShellRenderViewObserver::OnMessageReceived(const IPC::Message& message) { 62 bool ShellRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
17 return false; 63 bool handled = true;
64 IPC_BEGIN_MESSAGE_MAP(ShellRenderViewObserver, message)
65 IPC_MESSAGE_HANDLER(ShellViewMsg_CaptureTextDump, OnCaptureTextDump)
66 IPC_MESSAGE_UNHANDLED(handled = false)
67 IPC_END_MESSAGE_MAP()
68
69 return handled;
70 }
71
72 void ShellRenderViewObserver::OnCaptureTextDump(bool recursive) {
73 std::string dump =
74 DumpFramesAsText(render_view()->GetWebView()->mainFrame(), recursive);
75 Send(new ShellViewHostMsg_TextDump(routing_id(), dump));
18 } 76 }
19 77
20 } // namespace content 78 } // namespace content
OLDNEW
« 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