Commit 46b9df68 authored by ben@chromium.org's avatar ben@chromium.org

Make cloud print dialog creation function not use browser list, instead obtain...

Make cloud print dialog creation function not use browser list, instead obtain profile and parent window from invocation context.

http://crbug.com/129053
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10388214

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138485 0039d316-1c4b-4281-b951-d872f2087c98
parent 2110271e
......@@ -1140,9 +1140,9 @@ const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
string16 title16 = base::SysNSStringToUTF16(printTitle);
string16 printTicket16 = base::SysNSStringToUTF16(printTicket);
print_dialog_cloud::CreatePrintDialogForFile(
ProfileManager::GetDefaultProfile(), NULL,
FilePath([inputPath UTF8String]), title16,
printTicket16, [mime UTF8String], /*modal=*/false,
/*delete_on_close=*/false);
printTicket16, [mime UTF8String], /*delete_on_close=*/false);
}
}
......
......@@ -412,7 +412,7 @@ void ChromeContentBrowserClient::RenderProcessHostCreated(
id, profile, profile->GetRequestContextForRenderProcess(id)));
host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
#if !defined(OS_ANDROID)
host->GetChannel()->AddFilter(new PrintingMessageFilter());
host->GetChannel()->AddFilter(new PrintingMessageFilter(id));
#endif
host->GetChannel()->AddFilter(
new SearchProviderInstallStateMessageFilter(id, profile));
......
......@@ -20,12 +20,6 @@
#include "chrome/browser/printing/cloud_print/cloud_print_url.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/print_messages.h"
......@@ -481,13 +475,13 @@ void CloudPrintFlowHandler::StoreDialogClientSize() const {
}
CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate(
content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
const FilePath& path_to_file,
int width, int height,
const std::string& json_arguments,
const string16& print_job_title,
const string16& print_ticket,
const std::string& file_type,
bool modal,
bool delete_on_close,
bool close_after_signin,
const base::Closure& callback)
......@@ -498,39 +492,68 @@ CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate(
file_type,
close_after_signin,
callback)),
modal_(modal),
modal_parent_(modal_parent),
owns_flow_handler_(true),
path_to_file_(path_to_file) {
Init(width, height, json_arguments);
Init(browser_context, json_arguments);
}
// For unit testing.
CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate(
const FilePath& path_to_file,
CloudPrintFlowHandler* flow_handler,
int width, int height,
const std::string& json_arguments,
bool modal,
bool delete_on_close)
: delete_on_close_(delete_on_close),
flow_handler_(flow_handler),
modal_(modal),
modal_parent_(NULL),
owns_flow_handler_(true) {
Init(width, height, json_arguments);
Init(NULL, json_arguments);
}
void CloudPrintWebDialogDelegate::Init(int width, int height,
// Returns the persisted width/height for the print dialog.
void GetDialogWidthAndHeightFromPrefs(content::BrowserContext* browser_context,
int* width,
int* height) {
const int kDefaultWidth = 912;
const int kDefaultHeight = 633;
if (!browser_context) {
*width = kDefaultWidth;
*height = kDefaultHeight;
return;
}
Profile* profile = Profile::FromBrowserContext(browser_context);
if (!profile->GetPrefs()->FindPreference(prefs::kCloudPrintDialogWidth)) {
profile->GetPrefs()->RegisterIntegerPref(prefs::kCloudPrintDialogWidth,
kDefaultWidth,
PrefService::UNSYNCABLE_PREF);
}
if (!profile->GetPrefs()->FindPreference(prefs::kCloudPrintDialogHeight)) {
profile->GetPrefs()->RegisterIntegerPref(prefs::kCloudPrintDialogHeight,
kDefaultHeight,
PrefService::UNSYNCABLE_PREF);
}
*width = profile->GetPrefs()->GetInteger(prefs::kCloudPrintDialogWidth);
*height = profile->GetPrefs()->GetInteger(prefs::kCloudPrintDialogHeight);
}
void CloudPrintWebDialogDelegate::Init(content::BrowserContext* browser_context,
const std::string& json_arguments) {
// This information is needed to show the dialog HTML content.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
params_.url = GURL(chrome::kChromeUICloudPrintResourcesURL);
params_.height = height;
params_.width = width;
GetDialogWidthAndHeightFromPrefs(browser_context,
&params_.width,
&params_.height);
params_.json_input = json_arguments;
flow_handler_->SetDialogDelegate(this);
// If we're not modal we can show the dialog with no browser.
// We need this to keep Chrome alive while our dialog is up.
if (!modal_)
if (!modal_parent_)
browser::StartKeepAlive();
}
......@@ -545,7 +568,7 @@ CloudPrintWebDialogDelegate::~CloudPrintWebDialogDelegate() {
}
ui::ModalType CloudPrintWebDialogDelegate::GetDialogModalType() const {
return modal_ ? ui::MODAL_TYPE_WINDOW : ui::MODAL_TYPE_NONE;
return modal_parent_ ? ui::MODAL_TYPE_WINDOW : ui::MODAL_TYPE_NONE;
}
string16 CloudPrintWebDialogDelegate::GetDialogTitle() const {
......@@ -587,7 +610,7 @@ void CloudPrintWebDialogDelegate::OnDialogClosed(
// If we're modal we can show the dialog with no browser.
// End the keep-alive so that Chrome can exit.
if (!modal_)
if (!modal_parent_)
browser::EndKeepAlive();
delete this;
}
......@@ -607,11 +630,12 @@ bool CloudPrintWebDialogDelegate::HandleContextMenu(
return true;
}
void CreatePrintDialogForBytesImpl(scoped_refptr<base::RefCountedBytes> data,
void CreatePrintDialogForBytesImpl(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
scoped_refptr<base::RefCountedBytes> data,
const string16& print_job_title,
const string16& print_ticket,
const std::string& file_type,
bool modal) {
const std::string& file_type) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
// TODO(abodenha@chromium.org) Writing the PDF to a file before printing
// is wasteful. Modify the dialog flow to pull PDF data from memory.
......@@ -622,83 +646,61 @@ void CreatePrintDialogForBytesImpl(scoped_refptr<base::RefCountedBytes> data,
reinterpret_cast<const char*>(data->front()),
data->size());
}
print_dialog_cloud::CreatePrintDialogForFile(path,
print_dialog_cloud::CreatePrintDialogForFile(browser_context,
modal_parent,
path,
print_job_title,
print_ticket,
file_type,
modal,
true);
}
// Called from the UI thread, starts up the dialog.
void CreateDialogImpl(const FilePath& path_to_file,
void CreateDialogImpl(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
const FilePath& path_to_file,
const string16& print_job_title,
const string16& print_ticket,
const std::string& file_type,
bool modal,
bool delete_on_close,
bool close_after_signin,
const base::Closure& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Browser* browser = BrowserList::GetLastActive();
const int kDefaultWidth = 912;
const int kDefaultHeight = 633;
string16 job_title = print_job_title;
Profile* profile = NULL;
if (modal) {
if (job_title.empty()) {
WebContents* web_contents = browser->GetSelectedWebContents();
if (web_contents)
job_title = web_contents->GetTitle();
}
profile = browser->profile();
} else {
std::vector<Profile*> loaded_profiles =
g_browser_process->profile_manager()->GetLoadedProfiles();
DCHECK_GT(loaded_profiles.size(), 0U);
profile = loaded_profiles[0];
browser = browser::FindLastActiveWithProfile(profile);
}
DCHECK(profile);
PrefService* pref_service = profile->GetPrefs();
DCHECK(pref_service);
if (!pref_service->FindPreference(prefs::kCloudPrintDialogWidth)) {
pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogWidth,
kDefaultWidth,
PrefService::UNSYNCABLE_PREF);
}
if (!pref_service->FindPreference(prefs::kCloudPrintDialogHeight)) {
pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogHeight,
kDefaultHeight,
PrefService::UNSYNCABLE_PREF);
}
int width = pref_service->GetInteger(prefs::kCloudPrintDialogWidth);
int height = pref_service->GetInteger(prefs::kCloudPrintDialogHeight);
WebDialogDelegate* dialog_delegate =
new internal_cloud_print_helpers::CloudPrintWebDialogDelegate(
path_to_file, width, height, std::string(), job_title, print_ticket,
file_type, modal, delete_on_close, close_after_signin,
browser_context,
modal_parent,
path_to_file,
std::string(),
print_job_title,
print_ticket,
file_type,
delete_on_close,
close_after_signin,
callback);
browser::ShowWebDialog(modal ? browser->window()->GetNativeHandle() : NULL,
profile, browser, dialog_delegate);
browser::ShowWebDialog(modal_parent,
Profile::FromBrowserContext(browser_context),
NULL,
dialog_delegate);
}
void CreateDialogSigninImpl(const base::Closure& callback) {
CreateDialogImpl(FilePath(), string16(), string16(), std::string(),
true, false, true, callback);
void CreateDialogSigninImpl(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
const base::Closure& callback) {
CreateDialogImpl(browser_context, modal_parent, FilePath(), string16(),
string16(), std::string(), false, true, callback);
}
void CreateDialogFullImpl(const FilePath& path_to_file,
const string16& print_job_title,
const string16& print_ticket,
const std::string& file_type,
bool modal,
bool delete_on_close) {
CreateDialogImpl(path_to_file, print_job_title, print_ticket, file_type,
modal, delete_on_close, false, base::Closure());
void CreateDialogFullImpl(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
const FilePath& path_to_file,
const string16& print_job_title,
const string16& print_ticket,
const std::string& file_type,
bool delete_on_close) {
CreateDialogImpl(browser_context, modal_parent, path_to_file, print_job_title,
print_ticket, file_type, delete_on_close, false,
base::Closure());
}
......@@ -718,36 +720,41 @@ namespace print_dialog_cloud {
// TODO(scottbyer): The signature here will need to change as the
// workflow through the printing code changes to allow for dynamically
// changing page setup parameters while the dialog is active.
void CreatePrintDialogForFile(const FilePath& path_to_file,
void CreatePrintDialogForFile(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
const FilePath& path_to_file,
const string16& print_job_title,
const string16& print_ticket,
const std::string& file_type,
bool modal,
bool delete_on_close) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE) ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&internal_cloud_print_helpers::CreateDialogFullImpl,
path_to_file, print_job_title, print_ticket, file_type, modal,
delete_on_close));
browser_context, modal_parent, path_to_file, print_job_title,
print_ticket, file_type, delete_on_close));
}
void CreateCloudPrintSigninDialog(const base::Closure& callback) {
void CreateCloudPrintSigninDialog(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
const base::Closure& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&internal_cloud_print_helpers::CreateDialogSigninImpl,
browser_context,
modal_parent,
callback));
}
void CreatePrintDialogForBytes(scoped_refptr<base::RefCountedBytes> data,
void CreatePrintDialogForBytes(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
scoped_refptr<base::RefCountedBytes> data,
const string16& print_job_title,
const string16& print_ticket,
const std::string& file_type,
bool modal) {
const std::string& file_type) {
// TODO(abodenha@chromium.org) Avoid cloning the PDF data. Make use of a
// shared memory object instead.
// http://code.google.com/p/chromium/issues/detail?id=44093
......@@ -756,7 +763,8 @@ void CreatePrintDialogForBytes(scoped_refptr<base::RefCountedBytes> data,
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&internal_cloud_print_helpers::CreatePrintDialogForBytesImpl,
cloned_data, print_job_title, print_ticket, file_type, modal));
browser_context, modal_parent, cloned_data, print_job_title,
print_ticket, file_type));
}
bool CreatePrintDialogFromCommandLine(const CommandLine& command_line) {
......@@ -787,12 +795,14 @@ bool CreatePrintDialogFromCommandLine(const CommandLine& command_line) {
bool delete_on_close = CommandLine::ForCurrentProcess()->HasSwitch(
switches::kCloudPrintDeleteFile);
print_dialog_cloud::CreatePrintDialogForFile(cloud_print_file,
print_job_title,
print_job_print_ticket,
file_type,
false,
delete_on_close);
print_dialog_cloud::CreatePrintDialogForFile(
ProfileManager::GetDefaultProfile(),
NULL,
cloud_print_file,
print_job_title,
print_job_print_ticket,
file_type,
delete_on_close);
return true;
}
}
......
......@@ -12,39 +12,55 @@
#include "base/callback.h"
#include "base/memory/ref_counted_memory.h"
#include "base/string16.h"
#include "ui/gfx/native_widget_types.h"
class FilePath;
class CommandLine;
namespace content {
class BrowserContext;
}
namespace print_dialog_cloud {
// Creates a print dialog to print a file on disk.
// Called on the FILE or UI thread. Even though this may start up a modal
// dialog, it will return immediately. The dialog is handled asynchronously.
void CreatePrintDialogForFile(const FilePath& path_to_file,
// If non-NULL, |modal_parent| specifies a window that the print dialog is modal
// to.
void CreatePrintDialogForFile(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
const FilePath& path_to_file,
const string16& print_job_title,
const string16& print_ticket,
const std::string& file_type,
bool modal,
bool delete_on_close);
// Creates a print dialog to print data in RAM.
// Called on the FILE or UI thread. Even though this may start up a modal
// dialog, it will return immediately. The dialog is handled asynchronously.
void CreatePrintDialogForBytes(scoped_refptr<base::RefCountedBytes> data,
// If non-NULL, |modal_parent| specifies a window that the print dialog is modal
// to.
void CreatePrintDialogForBytes(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
scoped_refptr<base::RefCountedBytes> data,
const string16& print_job_title,
const string16& print_ticket,
const std::string& file_type,
bool modal);
const std::string& file_type);
// Parse switches from command_line and display the print dialog as appropriate.
// Uses the default profile.
bool CreatePrintDialogFromCommandLine(const CommandLine& command_line);
// Creates a dialog for signing into cloud print.
// The dialog will call |callback| when complete.
// Called on the UI thread. Even though this starts up a modal
// dialog, it will return immediately. The dialog is handled asynchronously.
void CreateCloudPrintSigninDialog(const base::Closure& callback);
// If non-NULL, |modal_parent| specifies a window that the print dialog is modal
// to.
void CreateCloudPrintSigninDialog(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
const base::Closure& callback);
} // end namespace
......
......@@ -16,8 +16,8 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/printing/cloud_print/cloud_print_url.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/common/chrome_paths.h"
......@@ -208,8 +208,9 @@ class PrintDialogCloudTest : public InProcessBrowserTest {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&internal_cloud_print_helpers::CreateDialogFullImpl,
browser()->profile(), browser()->window()->GetNativeHandle(),
path_to_pdf, string16(), string16(),
std::string("application/pdf"), true, false));
std::string("application/pdf"), false));
}
bool handler_added_;
......@@ -239,9 +240,6 @@ net::URLRequestJob* PrintDialogCloudTest::Factory(net::URLRequest* request,
#define MAYBE_HandlersRegistered HandlersRegistered
#endif
IN_PROC_BROWSER_TEST_F(PrintDialogCloudTest, MAYBE_HandlersRegistered) {
BrowserList::SetLastActive(browser());
ASSERT_TRUE(BrowserList::GetLastActive());
AddTestHandlers();
TestController::GetInstance()->set_use_delegate(true);
......
......@@ -159,13 +159,13 @@ class CloudPrintFlowHandler : public content::WebUIMessageHandler,
// is closed.
class CloudPrintWebDialogDelegate : public WebDialogDelegate {
public:
CloudPrintWebDialogDelegate(const FilePath& path_to_file,
int width, int height,
CloudPrintWebDialogDelegate(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
const FilePath& path_to_file,
const std::string& json_arguments,
const string16& print_job_title,
const string16& print_ticket,
const std::string& file_type,
bool modal,
bool delete_on_close,
bool close_after_signin,
const base::Closure& callback);
......@@ -190,16 +190,16 @@ class CloudPrintWebDialogDelegate : public WebDialogDelegate {
friend class ::CloudPrintWebDialogDelegateTest;
// For unit testing.
CloudPrintWebDialogDelegate(CloudPrintFlowHandler* flow_handler,
int width, int height,
CloudPrintWebDialogDelegate(const FilePath& path_to_file,
CloudPrintFlowHandler* flow_handler,
const std::string& json_arguments,
bool modal,
bool delete_on_close);
void Init(int width, int height, const std::string& json_arguments);
void Init(content::BrowserContext* browser_context,
const std::string& json_arguments);
bool delete_on_close_;
CloudPrintFlowHandler* flow_handler_;
bool modal_;
gfx::NativeWindow modal_parent_;
mutable bool owns_flow_handler_;
FilePath path_to_file_;
......@@ -209,13 +209,16 @@ class CloudPrintWebDialogDelegate : public WebDialogDelegate {
DISALLOW_COPY_AND_ASSIGN(CloudPrintWebDialogDelegate);
};
void CreateDialogFullImpl(const FilePath& path_to_file,
void CreateDialogFullImpl(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
const FilePath& path_to_file,
const string16& print_job_title,
const string16& print_ticket,
const std::string& file_type,
bool modal,
bool delete_on_close);
void CreateDialogSigninImpl(const base::Closure& callback);
void CreateDialogSigninImpl(content::BrowserContext* browser_context,
gfx::NativeWindow modal_parent,
const base::Closure& callback);
void Delete(const FilePath& path_to_file);
......
......@@ -317,7 +317,7 @@ class CloudPrintWebDialogDelegateTest : public testing::Test {
EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(_));
EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(NULL));
delegate_.reset(new CloudPrintWebDialogDelegate(
mock_flow_handler_.get(), 100, 100, std::string(), true, false));
mock_path, mock_flow_handler_.get(), std::string(), false));
}
virtual void TearDown() {
......@@ -333,7 +333,6 @@ class CloudPrintWebDialogDelegateTest : public testing::Test {
};
TEST_F(CloudPrintWebDialogDelegateTest, BasicChecks) {
EXPECT_EQ(ui::MODAL_TYPE_WINDOW, delegate_->GetDialogModalType());
EXPECT_THAT(delegate_->GetDialogContentURL().spec(),
StrEq(chrome::kChromeUICloudPrintResourcesURL));
EXPECT_TRUE(delegate_->GetDialogTitle().empty());
......
......@@ -22,6 +22,10 @@
#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "chrome/browser/printing/print_dialog_cloud.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_view_host_delegate.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#endif
using content::BrowserThread;
......@@ -76,8 +80,9 @@ void RenderParamsFromPrintSettings(const printing::PrintSettings& settings,
} // namespace
PrintingMessageFilter::PrintingMessageFilter()
: print_job_manager_(g_browser_process->print_job_manager()) {
PrintingMessageFilter::PrintingMessageFilter(int render_process_id)
: print_job_manager_(g_browser_process->print_job_manager()),
render_process_id_(render_process_id) {
}
PrintingMessageFilter::~PrintingMessageFilter() {
......@@ -155,7 +160,8 @@ void PrintingMessageFilter::OnAllocateTempFileForPrinting(
}
}
void PrintingMessageFilter::OnTempFileForPrintingWritten(int sequence_number) {
void PrintingMessageFilter::OnTempFileForPrintingWritten(int render_view_id,
int sequence_number) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
SequenceToPathMap* map = &g_printing_file_descriptor_map.Get().map;
SequenceToPathMap::iterator it = map->find(sequence_number);
......@@ -165,12 +171,16 @@ void PrintingMessageFilter::OnTempFileForPrintingWritten(int sequence_number) {
return;
}
content::RenderViewHost* view = content::RenderViewHost::FromID(
render_process_id_, render_view_id);
content::WebContents* wc = view->GetDelegate()->GetAsWebContents();
print_dialog_cloud::CreatePrintDialogForFile(
wc->GetBrowserContext(),
wc->GetView()->GetTopLevelNativeWindow(),
it->second,
string16(),
string16(),
std::string("application/pdf"),
true,
false);
// Erase the entry in the map.
......
......@@ -30,7 +30,7 @@ class PrintJobManager;
// renderer process on the IPC thread.
class PrintingMessageFilter : public content::BrowserMessageFilter {
public:
PrintingMessageFilter();
explicit PrintingMessageFilter(int render_process_id);
// content::BrowserMessageFilter methods.
virtual void OverrideThreadForMessage(
......@@ -53,7 +53,7 @@ class PrintingMessageFilter : public content::BrowserMessageFilter {
// to fill in resulting PDF in renderer.
void OnAllocateTempFileForPrinting(base::FileDescriptor* temp_file_fd,
int* sequence_number);
void OnTempFileForPrintingWritten(int sequence_number);
void OnTempFileForPrintingWritten(int render_view_id, int sequence_number);
#endif
// Get the default print setting. The task is handled by the print
......@@ -89,6 +89,8 @@ class PrintingMessageFilter : public content::BrowserMessageFilter {
printing::PrintJobManager* print_job_manager_;
int render_process_id_;
DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter);
};
......
......@@ -48,6 +48,7 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_view_host_delegate.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/browser/web_ui.h"
#include "printing/backend/print_backend.h"
#include "printing/metafile.h"
......@@ -547,7 +548,11 @@ void PrintPreviewHandler::OnSigninComplete(
}
void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) {
gfx::NativeWindow modal_parent =
web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow();
print_dialog_cloud::CreateCloudPrintSigninDialog(
web_ui()->GetWebContents()->GetBrowserContext(),
modal_parent,
base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr()));
}
......@@ -566,11 +571,16 @@ void PrintPreviewHandler::HandlePrintWithCloudPrint() {
return;
}
DCHECK_GT(data->size(), 0U);
print_dialog_cloud::CreatePrintDialogForBytes(data,
gfx::NativeWindow modal_parent =
web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow();
print_dialog_cloud::CreatePrintDialogForBytes(
web_ui()->GetWebContents()->GetBrowserContext(),
modal_parent,
data,
string16(print_preview_ui->initiator_tab_title()),
string16(),
std::string("application/pdf"),
true);
std::string("application/pdf"));
// Once the cloud print dialog comes up we're no longer in a background
// printing situation. Close the print preview.
......
......@@ -356,7 +356,8 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint,
IPC_SYNC_MESSAGE_CONTROL0_2(PrintHostMsg_AllocateTempFileForPrinting,
base::FileDescriptor /* temp file fd */,
int /* fd in browser*/)
IPC_MESSAGE_CONTROL1(PrintHostMsg_TempFileForPrintingWritten,
IPC_MESSAGE_CONTROL2(PrintHostMsg_TempFileForPrintingWritten,
int /* render_view_id */,
int /* fd in browser */)
#endif
......
......@@ -85,7 +85,8 @@ void ChromeMockRenderThread::OnAllocateTempFileForPrinting(
}
}
void ChromeMockRenderThread::OnTempFileForPrintingWritten(int browser_fd) {
void ChromeMockRenderThread::OnTempFileForPrintingWritten(int render_view_id,
int browser_fd) {
close(browser_fd);
}
#endif // defined(OS_CHROMEOS)
......
......@@ -60,7 +60,7 @@ class ChromeMockRenderThread : public content::MockRenderThread {
#if defined(OS_CHROMEOS)
void OnAllocateTempFileForPrinting(base::FileDescriptor* renderer_fd,
int* browser_fd);
void OnTempFileForPrintingWritten(int browser_fd);
void OnTempFileForPrintingWritten(int render_view_id, int browser_fd);
#endif
// PrintWebViewHelper expects default print settings.
......
......@@ -82,7 +82,8 @@ bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) {
return false;
// Tell the browser we've finished writing the file.
Send(new PrintHostMsg_TempFileForPrintingWritten(sequence_number));
Send(new PrintHostMsg_TempFileForPrintingWritten(routing_id(),
sequence_number));
return true;
#else
PrintHostMsg_DidPrintPage_Params printed_page_params;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment