0

[unseasoned-pdf] Migrate document loading methods.

- Create PluginDidStartLoading() and PluginDidStopLoading() in
  PdfViewPluginBase to wrap pp::PDF::DidStartLoading() and
  pp::PDF::DidStopLoading() for OutOfProcessInstance, and implement
  their Pepper-free equivalents in PdfViewWebPlugin.

- Migrate DidStartLoading() and DidStopLoading() to PdfViewPluginBase
  and make them private.

Bug: 1140629,1218534
Change-Id: Ieaa8aea89746c99df9c2de18f8cbe47ec8d3c3a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2960722
Commit-Queue: Hui Yingst <nigi@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#894434}
This commit is contained in:
Hui Yingst
2021-06-21 22:35:55 +00:00
committed by Chromium LUCI CQ
parent 2802b01d46
commit 3e609015c1
8 changed files with 62 additions and 29 deletions

@ -1008,20 +1008,12 @@ void OutOfProcessInstance::ScheduleTaskOnMainThread(
PPCompletionCallbackFromResultCallback(std::move(callback)), result);
}
void OutOfProcessInstance::DidStartLoading() {
if (did_call_start_loading_)
return;
void OutOfProcessInstance::PluginDidStartLoading() {
pp::PDF::DidStartLoading(this);
did_call_start_loading_ = true;
}
void OutOfProcessInstance::DidStopLoading() {
if (!did_call_start_loading_)
return;
void OutOfProcessInstance::PluginDidStopLoading() {
pp::PDF::DidStopLoading(this);
did_call_start_loading_ = false;
}
void OutOfProcessInstance::InvokePrintDialog() {

@ -137,8 +137,8 @@ class OutOfProcessInstance : public PdfViewPluginBase,
const AccessibilityViewportInfo& viewport_info) override;
void SetContentRestrictions(int content_restrictions) override;
void SetPluginCanSave(bool can_save) override;
void DidStartLoading() override;
void DidStopLoading() override;
void PluginDidStartLoading() override;
void PluginDidStopLoading() override;
void InvokePrintDialog() override;
void NotifySelectionChanged(const gfx::PointF& left,
int left_height,
@ -175,11 +175,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// The tickmarks.
std::vector<pp::Rect> tickmarks_;
// If true, this means we told the RenderView that we're starting a network
// request so that it can start the throbber. We will tell it again once the
// document finishes loading.
bool did_call_start_loading_ = false;
base::WeakPtrFactory<OutOfProcessInstance> weak_factory_{this};
};

@ -1224,6 +1224,22 @@ void PdfViewPluginBase::HandleViewportMessage(const base::Value& message) {
engine()->ScrolledToYPosition(scroll_position.y() * device_scale_);
}
void PdfViewPluginBase::DidStartLoading() {
if (did_call_start_loading_)
return;
PluginDidStartLoading();
did_call_start_loading_ = true;
}
void PdfViewPluginBase::DidStopLoading() {
if (!did_call_start_loading_)
return;
PluginDidStopLoading();
did_call_start_loading_ = false;
}
void PdfViewPluginBase::SaveToFile(const std::string& token) {
engine()->KillFormFocus();
ConsumeSaveToken(token);

@ -303,10 +303,8 @@ class PdfViewPluginBase : public PDFEngine::Client,
virtual void SetPluginCanSave(bool can_save) = 0;
// Sends start/stop loading notifications to the plugin's render frame.
// TODO(crbug.com/702993): Evaluate whether these methods are needed when the
// plugin is moved into a renderer process.
virtual void DidStartLoading() = 0;
virtual void DidStopLoading() = 0;
virtual void PluginDidStartLoading() = 0;
virtual void PluginDidStopLoading() = 0;
// Requests the plugin's render frame to set up a print dialog for the
// document.
@ -404,6 +402,11 @@ class PdfViewPluginBase : public PDFEngine::Client,
void HandleUpdateScrollMessage(const base::Value& message);
void HandleViewportMessage(const base::Value& message);
// Sends start/stop loading notifications to the plugin's render frame
// depending on `did_call_start_loading_`.
void DidStartLoading();
void DidStopLoading();
// Saves the document to a file.
void SaveToFile(const std::string& token);
@ -556,6 +559,11 @@ class PdfViewPluginBase : public PDFEngine::Client,
// The current state of document load.
DocumentLoadState document_load_state_ = DocumentLoadState::kLoading;
// If true, the render frame has been notified that we're starting a network
// request so that it can start the throbber. It will be notified again once
// the document finishes loading.
bool did_call_start_loading_ = false;
// The current state of accessibility.
AccessibilityState accessibility_state_ = AccessibilityState::kOff;

@ -148,9 +148,9 @@ class FakePdfViewPluginBase : public PdfViewPluginBase {
MOCK_METHOD(void, SetPluginCanSave, (bool), (override));
MOCK_METHOD(void, DidStartLoading, (), (override));
MOCK_METHOD(void, PluginDidStartLoading, (), (override));
MOCK_METHOD(void, DidStopLoading, (), (override));
MOCK_METHOD(void, PluginDidStopLoading, (), (override));
MOCK_METHOD(void, InvokePrintDialog, (), (override));

@ -58,6 +58,7 @@
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_local_frame_client.h"
#include "third_party/blink/public/web/web_plugin_container.h"
#include "third_party/blink/public/web/web_plugin_params.h"
#include "third_party/blink/public/web/web_print_preset_options.h"
@ -177,6 +178,10 @@ class BlinkContainerWrapper final : public PdfViewWebPlugin::ContainerWrapper {
return container_->GetDocument().GetFrame();
}
blink::WebLocalFrameClient* GetWebLocalFrameClient() override {
return GetFrame()->Client();
}
blink::WebPluginContainer* Container() override { return container_; }
private:
@ -684,12 +689,20 @@ void PdfViewWebPlugin::SetPluginCanSave(bool can_save) {
service->SetPluginCanSave(can_save);
}
void PdfViewWebPlugin::DidStartLoading() {
NOTIMPLEMENTED();
void PdfViewWebPlugin::PluginDidStartLoading() {
auto* client = container_wrapper_->GetWebLocalFrameClient();
if (!client)
return;
client->DidStartLoading();
}
void PdfViewWebPlugin::DidStopLoading() {
NOTIMPLEMENTED();
void PdfViewWebPlugin::PluginDidStopLoading() {
auto* client = container_wrapper_->GetWebLocalFrameClient();
if (!client)
return;
client->DidStopLoading();
}
void PdfViewWebPlugin::InvokePrintDialog() {

@ -29,6 +29,7 @@ namespace blink {
class WebAssociatedURLLoader;
class WebElement;
class WebLocalFrame;
class WebLocalFrameClient;
class WebPluginContainer;
class WebURL;
class WebURLRequest;
@ -93,6 +94,10 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// Returns the local frame to which the web plugin container belongs.
virtual blink::WebLocalFrame* GetFrame() = 0;
// Returns the local frame's client (render frame). May be null in unit
// tests.
virtual blink::WebLocalFrameClient* GetWebLocalFrameClient() = 0;
// Returns the blink web plugin container pointer that's wrapped inside this
// object. Returns nullptr if this object is for test only.
virtual blink::WebPluginContainer* Container() = 0;
@ -219,8 +224,8 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
const AccessibilityViewportInfo& viewport_info) override;
void SetContentRestrictions(int content_restrictions) override;
void SetPluginCanSave(bool can_save) override;
void DidStartLoading() override;
void DidStopLoading() override;
void PluginDidStartLoading() override;
void PluginDidStopLoading() override;
void InvokePrintDialog() override;
void NotifySelectionChanged(const gfx::PointF& left,
int left_height,

@ -124,6 +124,10 @@ class FakeContainerWrapper final : public PdfViewWebPlugin::ContainerWrapper {
blink::WebLocalFrame* GetFrame() override { return nullptr; }
blink::WebLocalFrameClient* GetWebLocalFrameClient() override {
return nullptr;
}
// TODO(https://crbug.com/1207575): Container() should not be used for testing
// since it doesn't have a valid blink::WebPluginContainer. Make this method
// fail once ContainerWrapper instead of blink::WebPluginContainer is used for