Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(912)

Unified Diff: chrome/browser/extensions/api/messaging/message_service.cc

Issue 591463003: Remote Assistance on Chrome OS Part III - NativeMessageHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@native_messaging
Patch Set: Address Sergey's feedback Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/messaging/message_service.cc
diff --git a/chrome/browser/extensions/api/messaging/message_service.cc b/chrome/browser/extensions/api/messaging/message_service.cc
index b6480899d69420bc0d7321932846fb59e0ca723b..d3eb43e1d8b4399b387bdc981df606b56bbc2be7 100644
--- a/chrome/browser/extensions/api/messaging/message_service.cc
+++ b/chrome/browser/extensions/api/messaging/message_service.cc
@@ -10,6 +10,7 @@
#include "base/json/json_writer.h"
#include "base/lazy_instance.h"
#include "base/metrics/histogram.h"
+#include "base/prefs/pref_service.h"
#include "base/stl_util.h"
#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
@@ -33,6 +34,7 @@
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/lazy_background_task_queue.h"
+#include "extensions/browser/pref_names.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
@@ -371,9 +373,9 @@ void MessageService::OpenChannelToNativeApp(
PrefService* pref_service = profile->GetPrefs();
// Verify that the host is not blocked by policies.
- NativeMessageProcessHost::PolicyPermission policy_permission =
- NativeMessageProcessHost::IsHostAllowed(pref_service, native_app_name);
- if (policy_permission == NativeMessageProcessHost::DISALLOW) {
+ PolicyPermission policy_permission =
+ IsHostAllowed(pref_service, native_app_name);
+ if (policy_permission == DISALLOW) {
DispatchOnDisconnect(source, receiver_port_id, kProhibitedByPoliciesError);
return;
}
@@ -387,22 +389,22 @@ void MessageService::OpenChannelToNativeApp(
content::RenderWidgetHost::FromID(source_process_id, source_routing_id)->
GetView()->GetNativeView();
- scoped_ptr<NativeMessageProcessHost> native_process =
- NativeMessageProcessHost::Create(
- native_view,
- base::WeakPtr<NativeMessageProcessHost::Client>(
- weak_factory_.GetWeakPtr()),
- source_extension_id, native_app_name, receiver_port_id,
- policy_permission == NativeMessageProcessHost::ALLOW_ALL);
+ scoped_ptr<NativeMessageHost> native_host = NativeMessageHost::Create(
+ native_view,
+ base::WeakPtr<NativeMessageHost::Client>(weak_factory_.GetWeakPtr()),
+ source_extension_id,
+ native_app_name,
+ receiver_port_id,
+ policy_permission == ALLOW_ALL);
// Abandon the channel.
- if (!native_process.get()) {
+ if (!native_host.get()) {
LOG(ERROR) << "Failed to create native process.";
DispatchOnDisconnect(
source, receiver_port_id, kReceivingEndDoesntExistError);
return;
}
- channel->receiver.reset(new NativeMessagePort(native_process.release()));
+ channel->receiver.reset(new NativeMessagePort(native_host.Pass()));
// Keep the opener alive until the channel is closed.
channel->opener->IncrementLazyKeepaliveCount();
@@ -562,8 +564,8 @@ void MessageService::PostMessage(int source_port_id, const Message& message) {
DispatchMessage(source_port_id, iter->second, message);
}
-void MessageService::PostMessageFromNativeProcess(int port_id,
- const std::string& message) {
+void MessageService::PostMessageFromNativeHost(int port_id,
+ const std::string& message) {
PostMessage(port_id, Message(message, false /* user_gesture */));
}
@@ -584,6 +586,45 @@ void MessageService::Observe(int type,
}
}
+// static
+MessageService::PolicyPermission MessageService::IsHostAllowed(
+ const PrefService* pref_service,
+ const std::string& native_host_name) {
+ PolicyPermission allow_result = ALLOW_ALL;
+ if (pref_service->IsManagedPreference(
+ pref_names::kNativeMessagingUserLevelHosts)) {
+ if (!pref_service->GetBoolean(pref_names::kNativeMessagingUserLevelHosts))
+ allow_result = ALLOW_SYSTEM_ONLY;
+ }
+
+ // All native messaging hosts are allowed if there is no blacklist.
+ if (!pref_service->IsManagedPreference(pref_names::kNativeMessagingBlacklist))
+ return allow_result;
+ const base::ListValue* blacklist =
+ pref_service->GetList(pref_names::kNativeMessagingBlacklist);
+ if (!blacklist)
+ return allow_result;
+
+ // Check if the name or the wildcard is in the blacklist.
+ base::StringValue name_value(native_host_name);
+ base::StringValue wildcard_value("*");
+ if (blacklist->Find(name_value) == blacklist->end() &&
+ blacklist->Find(wildcard_value) == blacklist->end()) {
+ return allow_result;
+ }
+
+ // The native messaging host is blacklisted. Check the whitelist.
+ if (pref_service->IsManagedPreference(
+ pref_names::kNativeMessagingWhitelist)) {
+ const base::ListValue* whitelist =
+ pref_service->GetList(pref_names::kNativeMessagingWhitelist);
+ if (whitelist && whitelist->Find(name_value) != whitelist->end())
+ return allow_result;
+ }
+
+ return DISALLOW;
+}
+
void MessageService::OnProcessClosed(content::RenderProcessHost* process) {
// Close any channels that share this renderer. We notify the opposite
// port that his pair has closed.

Powered by Google App Engine
This is Rietveld 408576698