1 /* 2 * Copyright (C) 2007 Kevin Ollivier <kevino (at) theolliviers.com> 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include "config.h" 29 #include "ChromeClientWx.h" 30 #include "Console.h" 31 #if ENABLE(DATABASE) 32 #include "DatabaseTracker.h" 33 #endif 34 #include "FileChooser.h" 35 #include "FloatRect.h" 36 #include "Frame.h" 37 #include "FrameLoadRequest.h" 38 #include "NotImplemented.h" 39 #include "PlatformString.h" 40 #include "WindowFeatures.h" 41 42 #include <stdio.h> 43 44 #include <wx/wxprec.h> 45 #ifndef WX_PRECOMP 46 #include <wx/wx.h> 47 #endif 48 #include <wx/textdlg.h> 49 #include <wx/tooltip.h> 50 51 #include "WebBrowserShell.h" 52 #include "WebView.h" 53 #include "WebViewPrivate.h" 54 55 namespace WebCore { 56 57 wxWebKitWindowFeatures wkFeaturesforWindowFeatures(const WindowFeatures& features) 58 { 59 wxWebKitWindowFeatures wkFeatures; 60 wkFeatures.menuBarVisible = features.menuBarVisible; 61 wkFeatures.statusBarVisible = features.statusBarVisible; 62 wkFeatures.toolBarVisible = features.toolBarVisible; 63 wkFeatures.locationBarVisible = features.locationBarVisible; 64 wkFeatures.scrollbarsVisible = features.scrollbarsVisible; 65 wkFeatures.resizable = features.resizable; 66 wkFeatures.fullscreen = features.fullscreen; 67 wkFeatures.dialog = features.dialog; 68 69 return wkFeatures; 70 } 71 72 ChromeClientWx::ChromeClientWx(wxWebView* webView) 73 { 74 m_webView = webView; 75 } 76 77 ChromeClientWx::~ChromeClientWx() 78 { 79 } 80 81 void ChromeClientWx::chromeDestroyed() 82 { 83 notImplemented(); 84 } 85 86 void ChromeClientWx::setWindowRect(const FloatRect&) 87 { 88 notImplemented(); 89 } 90 91 FloatRect ChromeClientWx::windowRect() 92 { 93 notImplemented(); 94 return FloatRect(); 95 } 96 97 FloatRect ChromeClientWx::pageRect() 98 { 99 notImplemented(); 100 return FloatRect(); 101 } 102 103 float ChromeClientWx::scaleFactor() 104 { 105 notImplemented(); 106 return 0.0; 107 } 108 109 void ChromeClientWx::focus() 110 { 111 notImplemented(); 112 } 113 114 void ChromeClientWx::unfocus() 115 { 116 notImplemented(); 117 } 118 119 bool ChromeClientWx::canTakeFocus(FocusDirection) 120 { 121 notImplemented(); 122 return false; 123 } 124 125 void ChromeClientWx::takeFocus(FocusDirection) 126 { 127 notImplemented(); 128 } 129 130 void ChromeClientWx::focusedNodeChanged(Node*) 131 { 132 } 133 134 Page* ChromeClientWx::createWindow(Frame*, const FrameLoadRequest& request, const WindowFeatures& features) 135 { 136 Page* myPage = 0; 137 wxWebViewNewWindowEvent wkEvent(m_webView); 138 wkEvent.SetURL(request.resourceRequest().url().string()); 139 140 wxWebKitWindowFeatures wkFeatures = wkFeaturesforWindowFeatures(features); 141 wkEvent.SetWindowFeatures(wkFeatures); 142 143 if (m_webView->GetEventHandler()->ProcessEvent(wkEvent)) { 144 if (wxWebView* webView = wkEvent.GetWebView()) { 145 WebViewPrivate* impl = webView->m_impl; 146 if (impl) 147 myPage = impl->page; 148 } 149 } 150 151 return myPage; 152 } 153 154 Page* ChromeClientWx::createModalDialog(Frame*, const FrameLoadRequest&) 155 { 156 notImplemented(); 157 return 0; 158 } 159 160 void ChromeClientWx::show() 161 { 162 notImplemented(); 163 } 164 165 bool ChromeClientWx::canRunModal() 166 { 167 notImplemented(); 168 return false; 169 } 170 171 void ChromeClientWx::runModal() 172 { 173 notImplemented(); 174 } 175 176 void ChromeClientWx::setToolbarsVisible(bool) 177 { 178 notImplemented(); 179 } 180 181 bool ChromeClientWx::toolbarsVisible() 182 { 183 notImplemented(); 184 return false; 185 } 186 187 void ChromeClientWx::setStatusbarVisible(bool) 188 { 189 notImplemented(); 190 } 191 192 bool ChromeClientWx::statusbarVisible() 193 { 194 notImplemented(); 195 return false; 196 } 197 198 void ChromeClientWx::setScrollbarsVisible(bool) 199 { 200 notImplemented(); 201 } 202 203 bool ChromeClientWx::scrollbarsVisible() 204 { 205 notImplemented(); 206 return false; 207 } 208 209 void ChromeClientWx::setMenubarVisible(bool) 210 { 211 notImplemented(); 212 } 213 214 bool ChromeClientWx::menubarVisible() 215 { 216 notImplemented(); 217 return false; 218 } 219 220 void ChromeClientWx::setResizable(bool) 221 { 222 notImplemented(); 223 } 224 225 void ChromeClientWx::addMessageToConsole(MessageSource source, 226 MessageType type, 227 MessageLevel level, 228 const String& message, 229 unsigned int lineNumber, 230 const String& sourceID) 231 { 232 if (m_webView) { 233 wxWebViewConsoleMessageEvent wkEvent(m_webView); 234 wkEvent.SetMessage(message); 235 wkEvent.SetLineNumber(lineNumber); 236 wkEvent.SetSourceID(sourceID); 237 wkEvent.SetLevel(static_cast<wxWebViewConsoleMessageLevel>(level)); 238 m_webView->GetEventHandler()->ProcessEvent(wkEvent); 239 } 240 } 241 242 bool ChromeClientWx::canRunBeforeUnloadConfirmPanel() 243 { 244 notImplemented(); 245 return true; 246 } 247 248 bool ChromeClientWx::runBeforeUnloadConfirmPanel(const String& string, 249 Frame* frame) 250 { 251 wxMessageDialog dialog(NULL, string, wxT("Confirm Action?"), wxYES_NO); 252 return dialog.ShowModal() == wxYES; 253 } 254 255 void ChromeClientWx::closeWindowSoon() 256 { 257 notImplemented(); 258 } 259 260 /* 261 Sites for testing prompts: 262 Alert - just type in a bad web address or http://www.htmlite.com/JS002.php 263 Prompt - http://www.htmlite.com/JS007.php 264 Confirm - http://www.htmlite.com/JS006.php 265 */ 266 267 void ChromeClientWx::runJavaScriptAlert(Frame* frame, const String& string) 268 { 269 if (m_webView) { 270 wxWebViewAlertEvent wkEvent(m_webView); 271 wkEvent.SetMessage(string); 272 if (!m_webView->GetEventHandler()->ProcessEvent(wkEvent)) 273 wxMessageBox(string, wxT("JavaScript Alert"), wxOK); 274 } 275 } 276 277 bool ChromeClientWx::runJavaScriptConfirm(Frame* frame, const String& string) 278 { 279 bool result = false; 280 if (m_webView) { 281 wxWebViewConfirmEvent wkEvent(m_webView); 282 wkEvent.SetMessage(string); 283 if (m_webView->GetEventHandler()->ProcessEvent(wkEvent)) 284 result = wkEvent.GetReturnCode() == wxID_YES; 285 else { 286 wxMessageDialog dialog(NULL, string, wxT("JavaScript Confirm"), wxYES_NO); 287 dialog.Centre(); 288 result = (dialog.ShowModal() == wxID_YES); 289 } 290 } 291 return result; 292 } 293 294 bool ChromeClientWx::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result) 295 { 296 if (m_webView) { 297 wxWebViewPromptEvent wkEvent(m_webView); 298 wkEvent.SetMessage(message); 299 wkEvent.SetResponse(defaultValue); 300 if (m_webView->GetEventHandler()->ProcessEvent(wkEvent)) { 301 result = wkEvent.GetResponse(); 302 return true; 303 } 304 else { 305 wxTextEntryDialog dialog(NULL, message, wxT("JavaScript Prompt"), wxEmptyString, wxOK | wxCANCEL); 306 dialog.Centre(); 307 if (dialog.ShowModal() == wxID_OK) { 308 result = dialog.GetValue(); 309 return true; 310 } 311 } 312 } 313 return false; 314 } 315 316 void ChromeClientWx::setStatusbarText(const String&) 317 { 318 notImplemented(); 319 } 320 321 bool ChromeClientWx::shouldInterruptJavaScript() 322 { 323 notImplemented(); 324 return false; 325 } 326 327 bool ChromeClientWx::tabsToLinks() const 328 { 329 notImplemented(); 330 return false; 331 } 332 333 IntRect ChromeClientWx::windowResizerRect() const 334 { 335 notImplemented(); 336 return IntRect(); 337 } 338 339 void ChromeClientWx::repaint(const IntRect& rect, bool contentChanged, bool immediate, bool repaintContentOnly) 340 { 341 if (!m_webView) 342 return; 343 344 if (contentChanged) 345 m_webView->RefreshRect(rect); 346 347 if (immediate) { 348 m_webView->Update(); 349 } 350 } 351 352 IntRect ChromeClientWx::windowToScreen(const IntRect& rect) const 353 { 354 notImplemented(); 355 return rect; 356 } 357 358 IntPoint ChromeClientWx::screenToWindow(const IntPoint& point) const 359 { 360 notImplemented(); 361 return point; 362 } 363 364 PlatformPageClient ChromeClientWx::platformPageClient() const 365 { 366 return m_webView; 367 } 368 369 void ChromeClientWx::contentsSizeChanged(Frame*, const IntSize&) const 370 { 371 notImplemented(); 372 } 373 374 void ChromeClientWx::scrollBackingStore(int dx, int dy, 375 const IntRect& scrollViewRect, 376 const IntRect& clipRect) 377 { 378 notImplemented(); 379 } 380 381 void ChromeClientWx::updateBackingStore() 382 { 383 notImplemented(); 384 } 385 386 void ChromeClientWx::mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) 387 { 388 notImplemented(); 389 } 390 391 void ChromeClientWx::setToolTip(const String& tip, TextDirection) 392 { 393 wxToolTip* tooltip = m_webView->GetToolTip(); 394 if (!tooltip || tooltip->GetTip() != wxString(tip)) 395 m_webView->SetToolTip(tip); 396 } 397 398 void ChromeClientWx::print(Frame*) 399 { 400 notImplemented(); 401 } 402 403 #if ENABLE(DATABASE) 404 void ChromeClientWx::exceededDatabaseQuota(Frame*, const String&) 405 { 406 unsigned long long quota = 5 * 1024 * 1024; 407 408 if (wxWebFrame* webFrame = m_webView->GetMainFrame()) 409 if (Frame* frame = webFrame->GetFrame()) 410 if (Document* document = frame->document()) 411 if (!DatabaseTracker::tracker().hasEntryForOrigin(document->securityOrigin())) 412 DatabaseTracker::tracker().setQuota(document->securityOrigin(), quota); 413 } 414 #endif 415 416 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 417 void ChromeClientWx::reachedMaxAppCacheSize(int64_t spaceNeeded) 418 { 419 notImplemented(); 420 } 421 #endif 422 423 void ChromeClientWx::scroll(const IntSize&, const IntRect&, const IntRect&) 424 { 425 m_webView->Refresh(); 426 notImplemented(); 427 } 428 429 void ChromeClientWx::runOpenPanel(Frame*, PassRefPtr<FileChooser>) 430 { 431 notImplemented(); 432 } 433 434 bool ChromeClientWx::setCursor(PlatformCursorHandle) 435 { 436 notImplemented(); 437 return false; 438 } 439 440 void ChromeClientWx::requestGeolocationPermissionForFrame(Frame*, Geolocation*) 441 { 442 // See the comment in WebCore/page/ChromeClient.h 443 notImplemented(); 444 } 445 446 } 447