Diff
Modified: trunk/Source/WebCore/ChangeLog (116257 => 116258)
--- trunk/Source/WebCore/ChangeLog 2012-05-07 01:41:09 UTC (rev 116257)
+++ trunk/Source/WebCore/ChangeLog 2012-05-07 01:50:45 UTC (rev 116258)
@@ -1,3 +1,48 @@
+2012-05-06 Jonathan Dong <[email protected]>
+
+ [BlackBerry] Autofill backing store implementation upstream
+ https://bugs.webkit.org/show_bug.cgi?id=85575
+
+ Reviewed by Rob Buis.
+
+ Implemented class AutofillBackingStore which is responsible
+ for handling interaction with autofill database.
+
+ Replaced static function
+ CredentialBackingStore* CredentialBackingStore::instance()
+ with a helper function
+ CredentialBackingStore& credentialBackingStore(),
+ and used DEFINE_STATIC_LOCAL to construct the singleton
+ object.
+ Also removed unnecessary function close() and combined with
+ the destructor of class CredentialBackingStore.
+
+ Initial upstream, No new tests.
+
+ * PlatformBlackBerry.cmake:
+ * platform/network/blackberry/AutofillBackingStore.cpp: Added.
+ (WebCore):
+ (WebCore::autofillBackingStore):
+ (WebCore::AutofillBackingStore::AutofillBackingStore):
+ (WebCore::AutofillBackingStore::~AutofillBackingStore):
+ (WebCore::AutofillBackingStore::open):
+ (WebCore::AutofillBackingStore::add):
+ (WebCore::AutofillBackingStore::update):
+ (WebCore::AutofillBackingStore::contains):
+ (WebCore::AutofillBackingStore::get):
+ (WebCore::AutofillBackingStore::clear):
+ * platform/network/blackberry/AutofillBackingStore.h: Added.
+ (WebCore):
+ (AutofillBackingStore):
+ * platform/network/blackberry/CredentialBackingStore.cpp:
+ (WebCore::credentialBackingStore):
+ (WebCore::CredentialBackingStore::~CredentialBackingStore):
+ * platform/network/blackberry/CredentialBackingStore.h:
+ (CredentialBackingStore):
+ (WebCore):
+ * platform/network/blackberry/CredentialStorageBlackBerry.cpp:
+ (WebCore::CredentialStorage::getFromPersistentStorage):
+
2012-05-06 MORITA Hajime <[email protected]>
[Shadow DOM] Node distribution should be refreshed before style recalc.
Modified: trunk/Source/WebCore/PlatformBlackBerry.cmake (116257 => 116258)
--- trunk/Source/WebCore/PlatformBlackBerry.cmake 2012-05-07 01:41:09 UTC (rev 116257)
+++ trunk/Source/WebCore/PlatformBlackBerry.cmake 2012-05-07 01:50:45 UTC (rev 116258)
@@ -90,6 +90,7 @@
LIST(APPEND WebCore_SOURCES
platform/network/MIMESniffing.cpp
platform/network/ProxyServer.cpp
+ platform/network/blackberry/AutofillBackingStore.cpp
platform/network/blackberry/DeferredData.cpp
platform/network/blackberry/NetworkJob.cpp
platform/network/blackberry/NetworkManager.cpp
Added: trunk/Source/WebCore/platform/network/blackberry/AutofillBackingStore.cpp (0 => 116258)
--- trunk/Source/WebCore/platform/network/blackberry/AutofillBackingStore.cpp (rev 0)
+++ trunk/Source/WebCore/platform/network/blackberry/AutofillBackingStore.cpp 2012-05-07 01:50:45 UTC (rev 116258)
@@ -0,0 +1,196 @@
+/*
+ * 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 "AutofillBackingStore.h"
+
+#include "FileSystem.h"
+#include "SQLiteStatement.h"
+#include <BlackBerryPlatformClient.h>
+
+#define HANDLE_SQL_EXEC_FAILURE(statement, returnValue, ...) \
+ if (statement) { \
+ LOG_ERROR(__VA_ARGS__); \
+ return returnValue; \
+ }
+
+namespace WebCore {
+
+AutofillBackingStore& autofillBackingStore()
+{
+ DEFINE_STATIC_LOCAL(AutofillBackingStore, backingStore, ());
+ if (!backingStore.m_database.isOpen())
+ backingStore.open(pathByAppendingComponent(BlackBerry::Platform::Client::get()->getApplicationDataDirectory().c_str(), "/autofill.db"));
+ return backingStore;
+}
+
+AutofillBackingStore::AutofillBackingStore()
+ : m_addStatement(0)
+ , m_updateStatement(0)
+ , m_containsStatement(0)
+ , m_getStatement(0)
+{
+}
+
+AutofillBackingStore::~AutofillBackingStore()
+{
+ delete m_addStatement;
+ m_addStatement = 0;
+ delete m_updateStatement;
+ m_updateStatement = 0;
+ delete m_containsStatement;
+ m_containsStatement = 0;
+ delete m_getStatement;
+ m_getStatement = 0;
+
+ if (m_database.isOpen())
+ m_database.close();
+}
+
+bool AutofillBackingStore::open(const String& dbPath)
+{
+ ASSERT(!m_database.isOpen());
+
+ HANDLE_SQL_EXEC_FAILURE(!m_database.open(dbPath), false,
+ "Failed to open database file %s for autofill database", dbPath.utf8().data());
+
+ if (!m_database.tableExists("autofill")) {
+ HANDLE_SQL_EXEC_FAILURE(!m_database.executeCommand("CREATE TABLE autofill (id INTEGER PRIMARY KEY, name VARCHAR NOT NULL, value VARCHAR NOT NULL, count INTEGER DEFAULT 1)"),
+ false, "Failed to create table autofill for autofill database");
+
+ // Create index for table autofill.
+ HANDLE_SQL_EXEC_FAILURE(!m_database.executeCommand("CREATE INDEX autofill_name ON autofill (name)"),
+ false, "Failed to create autofill_name index for table autofill");
+ }
+
+ // Prepare the statements.
+ m_addStatement = new SQLiteStatement(m_database, "INSERT INTO autofill (name, value) VALUES (?, ?)");
+ HANDLE_SQL_EXEC_FAILURE(m_addStatement->prepare() != SQLResultOk,
+ false, "Failed to prepare add statement");
+
+ m_updateStatement = new SQLiteStatement(m_database, "UPDATE autofill SET count = (SELECT count + 1 from autofill WHERE name = ? AND value = ?) WHERE name = ? AND value = ?");
+ HANDLE_SQL_EXEC_FAILURE(m_updateStatement->prepare() != SQLResultOk,
+ false, "Failed to prepare update statement");
+
+ m_containsStatement = new SQLiteStatement(m_database, "SELECT COUNT(*) FROM autofill WHERE name = ? AND value = ?");
+ HANDLE_SQL_EXEC_FAILURE(m_containsStatement->prepare() != SQLResultOk,
+ false, "Failed to prepare contains statement");
+
+ m_getStatement = new SQLiteStatement(m_database, "SELECT value FROM autofill WHERE name = ? and value like ? ORDER BY count DESC");
+ HANDLE_SQL_EXEC_FAILURE(m_getStatement->prepare() != SQLResultOk,
+ false, "Failed to prepare get statement");
+
+ return true;
+}
+
+bool AutofillBackingStore::add(const String& name, const String& value)
+{
+ if (name.isEmpty() || value.isEmpty())
+ return false;
+
+ ASSERT(m_database.isOpen());
+ ASSERT(m_database.tableExists("autofill"));
+
+ if (contains(name, value))
+ return update(name, value);
+
+ if (!m_addStatement)
+ return false;
+
+ m_addStatement->bindText(1, name);
+ m_addStatement->bindText(2, value);
+
+ int result = m_addStatement->step();
+ m_addStatement->reset();
+ HANDLE_SQL_EXEC_FAILURE(result != SQLResultDone, false,
+ "Failed to add autofill item into table autofill - %i", result);
+
+ return true;
+}
+
+bool AutofillBackingStore::update(const String& name, const String& value)
+{
+ if (!m_updateStatement)
+ return false;
+
+ m_updateStatement->bindText(1, name);
+ m_updateStatement->bindText(2, value);
+ m_updateStatement->bindText(3, name);
+ m_updateStatement->bindText(4, value);
+
+ int result = m_updateStatement->step();
+ m_updateStatement->reset();
+ HANDLE_SQL_EXEC_FAILURE(result != SQLResultDone, false,
+ "Failed to update autofill item in table autofill - %i", result);
+
+ return true;
+}
+
+bool AutofillBackingStore::contains(const String& name, const String& value) const
+{
+ if (!m_containsStatement)
+ return false;
+
+ m_containsStatement->bindText(1, name);
+ m_containsStatement->bindText(2, value);
+
+ int result = m_containsStatement->step();
+ int numberOfRows = m_containsStatement->getColumnInt(0);
+ m_containsStatement->reset();
+ HANDLE_SQL_EXEC_FAILURE(result != SQLResultRow, false,
+ "Failed to execute select autofill item from table autofill in contains - %i", result);
+
+ return numberOfRows;
+}
+
+Vector<String> AutofillBackingStore::get(const String& name, const String& valueHint)
+{
+ ASSERT(m_database.isOpen());
+ ASSERT(m_database.tableExists("autofill"));
+
+ Vector<String> candidates;
+ if (name.isEmpty() || valueHint.isEmpty() || !m_getStatement)
+ return candidates;
+
+ String value = valueHint + "%";
+ m_getStatement->bindText(1, name);
+ m_getStatement->bindText(2, value);
+
+ int result;
+ while ((result = m_getStatement->step()) == SQLResultRow)
+ candidates.append(m_getStatement->getColumnText(0));
+ m_getStatement->reset();
+ HANDLE_SQL_EXEC_FAILURE(result != SQLResultDone, candidates,
+ "Failed to execute select autofill item from table autofill in get - %i", result);
+
+ return candidates;
+}
+
+bool AutofillBackingStore::clear()
+{
+ ASSERT(m_database.isOpen());
+ ASSERT(m_database.tableExists("autofill"));
+
+ HANDLE_SQL_EXEC_FAILURE(!m_database.executeCommand("DELETE FROM autofill"),
+ false, "Failed to clear table autofill");
+
+ return true;
+}
+
+} // namespace WebCore
Added: trunk/Source/WebCore/platform/network/blackberry/AutofillBackingStore.h (0 => 116258)
--- trunk/Source/WebCore/platform/network/blackberry/AutofillBackingStore.h (rev 0)
+++ trunk/Source/WebCore/platform/network/blackberry/AutofillBackingStore.h 2012-05-07 01:50:45 UTC (rev 116258)
@@ -0,0 +1,52 @@
+/*
+ * 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 AutofillBackingStore_h
+#define AutofillBackingStore_h
+
+#include "SQLiteDatabase.h"
+
+namespace WebCore {
+
+class AutofillBackingStore {
+public:
+ friend AutofillBackingStore& autofillBackingStore();
+
+ ~AutofillBackingStore();
+ bool open(const String& dbPath);
+ bool add(const String& name, const String& value);
+ Vector<String> get(const String& name, const String& valueHint);
+ bool clear();
+
+private:
+ AutofillBackingStore();
+ bool update(const String& name, const String& value);
+ bool contains(const String& name, const String& value) const;
+
+ SQLiteDatabase m_database;
+ SQLiteStatement* m_addStatement;
+ SQLiteStatement* m_updateStatement;
+ SQLiteStatement* m_containsStatement;
+ SQLiteStatement* m_getStatement;
+};
+
+AutofillBackingStore& autofillBackingStore();
+
+} // namespace WebCore
+
+#endif // AutofillBackingStore_h
Modified: trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.cpp (116257 => 116258)
--- trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.cpp 2012-05-07 01:41:09 UTC (rev 116257)
+++ trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.cpp 2012-05-07 01:50:45 UTC (rev 116258)
@@ -38,13 +38,11 @@
namespace WebCore {
-CredentialBackingStore* CredentialBackingStore::instance()
+CredentialBackingStore& credentialBackingStore()
{
- static CredentialBackingStore* backingStore = 0;
- if (!backingStore) {
- backingStore = new CredentialBackingStore;
- backingStore->open(pathByAppendingComponent(BlackBerry::Platform::Client::get()->getApplicationDataDirectory().c_str(), "/credentials.db"));
- }
+ DEFINE_STATIC_LOCAL(CredentialBackingStore, backingStore, ());
+ if (!backingStore.m_database.isOpen())
+ backingStore.open(pathByAppendingComponent(BlackBerry::Platform::Client::get()->getApplicationDataDirectory().c_str(), "/credentials.db"));
return backingStore;
}
@@ -64,6 +62,27 @@
CredentialBackingStore::~CredentialBackingStore()
{
+ delete m_addLoginStatement;
+ m_addLoginStatement = 0;
+ delete m_updateLoginStatement;
+ m_updateLoginStatement = 0;
+ delete m_hasLoginStatement;
+ m_hasLoginStatement = 0;
+ delete m_getLoginStatement;
+ m_getLoginStatement = 0;
+ delete m_getLoginByURLStatement;
+ m_getLoginByURLStatement = 0;
+ delete m_removeLoginStatement;
+ m_removeLoginStatement = 0;
+ delete m_addNeverRememberStatement;
+ m_addNeverRememberStatement = 0;
+ delete m_hasNeverRememberStatement;
+ m_hasNeverRememberStatement = 0;
+ delete m_getNeverRememberStatement;
+ m_getNeverRememberStatement = 0;
+ delete m_removeNeverRememberStatement;
+ m_removeNeverRememberStatement = 0;
+
if (m_database.isOpen())
m_database.close();
}
@@ -137,33 +156,6 @@
return true;
}
-void CredentialBackingStore::close()
-{
- delete m_addLoginStatement;
- m_addLoginStatement = 0;
- delete m_updateLoginStatement;
- m_updateLoginStatement = 0;
- delete m_hasLoginStatement;
- m_hasLoginStatement = 0;
- delete m_getLoginStatement;
- m_getLoginStatement = 0;
- delete m_getLoginByURLStatement;
- m_getLoginByURLStatement = 0;
- delete m_removeLoginStatement;
- m_removeLoginStatement = 0;
- delete m_addNeverRememberStatement;
- m_addNeverRememberStatement = 0;
- delete m_hasNeverRememberStatement;
- m_hasNeverRememberStatement = 0;
- delete m_getNeverRememberStatement;
- m_getNeverRememberStatement = 0;
- delete m_removeNeverRememberStatement;
- m_removeNeverRememberStatement = 0;
-
- if (m_database.isOpen())
- m_database.close();
-}
-
bool CredentialBackingStore::addLogin(const KURL& url, const ProtectionSpace& protectionSpace, const Credential& credential)
{
ASSERT(m_database.isOpen());
Modified: trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.h (116257 => 116258)
--- trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.h 2012-05-07 01:41:09 UTC (rev 116257)
+++ trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.h 2012-05-07 01:50:45 UTC (rev 116258)
@@ -31,10 +31,10 @@
class CredentialBackingStore {
public:
- static CredentialBackingStore* instance();
+ friend CredentialBackingStore& credentialBackingStore();
+
~CredentialBackingStore();
bool open(const String& dbPath);
- void close();
bool addLogin(const KURL&, const ProtectionSpace&, const Credential&);
bool updateLogin(const KURL&, const ProtectionSpace&, const Credential&);
bool hasLogin(const KURL&, const ProtectionSpace&);
@@ -66,6 +66,8 @@
SQLiteStatement* m_removeNeverRememberStatement;
};
+CredentialBackingStore& credentialBackingStore();
+
} // namespace WebCore
#endif // ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
Modified: trunk/Source/WebCore/platform/network/blackberry/CredentialStorageBlackBerry.cpp (116257 => 116258)
--- trunk/Source/WebCore/platform/network/blackberry/CredentialStorageBlackBerry.cpp 2012-05-07 01:41:09 UTC (rev 116257)
+++ trunk/Source/WebCore/platform/network/blackberry/CredentialStorageBlackBerry.cpp 2012-05-07 01:50:45 UTC (rev 116258)
@@ -30,7 +30,7 @@
Credential CredentialStorage::getFromPersistentStorage(const ProtectionSpace& protectionSpace)
{
#if ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
- return CredentialBackingStore::instance()->getLogin(protectionSpace);
+ return credentialBackingStore().getLogin(protectionSpace);
#else
UNUSED_PARAM(protectionSpace);
return Credential();
Modified: trunk/Source/WebKit/blackberry/ChangeLog (116257 => 116258)
--- trunk/Source/WebKit/blackberry/ChangeLog 2012-05-07 01:41:09 UTC (rev 116257)
+++ trunk/Source/WebKit/blackberry/ChangeLog 2012-05-07 01:50:45 UTC (rev 116258)
@@ -1,5 +1,22 @@
2012-05-06 Jonathan Dong <[email protected]>
+ [BlackBerry] Autofill backing store implementation upstream
+ https://bugs.webkit.org/show_bug.cgi?id=85575
+
+ Reviewed by Rob Buis.
+
+ Replaced calling static function CredentialBackingStore::instance()
+ with calling the helper function credentialBackingStore().
+
+ * WebCoreSupport/CredentialManager.cpp:
+ (WebCore::CredentialManager::autofillAuthenticationChallenge):
+ (WebCore::CredentialManager::autofillPasswordForms):
+ (WebCore::CredentialManager::saveCredentialIfConfirmed):
+ (WebCore::CredentialManager::clearCredentials):
+ (WebCore::CredentialManager::clearNeverRememberSites):
+
+2012-05-06 Jonathan Dong <[email protected]>
+
[BlackBerry] Enable credential persistance and auto fill
https://bugs.webkit.org/show_bug.cgi?id=85572
Modified: trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialManager.cpp (116257 => 116258)
--- trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialManager.cpp 2012-05-07 01:41:09 UTC (rev 116257)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/CredentialManager.cpp 2012-05-07 01:50:45 UTC (rev 116258)
@@ -43,10 +43,10 @@
void CredentialManager::autofillAuthenticationChallenge(const ProtectionSpace& protectionSpace, WebString& username, WebString& password)
{
- if (CredentialBackingStore::instance()->hasNeverRemember(protectionSpace))
+ if (credentialBackingStore().hasNeverRemember(protectionSpace))
return;
- Credential savedCredential = CredentialBackingStore::instance()->getLogin(protectionSpace);
+ Credential savedCredential = credentialBackingStore().getLogin(protectionSpace);
username = savedCredential.user();
password = savedCredential.password();
}
@@ -61,9 +61,9 @@
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()))
+ if (!data.isValid() || !credentialBackingStore().hasLogin(data.url(), data.protectionSpace()))
continue;
- Credential savedCredential = CredentialBackingStore::instance()->getLogin(data.url());
+ Credential savedCredential = credentialBackingStore().getLogin(data.url());
data.setCredential(savedCredential);
}
}
@@ -73,33 +73,33 @@
{
ASSERT(pageClient);
- if (!data.isValid() || data.credential().isEmpty() || CredentialBackingStore::instance()->hasNeverRemember(data.protectionSpace()))
+ if (!data.isValid() || data.credential().isEmpty() || credentialBackingStore().hasNeverRemember(data.protectionSpace()))
return;
- Credential savedCredential = CredentialBackingStore::instance()->getLogin(data.url());
+ Credential savedCredential = credentialBackingStore().getLogin(data.url());
if (savedCredential == data.credential())
return;
PageClientBlackBerry::SaveCredentialType type = pageClient->notifyShouldSaveCredential(savedCredential.isEmpty());
if (type == PageClientBlackBerry::SaveCredentialYes) {
if (savedCredential.isEmpty())
- CredentialBackingStore::instance()->addLogin(data.url(), data.protectionSpace(), data.credential());
+ credentialBackingStore().addLogin(data.url(), data.protectionSpace(), data.credential());
else
- CredentialBackingStore::instance()->updateLogin(data.url(), data.protectionSpace(), data.credential());
+ credentialBackingStore().updateLogin(data.url(), data.protectionSpace(), data.credential());
} else if (type == PageClientBlackBerry::SaveCredentialNeverForThisSite) {
- CredentialBackingStore::instance()->addNeverRemember(data.url(), data.protectionSpace());
- CredentialBackingStore::instance()->removeLogin(data.url(), data.protectionSpace());
+ credentialBackingStore().addNeverRemember(data.url(), data.protectionSpace());
+ credentialBackingStore().removeLogin(data.url(), data.protectionSpace());
}
}
void CredentialManager::clearCredentials()
{
- CredentialBackingStore::instance()->clearLogins();
+ credentialBackingStore().clearLogins();
}
void CredentialManager::clearNeverRememberSites()
{
- CredentialBackingStore::instance()->clearNeverRemember();
+ credentialBackingStore().clearNeverRemember();
}
} // namespace WebCore