Diff
Modified: trunk/Source/WebKit/ChangeLog (109697 => 109698)
--- trunk/Source/WebKit/ChangeLog 2012-03-05 03:23:58 UTC (rev 109697)
+++ trunk/Source/WebKit/ChangeLog 2012-03-05 03:29:28 UTC (rev 109698)
@@ -1,3 +1,16 @@
+2012-03-04 Jonathan Dong <[email protected]>
+
+ [BlackBerry] upstream CredentialManager and CredentialTransformData implementation
+ https://bugs.webkit.org/show_bug.cgi?id=80107
+
+ Reviewed by Antonio Gomes.
+
+ Initial upstream of CredentialManager.[h|cpp] and
+ CredentialTransformData.[h|cpp].
+ No new test.
+
+ * PlatformBlackBerry.cmake:
+
2012-03-04 Raphael Kubo da Costa <[email protected]>
[CMake] Libraries are installed to /usr/lib and not /usr/lib64 on x86_64
Modified: trunk/Source/WebKit/PlatformBlackBerry.cmake (109697 => 109698)
--- trunk/Source/WebKit/PlatformBlackBerry.cmake 2012-03-05 03:23:58 UTC (rev 109697)
+++ trunk/Source/WebKit/PlatformBlackBerry.cmake 2012-03-05 03:29:28 UTC (rev 109698)
@@ -51,6 +51,8 @@
blackberry/WebCoreSupport/ChromeClientBlackBerry.cpp
blackberry/WebCoreSupport/ClientExtension.cpp
blackberry/WebCoreSupport/ContextMenuClientBlackBerry.cpp
+ blackberry/WebCoreSupport/CredentialManager.cpp
+ blackberry/WebCoreSupport/CredentialTransformData.cpp
blackberry/WebCoreSupport/DeviceMotionClientBlackBerry.cpp
blackberry/WebCoreSupport/DeviceOrientationClientBlackBerry.cpp
blackberry/WebCoreSupport/DragClientBlackBerry.cpp
Modified: trunk/Source/WebKit/blackberry/ChangeLog (109697 => 109698)
--- trunk/Source/WebKit/blackberry/ChangeLog 2012-03-05 03:23:58 UTC (rev 109697)
+++ trunk/Source/WebKit/blackberry/ChangeLog 2012-03-05 03:29:28 UTC (rev 109698)
@@ -1,3 +1,37 @@
+2012-03-04 Jonathan Dong <[email protected]>
+
+ [BlackBerry] upstream CredentialManager and CredentialTransformData implementation
+ https://bugs.webkit.org/show_bug.cgi?id=80107
+
+ Reviewed by Antonio Gomes.
+
+ Initial upstream of CredentialManager.[h|cpp] and
+ CredentialTransformData.[h|cpp].
+ No new test.
+
+ * WebCoreSupport/CredentialManager.cpp: Added.
+ (WebCore):
+ (WebCore::CredentialManager::CredentialManager):
+ (WebCore::CredentialManager::autofillAuthenticationChallenge):
+ (WebCore::CredentialManager::autofillPasswordForms):
+ (WebCore::CredentialManager::saveCredentialIfConfirmed):
+ * WebCoreSupport/CredentialManager.h: Added.
+ (WebKit):
+ (WebCore):
+ (CredentialManager):
+ * WebCoreSupport/CredentialTransformData.cpp: Added.
+ (WebCore::CredentialTransformData::CredentialTransformData):
+ (WebCore):
+ (WebCore::CredentialTransformData::url):
+ (WebCore::CredentialTransformData::credential):
+ (WebCore::CredentialTransformData::setCredential):
+ (WebCore::CredentialTransformData::findPasswordFormFields):
+ * WebCoreSupport/CredentialTransformData.h: Added.
+ (WebCore):
+ (CredentialTransformData):
+ (WebCore::CredentialTransformData::isValid):
+ (WebCore::CredentialTransformData::protectionSpace):
+
2012-03-04 Antonio Gomes <[email protected]>
[BlackBerry] Fixed positioned element not correctly positioned after orientation change, when viewport metatag is used
Added: trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialManager.cpp (0 => 109698)
--- trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialManager.cpp (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialManager.cpp 2012-03-05 03:29:28 UTC (rev 109698)
@@ -0,0 +1,96 @@
+/*
+ * 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"
+
+#if ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
+#include "CredentialManager.h"
+
+#include "CredentialBackingStore.h"
+#include "CredentialTransformData.h"
+#include "FrameLoaderClientBlackBerry.h"
+#include "HTMLFormElement.h"
+#include "KURL.h"
+#include "Logging.h"
+#include "WebPageClient.h"
+#include "WebPage_p.h"
+#include "WebString.h"
+
+using BlackBerry::WebKit::WebPageClient;
+using BlackBerry::WebKit::WebString;
+
+namespace WebCore {
+
+CredentialManager::CredentialManager(FrameLoaderClientBlackBerry* frameLoaderClient)
+ : m_frameLoaderClient(frameLoaderClient)
+{
+ ASSERT(m_frameLoaderClient);
+}
+
+void CredentialManager::autofillAuthenticationChallenge(const ProtectionSpace& protectionSpace, WebString& username, WebString& password)
+{
+ if (CredentialBackingStore::instance()->hasNeverRemember(protectionSpace))
+ return;
+
+ Credential savedCredential = CredentialBackingStore::instance()->getLogin(protectionSpace);
+ username = savedCredential.user();
+ password = savedCredential.password();
+}
+
+void CredentialManager::autofillPasswordForms(PassRefPtr<HTMLCollection> docForms)
+{
+ ASSERT(docForms);
+
+ RefPtr<HTMLCollection> forms = docForms;
+ size_t sourceLength = forms->length();
+ for (size_t i = 0; i < sourceLength; ++i) {
+ Node* node = forms->item(i);
+ if (node && node->isHTMLElement()) {
+ CredentialTransformData data(static_cast<HTMLFormElement*>(node));
+ if (!data.isValid() || !CredentialBackingStore::instance()->hasLogin(data.url(), data.protectionSpace()))
+ continue;
+ Credential savedCredential = CredentialBackingStore::instance()->getLogin(data.url());
+ data.setCredential(savedCredential);
+ }
+ }
+}
+
+void CredentialManager::saveCredentialIfConfirmed(const CredentialTransformData& data)
+{
+ if (!data.isValid() || data.credential().isEmpty() || CredentialBackingStore::instance()->hasNeverRemember(data.protectionSpace()))
+ return;
+
+ Credential savedCredential = CredentialBackingStore::instance()->getLogin(data.url());
+ if (savedCredential == data.credential())
+ return;
+
+ WebPageClient::SaveCredentialType type = m_frameLoaderClient->m_webPagePrivate->m_client->notifyShouldSaveCredential(savedCredential.isEmpty());
+ if (type == WebPageClient::SaveCredentialYes) {
+ if (savedCredential.isEmpty())
+ CredentialBackingStore::instance()->addLogin(data.url(), data.protectionSpace(), data.credential());
+ else
+ CredentialBackingStore::instance()->updateLogin(data.url(), data.protectionSpace(), data.credential());
+ } else if (type == WebPageClient::SaveCredentialNeverForThisSite) {
+ CredentialBackingStore::instance()->addNeverRemember(data.url(), data.protectionSpace());
+ CredentialBackingStore::instance()->removeLogin(data.url(), data.protectionSpace());
+ }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
Added: trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialManager.h (0 => 109698)
--- trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialManager.h (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialManager.h 2012-03-05 03:29:28 UTC (rev 109698)
@@ -0,0 +1,55 @@
+/*
+ * 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
+ */
+
+#ifndef CredentialManager_h
+#define CredentialManager_h
+
+#if ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
+
+#include "HTMLCollection.h"
+#include <wtf/PassRefPtr.h>
+
+namespace BlackBerry {
+namespace WebKit {
+class WebString;
+}
+}
+
+namespace WebCore {
+class FrameLoaderClientBlackBerry;
+class KURL;
+class ProtectionSpace;
+class CredentialTransformData;
+
+class CredentialManager {
+public:
+ CredentialManager(FrameLoaderClientBlackBerry*);
+
+ void autofillAuthenticationChallenge(const ProtectionSpace&, BlackBerry::WebKit::WebString& username, BlackBerry::WebKit::WebString& password);
+ void autofillPasswordForms(PassRefPtr<HTMLCollection> docForms);
+ void saveCredentialIfConfirmed(const CredentialTransformData&);
+
+private:
+ FrameLoaderClientBlackBerry* m_frameLoaderClient;
+};
+
+} // WebCore
+
+#endif // ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
+
+#endif // CredentialManager_h
Added: trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialTransformData.cpp (0 => 109698)
--- trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialTransformData.cpp (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialTransformData.cpp 2012-03-05 03:29:28 UTC (rev 109698)
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /*
+ * This methods are based on Chromium codes in
+ * Source/WebKit/chromium/src/WebPasswordFormUtils.cpp
+ */
+
+#include "config.h"
+#include "CredentialTransformData.h"
+
+#include "HTMLFormElement.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
+#include "KURL.h"
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+namespace {
+// Maximum number of password fields we will observe before throwing our
+// hands in the air and giving up with a given form.
+static const size_t maxPasswords = 3;
+
+// Helper method to clear url of unneeded parts.
+KURL stripURL(const KURL& url)
+{
+ KURL strippedURL = url;
+ strippedURL.setUser(String());
+ strippedURL.setPass(String());
+ strippedURL.setQuery(String());
+ strippedURL.setFragmentIdentifier(String());
+ return strippedURL;
+}
+
+// Helper method to determine which password is the main one, and which is
+// an old password (e.g on a "make new password" form), if any.
+bool locateSpecificPasswords(Vector<HTMLInputElement*>& passwords,
+ HTMLInputElement** password)
+{
+ ASSERT(password);
+
+ switch (passwords.size()) {
+ case 1:
+ // Single password, easy.
+ *password = passwords[0];
+ break;
+ case 2:
+ if (passwords[0]->value() == passwords[1]->value())
+ // Treat two identical passwords as a single password.
+ *password = passwords[0];
+ else {
+ // Assume first is old password, second is new (no choice but to guess).
+ *password = passwords[1];
+ }
+ break;
+ case 3:
+ if (passwords[0]->value() == passwords[1]->value()
+ && passwords[0]->value() == passwords[2]->value()) {
+ // All three passwords the same? Just treat as one and hope.
+ *password = passwords[0];
+ } else if (passwords[0]->value() == passwords[1]->value()) {
+ // Two the same and one different -> old password is duplicated one.
+ *password = passwords[2];
+ } else if (passwords[1]->value() == passwords[2]->value())
+ *password = passwords[1];
+ else {
+ // Three different passwords, or first and last match with middle
+ // different. No idea which is which, so no luck.
+ return false;
+ }
+ break;
+ default:
+ return false;
+ }
+ return true;
+}
+
+} // namespace
+
+CredentialTransformData::CredentialTransformData(HTMLFormElement* form)
+ : m_userNameElement(0)
+ , m_passwordElement(0)
+ , m_isValid(false)
+{
+ ASSERT(form);
+
+ // Get the document URL
+ KURL fullOrigin(ParsedURLString, form->document()->documentURI());
+
+ // Calculate the canonical action URL
+ String action = ""
+ if (action.isNull())
+ action = "" // missing 'action' attribute implies current URL
+ KURL fullAction = form->document()->completeURL(action);
+ if (!fullAction.isValid())
+ return;
+
+ if (!findPasswordFormFields(form))
+ return;
+
+ m_url = stripURL(fullOrigin);
+ m_action = stripURL(fullAction);
+ m_protectionSpace = ProtectionSpace(m_url.host(), m_url.port(), ProtectionSpaceServerHTTP, "Form", ProtectionSpaceAuthenticationSchemeHTMLForm);
+ m_credential = Credential(m_userNameElement->value(), m_passwordElement->value(), CredentialPersistencePermanent);
+
+ m_isValid = true;
+}
+
+CredentialTransformData::CredentialTransformData(const KURL& url, const ProtectionSpace& protectionSpace, const Credential& credential)
+ : m_url(url)
+ , m_protectionSpace(protectionSpace)
+ , m_credential(credential)
+ , m_userNameElement(0)
+ , m_passwordElement(0)
+ , m_isValid(true)
+{
+}
+
+KURL CredentialTransformData::url() const
+{
+ if (!m_isValid)
+ return KURL();
+
+ if (m_protectionSpace.authenticationScheme() == ProtectionSpaceAuthenticationSchemeHTMLForm)
+ return m_action;
+ return m_url;
+}
+
+Credential CredentialTransformData::credential() const
+{
+ if (m_credential.isEmpty() && m_userNameElement && m_passwordElement)
+ return m_credential = Credential(m_userNameElement->value(), m_passwordElement->value(), CredentialPersistencePermanent);
+ return m_credential;
+}
+
+void CredentialTransformData::setCredential(const Credential& credential)
+{
+ if (!m_isValid)
+ return;
+
+ m_credential = credential;
+ m_userNameElement->setValue(credential.user());
+ m_passwordElement->setValue(credential.password());
+}
+
+bool CredentialTransformData::findPasswordFormFields(HTMLFormElement* form)
+{
+ ASSERT(form);
+
+ int firstPasswordIndex = 0;
+ // First, find the password fields and activated submit button.
+ const Vector<FormAssociatedElement*>& formElements = form->associatedElements();
+ Vector<HTMLInputElement*> passwords;
+ for (size_t i = 0; i < formElements.size(); i++) {
+ if (!formElements[i]->isFormControlElement())
+ continue;
+ HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement*>(formElements[i]);
+ if (!formElement->hasLocalName(HTMLNames::inputTag))
+ continue;
+
+ HTMLInputElement* inputElement = formElement->toInputElement();
+ if (!inputElement->isEnabledFormControl())
+ continue;
+
+ if ((passwords.size() < maxPasswords)
+ && inputElement->isPasswordField()
+ && inputElement->shouldAutocomplete()) {
+ if (passwords.isEmpty())
+ firstPasswordIndex = i;
+ passwords.append(inputElement);
+ }
+ }
+
+ if (!passwords.isEmpty()) {
+ // Then, search backwards for the username field.
+ for (int i = firstPasswordIndex - 1; i >= 0; i--) {
+ if (!formElements[i]->isFormControlElement())
+ continue;
+ HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement*>(formElements[i]);
+ if (!formElement->hasLocalName(HTMLNames::inputTag))
+ continue;
+
+ HTMLInputElement* inputElement = formElement->toInputElement();
+ if (!inputElement->isEnabledFormControl())
+ continue;
+
+ // Various input types such as text, url, email can be a username field.
+ if ((inputElement->isTextField() && !inputElement->isPasswordField())
+ && (inputElement->shouldAutocomplete())) {
+ m_userNameElement = inputElement;
+ break;
+ }
+ }
+ }
+ if (!m_userNameElement)
+ return false;
+
+ if (!locateSpecificPasswords(passwords, &(m_passwordElement)))
+ return false;
+ return true;
+}
+
+} // namespace WebCore
Added: trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialTransformData.h (0 => 109698)
--- trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialTransformData.h (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialTransformData.h 2012-03-05 03:29:28 UTC (rev 109698)
@@ -0,0 +1,59 @@
+/*
+ * 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
+ */
+
+#ifndef CredentialTransformData_h
+#define CredentialTransformData_h
+
+#include "Credential.h"
+#include "HTMLFormElement.h"
+#include "KURL.h"
+#include "ProtectionSpace.h"
+
+namespace WebCore {
+
+class HTMLFormElement;
+
+struct CredentialTransformData {
+ // If the provided form is suitable for password completion, isValid() will
+ // return true;
+ CredentialTransformData(HTMLFormElement*);
+ CredentialTransformData(const KURL&, const ProtectionSpace&, const Credential&);
+
+ // If creation failed, return false.
+ bool isValid() const { return m_isValid; }
+
+ KURL url() const;
+ ProtectionSpace protectionSpace() const { return m_protectionSpace; }
+ Credential credential() const;
+ void setCredential(const Credential&);
+
+private:
+ bool findPasswordFormFields(HTMLFormElement*);
+
+ KURL m_url;
+ KURL m_action;
+ ProtectionSpace m_protectionSpace;
+ mutable Credential m_credential;
+ HTMLInputElement* m_userNameElement;
+ HTMLInputElement* m_passwordElement;
+ bool m_isValid;
+};
+
+} // namespace WebCore
+
+#endif