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

Side by Side Diff: Source/WebKit/chromium/src/WebSearchableFormData.cpp

Issue 19510005: [oilpan] Completely move HTMLFormControlElement's hierarchy to the managed heap Base URL: svn://svn.chromium.org/blink/branches/oilpan
Patch Set: Created 7 years, 5 months 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 | Annotate | Revision Log
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // There's a button that is already activated for submit, return 0. 92 // There's a button that is already activated for submit, return 0.
93 return 0; 93 return 0;
94 if (!firstSubmitButton && formElement->isSuccessfulSubmitButton()) 94 if (!firstSubmitButton && formElement->isSuccessfulSubmitButton())
95 firstSubmitButton = formElement; 95 firstSubmitButton = formElement;
96 } 96 }
97 return firstSubmitButton; 97 return firstSubmitButton;
98 } 98 }
99 99
100 // Returns true if the selected state of all the options matches the default 100 // Returns true if the selected state of all the options matches the default
101 // selected state. 101 // selected state.
102 bool IsSelectInDefaultState(HTMLSelectElement* select) 102 bool IsSelectInDefaultState(Handle<HTMLSelectElement> select)
103 { 103 {
104 const Vector<HTMLElement*>& listItems = select->listItems(); 104 const Vector<HTMLElement*>& listItems = select->listItems();
105 if (select->multiple() || select->size() > 1) { 105 if (select->multiple() || select->size() > 1) {
106 for (Vector<HTMLElement*>::const_iterator i(listItems.begin()); i != lis tItems.end(); ++i) { 106 for (Vector<HTMLElement*>::const_iterator i(listItems.begin()); i != lis tItems.end(); ++i) {
107 if (!(*i)->hasLocalName(HTMLNames::optionTag)) 107 if (!(*i)->hasLocalName(HTMLNames::optionTag))
108 continue; 108 continue;
109 HTMLOptionElement* optionElement = toHTMLOptionElement(*i); 109 HTMLOptionElement* optionElement = toHTMLOptionElement(*i);
110 if (optionElement->selected() != optionElement->hasAttribute(selecte dAttr)) 110 if (optionElement->selected() != optionElement->hasAttribute(selecte dAttr))
111 return false; 111 return false;
112 } 112 }
(...skipping 15 matching lines...) Expand all
128 if (!initialSelected) 128 if (!initialSelected)
129 initialSelected = optionElement; 129 initialSelected = optionElement;
130 } 130 }
131 return !initialSelected || initialSelected->selected(); 131 return !initialSelected || initialSelected->selected();
132 } 132 }
133 133
134 // Returns true if the form element is in its default state, false otherwise. 134 // Returns true if the form element is in its default state, false otherwise.
135 // The default state is the state of the form element on initial load of the 135 // The default state is the state of the form element on initial load of the
136 // page, and varies depending upon the form element. For example, a checkbox is 136 // page, and varies depending upon the form element. For example, a checkbox is
137 // in its default state if the checked state matches the state of the checked at tribute. 137 // in its default state if the checked state matches the state of the checked at tribute.
138 bool IsInDefaultState(HTMLFormControlElement* formElement) 138 bool IsInDefaultState(Handle<HTMLFormControlElement> formElement)
139 { 139 {
140 if (formElement->hasTagName(HTMLNames::inputTag)) { 140 if (formElement->hasTagName(HTMLNames::inputTag)) {
141 const HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(fo rmElement); 141 Handle<const HTMLInputElement> inputElement = Handle<HTMLInputElement>:: cast(formElement);
142 if (inputElement->isCheckbox() || inputElement->isRadioButton()) 142 if (inputElement->isCheckbox() || inputElement->isRadioButton())
143 return inputElement->checked() == inputElement->hasAttribute(checked Attr); 143 return inputElement->checked() == inputElement->hasAttribute(checked Attr);
144 } else if (formElement->hasTagName(HTMLNames::selectTag)) 144 } else if (formElement->hasTagName(HTMLNames::selectTag))
145 return IsSelectInDefaultState(static_cast<HTMLSelectElement*>(formElemen t)); 145 return IsSelectInDefaultState(Handle<HTMLSelectElement>::cast(formElemen t));
146 return true; 146 return true;
147 } 147 }
148 148
149 // Look for a suitable search text field in a given HTMLFormElement 149 // Look for a suitable search text field in a given HTMLFormElement
150 // Return nothing if one of those items are found: 150 // Return nothing if one of those items are found:
151 // - A text area field 151 // - A text area field
152 // - A file upload field 152 // - A file upload field
153 // - A Password field 153 // - A Password field
154 // - More than one text field 154 // - More than one text field
155 HTMLInputElement* findSuitableSearchInputElement(const HTMLFormElement* form) 155 Result<HTMLInputElement> findSuitableSearchInputElement(const HTMLFormElement* f orm)
156 { 156 {
157 HTMLInputElement* textElement = 0; 157 Handle<HTMLInputElement> textElement;
158 // FIXME: Consider refactoring this code so that we don't call form->associa tedElements() twice. 158 // FIXME: Consider refactoring this code so that we don't call form->associa tedElements() twice.
159 for (Vector<FormAssociatedElement*>::const_iterator i(form->associatedElemen ts().begin()); i != form->associatedElements().end(); ++i) { 159 for (Vector<FormAssociatedElement*>::const_iterator i(form->associatedElemen ts().begin()); i != form->associatedElements().end(); ++i) {
160 if (!(*i)->isFormControlElement()) 160 if (!(*i)->isFormControlElement())
161 continue; 161 continue;
162 162
163 HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement *>(*i); 163 Handle<HTMLFormControlElement> formElement(static_cast<HTMLFormControlEl ement*>(*i));
164 164
165 if (formElement->isDisabledFormControl() || formElement->name().isNull() ) 165 if (formElement->isDisabledFormControl() || formElement->name().isNull() )
166 continue; 166 continue;
167 167
168 if (!IsInDefaultState(formElement) || formElement->hasTagName(HTMLNames: :textareaTag)) 168 if (!IsInDefaultState(formElement) || formElement->hasTagName(HTMLNames: :textareaTag))
169 return 0; 169 return nullptr;
170 170
171 if (formElement->hasTagName(HTMLNames::inputTag) && formElement->willVal idate()) { 171 if (formElement->hasTagName(HTMLNames::inputTag) && formElement->willVal idate()) {
172 const HTMLInputElement* input = static_cast<const HTMLInputElement*> (formElement); 172 Handle<const HTMLInputElement> input = Handle<const HTMLInputElement >::cast(formElement);
173 173
174 // Return nothing if a file upload field or a password field are fou nd. 174 // Return nothing if a file upload field or a password field are fou nd.
175 if (input->isFileUpload() || input->isPasswordField()) 175 if (input->isFileUpload() || input->isPasswordField())
176 return 0; 176 return nullptr;
177 177
178 if (input->isTextField()) { 178 if (input->isTextField()) {
179 if (textElement) { 179 if (textElement) {
180 // The auto-complete bar only knows how to fill in one value . 180 // The auto-complete bar only knows how to fill in one value .
181 // This form has multiple fields; don't treat it as searchab le. 181 // This form has multiple fields; don't treat it as searchab le.
182 return 0; 182 return nullptr;
183 } 183 }
184 textElement = static_cast<HTMLInputElement*>(formElement); 184 textElement = Handle<HTMLInputElement>::cast(formElement);
185 } 185 }
186 } 186 }
187 } 187 }
188 return textElement; 188 return textElement;
189 } 189 }
190 190
191 // Build a search string based on a given HTMLFormElement and HTMLInputElement 191 // Build a search string based on a given HTMLFormElement and HTMLInputElement
192 // 192 //
193 // Search string output example from www.google.com: 193 // Search string output example from www.google.com:
194 // "hl=en&source=hp&biw=1085&bih=854&q={searchTerms}&btnG=Google+Search&aq=f&aqi =&aql=&oq=" 194 // "hl=en&source=hp&biw=1085&bih=854&q={searchTerms}&btnG=Google+Search&aq=f&aqi =&aql=&oq="
195 // 195 //
196 // Return false if the provided HTMLInputElement is not found in the form 196 // Return false if the provided HTMLInputElement is not found in the form
197 bool buildSearchString(const HTMLFormElement* form, Vector<char>* encodedString, TextEncoding* encoding, const HTMLInputElement* textElement) 197 bool buildSearchString(const HTMLFormElement* form, Vector<char>* encodedString, TextEncoding* encoding, Handle<const HTMLInputElement> textElement)
198 { 198 {
199 bool isElementFound = false; 199 bool isElementFound = false;
200 200
201 // FIXME: Consider refactoring this code so that we don't call form->associa tedElements() twice. 201 // FIXME: Consider refactoring this code so that we don't call form->associa tedElements() twice.
202 for (Vector<FormAssociatedElement*>::const_iterator i(form->associatedElemen ts().begin()); i != form->associatedElements().end(); ++i) { 202 for (Vector<FormAssociatedElement*>::const_iterator i(form->associatedElemen ts().begin()); i != form->associatedElements().end(); ++i) {
203 if (!(*i)->isFormControlElement()) 203 if (!(*i)->isFormControlElement())
204 continue; 204 continue;
205 205
206 HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement *>(*i); 206 HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement *>(*i);
207 207
(...skipping 25 matching lines...) Expand all
233 } 233 }
234 return isElementFound; 234 return isElementFound;
235 } 235 }
236 } // namespace 236 } // namespace
237 237
238 namespace WebKit { 238 namespace WebKit {
239 239
240 WebSearchableFormData::WebSearchableFormData(const WebFormElement& form, const W ebInputElement& selectedInputElement) 240 WebSearchableFormData::WebSearchableFormData(const WebFormElement& form, const W ebInputElement& selectedInputElement)
241 { 241 {
242 RefPtr<HTMLFormElement> formElement = form.operator PassRefPtr<HTMLFormEleme nt>(); 242 RefPtr<HTMLFormElement> formElement = form.operator PassRefPtr<HTMLFormEleme nt>();
243 HTMLInputElement* inputElement = selectedInputElement.operator PassRefPtr<HT MLInputElement>().get(); 243 Handle<HTMLInputElement> inputElement = selectedInputElement.operator Handle <HTMLInputElement>();
244 244
245 // Only consider forms that GET data. 245 // Only consider forms that GET data.
246 // Allow HTTPS only when an input element is provided. 246 // Allow HTTPS only when an input element is provided.
247 if (equalIgnoringCase(formElement->getAttribute(methodAttr), "post") 247 if (equalIgnoringCase(formElement->getAttribute(methodAttr), "post")
248 || (!IsHTTPFormSubmit(formElement.get()) && !inputElement)) 248 || (!IsHTTPFormSubmit(formElement.get()) && !inputElement))
249 return; 249 return;
250 250
251 Vector<char> encodedString; 251 Vector<char> encodedString;
252 TextEncoding encoding; 252 TextEncoding encoding;
253 253
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 288
289 String action(formElement->action()); 289 String action(formElement->action());
290 KURL url(formElement->document()->completeURL(action.isNull() ? "" : action) ); 290 KURL url(formElement->document()->completeURL(action.isNull() ? "" : action) );
291 RefPtr<FormData> formData = FormData::create(encodedString); 291 RefPtr<FormData> formData = FormData::create(encodedString);
292 url.setQuery(formData->flattenToString()); 292 url.setQuery(formData->flattenToString());
293 m_url = url; 293 m_url = url;
294 m_encoding = String(encoding.name()); 294 m_encoding = String(encoding.name());
295 } 295 }
296 296
297 } // namespace WebKit 297 } // namespace WebKit
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/src/WebPasswordFormUtils.cpp ('k') | Source/WebKit/chromium/src/WebSelectElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698