0

Inline PdfViewWebPlugin::CreateUrlLoaderInternal()

Inlines PdfViewWebPlugin::CreateUrlLoaderInternal() into the call sites,
as this method does very little now.

Also gets rid of UrlLoader::GrantUniversalAccess(), which the PDF viewer
always uses for all requests.

Bug: 1322928
Change-Id: I34c49fb2f83debeb52515819c21d1e188f0f452d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3710222
Auto-Submit: K. Moon <kmoon@chromium.org>
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Nigi <nigi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1015447}
This commit is contained in:
K. Moon
2022-06-17 18:42:20 +00:00
committed by Chromium LUCI CQ
parent ba8e320dc1
commit c6ef2d7f18
5 changed files with 5 additions and 32 deletions

@ -77,12 +77,6 @@ UrlLoader::UrlLoader(base::WeakPtr<Client> client)
UrlLoader::~UrlLoader() = default;
// Modeled on `content::PepperURLLoaderHost::OnHostMsgGrantUniversalAccess()`.
void UrlLoader::GrantUniversalAccess() {
DCHECK_EQ(state_, LoadingState::kWaitingToOpen);
grant_universal_access_ = true;
}
// Modeled on `content::PepperURLLoaderHost::OnHostMsgOpen()`.
void UrlLoader::Open(const UrlRequest& request,
base::OnceCallback<void(int)> callback) {
@ -140,7 +134,7 @@ void UrlLoader::Open(const UrlRequest& request,
// TODO(crbug.com/822081): Revisit whether we need universal access.
blink::WebAssociatedURLLoaderOptions options;
options.grant_universal_access = grant_universal_access_;
options.grant_universal_access = true;
ignore_redirects_ = request.ignore_redirects;
blink_loader_ = client_->CreateAssociatedURLLoader(options);
blink_loader_->LoadAsynchronously(blink_request, this);

@ -125,11 +125,6 @@ class UrlLoader final : public blink::WebAssociatedURLLoaderClient {
UrlLoader& operator=(const UrlLoader&) = delete;
~UrlLoader() override;
// Tries to grant the loader the capability to make unrestricted cross-origin
// requests ("universal access," in `blink::SecurityOrigin` terms). Must be
// called before `Open()`.
void GrantUniversalAccess();
// Mimic `pp::URLLoader`:
void Open(const UrlRequest& request, base::OnceCallback<void(int)> callback);
void ReadResponseBody(base::span<char> buffer,
@ -178,7 +173,6 @@ class UrlLoader final : public blink::WebAssociatedURLLoaderClient {
void SetLoadComplete(int32_t result);
base::WeakPtr<Client> client_;
bool grant_universal_access_ = false;
LoadingState state_ = LoadingState::kWaitingToOpen;
int32_t complete_result_ = 0;

@ -189,12 +189,6 @@ class UrlLoaderTest : public testing::Test {
blink::WebURLRequest saved_request_;
};
TEST_F(UrlLoaderTest, GrantUniversalAccess) {
loader_->GrantUniversalAccess();
loader_->Open(UrlRequest(), mock_callback_.Get());
EXPECT_TRUE(fake_client_.saved_options().grant_universal_access);
}
TEST_F(UrlLoaderTest, Open) {
EXPECT_CALL(*mock_url_loader_, LoadAsynchronously);
EXPECT_CALL(mock_callback_, Run).Times(0);
@ -204,7 +198,7 @@ TEST_F(UrlLoaderTest, Open) {
request.method = "FAKE";
loader_->Open(request, mock_callback_.Get());
EXPECT_FALSE(fake_client_.saved_options().grant_universal_access);
EXPECT_TRUE(fake_client_.saved_options().grant_universal_access);
EXPECT_EQ(GURL("http://example.com/fake.pdf"), GURL(saved_request_.Url()));
EXPECT_EQ("FAKE", saved_request_.HttpMethod().Ascii());
EXPECT_EQ(GURL(kOriginUrl),

@ -837,7 +837,7 @@ void PdfViewWebPlugin::LoadUrl(base::StringPiece url,
request.method = "GET";
request.ignore_redirects = true;
std::unique_ptr<UrlLoader> loader = CreateUrlLoaderInternal();
auto loader = std::make_unique<UrlLoader>(weak_factory_.GetWeakPtr());
UrlLoader* raw_loader = loader.get();
raw_loader->Open(request,
base::BindOnce(std::move(callback), std::move(loader)));
@ -857,7 +857,7 @@ void PdfViewWebPlugin::SubmitForm(const std::string& url,
request.method = "POST";
request.body.assign(static_cast<const char*>(data), length);
form_loader_ = CreateUrlLoaderInternal();
form_loader_ = std::make_unique<UrlLoader>(weak_factory_.GetWeakPtr());
form_loader_->Open(request, base::BindOnce(&PdfViewWebPlugin::DidFormOpen,
weak_factory_.GetWeakPtr()));
}
@ -878,13 +878,7 @@ std::unique_ptr<UrlLoader> PdfViewWebPlugin::CreateUrlLoader() {
SetContentRestrictions(kContentRestrictionSave | kContentRestrictionPrint);
}
return CreateUrlLoaderInternal();
}
std::unique_ptr<UrlLoader> PdfViewWebPlugin::CreateUrlLoaderInternal() {
auto loader = std::make_unique<UrlLoader>(weak_factory_.GetWeakPtr());
loader->GrantUniversalAccess();
return loader;
return std::make_unique<UrlLoader>(weak_factory_.GetWeakPtr());
}
std::vector<PDFEngine::Client::SearchStringResult>

@ -409,9 +409,6 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// Handles `Open()` result for `form_loader_`.
void DidFormOpen(int32_t result);
// Creates a URL loader with universal access.
std::unique_ptr<UrlLoader> CreateUrlLoaderInternal();
// Handles message for saving the PDF.
void HandleSaveMessage(const base::Value::Dict& message);
void SaveToBuffer(const std::string& token);