Index: webkit/tools/test_shell/test_webview_delegate.cc |
diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc |
index 475289ca3295f26a207959d94c8722a25fb266a8..04e5721a026b1ec033608162f0d863b2718b1e99 100644 |
--- a/webkit/tools/test_shell/test_webview_delegate.cc |
+++ b/webkit/tools/test_shell/test_webview_delegate.cc |
@@ -8,10 +8,7 @@ |
#include "webkit/tools/test_shell/test_webview_delegate.h" |
-#include <objidl.h> |
-#include <shlobj.h> |
-#include <shlwapi.h> |
- |
+#include "base/file_util.h" |
#include "base/gfx/point.h" |
#include "base/message_loop.h" |
#include "base/string_util.h" |
@@ -26,16 +23,18 @@ |
#include "webkit/glue/webkit_glue.h" |
#include "webkit/glue/webview.h" |
#include "webkit/glue/plugins/plugin_list.h" |
-#include "webkit/glue/plugins/webplugin_delegate_impl.h" |
#include "webkit/glue/window_open_disposition.h" |
-#include "webkit/tools/test_shell/drag_delegate.h" |
-#include "webkit/tools/test_shell/drop_delegate.h" |
#include "webkit/tools/test_shell/test_navigation_controller.h" |
#include "webkit/tools/test_shell/test_shell.h" |
-namespace { |
+#if defined(OS_WIN) |
+// TODO(port): make these files work everywhere. |
+#include "webkit/glue/plugins/webplugin_delegate_impl.h" |
+#include "webkit/tools/test_shell/drag_delegate.h" |
+#include "webkit/tools/test_shell/drop_delegate.h" |
+#endif |
-static int next_page_id_ = 1; |
+namespace { |
// Used to write a platform neutral file:/// URL by only taking the filename |
// (e.g., converts "file:///tmp/foo.txt" to just "foo.txt"). |
@@ -43,42 +42,15 @@ std::wstring UrlSuitableForTestResult(const std::wstring& url) { |
if (url.empty() || std::wstring::npos == url.find(L"file://")) |
return url; |
- return PathFindFileNameW(url.c_str()); |
+ return file_util::GetFilenameFromPath(url); |
} |
-// Adds a file called "DRTFakeFile" to |data_object| (CF_HDROP). Use to fake |
-// dragging a file. |
-void AddDRTFakeFileToDataObject(IDataObject* data_object) { |
- STGMEDIUM medium = {0}; |
- medium.tymed = TYMED_HGLOBAL; |
- |
- const char filename[] = "DRTFakeFile"; |
- const int filename_len = arraysize(filename); |
- |
- // Allocate space for the DROPFILES struct, filename, and 2 null characters. |
- medium.hGlobal = GlobalAlloc(GPTR, sizeof(DROPFILES) + filename_len + 2); |
- DCHECK(medium.hGlobal); |
- DROPFILES* drop_files = static_cast<DROPFILES*>(GlobalLock(medium.hGlobal)); |
- drop_files->pFiles = sizeof(DROPFILES); |
- drop_files->fWide = 0; // Filenames are ascii |
- strcpy_s(reinterpret_cast<char*>(drop_files) + sizeof(DROPFILES), |
- filename_len, filename); |
- GlobalUnlock(medium.hGlobal); |
- |
- FORMATETC file_desc_fmt = {CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; |
- data_object->SetData(&file_desc_fmt, &medium, TRUE); |
-} |
+int next_page_id_ = 1; |
} // namespace |
// WebViewDelegate ----------------------------------------------------------- |
-TestWebViewDelegate::~TestWebViewDelegate() { |
- if (custom_cursor_) |
- DestroyIcon(custom_cursor_); |
- RevokeDragDrop(shell_->webViewWnd()); |
-} |
- |
WebView* TestWebViewDelegate::CreateWebView(WebView* webview, |
bool user_gesture) { |
return shell_->CreateWebView(webview); |
@@ -88,36 +60,13 @@ WebWidget* TestWebViewDelegate::CreatePopupWidget(WebView* webview) { |
return shell_->CreatePopupWidget(webview); |
} |
-WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( |
- WebView* webview, |
- const GURL& url, |
- const std::string& mime_type, |
- const std::string& clsid, |
- std::string* actual_mime_type) { |
- HWND hwnd = GetContainingWindow(webview); |
- if (!hwnd) |
- return NULL; |
- |
- bool allow_wildcard = true; |
- WebPluginInfo info; |
- if (!NPAPI::PluginList::Singleton()->GetPluginInfo(url, mime_type, clsid, |
- allow_wildcard, &info, |
- actual_mime_type)) |
- return NULL; |
- |
- if (actual_mime_type && !actual_mime_type->empty()) |
- return WebPluginDelegateImpl::Create(info.file, *actual_mime_type, hwnd); |
- else |
- return WebPluginDelegateImpl::Create(info.file, mime_type, hwnd); |
-} |
- |
void TestWebViewDelegate::OpenURL(WebView* webview, const GURL& url, |
const GURL& referrer, |
WindowOpenDisposition disposition) { |
DCHECK_NE(disposition, CURRENT_TAB); // No code for this |
if (disposition == SUPPRESS_OPEN) |
return; |
- TestShell* shell; |
+ TestShell* shell = NULL; |
if (TestShell::CreateNewWindow(UTF8ToWide(url.spec()), &shell)) |
shell->Show(shell->webView(), disposition); |
} |
@@ -152,7 +101,7 @@ WindowOpenDisposition TestWebViewDelegate::DispositionForNavigationAction( |
if (is_custom_policy_delegate_) { |
std::wstring frame_name = frame->GetName(); |
printf("Policy delegate: attempt to load %s\n", |
- request->GetURL().spec().c_str()); |
+ request->GetURL().spec().c_str()); |
return IGNORE_ACTION; |
} else { |
return WebViewDelegate::DispositionForNavigationAction( |
@@ -305,6 +254,8 @@ void TestWebViewDelegate::DidReceiveTitle(WebView* webview, |
if (shell_->ShouldDumpTitleChanges()) { |
printf("TITLE CHANGED: %S\n", title.c_str()); |
} |
+ |
+ SetPageTitle(title); |
} |
void TestWebViewDelegate::DidFinishLoadForFrame(WebView* webview, |
@@ -424,10 +375,7 @@ void TestWebViewDelegate::AddMessageToConsole(WebView* webview, |
void TestWebViewDelegate::RunJavaScriptAlert(WebView* webview, |
const std::wstring& message) { |
if (shell_->interactive()) { |
- MessageBox(shell_->mainWnd(), |
- message.c_str(), |
- L"JavaScript Alert", |
- MB_OK); |
+ ShowJavaScriptAlert(message); |
} else { |
std::string utf8 = WideToUTF8(message); |
printf("ALERT: %s\n", utf8.c_str()); |
@@ -459,31 +407,6 @@ bool TestWebViewDelegate::RunJavaScriptPrompt(WebView* webview, |
return false; |
} |
-void TestWebViewDelegate::StartDragging(WebView* webview, |
- const WebDropData& drop_data) { |
- |
- if (!drag_delegate_) |
- drag_delegate_ = new TestDragDelegate(shell_->webViewWnd(), |
- shell_->webView()); |
- if (webkit_glue::IsLayoutTestMode()) { |
- if (shell_->layout_test_controller()->ShouldAddFileToPasteboard()) { |
- // Add a file called DRTFakeFile to the drag&drop clipboard. |
- AddDRTFakeFileToDataObject(drop_data.data_object); |
- } |
- |
- // When running a test, we need to fake a drag drop operation otherwise |
- // Windows waits for real mouse events to know when the drag is over. |
- EventSendingController::DoDragDrop(drop_data.data_object); |
- } else { |
- const DWORD ok_effect = DROPEFFECT_COPY | DROPEFFECT_LINK | DROPEFFECT_MOVE; |
- DWORD effect; |
- HRESULT res = DoDragDrop(drop_data.data_object, drag_delegate_.get(), |
- ok_effect, &effect); |
- DCHECK(DRAGDROP_S_DROP == res || DRAGDROP_S_CANCEL == res); |
- } |
- webview->DragSourceSystemDragEnded(); |
-} |
- |
void TestWebViewDelegate::ShowContextMenu(WebView* webview, |
ContextNode::Type type, |
int x, |
@@ -660,7 +583,7 @@ void TestWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) { |
// WebWidgetDelegate --------------------------------------------------------- |
-HWND TestWebViewDelegate::GetContainingWindow(WebWidget* webwidget) { |
+gfx::ViewHandle TestWebViewDelegate::GetContainingWindow(WebWidget* webwidget) { |
if (WebWidgetHost* host = GetHostForWidget(webwidget)) |
return host->window_handle(); |
@@ -679,24 +602,6 @@ void TestWebViewDelegate::DidScrollRect(WebWidget* webwidget, int dx, int dy, |
host->DidScrollRect(dx, dy, clip_rect); |
} |
-void TestWebViewDelegate::Show(WebWidget* webwidget, WindowOpenDisposition) { |
- if (webwidget == shell_->webView()) { |
- ShowWindow(shell_->mainWnd(), SW_SHOW); |
- UpdateWindow(shell_->mainWnd()); |
- } else if (webwidget == shell_->popup()) { |
- ShowWindow(shell_->popupWnd(), SW_SHOW); |
- UpdateWindow(shell_->popupWnd()); |
- } |
-} |
- |
-void TestWebViewDelegate::CloseWidgetSoon(WebWidget* webwidget) { |
- if (webwidget == shell_->webView()) { |
- PostMessage(shell_->mainWnd(), WM_CLOSE, 0, 0); |
- } else if (webwidget == shell_->popup()) { |
- shell_->ClosePopup(); |
- } |
-} |
- |
void TestWebViewDelegate::Focus(WebWidget* webwidget) { |
if (WebWidgetHost* host = GetHostForWidget(webwidget)) |
shell_->SetFocus(host, true); |
@@ -707,73 +612,15 @@ void TestWebViewDelegate::Blur(WebWidget* webwidget) { |
shell_->SetFocus(host, false); |
} |
-void TestWebViewDelegate::SetCursor(WebWidget* webwidget, |
- const WebCursor& cursor) { |
- if (WebWidgetHost* host = GetHostForWidget(webwidget)) { |
- if (custom_cursor_) { |
- DestroyIcon(custom_cursor_); |
- custom_cursor_ = NULL; |
- } |
- if (cursor.IsCustom()) { |
- custom_cursor_ = cursor.GetCustomCursor(); |
- host->SetCursor(custom_cursor_); |
- } else { |
- HINSTANCE mod_handle = GetModuleHandle(NULL); |
- host->SetCursor(cursor.GetCursor(mod_handle)); |
- } |
- } |
-} |
- |
-void TestWebViewDelegate::GetWindowRect(WebWidget* webwidget, |
- gfx::Rect* out_rect) { |
- if (WebWidgetHost* host = GetHostForWidget(webwidget)) { |
- RECT rect; |
- ::GetWindowRect(host->window_handle(), &rect); |
- *out_rect = gfx::Rect(rect); |
- } |
-} |
- |
-void TestWebViewDelegate::SetWindowRect(WebWidget* webwidget, |
- const gfx::Rect& rect) { |
- if (webwidget == shell_->webView()) { |
- // ignored |
- } else if (webwidget == shell_->popup()) { |
- MoveWindow(shell_->popupWnd(), |
- rect.x(), rect.y(), rect.width(), rect.height(), FALSE); |
- } |
-} |
- |
-void TestWebViewDelegate::GetRootWindowRect(WebWidget* webwidget, |
- gfx::Rect* out_rect) { |
- if (WebWidgetHost* host = GetHostForWidget(webwidget)) { |
- RECT rect; |
- HWND root_window = ::GetAncestor(host->window_handle(), GA_ROOT); |
- ::GetWindowRect(root_window, &rect); |
- *out_rect = gfx::Rect(rect); |
- } |
-} |
void TestWebViewDelegate::DidMove(WebWidget* webwidget, |
const WebPluginGeometry& move) { |
+#if defined(OS_WIN) |
+ // TODO(port): add me once plugins work. |
WebPluginDelegateImpl::MoveWindow( |
move.window, move.window_rect, move.clip_rect, move.cutout_rects, |
move.visible); |
-} |
- |
-void TestWebViewDelegate::RunModal(WebWidget* webwidget) { |
- Show(webwidget, NEW_WINDOW); |
- |
- WindowList* wl = TestShell::windowList(); |
- for (WindowList::const_iterator i = wl->begin(); i != wl->end(); ++i) { |
- if (*i != shell_->mainWnd()) |
- EnableWindow(*i, FALSE); |
- } |
- |
- shell_->set_is_modal(true); |
- MessageLoop::current()->Run(); |
- |
- for (WindowList::const_iterator i = wl->begin(); i != wl->end(); ++i) |
- EnableWindow(*i, TRUE); |
+#endif |
} |
bool TestWebViewDelegate::IsHidden() { |
@@ -781,9 +628,12 @@ bool TestWebViewDelegate::IsHidden() { |
} |
void TestWebViewDelegate::RegisterDragDrop() { |
+#if defined(OS_WIN) |
+ // TODO(port): add me once drag and drop works. |
DCHECK(!drop_delegate_); |
drop_delegate_ = new TestDropDelegate(shell_->webViewWnd(), |
shell_->webView()); |
+#endif |
} |
// Private methods ----------------------------------------------------------- |
@@ -797,10 +647,7 @@ void TestWebViewDelegate::UpdateAddressBar(WebView* webView) { |
if (!dataSource) |
return; |
- std::wstring frameURL = |
- UTF8ToWide(dataSource->GetRequest().GetMainDocumentURL().spec()); |
- SendMessage(shell_->editWnd(), WM_SETTEXT, 0, |
- reinterpret_cast<LPARAM>(frameURL.c_str())); |
+ SetAddressBarURL(dataSource->GetRequest().GetMainDocumentURL()); |
} |
void TestWebViewDelegate::LocationChangeDone(WebDataSource* data_source) { |
@@ -854,11 +701,6 @@ void TestWebViewDelegate::UpdateURL(WebFrame* frame) { |
const WebRequest& request = ds->GetRequest(); |
- // We don't hold a reference to the extra data. The request's reference will |
- // be sufficient because we won't modify it during our call. MAY BE NULL. |
- TestShellExtraRequestData* extra_data = |
- static_cast<TestShellExtraRequestData*>(request.GetExtraData()); |
- |
// Type is unused. |
scoped_ptr<TestNavigationEntry> entry(new TestNavigationEntry); |