Commit 0734e1b8 authored by K. Moon's avatar K. Moon Committed by Commit Bot

Add a skeletal chrome_pdf::BlinkUrlLoader

Adds a skeletal Blink implementation of chrome_pdf::UrlLoader. Almost
all functionality is left as NOTIMPLEMENTED(), although this change does
include basic lifetime management for the blink::WebAssociatedURLLoader
and related classes.

Bug: 1099022
Change-Id: I6ed1e0b5e6f02cd83fef1f8664c18a33c9b0f8e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2387202
Commit-Queue: K. Moon <kmoon@chromium.org>
Reviewed-by: default avatarDaniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803694}
parent 97c6e448
......@@ -208,6 +208,7 @@ if (enable_pdf) {
"//base",
"//ppapi/cpp:objects",
"//skia",
"//third_party/blink/public:blink",
"//ui/base",
]
}
......
......@@ -10,6 +10,9 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/check.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
#include "pdf/ppapi_migration/callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
......@@ -20,6 +23,9 @@
#include "ppapi/cpp/url_request_info.h"
#include "ppapi/cpp/url_response_info.h"
#include "ppapi/cpp/var.h"
#include "third_party/blink/public/web/web_associated_url_loader.h"
#include "third_party/blink/public/web/web_associated_url_loader_options.h"
#include "third_party/blink/public/web/web_local_frame.h"
namespace chrome_pdf {
......@@ -40,6 +46,91 @@ UrlResponse::~UrlResponse() = default;
UrlLoader::UrlLoader() = default;
UrlLoader::~UrlLoader() = default;
BlinkUrlLoader::BlinkUrlLoader(base::WeakPtr<Client> client)
: client_(std::move(client)) {}
BlinkUrlLoader::~BlinkUrlLoader() = default;
void BlinkUrlLoader::GrantUniversalAccess() {
NOTIMPLEMENTED();
}
// Modeled on `content::PepperURLLoaderHost::OnHostMsgOpen()`.
void BlinkUrlLoader::Open(const UrlRequest& request, ResultCallback callback) {
if (!client_) {
std::move(callback).Run(PP_ERROR_FAILED);
return;
}
blink::WebLocalFrame* frame = client_->GetFrame();
if (!frame) {
std::move(callback).Run(PP_ERROR_FAILED);
return;
}
blink::WebAssociatedURLLoaderOptions options;
blink_loader_.reset(frame->CreateAssociatedURLLoader(options));
DCHECK(blink_loader_);
NOTIMPLEMENTED();
}
bool BlinkUrlLoader::GetDownloadProgress(
int64_t& bytes_received,
int64_t& total_bytes_to_be_received) const {
NOTIMPLEMENTED();
return false;
}
void BlinkUrlLoader::ReadResponseBody(base::span<char> buffer,
ResultCallback callback) {
NOTIMPLEMENTED();
}
void BlinkUrlLoader::Close() {
NOTIMPLEMENTED();
}
bool BlinkUrlLoader::WillFollowRedirect(
const blink::WebURL& new_url,
const blink::WebURLResponse& redirect_response) {
NOTIMPLEMENTED();
return false;
}
void BlinkUrlLoader::DidSendData(uint64_t bytes_sent,
uint64_t total_bytes_to_be_sent) {
// Doesn't apply to PDF viewer requests.
NOTREACHED();
}
void BlinkUrlLoader::DidReceiveResponse(const blink::WebURLResponse& response) {
NOTIMPLEMENTED();
}
void BlinkUrlLoader::DidDownloadData(uint64_t data_length) {
// Doesn't apply to PDF viewer requests.
NOTREACHED();
}
void BlinkUrlLoader::DidReceiveData(const char* data, int data_length) {
NOTIMPLEMENTED();
}
void BlinkUrlLoader::DidReceiveCachedMetadata(const char* data,
int data_length) {
// Doesn't apply to PDF viewer requests.
NOTREACHED();
}
void BlinkUrlLoader::DidFinishLoading() {
NOTIMPLEMENTED();
}
void BlinkUrlLoader::DidFail(const blink::WebURLError& error) {
NOTIMPLEMENTED();
}
PepperUrlLoader::PepperUrlLoader(pp::InstanceHandle plugin_instance)
: plugin_instance_(plugin_instance), pepper_loader_(plugin_instance) {}
......
......@@ -7,6 +7,7 @@
#include <stdint.h>
#include <memory>
#include <string>
#include "base/containers/span.h"
......@@ -16,6 +17,12 @@
#include "pdf/ppapi_migration/callback.h"
#include "ppapi/cpp/instance_handle.h"
#include "ppapi/cpp/url_loader.h"
#include "third_party/blink/public/web/web_associated_url_loader_client.h"
namespace blink {
class WebAssociatedURLLoader;
class WebLocalFrame;
} // namespace blink
namespace chrome_pdf {
......@@ -65,7 +72,6 @@ struct UrlResponse final {
};
// Abstraction for a Blink or Pepper URL loader.
// TODO(crbug.com/1099022): Implement the Blink URL loader.
class UrlLoader : public base::RefCounted<UrlLoader> {
public:
UrlLoader(const UrlLoader&) = delete;
......@@ -101,6 +107,59 @@ class UrlLoader : public base::RefCounted<UrlLoader> {
UrlResponse response_;
};
// A Blink URL loader. This implementation tries to emulate a combination of
// `content::PepperURLLoaderHost` and `ppapi::proxy::URLLoaderResource`.
class BlinkUrlLoader final : public UrlLoader,
public blink::WebAssociatedURLLoaderClient {
public:
// Client interface required by `BlinkUrlLoader`. Instances should be passed
// using weak pointers, as the loader can be shared, and may outlive the
// client.
class Client {
public:
// Returns the current local frame. May return `nullptr` if the local frame
// no longer exists.
virtual blink::WebLocalFrame* GetFrame() = 0;
protected:
~Client() = default;
};
explicit BlinkUrlLoader(base::WeakPtr<Client> client);
BlinkUrlLoader(const BlinkUrlLoader&) = delete;
BlinkUrlLoader& operator=(const BlinkUrlLoader&) = delete;
// UrlLoader:
void GrantUniversalAccess() override;
void Open(const UrlRequest& request, ResultCallback callback) override;
bool GetDownloadProgress(int64_t& bytes_received,
int64_t& total_bytes_to_be_received) const override;
void ReadResponseBody(base::span<char> buffer,
ResultCallback callback) override;
void Close() override;
// blink::WebAssociatedURLLoaderClient:
bool WillFollowRedirect(
const blink::WebURL& new_url,
const blink::WebURLResponse& redirect_response) override;
void DidSendData(uint64_t bytes_sent,
uint64_t total_bytes_to_be_sent) override;
void DidReceiveResponse(const blink::WebURLResponse& response) override;
void DidDownloadData(uint64_t data_length) override;
void DidReceiveData(const char* data, int data_length) override;
void DidReceiveCachedMetadata(const char* data, int data_length) override;
void DidFinishLoading() override;
void DidFail(const blink::WebURLError& error) override;
private:
// Private because the class is RefCounted.
~BlinkUrlLoader() override;
base::WeakPtr<Client> client_;
std::unique_ptr<blink::WebAssociatedURLLoader> blink_loader_;
};
// A Pepper URL loader.
class PepperUrlLoader final : public UrlLoader {
public:
......
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