#include "config.h"
#include "V8Utilities.h"
#include <v8.h>
#include "V8CustomBinding.h"
#include "V8Proxy.h"
#include <wtf/Assertions.h>
#include "Frame.h"
namespace WebCore {
void createHiddenDependency(v8::Local<v8::Object> object, v8::Local<v8::Value> value, int cacheIndex)
{
v8::Local<v8::Value> cache = object->GetInternalField(cacheIndex);
if (cache->IsNull() || cache->IsUndefined()) {
cache = v8::Array::New();
object->SetInternalField(cacheIndex, cache);
}
v8::Local<v8::Array> cacheArray = v8::Local<v8::Array>::Cast(cache);
cacheArray->Set(v8::Integer::New(cacheArray->Length()), value);
}
void removeHiddenDependency(v8::Local<v8::Object> object, v8::Local<v8::Value> value, int cacheIndex)
{
v8::Local<v8::Value> cache = object->GetInternalField(cacheIndex);
ASSERT(cache->IsArray());
v8::Local<v8::Array> cacheArray = v8::Local<v8::Array>::Cast(cache);
for (int i = cacheArray->Length() - 1; i >= 0; --i) {
v8::Local<v8::Value> cached = cacheArray->Get(v8::Integer::New(i));
if (cached->StrictEquals(value)) {
cacheArray->Delete(i);
return;
}
}
ASSERT_NOT_REACHED();
}
bool processingUserGesture()
{
Frame* frame = V8Proxy::retrieveFrameForEnteredContext();
return frame && frame->script()->processingUserGesture();
}
bool shouldAllowNavigation(Frame* frame)
{
Frame* callingFrame = V8Proxy::retrieveFrameForCallingContext();
return callingFrame && callingFrame->loader()->shouldAllowNavigation(frame);
}
KURL completeURL(const String& relativeURL)
{
Frame* frame = V8Proxy::retrieveFrameForEnteredContext();
if (!frame)
return KURL();
return frame->loader()->completeURL(relativeURL);
}
void navigateIfAllowed(Frame* frame, const KURL& url, bool lockHistory, bool lockBackForwardList)
{
Frame* callingFrame = V8Proxy::retrieveFrameForCallingContext();
if (!callingFrame)
return;
if (!protocolIsJavaScript(url) || ScriptController::isSafeScript(frame))
frame->loader()->scheduleLocationChange(url.string(), callingFrame->loader()->outgoingReferrer(), lockHistory, lockBackForwardList, processingUserGesture());
}
}