OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <objidl.h> | 8 #include <objidl.h> |
9 #include <mlang.h> | 9 #include <mlang.h> |
10 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | 10 #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 } | 115 } |
116 | 116 |
117 return result; | 117 return result; |
118 } | 118 } |
119 | 119 |
120 string16 DumpRenderer(WebFrame* web_frame) { | 120 string16 DumpRenderer(WebFrame* web_frame) { |
121 return web_frame->renderTreeAsText(); | 121 return web_frame->renderTreeAsText(); |
122 } | 122 } |
123 | 123 |
124 bool CounterValueForElementById(WebFrame* web_frame, const std::string& id, | 124 bool CounterValueForElementById(WebFrame* web_frame, const std::string& id, |
125 std::wstring* counter_value) { | 125 string16* counter_value) { |
126 WebString result = | 126 WebString result = |
127 web_frame->counterValueForElementById(WebString::fromUTF8(id)); | 127 web_frame->counterValueForElementById(WebString::fromUTF8(id)); |
128 if (result.isNull()) | 128 if (result.isNull()) |
129 return false; | 129 return false; |
130 | 130 |
131 *counter_value = UTF16ToWideHack(result); | 131 *counter_value = result; |
132 return true; | 132 return true; |
133 } | 133 } |
134 | 134 |
135 int PageNumberForElementById(WebFrame* web_frame, | 135 int PageNumberForElementById(WebFrame* web_frame, |
136 const std::string& id, | 136 const std::string& id, |
137 float page_width_in_pixels, | 137 float page_width_in_pixels, |
138 float page_height_in_pixels) { | 138 float page_height_in_pixels) { |
139 return web_frame->pageNumberForElementById(WebString::fromUTF8(id), | 139 return web_frame->pageNumberForElementById(WebString::fromUTF8(id), |
140 page_width_in_pixels, | 140 page_width_in_pixels, |
141 page_height_in_pixels); | 141 page_height_in_pixels); |
142 } | 142 } |
143 | 143 |
144 int NumberOfPages(WebFrame* web_frame, | 144 int NumberOfPages(WebFrame* web_frame, |
145 float page_width_in_pixels, | 145 float page_width_in_pixels, |
146 float page_height_in_pixels) { | 146 float page_height_in_pixels) { |
147 WebSize size(static_cast<int>(page_width_in_pixels), | 147 WebSize size(static_cast<int>(page_width_in_pixels), |
148 static_cast<int>(page_height_in_pixels)); | 148 static_cast<int>(page_height_in_pixels)); |
149 int number_of_pages = web_frame->printBegin(size); | 149 int number_of_pages = web_frame->printBegin(size); |
150 web_frame->printEnd(); | 150 web_frame->printEnd(); |
151 return number_of_pages; | 151 return number_of_pages; |
152 } | 152 } |
153 | 153 |
154 std::wstring DumpFrameScrollPosition(WebFrame* web_frame, bool recursive) { | 154 string16 DumpFrameScrollPosition(WebFrame* web_frame, bool recursive) { |
155 gfx::Size offset = web_frame->scrollOffset(); | 155 gfx::Size offset = web_frame->scrollOffset(); |
156 std::wstring result; | 156 std::string result_utf8; |
157 | 157 |
158 if (offset.width() > 0 || offset.height() > 0) { | 158 if (offset.width() > 0 || offset.height() > 0) { |
159 if (web_frame->parent()) { | 159 if (web_frame->parent()) { |
160 base::StringAppendF(&result, L"frame '%ls' ", UTF16ToWide( | 160 base::StringAppendF(&result_utf8, "frame '%s' ", |
161 web_frame->name()).c_str()); | 161 UTF16ToUTF8(web_frame->name()).c_str()); |
162 } | 162 } |
163 base::StringAppendF(&result, L"scrolled to %d,%d\n", | 163 base::StringAppendF(&result_utf8, "scrolled to %d,%d\n", |
164 offset.width(), offset.height()); | 164 offset.width(), offset.height()); |
165 } | 165 } |
166 | 166 |
167 string16 result = UTF8ToUTF16(result_utf8); | |
168 | |
167 if (recursive) { | 169 if (recursive) { |
168 WebFrame* child = web_frame->firstChild(); | 170 WebFrame* child = web_frame->firstChild(); |
169 for (; child; child = child->nextSibling()) | 171 for (; child; child = child->nextSibling()) |
170 result.append(DumpFrameScrollPosition(child, recursive)); | 172 result.append(DumpFrameScrollPosition(child, recursive)); |
171 } | 173 } |
172 | 174 |
173 return result; | 175 return result; |
174 } | 176 } |
175 | 177 |
176 // Returns True if item1 < item2. | 178 // Returns True if item1 < item2. |
177 static bool HistoryItemCompareLess(const WebHistoryItem& item1, | 179 static bool HistoryItemCompareLess(const WebHistoryItem& item1, |
178 const WebHistoryItem& item2) { | 180 const WebHistoryItem& item2) { |
179 string16 target1 = item1.target(); | 181 string16 target1 = item1.target(); |
180 string16 target2 = item2.target(); | 182 string16 target2 = item2.target(); |
181 std::transform(target1.begin(), target1.end(), target1.begin(), tolower); | 183 std::transform(target1.begin(), target1.end(), target1.begin(), tolower); |
182 std::transform(target2.begin(), target2.end(), target2.begin(), tolower); | 184 std::transform(target2.begin(), target2.end(), target2.begin(), tolower); |
183 return target1 < target2; | 185 return target1 < target2; |
184 } | 186 } |
185 | 187 |
186 // Writes out a HistoryItem into a string in a readable format. | 188 // Writes out a HistoryItem into a UTF-8 string in a readable format. |
187 static std::wstring DumpHistoryItem(const WebHistoryItem& item, | 189 static std::string DumpHistoryItem(const WebHistoryItem& item, |
188 int indent, bool is_current) { | 190 int indent, bool is_current) { |
viettrungluu
2010/12/14 01:22:18
Nit: realign indentation.
| |
189 std::wstring result; | 191 std::string result; |
190 | 192 |
191 if (is_current) { | 193 if (is_current) { |
192 result.append(L"curr->"); | 194 result.append("curr->"); |
193 result.append(indent - 6, L' '); // 6 == L"curr->".length() | 195 result.append(indent - 6, ' '); // 6 == "curr->".length() |
194 } else { | 196 } else { |
195 result.append(indent, L' '); | 197 result.append(indent, ' '); |
196 } | 198 } |
197 | 199 |
198 std::string url = item.urlString().utf8(); | 200 std::string url = item.urlString().utf8(); |
199 size_t pos; | 201 size_t pos; |
200 if (url.find(kFileUrlPattern) == 0 && | 202 if (url.find(kFileUrlPattern) == 0 && |
201 ((pos = url.find(kLayoutTestsPattern)) != std::string::npos)) { | 203 ((pos = url.find(kLayoutTestsPattern)) != std::string::npos)) { |
202 // adjust file URLs to match upstream results. | 204 // adjust file URLs to match upstream results. |
203 url.replace(0, pos + kLayoutTestsPatternSize, kFileTestPrefix); | 205 url.replace(0, pos + kLayoutTestsPatternSize, kFileTestPrefix); |
204 } else if (url.find(kDataUrlPattern) == 0) { | 206 } else if (url.find(kDataUrlPattern) == 0) { |
205 // URL-escape data URLs to match results upstream. | 207 // URL-escape data URLs to match results upstream. |
206 std::string path = EscapePath(url.substr(kDataUrlPatternSize)); | 208 std::string path = EscapePath(url.substr(kDataUrlPatternSize)); |
207 url.replace(kDataUrlPatternSize, url.length(), path); | 209 url.replace(kDataUrlPatternSize, url.length(), path); |
208 } | 210 } |
209 | 211 |
210 result.append(UTF8ToWide(url)); | 212 result.append(url); |
211 if (!item.target().isEmpty()) | 213 if (!item.target().isEmpty()) |
212 result.append(L" (in frame \"" + UTF16ToWide(item.target()) + L"\")"); | 214 result.append(" (in frame \"" + UTF16ToUTF8(item.target()) + "\")"); |
213 if (item.isTargetItem()) | 215 if (item.isTargetItem()) |
214 result.append(L" **nav target**"); | 216 result.append(" **nav target**"); |
215 result.append(L"\n"); | 217 result.append("\n"); |
216 | 218 |
217 const WebVector<WebHistoryItem>& children = item.children(); | 219 const WebVector<WebHistoryItem>& children = item.children(); |
218 if (!children.isEmpty()) { | 220 if (!children.isEmpty()) { |
219 // Must sort to eliminate arbitrary result ordering which defeats | 221 // Must sort to eliminate arbitrary result ordering which defeats |
220 // reproducible testing. | 222 // reproducible testing. |
221 // TODO(darin): WebVector should probably just be a std::vector!! | 223 // TODO(darin): WebVector should probably just be a std::vector!! |
222 std::vector<WebHistoryItem> sorted_children; | 224 std::vector<WebHistoryItem> sorted_children; |
223 for (size_t i = 0; i < children.size(); ++i) | 225 for (size_t i = 0; i < children.size(); ++i) |
224 sorted_children.push_back(children[i]); | 226 sorted_children.push_back(children[i]); |
225 std::sort(sorted_children.begin(), sorted_children.end(), | 227 std::sort(sorted_children.begin(), sorted_children.end(), |
226 HistoryItemCompareLess); | 228 HistoryItemCompareLess); |
227 for (size_t i = 0; i < sorted_children.size(); i++) | 229 for (size_t i = 0; i < sorted_children.size(); i++) |
228 result += DumpHistoryItem(sorted_children[i], indent+4, false); | 230 result += DumpHistoryItem(sorted_children[i], indent+4, false); |
229 } | 231 } |
230 | 232 |
231 return result; | 233 return result; |
232 } | 234 } |
233 | 235 |
234 std::wstring DumpHistoryState(const std::string& history_state, int indent, | 236 string16 DumpHistoryState(const std::string& history_state, int indent, |
235 bool is_current) { | 237 bool is_current) { |
236 return DumpHistoryItem(HistoryItemFromString(history_state), indent, | 238 return UTF8ToUTF16( |
237 is_current); | 239 DumpHistoryItem(HistoryItemFromString(history_state), indent, |
240 is_current)); | |
238 } | 241 } |
239 | 242 |
240 void ResetBeforeTestRun(WebView* view) { | 243 void ResetBeforeTestRun(WebView* view) { |
241 WebFrame* web_frame = view->mainFrame(); | 244 WebFrame* web_frame = view->mainFrame(); |
242 | 245 |
243 // Reset the main frame name since tests always expect it to be empty. It | 246 // Reset the main frame name since tests always expect it to be empty. It |
244 // is normally not reset between page loads (even in IE and FF). | 247 // is normally not reset between page loads (even in IE and FF). |
245 if (web_frame) | 248 if (web_frame) |
246 web_frame->setName(WebString()); | 249 web_frame->setName(WebString()); |
247 | 250 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 NOTIMPLEMENTED(); | 419 NOTIMPLEMENTED(); |
417 return NULL; | 420 return NULL; |
418 #endif | 421 #endif |
419 } | 422 } |
420 | 423 |
421 int GetGlyphPageCount() { | 424 int GetGlyphPageCount() { |
422 return WebGlyphCache::pageCount(); | 425 return WebGlyphCache::pageCount(); |
423 } | 426 } |
424 | 427 |
425 } // namespace webkit_glue | 428 } // namespace webkit_glue |
OLD | NEW |