Commit e98901a4 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

PDF: Make DocumentLoader an interface.

To make it easier to write fake DocumentLoaders for testing. Split the
implementation off into DocumentLoaderImpl.

Change-Id: I44f16c757b8a9be133936c41c231a552a7e05f0a
Reviewed-on: https://chromium-review.googlesource.com/1013998
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatardsinclair <dsinclair@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553816}
parent b0478d0c
......@@ -36,8 +36,9 @@ if (enable_pdf) {
sources = [
"chunk_stream.h",
"document_loader.cc",
"document_loader.h",
"document_loader_impl.cc",
"document_loader_impl.h",
"draw_utils.cc",
"draw_utils.h",
"out_of_process_instance.cc",
......@@ -103,7 +104,7 @@ if (enable_pdf) {
test("pdf_unittests") {
sources = [
"chunk_stream_unittest.cc",
"document_loader_unittest.cc",
"document_loader_impl_unittest.cc",
"pdf_transform_unittest.cc",
"range_set_unittest.cc",
"run_all_unittests.cc",
......
......@@ -11,10 +11,6 @@
#include <memory>
#include <string>
#include "base/macros.h"
#include "pdf/chunk_stream.h"
#include "ppapi/utility/completion_callback_factory.h"
namespace pp {
class Instance;
}
......@@ -25,9 +21,6 @@ class URLLoaderWrapper;
class DocumentLoader {
public:
// Number was chosen in crbug.com/78264#c8
static constexpr uint32_t kDefaultRequestSize = 65536;
class Client {
public:
virtual ~Client() = default;
......@@ -48,84 +41,27 @@ class DocumentLoader {
virtual void CancelBrowserDownload() = 0;
};
explicit DocumentLoader(Client* client);
~DocumentLoader();
virtual ~DocumentLoader() = default;
bool Init(std::unique_ptr<URLLoaderWrapper> loader, const std::string& url);
virtual bool Init(std::unique_ptr<URLLoaderWrapper> loader,
const std::string& url) = 0;
// Data access interface. Return true if successful.
bool GetBlock(uint32_t position, uint32_t size, void* buf) const;
virtual bool GetBlock(uint32_t position, uint32_t size, void* buf) const = 0;
// Data availability interface. Return true if data is available.
bool IsDataAvailable(uint32_t position, uint32_t size) const;
virtual bool IsDataAvailable(uint32_t position, uint32_t size) const = 0;
// Data request interface.
void RequestData(uint32_t position, uint32_t size);
virtual void RequestData(uint32_t position, uint32_t size) {}
bool IsDocumentComplete() const;
void SetDocumentSize(uint32_t size);
uint32_t GetDocumentSize() const;
uint32_t bytes_received() const { return bytes_received_; }
virtual bool IsDocumentComplete() const = 0;
virtual void SetDocumentSize(uint32_t size) {}
virtual uint32_t GetDocumentSize() const = 0;
virtual uint32_t BytesReceived() const = 0;
// Clear pending requests from the queue.
void ClearPendingRequests();
// Exposed for unit tests.
void SetPartialLoadingEnabled(bool enabled);
bool is_partial_loader_active() const { return is_partial_loader_active_; }
private:
using DataStream = ChunkStream<kDefaultRequestSize>;
struct Chunk {
Chunk();
~Chunk();
void Clear();
uint32_t chunk_index = 0;
uint32_t data_size = 0;
std::unique_ptr<DataStream::ChunkData> chunk_data;
};
// Called by the completion callback of the document's URLLoader.
void DidOpenPartial(int32_t result);
// Call to read data from the document's URLLoader.
void ReadMore();
// Called by the completion callback of the document's URLLoader.
void DidRead(int32_t result);
bool ShouldCancelLoading() const;
void ContinueDownload();
// Called when we complete server request.
void ReadComplete();
bool SaveBuffer(char* input, uint32_t input_size);
void SaveChunkData();
uint32_t EndOfCurrentChunk() const;
Client* const client_;
std::string url_;
std::unique_ptr<URLLoaderWrapper> loader_;
pp::CompletionCallbackFactory<DocumentLoader> loader_factory_;
DataStream chunk_stream_;
bool partial_loading_enabled_ = true;
bool is_partial_loader_active_ = false;
static constexpr uint32_t kReadBufferSize = 256 * 1024;
char buffer_[kReadBufferSize];
// The current chunk DocumentLoader is working with.
Chunk chunk_;
// In units of Chunks.
RangeSet pending_requests_;
uint32_t bytes_received_ = 0;
DISALLOW_COPY_AND_ASSIGN(DocumentLoader);
virtual void ClearPendingRequests() {}
};
} // namespace chrome_pdf
......
......@@ -2,13 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/document_loader.h"
#include "pdf/document_loader_impl.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <utility>
#include "base/logging.h"
......@@ -53,23 +52,23 @@ bool IsValidContentType(const std::string& type) {
} // namespace
DocumentLoader::Chunk::Chunk() = default;
DocumentLoaderImpl::Chunk::Chunk() = default;
DocumentLoader::Chunk::~Chunk() = default;
DocumentLoaderImpl::Chunk::~Chunk() = default;
void DocumentLoader::Chunk::Clear() {
void DocumentLoaderImpl::Chunk::Clear() {
chunk_index = 0;
data_size = 0;
chunk_data.reset();
}
DocumentLoader::DocumentLoader(Client* client)
DocumentLoaderImpl::DocumentLoaderImpl(Client* client)
: client_(client), loader_factory_(this) {}
DocumentLoader::~DocumentLoader() = default;
DocumentLoaderImpl::~DocumentLoaderImpl() = default;
bool DocumentLoader::Init(std::unique_ptr<URLLoaderWrapper> loader,
const std::string& url) {
bool DocumentLoaderImpl::Init(std::unique_ptr<URLLoaderWrapper> loader,
const std::string& url) {
DCHECK(url_.empty());
DCHECK(!loader_);
......@@ -119,25 +118,29 @@ bool DocumentLoader::Init(std::unique_ptr<URLLoaderWrapper> loader,
return true;
}
bool DocumentLoader::IsDocumentComplete() const {
bool DocumentLoaderImpl::IsDocumentComplete() const {
return chunk_stream_.IsComplete();
}
void DocumentLoader::SetDocumentSize(uint32_t size) {
void DocumentLoaderImpl::SetDocumentSize(uint32_t size) {
chunk_stream_.set_eof_pos(size);
}
uint32_t DocumentLoader::GetDocumentSize() const {
uint32_t DocumentLoaderImpl::GetDocumentSize() const {
return chunk_stream_.eof_pos();
}
void DocumentLoader::ClearPendingRequests() {
uint32_t DocumentLoaderImpl::BytesReceived() const {
return bytes_received_;
}
void DocumentLoaderImpl::ClearPendingRequests() {
pending_requests_.Clear();
}
bool DocumentLoader::GetBlock(uint32_t position,
uint32_t size,
void* buf) const {
bool DocumentLoaderImpl::GetBlock(uint32_t position,
uint32_t size,
void* buf) const {
base::CheckedNumeric<uint32_t> addition_result = position;
addition_result += size;
if (!addition_result.IsValid())
......@@ -146,7 +149,8 @@ bool DocumentLoader::GetBlock(uint32_t position,
gfx::Range(position, addition_result.ValueOrDie()), buf);
}
bool DocumentLoader::IsDataAvailable(uint32_t position, uint32_t size) const {
bool DocumentLoaderImpl::IsDataAvailable(uint32_t position,
uint32_t size) const {
base::CheckedNumeric<uint32_t> addition_result = position;
addition_result += size;
if (!addition_result.IsValid())
......@@ -155,7 +159,7 @@ bool DocumentLoader::IsDataAvailable(uint32_t position, uint32_t size) const {
gfx::Range(position, addition_result.ValueOrDie()));
}
void DocumentLoader::RequestData(uint32_t position, uint32_t size) {
void DocumentLoaderImpl::RequestData(uint32_t position, uint32_t size) {
if (size == 0 || IsDataAvailable(position, size))
return;
......@@ -190,14 +194,14 @@ void DocumentLoader::RequestData(uint32_t position, uint32_t size) {
pending_requests_.Union(requested_chunks);
}
void DocumentLoader::SetPartialLoadingEnabled(bool enabled) {
void DocumentLoaderImpl::SetPartialLoadingEnabled(bool enabled) {
partial_loading_enabled_ = enabled;
if (!enabled) {
is_partial_loader_active_ = false;
}
}
bool DocumentLoader::ShouldCancelLoading() const {
bool DocumentLoaderImpl::ShouldCancelLoading() const {
if (!loader_)
return true;
if (!partial_loading_enabled_ || pending_requests_.IsEmpty())
......@@ -207,7 +211,7 @@ bool DocumentLoader::ShouldCancelLoading() const {
return !pending_requests_.Intersects(current_range);
}
void DocumentLoader::ContinueDownload() {
void DocumentLoaderImpl::ContinueDownload() {
if (!ShouldCancelLoading())
return ReadMore();
......@@ -252,10 +256,10 @@ void DocumentLoader::ContinueDownload() {
loader_->OpenRange(
url_, url_, start, length,
loader_factory_.NewCallback(&DocumentLoader::DidOpenPartial));
loader_factory_.NewCallback(&DocumentLoaderImpl::DidOpenPartial));
}
void DocumentLoader::DidOpenPartial(int32_t result) {
void DocumentLoaderImpl::DidOpenPartial(int32_t result) {
if (result != PP_OK) {
return ReadComplete();
}
......@@ -288,13 +292,13 @@ void DocumentLoader::DidOpenPartial(int32_t result) {
return ContinueDownload();
}
void DocumentLoader::ReadMore() {
void DocumentLoaderImpl::ReadMore() {
loader_->ReadResponseBody(
buffer_, sizeof(buffer_),
loader_factory_.NewCallback(&DocumentLoader::DidRead));
loader_factory_.NewCallback(&DocumentLoaderImpl::DidRead));
}
void DocumentLoader::DidRead(int32_t result) {
void DocumentLoaderImpl::DidRead(int32_t result) {
if (result < 0) {
// An error occurred.
// The renderer will detect that we're missing data and will display a
......@@ -322,7 +326,7 @@ void DocumentLoader::DidRead(int32_t result) {
return ContinueDownload();
}
bool DocumentLoader::SaveBuffer(char* input, uint32_t input_size) {
bool DocumentLoaderImpl::SaveBuffer(char* input, uint32_t input_size) {
const uint32_t document_size = GetDocumentSize();
if (document_size != 0) {
// If the HTTP server sends more data than expected, then truncate
......@@ -368,17 +372,17 @@ bool DocumentLoader::SaveBuffer(char* input, uint32_t input_size) {
return true;
}
void DocumentLoader::SaveChunkData() {
void DocumentLoaderImpl::SaveChunkData() {
chunk_stream_.SetChunkData(chunk_.chunk_index, std::move(chunk_.chunk_data));
chunk_.data_size = 0;
++chunk_.chunk_index;
}
uint32_t DocumentLoader::EndOfCurrentChunk() const {
uint32_t DocumentLoaderImpl::EndOfCurrentChunk() const {
return chunk_.chunk_index * DataStream::kChunkSize + chunk_.data_size;
}
void DocumentLoader::ReadComplete() {
void DocumentLoaderImpl::ReadComplete() {
if (GetDocumentSize() != 0) {
// If there is remaining data in |chunk_|, then save whatever can be saved.
// e.g. In the underrun case.
......
// Copyright 2018 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.
#ifndef PDF_DOCUMENT_LOADER_IMPL_H_
#define PDF_DOCUMENT_LOADER_IMPL_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "pdf/chunk_stream.h"
#include "pdf/document_loader.h"
#include "ppapi/utility/completion_callback_factory.h"
namespace chrome_pdf {
class DocumentLoaderImpl : public DocumentLoader {
public:
// Number was chosen in https://crbug.com/78264#c8
static constexpr uint32_t kDefaultRequestSize = 65536;
explicit DocumentLoaderImpl(Client* client);
~DocumentLoaderImpl() override;
// DocumentLoader:
bool Init(std::unique_ptr<URLLoaderWrapper> loader,
const std::string& url) override;
bool GetBlock(uint32_t position, uint32_t size, void* buf) const override;
bool IsDataAvailable(uint32_t position, uint32_t size) const override;
void RequestData(uint32_t position, uint32_t size) override;
bool IsDocumentComplete() const override;
void SetDocumentSize(uint32_t size) override;
uint32_t GetDocumentSize() const override;
uint32_t BytesReceived() const override;
void ClearPendingRequests() override;
// Exposed for unit tests.
void SetPartialLoadingEnabled(bool enabled);
bool is_partial_loader_active() const { return is_partial_loader_active_; }
private:
using DataStream = ChunkStream<kDefaultRequestSize>;
struct Chunk {
Chunk();
~Chunk();
void Clear();
uint32_t chunk_index = 0;
uint32_t data_size = 0;
std::unique_ptr<DataStream::ChunkData> chunk_data;
};
// Called by the completion callback of the document's URLLoader.
void DidOpenPartial(int32_t result);
// Call to read data from the document's URLLoader.
void ReadMore();
// Called by the completion callback of the document's URLLoader.
void DidRead(int32_t result);
bool ShouldCancelLoading() const;
void ContinueDownload();
// Called when we complete server request.
void ReadComplete();
bool SaveBuffer(char* input, uint32_t input_size);
void SaveChunkData();
uint32_t EndOfCurrentChunk() const;
Client* const client_;
std::string url_;
std::unique_ptr<URLLoaderWrapper> loader_;
pp::CompletionCallbackFactory<DocumentLoaderImpl> loader_factory_;
DataStream chunk_stream_;
bool partial_loading_enabled_ = true;
bool is_partial_loader_active_ = false;
static constexpr uint32_t kReadBufferSize = 256 * 1024;
char buffer_[kReadBufferSize];
// The current chunk DocumentLoader is working with.
Chunk chunk_;
// In units of Chunks.
RangeSet pending_requests_;
uint32_t bytes_received_ = 0;
DISALLOW_COPY_AND_ASSIGN(DocumentLoaderImpl);
};
} // namespace chrome_pdf
#endif // PDF_DOCUMENT_LOADER_IMPL_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/document_loader.h"
#include "pdf/document_loader_impl.h"
#include <algorithm>
#include <memory>
......@@ -25,7 +25,8 @@ namespace chrome_pdf {
namespace {
constexpr uint32_t kDefaultRequestSize = DocumentLoader::kDefaultRequestSize;
constexpr uint32_t kDefaultRequestSize =
DocumentLoaderImpl::kDefaultRequestSize;
class TestURLLoader : public URLLoaderWrapper {
public:
......@@ -263,12 +264,12 @@ class MockClient : public TestClient {
} // namespace
using DocumentLoaderTest = ::testing::Test;
using DocumentLoaderImplTest = ::testing::Test;
TEST_F(DocumentLoaderTest, PartialLoadingEnabled) {
TEST_F(DocumentLoaderImplTest, PartialLoadingEnabled) {
TestClient client;
client.SetCanUsePartialLoading();
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(1000000, 1);
EXPECT_FALSE(loader.is_partial_loader_active());
......@@ -277,11 +278,11 @@ TEST_F(DocumentLoaderTest, PartialLoadingEnabled) {
EXPECT_TRUE(loader.is_partial_loader_active());
}
TEST_F(DocumentLoaderTest, PartialLoadingDisabledOnSmallFiles) {
TEST_F(DocumentLoaderImplTest, PartialLoadingDisabledOnSmallFiles) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 2);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(1000000, 1);
EXPECT_FALSE(loader.is_partial_loader_active());
......@@ -290,11 +291,11 @@ TEST_F(DocumentLoaderTest, PartialLoadingDisabledOnSmallFiles) {
EXPECT_FALSE(loader.is_partial_loader_active());
}
TEST_F(DocumentLoaderTest, PartialLoadingDisabledIfContentEncoded) {
TEST_F(DocumentLoaderImplTest, PartialLoadingDisabledIfContentEncoded) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_encoded(true);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(1000000, 1);
EXPECT_FALSE(loader.is_partial_loader_active());
......@@ -303,11 +304,11 @@ TEST_F(DocumentLoaderTest, PartialLoadingDisabledIfContentEncoded) {
EXPECT_FALSE(loader.is_partial_loader_active());
}
TEST_F(DocumentLoaderTest, PartialLoadingDisabledNoAcceptRangeBytes) {
TEST_F(DocumentLoaderImplTest, PartialLoadingDisabledNoAcceptRangeBytes) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_accept_ranges_bytes(false);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(1000000, 1);
EXPECT_FALSE(loader.is_partial_loader_active());
......@@ -316,9 +317,9 @@ TEST_F(DocumentLoaderTest, PartialLoadingDisabledNoAcceptRangeBytes) {
EXPECT_FALSE(loader.is_partial_loader_active());
}
TEST_F(DocumentLoaderTest, PartialLoadingReallyDisabledRequestFromBegin) {
TEST_F(DocumentLoaderImplTest, PartialLoadingReallyDisabledRequestFromBegin) {
TestClient client;
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
client.SetCanUsePartialLoading();
loader.SetPartialLoadingEnabled(false);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
......@@ -331,10 +332,10 @@ TEST_F(DocumentLoaderTest, PartialLoadingReallyDisabledRequestFromBegin) {
EXPECT_FALSE(loader.is_partial_loader_active());
}
TEST_F(DocumentLoaderTest, PartialLoadingReallyDisabledRequestFromMiddle) {
TEST_F(DocumentLoaderImplTest, PartialLoadingReallyDisabledRequestFromMiddle) {
TestClient client;
client.SetCanUsePartialLoading();
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.SetPartialLoadingEnabled(false);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(1000000, 1);
......@@ -344,11 +345,11 @@ TEST_F(DocumentLoaderTest, PartialLoadingReallyDisabledRequestFromMiddle) {
EXPECT_FALSE(loader.is_partial_loader_active());
}
TEST_F(DocumentLoaderTest, PartialLoadingSimple) {
TEST_F(DocumentLoaderImplTest, PartialLoadingSimple) {
TestClient client;
client.SetCanUsePartialLoading();
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
// While we have no requests, we should not start partial loading.
......@@ -372,11 +373,11 @@ TEST_F(DocumentLoaderTest, PartialLoadingSimple) {
client.partial_loader_data()->open_byte_range().ToString());
}
TEST_F(DocumentLoaderTest, PartialLoadingBackOrder) {
TEST_F(DocumentLoaderImplTest, PartialLoadingBackOrder) {
TestClient client;
client.SetCanUsePartialLoading();
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
// While we have no requests, we should not start partial loading.
......@@ -402,10 +403,10 @@ TEST_F(DocumentLoaderTest, PartialLoadingBackOrder) {
client.partial_loader_data()->open_byte_range().ToString());
}
TEST_F(DocumentLoaderTest, CompleteWithoutPartial) {
TEST_F(DocumentLoaderImplTest, CompleteWithoutPartial) {
TestClient client;
client.SetCanUsePartialLoading();
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_FALSE(client.full_page_loader_data()->closed());
while (client.full_page_loader_data()->IsWaitRead()) {
......@@ -415,10 +416,10 @@ TEST_F(DocumentLoaderTest, CompleteWithoutPartial) {
EXPECT_TRUE(client.full_page_loader_data()->closed());
}
TEST_F(DocumentLoaderTest, ErrorDownloadFullDocument) {
TEST_F(DocumentLoaderImplTest, ErrorDownloadFullDocument) {
TestClient client;
client.SetCanUsePartialLoading();
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_TRUE(client.full_page_loader_data()->IsWaitRead());
EXPECT_FALSE(client.full_page_loader_data()->closed());
......@@ -427,9 +428,9 @@ TEST_F(DocumentLoaderTest, ErrorDownloadFullDocument) {
EXPECT_FALSE(loader.IsDocumentComplete());
}
TEST_F(DocumentLoaderTest, CompleteNoContentLength) {
TEST_F(DocumentLoaderImplTest, CompleteNoContentLength) {
TestClient client;
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_FALSE(client.full_page_loader_data()->closed());
for (int i = 0; i < 10; ++i) {
......@@ -443,11 +444,11 @@ TEST_F(DocumentLoaderTest, CompleteNoContentLength) {
EXPECT_TRUE(client.full_page_loader_data()->closed());
}
TEST_F(DocumentLoaderTest, CompleteWithPartial) {
TEST_F(DocumentLoaderImplTest, CompleteWithPartial) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(19 * kDefaultRequestSize, kDefaultRequestSize);
EXPECT_FALSE(client.full_page_loader_data()->closed());
......@@ -466,13 +467,13 @@ TEST_F(DocumentLoaderTest, CompleteWithPartial) {
EXPECT_TRUE(client.partial_loader_data()->closed());
}
TEST_F(DocumentLoaderTest, PartialRequestLastChunk) {
TEST_F(DocumentLoaderImplTest, PartialRequestLastChunk) {
const uint32_t kLastChunkSize = 300;
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20 +
kLastChunkSize);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(20 * kDefaultRequestSize, 1);
......@@ -496,19 +497,19 @@ TEST_F(DocumentLoaderTest, PartialRequestLastChunk) {
EXPECT_TRUE(loader.IsDataAvailable(kDefaultRequestSize * 20, kLastChunkSize));
}
TEST_F(DocumentLoaderTest, DocumentSize) {
TEST_F(DocumentLoaderImplTest, DocumentSize) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(123456789);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_EQ(static_cast<int>(loader.GetDocumentSize()),
client.full_page_loader_data()->content_length());
}
TEST_F(DocumentLoaderTest, DocumentSizeNoContentLength) {
TEST_F(DocumentLoaderImplTest, DocumentSizeNoContentLength) {
TestClient client;
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_EQ(0ul, loader.GetDocumentSize());
client.full_page_loader_data()->CallReadCallback(kDefaultRequestSize);
......@@ -519,12 +520,12 @@ TEST_F(DocumentLoaderTest, DocumentSizeNoContentLength) {
EXPECT_TRUE(loader.IsDocumentComplete());
}
TEST_F(DocumentLoaderTest, ClearPendingRequests) {
TEST_F(DocumentLoaderImplTest, ClearPendingRequests) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 100 +
58383);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(17 * kDefaultRequestSize + 100, 10);
loader.ClearPendingRequests();
......@@ -608,13 +609,13 @@ TEST_F(DocumentLoaderTest, ClearPendingRequests) {
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
}
TEST_F(DocumentLoaderTest, GetBlock) {
TEST_F(DocumentLoaderImplTest, GetBlock) {
std::vector<char> buffer(kDefaultRequestSize);
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20 +
58383);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_FALSE(loader.GetBlock(0, 1000, buffer.data()));
client.full_page_loader_data()->CallReadCallback(kDefaultRequestSize);
......@@ -634,12 +635,12 @@ TEST_F(DocumentLoaderTest, GetBlock) {
EXPECT_TRUE(loader.GetBlock(17 * kDefaultRequestSize, 3000, buffer.data()));
}
TEST_F(DocumentLoaderTest, IsDataAvailable) {
TEST_F(DocumentLoaderImplTest, IsDataAvailable) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20 +
58383);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_FALSE(loader.IsDataAvailable(0, 1000));
client.full_page_loader_data()->CallReadCallback(kDefaultRequestSize);
......@@ -659,12 +660,12 @@ TEST_F(DocumentLoaderTest, IsDataAvailable) {
EXPECT_TRUE(loader.IsDataAvailable(17 * kDefaultRequestSize, 3000));
}
TEST_F(DocumentLoaderTest, RequestData) {
TEST_F(DocumentLoaderImplTest, RequestData) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 100 +
58383);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(37 * kDefaultRequestSize + 200, 10);
loader.RequestData(25 * kDefaultRequestSize + 600, 100);
......@@ -726,12 +727,12 @@ TEST_F(DocumentLoaderTest, RequestData) {
EXPECT_TRUE(client.partial_loader_data()->closed());
}
TEST_F(DocumentLoaderTest, DoNotLoadAvailablePartialData) {
TEST_F(DocumentLoaderImplTest, DoNotLoadAvailablePartialData) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20 +
58383);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
// Send initial data from FullPageLoader.
client.full_page_loader_data()->CallReadCallback(kDefaultRequestSize);
......@@ -748,11 +749,11 @@ TEST_F(DocumentLoaderTest, DoNotLoadAvailablePartialData) {
EXPECT_TRUE(client.partial_loader_data()->closed());
}
TEST_F(DocumentLoaderTest, DoNotLoadDataAfterComplete) {
TEST_F(DocumentLoaderImplTest, DoNotLoadDataAfterComplete) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
for (int i = 0; i < 20; ++i) {
......@@ -767,11 +768,11 @@ TEST_F(DocumentLoaderTest, DoNotLoadDataAfterComplete) {
EXPECT_TRUE(client.full_page_loader_data()->closed());
}
TEST_F(DocumentLoaderTest, DoNotLoadPartialDataAboveDocumentSize) {
TEST_F(DocumentLoaderImplTest, DoNotLoadPartialDataAboveDocumentSize) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(20 * kDefaultRequestSize + 200, 10);
......@@ -782,12 +783,12 @@ TEST_F(DocumentLoaderTest, DoNotLoadPartialDataAboveDocumentSize) {
EXPECT_TRUE(client.partial_loader_data()->closed());
}
TEST_F(DocumentLoaderTest, MergePendingRequests) {
TEST_F(DocumentLoaderImplTest, MergePendingRequests) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 50 +
58383);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(17 * kDefaultRequestSize + 200, 10);
loader.RequestData(16 * kDefaultRequestSize + 600, 100);
......@@ -811,11 +812,11 @@ TEST_F(DocumentLoaderTest, MergePendingRequests) {
EXPECT_TRUE(client.partial_loader_data()->closed());
}
TEST_F(DocumentLoaderTest, PartialStopOnStatusCodeError) {
TEST_F(DocumentLoaderImplTest, PartialStopOnStatusCodeError) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(17 * kDefaultRequestSize + 200, 10);
......@@ -829,12 +830,12 @@ TEST_F(DocumentLoaderTest, PartialStopOnStatusCodeError) {
EXPECT_TRUE(client.partial_loader_data()->closed());
}
TEST_F(DocumentLoaderTest,
TEST_F(DocumentLoaderImplTest,
PartialAsFullDocumentLoadingRangeRequestNoRangeField) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(17 * kDefaultRequestSize + 200, 10);
......@@ -850,11 +851,11 @@ TEST_F(DocumentLoaderTest,
EXPECT_FALSE(loader.is_partial_loader_active());
}
TEST_F(DocumentLoaderTest, PartialMultiPart) {
TEST_F(DocumentLoaderImplTest, PartialMultiPart) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(17 * kDefaultRequestSize + 200, 10);
......@@ -872,11 +873,11 @@ TEST_F(DocumentLoaderTest, PartialMultiPart) {
loader.IsDataAvailable(17 * kDefaultRequestSize, kDefaultRequestSize));
}
TEST_F(DocumentLoaderTest, PartialMultiPartRangeError) {
TEST_F(DocumentLoaderImplTest, PartialMultiPartRangeError) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(17 * kDefaultRequestSize + 200, 10);
......@@ -894,11 +895,11 @@ TEST_F(DocumentLoaderTest, PartialMultiPartRangeError) {
EXPECT_TRUE(client.partial_loader_data()->closed());
}
TEST_F(DocumentLoaderTest, PartialConnectionErrorOnOpen) {
TEST_F(DocumentLoaderImplTest, PartialConnectionErrorOnOpen) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(17 * kDefaultRequestSize + 200, 10);
......@@ -917,11 +918,11 @@ TEST_F(DocumentLoaderTest, PartialConnectionErrorOnOpen) {
EXPECT_TRUE(client.partial_loader_data()->closed());
}
TEST_F(DocumentLoaderTest, PartialConnectionErrorOnRead) {
TEST_F(DocumentLoaderImplTest, PartialConnectionErrorOnRead) {
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(17 * kDefaultRequestSize + 200, 10);
......@@ -944,11 +945,11 @@ TEST_F(DocumentLoaderTest, PartialConnectionErrorOnRead) {
EXPECT_TRUE(client.partial_loader_data()->closed());
}
TEST_F(DocumentLoaderTest, ClientCompleteCallbacks) {
TEST_F(DocumentLoaderImplTest, ClientCompleteCallbacks) {
MockClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_CALL(client, OnDocumentComplete()).Times(0);
......@@ -961,9 +962,9 @@ TEST_F(DocumentLoaderTest, ClientCompleteCallbacks) {
Mock::VerifyAndClear(&client);
}
TEST_F(DocumentLoaderTest, ClientCompleteCallbacksNoContentLength) {
TEST_F(DocumentLoaderImplTest, ClientCompleteCallbacksNoContentLength) {
MockClient client;
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_CALL(client, OnDocumentCanceled()).Times(0);
......@@ -978,11 +979,11 @@ TEST_F(DocumentLoaderTest, ClientCompleteCallbacksNoContentLength) {
Mock::VerifyAndClear(&client);
}
TEST_F(DocumentLoaderTest, ClientCancelCallback) {
TEST_F(DocumentLoaderImplTest, ClientCancelCallback) {
MockClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_CALL(client, OnDocumentCanceled()).Times(0);
......@@ -997,11 +998,11 @@ TEST_F(DocumentLoaderTest, ClientCancelCallback) {
Mock::VerifyAndClear(&client);
}
TEST_F(DocumentLoaderTest, NewDataAvailable) {
TEST_F(DocumentLoaderImplTest, NewDataAvailable) {
MockClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20);
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_CALL(client, OnNewDataReceived()).Times(1);
......@@ -1017,10 +1018,10 @@ TEST_F(DocumentLoaderTest, NewDataAvailable) {
Mock::VerifyAndClear(&client);
}
TEST_F(DocumentLoaderTest, ClientPendingRequestCompleteFullLoader) {
TEST_F(DocumentLoaderImplTest, ClientPendingRequestCompleteFullLoader) {
MockClient client;
client.SetCanUsePartialLoading();
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
loader.RequestData(1000, 4000);
......@@ -1030,10 +1031,10 @@ TEST_F(DocumentLoaderTest, ClientPendingRequestCompleteFullLoader) {
Mock::VerifyAndClear(&client);
}
TEST_F(DocumentLoaderTest, ClientPendingRequestCompletePartialLoader) {
TEST_F(DocumentLoaderImplTest, ClientPendingRequestCompletePartialLoader) {
MockClient client;
client.SetCanUsePartialLoading();
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_CALL(client, OnPendingRequestComplete()).Times(1);
......@@ -1046,10 +1047,11 @@ TEST_F(DocumentLoaderTest, ClientPendingRequestCompletePartialLoader) {
Mock::VerifyAndClear(&client);
}
TEST_F(DocumentLoaderTest, ClientPendingRequestCompletePartialAndFullLoader) {
TEST_F(DocumentLoaderImplTest,
ClientPendingRequestCompletePartialAndFullLoader) {
MockClient client;
client.SetCanUsePartialLoading();
DocumentLoader loader(&client);
DocumentLoaderImpl loader(&client);
loader.Init(client.CreateFullPageLoader(), "http://url.com");
EXPECT_CALL(client, OnPendingRequestComplete()).Times(1);
......
......@@ -30,6 +30,7 @@
#include "gin/array_buffer.h"
#include "gin/public/gin_embedders.h"
#include "gin/public/isolate_holder.h"
#include "pdf/document_loader_impl.h"
#include "pdf/draw_utils.h"
#include "pdf/pdf_transform.h"
#include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
......@@ -1226,7 +1227,7 @@ bool PDFiumEngine::HandleDocumentLoad(const pp::URLLoader& loader) {
std::make_unique<URLLoaderWrapperImpl>(GetPluginInstance(), loader);
loader_wrapper->SetResponseHeaders(headers_);
doc_loader_ = std::make_unique<DocumentLoader>(this);
doc_loader_ = std::make_unique<DocumentLoaderImpl>(this);
if (doc_loader_->Init(std::move(loader_wrapper), url_)) {
// request initial data.
doc_loader_->RequestData(0, 1);
......@@ -1318,7 +1319,7 @@ void PDFiumEngine::OnPendingRequestComplete() {
}
void PDFiumEngine::OnNewDataReceived() {
client_->DocumentLoadProgress(doc_loader_->bytes_received(),
client_->DocumentLoadProgress(doc_loader_->BytesReceived(),
doc_loader_->GetDocumentSize());
}
......@@ -1388,7 +1389,7 @@ void PDFiumEngine::FinishLoadingDocument() {
document_features.is_tagged = FPDFCatalog_IsTagged(doc_);
document_features.form_type = static_cast<FormType>(FPDF_GetFormType(doc_));
client_->DocumentLoadComplete(document_features,
doc_loader_->bytes_received());
doc_loader_->BytesReceived());
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment