Пример #1
0
void DatePickerClient::generateHTML(BlackBerry::Platform::BlackBerryInputType type, const BlackBerry::Platform::String& value, const BlackBerry::Platform::String& min, const BlackBerry::Platform::String& max, double step)
{
    StringBuilder source;
    source.appendLiteral("<style>\n");
    // Include CSS file.
    source.append(popupControlBlackBerryCss,
                  sizeof(popupControlBlackBerryCss));
    source.appendLiteral("</style>\n<style>");
    source.append(timeControlBlackBerryCss,
                  sizeof(timeControlBlackBerryCss));
    source.appendLiteral("</style></head><body>\n"
                         "<script>\n"
                         "window.addEventListener('load', function () {");
    switch (type) {
    case BlackBerry::Platform::InputTypeDate:
        source.appendLiteral("window.popupcontrol.show(\"Date\", ");
        break;
    case BlackBerry::Platform::InputTypeTime:
        source.appendLiteral("window.popupcontrol.show(\"Time\", ");
        break;
    case BlackBerry::Platform::InputTypeDateTime:
        source.appendLiteral("window.popupcontrol.show(\"DateTime\", ");
        break;
    case BlackBerry::Platform::InputTypeDateTimeLocal:
        source.appendLiteral("window.popupcontrol.show(\"DateTimeLocal\", ");
        break;
    case BlackBerry::Platform::InputTypeMonth:
        source.appendLiteral("window.popupcontrol.show(\"Month\", ");
        break;
    case BlackBerry::Platform::InputTypeWeek:
    default:
        break;
    }
    if (!value.empty())
        source.append("\"" + String(value) + "\", ");
    else
        source.appendLiteral("0, ");

    if (!min.empty())
        source.append(String(min) + ", ");
    else
        source.appendLiteral("0, ");
    if (!max.empty())
        source.append(String(max) + ", ");
    else
        source.appendLiteral("0, ");
    source.append(String::number(step));
    source.appendLiteral("); \n }); \n");
    source.append(timeControlBlackBerryJs, sizeof(timeControlBlackBerryJs));
    source.appendLiteral("</script>\n"
                         "</body> </html>\n");
    m_source = source.toString();
}
Пример #2
0
static JSValueRef clientExtensionMethod(
    JSContextRef ctx, JSObjectRef functionObject, JSObjectRef thisObject,
    size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    JSValueRef jsRetVal = JSValueMakeUndefined(ctx);
    if (argumentCount <= 0)
        return jsRetVal;

    char** strArgs = new char*[argumentCount];
    for (unsigned i = 0; i < argumentCount; ++i) {
        JSStringRef string = JSValueToStringCopy(ctx, arguments[i], 0);
        size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
        strArgs[i] = new char[sizeUTF8];
        JSStringGetUTF8CString(string, strArgs[i], sizeUTF8);
        JSStringRelease(string);
    }

    WebPageClient* client = reinterpret_cast<WebPageClient*>(JSObjectGetPrivate(thisObject));
    BlackBerry::Platform::String retVal;
    if (client)
        retVal = client->invokeClientJavaScriptCallback(strArgs, argumentCount);
    // FIXME: add a mechanism to pass the length of the string here
    if (!retVal.empty())
        jsRetVal = JSValueMakeString(ctx, JSStringCreateWithUTF8CString(retVal.c_str()));

    for (unsigned i = 0; i < argumentCount; ++i)
        delete[] strArgs[i];
    delete[] strArgs;

    return jsRetVal;
}
Пример #3
0
bool WebSettings::isSupportedObjectMIMEType(const BlackBerry::Platform::String& mimeType)
{
    if (mimeType.empty())
        return false;

    if (!s_supportedObjectMIMETypes)
        return false;

    return s_supportedObjectMIMETypes->contains(MIMETypeRegistry::getNormalizedMIMEType(mimeType));
}
Пример #4
0
CookieParser::CookieParser(const URL& defaultCookieURL)
    : m_defaultCookieURL(defaultCookieURL)
{
    m_defaultCookieHost = defaultCookieURL.host();
    m_defaultDomainIsIPAddress = false;
    BlackBerry::Platform::String hostDomainCanonical = BlackBerry::Platform::getCanonicalIPFormat(m_defaultCookieHost);
    if (!hostDomainCanonical.empty()) {
        m_defaultCookieHost = hostDomainCanonical;
        m_defaultDomainIsIPAddress = true;
    }
}
Пример #5
0
void DatePickerClient::generateHTML(BlackBerry::Platform::BlackBerryInputType type, const BlackBerry::Platform::String& value, const BlackBerry::Platform::String& min, const BlackBerry::Platform::String& max, double step)
{
    StringBuilder source;
    String title = "";
    source.appendLiteral("<style>\n");
    // Include CSS file.
    source.append(popupControlBlackBerryCss,
            sizeof(popupControlBlackBerryCss));
    source.appendLiteral("</style>\n<style>");
    source.append(timeControlBlackBerryCss,
            sizeof(timeControlBlackBerryCss));
    source.appendLiteral("</style></head><body>\n");
    source.appendLiteral("<script>\n");
    source.appendLiteral("window.addEventListener('load', function showIt() {");
    source.appendLiteral("window.popupcontrol.show({");
    // Add DatePicker type
    source.appendLiteral("type:");
    switch (type) {
    case BlackBerry::Platform::InputTypeDate:
        source.appendLiteral("'Date', ");
        title = String::fromUTF8(s_resource.getString(BlackBerry::Platform::PICKER_DATE_TITLE));
        break;
    case BlackBerry::Platform::InputTypeTime:
        source.appendLiteral("'Time', ");
        title = String::fromUTF8(s_resource.getString(BlackBerry::Platform::PICKER_TIME_TITLE));
        break;
    case BlackBerry::Platform::InputTypeDateTime:
        source.appendLiteral("'DateTime', ");
        title = String::fromUTF8(s_resource.getString(BlackBerry::Platform::PICKER_DATE_TIME_TITLE));
        break;
    case BlackBerry::Platform::InputTypeDateTimeLocal:
        source.appendLiteral("'DateTimeLocal', ");
        title = String::fromUTF8(s_resource.getString(BlackBerry::Platform::PICKER_DATE_TIME_LOCAL_TITLE));
        break;
    case BlackBerry::Platform::InputTypeMonth:
        source.appendLiteral("'Month', ");
        title = String::fromUTF8(s_resource.getString(BlackBerry::Platform::PICKER_MONTH_TITLE));
        break;
    case BlackBerry::Platform::InputTypeWeek:
    default:
        break;
    }
    // Add datetime value
    source.appendLiteral("initialValue:");
    if (!value.empty())
        source.append("'" + String(value) + "', ");
    else
        source.appendLiteral("null, ");
    // Add lower and upper bounds
    source.appendLiteral("min:");
    if (!min.empty())
        source.append("'" + String(min) + "', ");
    else
        source.appendLiteral("null, ");
    source.appendLiteral("max:");
    if (!max.empty())
        source.append("'" + String(max) + "', ");
    else
        source.appendLiteral("null, ");
    // Add step size
    source.append("step:" + String::number(step) + ", ");
    // Add UI text
    source.appendLiteral("uiText: {");
    source.append("title:'" + title + "',");
    source.append("doneButtonLabel:'" + String::fromUTF8(s_resource.getString(BlackBerry::Platform::PICKER_DONE_BUTTON_LABEL)) + "',");
    source.append("cancelButtonLabel:'" + String::fromUTF8(s_resource.getString(BlackBerry::Platform::PICKER_CANCEL_BUTTON_LABEL)) + "',");
    source.append("monthLabels:" + DatePickerClient::generateDateLabels(UDAT_STANDALONE_MONTHS) + ",");
    source.append("shortMonthLabels:" + DatePickerClient::generateDateLabels(UDAT_SHORT_MONTHS) + ",");
    source.append("daysOfWeekLabels:" + DatePickerClient::generateDateLabels(UDAT_STANDALONE_WEEKDAYS) + ",");
    source.append("amPmLabels:" + DatePickerClient::generateDateLabels(UDAT_AM_PMS) + ",");
    source.appendLiteral("},");
    // Add directionality
    bool isRtl = BlackBerry::Platform::LocaleHandler::instance()->isRtlLocale();
    source.append("direction:'" + String(isRtl ? "rtl" : "ltr") + "',");
    source.appendLiteral("});\n");
    source.appendLiteral(" window.removeEventListener('load', showIt); }); \n");
    source.append(timeControlBlackBerryJs, sizeof(timeControlBlackBerryJs));
    source.appendLiteral("</script>\n"
                         "</body> </html>\n");
    m_source = source.toString();
}
Пример #6
0
void CookieManager::getRawCookies(Vector<RefPtr<ParsedCookie> > &stackOfCookies, const KURL& requestURL, CookieFilter filter) const
{
    // Force a sync load of the database
    if (!m_syncedWithDatabase && !m_privateMode)
        m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar());

    CookieLog("CookieManager - getRawCookies - processing url with domain - %s & protocol: %s & path: %s\n", requestURL.host().utf8().data(), requestURL.protocol().utf8().data(), requestURL.path().utf8().data());

    const bool invalidScheme = shouldIgnoreScheme(requestURL.protocol());
    const bool specialCaseForWebWorks = invalidScheme && m_shouldDumpAllCookies;
    const bool isConnectionSecure = requestURL.protocolIs("https") || requestURL.protocolIs("wss") || specialCaseForWebWorks;

    Vector<RefPtr<ParsedCookie> > cookieCandidates;
    Vector<CookieMap*> protocolsToSearch;

    // Special Case: If a server sets a "secure" cookie over a non-secure channel and tries to access the cookie
    // over a secure channel, it will not succeed because the secure protocol isn't mapped to the insecure protocol yet.
    // Set the map to the non-secure version, so it'll search the mapping for a secure cookie.
    CookieMap* targetMap = m_managerMap.get(requestURL.protocol());
    if (!targetMap && isConnectionSecure) {
        CookieLog("CookieManager - special case: secure protocol are not linked yet.");
        if (requestURL.protocolIs("https"))
            targetMap = m_managerMap.get("http");
        else if (requestURL.protocolIs("wss"))
            targetMap = m_managerMap.get("ws");
    }

    // Decide which scheme tree we should look at.
    // Return on invalid schemes. cookies are currently disabled on file and local.
    // We only want to enable them for WebWorks that enabled a special flag.
    if (specialCaseForWebWorks)
        copyValuesToVector(m_managerMap, protocolsToSearch);
    else if (invalidScheme)
        return;
    else {
        protocolsToSearch.append(targetMap);
        // FIXME: this is a hack for webworks apps; RFC 6265 says "Cookies do not provide isolation by scheme"
        // so we should not be checking protocols at all. See PR 135595
        if (m_shouldDumpAllCookies) {
            protocolsToSearch.append(m_managerMap.get("file"));
            protocolsToSearch.append(m_managerMap.get("local"));
        }
    }

    Vector<String> delimitedHost;

    // IP addresses are stored in a particular format (due to ipv6). Reduce the ip address so we can match
    // it with the one in memory.
    BlackBerry::Platform::String canonicalIP = BlackBerry::Platform::getCanonicalIPFormat(requestURL.host());
    if (!canonicalIP.empty())
        delimitedHost.append(String(canonicalIP.c_str()));
    else
        requestURL.host().lower().split(".", true, delimitedHost);

    // Go through all the protocol trees that we need to search for
    // and get all cookies that are valid for this domain
    for (size_t k = 0; k < protocolsToSearch.size(); k++) {
        CookieMap* currentMap = protocolsToSearch[k];

        // if no cookies exist for this protocol, break right away
        if (!currentMap)
            continue;

        CookieLog("CookieManager - looking at protocol map %s \n", currentMap->getName().utf8().data());

        // Special case for local and files - because WebApps expect to get ALL cookies from the backing-store on local protocol
        if (specialCaseForWebWorks) {
            CookieLog("CookieManager - special case find in protocol map - %s\n", currentMap->getName().utf8().data());
            currentMap->getAllChildCookies(&cookieCandidates);
        } else {
            // Get cookies from the null domain map
            currentMap->getAllCookies(&cookieCandidates);

            // Get cookies from Host-only cookies
            if (canonicalIP.empty()) {
                CookieLog("CookieManager - looking for host-only cookies for host - %s", requestURL.host().utf8().data());
                CookieMap* hostMap = currentMap->getSubdomainMap(requestURL.host());
                if (hostMap)
                    hostMap->getAllCookies(&cookieCandidates);
            }

            // Get cookies from the valid domain maps
            int i = delimitedHost.size() - 1;
            while (i >= 0) {
                CookieLog("CookieManager - finding %s in currentmap\n", delimitedHost[i].utf8().data());
                currentMap = currentMap->getSubdomainMap(delimitedHost[i]);
                // if this subdomain/domain does not exist in our mapping then we simply exit
                if (!currentMap) {
                    CookieLog("CookieManager - cannot find next map exiting the while loop.\n");
                    break;
                }
                CookieLog("CookieManager - found the map, grabbing cookies from this map\n");
                currentMap->getAllCookies(&cookieCandidates);
                i--;
            }
        }
    }

    CookieLog("CookieManager - there are %d cookies in candidate\n", cookieCandidates.size());

    for (size_t i = 0; i < cookieCandidates.size(); ++i) {
        RefPtr<ParsedCookie> cookie = cookieCandidates[i];

        // According to the path-matches rules in RFC6265, section 5.1.4,
        // we should add a '/' at the end of cookie-path for comparison if the cookie-path is not end with '/'.
        String path = cookie->path();
        CookieLog("CookieManager - comparing cookie path %s (len %d) to request path %s (len %d)", path.utf8().data(), path.length(), requestURL.path().utf8().data(), path.length());
        if (!equalIgnoringCase(path, requestURL.path()) && !path.endsWith("/", false))
            path = path + "/";

        // Only secure connections have access to secure cookies. Unless specialCaseForWebWorks is true.
        // Get the cookies filtering out HttpOnly cookies if requested.
        if (requestURL.path().startsWith(path, false) && (isConnectionSecure || !cookie->isSecure()) && (filter == WithHttpOnlyCookies || !cookie->isHttpOnly())) {
            CookieLog("CookieManager - cookie chosen - %s\n", cookie->toString().utf8().data());
            cookie->setLastAccessed(currentTime());
            stackOfCookies.append(cookie);
        }
    }

    std::stable_sort(stackOfCookies.begin(), stackOfCookies.end(), cookieSorter);
}