summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/network/android/ResourceHandleAndroid.cpp
blob: 35b3c5b517d8d8b8820658a8c450118fc18237dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* 
**
** Copyright 2007, The Android Open Source Project
**
** 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 "config.h"
#include "ResourceHandle.h"

#include "DocLoader.h"
#include "FrameAndroid.h"
#include "ResourceHandleClient.h"
#include "ResourceHandleInternal.h"
#include "WebCoreFrameBridge.h"
#include "WebCoreResourceLoader.h"

// #define notImplemented() do { fprintf(stderr, "FIXME: UNIMPLEMENTED %s %s:%d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); } while(0)

namespace WebCore {

ResourceHandleInternal::~ResourceHandleInternal()
{
    Release(m_loader);
}

ResourceHandle::~ResourceHandle()
{
}

bool ResourceHandle::start(Frame* frame)
{
    FrameAndroid* f = Android(frame);
    android::WebCoreResourceLoader* loader;
    bool highPriority = true;
    CachedResource* r = d->m_request.getCachedResource();
    if (r) {
        CachedResource::Type t = r->type();
        highPriority = !(t == CachedResource::ImageResource ||
                       t == CachedResource::FontResource);
    }
    loader = f->bridge()->startLoadingResource(this, d->m_request, highPriority, false);

    if (loader) {
        Release(d->m_loader);
        d->m_loader = loader;
    }

    return loader != NULL;
}

void ResourceHandle::cancel()
{
    if (d->m_loader)
        d->m_loader->cancel();
}

PassRefPtr<SharedBuffer> ResourceHandle::bufferedData()
{
    return 0;
}

bool ResourceHandle::supportsBufferedData()
{
    // We don't support buffering data on the native side.
    return false;
}

void ResourceHandle::setDefersLoading(bool defers)
{
    notImplemented();
}

/*
* This static method is called to check to see if a POST response is in
* the cache. The JNI call through to the HTTP cache stored on the Java
* side may be slow, but is only used during a navigation to
* a POST response.
*/
bool ResourceHandle::willLoadFromCache(ResourceRequest& request) 
{
    // set the cache policy correctly, copied from
    // network/mac/ResourceHandleMac.mm
    request.setCachePolicy(ReturnCacheDataDontLoad);
    return android::WebCoreResourceLoader::willLoadFromCache(request.url());
}

bool ResourceHandle::loadsBlocked() 
{
    // FIXME, need to check whether connection pipe is blocked.
    // return false for now
    return false; 
}

// Class to handle synchronized loading of resources.
class SyncLoader : public ResourceHandleClient {
public:
    SyncLoader(ResourceError& error, ResourceResponse& response, Vector<char>& data) {
        m_error = &error;
        m_response = &response;
        m_data = &data;
    }
    ~SyncLoader() {}

    virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse& response) {
        *m_response = response;
    }

    virtual void didReceiveData(ResourceHandle*, const char* data, int len, int lengthReceived) {
        m_data->append(data, len);
    }

    virtual void didFail(ResourceHandle*, const ResourceError& error) {
        *m_error = error;
    }

private:
    ResourceError*    m_error;
    ResourceResponse* m_response;
    Vector<char>*     m_data;
};

void ResourceHandle::loadResourceSynchronously(const ResourceRequest& request, 
        ResourceError& error, ResourceResponse& response, Vector<char>& data,
        Frame* frame) 
{
    FrameAndroid* f = Android(frame);
    SyncLoader s(error, response, data);
    ResourceHandle h(request, &s, false, false, false);
    // This blocks until the load is finished.
    f->bridge()->startLoadingResource(&h, request, true, true);
}

} // namespace WebCore