webkitgtk密码保存功能简单实现

21 篇文章 1 订阅
6 篇文章 0 订阅

转自 http://blog.csdn.net/zhangzhenghe/article/details/6870288

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


[cpp]  view plain copy
  1. diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.cpp WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.cpp  
  2. --- tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.cpp   1970-01-01 08:00:00.000000000 +0800  
  3. +++ WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.cpp   2011-10-13 14:19:50.000000000 +0800  
  4. @@ -0,0 +1,239 @@  
  5. +/* 
  6. + * formPassword.cpp 
  7. + * Copyright (C) Zhenghe Zhang 2011 <zhangzhenghe@xxx.com> 
  8. + *  
  9. + * webkit is free software: you can redistribute it and/or modify it 
  10. + * under the terms of the GNU General Public License as published by the 
  11. + * Free Software Foundation, either version 3 of the License, or 
  12. + * (at your option) any later version. 
  13. + *  
  14. + * webkit is distributed in the hope that it will be useful, but 
  15. + * WITHOUT ANY WARRANTY; without even the implied warranty of 
  16. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
  17. + * See the GNU General Public License for more details. 
  18. + *  
  19. + * You should have received a copy of the GNU General Public License along 
  20. + * with this program.  If not, see <http://www.gnu.org/licenses/>. 
  21. + */  
  22. +  
  23. +#include "config.h"  
  24. +  
  25. +#include "Frame.h"  
  26. +#include "Document.h"  
  27. +#include "HTMLCollection.h"  
  28. +#include "HTMLElement.h"  
  29. +#include "HTMLFormElement.h"  
  30. +#include "HTMLInputElement.h"  
  31. +#include "HTMLNames.h"  
  32. +#include "webkitwebframe.h"  
  33. +#include "webkitwebframeprivate.h"  
  34. +  
  35. +#include "formPassword.h"  
  36. +#include "formPasswordManager.h"  
  37. +  
  38. +using namespace WebCore;  
  39. +  
  40. +namespace WebKit{  
  41. +  
  42. +PasswordFormFields FormPassword::m_pwFormFields;  
  43. +PasswordString FormPassword::m_pwForm;  
  44. +  
  45. +// Helped method to clear url of unneeded parts.  
  46. +KURL stripURL(const KURL& url)  
  47. +{  
  48. +    KURL strippedURL = url;  
  49. +    strippedURL.setUser(String());  
  50. +    strippedURL.setPass(String());  
  51. +    strippedURL.setQuery(String());  
  52. +    strippedURL.setFragmentIdentifier(String());  
  53. +    return strippedURL;  
  54. +}  
  55. +  
  56. +bool FormPassword::writePasswordFormFieldsToFile()  
  57. +{  
  58. +    bool flag = false;  
  59. +    FormPasswordManager fpm;  
  60. +  
  61. +    savePasswordFormFields();  
  62. +    clearPasswordFormFields();  
  63. +      
  64. +    if(fpm.find_form_password_manager_xml(m_pwForm)){  
  65. +        printf("username_value = %s, password_value = %s, successfully\n",   
  66. +            m_pwForm.username_value.ascii().data(), m_pwForm.password_value.ascii().data());  
  67. +        flag = fpm.alter_form_password_manager_xml(m_pwForm);  
  68. +    }else{  
  69. +        printf("username_value = %s, password_value = %s, successfully\n",   
  70. +            m_pwForm.username_value.ascii().data(), m_pwForm.password_value.ascii().data());  
  71. +        if(!fpm.form_password_manager_xml_is_exist()){  
  72. +            flag = fpm.create_form_password_manager_xml(m_pwForm);  
  73. +        }else{  
  74. +            flag = fpm.add_form_password_manager_xml(m_pwForm);  
  75. +        }  
  76. +    }  
  77. +  
  78. +    return flag;  
  79. +}  
  80. +  
  81. +bool FormPassword::readPasswordFormFieldsFromFile()  
  82. +{  
  83. +    bool flag = false;  
  84. +    FormPasswordManager fpm;  
  85. +  
  86. +    savePasswordFormFields();  
  87. +  
  88. +    if(fpm.find_form_password_manager_xml(m_pwForm)){  
  89. +        printf("username_value = %s, password_value = %s, successfully\n",   
  90. +            m_pwForm.username_value.ascii().data(), m_pwForm.password_value.ascii().data());  
  91. +        flag = true;  
  92. +    }else  
  93. +        printf("failed\n");  
  94. +  
  95. +    return flag;  
  96. +}  
  97. +  
  98. +void FormPassword::findPasswordFormFields(HTMLFormElement *form)  
  99. +{  
  100. +    ASSERT(form);  
  101. +  
  102. +    bool flag = false;  
  103. +    size_t firstPasswordIndex = -1;  
  104. +  
  105. +    // First, find the password fields and activated submit button  
  106. +    const Vector<FormAssociatedElement*>& formElements = form->associatedElements();  
  107. +    for (size_t i = 0; i < formElements.size(); i++) {  
  108. +        if (!formElements[i]->isFormControlElement())  
  109. +            continue;  
  110. +  
  111. +        HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement*>(formElements[i]);  
  112. +        if (formElement->isActivatedSubmit())  
  113. +            m_pwFormFields.submit = formElement;  
  114. +  
  115. +        if (!formElement->hasLocalName(HTMLNames::inputTag))  
  116. +            continue;  
  117. +  
  118. +        HTMLInputElement* inputElement = NULL;  
  119. +        if (formElement->isHTMLElement()  
  120. +            && static_cast<HTMLElement*>(formElement)->hasTagName(HTMLNames::inputTag)) {  
  121. +            inputElement = static_cast<HTMLInputElement*>(formElement);  
  122. +        }  
  123. +  
  124. +        if(!inputElement)  
  125. +            continue;  
  126. +  
  127. +        if (!inputElement->isEnabledFormControl())  
  128. +            continue;  
  129. +  
  130. +        if (!flag && inputElement->isPasswordField() && inputElement->autoComplete()) {  
  131. +            m_pwFormFields.password = inputElement;  
  132. +            firstPasswordIndex = i;  
  133. +            flag = true;  
  134. +        }  
  135. +    }  
  136. +    if (m_pwFormFields.password) {  
  137. +        // Then, search backwards for the username field  
  138. +        for (int i = firstPasswordIndex - 1; i >= 0; i--) {  
  139. +            if (!formElements[i]->isFormControlElement())  
  140. +                continue;  
  141. +            HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement*>(formElements[i]);  
  142. +            if (!formElement->hasLocalName(HTMLNames::inputTag))  
  143. +                continue;  
  144. +  
  145. +            HTMLInputElement* inputElement = NULL;  
  146. +            if (formElement->isHTMLElement()  
  147. +                && static_cast<HTMLElement*>(formElement)->hasTagName(HTMLNames::inputTag)) {  
  148. +                inputElement = static_cast<HTMLInputElement*>(formElement);  
  149. +            }  
  150. +  
  151. +            if(!inputElement)  
  152. +                continue;  
  153. +  
  154. +            if (!inputElement->isEnabledFormControl())  
  155. +                continue;  
  156. +  
  157. +            // Various input types such as text, url, email can be a username field.  
  158. +            if ((inputElement->isTextField()   
  159. +                && !inputElement->isPasswordField()) && (inputElement->autoComplete())) {  
  160. +                m_pwFormFields.userName = inputElement;  
  161. +                break;  
  162. +            }  
  163. +        }  
  164. +    }  
  165. +}  
  166. +  
  167. +void FormPassword::findPasswordDocumentFields(HTMLFormElement *form)  
  168. +{  
  169. +    ASSERT(form);  
  170. +    findPasswordFormFields(form);  
  171. +  
  172. +    Frame* frame = form->document()->frame();  
  173. +    if (!frame)  
  174. +        return;  
  175. +  
  176. +    // Get the document URL  
  177. +    KURL fullOrigin(ParsedURLString, form->document()->documentURI());  
  178. +    m_pwFormFields.origin = stripURL(fullOrigin);  
  179. +  
  180. +    // Calculate the canonical action URL  
  181. +    String action = form->action();  
  182. +    if (action.isNull())  
  183. +        action = ""// missing 'action' attribute implies current URL  
  184. +  
  185. +    KURL fullAction = frame->loader()->completeURL(action);  
  186. +    if (!fullAction.isValid())  
  187. +        return;  
  188. +  
  189. +    m_pwFormFields.action = stripURL(fullAction);  
  190. +}  
  191. +  
  192. +void FormPassword::didFinishDocumentLoad(WebKitWebFrame* frame){  
  193. +    Frame* core_frame = core(frame);  
  194. +    Document *core_document = core_frame->document();  
  195. +    PassRefPtr<HTMLCollection> forms = core_document->forms();  
  196. +    size_t sourceLength = forms->length();  
  197. +  
  198. +    for (size_t i = 0; i < sourceLength; ++i) {  
  199. +        Node *node = forms->item(i);  
  200. +        if (node && node->isHTMLElement())  
  201. +            findPasswordDocumentFields(static_cast<HTMLFormElement*>(node));  
  202. +    }  
  203. +  
  204. +    if(readPasswordFormFieldsFromFile())  
  205. +        fillPasswordFormFields();  
  206. +}  
  207. +  
  208. +void FormPassword::savePasswordFormFields()  
  209. +{  
  210. +    if(m_pwFormFields.userName){  
  211. +        m_pwForm.username_name = m_pwFormFields.userName->name();  
  212. +        m_pwForm.username_value = m_pwFormFields.userName->value();  
  213. +    }  
  214. +  
  215. +    if(m_pwFormFields.password){  
  216. +        m_pwForm.password_name = m_pwFormFields.password->name();  
  217. +        m_pwForm.password_value = m_pwFormFields.password->value();  
  218. +    }  
  219. +  
  220. +    m_pwForm.action = String(m_pwFormFields.action.string());  
  221. +    m_pwForm.origin = String(m_pwFormFields.origin.string());  
  222. +}  
  223. +  
  224. +void FormPassword::fillPasswordFormFields()  
  225. +{  
  226. +    if(m_pwFormFields.userName){  
  227. +        m_pwFormFields.userName->setValue(m_pwForm.username_value);  
  228. +    }  
  229. +  
  230. +    if(m_pwFormFields.password){  
  231. +        m_pwFormFields.password->setValue(m_pwForm.password_value);  
  232. +    }  
  233. +}  
  234. +  
  235. +void FormPassword::clearPasswordFormFields()  
  236. +{  
  237. +    m_pwFormFields.userName = NULL;  
  238. +    m_pwFormFields.password = NULL;  
  239. +    m_pwFormFields.submit = NULL;  
  240. +}  
  241. +  
  242. +}//namespace WebKit  
  243. +  
  244. diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.h WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.h  
  245. --- tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.h 1970-01-01 08:00:00.000000000 +0800  
  246. +++ WebKit-r86000/Source/WebKit/gtk/FormPassword/formPassword.h 2011-10-13 14:40:04.000000000 +0800  
  247. @@ -0,0 +1,71 @@  
  248. +/* 
  249. + * formPassword.h 
  250. + * Copyright (C) Zhenghe Zhang 2011 <zhangzhenghe@xxx.com> 
  251. + *  
  252. + * webkit is free software: you can redistribute it and/or modify it 
  253. + * under the terms of the GNU General Public License as published by the 
  254. + * Free Software Foundation, either version 3 of the License, or 
  255. + * (at your option) any later version. 
  256. + *  
  257. + * webkit is distributed in the hope that it will be useful, but 
  258. + * WITHOUT ANY WARRANTY; without even the implied warranty of 
  259. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
  260. + * See the GNU General Public License for more details. 
  261. + *  
  262. + * You should have received a copy of the GNU General Public License along 
  263. + * with this program.  If not, see <http://www.gnu.org/licenses/>. 
  264. + */  
  265. +  
  266. +  
  267. +#ifndef FORM_PASSWORD_H  
  268. +#define FORM_PASSWORD_H  
  269. +  
  270. +namespace WebCore {  
  271. +class HTMLInputElement;  
  272. +class HTMLFormControlElement;  
  273. +class HTMLFormElement;  
  274. +class KURL;  
  275. +}  
  276. +  
  277. +typedef struct _WebKitWebFrame WebKitWebFrame;  
  278. +  
  279. +namespace WebKit{  
  280. +  
  281. +struct PasswordString;  
  282. +  
  283. +struct PasswordFormFields{  
  284. +    WebCore::HTMLInputElement* userName;  
  285. +    WebCore::HTMLInputElement* password;  
  286. +    WebCore::HTMLFormControlElement* submit;  
  287. +  
  288. +    WebCore::KURL origin;  
  289. +    WebCore::KURL action;  
  290. +  
  291. +    PasswordFormFields() : userName(0), password(0), submit(0) { }              
  292. +};  
  293. +  
  294. +class FormPassword{  
  295. +    public:  
  296. +        FormPassword() {}  
  297. +        ~FormPassword() {}  
  298. +  
  299. +  
  300. +        bool writePasswordFormFieldsToFile();  
  301. +        bool readPasswordFormFieldsFromFile();          
  302. +  
  303. +        void findPasswordFormFields(WebCore::HTMLFormElement* form);  
  304. +        void findPasswordDocumentFields(WebCore::HTMLFormElement *form);  
  305. +        void didFinishDocumentLoad(WebKitWebFrame* frame);  
  306. +  
  307. +        void fillPasswordFormFields();  
  308. +        void savePasswordFormFields();  
  309. +        void clearPasswordFormFields();  
  310. +  
  311. +    private:  
  312. +        static PasswordFormFields m_pwFormFields;  
  313. +        static PasswordString m_pwForm;  
  314. +};  
  315. +  
  316. +}//namespace WebKit  
  317. +  
  318. +#endif  //FORM_PASSWORD_H  
  319. diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.cpp WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.cpp  
  320. --- tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.cpp    1970-01-01 08:00:00.000000000 +0800  
  321. +++ WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.cpp    2011-10-13 14:19:05.000000000 +0800  
  322. @@ -0,0 +1,326 @@  
  323. +/* 
  324. + * formPasswordManager.cpp 
  325. + * Copyright (C) Zhenghe Zhang 2011 <zhangzhenghe@xxx.com> 
  326. + *  
  327. + * webkit is free software: you can redistribute it and/or modify it 
  328. + * under the terms of the GNU General Public License as published by the 
  329. + * Free Software Foundation, either version 3 of the License, or 
  330. + * (at your option) any later version. 
  331. + *  
  332. + * webkit is distributed in the hope that it will be useful, but 
  333. + * WITHOUT ANY WARRANTY; without even the implied warranty of 
  334. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
  335. + * See the GNU General Public License for more details. 
  336. + *  
  337. + * You should have received a copy of the GNU General Public License along 
  338. + * with this program.  If not, see <http://www.gnu.org/licenses/>. 
  339. + */  
  340. +   
  341. +#include "config.h"  
  342. +  
  343. +#include "formPasswordManager.h"  
  344. +  
  345. +#include <stdio.h>  
  346. +  
  347. +  
  348. +namespace WebKit{  
  349. +  
  350. +bool FormPasswordManager::m_first_flag = false;  
  351. +const char* FormPasswordManager::m_xml_file = "/tmp/password.txt";     
  352. +  
  353. +bool FormPasswordManager::create_form_password_manager_xml(PasswordString &pwForm)  
  354. +{  
  355. +    xmlDocPtr doc;  
  356. +    xmlNodePtr node, root_node;  
  357. +  
  358. +    /*Creates a new document, a node and set it as a root node */  
  359. +    doc = xmlNewDoc((const xmlChar*)"1.0");  
  360. +    if(!doc)  
  361. +        return false;  
  362. +  
  363. +    root_node = xmlNewNode(NULL, (const xmlChar*)"passwords");  
  364. +    xmlDocSetRootElement(doc, root_node);  
  365. +  
  366. +    /*creates a new node, which is "attached" as child node of root_node node. */  
  367. +    node = xmlNewChild(root_node, NULL,   
  368. +        (const xmlChar*)"passwordItem", NULL);  
  369. +  
  370. +    xmlNewChild(node, NULL, (const xmlChar*)"origin",  
  371. +        (const xmlChar*)pwForm.origin.ascii().data());  
  372. +    xmlNewChild(node, NULL, (const xmlChar*)"action",  
  373. +        (const xmlChar*)pwForm.action.ascii().data());  
  374. +  
  375. +    xmlNewChild(node, NULL, (const xmlChar*)"usernameName",  
  376. +        (const xmlChar*)pwForm.username_name.ascii().data());  
  377. +    xmlNewChild(node, NULL, (const xmlChar*)"usernameValue",  
  378. +        (const xmlChar*)pwForm.username_value.ascii().data());  
  379. +  
  380. +    xmlNewChild(node, NULL, (const xmlChar*)"passwordName",  
  381. +        (const xmlChar*)pwForm.password_name.ascii().data());  
  382. +    xmlNewChild(node, NULL, (const xmlChar*)"passwordValue",  
  383. +        (const xmlChar*)pwForm.password_value.ascii().data());  
  384. +  
  385. +    xmlSaveFormatFileEnc(m_xml_file, doc, "UTF-8", 1);   
  386. +  
  387. +  
  388. +    /*free the document */  
  389. +    xmlFreeDoc(doc);  
  390. +    xmlCleanupParser();  
  391. +    xmlMemoryDump();  
  392. +      
  393. +    return true;  
  394. +}  
  395. +  
  396. +bool FormPasswordManager::find_form_password_manager_xml(PasswordString &pwForm)  
  397. +{  
  398. +    xmlDocPtr doc;      
  399. +    xmlNodePtr cur;  
  400. +    bool f_flag = false;  
  401. +  
  402. +    doc = xmlParseFile(m_xml_file);  
  403. +    if(!doc)  
  404. +        return false;  
  405. +  
  406. +    cur = xmlDocGetRootElement(doc);  
  407. +    if (!cur) {  
  408. +        xmlFreeDoc(doc);  
  409. +        return false;  
  410. +    }  
  411. +  
  412. +    if (xmlStrcmp(cur->name, (const xmlChar*)"passwords")){  
  413. +        xmlFreeDoc(doc);  
  414. +        return false;  
  415. +    }  
  416. +  
  417. +    cur = cur->xmlChildrenNode;  
  418. +    while (cur != NULL) {  
  419. +        if ((!xmlStrcmp(cur->name, (const xmlChar*)"passwordItem"))){  
  420. +            f_flag = parse_form_password_manager_xml(XML_FLAG_FIND, cur, pwForm);  
  421. +            if(f_flag)  
  422. +                break;  
  423. +        }  
  424. +        cur = cur->next;  
  425. +    }  
  426. +  
  427. +    xmlFreeDoc(doc);  
  428. +    return f_flag;      
  429. +}  
  430. +  
  431. +bool FormPasswordManager::add_form_password_manager_xml(PasswordString &pwForm)  
  432. +{  
  433. +    xmlDocPtr doc;  
  434. +    xmlNodePtr node, add_node;  
  435. +    xmlKeepBlanksDefault(0);  
  436. +      
  437. +    doc = xmlParseFile(m_xml_file);  
  438. +    if(!doc)  
  439. +        return false;   
  440. +      
  441. +    node = xmlDocGetRootElement (doc);  
  442. +    if(!node){  
  443. +        xmlFreeDoc (doc);  
  444. +        return false;   
  445. +    }  
  446. +      
  447. +    add_node = xmlNewNode(NULL, (const xmlChar*)"passwordItem");  
  448. +    xmlAddChild(node, add_node);  
  449. +      
  450. +    xmlNewChild(add_node, NULL, (const xmlChar*)"origin",  
  451. +        (const xmlChar*)pwForm.origin.ascii().data());  
  452. +    xmlNewChild (add_node, NULL, (const xmlChar*)"action",  
  453. +        (const xmlChar*)pwForm.action.ascii().data());  
  454. +  
  455. +    xmlNewChild (add_node, NULL, (const xmlChar*)"usernameName",  
  456. +        (const xmlChar*)pwForm.username_name.ascii().data());  
  457. +    xmlNewChild (add_node, NULL, (const xmlChar*)"usernameValue",  
  458. +        (const xmlChar*)pwForm.username_value.ascii().data());  
  459. +  
  460. +    xmlNewChild (add_node, NULL, (const xmlChar*)"passwordName",  
  461. +        (const xmlChar*)pwForm.password_name.ascii().data());  
  462. +    xmlNewChild (add_node, NULL, (const xmlChar*)"passwordValue",  
  463. +        (const xmlChar*)pwForm.password_value.ascii().data());      
  464. +  
  465. +    xmlSaveFormatFileEnc(m_xml_file, doc, (const char *)doc->encoding, 1);   
  466. +  
  467. +    /* free the document */  
  468. +    xmlFreeDoc(doc);  
  469. +    xmlCleanupParser();  
  470. +    xmlMemoryDump();   
  471. +      
  472. +    return true;  
  473. +}  
  474. +  
  475. +bool FormPasswordManager::delete_form_password_manager_xml(PasswordString &pwForm)  
  476. +{  
  477. +    xmlDocPtr doc;  
  478. +    xmlNodePtr node, tmpNode;  
  479. +    xmlKeepBlanksDefault (0);  
  480. +  
  481. +    doc = xmlParseFile(m_xml_file);  
  482. +    if (!doc)  
  483. +        return false;  
  484. +  
  485. +    node = xmlDocGetRootElement(doc);  
  486. +    if(!node){  
  487. +        xmlFreeDoc(doc);  
  488. +        return false;  
  489. +    }  
  490. +      
  491. +    node = node->xmlChildrenNode;  
  492. +    while (node != NULL){  
  493. +        tmpNode = node->next;  
  494. +        if (!xmlStrcmp(node->name, (const xmlChar*)"passwordItem"))  
  495. +            parse_form_password_manager_xml(XML_FLAG_DELETE, node, pwForm);  
  496. +          
  497. +        node = tmpNode;  
  498. +    }  
  499. +      
  500. +    xmlSaveFormatFileEnc(m_xml_file, doc, (const char*)doc->encoding, 1);  
  501. +  
  502. +    /* free the document */  
  503. +    xmlFreeDoc(doc);  
  504. +    xmlCleanupParser();  
  505. +    xmlMemoryDump();  
  506. +      
  507. +    return true;  
  508. +}  
  509. +  
  510. +bool FormPasswordManager::alter_form_password_manager_xml(PasswordString &pwForm)  
  511. +{  
  512. +    xmlDocPtr doc;  
  513. +    xmlNodePtr node, tmpNode;  
  514. +      
  515. +    xmlKeepBlanksDefault(0);  
  516. +      
  517. +    doc = xmlParseFile(m_xml_file);  
  518. +    if(!doc)  
  519. +        return false;  
  520. +      
  521. +    node = xmlDocGetRootElement(doc);  
  522. +    if(!node){  
  523. +        xmlFreeDoc(doc);  
  524. +        return false;  
  525. +    }  
  526. +      
  527. +    node = node->xmlChildrenNode;  
  528. +    while(node != NULL)  
  529. +    {  
  530. +        tmpNode = node->next;  
  531. +        if(!xmlStrcmp(node->name, (const xmlChar*)"passwordItem"))  
  532. +            parse_form_password_manager_xml(XML_FLAG_ALTER, node, pwForm);  
  533. +          
  534. +        node = tmpNode;  
  535. +    }  
  536. +      
  537. +    xmlSaveFormatFileEnc(m_xml_file, doc, (const gchar*)doc->encoding, 1);  
  538. +  
  539. +    /* free the document */  
  540. +    xmlFreeDoc(doc);  
  541. +    xmlCleanupParser ();  
  542. +    xmlMemoryDump ();  
  543. +  
  544. +    return 0;  
  545. +}  
  546. +  
  547. +bool FormPasswordManager::form_password_manager_xml_is_exist()  
  548. +{  
  549. +    if(m_first_flag)  
  550. +        return true;  
  551. +    else{  
  552. +        if(access(m_xml_file, 0) == 0)  
  553. +            m_first_flag = true;  
  554. +    }  
  555. +  
  556. +    return m_first_flag;  
  557. +}  
  558. +  
  559. +bool FormPasswordManager::parse_form_password_manager_xml(XML_FLAG flag, xmlNodePtr cur, PasswordString &pwForm)  
  560. +{  
  561. +    int pwv_cnt = 0;  
  562. +    bool p_flag = false;  
  563. +    Vector<xmlNodePtr> pwvNode;  
  564. +  
  565. +    xmlNodePtr tmpNode;  
  566. +    xmlNodePtr alterNode;  
  567. +    xmlChar *value = NULL;  
  568. +  
  569. +    alterNode = cur->xmlChildrenNode;  
  570. +    while(alterNode != NULL){  
  571. +        tmpNode = alterNode->next;  
  572. +        if(!xmlStrcmp(alterNode->name, (const xmlChar*)"origin")){  
  573. +            value = xmlNodeGetContent(alterNode);  
  574. +            if(!xmlStrcmp(value, (const xmlChar*)pwForm.origin.ascii().data())){  
  575. +                pwvNode.append(alterNode);  
  576. +                ++pwv_cnt;  
  577. +            }              
  578. +        }else if(!xmlStrcmp(alterNode->name, (const xmlChar*)"action")){  
  579. +            value = xmlNodeGetContent(alterNode);  
  580. +            if(!xmlStrcmp(value, (const xmlChar*)pwForm.action.ascii().data())){  
  581. +                pwvNode.append(alterNode);  
  582. +                ++pwv_cnt;  
  583. +            }              
  584. +        }else if(!xmlStrcmp(alterNode->name, (const xmlChar*)"usernameName")){  
  585. +            value = xmlNodeGetContent(alterNode);  
  586. +            if(!xmlStrcmp(value, (const xmlChar*)pwForm.username_name.ascii().data())){  
  587. +                pwvNode.append(alterNode);  
  588. +                ++pwv_cnt;  
  589. +            }              
  590. +        }else if(!xmlStrcmp(alterNode->name, (const xmlChar*)"usernameValue")){  
  591. +            pwvNode.append(alterNode);       
  592. +        }else if(!xmlStrcmp(alterNode->name, (const xmlChar*)"passwordName")){  
  593. +            value = xmlNodeGetContent(alterNode);  
  594. +            if(!xmlStrcmp(value, (const xmlChar*)pwForm.password_name.ascii().data())){  
  595. +                pwvNode.append(alterNode);  
  596. +                ++pwv_cnt;  
  597. +            }              
  598. +        }else if(!xmlStrcmp(alterNode->name, (const xmlChar*)"passwordValue")){  
  599. +            pwvNode.append(alterNode);  
  600. +        }  
  601. +        alterNode = tmpNode;  
  602. +    }  
  603. +  
  604. +    if(pwv_cnt == 4){  
  605. +        for(int i = 0; i < (int)pwvNode.size(); ++i){  
  606. +            if(XML_FLAG_ALTER == flag){  
  607. +                if(!xmlStrcmp(pwvNode[i]->name, (const xmlChar*)"usernameValue")){  
  608. +                    xmlNodeSetContent(pwvNode[i], (const xmlChar*)pwForm.username_value.ascii().data());                      
  609. +                }else if(!xmlStrcmp(pwvNode[i]->name, (const xmlChar*)"passwordValue")){  
  610. +                    xmlNodeSetContent(pwvNode[i], (const xmlChar*)pwForm.password_value.ascii().data());                      
  611. +                }  
  612. +  
  613. +                p_flag = true;  
  614. +            }else if(XML_FLAG_FIND == flag){  
  615. +                if(!xmlStrcmp(pwvNode[i]->name, (const xmlChar*)"usernameValue")){  
  616. +                    p_flag = true;  
  617. +                    value = xmlNodeGetContent(pwvNode[i]);  
  618. +                    pwForm.username_value = (const char*)value;  
  619. +                    xmlFree(value);  
  620. +                }else if(!xmlStrcmp(pwvNode[i]->name, (const xmlChar*)"passwordValue")){  
  621. +                    value = xmlNodeGetContent(pwvNode[i]);  
  622. +                    pwForm.password_value = (const char*)value;  
  623. +                    xmlFree(value);                 
  624. +                }                  
  625. +            }else if(XML_FLAG_DELETE == flag){  
  626. +                xmlUnlinkNode(pwvNode[i]);  
  627. +                xmlFreeNode(pwvNode[i]);  
  628. +            }              
  629. +        }  
  630. +  
  631. +        if(XML_FLAG_DELETE == flag){             
  632. +            xmlUnlinkNode(cur);  
  633. +            xmlFreeNode(cur);  
  634. +            p_flag = true;  
  635. +        }  
  636. +    }  
  637. +  
  638. +    return p_flag;  
  639. +}  
  640. +  
  641. +} //Webkit  
  642. +   
  643. diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.h WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.h  
  644. --- tmp/WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.h  1970-01-01 08:00:00.000000000 +0800  
  645. +++ WebKit-r86000/Source/WebKit/gtk/FormPassword/formPasswordManager.h  2011-10-13 14:04:49.000000000 +0800  
  646. @@ -0,0 +1,78 @@  
  647. +/* 
  648. + * formPasswordManager.h 
  649. + * Copyright (C) Zhenghe Zhang 2011 <zhangzhenghe@xx.com> 
  650. + *  
  651. + * webkit is free software: you can redistribute it and/or modify it 
  652. + * under the terms of the GNU General Public License as published by the 
  653. + * Free Software Foundation, either version 3 of the License, or 
  654. + * (at your option) any later version. 
  655. + *  
  656. + * webkit is distributed in the hope that it will be useful, but 
  657. + * WITHOUT ANY WARRANTY; without even the implied warranty of 
  658. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
  659. + * See the GNU General Public License for more details. 
  660. + *  
  661. + * You should have received a copy of the GNU General Public License along 
  662. + * with this program.  If not, see <http://www.gnu.org/licenses/>. 
  663. + */  
  664. +  
  665. +#ifndef PASSWORD_MANAGER_H  
  666. +#define PASSWORD_MANAGER_H  
  667. +  
  668. +#include <wtf/Vector.h>  
  669. +#include <wtf/text/CString.h>  
  670. +#include <wtf/text/StringBuffer.h>  
  671. +#include <wtf/text/WTFString.h>  
  672. +  
  673. +#include <libxml/xpath.h>  
  674. +#include <libxml/parser.h>  
  675. +  
  676. +  
  677. +namespace WebKit  
  678. +{  
  679. +  
  680. +class FormPassword;  
  681. +  
  682. +struct PasswordString{  
  683. +    String username_name;  
  684. +    String username_value;  
  685. +    String password_name;  
  686. +    String password_value;  
  687. +  
  688. +    String origin;  
  689. +    String action;  
  690. +};  
  691. +  
  692. +enum XML_FLAG{  
  693. +    XML_FLAG_FIND,   
  694. +    XML_FLAG_DELETE,   
  695. +    XML_FLAG_ALTER  
  696. +};  
  697. +  
  698. +class FormPasswordManager  
  699. +{  
  700. +    public:  
  701. +        FormPasswordManager() {}  
  702. +        ~FormPasswordManager() {}  
  703. +  
  704. +        bool create_form_password_manager_xml(PasswordString &pwForm);  
  705. +        bool find_form_password_manager_xml(PasswordString &pwForm);  
  706. +        bool add_form_password_manager_xml(PasswordString &pwForm);  
  707. +        bool delete_form_password_manager_xml(PasswordString &pwForm);  
  708. +        bool alter_form_password_manager_xml(PasswordString &pwForm);  
  709. +  
  710. +        bool form_password_manager_xml_is_exist();  
  711. +  
  712. +        friend class FormPassword;  
  713. +  
  714. +    private:          
  715. +        bool parse_form_password_manager_xml(XML_FLAG flag, xmlNodePtr cur, PasswordString &pwForm);  
  716. +          
  717. +        static bool m_first_flag;  
  718. +        static const char *m_xml_file;          
  719. +};  
  720. +  
  721. +} //WebKit  
  722. +  
  723. +#endif  //PASSWORD_MANAGER_H  
  724. +  
  725. diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/GNUmakefile.am WebKit-r86000/Source/WebKit/gtk/GNUmakefile.am  
  726. --- tmp/WebKit-r86000/Source/WebKit/gtk/GNUmakefile.am  2011-04-29 16:28:44.000000000 +0800  
  727. +++ WebKit-r86000/Source/WebKit/gtk/GNUmakefile.am  2011-10-13 14:17:10.000000000 +0800  
  728. @@ -48,6 +48,7 @@  
  729.     -I$(WebCore)/bindings/gobject \  
  730.     -I$(WebKit) \  
  731.     -I$(WebKit)/WebCoreSupport \  
  732. +    -I$(WebKit)/FormPassword \  
  733.     -I$(WebKit)/webkit \  
  734.     -I$(GENSOURCES_WEBKIT) \  
  735.     -ISource/WebKit/gtk/webkit \  
  736. @@ -242,7 +243,11 @@  
  737.     Source/WebKit/gtk/webkit/webkitwebview.cpp \  
  738.     Source/WebKit/gtk/webkit/webkitwebviewprivate.h \  
  739.     Source/WebKit/gtk/webkit/webkitwebwindowfeatures.cpp \  
  740. -   Source/WebKit/gtk/webkit/webkitwebwindowfeaturesprivate.h  
  741. +   Source/WebKit/gtk/webkit/webkitwebwindowfeaturesprivate.h \  
  742. +    Source/WebKit/gtk/FormPassword/formPasswordManager.cpp \  
  743. +    Source/WebKit/gtk/FormPassword/formPasswordManager.h \  
  744. +    Source/WebKit/gtk/FormPassword/formPassword.cpp \  
  745. +    Source/WebKit/gtk/FormPassword/formPassword.h   
  746.    
  747.  pkgconfigdir = $(libdir)/pkgconfig  
  748.  pkgconfig_DATA = \  
  749. diff -Nur tmp/WebKit-r86000/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp WebKit-r86000/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp  
  750. --- tmp/WebKit-r86000/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp    2011-04-29 16:28:44.000000000 +0800  
  751. +++ WebKit-r86000/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp 2011-10-13 14:17:10.000000000 +0800  
  752. @@ -85,6 +85,7 @@  
  753.  #include "webkitwebsettingsprivate.h"  
  754.  #include "webkitwebview.h"  
  755.  #include "webkitwebviewprivate.h"  
  756. +#include "formPassword.h" //added by zhenghe  
  757.  #include <JavaScriptCore/APICast.h>  
  758.  #include <gio/gio.h>  
  759.  #include <glib.h>  
  760. @@ -311,6 +312,9 @@  
  761.      if (!policyFunction)  
  762.          return;  
  763.      (core(m_frame)->loader()->policyChecker()->*policyFunction)(PolicyUse);  
  764. +  
  765. +    FormPassword fpw; //added by zhenghe  
  766. +    fpw.writePasswordFormFieldsToFile();  
  767.  }  
  768.    
  769.  void FrameLoaderClient::committedLoad(WebCore::DocumentLoader* loader, const char* data, int length)  
  770. @@ -1009,8 +1013,11 @@  
  771.    
  772.  void FrameLoaderClient::dispatchDidFinishDocumentLoad()  
  773.  {  
  774. -    WebKitWebView* webView = getViewFromFrame(m_frame);  
  775. +    WebKitWebView* webView = getViewFromFrame(m_frame); //marked by zhenghe, form password  
  776.      g_signal_emit_by_name(webView, "document-load-finished", m_frame);  
  777. +  
  778. +    FormPassword fps; //added by zhenghe  
  779. +    fps.didFinishDocumentLoad(m_frame);  
  780.  }  
  781.    
  782.  void FrameLoaderClient::dispatchDidFirstLayout()  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值