Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(760)

Side by Side Diff: third_party/WebKit/Source/web/WebSearchableFormData.cpp

Issue 2505933005: Auto-Generating Search Engines - Remove HTTP Restriction (Closed)
Patch Set: added test Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/web/tests/WebSearchableFormDataTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 str.split(' ', charsets); 59 str.split(' ', charsets);
60 for (const String& charset : charsets) { 60 for (const String& charset : charsets) {
61 *encoding = WTF::TextEncoding(charset); 61 *encoding = WTF::TextEncoding(charset);
62 if (encoding->isValid()) 62 if (encoding->isValid())
63 return; 63 return;
64 } 64 }
65 if (form.document().loader()) 65 if (form.document().loader())
66 *encoding = WTF::TextEncoding(form.document().encoding()); 66 *encoding = WTF::TextEncoding(form.document().encoding());
67 } 67 }
68 68
69 // Returns true if the submit request results in an HTTP URL.
70 bool isHTTPFormSubmit(const HTMLFormElement& form) {
71 // FIXME: This function is insane. This is an overly complicated way to get
72 // this information.
73 String action(form.action());
74 // The isNull() check is trying to avoid completeURL returning KURL() when
75 // passed a null string.
76 return form.document()
77 .completeURL(action.isNull() ? "" : action)
78 .protocolIs("http");
79 }
80
81 // If the form does not have an activated submit button, the first submit 69 // If the form does not have an activated submit button, the first submit
82 // button is returned. 70 // button is returned.
83 HTMLFormControlElement* buttonToActivate(const HTMLFormElement& form) { 71 HTMLFormControlElement* buttonToActivate(const HTMLFormElement& form) {
84 HTMLFormControlElement* firstSubmitButton = nullptr; 72 HTMLFormControlElement* firstSubmitButton = nullptr;
85 for (auto& element : form.associatedElements()) { 73 for (auto& element : form.associatedElements()) {
86 if (!element->isFormControlElement()) 74 if (!element->isFormControlElement())
87 continue; 75 continue;
88 HTMLFormControlElement* control = toHTMLFormControlElement(element); 76 HTMLFormControlElement* control = toHTMLFormControlElement(element);
89 if (control->isActivatedSubmit()) { 77 if (control->isActivatedSubmit()) {
90 // There's a button that is already activated for submit, return 78 // There's a button that is already activated for submit, return
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } // namespace 216 } // namespace
229 217
230 WebSearchableFormData::WebSearchableFormData( 218 WebSearchableFormData::WebSearchableFormData(
231 const WebFormElement& form, 219 const WebFormElement& form,
232 const WebInputElement& selectedInputElement) { 220 const WebInputElement& selectedInputElement) {
233 HTMLFormElement* formElement = static_cast<HTMLFormElement*>(form); 221 HTMLFormElement* formElement = static_cast<HTMLFormElement*>(form);
234 HTMLInputElement* inputElement = 222 HTMLInputElement* inputElement =
235 static_cast<HTMLInputElement*>(selectedInputElement); 223 static_cast<HTMLInputElement*>(selectedInputElement);
236 224
237 // Only consider forms that GET data. 225 // Only consider forms that GET data.
238 // Allow HTTPS only when an input element is provided. 226 if (equalIgnoringASCIICase(formElement->getAttribute(methodAttr), "post"))
239 if (equalIgnoringASCIICase(formElement->getAttribute(methodAttr), "post") ||
240 (!isHTTPFormSubmit(*formElement) && !inputElement))
241 return; 227 return;
242 228
243 WTF::TextEncoding encoding; 229 WTF::TextEncoding encoding;
244 getFormEncoding(*formElement, &encoding); 230 getFormEncoding(*formElement, &encoding);
245 if (!encoding.isValid()) { 231 if (!encoding.isValid()) {
246 // Need a valid encoding to encode the form elements. 232 // Need a valid encoding to encode the form elements.
247 // If the encoding isn't found webkit ends up replacing the params with 233 // If the encoding isn't found webkit ends up replacing the params with
248 // empty strings. So, we don't try to do anything here. 234 // empty strings. So, we don't try to do anything here.
249 return; 235 return;
250 } 236 }
(...skipping 29 matching lines...) Expand all
280 266
281 String action(formElement->action()); 267 String action(formElement->action());
282 KURL url(formElement->document().completeURL(action.isNull() ? "" : action)); 268 KURL url(formElement->document().completeURL(action.isNull() ? "" : action));
283 RefPtr<EncodedFormData> formData = EncodedFormData::create(encodedString); 269 RefPtr<EncodedFormData> formData = EncodedFormData::create(encodedString);
284 url.setQuery(formData->flattenToString()); 270 url.setQuery(formData->flattenToString());
285 m_url = url; 271 m_url = url;
286 m_encoding = String(encoding.name()); 272 m_encoding = String(encoding.name());
287 } 273 }
288 274
289 } // namespace blink 275 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/web/tests/WebSearchableFormDataTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698