webkitgtk网页密码保存功能实现(应用WebKit-r86000.tar.bz2, http://builds.nightly.webkit.org/files/trunk/src/WebKit-r86000.tar.bz2)
由于客户需要实现浏览器保存网页“登录密码”的功能, 而这功能在webkit中并没有实现,需要自己来实现这个功能,而chromium中实现了该功能,所以仿照chromium的实现来实现webkitgtk保存密码的功能。
1. 所有的登录密码区域的网页源码都是应用form, 所以在浏览器解析完网页后提取form节点, 该节点提取时机在 WebKit-r86000/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp 文件中,下面函数即为操作函数。 如果有本地保存了用户名和密码,比如保存了“https://accounts.google.com/ServiceLogin”页面中的用户名和密码时, 当打开该页面时则自动填写“所保存的用户名和密码”。
void FrameLoaderClient::dispatchDidFinishDocumentLoad()
{
WebKitWebView* webView = getViewFromFrame(m_frame);
g_signal_emit_by_name(webView, "document-load-finished", m_frame);
FormPassword fps; //added by zhenghe
fps.didFinishDocumentLoad(m_frame);
}
2. 在用户点击提交按键时, 需要保存用户填写在form悾件中的用户名和密码,该时机也在 WebKit-r86000/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp 文件中,
void FrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction policyFunction, PassRefPtr<FormState>)
{
// FIXME: This is surely too simple
ASSERT(policyFunction);
if (!policyFunction)
return;
(core(m_frame)->loader()->policyChecker()->*policyFunction)(PolicyUse);
FormPassword fpw; //added by zhenghe
fpw.writePasswordFormFieldsToFile();
}
本补丁只是实现了一个非常简单的保存密码的功能。
不善言辞, 好多都描述不出来,望谅解! 请查看附件源码补丁,如果有错误或者不好的地方,请批评指正, 共同进步,thx!
chromium保存密码功能请看: http://www.szkway.cn/webinfo/GoogleChromeruhebaocunmimakouling.html
下面是补丁文件webkit.patch
diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.cpp WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.cpp
--- tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.cpp 1970-01-01 08:00:00.000000000 +0800
+++ WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.cpp 2011-10-13 14:19:50.000000000 +0800
@@ -0,0 +1,239 @@
+/*
+ * formPassword.cpp
+ * Copyright (C) Zhenghe Zhang 2011 <zhangzhenghe@xxx.com>
+ *
+ * webkit is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * webkit 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "Frame.h"
+#include "Document.h"
+#include "HTMLCollection.h"
+#include "HTMLElement.h"
+#include "HTMLFormElement.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
+#include "webkitwebframe.h"
+#include "webkitwebframeprivate.h"
+
+#include "formPassword.h"
+#include "formPasswordManager.h"
+
+using namespace WebCore;
+
+namespace WebKit{
+
+PasswordFormFields FormPassword::m_pwFormFields;
+PasswordString FormPassword::m_pwForm;
+
+// Helped 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;
+}
+
+bool FormPassword::writePasswordFormFieldsToFile()
+{
+ bool flag = false;
+ FormPasswordManager fpm;
+
+ savePasswordFormFields();
+ clearPasswordFormFields();
+
+ if(fpm.find_form_password_manager_xml(m_pwForm)){
+ printf("username_value = %s, password_value = %s, successfully\n",
+ m_pwForm.username_value.ascii().data(), m_pwForm.password_value.ascii().data());
+ flag = fpm.alter_form_password_manager_xml(m_pwForm);
+ }else{
+ printf("username_value = %s, password_value = %s, successfully\n",
+ m_pwForm.username_value.ascii().data(), m_pwForm.password_value.ascii().data());
+ if(!fpm.form_password_manager_xml_is_exist()){
+ flag = fpm.create_form_password_manager_xml(m_pwForm);
+ }else{
+ flag = fpm.add_form_password_manager_xml(m_pwForm);
+ }
+ }
+
+ return flag;
+}
+
+bool FormPassword::readPasswordFormFieldsFromFile()
+{
+ bool flag = false;
+ FormPasswordManager fpm;
+
+ savePasswordFormFields();
+
+ if(fpm.find_form_password_manager_xml(m_pwForm)){
+ printf("username_value = %s, password_value = %s, successfully\n",
+ m_pwForm.username_value.ascii().data(), m_pwForm.password_value.ascii().data());
+ flag = true;
+ }else
+ printf("failed\n");
+
+ return flag;
+}
+
+void FormPassword::findPasswordFormFields(HTMLFormElement *form)
+{
+ ASSERT(form);
+
+ bool flag = false;
+ size_t firstPasswordIndex = -1;
+
+ // First, find the password fields and activated submit button
+ const Vector<FormAssociatedElement*>& formElements = form->associatedElements();
+ for (size_t i = 0; i < formElements.size(); i++) {
+ if (!formElements[i]->isFormControlElement())
+ continue;
+
+ HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement*>(formElements[i]);
+ if (formElement->isActivatedSubmit())
+ m_pwFormFields.submit = formElement;
+
+ if (!formElement->hasLocalName(HTMLNames::inputTag))
+ continue;
+
+ HTMLInputElement* inputElement = NULL;
+ if (formElement->isHTMLElement()
+ && static_cast<HTMLElement*>(formElement)->hasTagName(HTMLNames::inputTag)) {
+ inputElement = static_cast<HTMLInputElement*>(formElement);
+ }
+
+ if(!inputElement)
+ continue;
+
+ if (!inputElement->isEnabledFormControl())
+ continue;
+
+ if (!flag && inputElement->isPasswordField() && inputElement->autoComplete()) {
+ m_pwFormFields.password = inputElement;
+ firstPasswordIndex = i;
+ flag = true;
+ }
+ }
+ if (m_pwFormFields.password) {
+ // 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 = NULL;
+ if (formElement->isHTMLElement()
+ && static_cast<HTMLElement*>(formElement)->hasTagName(HTMLNames::inputTag)) {
+ inputElement = static_cast<HTMLInputElement*>(formElement);
+ }
+
+ if(!inputElement)
+ continue;
+
+ if (!inputElement->isEnabledFormControl())
+ continue;
+
+ // Various input types such as text, url, email can be a username field.
+ if ((inputElement->isTextField()
+ && !inputElement->isPasswordField()) && (inputElement->autoComplete())) {
+ m_pwFormFields.userName = inputElement;
+ break;
+ }
+ }
+ }
+}
+
+void FormPassword::findPasswordDocumentFields(HTMLFormElement *form)
+{
+ ASSERT(form);
+ findPasswordFormFields(form);
+
+ Frame* frame = form->document()->frame();
+ if (!frame)
+ return;
+
+ // Get the document URL
+ KURL fullOrigin(ParsedURLString, form->document()->documentURI());
+ m_pwFormFields.origin = stripURL(fullOrigin);
+
+ // Calculate the canonical action URL
+ String action = form->action();
+ if (action.isNull())
+ action = ""; // missing 'action' attribute implies current URL
+
+ KURL fullAction = frame->loader()->completeURL(action);
+ if (!fullAction.isValid())
+ return;
+
+ m_pwFormFields.action = stripURL(fullAction);
+}
+
+void FormPassword::didFinishDocumentLoad(WebKitWebFrame* frame){
+ Frame* core_frame = core(frame);
+ Document *core_document = core_frame->document();
+ PassRefPtr<HTMLCollection> forms = core_document->forms();
+ size_t sourceLength = forms->length();
+
+ for (size_t i = 0; i < sourceLength; ++i) {
+ Node *node = forms->item(i);
+ if (node && node->isHTMLElement())
+ findPasswordDocumentFields(static_cast<HTMLFormElement*>(node));
+ }
+
+ if(readPasswordFormFieldsFromFile())
+ fillPasswordFormFields();
+}
+
+void FormPassword::savePasswordFormFields()
+{
+ if(m_pwFormFields.userName){
+ m_pwForm.username_name = m_pwFormFields.userName->name();
+ m_pwForm.username_value = m_pwFormFields.userName->value();
+ }
+
+ if(m_pwFormFields.password){
+ m_pwForm.password_name = m_pwFormFields.password->name();
+ m_pwForm.password_value = m_pwFormFields.password->value();
+ }
+
+ m_pwForm.action = String(m_pwFormFields.action.string());
+ m_pwForm.origin = String(m_pwFormFields.origin.string());
+}
+
+void FormPassword::fillPasswordFormFields()
+{
+ if(m_pwFormFields.userName){
+ m_pwFormFields.userName->setValue(m_pwForm.username_value);
+ }
+
+ if(m_pwFormFields.password){
+ m_pwFormFields.password->setValue(m_pwForm.password_value);
+ }
+}
+
+void FormPassword::clearPasswordFormFields()
+{
+ m_pwFormFields.userName = NULL;
+ m_pwFormFields.password = NULL;
+ m_pwFormFields.submit = NULL;
+}
+
+}//namespace WebKit
+
diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.h WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.h
--- tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.h 1970-01-01 08:00:00.000000000 +0800
+++ WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.h 2011-10-13 14:40:04.000000000 +0800
@@ -0,0 +1,71 @@
+/*
+ * formPassword.h
+ * Copyright (C) Zhenghe Zhang 2011 <zhangzhenghe@xxx.com>
+ *
+ * webkit is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * webkit 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef FORM_PASSWORD_H
+#define FORM_PASSWORD_H
+
+namespace WebCore {
+class HTMLInputElement;
+class HTMLFormControlElement;
+class HTMLFormElement;
+class KURL;
+}
+
+typedef struct _WebKitWebFrame WebKitWebFrame;
+
+namespace WebKit{
+
+struct PasswordString;
+
+struct PasswordFormFields{
+ WebCore::HTMLInputElement* userName;
+ WebCore::HTMLInputElement* password;
+ WebCore::HTMLFormControlElement* submit;
+
+ WebCore::KURL origin;
+ WebCore::KURL action;
+
+ PasswordFormFields() : userName(0), password(0), submit(0) { }
+};
+
+class FormPassword{
+ public:
+ FormPassword() {}
+ ~FormPassword() {}
+
+
+ bool writePasswordFormFieldsToFile();
+ bool readPasswordFormFieldsFromFile();
+
+ void findPasswordFormFields(WebCore::HTMLFormElement* form);
+ void findPasswordDocumentFields(WebCore::HTMLFormElement *form);
+ void didFinishDocumentLoad(WebKitWebFrame* frame);
+
+ void fillPasswordFormFields();
+ void savePasswordFormFields();
+ void clearPasswordFormFields();
+
+ private:
+ static PasswordFormFields m_pwFormFields;
+ static PasswordString m_pwForm;
+};
+
+}//namespace WebKit
+
+#endif //FORM_PASSWORD_H
diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.cpp WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.cpp
--- tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.cpp 1970-01-01 08:00:00.000000000 +0800
+++ WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.cpp 2011-10-13 14:19:05.000000000 +0800
@@ -0,0 +1,326 @@
+/*
+ * formPasswordManager.cpp
+ * Copyright (C) Zhenghe Zhang 2011 <zhangzhenghe@xxx.com>
+ *
+ * webkit is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * webkit 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "formPasswordManager.h"
+
+#include <stdio.h>
+
+
+namespace WebKit{
+
+bool FormPasswordManager::m_first_flag = false;
+const char* FormPasswordManager::m_xml_file = "/tmp/password.txt";
+
+bool FormPasswordManager::create_form_password_manager_xml(PasswordString &pwForm)
+{
+ xmlDocPtr doc;
+ xmlNodePtr node, root_node;
+
+ /*Creates a new document, a node and set it as a root node */
+ doc = xmlNewDoc((const xmlChar*)"1.0");
+ if(!doc)
+ return false;
+
+ root_node = xmlNewNode(NULL, (const xmlChar*)"passwords");
+ xmlDocSetRootElement(doc, root_node);
+
+ /*creates a new node, which is "attached" as child node of root_node node. */
+ node = xmlNewChild(root_node, NULL,
+ (const xmlChar*)"passwordItem", NULL);
+
+ xmlNewChild(node, NULL, (const xmlChar*)"origin",
+ (const xmlChar*)pwForm.origin.ascii().data());
+ xmlNewChild(node, NULL, (const xmlChar*)"action",
+ (const xmlChar*)pwForm.action.ascii().data());
+
+ xmlNewChild(node, NULL, (const xmlChar*)"usernameName",
+ (const xmlChar*)pwForm.username_name.ascii().data());
+ xmlNewChild(node, NULL, (const xmlChar*)"usernameValue",
+ (const xmlChar*)pwForm.username_value.ascii().data());
+
+ xmlNewChild(node, NULL, (const xmlChar*)"passwordName",
+ (const xmlChar*)pwForm.password_name.ascii().data());
+ xmlNewChild(node, NULL, (const xmlChar*)"passwordValue",
+ (const xmlChar*)pwForm.password_value.ascii().data());
+
+ xmlSaveFormatFileEnc(m_xml_file, doc, "UTF-8", 1);
+
+
+ /*free the document */
+ xmlFreeDoc(doc);
+ xmlCleanupParser();
+ xmlMemoryDump();
+
+ return true;
+}
+
+bool FormPasswordManager::find_form_password_manager_xml(PasswordString &pwForm)
+{
+ xmlDocPtr doc;
+ xmlNodePtr cur;
+ bool f_flag = false;
+
+ doc = xmlParseFile(m_xml_file);
+ if(!doc)
+ return false;
+
+ cur = xmlDocGetRootElement(doc);
+ if (!cur) {
+ xmlFreeDoc(doc);
+ return false;
+ }
+
+ if (xmlStrcmp(cur->name, (const xmlChar*)"passwords")){
+ xmlFreeDoc(doc);
+ return false;
+ }
+
+ cur = cur->xmlChildrenNode;
+ while (cur != NULL) {
+ if ((!xmlStrcmp(cur->name, (const xmlChar*)"passwordItem"))){
+ f_flag = parse_form_password_manager_xml(XML_FLAG_FIND, cur, pwForm);
+ if(f_flag)
+ break;
+ }
+ cur = cur->next;
+ }
+
+ xmlFreeDoc(doc);
+ return f_flag;
+}
+
+bool FormPasswordManager::add_form_password_manager_xml(PasswordString &pwForm)
+{
+ xmlDocPtr doc;
+ xmlNodePtr node, add_node;
+ xmlKeepBlanksDefault(0);
+
+ doc = xmlParseFile(m_xml_file);
+ if(!doc)
+ return false;
+
+ node = xmlDocGetRootElement (doc);
+ if(!node){
+ xmlFreeDoc (doc);
+ return false;
+ }
+
+ add_node = xmlNewNode(NULL, (const xmlChar*)"passwordItem");
+ xmlAddChild(node, add_node);
+
+ xmlNewChild(add_node, NULL, (const xmlChar*)"origin",
+ (const xmlChar*)pwForm.origin.ascii().data());
+ xmlNewChild (add_node, NULL, (const xmlChar*)"action",
+ (const xmlChar*)pwForm.action.ascii().data());
+
+ xmlNewChild (add_node, NULL, (const xmlChar*)"usernameName",
+ (const xmlChar*)pwForm.username_name.ascii().data());
+ xmlNewChild (add_node, NULL, (const xmlChar*)"usernameValue",
+ (const xmlChar*)pwForm.username_value.ascii().data());
+
+ xmlNewChild (add_node, NULL, (const xmlChar*)"passwordName",
+ (const xmlChar*)pwForm.password_name.ascii().data());
+ xmlNewChild (add_node, NULL, (const xmlChar*)"passwordValue",
+ (const xmlChar*)pwForm.password_value.ascii().data());
+
+ xmlSaveFormatFileEnc(m_xml_file, doc, (const char *)doc->encoding, 1);
+
+ /* free the document */
+ xmlFreeDoc(doc);
+ xmlCleanupParser();
+ xmlMemoryDump();
+
+ return true;
+}
+
+bool FormPasswordManager::delete_form_password_manager_xml(PasswordString &pwForm)
+{
+ xmlDocPtr doc;
+ xmlNodePtr node, tmpNode;
+ xmlKeepBlanksDefault (0);
+
+ doc = xmlParseFile(m_xml_file);
+ if (!doc)
+ return false;
+
+ node = xmlDocGetRootElement(doc);
+ if(!node){
+ xmlFreeDoc(doc);
+ return false;
+ }
+
+ node = node->xmlChildrenNode;
+ while (node != NULL){
+ tmpNode = node->next;
+ if (!xmlStrcmp(node->name, (const xmlChar*)"passwordItem"))
+ parse_form_password_manager_xml(XML_FLAG_DELETE, node, pwForm);
+
+ node = tmpNode;
+ }
+
+ xmlSaveFormatFileEnc(m_xml_file, doc, (const char*)doc->encoding, 1);
+
+ /* free the document */
+ xmlFreeDoc(doc);
+ xmlCleanupParser();
+ xmlMemoryDump();
+
+ return true;
+}
+
+bool FormPasswordManager::alter_form_password_manager_xml(PasswordString &pwForm)
+{
+ xmlDocPtr doc;
+ xmlNodePtr node, tmpNode;
+
+ xmlKeepBlanksDefault(0);
+
+ doc = xmlParseFile(m_xml_file);
+ if(!doc)
+ return false;
+
+ node = xmlDocGetRootElement(doc);
+ if(!node){
+ xmlFreeDoc(doc);
+ return false;
+ }
+
+ node = node->xmlChildrenNode;
+ while(node != NULL)
+ {
+ tmpNode = node->next;
+ if(!xmlStrcmp(node->name, (const xmlChar*)"passwordItem"))
+ parse_form_password_manager_xml(XML_FLAG_ALTER, node, pwForm);
+
+ node = tmpNode;
+ }
+
+ xmlSaveFormatFileEnc(m_xml_file, doc, (const gchar*)doc->encoding, 1);
+
+ /* free the document */
+ xmlFreeDoc(doc);
+ xmlCleanupParser ();
+ xmlMemoryDump ();
+
+ return 0;
+}
+
+bool FormPasswordManager::form_password_manager_xml_is_exist()
+{
+ if(m_first_flag)
+ return true;
+ else{
+ if(access(m_xml_file, 0) == 0)
+ m_first_flag = true;
+ }
+
+ return m_first_flag;
+}
+
+bool FormPasswordManager::parse_form_password_manager_xml(XML_FLAG flag, xmlNodePtr cur, PasswordString &pwForm)
+{
+ int pwv_cnt = 0;
+ bool p_flag = false;
+ Vector<xmlNodePtr> pwvNode;
+
+ xmlNodePtr tmpNode;
+ xmlNodePtr alterNode;
+ xmlChar *value = NULL;
+
+ alterNode = cur->xmlChildrenNode;
+ while(alterNode != NULL){
+ tmpNode = alterNode->next;
+ if(!xmlStrcmp(alterNode->name, (const xmlChar*)"origin")){
+ value = xmlNodeGetContent(alterNode);
+ if(!xmlStrcmp(value, (const xmlChar*)pwForm.origin.ascii().data())){
+ pwvNode.append(alterNode);
+ ++pwv_cnt;
+ }
+ }else if(!xmlStrcmp(alterNode->name, (const xmlChar*)"action")){
+ value = xmlNodeGetContent(alterNode);
+ if(!xmlStrcmp(value, (const xmlChar*)pwForm.action.ascii().data())){
+ pwvNode.append(alterNode);
+ ++pwv_cnt;
+ }
+ }else if(!xmlStrcmp(alterNode->name, (const xmlChar*)"usernameName")){
+ value = xmlNodeGetContent(alterNode);
+ if(!xmlStrcmp(value, (const xmlChar*)pwForm.username_name.ascii().data())){
+ pwvNode.append(alterNode);
+ ++pwv_cnt;
+ }
+ }else if(!xmlStrcmp(alterNode->name, (const xmlChar*)"usernameValue")){
+ pwvNode.append(alterNode);
+ }else if(!xmlStrcmp(alterNode->name, (const xmlChar*)"passwordName")){
+ value = xmlNodeGetContent(alterNode);
+ if(!xmlStrcmp(value, (const xmlChar*)pwForm.password_name.ascii().data())){
+ pwvNode.append(alterNode);
+ ++pwv_cnt;
+ }
+ }else if(!xmlStrcmp(alterNode->name, (const xmlChar*)"passwordValue")){
+ pwvNode.append(alterNode);
+ }
+ alterNode = tmpNode;
+ }
+
+ if(pwv_cnt == 4){
+ for(int i = 0; i < (int)pwvNode.size(); ++i){
+ if(XML_FLAG_ALTER == flag){
+ if(!xmlStrcmp(pwvNode[i]->name, (const xmlChar*)"usernameValue")){
+ xmlNodeSetContent(pwvNode[i], (const xmlChar*)pwForm.username_value.ascii().data());
+ }else if(!xmlStrcmp(pwvNode[i]->name, (const xmlChar*)"passwordValue")){
+ xmlNodeSetContent(pwvNode[i], (const xmlChar*)pwForm.password_value.ascii().data());
+ }
+
+ p_flag = true;
+ }else if(XML_FLAG_FIND == flag){
+ if(!xmlStrcmp(pwvNode[i]->name, (const xmlChar*)"usernameValue")){
+ p_flag = true;
+ value = xmlNodeGetContent(pwvNode[i]);
+ pwForm.username_value = (const char*)value;
+ xmlFree(value);
+ }else if(!xmlStrcmp(pwvNode[i]->name, (const xmlChar*)"passwordValue")){
+ value = xmlNodeGetContent(pwvNode[i]);
+ pwForm.password_value = (const char*)value;
+ xmlFree(value);
+ }
+ }else if(XML_FLAG_DELETE == flag){
+ xmlUnlinkNode(pwvNode[i]);
+ xmlFreeNode(pwvNode[i]);
+ }
+ }
+
+ if(XML_FLAG_DELETE == flag){
+ xmlUnlinkNode(cur);
+ xmlFreeNode(cur);
+ p_flag = true;
+ }
+ }
+
+ return p_flag;
+}
+
+} //Webkit
+
diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.h WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.h
--- tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.h 1970-01-01 08:00:00.000000000 +0800
+++ WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.h 2011-10-13 14:04:49.000000000 +0800
@@ -0,0 +1,78 @@
+/*
+ * formPasswordManager.h
+ * Copyright (C) Zhenghe Zhang 2011 <zhangzhenghe@xx.com>
+ *
+ * webkit is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * webkit 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PASSWORD_MANAGER_H
+#define PASSWORD_MANAGER_H
+
+#include <wtf/Vector.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/StringBuffer.h>
+#include <wtf/text/WTFString.h>
+
+#include <libxml/xpath.h>
+#include <libxml/parser.h>
+
+
+namespace WebKit
+{
+
+class FormPassword;
+
+struct PasswordString{
+ String username_name;
+ String username_value;
+ String password_name;
+ String password_value;
+
+ String origin;
+ String action;
+};
+
+enum XML_FLAG{
+ XML_FLAG_FIND,
+ XML_FLAG_DELETE,
+ XML_FLAG_ALTER
+};
+
+class FormPasswordManager
+{
+ public:
+ FormPasswordManager() {}
+ ~FormPasswordManager() {}
+
+ bool create_form_password_manager_xml(PasswordString &pwForm);
+ bool find_form_password_manager_xml(PasswordString &pwForm);
+ bool add_form_password_manager_xml(PasswordString &pwForm);
+ bool delete_form_password_manager_xml(PasswordString &pwForm);
+ bool alter_form_password_manager_xml(PasswordString &pwForm);
+
+ bool form_password_manager_xml_is_exist();
+
+ friend class FormPassword;
+
+ private:
+ bool parse_form_password_manager_xml(XML_FLAG flag, xmlNodePtr cur, PasswordString &pwForm);
+
+ static bool m_first_flag;
+ static const char *m_xml_file;
+};
+
+} //WebKit
+
+#endif //PASSWORD_MANAGER_H
+
diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/GNUmakefile.am WebKit-r86000/Source/WebKit/gtk/GNUmakefile.am
--- tmp/WebKit-r86000/Source/WebKit/gtk/GNUmakefile.am 2011-04-29 16:28:44.000000000 +0800
+++ WebKit-r86000/Source/WebKit/gtk/GNUmakefile.am 2011-10-13 14:17:10.000000000 +0800
@@ -48,6 +48,7 @@
-I$(WebCore)/bindings/gobject \
-I$(WebKit) \
-I$(WebKit)/WebCoreSupport \
+ -I$(WebKit)/FormPassword \
-I$(WebKit)/webkit \
-I$(GENSOURCES_WEBKIT) \
-ISource/WebKit/gtk/webkit \
@@ -242,7 +243,11 @@
Source/WebKit/gtk/webkit/webkitwebview.cpp \
Source/WebKit/gtk/webkit/webkitwebviewprivate.h \
Source/WebKit/gtk/webkit/webkitwebwindowfeatures.cpp \
- Source/WebKit/gtk/webkit/webkitwebwindowfeaturesprivate.h
+ Source/WebKit/gtk/webkit/webkitwebwindowfeaturesprivate.h \
+ Source/WebKit/gtk/FormPassword/formPasswordManager.cpp \
+ Source/WebKit/gtk/FormPassword/formPasswordManager.h \
+ Source/WebKit/gtk/FormPassword/formPassword.cpp \
+ Source/WebKit/gtk/FormPassword/formPassword.h
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = \
diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp WebKit-r86000/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
--- tmp/WebKit-r86000/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp 2011-04-29 16:28:44.000000000 +0800
+++ WebKit-r86000/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp 2011-10-13 14:17:10.000000000 +0800
@@ -85,6 +85,7 @@
#include "webkitwebsettingsprivate.h"
#include "webkitwebview.h"
#include "webkitwebviewprivate.h"
+#include "formPassword.h" //added by zhenghe
#include <JavaScriptCore/APICast.h>
#include <gio/gio.h>
#include <glib.h>
@@ -311,6 +312,9 @@
if (!policyFunction)
return;
(core(m_frame)->loader()->policyChecker()->*policyFunction)(PolicyUse);
+
+ FormPassword fpw; //added by zhenghe
+ fpw.writePasswordFormFieldsToFile();
}
void FrameLoaderClient::committedLoad(WebCore::DocumentLoader* loader, const char* data, int length)
@@ -1009,8 +1013,11 @@
void FrameLoaderClient::dispatchDidFinishDocumentLoad()
{
- WebKitWebView* webView = getViewFromFrame(m_frame);
+ WebKitWebView* webView = getViewFromFrame(m_frame); //marked by zhenghe, form password
g_signal_emit_by_name(webView, "document-load-finished", m_frame);
+
+ FormPassword fps; //added by zhenghe
+ fps.didFinishDocumentLoad(m_frame);
}
void FrameLoaderClient::dispatchDidFirstLayout()