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

Unified Diff: chrome/browser/extensions/api/messaging/native_message_host_chromeos.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/native_message_host_chromeos.cc
diff --git a/chrome/browser/extensions/api/messaging/native_message_host_chromeos.cc b/chrome/browser/extensions/api/messaging/native_message_host_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9a96ff41f1568a840b8af0152e23e357964c15ef
--- /dev/null
+++ b/chrome/browser/extensions/api/messaging/native_message_host_chromeos.cc
@@ -0,0 +1,125 @@
+// Copyright 2014 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 "extensions/browser/api/messaging/native_message_host.h"
+
+#include <string>
+
+#include "base/command_line.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "extensions/common/constants.h"
+#include "extensions/common/switches.h"
+#include "extensions/common/url_pattern.h"
+#include "ui/gfx/native_widget_types.h"
+#include "url/gurl.h"
+
+namespace extensions {
+
+namespace {
+
+typedef NativeMessageHost::Client Client;
+
+// A simple NativeMesageHost that echoes the received message. It is currently
+// used for testing.
+// TODO(kelvinp): Replace this class once Remote Assistance in process host
+// is implemented.
+class EchoHost : public NativeMessageHost {
+ public:
+ scoped_ptr<NativeMessageHost> static CreateEchoHost(
+ base::WeakPtr<Client> weak_client,
+ int destination_port) {
+ return scoped_ptr<NativeMessageHost>(
+ new EchoHost(weak_client, destination_port));
+ }
+
+ EchoHost(base::WeakPtr<Client> client, int port)
+ : client_(client), port_(port) {}
+
+ virtual void Send(const std::string& json) OVERRIDE {
+ client_->PostMessageFromNativeHost(port_, json);
+ };
+
+ private:
+ base::WeakPtr<Client> client_;
+ int port_;
+
+ DISALLOW_COPY_AND_ASSIGN(EchoHost);
+};
+
+struct BuiltInHost {
+ const char* const name;
+ const char* const* const allowed_origins;
+ int allowed_origins_count;
+ scoped_ptr<NativeMessageHost>(*create_function)(base::WeakPtr<Client>,
+ int port);
+};
+
+// If you modify the list of allowed_origins, don't forget to update
+// remoting/host/it2me/com.google.chrome.remote_assistance.json.jinja2
+// to keep the two lists in sync.
+// TODO(kelvinp): Load the native messaging manifest as a resource file into
+// chrome and fetch the list of allowed_origins from the manifest.
+const char* const kRemotingIt2MeOrigins[] = {
+ "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/",
+ "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/",
+ "chrome-extension://kgngmbheleoaphbjbaiobfdepmghbfah/",
+ "chrome-extension://odkaodonbgfohohmklejpjiejmcipmib/",
+ "chrome-extension://ojoimpklfciegopdfgeenehpalipignm/",
+ "chrome-extension://dokpleeekgeeiehdhmdkeimnkmoifgdd/",
+ "chrome-extension://ajoainacpilcemgiakehflpbkbfipojk/",
+ "chrome-extension://hmboipgjngjoiaeicfdifdoeacilalgc/",
+ "chrome-extension://dhdboenlgbbeohfjeboeooomjmgbejoh/"};
Sergey Ulanov 2014/09/25 01:45:22 This list is different what we have in com.google.
kelvinp 2014/09/26 18:12:27 Done.
+
+static const BuiltInHost kBuiltInHost[] = {
+ {"com.google.chrome.remote_assistance",
+ kRemotingIt2MeOrigins,
+ arraysize(kRemotingIt2MeOrigins),
+ &EchoHost::CreateEchoHost}};
Sergey Ulanov 2014/09/25 01:45:22 Given that this CL contains changes for the It2Me
kelvinp 2014/09/26 18:12:27 It2Me host would crash on launching now. We still
+
+bool MatchesSecurityOrigin(const BuiltInHost& host,
+ const std::string& extension_id) {
+ GURL origin(std::string(kExtensionScheme) + "://" + extension_id);
+ for (int i = 0; i < host.allowed_origins_count; i++) {
+ URLPattern allowed_origin(URLPattern::SCHEME_ALL);
+ DCHECK_EQ(URLPattern::PARSE_SUCCESS,
+ allowed_origin.Parse(host.allowed_origins[i]));
+ if (allowed_origin.MatchesSecurityOrigin(origin)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+} // namespace
+
+scoped_ptr<NativeMessageHost> NativeMessageHost::Create(
+ gfx::NativeView native_view,
+ base::WeakPtr<Client> weak_client,
+ const std::string& source_extension_id,
+ const std::string& native_host_name,
+ int destination_port,
+ bool allow_user_level) {
+ DCHECK(weak_client);
+ scoped_ptr<NativeMessageHost> not_found;
+
+ if (!CommandLine::ForCurrentProcess()
+ ->HasSwitch(switches::kEnableRemoteAssistance)) {
+ return not_found.Pass();
+ }
+
+ for (unsigned int i = 0; i < arraysize(kBuiltInHost); i++) {
+ const BuiltInHost& host = kBuiltInHost[i];
+ std::string name(host.name);
+ if (name == native_host_name &&
+ MatchesSecurityOrigin(host, source_extension_id)) {
+ return (*host.create_function)(weak_client, destination_port);
+ }
+ }
+
+ return not_found.Pass();
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698