<commit_before>/*
 * Copyright 2011, 2012 Esrille Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "HTMLObjectElementImp.h"

#include <boost/bind.hpp>

#include "DocumentImp.h"
#include "css/Box.h"

namespace org
{
namespace w3c
{
namespace dom
{
namespace bootstrap
{

HTMLObjectElementImp::HTMLObjectElementImp(DocumentImp* ownerDocument) :
    ObjectMixin(ownerDocument, u"object"),
    request(0),
    active(true),
    image(0)
{
}

HTMLObjectElementImp::HTMLObjectElementImp(HTMLObjectElementImp* org, bool deep) :
    ObjectMixin(org, deep),
    request(0), // TODO
    active(org->active),
    image(0)    // TODO
{
}

HTMLObjectElementImp::~HTMLObjectElementImp()
{
    delete request;
    delete image;
}

void HTMLObjectElementImp::eval()
{
    HTMLElementImp::eval();
    HTMLElementImp::evalBorder(this);
    HTMLElementImp::evalHeight(this);
    HTMLElementImp::evalWidth(this);
    HTMLElementImp::evalHspace(this);
    HTMLElementImp::evalVspace(this);

    std::u16string classid = getAttribute(u"classid");
    if (!classid.empty()) {
        active = false;
        return;
    }
    std::u16string data = getAttribute(u"data");
    if (data.empty()) {
        active = false;
        return;
    }
    std::u16string type = getAttribute(u"type");
    // TODO: Check type is a supported one.

    DocumentImp* document = getOwnerDocumentImp();
    request = new(std::nothrow) HttpRequest(document->getDocumentURI());
    if (request) {
        request->open(u"GET", data);
        request->setHanndler(boost::bind(&HTMLObjectElementImp::notify, this));
        document->incrementLoadEventDelayCount();
        request->send();
    } else
        active = false;
}

void HTMLObjectElementImp::notify()
{
    if (request->getStatus() != 200)
        active = false;
    else {
        // TODO: Check type
        image = new(std::nothrow) BoxImage();
        if (!image)
            active = false;
        else {
            if (FILE* file = request->openFile()) {
                image->open(file);
                fclose(file);
            }
            if (image->getState() != BoxImage::CompletelyAvailable) {
                active = false;
                delete image;
                image = 0;
            }
        }
    }
    // TODO: fire 'load' or 'error' event
    DocumentImp* document = getOwnerDocumentImp();
    document->decrementLoadEventDelayCount();
}
<commit_msg>(HTMLObjectElementImp::notify) : Trigger window redraw.<commit_after>/*
 * Copyright 2011, 2012 Esrille Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "HTMLObjectElementImp.h"

#include <boost/bind.hpp>

#include "DocumentImp.h"
#include "css/Box.h"

namespace org
{
namespace w3c
{
namespace dom
{
namespace bootstrap
{

HTMLObjectElementImp::HTMLObjectElementImp(DocumentImp* ownerDocument) :
    ObjectMixin(ownerDocument, u"object"),
    request(0),
    active(true),
    image(0)
{
}

HTMLObjectElementImp::HTMLObjectElementImp(HTMLObjectElementImp* org, bool deep) :
    ObjectMixin(org, deep),
    request(0), // TODO
    active(org->active),
    image(0)    // TODO
{
}

HTMLObjectElementImp::~HTMLObjectElementImp()
{
    delete request;
    delete image;
}

void HTMLObjectElementImp::eval()
{
    HTMLElementImp::eval();
    HTMLElementImp::evalBorder(this);
    HTMLElementImp::evalHeight(this);
    HTMLElementImp::evalWidth(this);
    HTMLElementImp::evalHspace(this);
    HTMLElementImp::evalVspace(this);

    if (!active)
        return;

    std::u16string classid = getAttribute(u"classid");
    if (!classid.empty()) {
        active = false;
        return;
    }
    std::u16string data = getAttribute(u"data");
    if (data.empty()) {
        active = false;
        return;
    }
    std::u16string type = getAttribute(u"type");
    // TODO: Check type is a supported one.

    DocumentImp* document = getOwnerDocumentImp();
    request = new(std::nothrow) HttpRequest(document->getDocumentURI());
    if (request) {
        request->open(u"GET", data);
        request->setHanndler(boost::bind(&HTMLObjectElementImp::notify, this));
        document->incrementLoadEventDelayCount();
        request->send();
    } else
        active = false;
}

void HTMLObjectElementImp::notify()
{
    if (request->getStatus() != 200)
        active = false;
    else {
        // TODO: Check type
        image = new(std::nothrow) BoxImage();
        if (!image)
            active = false;
        else {
            if (FILE* file = request->openFile()) {
                image->open(file);
                fclose(file);
            }
            if (image->getState() != BoxImage::CompletelyAvailable) {
                active = false;
                delete image;
                image = 0;
            }
        }
    }
    // TODO: fire 'load' or 'error' event
    if (Box* box = getBox())
        box->setFlags(1);
    DocumentImp* document = getOwnerDocumentImp();
    document->decrementLoadEventDelayCount();
}

{'fraction_non_alphanumeric': 0.12122728030682008, 'fraction_numerical': 0.009171252292813074, 'mean_word_length': 2.857234726688103, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4208363', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1744, 'n_words': 447}