| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 contains the implementation of TestWebViewDelegate, which serves | |
| 6 // as the WebViewDelegate for the TestShellWebHost. The host is expected to | |
| 7 // have initialized a MessageLoop before these methods are called. | |
| 8 | |
| 9 #include "webkit/tools/test_shell/test_webview_delegate.h" | |
| 10 | |
| 11 #include <objidl.h> | |
| 12 #include <shlobj.h> | |
| 13 #include <shlwapi.h> | |
| 14 | |
| 15 #include "base/debug/trace_event.h" | |
| 16 #include "base/message_loop.h" | |
| 17 #include "base/utf_string_conversions.h" | |
| 18 #include "net/base/net_errors.h" | |
| 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" | |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
| 23 #include "ui/base/window_open_disposition.h" | |
| 24 #include "ui/gfx/gdi_util.h" | |
| 25 #include "ui/gfx/native_widget_types.h" | |
| 26 #include "ui/gfx/point.h" | |
| 27 #include "webkit/glue/webdropdata.h" | |
| 28 #include "webkit/glue/webkit_glue.h" | |
| 29 #include "webkit/glue/webpreferences.h" | |
| 30 #include "webkit/plugins/npapi/plugin_list.h" | |
| 31 #include "webkit/plugins/npapi/webplugin.h" | |
| 32 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" | |
| 33 #include "webkit/tools/test_shell/drop_delegate.h" | |
| 34 #include "webkit/tools/test_shell/test_navigation_controller.h" | |
| 35 #include "webkit/tools/test_shell/test_shell.h" | |
| 36 | |
| 37 using WebKit::WebCursorInfo; | |
| 38 using WebKit::WebNavigationPolicy; | |
| 39 using WebKit::WebPopupMenuInfo; | |
| 40 using WebKit::WebRect; | |
| 41 using WebKit::WebWidget; | |
| 42 | |
| 43 // WebViewClient -------------------------------------------------------------- | |
| 44 | |
| 45 WebWidget* TestWebViewDelegate::createPopupMenu( | |
| 46 const WebPopupMenuInfo& info) { | |
| 47 NOTREACHED(); | |
| 48 return NULL; | |
| 49 } | |
| 50 | |
| 51 // WebWidgetClient ------------------------------------------------------------ | |
| 52 | |
| 53 void TestWebViewDelegate::show(WebNavigationPolicy) { | |
| 54 if (WebWidgetHost* host = GetWidgetHost()) { | |
| 55 HWND root = GetAncestor(host->view_handle(), GA_ROOT); | |
| 56 ShowWindow(root, SW_SHOW); | |
| 57 UpdateWindow(root); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 void TestWebViewDelegate::closeWidgetSoon() { | |
| 62 if (this == shell_->delegate()) { | |
| 63 PostMessage(shell_->mainWnd(), WM_CLOSE, 0, 0); | |
| 64 } else if (this == shell_->popup_delegate()) { | |
| 65 shell_->ClosePopup(); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void TestWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) { | |
| 70 if (WebWidgetHost* host = GetWidgetHost()) { | |
| 71 current_cursor_.InitFromCursorInfo(cursor_info); | |
| 72 HINSTANCE mod_handle = GetModuleHandle(NULL); | |
| 73 host->SetCursor(current_cursor_.GetCursor(mod_handle)); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 WebRect TestWebViewDelegate::windowRect() { | |
| 78 if (WebWidgetHost* host = GetWidgetHost()) { | |
| 79 RECT rect; | |
| 80 ::GetWindowRect(host->view_handle(), &rect); | |
| 81 return gfx::Rect(rect); | |
| 82 } | |
| 83 return WebRect(); | |
| 84 } | |
| 85 | |
| 86 void TestWebViewDelegate::setWindowRect(const WebRect& rect) { | |
| 87 if (this == shell_->delegate()) { | |
| 88 set_fake_window_rect(rect); | |
| 89 } else if (this == shell_->popup_delegate()) { | |
| 90 MoveWindow(shell_->popupWnd(), | |
| 91 rect.x, rect.y, rect.width, rect.height, FALSE); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 WebRect TestWebViewDelegate::rootWindowRect() { | |
| 96 if (using_fake_rect_) { | |
| 97 return fake_window_rect(); | |
| 98 } | |
| 99 if (WebWidgetHost* host = GetWidgetHost()) { | |
| 100 RECT rect; | |
| 101 HWND root_window = ::GetAncestor(host->view_handle(), GA_ROOT); | |
| 102 ::GetWindowRect(root_window, &rect); | |
| 103 return gfx::Rect(rect); | |
| 104 } | |
| 105 return WebRect(); | |
| 106 } | |
| 107 | |
| 108 WebRect TestWebViewDelegate::windowResizerRect() { | |
| 109 // Not necessary on Windows. | |
| 110 return WebRect(); | |
| 111 } | |
| 112 | |
| 113 void TestWebViewDelegate::runModal() { | |
| 114 WebWidgetHost* host = GetWidgetHost(); | |
| 115 if (!host) | |
| 116 return; | |
| 117 | |
| 118 show(WebKit::WebNavigationPolicyNewWindow); | |
| 119 | |
| 120 WindowList* wl = TestShell::windowList(); | |
| 121 for (WindowList::const_iterator i = wl->begin(); i != wl->end(); ++i) { | |
| 122 if (*i != shell_->mainWnd()) | |
| 123 EnableWindow(*i, FALSE); | |
| 124 } | |
| 125 | |
| 126 shell_->set_is_modal(true); | |
| 127 MessageLoop::current()->Run(); | |
| 128 | |
| 129 for (WindowList::const_iterator i = wl->begin(); i != wl->end(); ++i) | |
| 130 EnableWindow(*i, TRUE); | |
| 131 } | |
| 132 | |
| 133 // WebPluginPageDelegate ------------------------------------------------------ | |
| 134 | |
| 135 webkit::npapi::WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( | |
| 136 const base::FilePath& path, | |
| 137 const std::string& mime_type) { | |
| 138 HWND hwnd = shell_->webViewHost()->view_handle(); | |
| 139 if (!hwnd) | |
| 140 return NULL; | |
| 141 | |
| 142 return webkit::npapi::WebPluginDelegateImpl::Create(path, mime_type); | |
| 143 } | |
| 144 | |
| 145 void TestWebViewDelegate::CreatedPluginWindow( | |
| 146 gfx::PluginWindowHandle handle) { | |
| 147 // ignored | |
| 148 } | |
| 149 | |
| 150 void TestWebViewDelegate::WillDestroyPluginWindow( | |
| 151 gfx::PluginWindowHandle handle) { | |
| 152 // ignored | |
| 153 } | |
| 154 | |
| 155 void TestWebViewDelegate::DidMovePlugin( | |
| 156 const webkit::npapi::WebPluginGeometry& move) { | |
| 157 unsigned long flags = 0; | |
| 158 | |
| 159 if (move.rects_valid) { | |
| 160 HRGN hrgn = ::CreateRectRgn(move.clip_rect.x(), | |
| 161 move.clip_rect.y(), | |
| 162 move.clip_rect.right(), | |
| 163 move.clip_rect.bottom()); | |
| 164 gfx::SubtractRectanglesFromRegion(hrgn, move.cutout_rects); | |
| 165 | |
| 166 // Note: System will own the hrgn after we call SetWindowRgn, | |
| 167 // so we don't need to call DeleteObject(hrgn) | |
| 168 ::SetWindowRgn(move.window, hrgn, FALSE); | |
| 169 } else { | |
| 170 flags |= (SWP_NOSIZE | SWP_NOMOVE); | |
| 171 } | |
| 172 | |
| 173 if (move.visible) | |
| 174 flags |= SWP_SHOWWINDOW; | |
| 175 else | |
| 176 flags |= SWP_HIDEWINDOW; | |
| 177 | |
| 178 ::SetWindowPos(move.window, | |
| 179 NULL, | |
| 180 move.window_rect.x(), | |
| 181 move.window_rect.y(), | |
| 182 move.window_rect.width(), | |
| 183 move.window_rect.height(), | |
| 184 flags); | |
| 185 } | |
| 186 | |
| 187 // Public methods ------------------------------------------------------------- | |
| 188 | |
| 189 void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { | |
| 190 // No selection clipboard on windows, do nothing. | |
| 191 } | |
| 192 | |
| 193 // Private methods ------------------------------------------------------------ | |
| 194 | |
| 195 void TestWebViewDelegate::ShowJavaScriptAlert(const base::string16& message) { | |
| 196 MessageBox(NULL, message.c_str(), L"JavaScript Alert", MB_OK); | |
| 197 } | |
| 198 | |
| 199 void TestWebViewDelegate::SetPageTitle(const base::string16& title) { | |
| 200 // The Windows test shell, pre-refactoring, ignored this. *shrug* | |
| 201 } | |
| 202 | |
| 203 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { | |
| 204 base::string16 url_string = UTF8ToUTF16(url.spec()); | |
| 205 SendMessage(shell_->editWnd(), WM_SETTEXT, 0, | |
| 206 reinterpret_cast<LPARAM>(url_string.c_str())); | |
| 207 } | |
| OLD | NEW |