Skip to content

Commit

Permalink
Fix some nits in chrome_pdf::OutOfProcessInstance.
Browse files Browse the repository at this point in the history
Add an IsSaveDataSizeValid() helper function and rename a variable with
the wrong naming style.

Change-Id: I17cd04cfe66dcbc1d20d9f6b73e3194d768662af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1550119
Auto-Submit: Lei Zhang <thestig@chromium.org>
Commit-Queue: dstockwell <dstockwell@chromium.org>
Reviewed-by: dstockwell <dstockwell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#647162}
  • Loading branch information
leizleiz authored and Commit Bot committed Apr 3, 2019
1 parent 84568fa commit 4c0dfd8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ void ScaleRect(float scale, pp::Rect* rect) {
rect->SetRect(left, top, right - left, bottom - top);
}

bool IsSaveDataSizeValid(size_t size) {
return size > 0 && size <= kMaximumSavedFileSize;
}

} // namespace

OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)
Expand Down Expand Up @@ -1455,13 +1459,13 @@ void OutOfProcessInstance::SaveToBuffer(const std::string& token) {
message.Set(kJSFileName, pp::Var(file_name));
// This will be overwritten if the save is successful.
message.Set(kJSDataToSave, pp::Var(pp::Var::Null()));
const bool hasUnsavedChanges =
const bool has_unsaved_changes =
edit_mode_ && !base::FeatureList::IsEnabled(features::kSaveEditedPDFForm);
message.Set(kJSHasUnsavedChanges, pp::Var(hasUnsavedChanges));
message.Set(kJSHasUnsavedChanges, pp::Var(has_unsaved_changes));

if (ShouldSaveEdits()) {
std::vector<uint8_t> data = engine_->GetSaveData();
if (data.size() > 0 && data.size() <= kMaximumSavedFileSize) {
if (IsSaveDataSizeValid(data.size())) {
pp::VarArrayBuffer buffer(data.size());
std::copy(data.begin(), data.end(),
reinterpret_cast<char*>(buffer.Map()));
Expand All @@ -1470,7 +1474,7 @@ void OutOfProcessInstance::SaveToBuffer(const std::string& token) {
} else {
DCHECK(base::FeatureList::IsEnabled(features::kPDFAnnotations));
uint32_t length = engine_->GetLoadedByteSize();
if (length > 0 && length <= kMaximumSavedFileSize) {
if (IsSaveDataSizeValid(length)) {
pp::VarArrayBuffer buffer(length);
if (engine_->ReadLoadedBytes(length, buffer.Map())) {
message.Set(kJSDataToSave, buffer);
Expand Down Expand Up @@ -1657,7 +1661,7 @@ void OutOfProcessInstance::DocumentLoadComplete(
}
metadata_message.Set(
pp::Var(kJSCanSerializeDocument),
pp::Var(engine_->GetLoadedByteSize() <= kMaximumSavedFileSize));
pp::Var(IsSaveDataSizeValid(engine_->GetLoadedByteSize())));

pp::VarArray bookmarks = engine_->GetBookmarks();
metadata_message.Set(pp::Var(kJSBookmarks), bookmarks);
Expand Down

0 comments on commit 4c0dfd8

Please sign in to comment.