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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_host_chromeos.cc

Issue 639233002: Remote assistance on Chrome OS Part IV - It2MeHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedbacks Created 6 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/api/messaging/native_message_host.h" 5 #include "extensions/browser/api/messaging/native_message_host.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/message_loop/message_loop_proxy.h" 17 #include "base/message_loop/message_loop_proxy.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h" 20 #include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h"
21 #include "components/policy/core/common/policy_service.h"
20 #include "extensions/common/constants.h" 22 #include "extensions/common/constants.h"
23 #include "extensions/common/switches.h"
21 #include "extensions/common/url_pattern.h" 24 #include "extensions/common/url_pattern.h"
25 #include "net/url_request/url_request_context_getter.h"
26 #include "remoting/host/it2me/it2me_native_messaging_host.h"
22 #include "ui/gfx/native_widget_types.h" 27 #include "ui/gfx/native_widget_types.h"
23 #include "url/gurl.h" 28 #include "url/gurl.h"
24 29
25 namespace extensions { 30 namespace extensions {
26 31
27 namespace { 32 namespace {
28 33
29 // A simple NativeMesageHost that echoes the received message. It is currently 34 // A simple NativeMesageHost that mimics the implementation of
Wez 2014/10/17 17:57:59 typo
kelvinp 2014/10/20 00:21:16 I think both mimics and implementation are spelled
Wez 2014/10/20 01:16:13 Still typo ;)
30 // used for testing. 35 // chrome/test/data/native_messaging/native_hosts/echo.py. It is currently
31 // TODO(kelvinp): Replace this class once Remote Assistance in process host 36 // used for testing by ExtensionApiTest::NativeMessagingBasic.
32 // is implemented.
33 37
34 const char* const kEchoHostOrigins[] = { 38 const char* const kEchoHostOrigins[] = {
35 // ScopedTestNativeMessagingHost::kExtensionId 39 // ScopedTestNativeMessagingHost::kExtensionId
36 "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"}; 40 "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"};
37 41
38 class EchoHost : public NativeMessageHost { 42 class EchoHost : public NativeMessageHost {
39 public: 43 public:
40 static scoped_ptr<NativeMessageHost> Create() { 44 static scoped_ptr<NativeMessageHost> Create() {
41 return scoped_ptr<NativeMessageHost>(new EchoHost()); 45 return scoped_ptr<NativeMessageHost>(new EchoHost());
42 } 46 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 DISALLOW_COPY_AND_ASSIGN(EchoHost); 87 DISALLOW_COPY_AND_ASSIGN(EchoHost);
84 }; 88 };
85 89
86 struct BuiltInHost { 90 struct BuiltInHost {
87 const char* const name; 91 const char* const name;
88 const char* const* const allowed_origins; 92 const char* const* const allowed_origins;
89 int allowed_origins_count; 93 int allowed_origins_count;
90 scoped_ptr<NativeMessageHost>(*create_function)(); 94 scoped_ptr<NativeMessageHost>(*create_function)();
91 }; 95 };
92 96
97 scoped_ptr<NativeMessageHost> CreateIt2MeHost() {
98 if (CommandLine::ForCurrentProcess()->HasSwitch(
99 switches::kEnableRemoteAssistance)) {
100 return remoting::It2MeNativeMessagingHost::CreateForChromeOS(
101 g_browser_process->system_request_context(),
102 g_browser_process->policy_service());
103 }
104 return nullptr;
105 }
106
93 // If you modify the list of allowed_origins, don't forget to update 107 // If you modify the list of allowed_origins, don't forget to update
94 // remoting/host/it2me/com.google.chrome.remote_assistance.json.jinja2 108 // remoting/host/it2me/com.google.chrome.remote_assistance.json.jinja2
95 // to keep the two lists in sync. 109 // to keep the two lists in sync.
96 // TODO(kelvinp): Load the native messaging manifest as a resource file into 110 // TODO(kelvinp): Load the native messaging manifest as a resource file into
97 // chrome and fetch the list of allowed_origins from the manifest. 111 // chrome and fetch the list of allowed_origins from the manifest.
Wez 2014/10/17 17:57:59 nit: Is there a bug filed for that cleanup?
kelvinp 2014/10/20 00:21:16 Done.
98 /*const char* const kRemotingIt2MeOrigins[] = { 112 const char* const kRemotingIt2MeOrigins[] = {
99 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", 113 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/",
100 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/", 114 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/",
101 "chrome-extension://kgngmbheleoaphbjbaiobfdepmghbfah/", 115 "chrome-extension://kgngmbheleoaphbjbaiobfdepmghbfah/",
102 "chrome-extension://odkaodonbgfohohmklejpjiejmcipmib/", 116 "chrome-extension://odkaodonbgfohohmklejpjiejmcipmib/",
103 "chrome-extension://dokpleeekgeeiehdhmdkeimnkmoifgdd/", 117 "chrome-extension://dokpleeekgeeiehdhmdkeimnkmoifgdd/",
104 "chrome-extension://ajoainacpilcemgiakehflpbkbfipojk/", 118 "chrome-extension://ajoainacpilcemgiakehflpbkbfipojk/",
105 "chrome-extension://hmboipgjngjoiaeicfdifdoeacilalgc/"};*/ 119 "chrome-extension://hmboipgjngjoiaeicfdifdoeacilalgc/"};
106 120
107 static const BuiltInHost kBuiltInHost[] = { 121 static const BuiltInHost kBuiltInHost[] = {
108 {"com.google.chrome.test.echo", // ScopedTestNativeMessagingHost::kHostName 122 {"com.google.chrome.test.echo", // ScopedTestNativeMessagingHost::kHostName
109 kEchoHostOrigins, 123 kEchoHostOrigins,
110 arraysize(kEchoHostOrigins), 124 arraysize(kEchoHostOrigins),
111 &EchoHost::Create}, 125 &EchoHost::Create},
126 {"com.google.chrome.remote_assistance",
127 kRemotingIt2MeOrigins,
128 arraysize(kRemotingIt2MeOrigins),
129 &CreateIt2MeHost},
112 }; 130 };
113 131
114 bool MatchesSecurityOrigin(const BuiltInHost& host, 132 bool MatchesSecurityOrigin(const BuiltInHost& host,
115 const std::string& extension_id) { 133 const std::string& extension_id) {
116 GURL origin(std::string(kExtensionScheme) + "://" + extension_id); 134 GURL origin(std::string(kExtensionScheme) + "://" + extension_id);
117 for (int i = 0; i < host.allowed_origins_count; i++) { 135 for (int i = 0; i < host.allowed_origins_count; i++) {
118 URLPattern allowed_origin(URLPattern::SCHEME_ALL, host.allowed_origins[i]); 136 URLPattern allowed_origin(URLPattern::SCHEME_ALL, host.allowed_origins[i]);
119 if (allowed_origin.MatchesSecurityOrigin(origin)) { 137 if (allowed_origin.MatchesSecurityOrigin(origin)) {
120 return true; 138 return true;
121 } 139 }
(...skipping 18 matching lines...) Expand all
140 } 158 }
141 *error = kForbiddenError; 159 *error = kForbiddenError;
142 return nullptr; 160 return nullptr;
143 } 161 }
144 } 162 }
145 *error = kNotFoundError; 163 *error = kNotFoundError;
146 return nullptr; 164 return nullptr;
147 } 165 }
148 166
149 } // namespace extensions 167 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698