string16 ResourceBundle::GetLocalizedString(int message_id) { // 如果没有本地纯资源DLL, 返回一个空字符串(比崩溃好). if(!locale_resources_data_) { base::StackTrace().PrintBacktrace(); // See http://crbug.com/21925. LOG(WARNING) << "locale resources are not loaded"; return string16(); } DCHECK(IS_INTRESOURCE(message_id)); // Get a reference directly to the string resource. HINSTANCE hinstance = locale_resources_data_; const STRINGRESOURCEIMAGE* image = GetStringResourceImage(hinstance, message_id); if(!image) { base::StackTrace().PrintBacktrace(); // See http://crbug.com/21925. NOTREACHED() << "unable to find resource: " << message_id; return std::wstring(); } // Copy into a string16 and return. return string16(image->achString, image->nLength); }
string16 jstringToString16(JNIEnv* env, jstring jstr) { if (!jstr || !env) return string16(); const char* s = env->GetStringUTFChars(jstr, 0); if (!s) return string16(); string16 str = UTF8ToUTF16(s); env->ReleaseStringUTFChars(jstr, s); checkException(env); return str; }
void WebAutofill::formFieldFocused(WebCore::HTMLFormControlElement* formFieldElement) { if (!enabled()) { // In case that we've just been disabled and the last time we got autofill // suggestions we told Java about them, clear that bit Java side now // we're disabled. mWebViewCore->setWebTextViewAutoFillable(FORM_NOT_AUTOFILLABLE, string16()); return; } ASSERT(formFieldElement); Document* doc = formFieldElement->document(); Frame* frame = doc->frame(); // FIXME: Autofill only works in main frame for now. Should consider // child frames. if (frame != frame->page()->mainFrame()) return; unsigned domVersion = doc->domTreeVersion(); ASSERT(domVersion > 0); if (mLastSearchDomVersion != domVersion) { // Need to extract forms as DOM version has changed since the last time // we searched. searchDocument(formFieldElement->document()->frame()); mLastSearchDomVersion = domVersion; } ASSERT(mFormManager); // Get the FormField from the Node. webkit_glue::FormField* formField = new webkit_glue::FormField; FormManager::HTMLFormControlElementToFormField(formFieldElement, FormManager::EXTRACT_NONE, formField); formField->label = FormManager::LabelForElement(*formFieldElement); webkit_glue::FormData* form = new webkit_glue::FormData; mFormManager->FindFormWithFormControlElement(formFieldElement, FormManager::REQUIRE_AUTOCOMPLETE, form); mQueryMap[mQueryId] = new FormDataAndField(form, formField); bool suggestions = mAutofillManager->OnQueryFormFieldAutoFillWrapper(*form, *formField); mQueryId++; if (!suggestions) { ASSERT(mWebViewCore); // Tell Java no autofill suggestions for this form. mWebViewCore->setWebTextViewAutoFillable(FORM_NOT_AUTOFILLABLE, string16()); return; } }
TEST(StringTest, Ensure16Bit) { String string8("8bit"); EXPECT_TRUE(string8.is8Bit()); string8.ensure16Bit(); EXPECT_FALSE(string8.is8Bit()); EXPECT_EQ("8bit", string8); String string16(reinterpret_cast<const UChar*>(u"16bit")); EXPECT_FALSE(string16.is8Bit()); string16.ensure16Bit(); EXPECT_FALSE(string16.is8Bit()); EXPECT_EQ("16bit", string16); String empty8(StringImpl::empty()); EXPECT_TRUE(empty8.is8Bit()); empty8.ensure16Bit(); EXPECT_FALSE(empty8.is8Bit()); EXPECT_TRUE(empty8.isEmpty()); EXPECT_FALSE(empty8.isNull()); String empty16(StringImpl::empty16Bit()); EXPECT_FALSE(empty16.is8Bit()); empty16.ensure16Bit(); EXPECT_FALSE(empty16.is8Bit()); EXPECT_TRUE(empty16.isEmpty()); EXPECT_FALSE(empty16.isNull()); String nullString; nullString.ensure16Bit(); EXPECT_TRUE(nullString.isNull()); }
bool MockSpellCheck::initializeIfNeeded() { // Exit if we have already initialized this object. if (m_initialized) return false; // Create a table that consists of misspelled words used in WebKit layout // tests. // Since WebKit layout tests don't have so many misspelled words as // well-spelled words, it is easier to compare the given word with misspelled // ones than to compare with well-spelled ones. static const char* misspelledWords[] = { // These words are known misspelled words in webkit tests. // If there are other misspelled words in webkit tests, please add them in // this array. "foo", "Foo", "baz", "fo", "LibertyF", "chello", "xxxtestxxx", "XXxxx", "Textx", "blockquoted", "asd", "Lorem", "Nunc", "Curabitur", "eu", "adlj", "adaasj", "sdklj", "jlkds", "jsaada", "jlda", "zz", "contentEditable", // The following words are used by unit tests. "ifmmp", "qwertyuiopasd", "qwertyuiopasdf", "upper case", "wellcome" }; m_misspelledWords.clear(); for (size_t i = 0; i < arraysize(misspelledWords); ++i) m_misspelledWords.push_back(string16(misspelledWords[i], misspelledWords[i] + strlen(misspelledWords[i]))); // Mark as initialized to prevent this object from being initialized twice // or more. m_initialized = true; // Since this MockSpellCheck class doesn't download dictionaries, this // function always returns false. return false; }
void WebAutofill::setEmptyProfile() { // Set an empty profile. This will ensure that when autofill is enabled, // we will still search the document for autofillable forms and inform // java of their presence so we can invite the user to set up // their own profile. // Chromium code will strip the values sent into the profile so we need them to be // at least one non-whitespace character long. We need to set all fields of the // profile to a non-empty string so that any field type can trigger the autofill // suggestion. Autofill will not detect form fields if the profile value for that // field is an empty string. static const string16 empty = string16(ASCIIToUTF16("a")); setProfile(empty, empty, empty, empty, empty, empty, empty, empty, empty, empty); }
string16 FormatBytesInternal(int64 bytes, DataUnits units, bool show_units, const char* const* suffix) { if(bytes < 0) { NOTREACHED() << "Negative bytes value"; return string16(); } DCHECK(units>=DATA_UNITS_BYTE && units<=DATA_UNITS_GIBIBYTE); // 数量转换到正确的单位. double unit_amount = static_cast<double>(bytes); for(int i=0; i<units; ++i) { unit_amount /= 1024.0; } char buf[64]; if(bytes!=0 && units!=DATA_UNITS_BYTE && unit_amount<100) { base::snprintf(buf, arraysize(buf), "%.1lf", unit_amount); } else { base::snprintf(buf, arraysize(buf), "%.0lf", unit_amount); } std::string ret(buf); if(show_units) { ret += " "; ret += suffix[units]; } return ASCIIToUTF16(ret); }
static std::string HFSUniStr255_to_utf8str(const HFSUniStr255* src) { llutf16string string16((U16*)&(src->unicode), src->length); std::string result = utf16str_to_utf8str(string16); return result; }
bool RemoveChars(const string16& input, const base::StringPiece16& remove_chars, string16* output) { return ReplaceChars(input, remove_chars.as_string(), string16(), output); }
inline string16 getStringFieldAsString16(JNIEnv* env, jobject autoFillProfile, jfieldID fieldId) { jstring str = static_cast<jstring>(env->GetObjectField(autoFillProfile, fieldId)); return str ? jstringToString16(env, str) : string16(); }