Commit 08ad9575 authored by bartfab@chromium.org's avatar bartfab@chromium.org

Block printing through JS when printing is disabled by policy or pref

This CL ensures that when the PrintingEnabled policy or the corresponding
printing.enabled pref is set, the JS window.print() call is completely
ignored. Previously, it was bringing up a print preview dialog.

BUG=107709
TEST=Policy and pref both successfully block JS printing


Review URL: https://chromiumcodereview.appspot.com/10689190

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148622 0039d316-1c4b-4281-b951-d872f2087c98
parent 3766ed1c
......@@ -18,9 +18,11 @@
#include "chrome/browser/printing/print_preview_tab_controller.h"
#include "chrome/browser/printing/print_view_manager_observer.h"
#include "chrome/browser/printing/printer_query.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/print_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
......@@ -38,7 +40,6 @@
using base::TimeDelta;
using content::BrowserThread;
using content::RenderViewHost;
namespace {
......@@ -62,12 +63,16 @@ PrintViewManager::PrintViewManager(TabContents* tab)
observer_(NULL),
cookie_(0),
print_preview_state_(NOT_PREVIEWING),
scripted_print_preview_rph_(NULL) {
scripted_print_preview_rph_(NULL),
tab_content_blocked_(false) {
#if defined(OS_POSIX) && !defined(OS_MACOSX)
expecting_first_page_ = true;
#endif
registrar_.Add(this, chrome::NOTIFICATION_CONTENT_BLOCKED_STATE_CHANGED,
content::Source<TabContents>(tab));
printing_enabled_.Init(prefs::kPrintingEnabled,
tab->profile()->GetPrefs(),
this);
}
PrintViewManager::~PrintViewManager() {
......@@ -144,8 +149,10 @@ void PrintViewManager::PrintPreviewDone() {
print_preview_state_ = NOT_PREVIEWING;
}
void PrintViewManager::SetScriptedPrintingBlocked(bool blocked) {
Send(new PrintMsg_SetScriptedPrintingBlocked(routing_id(), blocked));
void PrintViewManager::UpdateScriptedPrintingBlocked() {
Send(new PrintMsg_SetScriptedPrintingBlocked(
routing_id(),
!printing_enabled_.GetValue() || tab_content_blocked_));
}
void PrintViewManager::set_observer(PrintViewManagerObserver* observer) {
......@@ -320,6 +327,11 @@ void PrintViewManager::OnScriptedPrintPreviewReply(IPC::Message* reply_msg) {
Send(reply_msg);
}
void PrintViewManager::DidStartLoading(
content::RenderViewHost* render_view_host) {
UpdateScriptedPrintingBlocked();
}
bool PrintViewManager::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message)
......@@ -345,8 +357,13 @@ void PrintViewManager::Observe(int type,
OnNotifyPrintJobEvent(*content::Details<JobEventDetails>(details).ptr());
break;
}
case chrome::NOTIFICATION_PREF_CHANGED: {
UpdateScriptedPrintingBlocked();
break;
}
case chrome::NOTIFICATION_CONTENT_BLOCKED_STATE_CHANGED: {
SetScriptedPrintingBlocked(*content::Details<const bool>(details).ptr());
tab_content_blocked_ = *content::Details<const bool>(details).ptr();
UpdateScriptedPrintingBlocked();
break;
}
default: {
......
......@@ -7,6 +7,7 @@
#include "base/memory/ref_counted.h"
#include "base/string16.h"
#include "chrome/browser/prefs/pref_member.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_observer.h"
......@@ -17,6 +18,7 @@ struct PrintHostMsg_DidPrintPage_Params;
namespace content {
class RenderProcessHost;
class RenderViewHost;
}
namespace printing {
......@@ -69,8 +71,8 @@ class PrintViewManager : public content::NotificationObserver,
// renderer in the case of scripted print preview.
void PrintPreviewDone();
// Whether to block scripted printing or not.
void SetScriptedPrintingBlocked(bool blocked);
// Whether to block scripted printing for our tab or not.
void UpdateScriptedPrintingBlocked();
// Sets |observer| as the current PrintViewManagerObserver. Pass in NULL to
// remove the current observer. |observer| may always be NULL, but |observer_|
......@@ -85,6 +87,10 @@ class PrintViewManager : public content::NotificationObserver,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// content::WebContentsObserver implementation.
virtual void DidStartLoading(
content::RenderViewHost* render_view_host) OVERRIDE;
// content::WebContentsObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
......@@ -203,6 +209,12 @@ class PrintViewManager : public content::NotificationObserver,
// Keeps track of the pending callback during scripted print preview.
content::RenderProcessHost* scripted_print_preview_rph_;
// Whether printing is enabled.
BooleanPrefMember printing_enabled_;
// Whether our tab content is in blocked state.
bool tab_content_blocked_;
DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
};
......
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