summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-01 20:12:09 +0000
committergfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-01 20:12:09 +0000
commit2a7e7c15ee743901d9384a08fe6b751b6644f16a (patch)
treea863d5e65767047f3e38ab3d5cdb937e6bac13a9
parent3491148530fd60dbd8e92cf4ee2954f948cc72d7 (diff)
downloadchromium_src-2a7e7c15ee743901d9384a08fe6b751b6644f16a.zip
chromium_src-2a7e7c15ee743901d9384a08fe6b751b6644f16a.tar.gz
chromium_src-2a7e7c15ee743901d9384a08fe6b751b6644f16a.tar.bz2
Policy to disable printing
Make Chrome refuse to print if the preference kPrintingEnabled is set to false. In this case, the 'Print...' option in the wrench menu is disabled, and if printing is invoked from JavaScript, then Chrome reports that no printer is installed. Changes to this preference after startup are also respected. BUG=54380 TEST=manual Review URL: http://codereview.chromium.org/3357011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61222 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/policy/policy_templates.grd11
-rw-r--r--chrome/app/policy/policy_templates.json10
-rw-r--r--chrome/browser/browser.cc19
-rw-r--r--chrome/browser/browser.h3
-rw-r--r--chrome/browser/browser_process_impl.cc16
-rw-r--r--chrome/browser/browser_process_impl.h4
-rw-r--r--chrome/browser/printing/print_job_manager.cc21
-rw-r--r--chrome/browser/printing/print_job_manager.h13
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc22
9 files changed, 105 insertions, 14 deletions
diff --git a/chrome/app/policy/policy_templates.grd b/chrome/app/policy/policy_templates.grd
index fed8431..d7316c2 100644
--- a/chrome/app/policy/policy_templates.grd
+++ b/chrome/app/policy/policy_templates.grd
@@ -194,6 +194,17 @@ templates and will be translated for each locale. -->
If this setting is disabled or not configured, browsing history is saved.
</message>
+ <message name="IDS_POLICY_PRINTINGENABLED_CAPTION" desc="Caption of the 'Printing enabled' policy settings page.">
+ Enable printing
+ </message>
+ <message name="IDS_POLICY_PRINTINGENABLED_DESC" desc="Description of the 'Printing enabled' policy settings page.">
+ Enables printing in <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> and prevents users from changing this setting.
+
+ If this setting is enabled or not configured, users can print.
+
+ If this setting is disabled, users cannot print from <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph>. Printing is disabled in the wrench menu, extensions, JavaScript applications, etc. It is still possible to print from plugins that bypass <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> while printing. For example certain Flash applications has the print option in their context menu, and that will not be disabled.
+ </message>
+
<message name="IDS_POLICY_AUTOFILLENABLED_CAPTION" desc="Caption of the 'autofill' policy.">
Enable AutoFill
</message>
diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json
index 2e2847e..127fbd8 100644
--- a/chrome/app/policy/policy_templates.json
+++ b/chrome/app/policy/policy_templates.json
@@ -154,6 +154,16 @@
}
},
{
+ 'name': 'PrintingEnabled',
+ 'type': 'main',
+ 'annotations': {
+ 'platforms': ['linux', 'mac', 'win'],
+ 'products': ['chrome'],
+ 'features': {'dynamic_refresh': 1},
+ 'example_value': True,
+ }
+ },
+ {
'name': 'SafeBrowsingEnabled',
'type': 'main',
'annotations': {
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index a504887..4e5128a 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -244,6 +244,15 @@ Browser::Browser(Type type, Profile* profile)
!profile->IsOffTheRecord()) {
match_preview_.reset(new MatchPreview(this));
}
+
+ PrefService *local_state = g_browser_process->local_state();
+ if (local_state) {
+ printing_enabled_.Init(prefs::kPrintingEnabled, local_state, this);
+ command_updater_.UpdateCommandEnabled(IDC_PRINT,
+ printing_enabled_.GetValue());
+ } else {
+ command_updater_.UpdateCommandEnabled(IDC_PRINT, true);
+ }
}
Browser::~Browser() {
@@ -3202,10 +3211,15 @@ void Browser::Observe(NotificationType type,
}
case NotificationType::PREF_CHANGED: {
- if (*(Details<std::string>(details).ptr()) == prefs::kUseVerticalTabs)
+ const std::string& pref_name = *Details<std::string>(details).ptr();
+ if (pref_name == prefs::kUseVerticalTabs) {
UseVerticalTabsChanged();
- else
+ } else if (pref_name == prefs::kPrintingEnabled) {
+ command_updater_.UpdateCommandEnabled(IDC_PRINT,
+ printing_enabled_.GetValue());
+ } else {
NOTREACHED();
+ }
break;
}
@@ -3289,7 +3303,6 @@ void Browser::InitCommandState() {
// Page-related commands
command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
- command_updater_.UpdateCommandEnabled(IDC_PRINT, true);
command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true);
command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true);
command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true);
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 55eb210..fe7f87c 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -1059,6 +1059,9 @@ class Browser : public TabHandlerDelegate,
// Keep track of the encoding auto detect pref.
BooleanPrefMember encoding_auto_detect_;
+ // Keep track of the printing enabled pref.
+ BooleanPrefMember printing_enabled_;
+
// Indicates if command execution is blocked.
bool block_command_execution_;
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 88b41a9..7201c08 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -638,12 +638,22 @@ void BrowserProcessImpl::CreateLocalState() {
PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
local_state_.reset(PrefService::CreatePrefService(local_state_path, NULL));
+ pref_change_registrar_.Init(local_state_.get());
+
// Make sure the the plugin updater gets notifications of changes
// in the plugin blacklist.
local_state_->RegisterListPref(prefs::kPluginsPluginsBlacklist);
- plugin_state_change_registrar_.Init(local_state_.get());
- plugin_state_change_registrar_.Add(prefs::kPluginsPluginsBlacklist,
- PluginUpdater::GetPluginUpdater());
+ pref_change_registrar_.Add(prefs::kPluginsPluginsBlacklist,
+ PluginUpdater::GetPluginUpdater());
+
+ // Initialize and set up notifications for the printing enabled
+ // preference.
+ local_state_->RegisterBooleanPref(prefs::kPrintingEnabled, true);
+ bool printing_enabled =
+ local_state_->GetBoolean(prefs::kPrintingEnabled);
+ print_job_manager_->set_printing_enabled(printing_enabled);
+ pref_change_registrar_.Add(prefs::kPrintingEnabled,
+ print_job_manager_.get());
}
void BrowserProcessImpl::CreateIconManager() {
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index 898a1b9..727cfb2 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -202,9 +202,9 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe {
// Our best estimate about the existence of the inspector directory.
bool have_inspector_files_;
- // Ensures that the observer of plugin disable/enable state
+ // Ensures that the observers of plugin/print disable/enable state
// notifications are properly added and removed.
- PrefChangeRegistrar plugin_state_change_registrar_;
+ PrefChangeRegistrar pref_change_registrar_;
#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_;
diff --git a/chrome/browser/printing/print_job_manager.cc b/chrome/browser/printing/print_job_manager.cc
index dc122ea..ce02f9e 100644
--- a/chrome/browser/printing/print_job_manager.cc
+++ b/chrome/browser/printing/print_job_manager.cc
@@ -4,9 +4,12 @@
#include "chrome/browser/printing/print_job_manager.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/printing/printer_query.h"
#include "chrome/common/notification_service.h"
+#include "chrome/common/pref_names.h"
#include "printing/printed_document.h"
#include "printing/printed_page.h"
@@ -78,6 +81,14 @@ void PrintJobManager::Observe(NotificationType type,
*Details<JobEventDetails>(details).ptr());
break;
}
+ case NotificationType::PREF_CHANGED: {
+ const std::string* pref_name = Details<std::string>(details).ptr();
+ if (*pref_name == prefs::kPrintingEnabled) {
+ PrefService *local_state = g_browser_process->local_state();
+ set_printing_enabled(local_state->GetBoolean(prefs::kPrintingEnabled));
+ }
+ break;
+ }
default: {
NOTREACHED();
break;
@@ -139,4 +150,14 @@ void PrintJobManager::OnPrintJobEvent(
}
}
+bool PrintJobManager::printing_enabled() {
+ AutoLock lock(enabled_lock_);
+ return printing_enabled_;
+}
+
+void PrintJobManager::set_printing_enabled(bool printing_enabled) {
+ AutoLock lock(enabled_lock_);
+ printing_enabled_ = printing_enabled;
+}
+
} // namespace printing
diff --git a/chrome/browser/printing/print_job_manager.h b/chrome/browser/printing/print_job_manager.h
index 59cc1ce..ca2bb47 100644
--- a/chrome/browser/printing/print_job_manager.h
+++ b/chrome/browser/printing/print_job_manager.h
@@ -43,6 +43,10 @@ class PrintJobManager : public NotificationObserver {
const NotificationSource& source,
const NotificationDetails& details);
+ bool printing_enabled();
+
+ void set_printing_enabled(bool printing_enabled);
+
private:
typedef std::vector<scoped_refptr<PrintJob> > PrintJobs;
typedef std::vector<scoped_refptr<PrinterQuery> > PrinterQueries;
@@ -56,11 +60,20 @@ class PrintJobManager : public NotificationObserver {
// Used to serialize access to queued_workers_.
Lock lock_;
+ // Used to serialize access to printing_enabled_
+ Lock enabled_lock_;
+
PrinterQueries queued_queries_;
// Current print jobs that are active.
PrintJobs current_jobs_;
+ // Printing is enabled/disabled. This variable is checked at only one place,
+ // by ResourceMessageFilter::OnGetDefaultPrintSettings. If its value is true
+ // at that point, then the initiated print flow will complete itself,
+ // even if the value of this variable changes afterwards.
+ bool printing_enabled_;
+
DISALLOW_COPY_AND_ASSIGN(PrintJobManager);
};
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index de09a9f..2f42aab 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -1144,6 +1144,12 @@ void ResourceMessageFilter::OnResolveProxyCompleted(
void ResourceMessageFilter::OnGetDefaultPrintSettings(IPC::Message* reply_msg) {
scoped_refptr<printing::PrinterQuery> printer_query;
+ if (!print_job_manager_->printing_enabled()) {
+ // Reply with NULL query.
+ OnGetDefaultPrintSettingsReply(printer_query, reply_msg);
+ return;
+ }
+
print_job_manager_->PopPrinterQuery(0, &printer_query);
if (!printer_query.get()) {
printer_query = new printing::PrinterQuery;
@@ -1168,7 +1174,8 @@ void ResourceMessageFilter::OnGetDefaultPrintSettingsReply(
scoped_refptr<printing::PrinterQuery> printer_query,
IPC::Message* reply_msg) {
ViewMsg_Print_Params params;
- if (printer_query->last_status() != printing::PrintingContext::OK) {
+ if (!printer_query.get() ||
+ printer_query->last_status() != printing::PrintingContext::OK) {
memset(&params, 0, sizeof(params));
} else {
RenderParamsFromPrintSettings(printer_query->settings(), &params);
@@ -1176,11 +1183,14 @@ void ResourceMessageFilter::OnGetDefaultPrintSettingsReply(
}
ViewHostMsg_GetDefaultPrintSettings::WriteReplyParams(reply_msg, params);
Send(reply_msg);
- // If user hasn't cancelled.
- if (printer_query->cookie() && printer_query->settings().dpi()) {
- print_job_manager_->QueuePrinterQuery(printer_query.get());
- } else {
- printer_query->StopWorker();
+ // If printing was enabled.
+ if (printer_query.get()) {
+ // If user hasn't cancelled.
+ if (printer_query->cookie() && printer_query->settings().dpi()) {
+ print_job_manager_->QueuePrinterQuery(printer_query.get());
+ } else {
+ printer_query->StopWorker();
+ }
}
}