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 "webkit/glue/webkit_glue.h" | 5 #include "webkit/glue/webkit_glue.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <mlang.h> | 8 #include <mlang.h> |
9 #include <objidl.h> | 9 #include <objidl.h> |
10 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | 10 #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 void EnableWebCoreLogChannels(const std::string& channels) { | 95 void EnableWebCoreLogChannels(const std::string& channels) { |
96 if (channels.empty()) | 96 if (channels.empty()) |
97 return; | 97 return; |
98 base::StringTokenizer t(channels, ", "); | 98 base::StringTokenizer t(channels, ", "); |
99 while (t.GetNext()) { | 99 while (t.GetNext()) { |
100 WebKit::enableLogChannel(t.token().c_str()); | 100 WebKit::enableLogChannel(t.token().c_str()); |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 string16 DumpDocumentText(WebFrame* web_frame) { | 104 base::string16 DumpDocumentText(WebFrame* web_frame) { |
105 // We use the document element's text instead of the body text here because | 105 // We use the document element's text instead of the body text here because |
106 // not all documents have a body, such as XML documents. | 106 // not all documents have a body, such as XML documents. |
107 WebElement document_element = web_frame->document().documentElement(); | 107 WebElement document_element = web_frame->document().documentElement(); |
108 if (document_element.isNull()) | 108 if (document_element.isNull()) |
109 return string16(); | 109 return base::string16(); |
110 | 110 |
111 return document_element.innerText(); | 111 return document_element.innerText(); |
112 } | 112 } |
113 | 113 |
114 string16 DumpFramesAsText(WebFrame* web_frame, bool recursive) { | 114 base::string16 DumpFramesAsText(WebFrame* web_frame, bool recursive) { |
115 string16 result; | 115 base::string16 result; |
116 | 116 |
117 // Add header for all but the main frame. Skip empty frames. | 117 // Add header for all but the main frame. Skip empty frames. |
118 if (web_frame->parent() && | 118 if (web_frame->parent() && |
119 !web_frame->document().documentElement().isNull()) { | 119 !web_frame->document().documentElement().isNull()) { |
120 result.append(ASCIIToUTF16("\n--------\nFrame: '")); | 120 result.append(ASCIIToUTF16("\n--------\nFrame: '")); |
121 result.append(web_frame->uniqueName()); | 121 result.append(web_frame->uniqueName()); |
122 result.append(ASCIIToUTF16("'\n--------\n")); | 122 result.append(ASCIIToUTF16("'\n--------\n")); |
123 } | 123 } |
124 | 124 |
125 result.append(DumpDocumentText(web_frame)); | 125 result.append(DumpDocumentText(web_frame)); |
126 result.append(ASCIIToUTF16("\n")); | 126 result.append(ASCIIToUTF16("\n")); |
127 | 127 |
128 if (recursive) { | 128 if (recursive) { |
129 WebFrame* child = web_frame->firstChild(); | 129 WebFrame* child = web_frame->firstChild(); |
130 for (; child; child = child->nextSibling()) | 130 for (; child; child = child->nextSibling()) |
131 result.append(DumpFramesAsText(child, recursive)); | 131 result.append(DumpFramesAsText(child, recursive)); |
132 } | 132 } |
133 | 133 |
134 return result; | 134 return result; |
135 } | 135 } |
136 | 136 |
137 string16 DumpRenderer(WebFrame* web_frame) { | 137 base::string16 DumpRenderer(WebFrame* web_frame) { |
138 return web_frame->renderTreeAsText(); | 138 return web_frame->renderTreeAsText(); |
139 } | 139 } |
140 | 140 |
141 int NumberOfPages(WebFrame* web_frame, | 141 int NumberOfPages(WebFrame* web_frame, |
142 float page_width_in_pixels, | 142 float page_width_in_pixels, |
143 float page_height_in_pixels) { | 143 float page_height_in_pixels) { |
144 WebSize size(static_cast<int>(page_width_in_pixels), | 144 WebSize size(static_cast<int>(page_width_in_pixels), |
145 static_cast<int>(page_height_in_pixels)); | 145 static_cast<int>(page_height_in_pixels)); |
146 | 146 |
147 WebPrintParams print_params; | 147 WebPrintParams print_params; |
148 print_params.paperSize = size; | 148 print_params.paperSize = size; |
149 print_params.printContentArea = WebRect(0, 0, size.width, size.height); | 149 print_params.printContentArea = WebRect(0, 0, size.width, size.height); |
150 print_params.printableArea = WebRect(0, 0, size.width, size.height); | 150 print_params.printableArea = WebRect(0, 0, size.width, size.height); |
151 | 151 |
152 int number_of_pages = web_frame->printBegin(print_params); | 152 int number_of_pages = web_frame->printBegin(print_params); |
153 web_frame->printEnd(); | 153 web_frame->printEnd(); |
154 return number_of_pages; | 154 return number_of_pages; |
155 } | 155 } |
156 | 156 |
157 string16 DumpFrameScrollPosition(WebFrame* web_frame, bool recursive) { | 157 base::string16 DumpFrameScrollPosition(WebFrame* web_frame, bool recursive) { |
158 gfx::Size offset = web_frame->scrollOffset(); | 158 gfx::Size offset = web_frame->scrollOffset(); |
159 std::string result_utf8; | 159 std::string result_utf8; |
160 | 160 |
161 if (offset.width() > 0 || offset.height() > 0) { | 161 if (offset.width() > 0 || offset.height() > 0) { |
162 if (web_frame->parent()) { | 162 if (web_frame->parent()) { |
163 base::StringAppendF(&result_utf8, "frame '%s' ", | 163 base::StringAppendF(&result_utf8, "frame '%s' ", |
164 UTF16ToUTF8(web_frame->uniqueName()).c_str()); | 164 UTF16ToUTF8(web_frame->uniqueName()).c_str()); |
165 } | 165 } |
166 base::StringAppendF(&result_utf8, "scrolled to %d,%d\n", | 166 base::StringAppendF(&result_utf8, "scrolled to %d,%d\n", |
167 offset.width(), offset.height()); | 167 offset.width(), offset.height()); |
168 } | 168 } |
169 | 169 |
170 string16 result = UTF8ToUTF16(result_utf8); | 170 base::string16 result = UTF8ToUTF16(result_utf8); |
171 | 171 |
172 if (recursive) { | 172 if (recursive) { |
173 WebFrame* child = web_frame->firstChild(); | 173 WebFrame* child = web_frame->firstChild(); |
174 for (; child; child = child->nextSibling()) | 174 for (; child; child = child->nextSibling()) |
175 result.append(DumpFrameScrollPosition(child, recursive)); | 175 result.append(DumpFrameScrollPosition(child, recursive)); |
176 } | 176 } |
177 | 177 |
178 return result; | 178 return result; |
179 } | 179 } |
180 | 180 |
181 // Returns True if item1 < item2. | 181 // Returns True if item1 < item2. |
182 static bool HistoryItemCompareLess(const WebHistoryItem& item1, | 182 static bool HistoryItemCompareLess(const WebHistoryItem& item1, |
183 const WebHistoryItem& item2) { | 183 const WebHistoryItem& item2) { |
184 string16 target1 = item1.target(); | 184 base::string16 target1 = item1.target(); |
185 string16 target2 = item2.target(); | 185 base::string16 target2 = item2.target(); |
186 std::transform(target1.begin(), target1.end(), target1.begin(), tolower); | 186 std::transform(target1.begin(), target1.end(), target1.begin(), tolower); |
187 std::transform(target2.begin(), target2.end(), target2.begin(), tolower); | 187 std::transform(target2.begin(), target2.end(), target2.begin(), tolower); |
188 return target1 < target2; | 188 return target1 < target2; |
189 } | 189 } |
190 | 190 |
191 // Writes out a HistoryItem into a UTF-8 string in a readable format. | 191 // Writes out a HistoryItem into a UTF-8 string in a readable format. |
192 static std::string DumpHistoryItem(const WebHistoryItem& item, | 192 static std::string DumpHistoryItem(const WebHistoryItem& item, |
193 int indent, bool is_current) { | 193 int indent, bool is_current) { |
194 std::string result; | 194 std::string result; |
195 | 195 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 sorted_children.push_back(children[i]); | 229 sorted_children.push_back(children[i]); |
230 std::sort(sorted_children.begin(), sorted_children.end(), | 230 std::sort(sorted_children.begin(), sorted_children.end(), |
231 HistoryItemCompareLess); | 231 HistoryItemCompareLess); |
232 for (size_t i = 0; i < sorted_children.size(); i++) | 232 for (size_t i = 0; i < sorted_children.size(); i++) |
233 result += DumpHistoryItem(sorted_children[i], indent+4, false); | 233 result += DumpHistoryItem(sorted_children[i], indent+4, false); |
234 } | 234 } |
235 | 235 |
236 return result; | 236 return result; |
237 } | 237 } |
238 | 238 |
239 string16 DumpHistoryState(const std::string& history_state, int indent, | 239 base::string16 DumpHistoryState(const std::string& history_state, int indent, |
240 bool is_current) { | 240 bool is_current) { |
241 return UTF8ToUTF16( | 241 return UTF8ToUTF16( |
242 DumpHistoryItem(HistoryItemFromString(history_state), indent, | 242 DumpHistoryItem(HistoryItemFromString(history_state), indent, |
243 is_current)); | 243 is_current)); |
244 } | 244 } |
245 | 245 |
246 #ifndef NDEBUG | 246 #ifndef NDEBUG |
247 // The log macro was having problems due to collisions with WTF, so we just | 247 // The log macro was having problems due to collisions with WTF, so we just |
248 // code here what that would have inlined. | 248 // code here what that would have inlined. |
249 void DumpLeakedObject(const char* file, int line, const char* object, | 249 void DumpLeakedObject(const char* file, int line, const char* object, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 base::GetCurrentProcessHandle())); | 366 base::GetCurrentProcessHandle())); |
367 return process_metrics->GetPagefileUsage() >> 10; | 367 return process_metrics->GetPagefileUsage() >> 10; |
368 } | 368 } |
369 #endif | 369 #endif |
370 | 370 |
371 double ZoomFactorToZoomLevel(double factor) { | 371 double ZoomFactorToZoomLevel(double factor) { |
372 return WebView::zoomFactorToZoomLevel(factor); | 372 return WebView::zoomFactorToZoomLevel(factor); |
373 } | 373 } |
374 | 374 |
375 } // namespace webkit_glue | 375 } // namespace webkit_glue |
OLD | NEW |