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'; ...@@ -1140,9 +1140,9 @@ const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
string16 title16 = base::SysNSStringToUTF16(printTitle); string16 title16 = base::SysNSStringToUTF16(printTitle);
string16 printTicket16 = base::SysNSStringToUTF16(printTicket); string16 printTicket16 = base::SysNSStringToUTF16(printTicket);
print_dialog_cloud::CreatePrintDialogForFile( print_dialog_cloud::CreatePrintDialogForFile(
ProfileManager::GetDefaultProfile(), NULL,
FilePath([inputPath UTF8String]), title16, FilePath([inputPath UTF8String]), title16,
printTicket16, [mime UTF8String], /*modal=*/false, printTicket16, [mime UTF8String], /*delete_on_close=*/false);
/*delete_on_close=*/false);
} }
} }
......
...@@ -412,7 +412,7 @@ void ChromeContentBrowserClient::RenderProcessHostCreated( ...@@ -412,7 +412,7 @@ void ChromeContentBrowserClient::RenderProcessHostCreated(
id, profile, profile->GetRequestContextForRenderProcess(id))); id, profile, profile->GetRequestContextForRenderProcess(id)));
host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile)); host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
host->GetChannel()->AddFilter(new PrintingMessageFilter()); host->GetChannel()->AddFilter(new PrintingMessageFilter(id));
#endif #endif
host->GetChannel()->AddFilter( host->GetChannel()->AddFilter(
new SearchProviderInstallStateMessageFilter(id, profile)); new SearchProviderInstallStateMessageFilter(id, profile));
......
...@@ -12,39 +12,55 @@ ...@@ -12,39 +12,55 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/string16.h" #include "base/string16.h"
#include "ui/gfx/native_widget_types.h"
class FilePath; class FilePath;
class CommandLine; class CommandLine;
namespace content {
class BrowserContext;
}
namespace print_dialog_cloud { namespace print_dialog_cloud {
// Creates a print dialog to print a file on disk. // 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 // 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. // 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_job_title,
const string16& print_ticket, const string16& print_ticket,
const std::string& file_type, const std::string& file_type,
bool modal,
bool delete_on_close); bool delete_on_close);
// Creates a print dialog to print data in RAM. // Creates a print dialog to print data in RAM.
// Called on the FILE or UI thread. Even though this may start up a modal // 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. // 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_job_title,
const string16& print_ticket, const string16& print_ticket,
const std::string& file_type, const std::string& file_type);
bool modal);
// Parse switches from command_line and display the print dialog as appropriate. // Parse switches from command_line and display the print dialog as appropriate.
// Uses the default profile.
bool CreatePrintDialogFromCommandLine(const CommandLine& command_line); bool CreatePrintDialogFromCommandLine(const CommandLine& command_line);
// Creates a dialog for signing into cloud print. // Creates a dialog for signing into cloud print.
// The dialog will call |callback| when complete. // The dialog will call |callback| when complete.
// Called on the UI thread. Even though this starts up a modal // Called on the UI thread. Even though this starts up a modal
// dialog, it will return immediately. The dialog is handled asynchronously. // 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 } // end namespace
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/printing/cloud_print/cloud_print_url.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.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
...@@ -208,8 +208,9 @@ class PrintDialogCloudTest : public InProcessBrowserTest { ...@@ -208,8 +208,9 @@ class PrintDialogCloudTest : public InProcessBrowserTest {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(&internal_cloud_print_helpers::CreateDialogFullImpl, base::Bind(&internal_cloud_print_helpers::CreateDialogFullImpl,
browser()->profile(), browser()->window()->GetNativeHandle(),
path_to_pdf, string16(), string16(), path_to_pdf, string16(), string16(),
std::string("application/pdf"), true, false)); std::string("application/pdf"), false));
} }
bool handler_added_; bool handler_added_;
...@@ -239,9 +240,6 @@ net::URLRequestJob* PrintDialogCloudTest::Factory(net::URLRequest* request, ...@@ -239,9 +240,6 @@ net::URLRequestJob* PrintDialogCloudTest::Factory(net::URLRequest* request,
#define MAYBE_HandlersRegistered HandlersRegistered #define MAYBE_HandlersRegistered HandlersRegistered
#endif #endif
IN_PROC_BROWSER_TEST_F(PrintDialogCloudTest, MAYBE_HandlersRegistered) { IN_PROC_BROWSER_TEST_F(PrintDialogCloudTest, MAYBE_HandlersRegistered) {
BrowserList::SetLastActive(browser());
ASSERT_TRUE(BrowserList::GetLastActive());
AddTestHandlers(); AddTestHandlers();
TestController::GetInstance()->set_use_delegate(true); TestController::GetInstance()->set_use_delegate(true);
......
...@@ -159,13 +159,13 @@ class CloudPrintFlowHandler : public content::WebUIMessageHandler, ...@@ -159,13 +159,13 @@ class CloudPrintFlowHandler : public content::WebUIMessageHandler,
// is closed. // is closed.
class CloudPrintWebDialogDelegate : public WebDialogDelegate { class CloudPrintWebDialogDelegate : public WebDialogDelegate {
public: public:
CloudPrintWebDialogDelegate(const FilePath& path_to_file, CloudPrintWebDialogDelegate(content::BrowserContext* browser_context,
int width, int height, gfx::NativeWindow modal_parent,
const FilePath& path_to_file,
const std::string& json_arguments, const std::string& json_arguments,
const string16& print_job_title, const string16& print_job_title,
const string16& print_ticket, const string16& print_ticket,
const std::string& file_type, const std::string& file_type,
bool modal,
bool delete_on_close, bool delete_on_close,
bool close_after_signin, bool close_after_signin,
const base::Closure& callback); const base::Closure& callback);
...@@ -190,16 +190,16 @@ class CloudPrintWebDialogDelegate : public WebDialogDelegate { ...@@ -190,16 +190,16 @@ class CloudPrintWebDialogDelegate : public WebDialogDelegate {
friend class ::CloudPrintWebDialogDelegateTest; friend class ::CloudPrintWebDialogDelegateTest;
// For unit testing. // For unit testing.
CloudPrintWebDialogDelegate(CloudPrintFlowHandler* flow_handler, CloudPrintWebDialogDelegate(const FilePath& path_to_file,
int width, int height, CloudPrintFlowHandler* flow_handler,
const std::string& json_arguments, const std::string& json_arguments,
bool modal,
bool delete_on_close); 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_; bool delete_on_close_;
CloudPrintFlowHandler* flow_handler_; CloudPrintFlowHandler* flow_handler_;
bool modal_; gfx::NativeWindow modal_parent_;
mutable bool owns_flow_handler_; mutable bool owns_flow_handler_;
FilePath path_to_file_; FilePath path_to_file_;
...@@ -209,13 +209,16 @@ class CloudPrintWebDialogDelegate : public WebDialogDelegate { ...@@ -209,13 +209,16 @@ class CloudPrintWebDialogDelegate : public WebDialogDelegate {
DISALLOW_COPY_AND_ASSIGN(CloudPrintWebDialogDelegate); 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_job_title,
const string16& print_ticket, const string16& print_ticket,
const std::string& file_type, const std::string& file_type,
bool modal,
bool delete_on_close); 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); void Delete(const FilePath& path_to_file);
......
...@@ -317,7 +317,7 @@ class CloudPrintWebDialogDelegateTest : public testing::Test { ...@@ -317,7 +317,7 @@ class CloudPrintWebDialogDelegateTest : public testing::Test {
EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(_)); EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(_));
EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(NULL)); EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(NULL));
delegate_.reset(new CloudPrintWebDialogDelegate( 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() { virtual void TearDown() {
...@@ -333,7 +333,6 @@ class CloudPrintWebDialogDelegateTest : public testing::Test { ...@@ -333,7 +333,6 @@ class CloudPrintWebDialogDelegateTest : public testing::Test {
}; };
TEST_F(CloudPrintWebDialogDelegateTest, BasicChecks) { TEST_F(CloudPrintWebDialogDelegateTest, BasicChecks) {
EXPECT_EQ(ui::MODAL_TYPE_WINDOW, delegate_->GetDialogModalType());
EXPECT_THAT(delegate_->GetDialogContentURL().spec(), EXPECT_THAT(delegate_->GetDialogContentURL().spec(),
StrEq(chrome::kChromeUICloudPrintResourcesURL)); StrEq(chrome::kChromeUICloudPrintResourcesURL));
EXPECT_TRUE(delegate_->GetDialogTitle().empty()); EXPECT_TRUE(delegate_->GetDialogTitle().empty());
......
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "chrome/browser/printing/print_dialog_cloud.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 #endif
using content::BrowserThread; using content::BrowserThread;
...@@ -76,8 +80,9 @@ void RenderParamsFromPrintSettings(const printing::PrintSettings& settings, ...@@ -76,8 +80,9 @@ void RenderParamsFromPrintSettings(const printing::PrintSettings& settings,
} // namespace } // namespace
PrintingMessageFilter::PrintingMessageFilter() PrintingMessageFilter::PrintingMessageFilter(int render_process_id)
: print_job_manager_(g_browser_process->print_job_manager()) { : print_job_manager_(g_browser_process->print_job_manager()),
render_process_id_(render_process_id) {
} }
PrintingMessageFilter::~PrintingMessageFilter() { PrintingMessageFilter::~PrintingMessageFilter() {
...@@ -155,7 +160,8 @@ void PrintingMessageFilter::OnAllocateTempFileForPrinting( ...@@ -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)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
SequenceToPathMap* map = &g_printing_file_descriptor_map.Get().map; SequenceToPathMap* map = &g_printing_file_descriptor_map.Get().map;
SequenceToPathMap::iterator it = map->find(sequence_number); SequenceToPathMap::iterator it = map->find(sequence_number);
...@@ -165,12 +171,16 @@ void PrintingMessageFilter::OnTempFileForPrintingWritten(int sequence_number) { ...@@ -165,12 +171,16 @@ void PrintingMessageFilter::OnTempFileForPrintingWritten(int sequence_number) {
return; return;
} }
content::RenderViewHost* view = content::RenderViewHost::FromID(
render_process_id_, render_view_id);
content::WebContents* wc = view->GetDelegate()->GetAsWebContents();
print_dialog_cloud::CreatePrintDialogForFile( print_dialog_cloud::CreatePrintDialogForFile(
wc->GetBrowserContext(),
wc->GetView()->GetTopLevelNativeWindow(),
it->second, it->second,
string16(), string16(),
string16(), string16(),
std::string("application/pdf"), std::string("application/pdf"),
true,
false); false);
// Erase the entry in the map. // Erase the entry in the map.
......
...@@ -30,7 +30,7 @@ class PrintJobManager; ...@@ -30,7 +30,7 @@ class PrintJobManager;
// renderer process on the IPC thread. // renderer process on the IPC thread.
class PrintingMessageFilter : public content::BrowserMessageFilter { class PrintingMessageFilter : public content::BrowserMessageFilter {
public: public:
PrintingMessageFilter(); explicit PrintingMessageFilter(int render_process_id);
// content::BrowserMessageFilter methods. // content::BrowserMessageFilter methods.
virtual void OverrideThreadForMessage( virtual void OverrideThreadForMessage(
...@@ -53,7 +53,7 @@ class PrintingMessageFilter : public content::BrowserMessageFilter { ...@@ -53,7 +53,7 @@ class PrintingMessageFilter : public content::BrowserMessageFilter {
// to fill in resulting PDF in renderer. // to fill in resulting PDF in renderer.
void OnAllocateTempFileForPrinting(base::FileDescriptor* temp_file_fd, void OnAllocateTempFileForPrinting(base::FileDescriptor* temp_file_fd,
int* sequence_number); int* sequence_number);
void OnTempFileForPrintingWritten(int sequence_number); void OnTempFileForPrintingWritten(int render_view_id, int sequence_number);
#endif #endif
// Get the default print setting. The task is handled by the print // Get the default print setting. The task is handled by the print
...@@ -89,6 +89,8 @@ class PrintingMessageFilter : public content::BrowserMessageFilter { ...@@ -89,6 +89,8 @@ class PrintingMessageFilter : public content::BrowserMessageFilter {
printing::PrintJobManager* print_job_manager_; printing::PrintJobManager* print_job_manager_;
int render_process_id_;
DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter); DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter);
}; };
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_view_host_delegate.h" #include "content/public/browser/render_view_host_delegate.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "printing/backend/print_backend.h" #include "printing/backend/print_backend.h"
#include "printing/metafile.h" #include "printing/metafile.h"
...@@ -547,7 +548,11 @@ void PrintPreviewHandler::OnSigninComplete( ...@@ -547,7 +548,11 @@ void PrintPreviewHandler::OnSigninComplete(
} }
void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) { void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) {
gfx::NativeWindow modal_parent =
web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow();
print_dialog_cloud::CreateCloudPrintSigninDialog( print_dialog_cloud::CreateCloudPrintSigninDialog(
web_ui()->GetWebContents()->GetBrowserContext(),
modal_parent,
base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr())); base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr()));
} }
...@@ -566,11 +571,16 @@ void PrintPreviewHandler::HandlePrintWithCloudPrint() { ...@@ -566,11 +571,16 @@ void PrintPreviewHandler::HandlePrintWithCloudPrint() {
return; return;
} }
DCHECK_GT(data->size(), 0U); 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(print_preview_ui->initiator_tab_title()),
string16(), string16(),
std::string("application/pdf"), std::string("application/pdf"));
true);
// Once the cloud print dialog comes up we're no longer in a background // Once the cloud print dialog comes up we're no longer in a background
// printing situation. Close the print preview. // printing situation. Close the print preview.
......
...@@ -356,7 +356,8 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint, ...@@ -356,7 +356,8 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint,
IPC_SYNC_MESSAGE_CONTROL0_2(PrintHostMsg_AllocateTempFileForPrinting, IPC_SYNC_MESSAGE_CONTROL0_2(PrintHostMsg_AllocateTempFileForPrinting,
base::FileDescriptor /* temp file fd */, base::FileDescriptor /* temp file fd */,
int /* fd in browser*/) int /* fd in browser*/)
IPC_MESSAGE_CONTROL1(PrintHostMsg_TempFileForPrintingWritten, IPC_MESSAGE_CONTROL2(PrintHostMsg_TempFileForPrintingWritten,
int /* render_view_id */,
int /* fd in browser */) int /* fd in browser */)
#endif #endif
......
...@@ -85,7 +85,8 @@ void ChromeMockRenderThread::OnAllocateTempFileForPrinting( ...@@ -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); close(browser_fd);
} }
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
......
...@@ -60,7 +60,7 @@ class ChromeMockRenderThread : public content::MockRenderThread { ...@@ -60,7 +60,7 @@ class ChromeMockRenderThread : public content::MockRenderThread {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
void OnAllocateTempFileForPrinting(base::FileDescriptor* renderer_fd, void OnAllocateTempFileForPrinting(base::FileDescriptor* renderer_fd,
int* browser_fd); int* browser_fd);
void OnTempFileForPrintingWritten(int browser_fd); void OnTempFileForPrintingWritten(int render_view_id, int browser_fd);
#endif #endif
// PrintWebViewHelper expects default print settings. // PrintWebViewHelper expects default print settings.
......
...@@ -82,7 +82,8 @@ bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) { ...@@ -82,7 +82,8 @@ bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) {
return false; return false;
// Tell the browser we've finished writing the file. // 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; return true;
#else #else
PrintHostMsg_DidPrintPage_Params printed_page_params; 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