Changeset 167851 in webkit


Ignore:
Timestamp:
Apr 26, 2014 9:09:45 PM (10 years ago)
Author:
Darin Adler
Message:

Frame and page lifetime fixes in WebCore::createWindow
https://bugs.webkit.org/show_bug.cgi?id=132089

Reviewed by Sam Weinig.

Speculative fix because I was unable to reproduce the crash that was
reported with the test case attached to this bug.

  • loader/FrameLoader.cpp:

(WebCore::createWindow): Changed code to remove the assumption that calls
out will not destroy the page or frame. Use RefPtr for the frame, and
added early exits if frame->page() becomes null at any point before we
use a page pointer.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r167850 r167851  
     12014-04-26  Darin Adler  <darin@apple.com>
     2
     3        Frame and page lifetime fixes in WebCore::createWindow
     4        https://bugs.webkit.org/show_bug.cgi?id=132089
     5
     6        Reviewed by Sam Weinig.
     7
     8        Speculative fix because I was unable to reproduce the crash that was
     9        reported with the test case attached to this bug.
     10
     11        * loader/FrameLoader.cpp:
     12        (WebCore::createWindow): Changed code to remove the assumption that calls
     13        out will not destroy the page or frame. Use RefPtr for the frame, and
     14        added early exits if frame->page() becomes null at any point before we
     15        use a page pointer.
     16
    1172014-04-26  Alexey Proskuryakov  <ap@apple.com>
    218
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r167791 r167851  
    34273427    ASSERT(!features.dialog || request.frameName().isEmpty());
    34283428
     3429    created = false;
     3430
    34293431    if (!request.frameName().isEmpty() && request.frameName() != "_blank") {
    3430         if (Frame* frame = lookupFrame->loader().findFrameForNavigation(request.frameName(), openerFrame->document())) {
     3432        if (RefPtr<Frame> frame = lookupFrame->loader().findFrameForNavigation(request.frameName(), openerFrame->document())) {
    34313433            if (request.frameName() != "_self") {
    34323434                if (Page* page = frame->page())
    34333435                    page->chrome().focus();
    34343436            }
    3435             created = false;
    3436             return frame;
     3437            return frame.release();
    34373438        }
    34383439    }
     
    34423443        // FIXME: This message should be moved off the console once a solution to https://bugs.webkit.org/show_bug.cgi?id=103274 exists.
    34433444        openerFrame->document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Blocked opening '" + request.resourceRequest().url().stringCenterEllipsizedToLength() + "' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set.");
    3444         return 0;
     3445        return nullptr;
    34453446    }
    34463447
     
    34543455    Page* oldPage = openerFrame->page();
    34553456    if (!oldPage)
    3456         return 0;
    3457 
    3458     NavigationAction action(requestWithReferrer.resourceRequest());
    3459     Page* page = oldPage->chrome().createWindow(openerFrame, requestWithReferrer, features, action);
     3457        return nullptr;
     3458
     3459    Page* page = oldPage->chrome().createWindow(openerFrame, requestWithReferrer, features, NavigationAction(requestWithReferrer.resourceRequest()));
    34603460    if (!page)
    3461         return 0;
    3462 
    3463     page->mainFrame().loader().forceSandboxFlags(openerFrame->document()->sandboxFlags());
     3461        return nullptr;
     3462
     3463    RefPtr<Frame> frame = &page->mainFrame();
     3464
     3465    frame->loader().forceSandboxFlags(openerFrame->document()->sandboxFlags());
    34643466
    34653467    if (request.frameName() != "_blank")
    3466         page->mainFrame().tree().setName(request.frameName());
     3468        frame->tree().setName(request.frameName());
    34673469
    34683470    page->chrome().setToolbarsVisible(features.toolBarVisible || features.locationBarVisible);
     3471
     3472    if (!frame->page())
     3473        return nullptr;
    34693474    page->chrome().setStatusbarVisible(features.statusBarVisible);
     3475
     3476    if (!frame->page())
     3477        return nullptr;
    34703478    page->chrome().setScrollbarsVisible(features.scrollbarsVisible);
     3479
     3480    if (!frame->page())
     3481        return nullptr;
    34713482    page->chrome().setMenubarVisible(features.menuBarVisible);
     3483
     3484    if (!frame->page())
     3485        return nullptr;
    34723486    page->chrome().setResizable(features.resizable);
    34733487
     
    34763490    // for the difference between the window size and the viewport size.
    34773491
    3478 // FIXME: We should reconcile the initialization of viewport arguments between iOS and OpenSource.
     3492    // FIXME: We should reconcile the initialization of viewport arguments between iOS and non-IOS.
    34793493#if !PLATFORM(IOS)
    34803494    FloatSize viewportSize = page->chrome().pageRect().size();
     
    34933507    FloatRect newWindowRect = DOMWindow::adjustWindowRect(page, windowRect);
    34943508
     3509    if (!frame->page())
     3510        return nullptr;
    34953511    page->chrome().setWindowRect(newWindowRect);
    34963512#else
     
    35023518    if (features.heightSet && features.height)
    35033519        arguments.height = features.height;
    3504     page->mainFrame().setViewportArguments(arguments);
     3520    frame->setViewportArguments(arguments);
    35053521#endif
    35063522
     3523    if (!frame->page())
     3524        return nullptr;
    35073525    page->chrome().show();
    35083526
    35093527    created = true;
    3510     return &page->mainFrame();
     3528    return frame.release();
    35113529}
    35123530
  • trunk/Source/WebCore/loader/SubframeLoader.cpp

    r167598 r167851  
    323323Frame* SubframeLoader::loadOrRedirectSubframe(HTMLFrameOwnerElement& ownerElement, const URL& url, const AtomicString& frameName, LockHistory lockHistory, LockBackForwardList lockBackForwardList)
    324324{
     325    if (!url.isValid())
     326        return nullptr;
     327
    325328    Frame* frame = ownerElement.contentFrame();
    326329    if (frame)
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r167594 r167851  
    18921892
    18931893    URL completedURL = firstFrame->document()->completeURL(urlString);
    1894     if (completedURL.isNull())
     1894    if (!completedURL.isValid())
    18951895        return;
    18961896
    18971897    if (isInsecureScriptAccess(activeWindow, completedURL))
     1898        return;
     1899
     1900    Frame* referrerFrame = activeDocument->frame();
     1901    if (!referrerFrame)
    18981902        return;
    18991903
     
    19011905    LockHistory lockHistory = (locking != LockHistoryBasedOnGestureState || !ScriptController::processingUserGesture()) ? LockHistory::Yes : LockHistory::No;
    19021906    LockBackForwardList lockBackForwardList = (locking != LockHistoryBasedOnGestureState) ? LockBackForwardList::Yes : LockBackForwardList::No;
    1903     m_frame->navigationScheduler().scheduleLocationChange(activeDocument->securityOrigin(),
    1904         // FIXME: What if activeDocument()->frame() is 0?
    1905         completedURL, activeDocument->frame()->loader().outgoingReferrer(),
    1906         lockHistory, lockBackForwardList);
     1907    m_frame->navigationScheduler().scheduleLocationChange(activeDocument->securityOrigin(), completedURL, referrerFrame->loader().outgoingReferrer(), lockHistory, lockBackForwardList);
    19071908}
    19081909
     
    19891990        // Don't expose client code to invalid URLs.
    19901991        activeWindow.printErrorMessage("Unable to open a window with invalid URL '" + completedURL.string() + "'.\n");
    1991         return 0;
     1992        return nullptr;
    19921993    }
    19931994
     
    20042005    RefPtr<Frame> newFrame = WebCore::createWindow(activeFrame, openerFrame, frameRequest, windowFeatures, created);
    20052006    if (!newFrame)
    2006         return 0;
     2007        return nullptr;
    20072008
    20082009    newFrame->loader().setOpener(openerFrame);
     
    20332034{
    20342035    if (!isCurrentlyDisplayedInFrame())
    2035         return 0;
     2036        return nullptr;
    20362037    Document* activeDocument = activeWindow.document();
    20372038    if (!activeDocument)
    2038         return 0;
     2039        return nullptr;
    20392040    Frame* firstFrame = firstWindow.frame();
    20402041    if (!firstFrame)
    2041         return 0;
     2042        return nullptr;
    20422043
    20432044    if (!firstWindow.allowPopUp()) {
     
    20452046        // Otherwise, illegitimate window.open() calls with no name will pass right through the popup blocker.
    20462047        if (frameName.isEmpty() || !m_frame->tree().find(frameName))
    2047             return 0;
     2048            return nullptr;
    20482049    }
    20492050
    20502051    // Get the target frame for the special cases of _top and _parent.
    20512052    // In those cases, we schedule a location change right now and return early.
    2052     Frame* targetFrame = 0;
     2053    Frame* targetFrame = nullptr;
    20532054    if (frameName == "_top")
    20542055        targetFrame = &m_frame->tree().top();
     
    20612062    if (targetFrame) {
    20622063        if (!activeDocument->canNavigate(targetFrame))
    2063             return 0;
     2064            return nullptr;
    20642065
    20652066        URL completedURL = firstFrame->document()->completeURL(urlString);
     2067        if (!completedURL.isValid())
     2068            return nullptr;
    20662069
    20672070        if (targetFrame->document()->domWindow()->isInsecureScriptAccess(activeWindow, completedURL))
     
    20812084    WindowFeatures windowFeatures(windowFeaturesString);
    20822085    RefPtr<Frame> result = createWindow(urlString, frameName, windowFeatures, activeWindow, firstFrame, m_frame);
    2083     return result ? result->document()->domWindow() : 0;
     2086    return result ? result->document()->domWindow() : nullptr;
    20842087}
    20852088
Note: See TracChangeset for help on using the changeset viewer.