0

Fix crash from ipc_fuzzer

Can't reproduce original crash so I just fix all crashes I see.

Use WeakPtr in AskUserForSettings callback.

Move chrome::ShowMessageBox in separate task and protection against nested message boxes.

Add missing return into AskUserForSettings.

BUG=472146

Review URL: https://codereview.chromium.org/1083433003

Cr-Commit-Position: refs/heads/master@{#324746}
This commit is contained in:
vitalybuka
2015-04-10 18:46:42 -07:00
committed by Commit bot
parent 7d62e83efb
commit 442258da86
4 changed files with 30 additions and 24 deletions

@@ -93,6 +93,13 @@ void NotificationCallback(PrintJobWorkerOwner* print_job,
content::Details<JobEventDetails>(details)); content::Details<JobEventDetails>(details));
} }
void PostOnOwnerThread(const scoped_refptr<PrintJobWorkerOwner>& owner,
const PrintingContext::PrintSettingsCallback& callback,
PrintingContext::Result result) {
owner->PostTask(FROM_HERE, base::Bind(&HoldRefCallback, owner,
base::Bind(callback, result)));
}
} // namespace } // namespace
PrintJobWorker::PrintJobWorker(int render_process_id, PrintJobWorker::PrintJobWorker(int render_process_id,
@@ -219,21 +226,12 @@ void PrintJobWorker::GetSettingsWithUI(
} }
#endif #endif
// weak_factory_ creates pointers valid only on owner_ thread.
printing_context_->AskUserForSettings( printing_context_->AskUserForSettings(
document_page_count, document_page_count, has_selection, is_scripted,
has_selection, base::Bind(&PostOnOwnerThread, make_scoped_refptr(owner_),
is_scripted, base::Bind(&PrintJobWorker::GetSettingsDone,
base::Bind(&PrintJobWorker::GetSettingsWithUIDone, weak_factory_.GetWeakPtr())));
base::Unretained(this)));
}
void PrintJobWorker::GetSettingsWithUIDone(PrintingContext::Result result) {
PostTask(FROM_HERE,
base::Bind(&HoldRefCallback,
make_scoped_refptr(owner_),
base::Bind(&PrintJobWorker::GetSettingsDone,
base::Unretained(this),
result)));
} }
void PrintJobWorker::UseDefaultSettings() { void PrintJobWorker::UseDefaultSettings() {

@@ -114,11 +114,6 @@ class PrintJobWorker {
bool has_selection, bool has_selection,
bool is_scripted); bool is_scripted);
// The callback used by PrintingContext::GetSettingsWithUI() to notify this
// object that the print settings are set. This is needed in order to bounce
// back into the IO thread for GetSettingsDone().
void GetSettingsWithUIDone(PrintingContext::Result result);
// Called on the UI thread to update the print settings. // Called on the UI thread to update the print settings.
void UpdatePrintSettings(scoped_ptr<base::DictionaryValue> new_settings); void UpdatePrintSettings(scoped_ptr<base::DictionaryValue> new_settings);

@@ -4,6 +4,7 @@
#include "chrome/browser/printing/print_view_manager_base.h" #include "chrome/browser/printing/print_view_manager_base.h"
#include "base/auto_reset.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
@@ -40,6 +41,18 @@ namespace printing {
namespace { namespace {
void ShowWarningMessageBox(const base::string16& message) {
// Runs always on the UI thread.
static bool is_dialog_shown = false;
if (is_dialog_shown)
return;
// Block opening dialog from nested task.
base::AutoReset<bool> auto_reset(&is_dialog_shown, true);
chrome::ShowMessageBox(nullptr, base::string16(), message,
chrome::MESSAGE_BOX_TYPE_WARNING);
}
} // namespace } // namespace
PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents) PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents)
@@ -195,11 +208,10 @@ void PrintViewManagerBase::OnPrintingFailed(int cookie) {
} }
void PrintViewManagerBase::OnShowInvalidPrinterSettingsError() { void PrintViewManagerBase::OnShowInvalidPrinterSettingsError() {
chrome::ShowMessageBox(NULL, base::MessageLoop::current()->PostTask(
base::string16(), FROM_HERE, base::Bind(&ShowWarningMessageBox,
l10n_util::GetStringUTF16( l10n_util::GetStringUTF16(
IDS_PRINT_INVALID_PRINTER_SETTINGS), IDS_PRINT_INVALID_PRINTER_SETTINGS)));
chrome::MESSAGE_BOX_TYPE_WARNING);
} }
void PrintViewManagerBase::DidStartLoading() { void PrintViewManagerBase::DidStartLoading() {

@@ -69,6 +69,7 @@ void PrintingContextSytemDialogWin::AskUserForSettings(
if (ShowPrintDialog(&dialog_options) != S_OK) { if (ShowPrintDialog(&dialog_options) != S_OK) {
ResetSettings(); ResetSettings();
callback.Run(FAILED); callback.Run(FAILED);
return;
} }
// TODO(maruel): Support PD_PRINTTOFILE. // TODO(maruel): Support PD_PRINTTOFILE.