summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/printing/print_job_worker.cc30
-rw-r--r--chrome/browser/printing/print_job_worker.h27
-rw-r--r--chrome/browser/printing/printer_query.cc21
-rw-r--r--chrome/browser/printing/printer_query.h24
-rw-r--r--chrome/browser/printing/printing_message_filter.cc7
-rw-r--r--chrome/browser/printing/printing_ui_web_contents_observer.cc20
-rw-r--r--chrome/browser/printing/printing_ui_web_contents_observer.h25
-rw-r--r--chrome/chrome_browser.gypi2
8 files changed, 113 insertions, 43 deletions
diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc
index a3298f5..66477b1 100644
--- a/chrome/browser/printing/print_job_worker.cc
+++ b/chrome/browser/printing/print_job_worker.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/printing/print_job.h"
+#include "chrome/browser/printing/printing_ui_web_contents_observer.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "grit/generated_resources.h"
@@ -77,11 +78,12 @@ void PrintJobWorker::SetPrintDestination(
destination_ = destination;
}
-void PrintJobWorker::GetSettings(bool ask_user_for_settings,
- gfx::NativeView parent_view,
- int document_page_count,
- bool has_selection,
- MarginType margin_type) {
+void PrintJobWorker::GetSettings(
+ bool ask_user_for_settings,
+ scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer,
+ int document_page_count,
+ bool has_selection,
+ MarginType margin_type) {
DCHECK_EQ(message_loop(), base::MessageLoop::current());
DCHECK_EQ(page_number_, PageNumber::npos());
@@ -100,8 +102,10 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
BrowserThread::UI, FROM_HERE,
base::Bind(&HoldRefCallback, make_scoped_refptr(owner_),
base::Bind(&PrintJobWorker::GetSettingsWithUI,
- base::Unretained(this), parent_view,
- document_page_count, has_selection)));
+ base::Unretained(this),
+ base::Passed(&web_contents_observer),
+ document_page_count,
+ has_selection)));
} else {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
@@ -169,11 +173,17 @@ void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) {
result));
}
-void PrintJobWorker::GetSettingsWithUI(gfx::NativeView parent_view,
- int document_page_count,
- bool has_selection) {
+void PrintJobWorker::GetSettingsWithUI(
+ scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer,
+ int document_page_count,
+ bool has_selection) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ gfx::NativeView parent_view = web_contents_observer->GetParentView();
+ if (!parent_view) {
+ GetSettingsWithUIDone(printing::PrintingContext::FAILED);
+ return;
+ }
printing_context_->AskUserForSettings(
parent_view, document_page_count, has_selection,
base::Bind(&PrintJobWorker::GetSettingsWithUIDone,
diff --git a/chrome/browser/printing/print_job_worker.h b/chrome/browser/printing/print_job_worker.h
index 2b639fa..beb3cd7 100644
--- a/chrome/browser/printing/print_job_worker.h
+++ b/chrome/browser/printing/print_job_worker.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H__
-#define CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H__
+#ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H_
+#define CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H_
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
@@ -13,7 +13,8 @@
#include "printing/print_destination_interface.h"
#include "printing/printing_context.h"
#include "printing/print_job_constants.h"
-#include "ui/gfx/native_widget_types.h"
+
+class PrintingUIWebContentsObserver;
namespace base {
class DictionaryValue;
@@ -45,11 +46,12 @@ 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::NativeView parent_view,
- int document_page_count,
- bool has_selection,
- MarginType margin_type);
+ void GetSettings(
+ bool ask_user_for_settings,
+ scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer,
+ int document_page_count,
+ bool has_selection,
+ MarginType margin_type);
// Set the new print settings. This function takes ownership of
// |new_settings|.
@@ -95,9 +97,10 @@ class PrintJobWorker : public base::Thread {
// Asks the user for print settings. Must be called on the UI thread.
// Required on Mac and Linux. Windows can display UI from non-main threads,
// but sticks with this for consistency.
- void GetSettingsWithUI(gfx::NativeView parent_view,
- int document_page_count,
- bool has_selection);
+ void GetSettingsWithUI(
+ scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer,
+ int document_page_count,
+ bool has_selection);
// The callback used by PrintingContext::GetSettingsWithUI() to notify this
// object that the print settings are set. This is needed in order to bounce
@@ -140,4 +143,4 @@ class PrintJobWorker : public base::Thread {
} // namespace printing
-#endif // CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H__
+#endif // CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H_
diff --git a/chrome/browser/printing/printer_query.cc b/chrome/browser/printing/printer_query.cc
index 6935975..03198e2 100644
--- a/chrome/browser/printing/printer_query.cc
+++ b/chrome/browser/printing/printer_query.cc
@@ -10,6 +10,7 @@
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "chrome/browser/printing/print_job_worker.h"
+#include "chrome/browser/printing/printing_ui_web_contents_observer.h"
namespace printing {
@@ -68,12 +69,13 @@ int PrinterQuery::cookie() const {
return cookie_;
}
-void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
- gfx::NativeView parent_view,
- int expected_page_count,
- bool has_selection,
- MarginType margin_type,
- const base::Closure& callback) {
+void PrinterQuery::GetSettings(
+ GetSettingsAskParam ask_user_for_settings,
+ scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer,
+ int expected_page_count,
+ bool has_selection,
+ MarginType margin_type,
+ const base::Closure& callback) {
DCHECK_EQ(io_message_loop_, base::MessageLoop::current());
DCHECK(!is_print_dialog_box_shown_);
@@ -85,8 +87,11 @@ void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
FROM_HERE,
base::Bind(&PrintJobWorker::GetSettings,
base::Unretained(worker_.get()),
- is_print_dialog_box_shown_, parent_view,
- expected_page_count, has_selection, margin_type));
+ is_print_dialog_box_shown_,
+ base::Passed(&web_contents_observer),
+ expected_page_count,
+ has_selection,
+ margin_type));
}
void PrinterQuery::SetSettings(const DictionaryValue& new_settings,
diff --git a/chrome/browser/printing/printer_query.h b/chrome/browser/printing/printer_query.h
index 3256a91..aab4914 100644
--- a/chrome/browser/printing/printer_query.h
+++ b/chrome/browser/printing/printer_query.h
@@ -10,7 +10,8 @@
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/printing/print_job_worker_owner.h"
#include "printing/print_job_constants.h"
-#include "ui/gfx/native_widget_types.h"
+
+class PrintingUIWebContentsObserver;
namespace base {
class DictionaryValue;
@@ -19,8 +20,8 @@ class MessageLoop;
namespace printing {
- class PrintDestinationInterface;
- class PrintJobWorker;
+class PrintDestinationInterface;
+class PrintJobWorker;
// Query the printer for settings.
class PrinterQuery : public PrintJobWorkerOwner {
@@ -42,15 +43,16 @@ class PrinterQuery : public PrintJobWorkerOwner {
virtual int cookie() const OVERRIDE;
// Initializes the printing context. It is fine to call this function multiple
- // times to reinitialize the settings. |parent_view| parameter's window will
- // be the owner of the print setting dialog box. It is unused when
+ // times to reinitialize the settings. |web_contents_observer| can be queried
+ // to find 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::NativeView parent_view,
- int expected_page_count,
- bool has_selection,
- MarginType margin_type,
- const base::Closure& callback);
+ void GetSettings(
+ GetSettingsAskParam ask_user_for_settings,
+ scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer,
+ int expected_page_count,
+ bool has_selection,
+ MarginType margin_type,
+ const base::Closure& callback);
// Updates the current settings with |new_settings| dictionary values.
void SetSettings(const base::DictionaryValue& new_settings,
diff --git a/chrome/browser/printing/printing_message_filter.cc b/chrome/browser/printing/printing_message_filter.cc
index 79a1194..5b48b89 100644
--- a/chrome/browser/printing/printing_message_filter.cc
+++ b/chrome/browser/printing/printing_message_filter.cc
@@ -10,13 +10,13 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/printing/printer_query.h"
#include "chrome/browser/printing/print_job_manager.h"
+#include "chrome/browser/printing/printing_ui_web_contents_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/common/print_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
#if defined(ENABLE_FULL_PRINTING)
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
@@ -30,6 +30,7 @@
#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "chrome/browser/printing/print_dialog_cloud.h"
+#include "content/public/browser/web_contents_view.h"
#endif
#if defined(OS_ANDROID)
@@ -273,10 +274,12 @@ void PrintingMessageFilter::GetPrintSettingsForRenderView(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
content::WebContents* wc = GetWebContentsForRenderView(render_view_id);
if (wc) {
+ scoped_ptr<PrintingUIWebContentsObserver> wc_observer(
+ new PrintingUIWebContentsObserver(wc));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&printing::PrinterQuery::GetSettings, printer_query,
- params.ask_user_for_settings, wc->GetView()->GetNativeView(),
+ params.ask_user_for_settings, base::Passed(&wc_observer),
params.expected_page_count, params.has_selection,
params.margin_type, callback));
} else {
diff --git a/chrome/browser/printing/printing_ui_web_contents_observer.cc b/chrome/browser/printing/printing_ui_web_contents_observer.cc
new file mode 100644
index 0000000..03a09f7
--- /dev/null
+++ b/chrome/browser/printing/printing_ui_web_contents_observer.cc
@@ -0,0 +1,20 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/printing/printing_ui_web_contents_observer.h"
+
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+
+PrintingUIWebContentsObserver::PrintingUIWebContentsObserver(
+ content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+}
+
+gfx::NativeView PrintingUIWebContentsObserver::GetParentView() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ return web_contents() ? web_contents()->GetView()->GetNativeView() : NULL;
+}
diff --git a/chrome/browser/printing/printing_ui_web_contents_observer.h b/chrome/browser/printing/printing_ui_web_contents_observer.h
new file mode 100644
index 0000000..66d51e7
--- /dev/null
+++ b/chrome/browser/printing/printing_ui_web_contents_observer.h
@@ -0,0 +1,25 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PRINTING_PRINTING_UI_WEB_CONTENTS_OBSERVER_H_
+#define CHROME_BROWSER_PRINTING_PRINTING_UI_WEB_CONTENTS_OBSERVER_H_
+
+#include "base/basictypes.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "ui/gfx/native_widget_types.h"
+
+// Wrapper used to keep track of the lifetime of a WebContents.
+// Lives on the UI thread.
+class PrintingUIWebContentsObserver : public content::WebContentsObserver {
+ public:
+ explicit PrintingUIWebContentsObserver(content::WebContents* web_contents);
+
+ // Return the parent NativeView of the observed WebContents.
+ gfx::NativeView GetParentView();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PrintingUIWebContentsObserver);
+};
+
+#endif // CHROME_BROWSER_PRINTING_PRINTING_UI_WEB_CONTENTS_OBSERVER_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 02560ce..0090b52 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1695,6 +1695,8 @@
'browser/printing/printer_query.h',
'browser/printing/printing_message_filter.cc',
'browser/printing/printing_message_filter.h',
+ 'browser/printing/printing_ui_web_contents_observer.cc',
+ 'browser/printing/printing_ui_web_contents_observer.h',
'browser/process_info_snapshot.h',
'browser/process_info_snapshot_mac.cc',
'browser/process_singleton.h',