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));
......
......@@ -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