Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: webkit/tools/test_shell/gtk/test_webview_delegate.cc

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

Powered by Google App Engine
This is Rietveld 408576698