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

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

Issue 686373002: Revert of Remote assistance on Chrome OS Part IV - It2MeHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « chrome/browser/extensions/api/DEPS ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
20 #include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h" 19 #include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h"
21 #include "components/policy/core/common/policy_service.h"
22 #include "extensions/common/constants.h" 20 #include "extensions/common/constants.h"
23 #include "extensions/common/switches.h"
24 #include "extensions/common/url_pattern.h" 21 #include "extensions/common/url_pattern.h"
25 #include "net/url_request/url_request_context_getter.h"
26 #include "remoting/host/chromoting_host_context.h"
27 #include "remoting/host/it2me/it2me_native_messaging_host.h"
28 #include "ui/gfx/native_widget_types.h" 22 #include "ui/gfx/native_widget_types.h"
29 #include "url/gurl.h" 23 #include "url/gurl.h"
30 24
31 namespace extensions { 25 namespace extensions {
32 26
33 namespace { 27 namespace {
34 28
35 // A simple NativeMessageHost that mimics the implementation of 29 // A simple NativeMesageHost that echoes the received message. It is currently
36 // chrome/test/data/native_messaging/native_hosts/echo.py. It is currently 30 // used for testing.
37 // used for testing by ExtensionApiTest::NativeMessagingBasic. 31 // TODO(kelvinp): Replace this class once Remote Assistance in process host
32 // is implemented.
38 33
39 const char* const kEchoHostOrigins[] = { 34 const char* const kEchoHostOrigins[] = {
40 // ScopedTestNativeMessagingHost::kExtensionId 35 // ScopedTestNativeMessagingHost::kExtensionId
41 "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"}; 36 "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"};
42 37
43 class EchoHost : public NativeMessageHost { 38 class EchoHost : public NativeMessageHost {
44 public: 39 public:
45 static scoped_ptr<NativeMessageHost> Create() { 40 static scoped_ptr<NativeMessageHost> Create() {
46 return scoped_ptr<NativeMessageHost>(new EchoHost()); 41 return scoped_ptr<NativeMessageHost>(new EchoHost());
47 } 42 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 DISALLOW_COPY_AND_ASSIGN(EchoHost); 83 DISALLOW_COPY_AND_ASSIGN(EchoHost);
89 }; 84 };
90 85
91 struct BuiltInHost { 86 struct BuiltInHost {
92 const char* const name; 87 const char* const name;
93 const char* const* const allowed_origins; 88 const char* const* const allowed_origins;
94 int allowed_origins_count; 89 int allowed_origins_count;
95 scoped_ptr<NativeMessageHost>(*create_function)(); 90 scoped_ptr<NativeMessageHost>(*create_function)();
96 }; 91 };
97 92
98 scoped_ptr<NativeMessageHost> CreateIt2MeHost() {
99 if (CommandLine::ForCurrentProcess()->HasSwitch(
100 switches::kEnableRemoteAssistance)) {
101 scoped_ptr<remoting::It2MeHostFactory> host_factory(
102 new remoting::It2MeHostFactory());
103 host_factory->set_policy_service(g_browser_process->policy_service());
104 scoped_ptr<remoting::ChromotingHostContext> context =
105 remoting::ChromotingHostContext::CreateForChromeOS(
106 make_scoped_refptr(g_browser_process->system_request_context()));
107 scoped_ptr<NativeMessageHost> host(new remoting::It2MeNativeMessagingHost(
108 context.Pass(), host_factory.Pass()));
109 return host.Pass();
110 }
111 return nullptr;
112 }
113
114 // If you modify the list of allowed_origins, don't forget to update 93 // If you modify the list of allowed_origins, don't forget to update
115 // remoting/host/it2me/com.google.chrome.remote_assistance.json.jinja2 94 // remoting/host/it2me/com.google.chrome.remote_assistance.json.jinja2
116 // to keep the two lists in sync. 95 // to keep the two lists in sync.
117 // TODO(kelvinp): Load the native messaging manifest as a resource file into 96 // TODO(kelvinp): Load the native messaging manifest as a resource file into
118 // chrome and fetch the list of allowed_origins from the manifest (see 97 // chrome and fetch the list of allowed_origins from the manifest.
119 // crbug/424743). 98 /*const char* const kRemotingIt2MeOrigins[] = {
120 const char* const kRemotingIt2MeOrigins[] = {
121 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", 99 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/",
122 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/", 100 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/",
123 "chrome-extension://kgngmbheleoaphbjbaiobfdepmghbfah/", 101 "chrome-extension://kgngmbheleoaphbjbaiobfdepmghbfah/",
124 "chrome-extension://odkaodonbgfohohmklejpjiejmcipmib/", 102 "chrome-extension://odkaodonbgfohohmklejpjiejmcipmib/",
125 "chrome-extension://dokpleeekgeeiehdhmdkeimnkmoifgdd/", 103 "chrome-extension://dokpleeekgeeiehdhmdkeimnkmoifgdd/",
126 "chrome-extension://ajoainacpilcemgiakehflpbkbfipojk/", 104 "chrome-extension://ajoainacpilcemgiakehflpbkbfipojk/",
127 "chrome-extension://hmboipgjngjoiaeicfdifdoeacilalgc/"}; 105 "chrome-extension://hmboipgjngjoiaeicfdifdoeacilalgc/"};*/
128 106
129 static const BuiltInHost kBuiltInHost[] = { 107 static const BuiltInHost kBuiltInHost[] = {
130 {"com.google.chrome.test.echo", // ScopedTestNativeMessagingHost::kHostName 108 {"com.google.chrome.test.echo", // ScopedTestNativeMessagingHost::kHostName
131 kEchoHostOrigins, 109 kEchoHostOrigins,
132 arraysize(kEchoHostOrigins), 110 arraysize(kEchoHostOrigins),
133 &EchoHost::Create}, 111 &EchoHost::Create},
134 {"com.google.chrome.remote_assistance",
135 kRemotingIt2MeOrigins,
136 arraysize(kRemotingIt2MeOrigins),
137 &CreateIt2MeHost},
138 }; 112 };
139 113
140 bool MatchesSecurityOrigin(const BuiltInHost& host, 114 bool MatchesSecurityOrigin(const BuiltInHost& host,
141 const std::string& extension_id) { 115 const std::string& extension_id) {
142 GURL origin(std::string(kExtensionScheme) + "://" + extension_id); 116 GURL origin(std::string(kExtensionScheme) + "://" + extension_id);
143 for (int i = 0; i < host.allowed_origins_count; i++) { 117 for (int i = 0; i < host.allowed_origins_count; i++) {
144 URLPattern allowed_origin(URLPattern::SCHEME_ALL, host.allowed_origins[i]); 118 URLPattern allowed_origin(URLPattern::SCHEME_ALL, host.allowed_origins[i]);
145 if (allowed_origin.MatchesSecurityOrigin(origin)) { 119 if (allowed_origin.MatchesSecurityOrigin(origin)) {
146 return true; 120 return true;
147 } 121 }
(...skipping 18 matching lines...) Expand all
166 } 140 }
167 *error = kForbiddenError; 141 *error = kForbiddenError;
168 return nullptr; 142 return nullptr;
169 } 143 }
170 } 144 }
171 *error = kNotFoundError; 145 *error = kNotFoundError;
172 return nullptr; 146 return nullptr;
173 } 147 }
174 148
175 } // namespace extensions 149 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/DEPS ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698