Fix some nits in OutOfProcessInstance message handlers.
- Use early returns in HandleGetPasswordCompleteMessage(). - Consolidate some checks in HandleResetPrintPreviewModeMessage(). - Change SetTwoUpView() to HandleSetTwoUpViewMessage() and consistently validate the message like other handlers. Also mark this message handler private. - Make comment style consistent through out the file. Change-Id: Ie437086adf83015f90858a864e1acdb9e826bf34 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2242853 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Daniel Hosseinian <dhoss@chromium.org> Cr-Commit-Position: refs/heads/master@{#778900}
This commit is contained in:
@ -564,7 +564,7 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) {
|
||||
} else if (type == kJSRotateCounterclockwiseType) {
|
||||
RotateCounterclockwise();
|
||||
} else if (type == kJSSetTwoUpViewType) {
|
||||
SetTwoUpView(dict.Get(pp::Var(kJSEnableTwoUpView)).AsBool());
|
||||
HandleSetTwoUpViewMessage(dict);
|
||||
} else if (type == kJSSelectAllType) {
|
||||
engine_->SelectAll();
|
||||
} else if (type == kJSBackgroundColorChangedType) {
|
||||
@ -1493,19 +1493,14 @@ void OutOfProcessInstance::RotateCounterclockwise() {
|
||||
engine_->RotateCounterclockwise();
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::SetTwoUpView(bool enable_two_up_view) {
|
||||
DCHECK(base::FeatureList::IsEnabled(features::kPDFTwoUpView));
|
||||
engine_->SetTwoUpView(enable_two_up_view);
|
||||
}
|
||||
|
||||
// static
|
||||
std::string OutOfProcessInstance::GetFileNameFromUrl(const std::string& url) {
|
||||
// Generate a file name. Unfortunately, MIME type can't be provided, since it
|
||||
// requires IO.
|
||||
base::string16 file_name = net::GetSuggestedFilename(
|
||||
GURL(url), std::string() /* content_disposition */,
|
||||
std::string() /* referrer_charset */, std::string() /* suggested_name */,
|
||||
std::string() /* mime_type */, std::string() /* default_name */);
|
||||
GURL(url), /*content_disposition=*/std::string(),
|
||||
/*referrer_charset=*/std::string(), /*suggested_name=*/std::string(),
|
||||
/*mime_type=*/std::string(), /*default_name=*/std::string());
|
||||
return base::UTF16ToUTF8(file_name);
|
||||
}
|
||||
|
||||
@ -1537,18 +1532,15 @@ void OutOfProcessInstance::HandleGetNamedDestinationMessage(
|
||||
|
||||
void OutOfProcessInstance::HandleGetPasswordCompleteMessage(
|
||||
const pp::VarDictionary& dict) {
|
||||
if (!dict.Get(pp::Var(kJSPassword)).is_string()) {
|
||||
if (!dict.Get(pp::Var(kJSPassword)).is_string() || !password_callback_) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
if (password_callback_) {
|
||||
pp::CompletionCallbackWithOutput<pp::Var> callback = *password_callback_;
|
||||
password_callback_.reset();
|
||||
*callback.output() = dict.Get(pp::Var(kJSPassword)).pp_var();
|
||||
callback.Run(PP_OK);
|
||||
} else {
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
pp::CompletionCallbackWithOutput<pp::Var> callback = *password_callback_;
|
||||
password_callback_.reset();
|
||||
*callback.output() = dict.Get(pp::Var(kJSPassword)).pp_var();
|
||||
callback.Run(PP_OK);
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::HandleGetSelectedTextMessage() {
|
||||
@ -1631,16 +1623,10 @@ void OutOfProcessInstance::HandleResetPrintPreviewModeMessage(
|
||||
// case, the page index for |url| should be non-negative.
|
||||
bool is_previewing_pdf = IsPreviewingPDF(print_preview_page_count);
|
||||
int page_index = ExtractPrintPreviewPageIndex(url);
|
||||
if (is_previewing_pdf) {
|
||||
if (page_index != kCompletePDFIndex) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (page_index < 0) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
if ((is_previewing_pdf && page_index != kCompletePDFIndex) ||
|
||||
(!is_previewing_pdf && page_index < 0)) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
print_preview_page_count_ = print_preview_page_count;
|
||||
@ -1653,11 +1639,22 @@ void OutOfProcessInstance::HandleResetPrintPreviewModeMessage(
|
||||
preview_engine_.reset();
|
||||
engine_ = PDFEngine::Create(this, false);
|
||||
engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool());
|
||||
engine_->New(url_.c_str(), nullptr /* empty header */);
|
||||
engine_->New(url_.c_str(), /*headers=*/nullptr);
|
||||
|
||||
paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::HandleSetTwoUpViewMessage(
|
||||
const pp::VarDictionary& dict) {
|
||||
if (!base::FeatureList::IsEnabled(features::kPDFTwoUpView) ||
|
||||
!dict.Get(pp::Var(kJSEnableTwoUpView)).is_bool()) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
engine_->SetTwoUpView(dict.Get(pp::Var(kJSEnableTwoUpView)).AsBool());
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::HandleViewportMessage(
|
||||
const pp::VarDictionary& dict) {
|
||||
pp::Var layout_options_var = dict.Get(kJSLayoutOptions);
|
||||
|
@ -155,7 +155,6 @@ class OutOfProcessInstance : public pp::Instance,
|
||||
// Helper functions for implementing PPP_PDF.
|
||||
void RotateClockwise();
|
||||
void RotateCounterclockwise();
|
||||
void SetTwoUpView(bool enable_two_up_view);
|
||||
|
||||
// Creates a file name for saving a PDF file, given the source URL. Exposed
|
||||
// for testing.
|
||||
@ -170,6 +169,7 @@ class OutOfProcessInstance : public pp::Instance,
|
||||
void HandleLoadPreviewPageMessage(const pp::VarDictionary& dict);
|
||||
void HandlePrintMessage(const pp::VarDictionary& dict);
|
||||
void HandleResetPrintPreviewModeMessage(const pp::VarDictionary& dict);
|
||||
void HandleSetTwoUpViewMessage(const pp::VarDictionary& dict);
|
||||
void HandleViewportMessage(const pp::VarDictionary& dict);
|
||||
|
||||
void ResetRecentlySentFindUpdate(int32_t);
|
||||
|
Reference in New Issue
Block a user