Пример #1
0
int main(int argc, char** argv)
{
    wkeWebView webView;
    const char* url;
    wchar_t filename[1024];
    void* pixels;
    int w, h;

    printf(wkeVersionString());

    wkeInit();
    webView = wkeCreateWebView();
    wkeResize(webView, 1024, 768);

    url = argc >= 2 ? argv[1] : "http://www.google.com";
    printf("loading url %s ...\n", url);    
    wkeLoadURL(webView, url);

    while (1)
    {
        wkeUpdate();
        if (wkeIsLoadComplete(webView))
            break;
			
        Sleep(10);
    }
	
    /*hidden scrollbar*/
    wkeRunJS(webView, "document.body.style.overflow='hidden'");

    w = wkeContentsWidth(webView);
    h = wkeContentsHeight(webView);
    wkeResize(webView, w, h);

    pixels = malloc(w*h*4);
    wkePaint(webView, pixels, 0);

    //save bitmap
    swprintf(filename, 1024, L"%s.bmp", wkeTitleW(webView));
    convertFilename(filename);
    wprintf(L"%s\n", filename);
    
    saveBitmap(pixels, w, h, filename);

    free(pixels);
    wkeDestroyWebView(webView);
    wkeShutdown();

    return 0;
}
Пример #2
0
/* see drm_file.h */
int32_t
DRM_file_mkdir(const uint16_t* name, int32_t nameChars)
{
    ALOGD("DRM_file_mkdir started!..");
#if 0
    if (convertFilename(name, nameChars, tmpPathBuf1) <= 0)
    {
        ALOGD("DRM_file_mkdir: bad filename");
        return DRM_FILE_FAILURE;
    }
#endif

    if (mkdir(name,0777) != 0)
    {
        ALOGD("DRM_file_mkdir failed!errno=%d",errno);
        return DRM_FILE_FAILURE;
    }

    return DRM_FILE_SUCCESS;
}
Пример #3
0
/**
 * Perform a stat() call on the given filename.
 * Helper for getFileLength and exists
 * @param name unicode name
 * @param nameLen number of unicode characters in name
 * @param sbuf stat buffer
 * @return TRUE on success, FALSE on failure
 */
static int32_t
getFileStat(const uint16_t *name, int32_t nameLen, struct stat *sbuf)
{
    ALOGD("getFileStat: %.*S", nameLen, name);
#if 0
    if (convertFilename(name, nameLen, tmpPathBuf1) <= 0)
    {
        ALOGD("getFileStat: bad filename");
    }
#endif
    if (stat(name, sbuf) != 0)
    {
        ALOGD("getFileStat %s: stat() errno=%d", tmpPathBuf1, errno);
    }
    else /* Successful */
    {
        return TRUE;
    }

    return FALSE;
}
Пример #4
0
/* see drm_file.h */
int32_t
DRM_file_open(const uint16_t *name, int32_t nameLen, int32_t mode,
                      int64_t* handle)
{
    int res;

#if DRM_FILE_MODE_READ != 1 || DRM_FILE_MODE_WRITE != 2
#error constants changed
#endif

    /* Convert DRM file modes to posix modes */
    static const int modes[4] =
    { 0,
      O_RDONLY,
      O_WRONLY | O_CREAT,
      O_RDWR | O_CREAT
    };

    ALOGD("DRM_file_open %d, name= %s, mode 0x%x", nameLen, name, mode);

    assert((mode & ~(DRM_FILE_MODE_READ|DRM_FILE_MODE_WRITE)) == 0);

#if 0
    if (convertFilename(name, nameLen, tmpPathBuf1) <= 0)
    {
        ALOGD("DRM_file_open: bad filename");
        return DRM_FILE_FAILURE;
    }
#endif

    if ((res = open(name, modes[mode], 0777)) == -1)
    {
        ALOGD("DRM_file_open: open failed errno=%s", strerror(errno));
        return DRM_FILE_FAILURE;
    }
    ALOGD("DRM_file_open: open '%s; returned %d", name, res);
    *handle = res;

    return DRM_FILE_SUCCESS;
}
Пример #5
0
/* see drm_file.h */
int32_t
DRM_file_delete(const uint16_t *name, int32_t nameLen)
{
    ALOGD("DRM_file_delete: %.*S", nameLen, name);

#if 0
    if (convertFilename(name, nameLen, tmpPathBuf1) <= 0)
    {
        ALOGD("DRM_file_delete: bad filename");
        return DRM_FILE_FAILURE;
    }
    else
    {
#endif
       struct stat sinfo;
       if (stat(name, &sinfo) != 0) {
           ALOGD("DRM_file_delete: stat failed, errno=%d", errno);
           return DRM_FILE_FAILURE;
       }
#ifndef DEVICE_FILESYSTEM
       if (S_ISDIR(sinfo.st_mode)){
            /* it's a dir */
            if (rmdir(name) != 0) {
                ALOGD("DRM_file_delete: dir remove failed, errno=%d", errno);
                return DRM_FILE_FAILURE;
            }
            else
            {
                return DRM_FILE_SUCCESS;
            }
        }
#endif
        /* it's a file */
        if (unlink(name) != 0)
        {
            ALOGD("DRM_file_delete: file remove failed, errno=%d", errno);
            return DRM_FILE_FAILURE;
        }
        else
        {
#ifndef DEVICE_FILESYSTEM
            availableSize += sinfo.st_size;
#endif
            return DRM_FILE_SUCCESS;
        }
    return DRM_FILE_FAILURE;
}

/* see drm_file.h */
int32_t
DRM_file_rename(const uint16_t *oldName, int32_t oldNameLen,
                const uint16_t *newName, int32_t newNameLen)
{
    ALOGD("DRM_file_rename %.*S -> %.*S",
                                    oldNameLen, oldName, newNameLen, newName);
    if (DRM_file_exists(newName, newNameLen) != DRM_FILE_FAILURE)
    {
        ALOGD("DRM_file_rename: filename:%s exist",newName);
        return DRM_FILE_FAILURE;
    }

#if 0
    if (convertFilename(oldName, oldNameLen, tmpPathBuf1) <= 0 ||
        convertFilename(newName, newNameLen, tmpPathBuf2) <= 0)
    {
        ALOGD("DRM_file_rename: bad filename");
    }
    else if (rename(tmpPathBuf1, tmpPathBuf2) != 0)
#else
    if (rename(oldName, newName) != 0)
#endif
    {
         ALOGD("DRM_file_rename: failed errno=%d", errno);
    }
    else /* Success */
    {
        return DRM_FILE_SUCCESS;
    }

    return DRM_FILE_FAILURE;
}
Пример #6
0
/* see drm_file.h */
int32_t
DRM_file_listOpen(const uint16_t *prefix,
                    int32_t prefixLen,
                    int32_t* session,
                    int32_t* iteration)
{
    ALOGD("DRM_file_listOpen: %.*S", prefixLen, prefix);

#if 0
    if (convertFilename(prefix, prefixLen, tmpPathBuf1) <= 0)
    {
        ALOGD("DRM_file_listOpen: bad filename");
    }
    else
    {
#endif
        DIR *dir;

        /* find the last /, and store the offset to the leaf prefix in
         * *iteration
         */
        char *sep = strrchr(prefix, '/');
        /* Root "/" is a leaf */
        if (sep == NULL || ((sep != NULL) && (sep == tmpPathBuf1)))
        {
            *iteration = prefixLen;

#ifdef ALOGD_ON
            sep = " <empty>"; /* ALOGD will show sep+1 */
#endif
        }
        else
        {
            *iteration = sep - tmpPathBuf1 + 1;
            *sep = 0;
        }
        dir = opendir(prefix);

        if (dir == NULL)
        {
            ALOGD("DRM_file_listOpen: opendir %s: errno=%d", prefix, errno);
        }
        else
        {
            ALOGD("DRM_file_listOpen: dir %s, filter %s", prefix, sep+1);
            *session = (int32_t)(long)dir;
            return DRM_FILE_SUCCESS;
        }
    return DRM_FILE_FAILURE;
}

/* see drm_file.h */
int32_t
DRM_file_listNextEntry(const uint16_t *prefix, int32_t prefixLen,
                       uint16_t* entry, int32_t entrySize,
                       int32_t *session, int32_t* iteration)
{
    struct dirent *ent;

    /* We stored the offset of the leaf part of the prefix (if any)
     * in *iteration
     */
    const uint16_t* strData   = prefix + *iteration;
    int32_t   strLength = prefixLen - *iteration;

    /* entrySize is bytes for some reason. Convert to ucs chars */
    entrySize /= 2;

    /* Now we want to filter for files which start with the (possibly empty)
     * sequence at strData. We have to return fully-qualified filenames,
     * which means *iteration characters from prefix, plus the
     * leaf name.
     */

    while ( (ent = readdir((DIR *)(long)*session)) != NULL)
    {
        int len = strlen(ent->d_name);

        if ( (len + *iteration) > entrySize)
        {
            ALOGD("DRM_file_listNextEntry: %s too long", ent->d_name);
        }
        else if (strcmp(ent->d_name, ".") != 0 &&
                 strcmp(ent->d_name, "..") != 0)
        {
            int idx;
            struct stat sinfo;

            /* check against the filter */

            for (idx = 0; idx < strLength; ++idx)
            {
                if (ent->d_name[idx] != strData[idx])
                    goto next_name;
            }

            ALOGD("DRM_file_listNextEntry: matched %s", ent->d_name);

            /* Now generate the fully-qualified name */

            for (idx = 0; idx < *iteration; ++idx)
                entry[idx] = prefix[idx];

            for (idx = 0; idx < len; ++idx)
                entry[*iteration + idx] = (unsigned char)ent->d_name[idx];

            /*add "/" at the end of a DIR file entry*/
            if (getFileStat(entry, idx + *iteration, &sinfo)){
                if (S_ISDIR(sinfo.st_mode) &&
                        (idx + 1 + *iteration) < entrySize) {
                    entry[*iteration + idx] = '/';
                    ++idx;
                }
            }
            else
            {
                ALOGD("DRM_file_listNextEntry: stat FAILURE on %.*S",
                      idx + *iteration, entry);
            }
            ALOGD("DRM_file_listNextEntry: got %.*S", idx + *iteration, entry);

            return idx + *iteration;
        }

    next_name:
        ALOGD("DRM_file_listNextEntry: rejected %s", ent->d_name);
    }

    ALOGD("DRM_file_listNextEntry: end of list");
    return 0;
}

/* see drm_file.h */
int32_t
DRM_file_listClose(int32_t session, int32_t iteration)
{
    closedir( (DIR *)(long)session);
    return DRM_FILE_SUCCESS;
}