summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/printing/print_job_worker.cc10
-rw-r--r--chrome/browser/printing/print_job_worker.h4
-rw-r--r--chrome/browser/printing/printer_query.cc4
-rw-r--r--chrome/browser/printing/printer_query.h6
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc24
-rw-r--r--gfx/native_widget_types.h20
-rw-r--r--printing/printing_context.h2
-rw-r--r--printing/printing_context_cairo.cc2
-rw-r--r--printing/printing_context_mac.mm16
-rw-r--r--printing/printing_context_win.cc13
10 files changed, 60 insertions, 41 deletions
diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc
index 34d14dc..3a9ae03 100644
--- a/chrome/browser/printing/print_job_worker.cc
+++ b/chrome/browser/printing/print_job_worker.cc
@@ -65,7 +65,7 @@ void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) {
}
void PrintJobWorker::GetSettings(bool ask_user_for_settings,
- gfx::NativeWindow parent_window,
+ gfx::NativeView parent_view,
int document_page_count,
bool has_selection,
bool use_overlays) {
@@ -82,11 +82,11 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableMethod(this, &PrintJobWorker::GetSettingsWithUI,
- parent_window, document_page_count,
+ parent_view, document_page_count,
has_selection));
#else
PrintingContext::Result result = printing_context_.AskUserForSettings(
- parent_window, document_page_count, has_selection);
+ parent_view, document_page_count, has_selection);
GetSettingsDone(result);
#endif
} else {
@@ -111,13 +111,13 @@ void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) {
}
#if defined(OS_MACOSX)
-void PrintJobWorker::GetSettingsWithUI(gfx::NativeWindow parent_window,
+void PrintJobWorker::GetSettingsWithUI(gfx::NativeView parent_view,
int document_page_count,
bool has_selection) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
PrintingContext::Result result = printing_context_.AskUserForSettings(
- parent_window, document_page_count, has_selection);
+ parent_view, document_page_count, has_selection);
message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
this, &PrintJobWorker::GetSettingsDone, result));
}
diff --git a/chrome/browser/printing/print_job_worker.h b/chrome/browser/printing/print_job_worker.h
index 8562ea9..ece1659 100644
--- a/chrome/browser/printing/print_job_worker.h
+++ b/chrome/browser/printing/print_job_worker.h
@@ -34,7 +34,7 @@ class PrintJobWorker : public base::Thread {
// Initializes the print settings. If |ask_user_for_settings| is true, a
// Print... dialog box will be shown to ask the user his preference.
void GetSettings(bool ask_user_for_settings,
- gfx::NativeWindow parent_window,
+ gfx::NativeView parent_view,
int document_page_count,
bool has_selection,
bool use_overlays);
@@ -83,7 +83,7 @@ class PrintJobWorker : public base::Thread {
#if defined(OS_MACOSX)
// Asks the user for print settings. Must be called on the UI thread.
// Mac-only since Windows can display UI from non-main threads.
- void GetSettingsWithUI(gfx::NativeWindow parent_window,
+ void GetSettingsWithUI(gfx::NativeView parent_view,
int document_page_count,
bool has_selection);
#endif
diff --git a/chrome/browser/printing/printer_query.cc b/chrome/browser/printing/printer_query.cc
index 86c0f67..9b5772fb 100644
--- a/chrome/browser/printing/printer_query.cc
+++ b/chrome/browser/printing/printer_query.cc
@@ -62,7 +62,7 @@ PrintJobWorker* PrinterQuery::DetachWorker(PrintJobWorkerOwner* new_owner) {
}
void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
- gfx::NativeWindow parent_window,
+ gfx::NativeView parent_view,
int expected_page_count,
bool has_selection,
bool use_overlays,
@@ -92,7 +92,7 @@ void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
worker_.get(),
&PrintJobWorker::GetSettings,
is_print_dialog_box_shown_,
- parent_window,
+ parent_view,
expected_page_count,
has_selection,
use_overlays));
diff --git a/chrome/browser/printing/printer_query.h b/chrome/browser/printing/printer_query.h
index 8810022..d1d054d 100644
--- a/chrome/browser/printing/printer_query.h
+++ b/chrome/browser/printing/printer_query.h
@@ -43,11 +43,11 @@ class PrinterQuery : public PrintJobWorkerOwner {
virtual int cookie() const { return cookie_; }
// Initializes the printing context. It is fine to call this function multiple
- // times to reinitialize the settings. |parent_window| parameter will be the
- // owner of the print setting dialog box. It is unused when
+ // times to reinitialize the settings. |parent_view| parameter's window will
+ // be the owner of the print setting dialog box. It is unused when
// |ask_for_user_settings| is DEFAULTS.
void GetSettings(GetSettingsAskParam ask_user_for_settings,
- gfx::NativeWindow parent_window,
+ gfx::NativeView parent_view,
int expected_page_count,
bool has_selection,
bool use_overlays,
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index bf79fa5..791cd5b 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -433,7 +433,8 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget)
IPC_MESSAGE_HANDLER(ViewHostMsg_SetCookie, OnSetCookie)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetCookies, OnGetCookies)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetRawCookies, OnGetRawCookies)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetRawCookies,
+ OnGetRawCookies)
IPC_MESSAGE_HANDLER(ViewHostMsg_DeleteCookie, OnDeleteCookie)
IPC_MESSAGE_HANDLER(ViewHostMsg_GetCookiesEnabled, OnGetCookiesEnabled)
#if defined(OS_WIN) // This hack is Windows-specific.
@@ -1131,12 +1132,8 @@ void ResourceMessageFilter::OnGetDefaultPrintSettingsReply(
void ResourceMessageFilter::OnScriptedPrint(
const ViewHostMsg_ScriptedPrint_Params& params,
IPC::Message* reply_msg) {
-#if defined(OS_WIN)
- HWND host_window = gfx::NativeViewFromId(params.host_window_id);
-#elif defined(OS_MACOSX)
- gfx::NativeWindow host_window = NULL;
- // TODO: Get an actual window ref here, to allow a sheet-based print dialog.
-#endif
+ gfx::NativeView host_view =
+ gfx::NativeViewFromIdInBrowser(params.host_window_id);
scoped_refptr<printing::PrinterQuery> printer_query;
print_job_manager_->PopPrinterQuery(params.cookie, &printer_query);
@@ -1150,20 +1147,9 @@ void ResourceMessageFilter::OnScriptedPrint(
printer_query,
params.routing_id,
reply_msg);
-#if defined(OS_WIN)
- // Shows the Print... dialog box. This is asynchronous, only the IPC message
- // sender will hang until the Print dialog is dismissed.
- if (!host_window || !IsWindow(host_window)) {
- // TODO(maruel): bug 1214347 Get the right browser window instead.
- host_window = GetDesktopWindow();
- } else {
- host_window = GetAncestor(host_window, GA_ROOTOWNER);
- }
- DCHECK(host_window);
-#endif
printer_query->GetSettings(printing::PrinterQuery::ASK_USER,
- host_window,
+ host_view,
params.expected_pages_count,
params.has_selection,
params.use_overlays,
diff --git a/gfx/native_widget_types.h b/gfx/native_widget_types.h
index b45c3b6..8cbbf8f 100644
--- a/gfx/native_widget_types.h
+++ b/gfx/native_widget_types.h
@@ -89,12 +89,26 @@ typedef intptr_t NativeViewId;
#if defined(OS_WIN)
// Convert a NativeViewId to a NativeView.
-// This is only used on Windows, where we pass an HWND into the renderer and
-// let the renderer operate on it. On other platforms, the renderer doesn't
-// have access to native platform widgets.
+//
+// On Windows, we pass an HWND into the renderer. As stated above, the renderer
+// should not be performing operations on the view.
static inline NativeView NativeViewFromId(NativeViewId id) {
return reinterpret_cast<NativeView>(id);
}
+#define NativeViewFromIdInBrowser(x) NativeViewFromId(x)
+#elif defined(OS_MACOSX)
+// On the Mac, a NativeView is a pointer to an object, and is useless outside
+// the process in which it was created. NativeViewFromId should only be used
+// inside the appropriate platform ifdef outside of the browser.
+// (NativeViewFromIdInBrowser can be used everywhere in the browser.) If your
+// cross-platform design involves a call to NativeViewFromId from outside the
+// browser it will never work on the Mac and is fundamentally broken.
+
+// Please do not call this from outside the browser. It won't work; the name
+// should give you a subtle hint.
+static inline NativeView NativeViewFromIdInBrowser(NativeViewId id) {
+ return reinterpret_cast<NativeView>(id);
+}
#endif
// Convert a NativeView to a NativeViewId. See the comments at the top of
diff --git a/printing/printing_context.h b/printing/printing_context.h
index e6efe7e..ec8a7d8 100644
--- a/printing/printing_context.h
+++ b/printing/printing_context.h
@@ -47,7 +47,7 @@ class PrintingContext {
// Asks the user what printer and format should be used to print. Updates the
// context with the select device settings.
- Result AskUserForSettings(gfx::NativeWindow window, int max_pages,
+ Result AskUserForSettings(gfx::NativeView parent_view, int max_pages,
bool has_selection);
// Selects the user's default printer and format. Updates the context with the
diff --git a/printing/printing_context_cairo.cc b/printing/printing_context_cairo.cc
index d0a571f..4d438d1 100644
--- a/printing/printing_context_cairo.cc
+++ b/printing/printing_context_cairo.cc
@@ -23,7 +23,7 @@ PrintingContext::~PrintingContext() {
}
PrintingContext::Result PrintingContext::AskUserForSettings(
- gfx::NativeWindow window,
+ gfx::NativeView parent_view,
int max_pages,
bool has_selection) {
diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm
index c4f09b0..ad09360 100644
--- a/printing/printing_context_mac.mm
+++ b/printing/printing_context_mac.mm
@@ -29,7 +29,7 @@ PrintingContext::~PrintingContext() {
PrintingContext::Result PrintingContext::AskUserForSettings(
- gfx::NativeWindow window, int max_pages, bool has_selection) {
+ gfx::NativeView parent_view, int max_pages, bool has_selection) {
DCHECK([NSThread isMainThread]);
// We deliberately don't feed max_pages into the dialog, because setting
@@ -40,6 +40,7 @@ PrintingContext::Result PrintingContext::AskUserForSettings(
// adding a new custom view to the panel on 10.5; 10.6 has
// NSPrintPanelShowsPrintSelection).
NSPrintPanel* panel = [NSPrintPanel printPanel];
+ NSPrintInfo* printInfo = [NSPrintInfo sharedPrintInfo];
NSPrintPanelOptions options = [panel options];
options |= NSPrintPanelShowsPaperSize;
@@ -47,10 +48,19 @@ PrintingContext::Result PrintingContext::AskUserForSettings(
options |= NSPrintPanelShowsScaling;
[panel setOptions:options];
+ if (parent_view) {
+ NSString* job_title = [[parent_view window] title];
+ if (job_title) {
+ PMPrintSettings printSettings =
+ (PMPrintSettings)[printInfo PMPrintSettings];
+ PMPrintSettingsSetJobName(printSettings, (CFStringRef)job_title);
+ [printInfo updateFromPMPrintSettings];
+ }
+ }
+
// TODO(stuartmorgan): We really want a tab sheet here, not a modal window.
// Will require restructuring the PrintingContext API to use a callback.
- NSInteger selection =
- [panel runModalWithPrintInfo:[NSPrintInfo sharedPrintInfo]];
+ NSInteger selection = [panel runModalWithPrintInfo:printInfo];
if (selection != NSOKButton) {
return CANCEL;
}
diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc
index 2142b0f..6215cd4 100644
--- a/printing/printing_context_win.cc
+++ b/printing/printing_context_win.cc
@@ -152,12 +152,21 @@ PrintingContext::~PrintingContext() {
}
PrintingContext::Result PrintingContext::AskUserForSettings(
- HWND window,
+ HWND view,
int max_pages,
bool has_selection) {
- DCHECK(window);
DCHECK(!in_print_job_);
dialog_box_dismissed_ = false;
+
+ HWND window;
+ if (!view || !IsWindow(view)) {
+ // TODO(maruel): bug 1214347 Get the right browser window instead.
+ window = GetDesktopWindow();
+ } else {
+ window = GetAncestor(view, GA_ROOTOWNER);
+ }
+ DCHECK(window);
+
// Show the OS-dependent dialog box.
// If the user press
// - OK, the settings are reset and reinitialized with the new settings. OK is