summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorjdomingos@chromium.org <jdomingos@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 21:19:41 +0000
committerjdomingos@chromium.org <jdomingos@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 21:19:41 +0000
commitb9304c64bdc1f43f13c2f167e7c1a84459e2be3e (patch)
treedc049b21f29a8609cdf590db2457bb8f6f7bcccc /components
parent3b4155cc075e3f83d25d4170d0a530c6b92784ca (diff)
downloadchromium_src-b9304c64bdc1f43f13c2f167e7c1a84459e2be3e.zip
chromium_src-b9304c64bdc1f43f13c2f167e7c1a84459e2be3e.tar.gz
chromium_src-b9304c64bdc1f43f13c2f167e7c1a84459e2be3e.tar.bz2
"Do you want Google Chrome to remember this password?" bar disappears quickly due to fast redirected. The bar also sometimes appears when it shouldn't because we were not taking the good page in consideration.
This Cl ignore the redirection pages by checking the content of the head and the body for the webpage BUG=26186 Review URL: https://chromiumcodereview.appspot.com/21055012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222346 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/autofill/content/renderer/form_autofill_util.cc52
-rw-r--r--components/autofill/content/renderer/form_autofill_util.h17
-rw-r--r--components/autofill/content/renderer/password_autofill_agent.cc6
3 files changed, 74 insertions, 1 deletions
diff --git a/components/autofill/content/renderer/form_autofill_util.cc b/components/autofill/content/renderer/form_autofill_util.cc
index 69ab4c9..1a694f32 100644
--- a/components/autofill/content/renderer/form_autofill_util.cc
+++ b/components/autofill/content/renderer/form_autofill_util.cc
@@ -79,7 +79,7 @@ bool IsNoScriptElement(const WebElement& element) {
}
bool HasTagName(const WebNode& node, const WebKit::WebString& tag) {
- return node.isElementNode() && node.toConst<WebElement>().hasTagName(tag);
+ return node.isElementNode() && node.toConst<WebElement>().hasHTMLTagName(tag);
}
bool IsAutofillableElement(const WebFormControlElement& element) {
@@ -1076,4 +1076,54 @@ bool FormWithElementIsAutofilled(const WebInputElement& element) {
return false;
}
+bool IsWebpageEmpty(const WebKit::WebFrame* frame) {
+ WebKit::WebDocument document = frame->document();
+
+ return IsWebElementEmpty(document.head()) &&
+ IsWebElementEmpty(document.body());
+}
+
+bool IsWebElementEmpty(const WebKit::WebElement& element) {
+ // This array contains all tags which can be present in an empty page.
+ const char* const kAllowedValue[] = {
+ "script",
+ "meta",
+ "title",
+ };
+ const size_t kAllowedValueLength = arraysize(kAllowedValue);
+
+ if (element.isNull())
+ return true;
+ // The childNodes method is not a const method. Therefore it cannot be called
+ // on a const reference. Therefore we need a const cast.
+ const WebKit::WebNodeList& children =
+ const_cast<WebKit::WebElement&>(element).childNodes();
+ for (size_t i = 0; i < children.length(); ++i) {
+ const WebKit::WebNode& item = children.item(i);
+
+ if (item.isTextNode() &&
+ !ContainsOnlyWhitespaceASCII(item.nodeValue().utf8()))
+ return false;
+
+ // We ignore all other items with names which begin with
+ // the character # because they are not html tags.
+ if (item.nodeName().utf8()[0] == '#')
+ continue;
+
+ bool tag_is_allowed = false;
+ // Test if the item name is in the kAllowedValue array
+ for (size_t allowed_value_index = 0;
+ allowed_value_index < kAllowedValueLength; ++allowed_value_index) {
+ if (HasTagName(item,
+ WebString::fromUTF8(kAllowedValue[allowed_value_index]))) {
+ tag_is_allowed = true;
+ break;
+ }
+ }
+ if (!tag_is_allowed)
+ return false;
+ }
+ return true;
+}
+
} // namespace autofill
diff --git a/components/autofill/content/renderer/form_autofill_util.h b/components/autofill/content/renderer/form_autofill_util.h
index 3f2bac9..8c109c4 100644
--- a/components/autofill/content/renderer/form_autofill_util.h
+++ b/components/autofill/content/renderer/form_autofill_util.h
@@ -11,8 +11,10 @@
namespace WebKit {
class WebDocument;
+class WebElement;
class WebFormElement;
class WebFormControlElement;
+class WebFrame;
class WebInputElement;
class WebNode;
}
@@ -144,6 +146,21 @@ bool ClearPreviewedFormWithElement(const WebKit::WebInputElement& element,
// Returns true if |form| has any auto-filled fields.
bool FormWithElementIsAutofilled(const WebKit::WebInputElement& element);
+// Checks if the webpage is empty.
+// This kind of webpage is considered as empty:
+// <html>
+// <head>
+// <head/>
+// <body>
+// <body/>
+// <html/>
+// Meta, script and title tags don't influence the emptiness of a webpage.
+bool IsWebpageEmpty(const WebKit::WebFrame* frame);
+
+// This function checks whether the children of |element|
+// are of the type <script>, <meta>, or <title>.
+bool IsWebElementEmpty(const WebKit::WebElement& element);
+
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_AUTOFILL_UTIL_H_
diff --git a/components/autofill/content/renderer/password_autofill_agent.cc b/components/autofill/content/renderer/password_autofill_agent.cc
index d9a12cd..f39669e 100644
--- a/components/autofill/content/renderer/password_autofill_agent.cc
+++ b/components/autofill/content/renderer/password_autofill_agent.cc
@@ -23,6 +23,8 @@
#include "third_party/WebKit/public/web/WebFormElement.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
+#include "third_party/WebKit/public/web/WebNode.h"
+#include "third_party/WebKit/public/web/WebNodeList.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
#include "third_party/WebKit/public/web/WebView.h"
@@ -361,6 +363,10 @@ void PasswordAutofillAgent::SendPasswordForms(WebKit::WebFrame* frame,
if (!OriginCanAccessPasswordManager(origin))
return;
+ // Checks whether the webpage is a redirect page or an empty page.
+ if (IsWebpageEmpty(frame))
+ return;
+
WebKit::WebVector<WebKit::WebFormElement> forms;
frame->document().forms(forms);