OLD | NEW |
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/browser_process.h" |
20 #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" | 21 #include "components/policy/core/common/policy_service.h" |
22 #include "extensions/common/constants.h" | 22 #include "extensions/common/constants.h" |
23 #include "extensions/common/switches.h" | 23 #include "extensions/common/switches.h" |
24 #include "extensions/common/url_pattern.h" | 24 #include "extensions/common/url_pattern.h" |
25 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
| 26 #if defined(USE_X11) |
26 #include "remoting/host/chromoting_host_context.h" | 27 #include "remoting/host/chromoting_host_context.h" |
27 #include "remoting/host/it2me/it2me_native_messaging_host.h" | 28 #include "remoting/host/it2me/it2me_native_messaging_host.h" |
| 29 # endif // defined(USE_X11) |
28 #include "ui/gfx/native_widget_types.h" | 30 #include "ui/gfx/native_widget_types.h" |
29 #include "url/gurl.h" | 31 #include "url/gurl.h" |
30 | 32 |
31 namespace extensions { | 33 namespace extensions { |
32 | 34 |
33 namespace { | 35 namespace { |
34 | 36 |
35 // A simple NativeMessageHost that mimics the implementation of | 37 // A simple NativeMessageHost that mimics the implementation of |
36 // chrome/test/data/native_messaging/native_hosts/echo.py. It is currently | 38 // chrome/test/data/native_messaging/native_hosts/echo.py. It is currently |
37 // used for testing by ExtensionApiTest::NativeMessagingBasic. | 39 // used for testing by ExtensionApiTest::NativeMessagingBasic. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 DISALLOW_COPY_AND_ASSIGN(EchoHost); | 90 DISALLOW_COPY_AND_ASSIGN(EchoHost); |
89 }; | 91 }; |
90 | 92 |
91 struct BuiltInHost { | 93 struct BuiltInHost { |
92 const char* const name; | 94 const char* const name; |
93 const char* const* const allowed_origins; | 95 const char* const* const allowed_origins; |
94 int allowed_origins_count; | 96 int allowed_origins_count; |
95 scoped_ptr<NativeMessageHost>(*create_function)(); | 97 scoped_ptr<NativeMessageHost>(*create_function)(); |
96 }; | 98 }; |
97 | 99 |
| 100 // Remote assistance currently only supports X11. |
| 101 // TODO(kelvinp): Migrate to ozone once it is ready (crbug.com/426716). |
| 102 #if defined(USE_X11) |
98 scoped_ptr<NativeMessageHost> CreateIt2MeHost() { | 103 scoped_ptr<NativeMessageHost> CreateIt2MeHost() { |
99 if (CommandLine::ForCurrentProcess()->HasSwitch( | 104 if (CommandLine::ForCurrentProcess()->HasSwitch( |
100 switches::kEnableRemoteAssistance)) { | 105 switches::kEnableRemoteAssistance)) { |
101 scoped_ptr<remoting::It2MeHostFactory> host_factory( | 106 scoped_ptr<remoting::It2MeHostFactory> host_factory( |
102 new remoting::It2MeHostFactory()); | 107 new remoting::It2MeHostFactory()); |
103 host_factory->set_policy_service(g_browser_process->policy_service()); | 108 host_factory->set_policy_service(g_browser_process->policy_service()); |
104 scoped_ptr<remoting::ChromotingHostContext> context = | 109 scoped_ptr<remoting::ChromotingHostContext> context = |
105 remoting::ChromotingHostContext::CreateForChromeOS( | 110 remoting::ChromotingHostContext::CreateForChromeOS( |
106 make_scoped_refptr(g_browser_process->system_request_context())); | 111 make_scoped_refptr(g_browser_process->system_request_context())); |
107 scoped_ptr<NativeMessageHost> host(new remoting::It2MeNativeMessagingHost( | 112 scoped_ptr<NativeMessageHost> host(new remoting::It2MeNativeMessagingHost( |
(...skipping 10 matching lines...) Expand all Loading... |
118 // chrome and fetch the list of allowed_origins from the manifest (see | 123 // chrome and fetch the list of allowed_origins from the manifest (see |
119 // crbug/424743). | 124 // crbug/424743). |
120 const char* const kRemotingIt2MeOrigins[] = { | 125 const char* const kRemotingIt2MeOrigins[] = { |
121 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", | 126 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", |
122 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/", | 127 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/", |
123 "chrome-extension://kgngmbheleoaphbjbaiobfdepmghbfah/", | 128 "chrome-extension://kgngmbheleoaphbjbaiobfdepmghbfah/", |
124 "chrome-extension://odkaodonbgfohohmklejpjiejmcipmib/", | 129 "chrome-extension://odkaodonbgfohohmklejpjiejmcipmib/", |
125 "chrome-extension://dokpleeekgeeiehdhmdkeimnkmoifgdd/", | 130 "chrome-extension://dokpleeekgeeiehdhmdkeimnkmoifgdd/", |
126 "chrome-extension://ajoainacpilcemgiakehflpbkbfipojk/", | 131 "chrome-extension://ajoainacpilcemgiakehflpbkbfipojk/", |
127 "chrome-extension://hmboipgjngjoiaeicfdifdoeacilalgc/"}; | 132 "chrome-extension://hmboipgjngjoiaeicfdifdoeacilalgc/"}; |
| 133 #endif // defined(USE_X11) |
128 | 134 |
129 static const BuiltInHost kBuiltInHost[] = { | 135 static const BuiltInHost kBuiltInHost[] = { |
130 {"com.google.chrome.test.echo", // ScopedTestNativeMessagingHost::kHostName | 136 {"com.google.chrome.test.echo", // ScopedTestNativeMessagingHost::kHostName |
131 kEchoHostOrigins, | 137 kEchoHostOrigins, |
132 arraysize(kEchoHostOrigins), | 138 arraysize(kEchoHostOrigins), |
133 &EchoHost::Create}, | 139 &EchoHost::Create}, |
| 140 #if defined(USE_X11) |
134 {"com.google.chrome.remote_assistance", | 141 {"com.google.chrome.remote_assistance", |
135 kRemotingIt2MeOrigins, | 142 kRemotingIt2MeOrigins, |
136 arraysize(kRemotingIt2MeOrigins), | 143 arraysize(kRemotingIt2MeOrigins), |
137 &CreateIt2MeHost}, | 144 &CreateIt2MeHost}, |
| 145 #endif // defined(USE_X11) |
138 }; | 146 }; |
139 | 147 |
140 bool MatchesSecurityOrigin(const BuiltInHost& host, | 148 bool MatchesSecurityOrigin(const BuiltInHost& host, |
141 const std::string& extension_id) { | 149 const std::string& extension_id) { |
142 GURL origin(std::string(kExtensionScheme) + "://" + extension_id); | 150 GURL origin(std::string(kExtensionScheme) + "://" + extension_id); |
143 for (int i = 0; i < host.allowed_origins_count; i++) { | 151 for (int i = 0; i < host.allowed_origins_count; i++) { |
144 URLPattern allowed_origin(URLPattern::SCHEME_ALL, host.allowed_origins[i]); | 152 URLPattern allowed_origin(URLPattern::SCHEME_ALL, host.allowed_origins[i]); |
145 if (allowed_origin.MatchesSecurityOrigin(origin)) { | 153 if (allowed_origin.MatchesSecurityOrigin(origin)) { |
146 return true; | 154 return true; |
147 } | 155 } |
(...skipping 18 matching lines...) Expand all Loading... |
166 } | 174 } |
167 *error = kForbiddenError; | 175 *error = kForbiddenError; |
168 return nullptr; | 176 return nullptr; |
169 } | 177 } |
170 } | 178 } |
171 *error = kNotFoundError; | 179 *error = kNotFoundError; |
172 return nullptr; | 180 return nullptr; |
173 } | 181 } |
174 | 182 |
175 } // namespace extensions | 183 } // namespace extensions |
OLD | NEW |