void WebNotificationManagerProxy::populateCopyOfNotificationPermissions(HashMap<String, bool>& permissions)
{
    RefPtr<ImmutableDictionary> knownPermissions = m_provider.notificationPermissions();

    if (!knownPermissions)
        return;

    permissions.clear();
    RefPtr<ImmutableArray> knownOrigins = knownPermissions->keys();
    for (size_t i = 0; i < knownOrigins->size(); ++i) {
        WebString* origin = knownOrigins->at<WebString>(i);
        permissions.set(origin->string(), knownPermissions->get<WebBoolean>(origin->string())->value());
    }
}
Exemple #2
0
void WebViewHost::setStatusText(const WebString& text)
{
    if (!layoutTestController()->shouldDumpStatusCallbacks())
        return;
    // When running tests, write to stdout.
    printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", text.utf8().data());
}
WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTarget)
{
    if (baseTarget.isEmpty())
        return String("<base href=\".\">");
    String baseString = "<base href=\".\" target=\"" + static_cast<const String&>(baseTarget) + "\">";
    return baseString;
}
Exemple #4
0
void WebURLRequest::setHTTPReferrer(const WebString& referrer, WebReferrerPolicy referrerPolicy)
{
    if (referrer.isEmpty())
        m_private->m_resourceRequest->clearHTTPReferrer();
    else
        m_private->m_resourceRequest->setHTTPReferrer(Referrer(referrer, static_cast<ReferrerPolicy>(referrerPolicy)));
}
Exemple #5
0
void WebViewHost::didReceiveResponse(WebFrame*, unsigned identifier, const WebURLResponse& response)
{
    if (m_shell->shouldDumpResourceLoadCallbacks()) {
        printResourceDescription(identifier);
        fputs(" - didReceiveResponse ", stdout);
        printResponseDescription(response);
        fputs("\n", stdout);
    }
    if (m_shell->shouldDumpResourceResponseMIMETypes()) {
        GURL url = response.url();
        WebString mimeType = response.mimeType();
        printf("%s has MIME type %s\n",
            url.ExtractFileName().c_str(),
            // Simulate NSURLResponse's mapping of empty/unknown MIME types to application/octet-stream
            mimeType.isEmpty() ? "application/octet-stream" : mimeType.utf8().data());
    }
}
WebString WebFrameSerializer::generateBaseTagDeclaration(const WebString& baseTarget)
{
    // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|.
    if (baseTarget.isEmpty())
        return String("<base href=\".\">");
    String baseString = "<base href=\".\" target=\"" + static_cast<const String&>(baseTarget) + "\">";
    return baseString;
}
Exemple #7
0
bool MockSpellCheck::spellCheckWord(const WebString& text, int* misspelledOffset, int* misspelledLength)
{
    ASSERT(misspelledOffset);
    ASSERT(misspelledLength);

    // Initialize this spellchecker.
    initializeIfNeeded();

    // Reset the result values as our spellchecker does.
    *misspelledOffset = 0;
    *misspelledLength = 0;

    // Convert to a String because we store String instances in
    // m_misspelledWords and WebString has no find().
    const String stringText(text.data(), text.length());

    // Extract the first possible English word from the given string.
    // The given string may include non-ASCII characters or numbers. So, we
    // should filter out such characters before start looking up our
    // misspelled-word table.
    // (This is a simple version of our SpellCheckWordIterator class.)
    // If the given string doesn't include any ASCII characters, we can treat the
    // string as valid one.
    // Unfortunately, This implementation splits a contraction, i.e. "isn't" is
    // split into two pieces "isn" and "t". This is OK because webkit tests
    // don't have misspelled contractions.
    int wordOffset = stringText.find(isASCIIAlpha);
    if (wordOffset == -1)
        return true;
    int wordEnd = stringText.find(isNotASCIIAlpha, wordOffset);
    int wordLength = wordEnd == -1 ? stringText.length() - wordOffset : wordEnd - wordOffset;

    // Look up our misspelled-word table to check if the extracted word is a
    // known misspelled word, and return the offset and the length of the
    // extracted word if this word is a known misspelled word.
    // (See the comment in MockSpellCheck::initializeIfNeeded() why we use a
    // misspelled-word table.)
    String word = stringText.substring(wordOffset, wordLength);
    if (!m_misspelledWords.contains(word))
        return true;

    *misspelledOffset = wordOffset;
    *misspelledLength = wordLength;
    return false;
}
Exemple #8
0
static PassOwnPtr<Vector<String> > toStringVector(ImmutableArray* patterns)
{
    if (!patterns)
        return 0;

    size_t size =  patterns->size();
    if (!size)
        return 0;

    Vector<String>* patternsVector = new Vector<String>;
    patternsVector->reserveInitialCapacity(size);
    for (size_t i = 0; i < size; ++i) {
        WebString* entry = patterns->at<WebString>(i);
        if (entry)
            patternsVector->uncheckedAppend(entry->string());
    }
    return patternsVector;
}
static void webkitCookieManagerGetDomainsWithCookiesCallback(WKArrayRef wkDomains, WKErrorRef, void* context)
{
    GRefPtr<GTask> task = adoptGRef(G_TASK(context));
    if (g_task_return_error_if_cancelled(task.get()))
        return;

    ImmutableArray* domains = toImpl(wkDomains);
    GPtrArray* returnValue = g_ptr_array_sized_new(domains->size());
    for (size_t i = 0; i < domains->size(); ++i) {
        WebString* domainString = static_cast<WebString*>(domains->at(i));
        String domain = domainString->string();
        if (domain.isEmpty())
            continue;
        g_ptr_array_add(returnValue, g_strdup(domain.utf8().data()));
    }
    g_ptr_array_add(returnValue, 0);
    g_task_return_pointer(task.get(), g_ptr_array_free(returnValue, FALSE), reinterpret_cast<GDestroyNotify>(g_strfreev));
}
Exemple #10
0
bool WebViewHost::shouldInsertText(const WebString& text, const WebRange& range, WebEditingAction action)
{
    if (layoutTestController()->shouldDumpEditingCallbacks()) {
        printf("EDITING DELEGATE: shouldInsertText:%s replacingDOMRange:", text.utf8().data());
        printRangeDescription(range);
        printf(" givenAction:%s\n", editingActionDescription(action).c_str());
    }
    return layoutTestController()->acceptsEditing();
}
Exemple #11
0
bool WebViewHost::shouldApplyStyle(const WebString& style, const WebRange& range)
{
    if (layoutTestController()->shouldDumpEditingCallbacks()) {
        printf("EDITING DELEGATE: shouldApplyStyle:%s toElementsInDOMRange:", style.utf8().data());
        printRangeDescription(range);
        fputs("\n", stdout);
    }
    return layoutTestController()->acceptsEditing();
}
Exemple #12
0
void EditorClientImpl::doAutofill(Timer<EditorClientImpl>* timer)
{
    OwnPtr<AutofillArgs> args(m_autofillArgs.release());
    HTMLInputElement* inputElement = args->inputElement.get();

    const String& value = inputElement->value();

    // Enforce autofill_on_empty_value and caret_at_end.

    bool isCaretAtEnd = true;
    if (args->requireCaretAtEnd)
        isCaretAtEnd = inputElement->selectionStart() == inputElement->selectionEnd()
                       && inputElement->selectionEnd() == static_cast<int>(value.length());

    if ((!args->autofillOnEmptyValue && value.isEmpty()) || !isCaretAtEnd) {
        m_webView->hideAutoFillPopup();
        return;
    }

    // First let's see if there is a password listener for that element.
    // We won't trigger form autofill in that case, as having both behavior on
    // a node would be confusing.
    WebFrameImpl* webframe = WebFrameImpl::fromFrame(inputElement->document()->frame());
    if (!webframe)
        return;
    WebPasswordAutocompleteListener* listener = webframe->getPasswordListener(inputElement);
    if (listener) {
        if (args->autofillFormOnly)
            return;

        listener->performInlineAutocomplete(value,
                                            args->backspaceOrDeletePressed,
                                            true);
        return;
    }

    // Then trigger form autofill.
    WebString name = WebInputElement(inputElement).nameForAutofill();
    ASSERT(static_cast<int>(name.length()) > 0);

    if (m_webView->client())
        m_webView->client()->queryAutofillSuggestions(WebNode(inputElement),
                                                      name, WebString(value));
}
Exemple #13
0
bool WebSettings::isSupportedObjectMIMEType(const WebString& mimeType)
{
    if (mimeType.isEmpty())
        return false;

    if (!s_supportedObjectMIMETypes)
        return false;

    return s_supportedObjectMIMETypes->contains(MIMETypeRegistry::getNormalizedMIMEType(mimeType));
}
Exemple #14
0
static Vector<String> toStringVector(API::Array* array)
{
    Vector<String> patternVector;
    if (!array)
        return patternVector;

    size_t size = array->size();
    if (!size)
        return patternVector;
    
    patternVector.reserveInitialCapacity(size);
    for (size_t i = 0; i < size; ++i) {
        WebString* webString = array->at<WebString>(i);
        ASSERT(webString);
        patternVector.uncheckedAppend(webString->string());
    }
    
    return patternVector;
}
static Vector<String> toStringVector(ImmutableArray* patterns)
{
    Vector<String> patternsVector;

    if (!patterns)
        return patternsVector;

    size_t size = patterns->size();
    if (!size)
        return patternsVector;

    patternsVector.reserveInitialCapacity(size);
    for (size_t i = 0; i < size; ++i) {
        WebString* entry = patterns->at<WebString>(i);
        if (entry)
            patternsVector.uncheckedAppend(entry->string());
    }
    return patternsVector;
}
Exemple #16
0
void PlainTextController::plainText(const CppArgumentList& arguments, CppVariant* result)
{
    result->setNull();

    if (arguments.size() < 1 || !arguments[0].isObject())
        return;

    // Check that passed-in object is, in fact, a range.
    NPObject* npobject = NPVARIANT_TO_OBJECT(arguments[0]);
    if (!npobject)
        return;
    WebRange range;
    if (!WebBindings::getRange(npobject, &range))
        return;

    // Extract the text using the Range's text() method
    WebString text = range.toPlainText();
    result->set(text.utf8());
}
bool EditorClientImpl::autofill(HTMLInputElement* inputElement,
                                bool autofillFormOnly,
                                bool autofillOnEmptyValue,
                                bool requireCaretAtEnd)
{
    // Cancel any pending DoAutofill call.
    m_autofillArgs.clear();
    m_autofillTimer.stop();

    // FIXME: Remove the extraneous isEnabledFormControl call below.
    // Let's try to trigger autofill for that field, if applicable.
    if (!inputElement->isEnabledFormControl() || !inputElement->isTextField()
        || inputElement->isPasswordField() || !inputElement->autoComplete()
        || !inputElement->isEnabledFormControl()
        || inputElement->isReadOnlyFormControl())
        return false;

    WebString name = WebInputElement(inputElement).nameForAutofill();
    if (name.isEmpty()) // If the field has no name, then we won't have values.
        return false;

    // Don't attempt to autofill with values that are too large.
    if (inputElement->value().length() > maximumTextSizeForAutofill)
        return false;

    m_autofillArgs = new AutofillArgs();
    m_autofillArgs->inputElement = inputElement;
    m_autofillArgs->autofillFormOnly = autofillFormOnly;
    m_autofillArgs->autofillOnEmptyValue = autofillOnEmptyValue;
    m_autofillArgs->requireCaretAtEnd = requireCaretAtEnd;
    m_autofillArgs->backspaceOrDeletePressed = m_backspaceOrDeletePressed;

    if (!requireCaretAtEnd)
        doAutofill(0);
    else {
        // We post a task for doing the autofill as the caret position is not set
        // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976)
        // and we need it to determine whether or not to trigger autofill.
        m_autofillTimer.startOneShot(0.0);
    }
    return true;
}
bool NotificationPresenter::simulateClick(const WebString& title)
{
    string id(title.utf8());
    if (m_activeNotifications.find(id) == m_activeNotifications.end())
        return false;

    const WebNotification& notification = m_activeNotifications.find(id)->second;
    WebNotification eventTarget(notification);
    eventTarget.dispatchClickEvent();
    return true;
}
void WebSettings::setAppCachePath(const WebString& path)
{
    // The directory of cacheStorage for one page group can only be initialized once.
    static HashSet<WTF::String> initGroups;
    if (path.isEmpty() || initGroups.contains(d->m_webCoreSettingsState->pageGroupName))
        return;

    initGroups.add(d->m_webCoreSettingsState->pageGroupName);
    d->m_webCoreSettingsState->appCachePath = path;
    WebCore::cacheStorage(d->m_webCoreSettingsState->pageGroupName).setCacheDirectory(d->m_webCoreSettingsState->appCachePath);
}
Exemple #20
0
WebAnimation WebAnimation::fadeAnimation(const WebString& name, float from, float to, double duration)
{
    WebAnimation tmp;
    tmp.d->name = String(name.impl());
    tmp.d->animation = Animation::create();
    tmp.d->animation->setDuration(duration);
    tmp.d->keyframes = KeyframeValueList(AnimatedPropertyOpacity);
    tmp.d->keyframes.insert(new FloatAnimationValue(0, from));
    tmp.d->keyframes.insert(new FloatAnimationValue(1.0, to));

    return tmp;
}
Exemple #21
0
void SpellCheckClient::requestCheckingOfText(const WebString& text, WebTextCheckingCompletion* completion)
{
    if (text.isEmpty()) {
        if (completion)
            completion->didCancelCheckingText();
        return;
    }

    m_lastRequestedTextCheckingCompletion = completion;
    m_lastRequestedTextCheckString = text;
    m_delegate->postDelayedTask(new HostMethodTask(this, &SpellCheckClient::finishLastTextCheck), 0);
}
void WebSettings::setDatabasePath(const WebString& path)
{
    // DatabaseTracker can only be initialized for once, so it doesn't
    // make sense to change database path after DatabaseTracker has
    // already been initialized.
    static HashSet<WTF::String> initGroups;
    if (path.isEmpty() || initGroups.contains(d->m_webCoreSettingsState->pageGroupName))
        return;

    initGroups.add(d->m_webCoreSettingsState->pageGroupName);
    d->m_webCoreSettingsState->databasePath = path;
    WebCore::databaseTrackerManager().initializeTracker(d->m_webCoreSettingsState->pageGroupName, d->m_webCoreSettingsState->databasePath);
}
Exemple #23
0
WebCore::ProtectionSpace getProtectionSpace(const char* url, WebString& realm, WebString& scheme)
{
    WebCore::ProtectionSpaceAuthenticationScheme protectionSpaceScheme = WebCore::ProtectionSpaceAuthenticationSchemeDefault;
    if (equalIgnoringCase(scheme, "ntlm"))
        protectionSpaceScheme = WebCore::ProtectionSpaceAuthenticationSchemeNTLM;
    else if (equalIgnoringCase(scheme, "basic"))
        protectionSpaceScheme = WebCore::ProtectionSpaceAuthenticationSchemeHTTPBasic;
    else if (equalIgnoringCase(scheme, "digest"))
        protectionSpaceScheme = WebCore::ProtectionSpaceAuthenticationSchemeHTTPDigest;
    WebCore::KURL kurl(WebCore::KURL(), url);
    return WebCore::ProtectionSpace(kurl.host(), kurl.port(), realm.equalIgnoringCase("ftp") ?
            WebCore::ProtectionSpaceServerFTP : WebCore::ProtectionSpaceServerHTTP, realm, protectionSpaceScheme);
}
Exemple #24
0
void WebViewHost::didReceiveTitle(WebFrame* frame, const WebString& title)
{
    WebCString title8 = title.utf8();

    if (m_shell->shouldDumpFrameLoadCallbacks()) {
        printFrameDescription(frame);
        printf(" - didReceiveTitle: %s\n", title8.data());
    }

    if (layoutTestController()->shouldDumpTitleChanges())
        printf("TITLE CHANGED: %s\n", title8.data());

    setPageTitle(title);
}
GURL WebStringToGURL(const WebString& webString)
{
    if (webString.isEmpty())
        return GURL();

    String str = webString;
    if (str.is8Bit()) {
        // Ensure the (possibly Latin-1) 8-bit string is UTF-8 for GURL.
        StringUTF8Adaptor utf8(str);
        return GURL(utf8.asStringPiece());
    }

    // GURL can consume UTF-16 directly.
    return GURL(base::StringPiece16(str.characters16(), str.length()));
}
bool MockWebSpeechInputController::startRecognition(int requestId, const WebRect& elementRect, const WebString& language, const WebString& grammar, const WebSecurityOrigin& origin)
{
    if (m_speechTask)
        return false;

    m_requestId = requestId;
    m_requestRect = elementRect;
    m_recording = true;
    m_language = language.utf8();

    m_speechTask = new SpeechTask(this);
    m_delegate->postTask(m_speechTask);

    return true;
}
Exemple #27
0
bool WebSocketImpl::sendText(const WebString& message)
{
    size_t size = message.utf8().length();
    m_bufferedAmount += size;
    if (m_isClosingOrClosed)
        m_bufferedAmountAfterClose += size;

    // FIXME: Deprecate this call.
    m_client->didUpdateBufferedAmount(m_bufferedAmount);

    if (m_isClosingOrClosed)
        return true;

    m_private->send(message);
    return true;
}
Exemple #28
0
void SpellCheckClient::requestCheckingOfText(
        const WebString& text,
        const WebVector<uint32_t>& markers,
        const WebVector<unsigned>& markerOffsets,
        WebTextCheckingCompletion* completion)
{
    if (text.isEmpty()) {
        if (completion)
            completion->didCancelCheckingText();
        return;
    }

    m_lastRequestedTextCheckingCompletion = completion;
    m_lastRequestedTextCheckString = text;
    if (m_spellcheck.hasInCache(text))
        finishLastTextCheck();
    else
        m_delegate->postDelayedTask(new HostMethodTask(this, &SpellCheckClient::finishLastTextCheck), 0);
}
bool WebLocalFrameImpl::executeCommand(const WebString& name, const WebNode& node)
{
    ASSERT(frame());

    if (name.length() <= 2)
        return false;

    // Since we don't have NSControl, we will convert the format of command
    // string and call the function on Editor directly.
    String command = name;

    // Make sure the first letter is upper case.
    command.replace(0, 1, command.substring(0, 1).upper());

    // Remove the trailing ':' if existing.
    if (command[command.length() - 1] == UChar(':'))
        command = command.substring(0, command.length() - 1);

    return frame()->editor().executeCommand(command);
}
void EventSender::keyDown(const CppArgumentList& arguments, CppVariant* result)
{
    result->setNull();
    if (arguments.size() < 1 || !arguments[0].isString())
        return;
    bool generateChar = false;

    // FIXME: I'm not exactly sure how we should convert the string to a key
    // event. This seems to work in the cases I tested.
    // FIXME: Should we also generate a KEY_UP?
    string codeStr = arguments[0].toString();

    // Convert \n -> VK_RETURN.  Some layout tests use \n to mean "Enter", when
    // Windows uses \r for "Enter".
    int code = 0;
    int text = 0;
    bool needsShiftKeyModifier = false;
    if ("\n" == codeStr) {
        generateChar = true;
        text = code = webkit_support::VKEY_RETURN;
    } else if ("rightArrow" == codeStr)
        code = webkit_support::VKEY_RIGHT;
    else if ("downArrow" == codeStr)
        code = webkit_support::VKEY_DOWN;
    else if ("leftArrow" == codeStr)
        code = webkit_support::VKEY_LEFT;
    else if ("upArrow" == codeStr)
        code = webkit_support::VKEY_UP;
    else if ("insert" == codeStr)
        code = webkit_support::VKEY_INSERT;
    else if ("delete" == codeStr)
        code = webkit_support::VKEY_DELETE;
    else if ("pageUp" == codeStr)
        code = webkit_support::VKEY_PRIOR;
    else if ("pageDown" == codeStr)
        code = webkit_support::VKEY_NEXT;
    else if ("home" == codeStr)
        code = webkit_support::VKEY_HOME;
    else if ("end" == codeStr)
        code = webkit_support::VKEY_END;
    else if ("printScreen" == codeStr)
        code = webkit_support::VKEY_SNAPSHOT;
    else if ("menu" == codeStr)
        // FIXME: Change this to webkit_support::VKEY_APPS.
        code = 0x5D;
    else {
        // Compare the input string with the function-key names defined by the
        // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key
        // name, set its key code.
        for (int i = 1; i <= 24; ++i) {
            char functionChars[10];
            snprintf(functionChars, 10, "F%d", i);
            string functionKeyName(functionChars);
            if (functionKeyName == codeStr) {
                code = webkit_support::VKEY_F1 + (i - 1);
                break;
            }
        }
        if (!code) {
            WebString webCodeStr = WebString::fromUTF8(codeStr.data(), codeStr.size());
            ASSERT(webCodeStr.length() == 1);
            text = code = webCodeStr.data()[0];
            needsShiftKeyModifier = needsShiftModifier(code);
            if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z')
                code -= 'a' - 'A';
            generateChar = true;
        }
    }

    // For one generated keyboard event, we need to generate a keyDown/keyUp
    // pair; refer to EventSender.cpp in Tools/DumpRenderTree/win.
    // On Windows, we might also need to generate a char event to mimic the
    // Windows event flow; on other platforms we create a merged event and test
    // the event flow that that platform provides.
    WebKeyboardEvent eventDown, eventChar, eventUp;
    eventDown.type = WebInputEvent::RawKeyDown;
    eventDown.modifiers = 0;
    eventDown.windowsKeyCode = code;
    if (generateChar) {
        eventDown.text[0] = text;
        eventDown.unmodifiedText[0] = text;
    }
    eventDown.setKeyIdentifierFromWindowsKeyCode();

    if (arguments.size() >= 2 && (arguments[1].isObject() || arguments[1].isString()))
        eventDown.isSystemKey = applyKeyModifiers(&(arguments[1]), &eventDown);

    if (needsShiftKeyModifier)
        eventDown.modifiers |= WebInputEvent::ShiftKey;

    // See if KeyLocation argument is given.
    if (arguments.size() >= 3 && arguments[2].isNumber()) {
        int location = arguments[2].toInt32();
        if (location == DOMKeyLocationNumpad)
            eventDown.modifiers |= WebInputEvent::IsKeyPad;
    }

    eventChar = eventUp = eventDown;
    eventUp.type = WebInputEvent::KeyUp;
    // EventSender.m forces a layout here, with at least one
    // test (fast/forms/focus-control-to-page.html) relying on this.
    webview()->layout();

    // In the browser, if a keyboard event corresponds to an editor command,
    // the command will be dispatched to the renderer just before dispatching
    // the keyboard event, and then it will be executed in the
    // RenderView::handleCurrentKeyboardEvent() method, which is called from
    // third_party/WebKit/Source/WebKit/chromium/src/EditorClientImpl.cpp.
    // We just simulate the same behavior here.
    string editCommand;
    if (getEditCommand(eventDown, &editCommand))
        m_shell->webViewHost()->setEditCommand(editCommand, "");

    webview()->handleInputEvent(eventDown);

    m_shell->webViewHost()->clearEditCommand();

    if (generateChar) {
        eventChar.type = WebInputEvent::Char;
        eventChar.keyIdentifier[0] = '\0';
        webview()->handleInputEvent(eventChar);
    }

    webview()->handleInputEvent(eventUp);
}