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) {
|
} else if (type == kJSRotateCounterclockwiseType) {
|
||||||
RotateCounterclockwise();
|
RotateCounterclockwise();
|
||||||
} else if (type == kJSSetTwoUpViewType) {
|
} else if (type == kJSSetTwoUpViewType) {
|
||||||
SetTwoUpView(dict.Get(pp::Var(kJSEnableTwoUpView)).AsBool());
|
HandleSetTwoUpViewMessage(dict);
|
||||||
} else if (type == kJSSelectAllType) {
|
} else if (type == kJSSelectAllType) {
|
||||||
engine_->SelectAll();
|
engine_->SelectAll();
|
||||||
} else if (type == kJSBackgroundColorChangedType) {
|
} else if (type == kJSBackgroundColorChangedType) {
|
||||||
@ -1493,19 +1493,14 @@ void OutOfProcessInstance::RotateCounterclockwise() {
|
|||||||
engine_->RotateCounterclockwise();
|
engine_->RotateCounterclockwise();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutOfProcessInstance::SetTwoUpView(bool enable_two_up_view) {
|
|
||||||
DCHECK(base::FeatureList::IsEnabled(features::kPDFTwoUpView));
|
|
||||||
engine_->SetTwoUpView(enable_two_up_view);
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
std::string OutOfProcessInstance::GetFileNameFromUrl(const std::string& url) {
|
std::string OutOfProcessInstance::GetFileNameFromUrl(const std::string& url) {
|
||||||
// Generate a file name. Unfortunately, MIME type can't be provided, since it
|
// Generate a file name. Unfortunately, MIME type can't be provided, since it
|
||||||
// requires IO.
|
// requires IO.
|
||||||
base::string16 file_name = net::GetSuggestedFilename(
|
base::string16 file_name = net::GetSuggestedFilename(
|
||||||
GURL(url), std::string() /* content_disposition */,
|
GURL(url), /*content_disposition=*/std::string(),
|
||||||
std::string() /* referrer_charset */, std::string() /* suggested_name */,
|
/*referrer_charset=*/std::string(), /*suggested_name=*/std::string(),
|
||||||
std::string() /* mime_type */, std::string() /* default_name */);
|
/*mime_type=*/std::string(), /*default_name=*/std::string());
|
||||||
return base::UTF16ToUTF8(file_name);
|
return base::UTF16ToUTF8(file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1537,18 +1532,15 @@ void OutOfProcessInstance::HandleGetNamedDestinationMessage(
|
|||||||
|
|
||||||
void OutOfProcessInstance::HandleGetPasswordCompleteMessage(
|
void OutOfProcessInstance::HandleGetPasswordCompleteMessage(
|
||||||
const pp::VarDictionary& dict) {
|
const pp::VarDictionary& dict) {
|
||||||
if (!dict.Get(pp::Var(kJSPassword)).is_string()) {
|
if (!dict.Get(pp::Var(kJSPassword)).is_string() || !password_callback_) {
|
||||||
NOTREACHED();
|
NOTREACHED();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (password_callback_) {
|
|
||||||
pp::CompletionCallbackWithOutput<pp::Var> callback = *password_callback_;
|
pp::CompletionCallbackWithOutput<pp::Var> callback = *password_callback_;
|
||||||
password_callback_.reset();
|
password_callback_.reset();
|
||||||
*callback.output() = dict.Get(pp::Var(kJSPassword)).pp_var();
|
*callback.output() = dict.Get(pp::Var(kJSPassword)).pp_var();
|
||||||
callback.Run(PP_OK);
|
callback.Run(PP_OK);
|
||||||
} else {
|
|
||||||
NOTREACHED();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutOfProcessInstance::HandleGetSelectedTextMessage() {
|
void OutOfProcessInstance::HandleGetSelectedTextMessage() {
|
||||||
@ -1631,16 +1623,10 @@ void OutOfProcessInstance::HandleResetPrintPreviewModeMessage(
|
|||||||
// case, the page index for |url| should be non-negative.
|
// case, the page index for |url| should be non-negative.
|
||||||
bool is_previewing_pdf = IsPreviewingPDF(print_preview_page_count);
|
bool is_previewing_pdf = IsPreviewingPDF(print_preview_page_count);
|
||||||
int page_index = ExtractPrintPreviewPageIndex(url);
|
int page_index = ExtractPrintPreviewPageIndex(url);
|
||||||
if (is_previewing_pdf) {
|
if ((is_previewing_pdf && page_index != kCompletePDFIndex) ||
|
||||||
if (page_index != kCompletePDFIndex) {
|
(!is_previewing_pdf && page_index < 0)) {
|
||||||
NOTREACHED();
|
NOTREACHED();
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (page_index < 0) {
|
|
||||||
NOTREACHED();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_preview_page_count_ = print_preview_page_count;
|
print_preview_page_count_ = print_preview_page_count;
|
||||||
@ -1653,11 +1639,22 @@ void OutOfProcessInstance::HandleResetPrintPreviewModeMessage(
|
|||||||
preview_engine_.reset();
|
preview_engine_.reset();
|
||||||
engine_ = PDFEngine::Create(this, false);
|
engine_ = PDFEngine::Create(this, false);
|
||||||
engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool());
|
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_));
|
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(
|
void OutOfProcessInstance::HandleViewportMessage(
|
||||||
const pp::VarDictionary& dict) {
|
const pp::VarDictionary& dict) {
|
||||||
pp::Var layout_options_var = dict.Get(kJSLayoutOptions);
|
pp::Var layout_options_var = dict.Get(kJSLayoutOptions);
|
||||||
|
@ -155,7 +155,6 @@ class OutOfProcessInstance : public pp::Instance,
|
|||||||
// Helper functions for implementing PPP_PDF.
|
// Helper functions for implementing PPP_PDF.
|
||||||
void RotateClockwise();
|
void RotateClockwise();
|
||||||
void RotateCounterclockwise();
|
void RotateCounterclockwise();
|
||||||
void SetTwoUpView(bool enable_two_up_view);
|
|
||||||
|
|
||||||
// Creates a file name for saving a PDF file, given the source URL. Exposed
|
// Creates a file name for saving a PDF file, given the source URL. Exposed
|
||||||
// for testing.
|
// for testing.
|
||||||
@ -170,6 +169,7 @@ class OutOfProcessInstance : public pp::Instance,
|
|||||||
void HandleLoadPreviewPageMessage(const pp::VarDictionary& dict);
|
void HandleLoadPreviewPageMessage(const pp::VarDictionary& dict);
|
||||||
void HandlePrintMessage(const pp::VarDictionary& dict);
|
void HandlePrintMessage(const pp::VarDictionary& dict);
|
||||||
void HandleResetPrintPreviewModeMessage(const pp::VarDictionary& dict);
|
void HandleResetPrintPreviewModeMessage(const pp::VarDictionary& dict);
|
||||||
|
void HandleSetTwoUpViewMessage(const pp::VarDictionary& dict);
|
||||||
void HandleViewportMessage(const pp::VarDictionary& dict);
|
void HandleViewportMessage(const pp::VarDictionary& dict);
|
||||||
|
|
||||||
void ResetRecentlySentFindUpdate(int32_t);
|
void ResetRecentlySentFindUpdate(int32_t);
|
||||||
|
Reference in New Issue
Block a user