| 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 // This file contains the implementation of TestWebViewDelegate, which serves | 5 // This file contains the implementation of TestWebViewDelegate, which serves |
| 6 // as the WebViewDelegate for the TestShellWebHost. The host is expected to | 6 // as the WebViewDelegate for the TestShellWebHost. The host is expected to |
| 7 // have initialized a MessageLoop before these methods are called. | 7 // have initialized a MessageLoop before these methods are called. |
| 8 | 8 |
| 9 #include "webkit/tools/test_shell/test_webview_delegate.h" | 9 #include "webkit/tools/test_shell/test_webview_delegate.h" |
| 10 | 10 |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" |
| 15 #include "base/trace_event.h" | 16 #include "base/trace_event.h" |
| 16 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 18 #include "gfx/native_widget_types.h" | 19 #include "gfx/native_widget_types.h" |
| 19 #include "gfx/point.h" | 20 #include "gfx/point.h" |
| 20 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 21 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" | 22 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" |
| 22 #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" | 23 #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" |
| 23 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" | 24 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" |
| 24 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientationClientMo
ck.h" | 25 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientationClientMo
ck.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 return url.ExtractFileName(); | 201 return url.ExtractFileName(); |
| 201 | 202 |
| 202 return url.possibly_invalid_spec(); | 203 return url.possibly_invalid_spec(); |
| 203 } | 204 } |
| 204 | 205 |
| 205 std::string GetResponseDescription(const WebURLResponse& response) { | 206 std::string GetResponseDescription(const WebURLResponse& response) { |
| 206 if (response.isNull()) | 207 if (response.isNull()) |
| 207 return "(null)"; | 208 return "(null)"; |
| 208 | 209 |
| 209 const std::string url = GURL(response.url()).possibly_invalid_spec(); | 210 const std::string url = GURL(response.url()).possibly_invalid_spec(); |
| 210 return StringPrintf("<NSURLResponse %s, http status code %d>", | 211 return base::StringPrintf("<NSURLResponse %s, http status code %d>", |
| 211 DescriptionSuitableForTestResult(url).c_str(), | 212 DescriptionSuitableForTestResult(url).c_str(), |
| 212 response.httpStatusCode()); | 213 response.httpStatusCode()); |
| 213 } | 214 } |
| 214 | 215 |
| 215 std::string GetErrorDescription(const WebURLError& error) { | 216 std::string GetErrorDescription(const WebURLError& error) { |
| 216 std::string domain = UTF16ToASCII(error.domain); | 217 std::string domain = UTF16ToASCII(error.domain); |
| 217 int code = error.reason; | 218 int code = error.reason; |
| 218 | 219 |
| 219 if (domain == net::kErrorDomain) { | 220 if (domain == net::kErrorDomain) { |
| 220 domain = "NSURLErrorDomain"; | 221 domain = "NSURLErrorDomain"; |
| 221 switch (error.reason) { | 222 switch (error.reason) { |
| 222 case net::ERR_ABORTED: | 223 case net::ERR_ABORTED: |
| 223 code = -999; | 224 code = -999; |
| 224 break; | 225 break; |
| 225 case net::ERR_UNSAFE_PORT: | 226 case net::ERR_UNSAFE_PORT: |
| 226 // Our unsafe port checking happens at the network stack level, but we | 227 // Our unsafe port checking happens at the network stack level, but we |
| 227 // make this translation here to match the behavior of stock WebKit. | 228 // make this translation here to match the behavior of stock WebKit. |
| 228 domain = "WebKitErrorDomain"; | 229 domain = "WebKitErrorDomain"; |
| 229 code = 103; | 230 code = 103; |
| 230 break; | 231 break; |
| 231 case net::ERR_ADDRESS_INVALID: | 232 case net::ERR_ADDRESS_INVALID: |
| 232 case net::ERR_ADDRESS_UNREACHABLE: | 233 case net::ERR_ADDRESS_UNREACHABLE: |
| 233 code = -1004; | 234 code = -1004; |
| 234 break; | 235 break; |
| 235 } | 236 } |
| 236 } else { | 237 } else { |
| 237 DLOG(WARNING) << "Unknown error domain"; | 238 DLOG(WARNING) << "Unknown error domain"; |
| 238 } | 239 } |
| 239 | 240 |
| 240 return StringPrintf("<NSError domain %s, code %d, failing URL \"%s\">", | 241 return base::StringPrintf("<NSError domain %s, code %d, failing URL \"%s\">", |
| 241 domain.c_str(), code, error.unreachableURL.spec().data()); | 242 domain.c_str(), code, error.unreachableURL.spec().data()); |
| 242 } | 243 } |
| 243 | 244 |
| 244 std::string GetNodeDescription(const WebNode& node, int exception) { | 245 std::string GetNodeDescription(const WebNode& node, int exception) { |
| 245 if (exception) | 246 if (exception) |
| 246 return "ERROR"; | 247 return "ERROR"; |
| 247 if (node.isNull()) | 248 if (node.isNull()) |
| 248 return "(null)"; | 249 return "(null)"; |
| 249 std::string str = node.nodeName().utf8(); | 250 std::string str = node.nodeName().utf8(); |
| 250 const WebNode& parent = node.parentNode(); | 251 const WebNode& parent = node.parentNode(); |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 if (error.reason == net::ERR_ABORTED) | 893 if (error.reason == net::ERR_ABORTED) |
| 893 return; | 894 return; |
| 894 | 895 |
| 895 const WebDataSource* failed_ds = frame->provisionalDataSource(); | 896 const WebDataSource* failed_ds = frame->provisionalDataSource(); |
| 896 | 897 |
| 897 TestShellExtraData* extra_data = | 898 TestShellExtraData* extra_data = |
| 898 static_cast<TestShellExtraData*>(failed_ds->extraData()); | 899 static_cast<TestShellExtraData*>(failed_ds->extraData()); |
| 899 bool replace = extra_data && extra_data->pending_page_id != -1; | 900 bool replace = extra_data && extra_data->pending_page_id != -1; |
| 900 | 901 |
| 901 const std::string& error_text = | 902 const std::string& error_text = |
| 902 StringPrintf("Error %d when loading url %s", error.reason, | 903 base::StringPrintf("Error %d when loading url %s", error.reason, |
| 903 failed_ds->request().url().spec().data()); | 904 failed_ds->request().url().spec().data()); |
| 904 | 905 |
| 905 // Make sure we never show errors in view source mode. | 906 // Make sure we never show errors in view source mode. |
| 906 frame->enableViewSourceMode(false); | 907 frame->enableViewSourceMode(false); |
| 907 | 908 |
| 908 frame->loadHTMLString( | 909 frame->loadHTMLString( |
| 909 error_text, GURL("testshell-error:"), error.unreachableURL, replace); | 910 error_text, GURL("testshell-error:"), error.unreachableURL, replace); |
| 910 } | 911 } |
| 911 | 912 |
| 912 void TestWebViewDelegate::didCommitProvisionalLoad( | 913 void TestWebViewDelegate::didCommitProvisionalLoad( |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 } | 1334 } |
| 1334 | 1335 |
| 1335 void TestWebViewDelegate::set_fake_window_rect(const WebRect& rect) { | 1336 void TestWebViewDelegate::set_fake_window_rect(const WebRect& rect) { |
| 1336 fake_rect_ = rect; | 1337 fake_rect_ = rect; |
| 1337 using_fake_rect_ = true; | 1338 using_fake_rect_ = true; |
| 1338 } | 1339 } |
| 1339 | 1340 |
| 1340 WebRect TestWebViewDelegate::fake_window_rect() { | 1341 WebRect TestWebViewDelegate::fake_window_rect() { |
| 1341 return fake_rect_; | 1342 return fake_rect_; |
| 1342 } | 1343 } |
| OLD | NEW |