Remove PPAPI dependency by adding a pp::Var to base::Value converter
This change removes the pp::Var dependency from core PDF code by converting the incoming pp::Var data to base::Value and updating the core PDF code to work with base::Value instead of pp::Var. The pp::Var types of PP_VARTYPE_OBJECT and PP_VARTYPE_RESOURCE do not have any valid conversion to base::Value and hence have added NOTREACHED() in those cases. Bug: 1094049 Change-Id: I3f6e54b04878e10d0d0ae860a6b1e8446e7e04e1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2413707 Commit-Queue: Gourab Kundu <gourabk@microsoft.com> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: K. Moon <kmoon@chromium.org> Reviewed-by: Ankit Kumar 🌪️ <ankk@microsoft.com> Cr-Commit-Position: refs/heads/master@{#809692}
This commit is contained in:
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
#include "base/check_op.h"
|
#include "base/check_op.h"
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "ppapi/cpp/var.h"
|
|
||||||
#include "ppapi/cpp/var_dictionary.h"
|
|
||||||
#include "ui/gfx/geometry/point.h"
|
#include "ui/gfx/geometry/point.h"
|
||||||
#include "ui/gfx/geometry/rect.h"
|
#include "ui/gfx/geometry/rect.h"
|
||||||
#include "ui/gfx/geometry/size.h"
|
#include "ui/gfx/geometry/size.h"
|
||||||
@@ -59,11 +57,11 @@ base::Value DocumentLayout::Options::ToValue() const {
|
|||||||
return dictionary;
|
return dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentLayout::Options::FromVar(const pp::Var& var) {
|
void DocumentLayout::Options::FromValue(const base::Value& value) {
|
||||||
pp::VarDictionary dictionary(var);
|
DCHECK(value.is_dict());
|
||||||
|
|
||||||
int32_t default_page_orientation =
|
int32_t default_page_orientation =
|
||||||
dictionary.Get(kDefaultPageOrientation).AsInt();
|
value.FindKey(kDefaultPageOrientation)->GetInt();
|
||||||
DCHECK_GE(default_page_orientation,
|
DCHECK_GE(default_page_orientation,
|
||||||
static_cast<int32_t>(PageOrientation::kOriginal));
|
static_cast<int32_t>(PageOrientation::kOriginal));
|
||||||
DCHECK_LE(default_page_orientation,
|
DCHECK_LE(default_page_orientation,
|
||||||
@@ -71,7 +69,7 @@ void DocumentLayout::Options::FromVar(const pp::Var& var) {
|
|||||||
default_page_orientation_ =
|
default_page_orientation_ =
|
||||||
static_cast<PageOrientation>(default_page_orientation);
|
static_cast<PageOrientation>(default_page_orientation);
|
||||||
|
|
||||||
two_up_view_enabled_ = dictionary.Get(kTwoUpViewEnabled).AsBool();
|
two_up_view_enabled_ = value.FindKey(kTwoUpViewEnabled)->GetBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentLayout::Options::RotatePagesClockwise() {
|
void DocumentLayout::Options::RotatePagesClockwise() {
|
||||||
|
@@ -18,10 +18,6 @@ namespace base {
|
|||||||
class Value;
|
class Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace pp {
|
|
||||||
class Var;
|
|
||||||
} // namespace pp
|
|
||||||
|
|
||||||
namespace chrome_pdf {
|
namespace chrome_pdf {
|
||||||
|
|
||||||
// Layout of pages within a PDF document. Pages are placed as rectangles
|
// Layout of pages within a PDF document. Pages are placed as rectangles
|
||||||
@@ -55,8 +51,8 @@ class DocumentLayout final {
|
|||||||
// Serializes layout options to a base::Value.
|
// Serializes layout options to a base::Value.
|
||||||
base::Value ToValue() const;
|
base::Value ToValue() const;
|
||||||
|
|
||||||
// Deserializes layout options from a pp::Var.
|
// Deserializes layout options from a base::Value.
|
||||||
void FromVar(const pp::Var& var);
|
void FromValue(const base::Value& value);
|
||||||
|
|
||||||
PageOrientation default_page_orientation() const {
|
PageOrientation default_page_orientation() const {
|
||||||
return default_page_orientation_;
|
return default_page_orientation_;
|
||||||
|
@@ -1833,7 +1833,7 @@ void OutOfProcessInstance::HandleViewportMessage(
|
|||||||
pp::Var layout_options_var = dict.Get(kJSLayoutOptions);
|
pp::Var layout_options_var = dict.Get(kJSLayoutOptions);
|
||||||
if (!layout_options_var.is_undefined()) {
|
if (!layout_options_var.is_undefined()) {
|
||||||
DocumentLayout::Options layout_options;
|
DocumentLayout::Options layout_options;
|
||||||
layout_options.FromVar(layout_options_var);
|
layout_options.FromValue(ValueFromVar(layout_options_var));
|
||||||
// TODO(crbug.com/1013800): Eliminate need to get document size from here.
|
// TODO(crbug.com/1013800): Eliminate need to get document size from here.
|
||||||
document_size_ =
|
document_size_ =
|
||||||
PPSizeFromSize(engine()->ApplyDocumentLayout(layout_options));
|
PPSizeFromSize(engine()->ApplyDocumentLayout(layout_options));
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "base/containers/span.h"
|
||||||
|
#include "base/notreached.h"
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "ppapi/cpp/var.h"
|
#include "ppapi/cpp/var.h"
|
||||||
#include "ppapi/cpp/var_array.h"
|
#include "ppapi/cpp/var_array.h"
|
||||||
@@ -55,4 +57,57 @@ pp::Var VarFromValue(const base::Value& value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base::Value ValueFromVar(const pp::Var& var) {
|
||||||
|
switch (var.pp_var().type) {
|
||||||
|
case PP_VARTYPE_UNDEFINED:
|
||||||
|
return base::Value();
|
||||||
|
case PP_VARTYPE_NULL:
|
||||||
|
return base::Value();
|
||||||
|
case PP_VARTYPE_BOOL:
|
||||||
|
return base::Value(var.AsBool());
|
||||||
|
case PP_VARTYPE_INT32:
|
||||||
|
return base::Value(var.AsInt());
|
||||||
|
case PP_VARTYPE_DOUBLE:
|
||||||
|
return base::Value(var.AsDouble());
|
||||||
|
case PP_VARTYPE_STRING:
|
||||||
|
return base::Value(var.AsString());
|
||||||
|
case PP_VARTYPE_OBJECT:
|
||||||
|
// There is no valid conversion from PP_VARTYPE_OBJECT to a base::Value
|
||||||
|
// type. This should not be called to convert this type.
|
||||||
|
NOTREACHED();
|
||||||
|
return base::Value();
|
||||||
|
case PP_VARTYPE_ARRAY: {
|
||||||
|
pp::VarArray var_array(var);
|
||||||
|
base::Value::ListStorage list_storage(var_array.GetLength());
|
||||||
|
for (uint32_t i = 0; i < var_array.GetLength(); ++i) {
|
||||||
|
list_storage[i] = ValueFromVar(var_array.Get(i));
|
||||||
|
}
|
||||||
|
return base::Value(std::move(list_storage));
|
||||||
|
}
|
||||||
|
case PP_VARTYPE_DICTIONARY: {
|
||||||
|
base::Value val_dictionary(base::Value::Type::DICTIONARY);
|
||||||
|
pp::VarDictionary var_dict(var);
|
||||||
|
pp::VarArray dict_keys = var_dict.GetKeys();
|
||||||
|
for (uint32_t i = 0; i < dict_keys.GetLength(); ++i) {
|
||||||
|
pp::Var key = dict_keys.Get(i);
|
||||||
|
val_dictionary.SetKey(key.AsString(), ValueFromVar(var_dict.Get(key)));
|
||||||
|
}
|
||||||
|
return val_dictionary;
|
||||||
|
}
|
||||||
|
case PP_VARTYPE_ARRAY_BUFFER: {
|
||||||
|
pp::VarArrayBuffer var_array_buffer(var);
|
||||||
|
base::Value value(
|
||||||
|
base::make_span(static_cast<uint8_t*>(var_array_buffer.Map()),
|
||||||
|
var_array_buffer.ByteLength()));
|
||||||
|
var_array_buffer.Unmap();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case PP_VARTYPE_RESOURCE:
|
||||||
|
// There is no valid conversion from PP_VARTYPE_RESOURCE to a base::Value
|
||||||
|
// type. This should not be called to convert this type.
|
||||||
|
NOTREACHED();
|
||||||
|
return base::Value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace chrome_pdf
|
} // namespace chrome_pdf
|
@@ -16,6 +16,7 @@ class Var;
|
|||||||
namespace chrome_pdf {
|
namespace chrome_pdf {
|
||||||
|
|
||||||
pp::Var VarFromValue(const base::Value& value);
|
pp::Var VarFromValue(const base::Value& value);
|
||||||
|
base::Value ValueFromVar(const pp::Var& var);
|
||||||
|
|
||||||
} // namespace chrome_pdf
|
} // namespace chrome_pdf
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user