Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 was forked off the Mac port. | 5 // This file was forked off the Mac port. |
| 6 | 6 |
| 7 #include "webkit/tools/test_shell/test_webview_delegate.h" | 7 #include "webkit/tools/test_shell/test_webview_delegate.h" |
| 8 | 8 |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 | 10 |
| 11 #include "base/gfx/point.h" | 11 #include "base/gfx/point.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "chrome/common/page_transition_types.h" | 14 #include "chrome/common/page_transition_types.h" |
| 15 #include "webkit/glue/webdatasource.h" | 15 #include "webkit/glue/webdatasource.h" |
| 16 #include "webkit/glue/webdropdata.h" | 16 #include "webkit/glue/webdropdata.h" |
| 17 #include "webkit/glue/weberror.h" | 17 #include "webkit/glue/weberror.h" |
| 18 #include "webkit/glue/webframe.h" | 18 #include "webkit/glue/webframe.h" |
| 19 #include "webkit/glue/webpreferences.h" | 19 #include "webkit/glue/webpreferences.h" |
| 20 #include "webkit/glue/weburlrequest.h" | 20 #include "webkit/glue/weburlrequest.h" |
| 21 #include "webkit/glue/webkit_glue.h" | 21 #include "webkit/glue/webkit_glue.h" |
| 22 #include "webkit/glue/webview.h" | 22 #include "webkit/glue/webview.h" |
| 23 #include "webkit/glue/window_open_disposition.h" | 23 #include "webkit/glue/window_open_disposition.h" |
| 24 #include "webkit/tools/test_shell/test_navigation_controller.h" | 24 #include "webkit/tools/test_shell/test_navigation_controller.h" |
| 25 #include "webkit/tools/test_shell/test_shell.h" | 25 #include "webkit/tools/test_shell/test_shell.h" |
| 26 | 26 |
| 27 static int32 next_page_id_ = 1; | |
| 28 | |
| 29 // WebViewDelegate ----------------------------------------------------------- | 27 // WebViewDelegate ----------------------------------------------------------- |
| 30 | 28 |
| 31 TestWebViewDelegate::~TestWebViewDelegate() { | 29 TestWebViewDelegate::~TestWebViewDelegate() { |
| 32 } | 30 } |
| 33 | 31 |
| 34 WebView* TestWebViewDelegate::CreateWebView(WebView* webview, | |
| 35 bool user_gesture) { | |
| 36 return shell_->CreateWebView(webview); | |
| 37 } | |
| 38 | |
| 39 WebWidget* TestWebViewDelegate::CreatePopupWidget(WebView* webview) { | |
| 40 return shell_->CreatePopupWidget(webview); | |
| 41 } | |
| 42 | |
| 43 WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( | 32 WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( |
| 44 WebView* webview, | 33 WebView* webview, |
| 45 const GURL& url, | 34 const GURL& url, |
| 46 const std::string& mime_type, | 35 const std::string& mime_type, |
| 47 const std::string& clsid, | 36 const std::string& clsid, |
| 48 std::string* actual_mime_type) { | 37 std::string* actual_mime_type) { |
| 38 NOTIMPLEMENTED(); | |
| 49 return NULL; | 39 return NULL; |
| 50 } | 40 } |
| 51 | 41 |
| 52 void TestWebViewDelegate::OpenURL(WebView* webview, const GURL& url, | 42 void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) { |
| 53 const GURL&, // TODO(eroman): use referrer | 43 NOTIMPLEMENTED(); |
| 54 WindowOpenDisposition disposition) { | |
| 55 DCHECK_NE(disposition, CURRENT_TAB); // No code for this | |
| 56 if (disposition == SUPPRESS_OPEN) | |
| 57 return; | |
| 58 TestShell* shell = NULL; | |
| 59 if (TestShell::CreateNewWindow(UTF8ToWide(url.spec()), &shell)) | |
| 60 shell->Show(shell->webView(), disposition); | |
| 61 } | |
| 62 | |
| 63 void TestWebViewDelegate::DidStartLoading(WebView* webview) { | |
| 64 if (page_is_loading_) { | |
| 65 LOG(ERROR) << "DidStartLoading called while loading"; | |
| 66 return; | |
| 67 } | |
| 68 page_is_loading_ = true; | |
| 69 } | |
| 70 | |
| 71 void TestWebViewDelegate::DidStopLoading(WebView* webview) { | |
| 72 if (!page_is_loading_) { | |
| 73 LOG(ERROR) << "DidStopLoading called while not loading"; | |
| 74 return; | |
| 75 } | |
| 76 page_is_loading_ = false; | |
| 77 } | |
| 78 | |
| 79 void TestWebViewDelegate::WindowObjectCleared(WebFrame* webframe) { | |
| 80 shell_->BindJSObjectsToWindow(webframe); | |
| 81 } | |
| 82 | |
| 83 WindowOpenDisposition TestWebViewDelegate::DispositionForNavigationAction( | |
| 84 WebView* webview, | |
| 85 WebFrame* frame, | |
| 86 const WebRequest* request, | |
| 87 WebNavigationType type, | |
| 88 WindowOpenDisposition disposition, | |
| 89 bool is_redirect) { | |
| 90 if (is_custom_policy_delegate_) { | |
| 91 std::wstring frame_name = frame->GetName(); | |
| 92 printf("Policy delegate: attempt to load %s\n", | |
| 93 request->GetURL().spec().c_str()); | |
| 94 return IGNORE_ACTION; | |
| 95 } else { | |
| 96 return static_cast<WindowOpenDisposition>( | |
| 97 WebViewDelegate::DispositionForNavigationAction(webview, frame, request, | |
| 98 type, disposition, | |
| 99 is_redirect)); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 void TestWebViewDelegate::SetCustomPolicyDelegate(bool isCustom) { | |
| 104 is_custom_policy_delegate_ = isCustom; | |
| 105 } | |
| 106 | |
| 107 void TestWebViewDelegate::AssignIdentifierToRequest(WebView* webview, | |
| 108 uint32 identifier, | |
| 109 const WebRequest& request) { | |
| 110 if (shell_->ShouldDumpResourceLoadCallbacks()) { | |
| 111 resource_identifier_map_[identifier] = request.GetURL().spec(); | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 std::string TestWebViewDelegate::GetResourceDescription(uint32 identifier) { | |
| 116 ResourceMap::iterator it = resource_identifier_map_.find(identifier); | |
| 117 return it != resource_identifier_map_.end() ? it->second : "<unknown>"; | |
| 118 } | |
| 119 | |
| 120 void TestWebViewDelegate::WillSendRequest(WebView* webview, | |
| 121 uint32 identifier, | |
| 122 WebRequest* request) { | |
| 123 std::string request_url = request->GetURL().spec(); | |
| 124 | |
| 125 if (shell_->ShouldDumpResourceLoadCallbacks()) { | |
| 126 printf("%s - willSendRequest <WebRequest URL \"%s\">\n", | |
| 127 GetResourceDescription(identifier).c_str(), | |
| 128 request_url.c_str()); | |
| 129 } | |
| 130 | |
| 131 // Set the new substituted URL. | |
| 132 request->SetURL(GURL(TestShell::RewriteLocalUrl(request_url))); | |
| 133 } | |
| 134 | |
| 135 void TestWebViewDelegate::DidFinishLoading(WebView* webview, | |
| 136 uint32 identifier) { | |
| 137 if (shell_->ShouldDumpResourceLoadCallbacks()) { | |
| 138 printf("%s - didFinishLoading\n", | |
| 139 GetResourceDescription(identifier).c_str()); | |
| 140 } | |
| 141 | |
| 142 resource_identifier_map_.erase(identifier); | |
| 143 } | |
| 144 | |
| 145 void TestWebViewDelegate::DidFailLoadingWithError(WebView* webview, | |
| 146 uint32 identifier, | |
| 147 const WebError& error) { | |
| 148 if (shell_->ShouldDumpResourceLoadCallbacks()) { | |
| 149 printf("%s - didFailLoadingWithError <WebError code %d," | |
| 150 " failing URL \"%s\">\n", | |
| 151 GetResourceDescription(identifier).c_str(), | |
| 152 error.GetErrorCode(), | |
| 153 error.GetFailedURL().spec().c_str()); | |
| 154 } | |
| 155 | |
| 156 resource_identifier_map_.erase(identifier); | |
| 157 } | |
| 158 | |
| 159 void TestWebViewDelegate::DidStartProvisionalLoadForFrame( | |
| 160 WebView* webview, | |
| 161 WebFrame* frame, | |
| 162 NavigationGesture gesture) { | |
| 163 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 164 printf("%S - didStartProvisionalLoadForFrame\n", | |
| 165 GetFrameDescription(frame).c_str()); | |
| 166 } | |
| 167 | |
| 168 if (!top_loading_frame_) { | |
| 169 top_loading_frame_ = frame; | |
| 170 } | |
| 171 UpdateAddressBar(webview); | |
| 172 } | |
| 173 | |
| 174 void TestWebViewDelegate::DidReceiveServerRedirectForProvisionalLoadForFrame( | |
| 175 WebView* webview, | |
| 176 WebFrame* frame) { | |
| 177 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 178 printf("%S - didReceiveServerRedirectForProvisionalLoadForFrame\n", | |
| 179 GetFrameDescription(frame).c_str()); | |
| 180 } | |
| 181 | |
| 182 UpdateAddressBar(webview); | |
| 183 } | |
| 184 | |
| 185 void TestWebViewDelegate::DidFailProvisionalLoadWithError( | |
| 186 WebView* webview, | |
| 187 const WebError& error, | |
| 188 WebFrame* frame) { | |
| 189 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 190 printf("%S - didFailProvisionalLoadWithError\n", | |
| 191 GetFrameDescription(frame).c_str()); | |
| 192 } | |
| 193 | |
| 194 if (page_is_loading_) | |
| 195 DidStopLoading(webview); | |
| 196 LocationChangeDone(frame->GetProvisionalDataSource()); | |
| 197 | |
| 198 // Don't display an error page if we're running layout tests, because | |
| 199 // DumpRenderTree doesn't. | |
| 200 if (!shell_->interactive()) | |
| 201 return; | |
| 202 | |
| 203 // Don't display an error page if this is simply a cancelled load. Aside | |
| 204 // from being dumb, WebCore doesn't expect it and it will cause a crash. | |
| 205 if (error.GetErrorCode() == net::ERR_ABORTED) | |
| 206 return; | |
| 207 | |
| 208 const WebRequest& failed_request = | |
| 209 frame->GetProvisionalDataSource()->GetRequest(); | |
| 210 TestShellExtraRequestData* extra_data = | |
| 211 static_cast<TestShellExtraRequestData*>(failed_request.GetExtraData()); | |
| 212 bool replace = extra_data && extra_data->pending_page_id != -1; | |
| 213 | |
| 214 scoped_ptr<WebRequest> request(failed_request.Clone()); | |
| 215 request->SetURL(GURL("testshell-error:")); | |
| 216 | |
| 217 std::string error_text = | |
| 218 StringPrintf("Error loading url: %d", error.GetErrorCode()); | |
| 219 | |
| 220 frame->LoadAlternateHTMLString(request.get(), error_text, | |
| 221 error.GetFailedURL(), replace); | |
| 222 } | |
| 223 | |
| 224 void TestWebViewDelegate::DidCommitLoadForFrame(WebView* webview, | |
| 225 WebFrame* frame, | |
| 226 bool is_new_navigation) { | |
| 227 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 228 printf("%S - didCommitLoadForFrame\n", | |
| 229 GetFrameDescription(frame).c_str()); | |
| 230 } | |
| 231 | |
| 232 UpdateForCommittedLoad(frame, is_new_navigation); | |
| 233 } | |
| 234 | |
| 235 void TestWebViewDelegate::DidReceiveTitle(WebView* webview, | |
| 236 const std::wstring& title, | |
| 237 WebFrame* frame) { | |
| 238 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 239 printf("%S - didReceiveTitle\n", | |
| 240 GetFrameDescription(frame).c_str()); | |
| 241 } | |
| 242 | |
| 243 if (shell_->ShouldDumpTitleChanges()) { | |
| 244 printf("TITLE CHANGED: %S\n", title.c_str()); | |
| 245 } | |
| 246 gtk_window_set_title(GTK_WINDOW(shell_->mainWnd()), WideToUTF8(title).c_str()) ; | |
| 247 } | |
| 248 | |
| 249 void TestWebViewDelegate::DidFinishLoadForFrame(WebView* webview, | |
| 250 WebFrame* frame) { | |
| 251 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 252 printf("%S - didFinishLoadForFrame\n", | |
| 253 GetFrameDescription(frame).c_str()); | |
| 254 } | |
| 255 | |
| 256 UpdateAddressBar(webview); | |
| 257 LocationChangeDone(frame->GetDataSource()); | |
| 258 } | |
| 259 | |
| 260 void TestWebViewDelegate::DidFailLoadWithError(WebView* webview, | |
| 261 const WebError& error, | |
| 262 WebFrame* frame) { | |
| 263 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 264 printf("%S - didFailLoadWithError\n", | |
| 265 GetFrameDescription(frame).c_str()); | |
| 266 } | |
| 267 | |
| 268 if (page_is_loading_) | |
| 269 DidStopLoading(webview); | |
| 270 LocationChangeDone(frame->GetDataSource()); | |
| 271 } | |
| 272 | |
| 273 void TestWebViewDelegate::DidFinishDocumentLoadForFrame(WebView* webview, | |
| 274 WebFrame* frame) { | |
| 275 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 276 printf("%S - didFinishDocumentLoadForFrame\n", | |
| 277 GetFrameDescription(frame).c_str()); | |
| 278 } | |
| 279 } | |
| 280 | |
| 281 void TestWebViewDelegate::DidHandleOnloadEventsForFrame(WebView* webview, | |
| 282 WebFrame* frame) { | |
| 283 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 284 printf("%S - didHandleOnloadEventsForFrame\n", | |
| 285 GetFrameDescription(frame).c_str()); | |
| 286 } | |
| 287 } | |
| 288 | |
| 289 void TestWebViewDelegate::DidChangeLocationWithinPageForFrame( | |
| 290 WebView* webview, WebFrame* frame, bool is_new_navigation) { | |
| 291 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 292 printf("%S - didChangeLocationWithinPageForFrame\n", | |
| 293 GetFrameDescription(frame).c_str()); | |
| 294 } | |
| 295 | |
| 296 UpdateForCommittedLoad(frame, is_new_navigation); | |
| 297 } | |
| 298 | |
| 299 void TestWebViewDelegate::DidReceiveIconForFrame(WebView* webview, | |
| 300 WebFrame* frame) { | |
| 301 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 302 printf("%S - didReceiveIconForFrame\n", | |
| 303 GetFrameDescription(frame).c_str()); | |
| 304 } | |
| 305 } | |
| 306 | |
| 307 void TestWebViewDelegate::WillPerformClientRedirect( | |
| 308 WebView* webview, WebFrame* frame, const std::wstring& dest_url, | |
| 309 unsigned int delay_seconds, unsigned int fire_date) { | |
| 310 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 311 // TODO: prettyprint the url? | |
| 312 printf("%S - willPerformClientRedirectToURL: %S\n", | |
| 313 GetFrameDescription(frame).c_str(), dest_url.c_str()); | |
| 314 } | |
| 315 } | |
| 316 | |
| 317 void TestWebViewDelegate::DidCancelClientRedirect(WebView* webview, | |
| 318 WebFrame* frame) { | |
| 319 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 320 printf("%S - didCancelClientRedirectForFrame\n", | |
| 321 GetFrameDescription(frame).c_str()); | |
| 322 } | |
| 323 } | |
| 324 | |
| 325 void TestWebViewDelegate::AddMessageToConsole(WebView* webview, | |
| 326 const std::wstring& message, | |
| 327 unsigned int line_no, | |
| 328 const std::wstring& source_id) { | |
| 329 if (shell_->interactive()) { | |
| 330 logging::LogMessage("CONSOLE", 0).stream() << "\"" | |
| 331 << message.c_str() | |
| 332 << ",\" source: " | |
| 333 << source_id.c_str() | |
| 334 << "(" | |
| 335 << line_no | |
| 336 << ")"; | |
| 337 } else { | |
| 338 // This matches win DumpRenderTree's UIDelegate.cpp. | |
| 339 std::wstring new_message = message; | |
| 340 if (!message.empty()) { | |
| 341 new_message = message; | |
| 342 size_t file_protocol = new_message.find(L"file://"); | |
| 343 if (file_protocol != std::wstring::npos) { | |
| 344 new_message = new_message.substr(0, file_protocol) + new_message; | |
| 345 // UrlSuitableForTestResult(new_message); | |
| 346 } | |
| 347 } | |
| 348 | |
| 349 std::string utf8 = WideToUTF8(new_message); | |
| 350 printf("CONSOLE MESSAGE: line %d: %s\n", line_no, utf8.c_str()); | |
| 351 } | |
| 352 } | |
| 353 | |
| 354 void TestWebViewDelegate::RunJavaScriptAlert(WebView* webview, | |
| 355 const std::wstring& message) { | |
| 356 if (shell_->interactive()) { | |
| 357 NOTIMPLEMENTED(); | |
| 358 } else { | |
| 359 std::string utf8 = WideToUTF8(message); | |
| 360 printf("ALERT: %s\n", utf8.c_str()); | |
| 361 } | |
| 362 } | |
| 363 | |
| 364 bool TestWebViewDelegate::RunJavaScriptConfirm(WebView* webview, | |
| 365 const std::wstring& message) { | |
| 366 if (!shell_->interactive()) { | |
| 367 // When running tests, write to stdout. | |
| 368 std::string utf8 = WideToUTF8(message); | |
| 369 printf("CONFIRM: %s\n", utf8.c_str()); | |
| 370 return true; | |
| 371 } | |
| 372 return false; | |
| 373 } | |
| 374 | |
| 375 bool TestWebViewDelegate::RunJavaScriptPrompt(WebView* webview, | |
| 376 const std::wstring& message, const std::wstring& default_value, | |
| 377 std::wstring* result) { | |
| 378 if (!shell_->interactive()) { | |
| 379 // When running tests, write to stdout. | |
| 380 std::string utf8_message = WideToUTF8(message); | |
| 381 std::string utf8_default_value = WideToUTF8(default_value); | |
| 382 printf("PROMPT: %s, default text: %s\n", utf8_message.c_str(), | |
| 383 utf8_default_value.c_str()); | |
| 384 return true; | |
| 385 } | |
| 386 return false; | |
| 387 } | 44 } |
| 388 | 45 |
| 389 void TestWebViewDelegate::StartDragging(WebView* webview, | 46 void TestWebViewDelegate::StartDragging(WebView* webview, |
| 390 const WebDropData& drop_data) { | 47 const WebDropData& drop_data) { |
| 391 } | 48 NOTIMPLEMENTED(); |
| 392 | |
| 393 void TestWebViewDelegate::ShowContextMenu(WebView* webview, | |
| 394 ContextNode::Type type, | |
| 395 int x, | |
| 396 int y, | |
| 397 const GURL& link_url, | |
| 398 const GURL& image_url, | |
| 399 const GURL& page_url, | |
| 400 const GURL& frame_url, | |
| 401 const std::wstring& selection_text, | |
| 402 const std::wstring& misspelled_word, | |
| 403 int edit_flags, | |
| 404 const std::string& security_info) { | |
| 405 CapturedContextMenuEvent context(type, x, y); | |
| 406 captured_context_menu_events_.push_back(context); | |
| 407 } | |
| 408 | |
| 409 // The output from these methods in non-interactive mode should match that | |
| 410 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. | |
| 411 bool TestWebViewDelegate::ShouldBeginEditing(WebView* webview, | |
| 412 std::wstring range) { | |
| 413 if (shell_->ShouldDumpEditingCallbacks()) { | |
| 414 std::string utf8 = WideToUTF8(range); | |
| 415 printf("EDITING DELEGATE: shouldBeginEditingInDOMRange:%s\n", | |
| 416 utf8.c_str()); | |
| 417 } | |
| 418 return shell_->AcceptsEditing(); | |
| 419 } | |
| 420 | |
| 421 bool TestWebViewDelegate::ShouldEndEditing(WebView* webview, | |
| 422 std::wstring range) { | |
| 423 if (shell_->ShouldDumpEditingCallbacks()) { | |
| 424 std::string utf8 = WideToUTF8(range); | |
| 425 printf("EDITING DELEGATE: shouldEndEditingInDOMRange:%s\n", | |
| 426 utf8.c_str()); | |
| 427 } | |
| 428 return shell_->AcceptsEditing(); | |
| 429 } | |
| 430 | |
| 431 bool TestWebViewDelegate::ShouldInsertNode(WebView* webview, | |
| 432 std::wstring node, | |
| 433 std::wstring range, | |
| 434 std::wstring action) { | |
| 435 if (shell_->ShouldDumpEditingCallbacks()) { | |
| 436 std::string utf8_node = WideToUTF8(node); | |
| 437 std::string utf8_range = WideToUTF8(range); | |
| 438 std::string utf8_action = WideToUTF8(action); | |
| 439 printf("EDITING DELEGATE: shouldInsertNode:%s " | |
| 440 "replacingDOMRange:%s givenAction:%s\n", | |
| 441 utf8_node.c_str(), utf8_range.c_str(), utf8_action.c_str()); | |
| 442 } | |
| 443 return shell_->AcceptsEditing(); | |
| 444 } | |
| 445 | |
| 446 bool TestWebViewDelegate::ShouldInsertText(WebView* webview, | |
| 447 std::wstring text, | |
| 448 std::wstring range, | |
| 449 std::wstring action) { | |
| 450 if (shell_->ShouldDumpEditingCallbacks()) { | |
| 451 std::string utf8_text = WideToUTF8(text); | |
| 452 std::string utf8_range = WideToUTF8(range); | |
| 453 std::string utf8_action = WideToUTF8(action); | |
| 454 printf("EDITING DELEGATE: shouldInsertText:%s " | |
| 455 "replacingDOMRange:%s givenAction:%s\n", | |
| 456 utf8_text.c_str(), utf8_range.c_str(), utf8_action.c_str()); | |
| 457 } | |
| 458 return shell_->AcceptsEditing(); | |
| 459 } | |
| 460 | |
| 461 bool TestWebViewDelegate::ShouldChangeSelectedRange(WebView* webview, | |
| 462 std::wstring fromRange, | |
| 463 std::wstring toRange, | |
| 464 std::wstring affinity, | |
| 465 bool stillSelecting) { | |
| 466 if (shell_->ShouldDumpEditingCallbacks()) { | |
| 467 std::string utf8_from = WideToUTF8(fromRange); | |
| 468 std::string utf8_to = WideToUTF8(toRange); | |
| 469 std::string utf8_affinity = WideToUTF8(affinity); | |
| 470 printf("EDITING DELEGATE: shouldChangeSelectedDOMRange:%s " | |
| 471 "toDOMRange:%s affinity:%s stillSelecting:%s\n", | |
| 472 utf8_from.c_str(), | |
| 473 utf8_to.c_str(), | |
| 474 utf8_affinity.c_str(), | |
| 475 (stillSelecting ? "TRUE" : "FALSE")); | |
| 476 } | |
| 477 return shell_->AcceptsEditing(); | |
| 478 } | |
| 479 | |
| 480 bool TestWebViewDelegate::ShouldDeleteRange(WebView* webview, | |
| 481 std::wstring range) { | |
| 482 if (shell_->ShouldDumpEditingCallbacks()) { | |
| 483 std::string utf8 = WideToUTF8(range); | |
| 484 printf("EDITING DELEGATE: shouldDeleteDOMRange:%s\n", utf8.c_str()); | |
| 485 } | |
| 486 return shell_->AcceptsEditing(); | |
| 487 } | |
| 488 | |
| 489 bool TestWebViewDelegate::ShouldApplyStyle(WebView* webview, | |
| 490 std::wstring style, | |
| 491 std::wstring range) { | |
| 492 if (shell_->ShouldDumpEditingCallbacks()) { | |
| 493 std::string utf8_style = WideToUTF8(style); | |
| 494 std::string utf8_range = WideToUTF8(range); | |
| 495 printf("EDITING DELEGATE: shouldApplyStyle:%s toElementsInDOMRange:%s\n", | |
| 496 utf8_style.c_str(), utf8_range.c_str()); | |
| 497 } | |
| 498 return shell_->AcceptsEditing(); | |
| 499 } | |
| 500 | |
| 501 bool TestWebViewDelegate::SmartInsertDeleteEnabled() { | |
| 502 return true; | |
| 503 } | |
| 504 | |
| 505 void TestWebViewDelegate::DidBeginEditing() { | |
| 506 if (shell_->ShouldDumpEditingCallbacks()) { | |
| 507 printf("EDITING DELEGATE: " | |
| 508 "webViewDidBeginEditing:WebViewDidBeginEditingNotification\n"); | |
| 509 } | |
| 510 } | |
| 511 | |
| 512 void TestWebViewDelegate::DidChangeSelection() { | |
| 513 if (shell_->ShouldDumpEditingCallbacks()) { | |
| 514 printf("EDITING DELEGATE: " | |
| 515 "webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n"); | |
| 516 } | |
| 517 } | |
| 518 | |
| 519 void TestWebViewDelegate::DidChangeContents() { | |
| 520 if (shell_->ShouldDumpEditingCallbacks()) { | |
| 521 printf("EDITING DELEGATE: " | |
| 522 "webViewDidChange:WebViewDidChangeNotification\n"); | |
| 523 } | |
| 524 } | |
| 525 | |
| 526 void TestWebViewDelegate::DidEndEditing() { | |
| 527 if (shell_->ShouldDumpEditingCallbacks()) { | |
| 528 printf("EDITING DELEGATE: " | |
| 529 "webViewDidEndEditing:WebViewDidEndEditingNotification\n"); | |
| 530 } | |
| 531 } | |
| 532 | |
| 533 WebHistoryItem* TestWebViewDelegate::GetHistoryEntryAtOffset(int offset) { | |
| 534 TestNavigationEntry* entry = static_cast<TestNavigationEntry*>( | |
| 535 shell_->navigation_controller()->GetEntryAtOffset(offset)); | |
| 536 if (!entry) | |
| 537 return NULL; | |
| 538 | |
| 539 return entry->GetHistoryItem(); | |
| 540 } | |
| 541 | |
| 542 int TestWebViewDelegate::GetHistoryBackListCount() { | |
| 543 int current_index = | |
| 544 shell_->navigation_controller()->GetLastCommittedEntryIndex(); | |
| 545 return current_index; | |
| 546 } | |
| 547 | |
| 548 int TestWebViewDelegate::GetHistoryForwardListCount() { | |
| 549 int current_index = | |
| 550 shell_->navigation_controller()->GetLastCommittedEntryIndex(); | |
| 551 return shell_->navigation_controller()->GetEntryCount() - current_index - 1; | |
| 552 } | |
| 553 | |
| 554 void TestWebViewDelegate::SetUserStyleSheetEnabled(bool is_enabled) { | |
| 555 WebPreferences* prefs = shell_->GetWebPreferences(); | |
| 556 prefs->user_style_sheet_enabled = is_enabled; | |
| 557 shell_->webView()->SetPreferences(*prefs); | |
| 558 } | |
| 559 | |
| 560 void TestWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) { | |
| 561 WebPreferences* prefs = shell_->GetWebPreferences(); | |
| 562 prefs->user_style_sheet_location = location; | |
| 563 shell_->webView()->SetPreferences(*prefs); | |
| 564 } | |
| 565 | |
| 566 // WebWidgetDelegate --------------------------------------------------------- | |
| 567 | |
| 568 gfx::ViewHandle TestWebViewDelegate::GetContainingWindow(WebWidget* webwidget) { | |
| 569 if (WebWidgetHost* host = GetHostForWidget(webwidget)) | |
| 570 return host->window_handle(); | |
| 571 | |
| 572 return NULL; | |
| 573 } | |
| 574 | |
| 575 void TestWebViewDelegate::DidInvalidateRect(WebWidget* webwidget, | |
| 576 const gfx::Rect& rect) { | |
| 577 WebWidgetHost* host = GetHostForWidget(webwidget); | |
| 578 if (host) | |
| 579 host->DidInvalidateRect(rect); | |
| 580 } | |
| 581 | |
| 582 void TestWebViewDelegate::DidScrollRect(WebWidget* webwidget, int dx, int dy, | |
| 583 const gfx::Rect& clip_rect) { | |
| 584 if (WebWidgetHost* host = GetHostForWidget(webwidget)) | |
| 585 host->DidScrollRect(dx, dy, clip_rect); | |
| 586 } | 49 } |
| 587 | 50 |
| 588 void TestWebViewDelegate::Show(WebWidget* webview, | 51 void TestWebViewDelegate::Show(WebWidget* webview, |
| 589 WindowOpenDisposition disposition) { | 52 WindowOpenDisposition disposition) { |
| 53 NOTIMPLEMENTED(); | |
| 590 } | 54 } |
| 591 | 55 |
| 592 void TestWebViewDelegate::CloseWidgetSoon(WebWidget* webwidget) { | 56 void TestWebViewDelegate::CloseWidgetSoon(WebWidget* webwidget) { |
| 593 NOTIMPLEMENTED(); | 57 NOTIMPLEMENTED(); |
| 594 } | 58 } |
| 595 | 59 |
| 596 void TestWebViewDelegate::Focus(WebWidget* webwidget) { | |
| 597 if (WebWidgetHost* host = GetHostForWidget(webwidget)) | |
| 598 shell_->SetFocus(host, true); | |
| 599 } | |
| 600 | |
| 601 void TestWebViewDelegate::Blur(WebWidget* webwidget) { | |
| 602 if (WebWidgetHost* host = GetHostForWidget(webwidget)) | |
| 603 shell_->SetFocus(host, false); | |
| 604 } | |
| 605 | |
| 606 void TestWebViewDelegate::SetCursor(WebWidget* webwidget, | 60 void TestWebViewDelegate::SetCursor(WebWidget* webwidget, |
| 607 const WebCursor& cursor) { | 61 const WebCursor& cursor) { |
| 608 //TODO: Mac cursor handling | 62 // TODO(port): GTK cursor handling. |
|
tony
2008/11/09 18:07:50
Nit: NOTIMPLEMENTED()?
| |
| 609 } | 63 } |
| 610 | 64 |
| 611 void TestWebViewDelegate::GetWindowRect(WebWidget* webwidget, | 65 void TestWebViewDelegate::GetWindowRect(WebWidget* webwidget, |
| 612 gfx::Rect* out_rect) { | 66 gfx::Rect* out_rect) { |
| 613 DCHECK(out_rect); | 67 DCHECK(out_rect); |
| 614 //if (WebWidgetHost* host = GetHostForWidget(webwidget)) { | 68 //if (WebWidgetHost* host = GetHostForWidget(webwidget)) { |
| 615 NOTIMPLEMENTED(); | 69 NOTIMPLEMENTED(); |
| 616 //} | 70 //} |
| 617 } | 71 } |
| 618 | 72 |
| 619 void TestWebViewDelegate::SetWindowRect(WebWidget* webwidget, | 73 void TestWebViewDelegate::SetWindowRect(WebWidget* webwidget, |
| 620 const gfx::Rect& rect) { | 74 const gfx::Rect& rect) { |
| 621 // TODO: Mac window movement | 75 // TODO(port): window movement |
| 622 if (webwidget == shell_->webView()) { | 76 if (webwidget == shell_->webView()) { |
| 623 // ignored | 77 // ignored |
| 624 } else if (webwidget == shell_->popup()) { | 78 } else if (webwidget == shell_->popup()) { |
| 625 // MoveWindow(shell_->popupWnd(), | 79 // MoveWindow(shell_->popupWnd(), |
|
tony
2008/11/09 18:07:50
NOTIMPLEMENTED?
| |
| 626 // rect.x(), rect.y(), rect.width(), rect.height(), FALSE); | 80 // rect.x(), rect.y(), rect.width(), rect.height(), FALSE); |
| 627 } | 81 } |
| 628 } | 82 } |
| 629 | 83 |
| 630 void TestWebViewDelegate::GetRootWindowRect(WebWidget* webwidget, | 84 void TestWebViewDelegate::GetRootWindowRect(WebWidget* webwidget, |
| 631 gfx::Rect* out_rect) { | 85 gfx::Rect* out_rect) { |
| 632 //if (WebWidgetHost* host = GetHostForWidget(webwidget)) { | 86 //if (WebWidgetHost* host = GetHostForWidget(webwidget)) { |
| 633 NOTIMPLEMENTED(); | 87 NOTIMPLEMENTED(); |
| 634 //} | 88 //} |
| 635 } | 89 } |
| 636 | 90 |
| 637 void TestWebViewDelegate::DidMove(WebWidget* webwidget, | |
| 638 const WebPluginGeometry& move) { | |
| 639 // TODO: uncomment when Mac plugins are working | |
| 640 // WebPluginDelegateImpl::MoveWindow( | |
| 641 // move.window, move.window_rect, move.clip_rect, move.visible); */ | |
| 642 } | |
| 643 | |
| 644 void TestWebViewDelegate::RegisterDragDrop() { | |
| 645 // TODO: uncomment when Mac drag and drop is working | |
| 646 // DCHECK(!drop_delegate_); | |
| 647 // drop_delegate_ = new TestDropDelegate(shell_->webViewWnd(), | |
| 648 // shell_->webView()); | |
| 649 } | |
| 650 | |
| 651 void TestWebViewDelegate::RunModal(WebWidget* webwidget) { | 91 void TestWebViewDelegate::RunModal(WebWidget* webwidget) { |
| 652 // TODO(pinkerton): implement me | 92 NOTIMPLEMENTED(); |
| 653 } | |
| 654 | |
| 655 bool TestWebViewDelegate::IsHidden() { | |
| 656 return false; | |
| 657 } | 93 } |
| 658 | 94 |
| 659 // Private methods ----------------------------------------------------------- | 95 // Private methods ----------------------------------------------------------- |
| 660 | 96 |
| 661 void TestWebViewDelegate::UpdateAddressBar(WebView* webView) { | 97 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { |
| 662 WebFrame* mainFrame = webView->GetMainFrame(); | 98 gtk_window_set_title(GTK_WINDOW(shell_->mainWnd()), |
| 663 | 99 ("Test Shell - " + WideToUTF8(title)).c_str()); |
| 664 WebDataSource* dataSource = mainFrame->GetDataSource(); | |
| 665 if (!dataSource) | |
| 666 dataSource = mainFrame->GetProvisionalDataSource(); | |
| 667 if (!dataSource) | |
| 668 return; | |
| 669 | |
| 670 std::string frameURL = dataSource->GetRequest().GetMainDocumentURL().spec(); | |
| 671 LOG(INFO) << " -- Address bar " << frameURL; | |
| 672 | |
| 673 gtk_entry_set_text(GTK_ENTRY(shell_->editWnd()), frameURL.c_str()); | |
| 674 } | 100 } |
| 675 | 101 |
| 676 void TestWebViewDelegate::LocationChangeDone(WebDataSource* data_source) { | 102 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { |
| 677 if (data_source->GetWebFrame() == top_loading_frame_) { | 103 gtk_entry_set_text(GTK_ENTRY(shell_->editWnd()), url.spec().c_str()); |
| 678 top_loading_frame_ = NULL; | |
| 679 NOTIMPLEMENTED(); | |
| 680 | |
| 681 if (!shell_->interactive()) | |
| 682 shell_->layout_test_controller()->LocationChangeDone(); | |
| 683 } | |
| 684 } | 104 } |
| 685 | |
| 686 WebWidgetHost* TestWebViewDelegate::GetHostForWidget(WebWidget* webwidget) { | |
| 687 if (webwidget == shell_->webView()) | |
| 688 return shell_->webViewHost(); | |
| 689 if (webwidget == shell_->popup()) | |
| 690 return shell_->popupHost(); | |
| 691 return NULL; | |
| 692 } | |
| 693 | |
| 694 void TestWebViewDelegate::UpdateForCommittedLoad(WebFrame* frame, | |
| 695 bool is_new_navigation) { | |
| 696 WebView* webview = shell_->webView(); | |
| 697 | |
| 698 // Code duplicated from RenderView::DidCommitLoadForFrame. | |
| 699 const WebRequest& request = | |
| 700 webview->GetMainFrame()->GetDataSource()->GetRequest(); | |
| 701 TestShellExtraRequestData* extra_data = | |
| 702 static_cast<TestShellExtraRequestData*>(request.GetExtraData()); | |
| 703 | |
| 704 if (is_new_navigation) { | |
| 705 // New navigation. | |
| 706 UpdateSessionHistory(frame); | |
| 707 page_id_ = next_page_id_++; | |
| 708 } else if (extra_data && extra_data->pending_page_id != -1 && | |
| 709 !extra_data->request_committed) { | |
| 710 // This is a successful session history navigation! | |
| 711 UpdateSessionHistory(frame); | |
| 712 page_id_ = extra_data->pending_page_id; | |
| 713 } | |
| 714 | |
| 715 // Don't update session history multiple times. | |
| 716 if (extra_data) | |
| 717 extra_data->request_committed = true; | |
| 718 | |
| 719 UpdateURL(frame); | |
| 720 } | |
| 721 | |
| 722 void TestWebViewDelegate::UpdateURL(WebFrame* frame) { | |
| 723 WebDataSource* ds = frame->GetDataSource(); | |
| 724 DCHECK(ds); | |
| 725 | |
| 726 const WebRequest& request = ds->GetRequest(); | |
| 727 | |
| 728 scoped_ptr<TestNavigationEntry> entry(new TestNavigationEntry); | |
| 729 | |
| 730 // Bug 654101: the referrer will be empty on https->http transitions. It | |
| 731 // would be nice if we could get the real referrer from somewhere. | |
| 732 entry->SetPageID(page_id_); | |
| 733 if (ds->HasUnreachableURL()) { | |
| 734 entry->SetURL(GURL(ds->GetUnreachableURL())); | |
| 735 } else { | |
| 736 entry->SetURL(GURL(request.GetURL())); | |
| 737 } | |
| 738 | |
| 739 shell_->navigation_controller()->DidNavigateToEntry(entry.release()); | |
| 740 | |
| 741 last_page_id_updated_ = std::max(last_page_id_updated_, page_id_); | |
| 742 } | |
| 743 | |
| 744 void TestWebViewDelegate::UpdateSessionHistory(WebFrame* frame) { | |
| 745 // If we have a valid page ID at this point, then it corresponds to the page | |
| 746 // we are navigating away from. Otherwise, this is the first navigation, so | |
| 747 // there is no past session history to record. | |
| 748 if (page_id_ == -1) | |
| 749 return; | |
| 750 | |
| 751 TestNavigationEntry* entry = static_cast<TestNavigationEntry*>( | |
| 752 shell_->navigation_controller()->GetEntryWithPageID(page_id_)); | |
| 753 if (!entry) | |
| 754 return; | |
| 755 | |
| 756 GURL url; | |
| 757 std::wstring title; | |
| 758 std::string state; | |
| 759 if (!shell_->webView()->GetMainFrame()-> | |
| 760 GetPreviousState(&url, &title, &state)) | |
| 761 return; | |
| 762 | |
| 763 entry->SetURL(url); | |
| 764 entry->SetTitle(title); | |
| 765 entry->SetContentState(state); | |
| 766 } | |
| 767 | |
| 768 std::wstring TestWebViewDelegate::GetFrameDescription(WebFrame* webframe) { | |
| 769 std::wstring name = webframe->GetName(); | |
| 770 | |
| 771 if (webframe == shell_->webView()->GetMainFrame()) { | |
| 772 if (name.length()) | |
| 773 return L"main frame \"" + name + L"\""; | |
| 774 else | |
| 775 return L"main frame"; | |
| 776 } else { | |
| 777 if (name.length()) | |
| 778 return L"frame \"" + name + L"\""; | |
| 779 else | |
| 780 return L"frame (anonymous)"; | |
| 781 } | |
| 782 } | |
| OLD | NEW |