Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / utility / chrome_content_utility_client.cc
index 9c883f5..c66abcf 100644 (file)
@@ -20,6 +20,7 @@
 #include "chrome/common/extensions/extension_l10n_util.h"
 #include "chrome/common/extensions/update_manifest.h"
 #include "chrome/common/safe_browsing/zip_analyzer.h"
+#include "chrome/utility/chrome_content_utility_ipc_whitelist.h"
 #include "chrome/utility/cloud_print/bitmap_image.h"
 #include "chrome/utility/cloud_print/pwg_encoder.h"
 #include "chrome/utility/extensions/unpacker.h"
@@ -27,6 +28,7 @@
 #include "chrome/utility/web_resource_unpacker.h"
 #include "content/public/child/image_decoder_utils.h"
 #include "content/public/common/content_paths.h"
+#include "content/public/common/content_switches.h"
 #include "content/public/utility/utility_thread.h"
 #include "extensions/common/extension.h"
 #include "extensions/common/manifest.h"
@@ -72,7 +74,6 @@
 
 #if defined(ENABLE_MDNS)
 #include "chrome/utility/local_discovery/service_discovery_message_handler.h"
-#include "content/public/common/content_switches.h"
 #endif  // ENABLE_MDNS
 
 namespace chrome {
@@ -305,7 +306,8 @@ static base::LazyInstance<PdfFunctions> g_pdf_lib = LAZY_INSTANCE_INITIALIZER;
 
 }  // namespace
 
-ChromeContentUtilityClient::ChromeContentUtilityClient() {
+ChromeContentUtilityClient::ChromeContentUtilityClient()
+    : filter_messages_(false) {
 #if !defined(OS_ANDROID)
   handlers_.push_back(new ProfileImportHandler());
 #endif  // OS_ANDROID
@@ -326,10 +328,22 @@ void ChromeContentUtilityClient::UtilityThreadStarted() {
   std::string lang = command_line->GetSwitchValueASCII(switches::kLang);
   if (!lang.empty())
     extension_l10n_util::SetProcessLocale(lang);
+
+  if (command_line->HasSwitch(switches::kUtilityProcessRunningElevated)) {
+    message_id_whitelist_.insert(kMessageWhitelist,
+                                 kMessageWhitelist + kMessageWhitelistSize);
+    filter_messages_ = true;
+  }
 }
 
 bool ChromeContentUtilityClient::OnMessageReceived(
     const IPC::Message& message) {
+  if (filter_messages_ &&
+      (message_id_whitelist_.find(message.type()) ==
+       message_id_whitelist_.end())) {
+    return false;
+  }
+
   bool handled = true;
   IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message)
     IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension)
@@ -348,6 +362,8 @@ bool ChromeContentUtilityClient::OnMessageReceived(
     IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON)
     IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults,
                         OnGetPrinterCapsAndDefaults)
+    IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults,
+                        OnGetPrinterSemanticCapsAndDefaults)
     IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing)
     IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection,
                         OnAnalyzeZipFileForDownloadProtection)
@@ -747,6 +763,29 @@ void ChromeContentUtilityClient::OnGetPrinterCapsAndDefaults(
   ReleaseProcessIfNeeded();
 }
 
+void ChromeContentUtilityClient::OnGetPrinterSemanticCapsAndDefaults(
+    const std::string& printer_name) {
+#if defined(ENABLE_FULL_PRINTING)
+  scoped_refptr<printing::PrintBackend> print_backend =
+      printing::PrintBackend::CreateInstance(NULL);
+  printing::PrinterSemanticCapsAndDefaults printer_info;
+
+  crash_keys::ScopedPrinterInfo crash_key(
+      print_backend->GetPrinterDriverInfo(printer_name));
+
+  if (print_backend->GetPrinterSemanticCapsAndDefaults(printer_name,
+                                                       &printer_info)) {
+    Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded(
+        printer_name, printer_info));
+  } else  // NOLINT
+#endif
+  {
+    Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed(
+        printer_name));
+  }
+  ReleaseProcessIfNeeded();
+}
+
 void ChromeContentUtilityClient::OnStartupPing() {
   Send(new ChromeUtilityHostMsg_ProcessStarted);
   // Don't release the process, we assume further messages are on the way.