OLD | NEW |
---|---|
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) { | |
jam
2012/01/26 18:47:34
nit: here and below, CamelCase
jochen (gone - plz use gerrit)
2012/01/27 08:49:56
Done.
| |
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 |
OLD | NEW |