blob: e18e01821f90ae83f4acb841236639844bc812be [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/fileapi/URLFileAPI.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ScriptState.h"
#include "core/dom/DOMURL.h"
#include "core/dom/ExecutionContext.h"
#include "core/fileapi/Blob.h"
#include "core/frame/UseCounter.h"
#include "core/html/PublicURLManager.h"
namespace blink {
// static
String URLFileAPI::createObjectURL(ScriptState* scriptState,
Blob* blob,
ExceptionState& exceptionState) {
DCHECK(blob);
ExecutionContext* executionContext = scriptState->getExecutionContext();
DCHECK(executionContext);
if (blob->isClosed()) {
// TODO(jsbell): The spec doesn't throw, but rather returns a blob: URL
// without adding it to the store.
exceptionState.throwDOMException(
InvalidStateError,
String(blob->isFile() ? "File" : "Blob") + " has been closed.");
return String();
}
UseCounter::count(executionContext, UseCounter::CreateObjectURLBlob);
return DOMURL::createPublicURL(executionContext, blob, blob->uuid());
}
// static
void URLFileAPI::revokeObjectURL(ScriptState* scriptState,
const String& urlString) {
ExecutionContext* executionContext = scriptState->getExecutionContext();
DCHECK(executionContext);
KURL url(KURL(), urlString);
executionContext->removeURLFromMemoryCache(url);
executionContext->publicURLManager().revoke(url);
}
} // namespace blink