ChromeClientBlackBerry.cpp 26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
 * Copyright (C) 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"
#include "ChromeClientBlackBerry.h"

#include "BackingStore.h"
#include "BackingStoreClient.h"
#include "BackingStore_p.h"
26
#include "ColorChooser.h"
27 28 29 30 31 32 33 34 35 36 37
#include "DatabaseTracker.h"
#include "Document.h"
#include "DumpRenderTreeClient.h"
#include "DumpRenderTreeSupport.h"
#include "FileChooser.h"
#include "FileIconLoader.h"
#include "Frame.h"
#include "FrameLoadRequest.h"
#include "FrameLoader.h"
#include "Geolocation.h"
#include "GeolocationControllerClientBlackBerry.h"
38
#include "GraphicsLayer.h"
39 40 41 42 43 44 45 46 47 48 49
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "HitTestResult.h"
#include "Icon.h"
#include "InputHandler.h"
#include "KURL.h"
#include "Node.h"
#include "NotImplemented.h"
#include "Page.h"
#include "PageGroup.h"
#include "PageGroupLoadDeferrer.h"
50 51
#include "PagePopupBlackBerry.h"
#include "PagePopupClient.h"
52 53 54 55 56 57 58 59 60 61
#include "PopupMenuBlackBerry.h"
#include "RenderView.h"
#include "SVGZoomAndPan.h"
#include "SearchPopupMenuBlackBerry.h"
#include "SecurityOrigin.h"
#include "SharedPointer.h"
#include "ViewportArguments.h"
#include "WebPage.h"
#include "WebPageClient.h"
#include "WebPage_p.h"
62
#include "WebPopupType.h"
63 64 65
#include "WebSettings.h"
#include "WebString.h"
#include "WindowFeatures.h"
66

67 68
#include <BlackBerryPlatformLog.h>
#include <BlackBerryPlatformSettings.h>
69
#include <BlackBerryPlatformWindow.h>
70

71
#include <wtf/text/CString.h>
72
#include <wtf/text/WTFString.h>
73

74 75 76 77
#define DEBUG_OVERFLOW_DETECTION 0

using namespace BlackBerry::WebKit;

78 79
using BlackBerry::Platform::Graphics::Window;

80 81
namespace WebCore {

82
static CString toOriginString(Frame* frame)
83
{
84
    return frame->document()->securityOrigin()->toString().latin1();
85 86 87 88 89 90 91 92 93
}

ChromeClientBlackBerry::ChromeClientBlackBerry(WebPagePrivate* pagePrivate)
    : m_webPagePrivate(pagePrivate)
{
}

void ChromeClientBlackBerry::addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, unsigned int lineNumber, const String& sourceID)
{
94
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
95
    if (m_webPagePrivate->m_dumpRenderTree) {
96
        m_webPagePrivate->m_dumpRenderTree->addMessageToConsole(message, lineNumber, sourceID);
97 98
        return;
    }
99 100 101 102 103 104 105
#endif

    m_webPagePrivate->m_client->addMessageToConsole(message.characters(), message.length(), sourceID.characters(), sourceID.length(), lineNumber);
}

void ChromeClientBlackBerry::runJavaScriptAlert(Frame* frame, const String& message)
{
106
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
107 108 109 110 111 112 113
    if (m_webPagePrivate->m_dumpRenderTree) {
        m_webPagePrivate->m_dumpRenderTree->runJavaScriptAlert(message);
        return;
    }
#endif

    TimerBase::fireTimersInNestedEventLoop();
114
    CString latinOrigin = toOriginString(frame);
115 116 117 118 119
    m_webPagePrivate->m_client->runJavaScriptAlert(message.characters(), message.length(), latinOrigin.data(), latinOrigin.length());
}

bool ChromeClientBlackBerry::runJavaScriptConfirm(Frame* frame, const String& message)
{
120
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
121 122 123 124 125
    if (m_webPagePrivate->m_dumpRenderTree)
        return m_webPagePrivate->m_dumpRenderTree->runJavaScriptConfirm(message);
#endif

    TimerBase::fireTimersInNestedEventLoop();
126
    CString latinOrigin = toOriginString(frame);
127 128 129 130 131
    return m_webPagePrivate->m_client->runJavaScriptConfirm(message.characters(), message.length(), latinOrigin.data(), latinOrigin.length());
}

bool ChromeClientBlackBerry::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
{
132
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
133 134 135 136 137 138 139
    if (m_webPagePrivate->m_dumpRenderTree) {
        result = m_webPagePrivate->m_dumpRenderTree->runJavaScriptPrompt(message, defaultValue);
        return true;
    }
#endif

    TimerBase::fireTimersInNestedEventLoop();
140
    CString latinOrigin = toOriginString(frame);
141 142 143 144 145 146 147 148 149 150
    WebString clientResult;
    if (m_webPagePrivate->m_client->runJavaScriptPrompt(message.characters(), message.length(), defaultValue.characters(), defaultValue.length(), latinOrigin.data(), latinOrigin.length(), clientResult)) {
        result = clientResult;
        return true;
    }
    return false;
}

void ChromeClientBlackBerry::chromeDestroyed()
{
151 152
    // Destroy popup if we have.
    closePagePopup(0);
153 154 155 156 157 158 159 160 161 162
    delete this;
}

void ChromeClientBlackBerry::setWindowRect(const FloatRect&)
{
    // The window dimensions are fixed in the RIM port.
}

FloatRect ChromeClientBlackBerry::windowRect()
{
163 164 165 166 167
    IntSize windowSize;

    if (Window* window = m_webPagePrivate->m_client->window())
        windowSize = window->windowSize();

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    return FloatRect(0, 0, windowSize.width(), windowSize.height());
}

FloatRect ChromeClientBlackBerry::pageRect()
{
    notImplemented();
    return FloatRect();
}

float ChromeClientBlackBerry::scaleFactor()
{
    return 1;
}

void ChromeClientBlackBerry::focus()
{
    notImplemented();
}

void ChromeClientBlackBerry::unfocus()
{
    notImplemented();
}

bool ChromeClientBlackBerry::canTakeFocus(FocusDirection)
{
    notImplemented();
    return false;
}

void ChromeClientBlackBerry::takeFocus(FocusDirection)
{
    notImplemented();
}

203
void ChromeClientBlackBerry::focusedNodeChanged(Node*)
204
{
205
    m_webPagePrivate->m_inputHandler->focusedNodeChanged();
206 207 208 209 210 211 212 213 214 215 216 217 218 219
}

void ChromeClientBlackBerry::focusedFrameChanged(Frame*)
{
    // To be used by In-region backing store context switching.
}

bool ChromeClientBlackBerry::shouldForceDocumentStyleSelectorUpdate()
{
    return !m_webPagePrivate->m_webSettings->isJavaScriptEnabled() && !m_webPagePrivate->m_inputHandler->processingChange();
}

Page* ChromeClientBlackBerry::createWindow(Frame*, const FrameLoadRequest& request, const WindowFeatures& features, const NavigationAction&)
{
220
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
221 222 223 224
    if (m_webPagePrivate->m_dumpRenderTree && !m_webPagePrivate->m_dumpRenderTree->allowsOpeningWindow())
        return 0;
#endif

225
    PageGroupLoadDeferrer deferrer(m_webPagePrivate->m_page, true);
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
    TimerBase::fireTimersInNestedEventLoop();

    int x = features.xSet ? features.x : 0;
    int y = features.ySet ? features.y : 0;
    int width = features.widthSet? features.width : -1;
    int height = features.heightSet ? features.height : -1;
    unsigned flags = 0;

    if (features.menuBarVisible)
        flags |= WebPageClient::FlagWindowHasMenuBar;
    if (features.statusBarVisible)
        flags |= WebPageClient::FlagWindowHasStatusBar;
    if (features.toolBarVisible)
        flags |= WebPageClient::FlagWindowHasToolBar;
    if (features.locationBarVisible)
        flags |= WebPageClient::FlagWindowHasLocationBar;
    if (features.scrollbarsVisible)
        flags |= WebPageClient::FlagWindowHasScrollBar;
    if (features.resizable)
        flags |= WebPageClient::FlagWindowIsResizable;
    if (features.fullscreen)
        flags |= WebPageClient::FlagWindowIsFullScreen;
    if (features.dialog)
        flags |= WebPageClient::FlagWindowIsDialog;

    WebPage* webPage = m_webPagePrivate->m_client->createWindow(x, y, width, height, flags, WebString(request.resourceRequest().url().string()), WebString(request.frameName()));
    if (!webPage)
        return 0;

255
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
    if (m_webPagePrivate->m_dumpRenderTree)
        m_webPagePrivate->m_dumpRenderTree->windowCreated(webPage);
#endif

    return webPage->d->m_page;
}

void ChromeClientBlackBerry::show()
{
    notImplemented();
}

bool ChromeClientBlackBerry::canRunModal()
{
    notImplemented();
    return false;
}

void ChromeClientBlackBerry::runModal()
{
    notImplemented();
}

bool ChromeClientBlackBerry::selectItemWritingDirectionIsNatural()
{
    return false;
}

bool ChromeClientBlackBerry::selectItemAlignmentFollowsMenuWritingDirection()
{
    return true;
}

289 290
bool ChromeClientBlackBerry::hasOpenedPopup() const
{
291
    return m_webPagePrivate->m_webPage->hasOpenedPopup();
292 293
}

294 295 296 297 298 299 300 301 302 303
PassRefPtr<PopupMenu> ChromeClientBlackBerry::createPopupMenu(PopupMenuClient* client) const
{
    return adoptRef(new PopupMenuBlackBerry(client));
}

PassRefPtr<SearchPopupMenu> ChromeClientBlackBerry::createSearchPopupMenu(PopupMenuClient* client) const
{
    return adoptRef(new SearchPopupMenuBlackBerry(client));
}

304 305
PagePopup* ChromeClientBlackBerry::openPagePopup(PagePopupClient* client, const IntRect& originBoundsInRootView)
{
306
    closePagePopup(0);
307

308 309
    PagePopupBlackBerry* webPopup = new PagePopupBlackBerry(m_webPagePrivate, client, rootViewToScreen(originBoundsInRootView));
    m_webPagePrivate->m_webPage->popupOpened(webPopup);
310 311 312 313 314
    if (webPopup->sendCreatePopupWebViewRequest())
        return webPopup;

    closePagePopup(0);
    return 0;
315 316
}

317
void ChromeClientBlackBerry::closePagePopup(PagePopup*)
318
{
319 320 321 322 323
    if (!hasOpenedPopup())
        return;

    PagePopupBlackBerry* webPopup = m_webPagePrivate->m_webPage->popup();
    webPopup->closePopup();
324
    delete webPopup;
325
}
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377

void ChromeClientBlackBerry::setToolbarsVisible(bool)
{
    notImplemented();
}

bool ChromeClientBlackBerry::toolbarsVisible()
{
    notImplemented();
    return false;
}

void ChromeClientBlackBerry::setStatusbarVisible(bool)
{
    notImplemented();
}

bool ChromeClientBlackBerry::statusbarVisible()
{
    notImplemented();
    return false;
}

void ChromeClientBlackBerry::setScrollbarsVisible(bool)
{
    notImplemented();
}

bool ChromeClientBlackBerry::scrollbarsVisible()
{
    notImplemented();
    return false;
}

void ChromeClientBlackBerry::setMenubarVisible(bool)
{
    notImplemented();
}

bool ChromeClientBlackBerry::menubarVisible()
{
    notImplemented();
    return false;
}

void ChromeClientBlackBerry::setResizable(bool)
{
    notImplemented();
}

bool ChromeClientBlackBerry::canRunBeforeUnloadConfirmPanel()
{
378
    return true;
379 380
}

381
bool ChromeClientBlackBerry::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
382
{
383
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
384 385 386 387
    if (m_webPagePrivate->m_dumpRenderTree)
        return m_webPagePrivate->m_dumpRenderTree->runBeforeUnloadConfirmPanel(message);
#endif

388
    TimerBase::fireTimersInNestedEventLoop();
389
    CString latinOrigin = toOriginString(frame);
390
    return m_webPagePrivate->m_client->runBeforeUnloadConfirmPanel(message.characters(), message.length(), latinOrigin.data(), latinOrigin.length());
391 392 393 394
}

void ChromeClientBlackBerry::closeWindowSoon()
{
395 396
    if (m_webPagePrivate->m_page->openedByDOM())
        m_webPagePrivate->m_client->scheduleCloseWindow();
397 398 399 400 401 402
}

void ChromeClientBlackBerry::setStatusbarText(const String& status)
{
    m_webPagePrivate->m_client->setStatus(status);

403
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
404 405 406 407 408 409 410 411 412 413 414
    if (m_webPagePrivate->m_dumpRenderTree)
        m_webPagePrivate->m_dumpRenderTree->setStatusText(status);
#endif
}

IntRect ChromeClientBlackBerry::windowResizerRect() const
{
    notImplemented();
    return IntRect();
}

415
IntPoint ChromeClientBlackBerry::screenToRootView(const IntPoint& screenPos) const
416
{
417 418 419 420
    IntPoint windowPoint;
    if (Window* window = m_webPagePrivate->m_client->window())
        windowPoint = window->windowLocation();

421 422 423 424
    windowPoint.move(-screenPos.x(), -screenPos.y());
    return windowPoint;
}

425
IntRect ChromeClientBlackBerry::rootViewToScreen(const IntRect& windowRect) const
426 427
{
    IntRect windowPoint(windowRect);
428 429 430 431
    IntPoint location;
    if (Window* window = m_webPagePrivate->m_client->window())
        location = window->windowLocation();

432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
    windowPoint.move(location.x(), location.y());
    return windowPoint;
}

void ChromeClientBlackBerry::mouseDidMoveOverElement(const HitTestResult& result, unsigned int modifierFlags)
{
    notImplemented();
}

void ChromeClientBlackBerry::setToolTip(const String& tooltip, TextDirection)
{
    m_webPagePrivate->m_client->setToolTip(tooltip);
}

#if ENABLE(EVENT_MODE_METATAGS)
void ChromeClientBlackBerry::didReceiveCursorEventMode(Frame* frame, CursorEventMode mode) const
{
    if (m_webPagePrivate->m_mainFrame != frame)
        return;

    m_webPagePrivate->didReceiveCursorEventMode(mode);
}

void ChromeClientBlackBerry::didReceiveTouchEventMode(Frame* frame, TouchEventMode mode) const
{
    if (m_webPagePrivate->m_mainFrame != frame)
        return;

    m_webPagePrivate->didReceiveTouchEventMode(mode);
}
#endif

void ChromeClientBlackBerry::dispatchViewportPropertiesDidChange(const ViewportArguments& arguments) const
{
    m_webPagePrivate->dispatchViewportPropertiesDidChange(arguments);
}

void ChromeClientBlackBerry::print(Frame*)
{
    notImplemented();
}

void ChromeClientBlackBerry::exceededDatabaseQuota(Frame* frame, const String& name)
{
#if ENABLE(SQL_DATABASE)
    Document* document = frame->document();
    if (!document)
        return;

    SecurityOrigin* origin = document->securityOrigin();

483
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
    if (m_webPagePrivate->m_dumpRenderTree) {
        m_webPagePrivate->m_dumpRenderTree->exceededDatabaseQuota(origin, name);
        return;
    }
#endif

    DatabaseTracker& tracker = DatabaseTracker::tracker();

    unsigned long long totalUsage = tracker.totalDatabaseUsage();
    unsigned long long originUsage = tracker.usageForOrigin(origin);

    DatabaseDetails details = tracker.detailsForNameAndOrigin(name, origin);
    unsigned long long estimatedSize = details.expectedUsage();
    const String& nameStr = details.displayName();

    String originStr = origin->databaseIdentifier();

    unsigned long long quota = m_webPagePrivate->m_client->databaseQuota(originStr.characters(), originStr.length(),
        nameStr.characters(), nameStr.length(), totalUsage, originUsage, estimatedSize);

    tracker.setQuota(origin, quota);
#endif
}

void ChromeClientBlackBerry::runOpenPanel(Frame*, PassRefPtr<FileChooser> chooser)
{
    SharedArray<WebString> initialFiles;
511 512 513 514
    unsigned numberOfInitialFiles = chooser->settings().selectedFiles.size();
    if (numberOfInitialFiles > 0)
        initialFiles.reset(new WebString[numberOfInitialFiles], numberOfInitialFiles);
    for (unsigned i = 0; i < numberOfInitialFiles; ++i)
515 516
        initialFiles[i] = chooser->settings().selectedFiles[i];

517 518 519 520 521 522 523 524 525 526 527 528
    SharedArray<WebString> acceptMIMETypes;
    unsigned numberOfTypes = chooser->settings().acceptMIMETypes.size();
    if (numberOfTypes > 0)
        acceptMIMETypes.reset(new WebString[numberOfTypes], numberOfTypes);
    for (unsigned i = 0; i < numberOfTypes; ++i)
        acceptMIMETypes[i] = chooser->settings().acceptMIMETypes[i];

    WebString capture;
#if ENABLE(MEDIA_CAPTURE)
    capture = chooser->settings().capture;
#endif

529 530 531
    SharedArray<WebString> chosenFiles;

    {
532
        PageGroupLoadDeferrer deferrer(m_webPagePrivate->m_page, true);
533 534
        TimerBase::fireTimersInNestedEventLoop();

535
        if (!m_webPagePrivate->m_client->chooseFilenames(chooser->settings().allowsMultipleFiles, acceptMIMETypes, initialFiles, capture, chosenFiles))
536 537 538
            return;
    }

539 540
    Vector<String> files(chosenFiles.length());
    for (unsigned i = 0; i < chosenFiles.length(); ++i)
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
        files[i] = chosenFiles[i];
    chooser->chooseFiles(files);
}

void ChromeClientBlackBerry::loadIconForFiles(const Vector<String>& filenames, FileIconLoader* loader)
{
    loader->notifyFinished(Icon::createIconForFiles(filenames));
}

void ChromeClientBlackBerry::setCursor(const Cursor&)
{
    notImplemented();
}

void ChromeClientBlackBerry::formStateDidChange(const Node* node)
{
    m_webPagePrivate->m_inputHandler->nodeTextChanged(node);
}

void ChromeClientBlackBerry::scrollbarsModeDidChange() const
{
    notImplemented();
}

void ChromeClientBlackBerry::contentsSizeChanged(Frame* frame, const IntSize& size) const
{
    if (frame != m_webPagePrivate->m_mainFrame)
        return;

    m_webPagePrivate->contentsSizeChanged(size);
}

573
void ChromeClientBlackBerry::invalidateRootView(const IntRect& updateRect, bool immediate)
574 575 576 577
{
    m_webPagePrivate->m_backingStore->d->repaint(updateRect, false /*contentChanged*/, immediate);
}

578
void ChromeClientBlackBerry::invalidateContentsAndRootView(const IntRect& updateRect, bool immediate)
579 580 581 582 583 584 585
{
    m_webPagePrivate->m_backingStore->d->repaint(updateRect, true /*contentChanged*/, immediate);
}

void ChromeClientBlackBerry::invalidateContentsForSlowScroll(const IntSize& delta, const IntRect& updateRect, bool immediate, const ScrollView* scrollView)
{
    if (scrollView != m_webPagePrivate->m_mainFrame->view())
586
        invalidateContentsAndRootView(updateRect, true /*immediate*/);
587
    else {
588 589 590
        BackingStoreClient* backingStoreClient = m_webPagePrivate->backingStoreClient();
        ASSERT(backingStoreClient);
        backingStoreClient->checkOriginOfCurrentScrollOperation();
591 592 593 594 595 596 597 598 599 600 601 602 603

        m_webPagePrivate->m_backingStore->d->slowScroll(delta, updateRect, immediate);
    }
}

void ChromeClientBlackBerry::scroll(const IntSize& delta, const IntRect& scrollViewRect, const IntRect& clipRect)
{
    // FIXME: There's a chance the function is called indirectly by FrameView's dtor
    // when the Frame's view() is null. We probably want to fix it in another way, but
    // at this moment let's do a quick fix.
    if (!m_webPagePrivate->m_mainFrame->view())
        return;

604 605 606
    BackingStoreClient* backingStoreClient = m_webPagePrivate->backingStoreClient();
    ASSERT(backingStoreClient);
    backingStoreClient->checkOriginOfCurrentScrollOperation();
607 608 609 610 611 612 613

    m_webPagePrivate->m_backingStore->d->scroll(delta, scrollViewRect, clipRect);
}

void ChromeClientBlackBerry::scrollableAreasDidChange()
{
    typedef HashSet<ScrollableArea*> ScrollableAreaSet;
614
    const ScrollableAreaSet* scrollableAreas = m_webPagePrivate->m_mainFrame->view()->scrollableAreas();
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642

    bool hasAtLeastOneInRegionScrollableArea = false;
    ScrollableAreaSet::iterator end = scrollableAreas->end();
    for (ScrollableAreaSet::iterator it = scrollableAreas->begin(); it != end; ++it) {
        if ((*it) != m_webPagePrivate->m_page->mainFrame()->view()) {
            hasAtLeastOneInRegionScrollableArea = true;
            break;
        }
    }

    m_webPagePrivate->setHasInRegionScrollableAreas(hasAtLeastOneInRegionScrollableArea);
}

void ChromeClientBlackBerry::scrollRectIntoView(const IntRect&, const ScrollView*) const
{
    m_webPagePrivate->notifyTransformedScrollChanged();
}

bool ChromeClientBlackBerry::shouldInterruptJavaScript()
{
    TimerBase::fireTimersInNestedEventLoop();
    return m_webPagePrivate->m_client->shouldInterruptJavaScript();
}

KeyboardUIMode ChromeClientBlackBerry::keyboardUIMode()
{
    bool tabsToLinks = true;

643
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
    if (m_webPagePrivate->m_dumpRenderTree)
        tabsToLinks = DumpRenderTreeSupport::linksIncludedInFocusChain();
#endif

    return tabsToLinks ? KeyboardAccessTabsToLinks : KeyboardAccessDefault;
}

PlatformPageClient ChromeClientBlackBerry::platformPageClient() const
{
    return m_webPagePrivate;
}

#if ENABLE(TOUCH_EVENTS)
void ChromeClientBlackBerry::needTouchEvents(bool value)
{
    m_webPagePrivate->setNeedTouchEvents(value);
}
#endif

void ChromeClientBlackBerry::reachedMaxAppCacheSize(int64_t spaceNeeded)
{
    notImplemented();
}

void ChromeClientBlackBerry::layoutUpdated(Frame* frame) const
{
    if (frame != m_webPagePrivate->m_mainFrame)
        return;

    m_webPagePrivate->layoutFinished();
}

void ChromeClientBlackBerry::overflowExceedsContentsSize(Frame* frame) const
{
    if (frame != m_webPagePrivate->m_mainFrame)
        return;

#if DEBUG_OVERFLOW_DETECTION
    BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "ChromeClientBlackBerry::overflowExceedsContentsSize contents=%dx%d overflow=%dx%d",
                           frame->contentRenderer()->rightLayoutOverflow(),
                           frame->contentRenderer()->bottomLayoutOverflow(),
                           frame->contentRenderer()->rightAbsoluteVisibleOverflow(),
                           frame->contentRenderer()->bottomAbsoluteVisibleOverflow());
#endif
    m_webPagePrivate->overflowExceedsContentsSize();
}

void ChromeClientBlackBerry::didDiscoverFrameSet(Frame* frame) const
{
    if (frame != m_webPagePrivate->m_mainFrame)
        return;

    BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "ChromeClientBlackBerry::didDiscoverFrameSet");
    if (m_webPagePrivate->loadState() == WebPagePrivate::Committed) {
        m_webPagePrivate->setShouldUseFixedDesktopMode(true);
        m_webPagePrivate->zoomToInitialScaleOnLoad();
    }
}

int ChromeClientBlackBerry::reflowWidth() const
{
    return m_webPagePrivate->reflowWidth();
}

void ChromeClientBlackBerry::chooseIconForFiles(const Vector<String>&, FileChooser*)
{
    notImplemented();
}

bool ChromeClientBlackBerry::supportsFullscreenForNode(const Node* node)
{
    return node->hasTagName(HTMLNames::videoTag);
}

void ChromeClientBlackBerry::enterFullscreenForNode(Node* node)
{
    if (!supportsFullscreenForNode(node))
        return;

    m_webPagePrivate->enterFullscreenForNode(node);
}

void ChromeClientBlackBerry::exitFullscreenForNode(Node* node)
{
    m_webPagePrivate->exitFullscreenForNode(node);
}

731 732 733 734 735 736 737 738
#if ENABLE(FULLSCREEN_API)
bool ChromeClientBlackBerry::supportsFullScreenForElement(const WebCore::Element* element, bool withKeyboard)
{
    return !withKeyboard;
}

void ChromeClientBlackBerry::enterFullScreenForElement(WebCore::Element* element)
{
739 740 741 742 743
    // To avoid glitches on the screen when entering fullscreen, lets suspend the
    // Backing Store screen updates and only resume at the next call of WebPagePrivate::setViewportSize.
    m_webPagePrivate->m_isTogglingFullScreenState = true;
    m_webPagePrivate->m_backingStore->d->suspendScreenAndBackingStoreUpdates();

744
    element->document()->webkitWillEnterFullScreenForElement(element);
745
    m_webPagePrivate->enterFullScreenForElement(element);
746
    element->document()->webkitDidEnterFullScreenForElement(element);
747
    m_fullScreenElement = element;
748 749
}

750
void ChromeClientBlackBerry::exitFullScreenForElement(WebCore::Element*)
751
{
752 753 754
    m_webPagePrivate->m_isTogglingFullScreenState = true;
    m_webPagePrivate->m_backingStore->d->suspendScreenAndBackingStoreUpdates();

755 756 757 758 759 760 761 762
    // The element passed into this function is not reliable, i.e. it could
    // be null. In addition the parameter may be disappearing in the future.
    // So we use the reference to the element we saved above.
    ASSERT(m_fullScreenElement);
    m_fullScreenElement->document()->webkitWillExitFullScreenForElement(m_fullScreenElement.get());
    m_webPagePrivate->exitFullScreenForElement(m_fullScreenElement.get());
    m_fullScreenElement->document()->webkitDidExitFullScreenForElement(m_fullScreenElement.get());
    m_fullScreenElement.clear();
763
}
764 765 766 767 768

void ChromeClientBlackBerry::fullScreenRendererChanged(RenderBox* fullScreenRenderer)
{
    // Once we go fullscreen using the new FULLSCREEN_API code path, we have to take into account
    // our port specific page scaling.
769
    if (fullScreenRenderer) {
770 771
        int width = m_webPagePrivate->m_mainFrame->view()->visibleContentRect().size().width();
        fullScreenRenderer->style()->setWidth(Length(width, Fixed));
772
    }
773
}
774 775
#endif

776 777 778 779
#if ENABLE(WEBGL)
void ChromeClientBlackBerry::requestWebGLPermission(Frame* frame)
{
    if (frame) {
780
        CString latinOrigin = toOriginString(frame);
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
        m_webPagePrivate->m_client->requestWebGLPermission(latinOrigin.data());
    }
}
#endif

#if ENABLE(SVG)
void ChromeClientBlackBerry::didSetSVGZoomAndPan(Frame* frame, unsigned short zoomAndPan)
{
    // For top-level SVG document, there is no viewport tag, we use viewport's user-scalable
    // to enable/disable zoom when top-level SVG document's zoomAndPan changed. Because there is no viewport
    // tag, other fields with default value in ViewportArguments are ok.
    if (frame == m_webPagePrivate->m_page->mainFrame()) {
        ViewportArguments arguments;
        switch (zoomAndPan) {
        case SVGZoomAndPan::SVG_ZOOMANDPAN_DISABLE:
            arguments.userScalable = 0;
            break;
        case SVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY:
            arguments.userScalable = 1;
            break;
        default:
            return;
        }
        didReceiveViewportArguments(frame, arguments);
    }
}
#endif

#if USE(ACCELERATED_COMPOSITING)
void ChromeClientBlackBerry::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* graphicsLayer)
{
    // If the graphicsLayer parameter is 0, WebCore is actually
    // trying to remove a previously attached layer.
    m_webPagePrivate->setRootLayerWebKitThread(frame, graphicsLayer ? graphicsLayer->platformLayer() : 0);
}

void ChromeClientBlackBerry::setNeedsOneShotDrawingSynchronization()
{
    m_webPagePrivate->setNeedsOneShotDrawingSynchronization();
}

822
void ChromeClientBlackBerry::scheduleCompositingLayerFlush()
823 824 825 826 827 828 829 830 831 832
{
    m_webPagePrivate->scheduleRootLayerCommit();
}

bool ChromeClientBlackBerry::allowsAcceleratedCompositing() const
{
    return true;
}
#endif

833 834 835 836 837
PassOwnPtr<ColorChooser> ChromeClientBlackBerry::createColorChooser(ColorChooserClient*, const Color&)
{
    return nullptr;
}

838 839 840 841 842 843
#if ENABLE(NAVIGATOR_CONTENT_UTILS)
void ChromeClientBlackBerry::registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title)
{
    m_webPagePrivate->m_client->registerProtocolHandler(scheme, baseURL, url, title);
}

844
#if ENABLE(CUSTOM_SCHEME_HANDLER)
845
ChromeClient::CustomHandlersState ChromeClientBlackBerry::isProtocolHandlerRegistered(const String& scheme, const String& baseURL, const String& url)
846
{
847
    return static_cast<CustomHandlersState>(m_webPagePrivate->m_client->isProtocolHandlerRegistered(scheme, baseURL, url));
848 849
}

850
void ChromeClientBlackBerry::unregisterProtocolHandler(const String& scheme, const String& baseURL, const String& url)
851
{
852
    m_webPagePrivate->m_client->unregisterProtocolHandler(scheme, baseURL, url);
853 854
}
#endif
855 856
#endif

857
} // namespace WebCore