Title: [131014] trunk/Source
Revision
131014
Author
commit-qu...@webkit.org
Date
2012-10-10 21:55:05 -0700 (Wed, 10 Oct 2012)

Log Message

[BlackBerry] Fix assertion in NetworkJob::notifyChallengeResult.
https://bugs.webkit.org/show_bug.cgi?id=97397
Internal PR: 186597.

Internally reviewed by Yong Li, Joe Mason.
Patch by Lianghui Chen <liac...@rim.com> on 2012-10-10
Reviewed by George Staikos.

Source/WebCore:

Add a singleton AuthenticationChallengeManager to manage authentication
challenge dialog. It does following things:
Record page creation/deletion, so it knows what page is present or not.
Record page visibility change so it knows when to display a dialog or not.
Accept authentication challenge, and decide whether to postpone the
    challenge dialog based on whether there is active authentication challenge
    dialog already and whether its page is visible or not.
When a challenge result comes back, notify the result to all clients
    authenticating for the same protection space, and then start the next
    authentication challenge from the same page, if there is one.
When a page becomes visible, start the first authentication challenge
    dialog that has been blocked before.
When an authentication challenge is requested, the NetworkJob will be
    deferred so its initial response will be saved while waiting for
    user decision on the challenge.

No new tests for platform specific internal change.

* PlatformBlackBerry.cmake:
* platform/blackberry/AuthenticationChallengeManager.cpp: Added.
(WebCore):
(ChallengeInfo):
(WebCore::ChallengeInfo::ChallengeInfo):
(AuthenticationChallengeManagerPrivate):
(WebCore::AuthenticationChallengeManagerPrivate::AuthenticationChallengeManagerPrivate):
(WebCore::AuthenticationChallengeManagerPrivate::resumeAuthenticationChallenge):
(WebCore::AuthenticationChallengeManagerPrivate::startAuthenticationChallenge):
(WebCore::AuthenticationChallengeManagerPrivate::pageExists):
(WebCore::AuthenticationChallengeManager::AuthenticationChallengeManager):
(WebCore::AuthenticationChallengeManager::pageCreated):
(WebCore::AuthenticationChallengeManager::pageDeleted):
(WebCore::AuthenticationChallengeManager::pageVisibilityChanged):
(WebCore::AuthenticationChallengeManager::authenticationChallenge):
(WebCore::AuthenticationChallengeManager::cancelAuthenticationChallenge):
(WebCore::AuthenticationChallengeManager::notifyChallengeResult):
(WebCore::AuthenticationChallengeManager::instance):
(WebCore::AuthenticationChallengeManager::init):
* platform/blackberry/AuthenticationChallengeManager.h:
(WebCore):
(AuthenticationChallengeManager):
* platform/blackberry/PageClientBlackBerry.h:
* platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.cpp:
(WebCore::MediaPlayerPrivate::MediaPlayerPrivate):
(WebCore::MediaPlayerPrivate::~MediaPlayerPrivate):
(WebCore::MediaPlayerPrivate::onAuthenticationNeeded):
(WebCore::MediaPlayerPrivate::notifyChallengeResult):
* platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.h:
(MediaPlayerPrivate):
* platform/network/blackberry/NetworkJob.cpp:
(WebCore::NetworkJob::NetworkJob):
(WebCore::NetworkJob::~NetworkJob):
(WebCore):
(WebCore::NetworkJob::handleNotifyStatusReceived):
(WebCore::NetworkJob::handleNotifyClose):
(WebCore::NetworkJob::shouldReleaseClientResource):
(WebCore::NetworkJob::sendRequestWithCredentials):
(WebCore::NetworkJob::notifyChallengeResult):
* platform/network/blackberry/NetworkJob.h:
(NetworkJob):

Source/WebKit/blackberry:

Update WebPage to use new AuthenticationChallengeManager.
Register page creation/deletion and visibility change to the new
    AuthenticationChallengeManager.
Initialize AuthenticationChallengeManager in GlobalInitialize() function.

* Api/BlackBerryGlobal.cpp:
(BlackBerry::WebKit::globalInitialize):
* Api/WebPage.cpp:
(BlackBerry::WebKit::WebPagePrivate::WebPagePrivate):
(BlackBerry::WebKit::WebPagePrivate::~WebPagePrivate):
(BlackBerry::WebKit::WebPagePrivate::authenticationChallenge):
(BlackBerry::WebKit::WebPage::setVisible):
* Api/WebPage_p.h:
(WebPagePrivate):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (131013 => 131014)


--- trunk/Source/WebCore/ChangeLog	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebCore/ChangeLog	2012-10-11 04:55:05 UTC (rev 131014)
@@ -1,3 +1,72 @@
+2012-10-10  Lianghui Chen  <liac...@rim.com>
+
+        [BlackBerry] Fix assertion in NetworkJob::notifyChallengeResult.
+        https://bugs.webkit.org/show_bug.cgi?id=97397
+        Internal PR: 186597.
+
+        Internally reviewed by Yong Li, Joe Mason.
+        Reviewed by George Staikos.
+
+        Add a singleton AuthenticationChallengeManager to manage authentication
+        challenge dialog. It does following things:
+        Record page creation/deletion, so it knows what page is present or not.
+        Record page visibility change so it knows when to display a dialog or not.
+        Accept authentication challenge, and decide whether to postpone the
+            challenge dialog based on whether there is active authentication challenge
+            dialog already and whether its page is visible or not.
+        When a challenge result comes back, notify the result to all clients
+            authenticating for the same protection space, and then start the next
+            authentication challenge from the same page, if there is one.
+        When a page becomes visible, start the first authentication challenge
+            dialog that has been blocked before.
+        When an authentication challenge is requested, the NetworkJob will be
+            deferred so its initial response will be saved while waiting for
+            user decision on the challenge.
+
+        No new tests for platform specific internal change.
+
+        * PlatformBlackBerry.cmake:
+        * platform/blackberry/AuthenticationChallengeManager.cpp: Added.
+        (WebCore):
+        (ChallengeInfo):
+        (WebCore::ChallengeInfo::ChallengeInfo):
+        (AuthenticationChallengeManagerPrivate):
+        (WebCore::AuthenticationChallengeManagerPrivate::AuthenticationChallengeManagerPrivate):
+        (WebCore::AuthenticationChallengeManagerPrivate::resumeAuthenticationChallenge):
+        (WebCore::AuthenticationChallengeManagerPrivate::startAuthenticationChallenge):
+        (WebCore::AuthenticationChallengeManagerPrivate::pageExists):
+        (WebCore::AuthenticationChallengeManager::AuthenticationChallengeManager):
+        (WebCore::AuthenticationChallengeManager::pageCreated):
+        (WebCore::AuthenticationChallengeManager::pageDeleted):
+        (WebCore::AuthenticationChallengeManager::pageVisibilityChanged):
+        (WebCore::AuthenticationChallengeManager::authenticationChallenge):
+        (WebCore::AuthenticationChallengeManager::cancelAuthenticationChallenge):
+        (WebCore::AuthenticationChallengeManager::notifyChallengeResult):
+        (WebCore::AuthenticationChallengeManager::instance):
+        (WebCore::AuthenticationChallengeManager::init):
+        * platform/blackberry/AuthenticationChallengeManager.h:
+        (WebCore):
+        (AuthenticationChallengeManager):
+        * platform/blackberry/PageClientBlackBerry.h:
+        * platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.cpp:
+        (WebCore::MediaPlayerPrivate::MediaPlayerPrivate):
+        (WebCore::MediaPlayerPrivate::~MediaPlayerPrivate):
+        (WebCore::MediaPlayerPrivate::onAuthenticationNeeded):
+        (WebCore::MediaPlayerPrivate::notifyChallengeResult):
+        * platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.h:
+        (MediaPlayerPrivate):
+        * platform/network/blackberry/NetworkJob.cpp:
+        (WebCore::NetworkJob::NetworkJob):
+        (WebCore::NetworkJob::~NetworkJob):
+        (WebCore):
+        (WebCore::NetworkJob::handleNotifyStatusReceived):
+        (WebCore::NetworkJob::handleNotifyClose):
+        (WebCore::NetworkJob::shouldReleaseClientResource):
+        (WebCore::NetworkJob::sendRequestWithCredentials):
+        (WebCore::NetworkJob::notifyChallengeResult):
+        * platform/network/blackberry/NetworkJob.h:
+        (NetworkJob):
+
 2012-10-10  Simon Fraser  <simon.fra...@apple.com>
 
         compositing/tiling/crash-reparent-tiled-layer.html is flakey

Modified: trunk/Source/WebCore/PlatformBlackBerry.cmake (131013 => 131014)


--- trunk/Source/WebCore/PlatformBlackBerry.cmake	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebCore/PlatformBlackBerry.cmake	2012-10-11 04:55:05 UTC (rev 131014)
@@ -61,6 +61,7 @@
     bindings/cpp/WebDOMString.cpp
     bindings/cpp/WebExceptionHandler.cpp
     platform/blackberry/CookieDatabaseBackingStore/CookieDatabaseBackingStore.cpp
+    platform/blackberry/AuthenticationChallengeManager.cpp
     platform/blackberry/CookieManager.cpp
     platform/blackberry/CookieMap.cpp
     platform/blackberry/CookieParser.cpp

Added: trunk/Source/WebCore/platform/blackberry/AuthenticationChallengeManager.cpp (0 => 131014)


--- trunk/Source/WebCore/platform/blackberry/AuthenticationChallengeManager.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/blackberry/AuthenticationChallengeManager.cpp	2012-10-11 04:55:05 UTC (rev 131014)
@@ -0,0 +1,243 @@
+/*
+ * Copyright (C) 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 "AuthenticationChallengeManager.h"
+
+#include "Credential.h"
+#include "KURL.h"
+#include "PageClientBlackBerry.h"
+#include "ProtectionSpace.h"
+
+#include <BlackBerryPlatformAssert.h>
+#include <BlackBerryPlatformLog.h>
+#include <wtf/Assertions.h>
+#include <wtf/HashMap.h>
+#include <wtf/Vector.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+typedef HashMap<PageClientBlackBerry*, bool> PageVisibilityMap;
+
+struct ChallengeInfo {
+    ChallengeInfo(const KURL&, const ProtectionSpace&, const Credential&, AuthenticationChallengeClient*, PageClientBlackBerry*);
+
+    KURL url;
+    ProtectionSpace space;
+    Credential credential;
+    AuthenticationChallengeClient* authClient;
+    PageClientBlackBerry* pageClient;
+    bool blocked;
+};
+
+ChallengeInfo::ChallengeInfo(const KURL& aUrl, const ProtectionSpace& aSpace, const Credential& aCredential,
+    AuthenticationChallengeClient* anAuthClient, PageClientBlackBerry* aPageClient)
+    : url(aUrl)
+    , space(aSpace)
+    , credential(aCredential)
+    , authClient(anAuthClient)
+    , pageClient(aPageClient)
+    , blocked(false)
+{
+}
+
+class AuthenticationChallengeManagerPrivate {
+public:
+    AuthenticationChallengeManagerPrivate();
+
+    bool resumeAuthenticationChallenge(PageClientBlackBerry*);
+    void startAuthenticationChallenge(ChallengeInfo*);
+    bool pageExists(PageClientBlackBerry*);
+
+    ChallengeInfo* m_activeChallenge;
+    PageVisibilityMap m_pageVisibilityMap;
+    Vector<OwnPtr<ChallengeInfo> > m_challenges;
+};
+
+AuthenticationChallengeManagerPrivate::AuthenticationChallengeManagerPrivate()
+    : m_activeChallenge(0)
+{
+}
+
+bool AuthenticationChallengeManagerPrivate::resumeAuthenticationChallenge(PageClientBlackBerry* client)
+{
+    ASSERT(!m_activeChallenge);
+
+    for (size_t i = 0; i < m_challenges.size(); ++i) {
+        if (m_challenges[i]->pageClient == client && m_challenges[i]->blocked) {
+            startAuthenticationChallenge(m_challenges[i].get());
+            return true;
+        }
+    }
+
+    return false;
+}
+
+void AuthenticationChallengeManagerPrivate::startAuthenticationChallenge(ChallengeInfo* info)
+{
+    m_activeChallenge = info;
+    m_activeChallenge->blocked = false;
+    m_activeChallenge->pageClient->authenticationChallenge(m_activeChallenge->url, m_activeChallenge->space, m_activeChallenge->credential);
+}
+
+bool AuthenticationChallengeManagerPrivate::pageExists(PageClientBlackBerry* client)
+{
+    return m_pageVisibilityMap.find(client) != m_pageVisibilityMap.end();
+}
+
+AuthenticationChallengeManager::AuthenticationChallengeManager()
+    : d(adoptPtr(new AuthenticationChallengeManagerPrivate))
+{
+}
+
+void AuthenticationChallengeManager::pageCreated(PageClientBlackBerry* client)
+{
+    d->m_pageVisibilityMap.add(client, true);
+}
+
+void AuthenticationChallengeManager::pageDeleted(PageClientBlackBerry* client)
+{
+    d->m_pageVisibilityMap.remove(client);
+
+    if (d->m_activeChallenge && d->m_activeChallenge->pageClient == client)
+        d->m_activeChallenge = 0;
+
+    Vector<OwnPtr<ChallengeInfo> > existing;
+    d->m_challenges.swap(existing);
+
+    for (size_t i = 0; i < existing.size(); ++i) {
+        if (existing[i]->pageClient != client)
+            d->m_challenges.append(existing[i].release());
+    }
+}
+
+void AuthenticationChallengeManager::pageVisibilityChanged(PageClientBlackBerry* client, bool visible)
+{
+    PageVisibilityMap::iterator iter = d->m_pageVisibilityMap.find(client);
+
+    ASSERT(iter != d->m_pageVisibilityMap.end());
+    if (iter == d->m_pageVisibilityMap.end()) {
+        d->m_pageVisibilityMap.add(client, visible);
+        return;
+    }
+
+    if (iter->second == visible)
+        return;
+
+    iter->second = visible;
+    if (!visible)
+        return;
+
+    if (d->m_activeChallenge)
+        return;
+
+    d->resumeAuthenticationChallenge(client);
+}
+
+void AuthenticationChallengeManager::authenticationChallenge(const KURL& url, const ProtectionSpace& space,
+    const Credential& credential, AuthenticationChallengeClient* authClient, PageClientBlackBerry* pageClient)
+{
+    BLACKBERRY_ASSERT(authClient);
+    BLACKBERRY_ASSERT(pageClient);
+
+    ChallengeInfo* info = new ChallengeInfo(url, space, credential, authClient, pageClient);
+    d->m_challenges.append(adoptPtr(info));
+
+    if (d->m_activeChallenge || !pageClient->isVisible()) {
+        info->blocked = true;
+        return;
+    }
+
+    d->startAuthenticationChallenge(info);
+}
+
+void AuthenticationChallengeManager::cancelAuthenticationChallenge(AuthenticationChallengeClient* client)
+{
+    BLACKBERRY_ASSERT(client);
+
+    if (d->m_activeChallenge && d->m_activeChallenge->authClient == client)
+        d->m_activeChallenge = 0;
+
+    Vector<OwnPtr<ChallengeInfo> > existing;
+    d->m_challenges.swap(existing);
+
+    ChallengeInfo* next = 0;
+    PageClientBlackBerry* page = 0;
+
+    for (size_t i = 0; i < existing.size(); ++i) {
+        if (existing[i]->authClient != client) {
+            if (page && !next && existing[i]->pageClient == page)
+                next = existing[i].get();
+            d->m_challenges.append(existing[i].release());
+        } else if (d->m_activeChallenge == existing[i].get())
+            page = existing[i]->pageClient;
+    }
+
+    if (next)
+        d->startAuthenticationChallenge(next);
+}
+
+void AuthenticationChallengeManager::notifyChallengeResult(const KURL& url, const ProtectionSpace& space,
+    AuthenticationChallengeResult result, const Credential& credential)
+{
+    d->m_activeChallenge = 0;
+
+    Vector<OwnPtr<ChallengeInfo> > existing;
+    d->m_challenges.swap(existing);
+
+    ChallengeInfo* next = 0;
+    PageClientBlackBerry* page = 0;
+
+    for (size_t i = 0; i < existing.size(); ++i) {
+        if (existing[i]->space != space) {
+            if (page && !next && existing[i]->pageClient == page)
+                next = existing[i].get();
+            d->m_challenges.append(existing[i].release());
+        } else {
+            page = existing[i]->pageClient;
+            existing[i]->authClient->notifyChallengeResult(existing[i]->url, space, result, credential);
+
+            // After calling notifyChallengeResult(), page could be destroyed or something.
+            if (!d->pageExists(page) || !page->isVisible())
+                page = 0;
+        }
+    }
+
+    if (next)
+        d->startAuthenticationChallenge(next);
+}
+
+// Keep following code at the end of this file!!!
+static AuthenticationChallengeManager* s_manager = 0;
+
+AuthenticationChallengeManager* AuthenticationChallengeManager::instance()
+{
+    ASSERT(s_manager);
+    return s_manager;
+}
+
+void AuthenticationChallengeManager::init()
+{
+    ASSERT(!s_manager);
+    s_manager = new AuthenticationChallengeManager();
+}
+
+// No more code after this line, all new code should come before s_manager declaration!!!
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/blackberry/AuthenticationChallengeManager.h (131013 => 131014)


--- trunk/Source/WebCore/platform/blackberry/AuthenticationChallengeManager.h	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebCore/platform/blackberry/AuthenticationChallengeManager.h	2012-10-11 04:55:05 UTC (rev 131014)
@@ -19,8 +19,13 @@
 #ifndef AuthenticationChallengeManager_h
 #define AuthenticationChallengeManager_h
 
+#include <wtf/OwnPtr.h>
+
+class PageClientBlackBerry;
+
 namespace WebCore {
 
+class AuthenticationChallengeManagerPrivate;
 class Credential;
 class KURL;
 class ProtectionSpace;
@@ -35,6 +40,27 @@
     virtual void notifyChallengeResult(const KURL&, const ProtectionSpace&, AuthenticationChallengeResult, const Credential&) = 0;
 };
 
+class AuthenticationChallengeManager {
+public:
+    static void init();
+    static AuthenticationChallengeManager* instance();
+
+    void pageCreated(PageClientBlackBerry*);
+    void pageDeleted(PageClientBlackBerry*);
+    void pageVisibilityChanged(PageClientBlackBerry*, bool visible);
+
+    void authenticationChallenge(const KURL&, const ProtectionSpace&, const Credential&, AuthenticationChallengeClient*, PageClientBlackBerry*);
+    void cancelAuthenticationChallenge(AuthenticationChallengeClient*);
+    void notifyChallengeResult(const KURL&, const ProtectionSpace&, AuthenticationChallengeResult, const Credential&);
+
+private:
+    AuthenticationChallengeManager();
+    ~AuthenticationChallengeManager();
+
+    OwnPtr<AuthenticationChallengeManagerPrivate> d;
+};
+
+
 } // namespace WebCore
 
 #endif // AuthenticationChallengeManager_h

Modified: trunk/Source/WebCore/platform/blackberry/PageClientBlackBerry.h (131013 => 131014)


--- trunk/Source/WebCore/platform/blackberry/PageClientBlackBerry.h	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebCore/platform/blackberry/PageClientBlackBerry.h	2012-10-11 04:55:05 UTC (rev 131014)
@@ -72,7 +72,7 @@
     virtual int showAlertDialog(BlackBerry::WebKit::WebPageClient::AlertType) = 0;
     virtual bool isActive() const = 0;
     virtual bool isVisible() const = 0;
-    virtual void authenticationChallenge(const WebCore::KURL&, const WebCore::ProtectionSpace&, const WebCore::Credential&, WebCore::AuthenticationChallengeClient*) = 0;
+    virtual void authenticationChallenge(const WebCore::KURL&, const WebCore::ProtectionSpace&, const WebCore::Credential&) = 0;
     virtual SaveCredentialType notifyShouldSaveCredential(bool) = 0;
     virtual void syncProxyCredential(const WebCore::Credential&) = 0;
 };

Modified: trunk/Source/WebCore/platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.cpp (131013 => 131014)


--- trunk/Source/WebCore/platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.cpp	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebCore/platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.cpp	2012-10-11 04:55:05 UTC (rev 131014)
@@ -21,6 +21,7 @@
 #if ENABLE(VIDEO)
 #include "MediaPlayerPrivateBlackBerry.h"
 
+#include "AuthenticationChallengeManager.h"
 #include "CookieManager.h"
 #include "Credential.h"
 #include "CredentialStorage.h"
@@ -114,6 +115,7 @@
     , m_userDrivenSeekTimer(this, &MediaPlayerPrivate::userDrivenSeekTimerFired)
     , m_lastSeekTime(0)
     , m_lastSeekTimePending(false)
+    , m_isAuthenticationChallenging(false)
     , m_waitMetadataTimer(this, &MediaPlayerPrivate::waitMetadataTimerFired)
     , m_waitMetadataPopDialogCounter(0)
 {
@@ -121,6 +123,9 @@
 
 MediaPlayerPrivate::~MediaPlayerPrivate()
 {
+    if (m_isAuthenticationChallenging)
+        AuthenticationChallengeManager::instance()->cancelAuthenticationChallenge(this);
+
     if (isFullscreen()) {
         m_webCorePlayer->mediaPlayerClient()->mediaPlayerExitFullscreen();
     }
@@ -713,12 +718,18 @@
         return;
     }
 
-    if (frameView() && frameView()->hostWindow())
-        frameView()->hostWindow()->platformPageClient()->authenticationChallenge(url, protectionSpace, credential, this);
+    if (!frameView() || !frameView()->hostWindow())
+        return;
+
+    m_isAuthenticationChallenging = true;
+    AuthenticationChallengeManager::instance()->authenticationChallenge(url, protectionSpace, credential,
+        this, frameView()->hostWindow()->platformPageClient());
 }
 
 void MediaPlayerPrivate::notifyChallengeResult(const KURL& url, const ProtectionSpace& protectionSpace, AuthenticationChallengeResult result, const Credential& credential)
 {
+    m_isAuthenticationChallenging = false;
+
     if (result != AuthenticationChallengeSuccess || !url.isValid())
         return;
 

Modified: trunk/Source/WebCore/platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.h (131013 => 131014)


--- trunk/Source/WebCore/platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.h	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebCore/platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.h	2012-10-11 04:55:05 UTC (rev 131014)
@@ -174,6 +174,7 @@
     Timer<MediaPlayerPrivate> m_userDrivenSeekTimer;
     float m_lastSeekTime;
     bool m_lastSeekTimePending;
+    bool m_isAuthenticationChallenging;
     void waitMetadataTimerFired(Timer<MediaPlayerPrivate>*);
     Timer<MediaPlayerPrivate> m_waitMetadataTimer;
     int m_waitMetadataPopDialogCounter;

Modified: trunk/Source/WebCore/platform/network/blackberry/NetworkJob.cpp (131013 => 131014)


--- trunk/Source/WebCore/platform/network/blackberry/NetworkJob.cpp	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebCore/platform/network/blackberry/NetworkJob.cpp	2012-10-11 04:55:05 UTC (rev 131014)
@@ -19,6 +19,7 @@
 #include "config.h"
 #include "NetworkJob.h"
 
+#include "AuthenticationChallengeManager.h"
 #include "Chrome.h"
 #include "ChromeClient.h"
 #include "CookieManager.h"
@@ -84,9 +85,16 @@
     , m_deferredData(*this)
     , m_deferLoadingCount(0)
     , m_frame(0)
+    , m_isAuthenticationChallenging(false)
 {
 }
 
+NetworkJob::~NetworkJob()
+{
+    if (m_isAuthenticationChallenging)
+        AuthenticationChallengeManager::instance()->cancelAuthenticationChallenge(this);
+}
+
 bool NetworkJob::initialize(int playerId,
                             const String& pageGroupName,
                             const KURL& url,
@@ -197,10 +205,8 @@
 
     m_response.setHTTPStatusText(message);
 
-    if (isUnauthorized(m_extendedStatusCode)) {
+    if (isUnauthorized(m_extendedStatusCode))
         purgeCredentials();
-        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelCritical, "Authentication failed, purge the stored credentials for this site.");
-    }
 }
 
 void NetworkJob::notifyHeadersReceived(BlackBerry::Platform::NetworkRequest::HeaderList& headers)
@@ -478,6 +484,7 @@
 #ifndef NDEBUG
     m_isRunning = false;
 #endif
+
     if (!m_cancelled) {
         if (!m_statusReceived) {
             // Connection failed before sending notifyStatusReceived: use generic NetworkError.
@@ -489,6 +496,7 @@
                 m_extendedStatusCode = BlackBerry::Platform::FilterStream::StatusTooManyRedirects;
 
             sendResponseIfNeeded();
+
             if (isClientAvailable()) {
                 if (isError(status))
                     m_extendedStatusCode = status;
@@ -514,7 +522,7 @@
 
 bool NetworkJob::shouldReleaseClientResource()
 {
-    if ((m_needsRetryAsFTPDirectory && retryAsFTPDirectory()) || (isRedirect(m_extendedStatusCode) && handleRedirect()) || m_newJobWithCredentialsStarted)
+    if ((m_needsRetryAsFTPDirectory && retryAsFTPDirectory()) || (isRedirect(m_extendedStatusCode) && handleRedirect()) || m_newJobWithCredentialsStarted || m_isAuthenticationChallenging)
         return false;
     return true;
 }
@@ -784,8 +792,13 @@
                 return false;
 
             m_handle->getInternal()->m_currentWebChallenge = AuthenticationChallenge();
-            m_frame->page()->chrome()->client()->platformPageClient()->authenticationChallenge(newURL, protectionSpace, Credential(), this);
-            return true;
+
+            m_isAuthenticationChallenging = true;
+            updateDeferLoadingCount(1);
+
+            AuthenticationChallengeManager::instance()->authenticationChallenge(newURL, protectionSpace,
+                Credential(), this, m_frame->page()->chrome()->client()->platformPageClient());
+            return false;
         }
 
         credential = Credential(username, password, CredentialPersistenceForSession);
@@ -846,16 +859,25 @@
 
 void NetworkJob::notifyChallengeResult(const KURL& url, const ProtectionSpace& protectionSpace, AuthenticationChallengeResult result, const Credential& credential)
 {
-    if (result != AuthenticationChallengeSuccess || protectionSpace.host().isEmpty() || !url.isValid()) {
-        m_newJobWithCredentialsStarted = false;
-        return;
+    ASSERT(url.isValid());
+    ASSERT(url == m_response.url());
+    ASSERT(!protectionSpace.host().isEmpty());
+
+    if (m_isAuthenticationChallenging) {
+        m_isAuthenticationChallenging = false;
+        if (result == AuthenticationChallengeSuccess)
+            cancelJob();
+        updateDeferLoadingCount(-1);
     }
 
+    if (result != AuthenticationChallengeSuccess)
+        return;
+
     if (m_handle->getInternal()->m_currentWebChallenge.isNull())
         m_handle->getInternal()->m_currentWebChallenge = AuthenticationChallenge(protectionSpace, credential, 0, m_response, ResourceError());
 
     ResourceRequest newRequest = m_handle->firstRequest();
-    newRequest.setURL(m_response.url());
+    newRequest.setURL(url);
     newRequest.setMustHandleInternally(true);
     m_newJobWithCredentialsStarted = startNewJobWithRequest(newRequest);
 }

Modified: trunk/Source/WebCore/platform/network/blackberry/NetworkJob.h (131013 => 131014)


--- trunk/Source/WebCore/platform/network/blackberry/NetworkJob.h	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebCore/platform/network/blackberry/NetworkJob.h	2012-10-11 04:55:05 UTC (rev 131014)
@@ -29,6 +29,7 @@
 #include <network/FilterStream.h>
 #include <wtf/OwnPtr.h>
 #include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
 #include <wtf/text/WTFString.h>
 
 namespace BlackBerry {
@@ -49,6 +50,8 @@
 class NetworkJob : public AuthenticationChallengeClient, public BlackBerry::Platform::FilterStream {
 public:
     NetworkJob();
+    ~NetworkJob();
+
     bool initialize(int playerId,
                     const String& pageGroupName,
                     const KURL&,
@@ -171,6 +174,8 @@
     DeferredData m_deferredData;
     int m_deferLoadingCount;
     const Frame* m_frame;
+
+    bool m_isAuthenticationChallenging;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit/blackberry/Api/BlackBerryGlobal.cpp (131013 => 131014)


--- trunk/Source/WebKit/blackberry/Api/BlackBerryGlobal.cpp	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebKit/blackberry/Api/BlackBerryGlobal.cpp	2012-10-11 04:55:05 UTC (rev 131014)
@@ -20,6 +20,7 @@
 #include "BlackBerryGlobal.h"
 
 #include "ApplicationCacheStorage.h"
+#include "AuthenticationChallengeManager.h"
 #include "CacheClientBlackBerry.h"
 #include "CookieManager.h"
 #include "CrossOriginPreflightResultCache.h"
@@ -80,6 +81,8 @@
     BlackBerry::Platform::Settings* settings = BlackBerry::Platform::Settings::instance();
 
     ImageSource::setMaxPixelsPerDecodedImage(settings->maxPixelsPerDecodedImage());
+
+    AuthenticationChallengeManager::init();
 }
 
 void collectJavascriptGarbageNow()

Modified: trunk/Source/WebKit/blackberry/Api/WebPage.cpp (131013 => 131014)


--- trunk/Source/WebKit/blackberry/Api/WebPage.cpp	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebKit/blackberry/Api/WebPage.cpp	2012-10-11 04:55:05 UTC (rev 131014)
@@ -434,6 +434,8 @@
         BlackBerry::Platform::DeviceInfo::instance();
         defaultUserAgent();
     }
+
+    AuthenticationChallengeManager::instance()->pageCreated(this);
 }
 
 WebPage::WebPage(WebPageClient* client, const WebString& pageGroupName, const Platform::IntRect& rect)
@@ -445,6 +447,7 @@
 
 WebPagePrivate::~WebPagePrivate()
 {
+    AuthenticationChallengeManager::instance()->pageDeleted(this);
     // Hand the backingstore back to another owner if necessary.
     m_webPage->setVisible(false);
     if (BackingStorePrivate::currentBackingStoreOwner() == m_webPage)
@@ -2185,18 +2188,19 @@
     return m_client->isActive();
 }
 
-void WebPagePrivate::authenticationChallenge(const KURL& url, const ProtectionSpace& protectionSpace, const Credential& inputCredential, AuthenticationChallengeClient* client)
+void WebPagePrivate::authenticationChallenge(const KURL& url, const ProtectionSpace& protectionSpace, const Credential& inputCredential)
 {
     WebString username;
     WebString password;
+    AuthenticationChallengeManager* authmgr = AuthenticationChallengeManager::instance();
 
 #if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
     if (m_dumpRenderTree) {
         Credential credential(inputCredential, inputCredential.persistence());
         if (m_dumpRenderTree->didReceiveAuthenticationChallenge(credential))
-            client->notifyChallengeResult(url, protectionSpace, AuthenticationChallengeSuccess, credential);
+            authmgr->notifyChallengeResult(url, protectionSpace, AuthenticationChallengeSuccess, credential);
         else
-            client->notifyChallengeResult(url, protectionSpace, AuthenticationChallengeCancelled, inputCredential);
+            authmgr->notifyChallengeResult(url, protectionSpace, AuthenticationChallengeCancelled, inputCredential);
         return;
     }
 #endif
@@ -2217,9 +2221,9 @@
 #endif
 
     if (isConfirmed)
-        client->notifyChallengeResult(url, protectionSpace, AuthenticationChallengeSuccess, credential);
+        authmgr->notifyChallengeResult(url, protectionSpace, AuthenticationChallengeSuccess, credential);
     else
-        client->notifyChallengeResult(url, protectionSpace, AuthenticationChallengeCancelled, inputCredential);
+        authmgr->notifyChallengeResult(url, protectionSpace, AuthenticationChallengeCancelled, inputCredential);
 }
 
 PageClientBlackBerry::SaveCredentialType WebPagePrivate::notifyShouldSaveCredential(bool isNew)
@@ -3224,6 +3228,7 @@
         return;
 
     d->setVisible(visible);
+    AuthenticationChallengeManager::instance()->pageVisibilityChanged(d, visible);
 
     if (!visible) {
         d->suspendBackingStore();

Modified: trunk/Source/WebKit/blackberry/Api/WebPage_p.h (131013 => 131014)


--- trunk/Source/WebKit/blackberry/Api/WebPage_p.h	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebKit/blackberry/Api/WebPage_p.h	2012-10-11 04:55:05 UTC (rev 131014)
@@ -201,7 +201,7 @@
     virtual int showAlertDialog(WebPageClient::AlertType atype);
     virtual bool isActive() const;
     virtual bool isVisible() const { return m_visible; }
-    virtual void authenticationChallenge(const WebCore::KURL&, const WebCore::ProtectionSpace&, const WebCore::Credential&, WebCore::AuthenticationChallengeClient*);
+    virtual void authenticationChallenge(const WebCore::KURL&, const WebCore::ProtectionSpace&, const WebCore::Credential&);
     virtual SaveCredentialType notifyShouldSaveCredential(bool);
     virtual void syncProxyCredential(const WebCore::Credential&);
 

Modified: trunk/Source/WebKit/blackberry/ChangeLog (131013 => 131014)


--- trunk/Source/WebKit/blackberry/ChangeLog	2012-10-11 04:49:49 UTC (rev 131013)
+++ trunk/Source/WebKit/blackberry/ChangeLog	2012-10-11 04:55:05 UTC (rev 131014)
@@ -1,3 +1,27 @@
+2012-10-10  Lianghui Chen  <liac...@rim.com>
+
+        [BlackBerry] Fix assertion in NetworkJob::notifyChallengeResult.
+        https://bugs.webkit.org/show_bug.cgi?id=97397
+        Internal PR: 186597.
+
+        Internally reviewed by Yong Li, Joe Mason.
+        Reviewed by George Staikos.
+
+        Update WebPage to use new AuthenticationChallengeManager.
+        Register page creation/deletion and visibility change to the new
+            AuthenticationChallengeManager.
+        Initialize AuthenticationChallengeManager in GlobalInitialize() function.
+
+        * Api/BlackBerryGlobal.cpp:
+        (BlackBerry::WebKit::globalInitialize):
+        * Api/WebPage.cpp:
+        (BlackBerry::WebKit::WebPagePrivate::WebPagePrivate):
+        (BlackBerry::WebKit::WebPagePrivate::~WebPagePrivate):
+        (BlackBerry::WebKit::WebPagePrivate::authenticationChallenge):
+        (BlackBerry::WebKit::WebPage::setVisible):
+        * Api/WebPage_p.h:
+        (WebPagePrivate):
+
 2012-10-10  Andrew Lo  <a...@rim.com>
 
         [BlackBerry] Do not perform backing store blit for animations during one-shot drawing synchronization
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to