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/extensions/api/messaging/native_messaging_test_util.h" | 19 #include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h" |
20 #include "extensions/common/constants.h" | 20 #include "extensions/common/constants.h" |
| 21 #include "extensions/common/switches.h" |
21 #include "extensions/common/url_pattern.h" | 22 #include "extensions/common/url_pattern.h" |
| 23 #include "remoting/host/it2me/it2me_native_messaging_host.h" |
22 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
23 #include "url/gurl.h" | 25 #include "url/gurl.h" |
24 | 26 |
25 namespace extensions { | 27 namespace extensions { |
26 | 28 |
27 namespace { | 29 namespace { |
28 | 30 |
29 // A simple NativeMesageHost that echoes the received message. It is currently | 31 // A simple NativeMesageHost that echoes the received message. It is currently |
30 // used for testing. | 32 // used for testing. |
31 // TODO(kelvinp): Replace this class once Remote Assistance in process host | 33 // TODO(kelvinp): Replace this class once Remote Assistance in process host |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 DISALLOW_COPY_AND_ASSIGN(EchoHost); | 85 DISALLOW_COPY_AND_ASSIGN(EchoHost); |
84 }; | 86 }; |
85 | 87 |
86 struct BuiltInHost { | 88 struct BuiltInHost { |
87 const char* const name; | 89 const char* const name; |
88 const char* const* const allowed_origins; | 90 const char* const* const allowed_origins; |
89 int allowed_origins_count; | 91 int allowed_origins_count; |
90 scoped_ptr<NativeMessageHost>(*create_function)(); | 92 scoped_ptr<NativeMessageHost>(*create_function)(); |
91 }; | 93 }; |
92 | 94 |
| 95 scoped_ptr<NativeMessageHost> CreateIt2MeHost() { |
| 96 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 97 switches::kEnableRemoteAssistance)) { |
| 98 return remoting::It2MeNativeMessagingHost::Create(); |
| 99 } |
| 100 return nullptr; |
| 101 } |
| 102 |
93 // If you modify the list of allowed_origins, don't forget to update | 103 // If you modify the list of allowed_origins, don't forget to update |
94 // remoting/host/it2me/com.google.chrome.remote_assistance.json.jinja2 | 104 // remoting/host/it2me/com.google.chrome.remote_assistance.json.jinja2 |
95 // to keep the two lists in sync. | 105 // to keep the two lists in sync. |
96 // TODO(kelvinp): Load the native messaging manifest as a resource file into | 106 // TODO(kelvinp): Load the native messaging manifest as a resource file into |
97 // chrome and fetch the list of allowed_origins from the manifest. | 107 // chrome and fetch the list of allowed_origins from the manifest. |
98 /*const char* const kRemotingIt2MeOrigins[] = { | 108 const char* const kRemotingIt2MeOrigins[] = { |
99 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", | 109 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", |
100 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/", | 110 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/", |
101 "chrome-extension://kgngmbheleoaphbjbaiobfdepmghbfah/", | 111 "chrome-extension://kgngmbheleoaphbjbaiobfdepmghbfah/", |
102 "chrome-extension://odkaodonbgfohohmklejpjiejmcipmib/", | 112 "chrome-extension://odkaodonbgfohohmklejpjiejmcipmib/", |
103 "chrome-extension://dokpleeekgeeiehdhmdkeimnkmoifgdd/", | 113 "chrome-extension://dokpleeekgeeiehdhmdkeimnkmoifgdd/", |
104 "chrome-extension://ajoainacpilcemgiakehflpbkbfipojk/", | 114 "chrome-extension://ajoainacpilcemgiakehflpbkbfipojk/", |
105 "chrome-extension://hmboipgjngjoiaeicfdifdoeacilalgc/"};*/ | 115 "chrome-extension://hmboipgjngjoiaeicfdifdoeacilalgc/"}; |
106 | 116 |
107 static const BuiltInHost kBuiltInHost[] = { | 117 static const BuiltInHost kBuiltInHost[] = { |
108 {"com.google.chrome.test.echo", // ScopedTestNativeMessagingHost::kHostName | 118 {"com.google.chrome.test.echo", // ScopedTestNativeMessagingHost::kHostName |
109 kEchoHostOrigins, | 119 kEchoHostOrigins, |
110 arraysize(kEchoHostOrigins), | 120 arraysize(kEchoHostOrigins), |
111 &EchoHost::Create}, | 121 &EchoHost::Create}, |
| 122 {"com.google.chrome.remote_assistance", |
| 123 kRemotingIt2MeOrigins, |
| 124 arraysize(kRemotingIt2MeOrigins), |
| 125 &CreateIt2MeHost}, |
112 }; | 126 }; |
113 | 127 |
114 bool MatchesSecurityOrigin(const BuiltInHost& host, | 128 bool MatchesSecurityOrigin(const BuiltInHost& host, |
115 const std::string& extension_id) { | 129 const std::string& extension_id) { |
116 GURL origin(std::string(kExtensionScheme) + "://" + extension_id); | 130 GURL origin(std::string(kExtensionScheme) + "://" + extension_id); |
117 for (int i = 0; i < host.allowed_origins_count; i++) { | 131 for (int i = 0; i < host.allowed_origins_count; i++) { |
118 URLPattern allowed_origin(URLPattern::SCHEME_ALL, host.allowed_origins[i]); | 132 URLPattern allowed_origin(URLPattern::SCHEME_ALL, host.allowed_origins[i]); |
119 if (allowed_origin.MatchesSecurityOrigin(origin)) { | 133 if (allowed_origin.MatchesSecurityOrigin(origin)) { |
120 return true; | 134 return true; |
121 } | 135 } |
(...skipping 18 matching lines...) Expand all Loading... |
140 } | 154 } |
141 *error = kForbiddenError; | 155 *error = kForbiddenError; |
142 return nullptr; | 156 return nullptr; |
143 } | 157 } |
144 } | 158 } |
145 *error = kNotFoundError; | 159 *error = kNotFoundError; |
146 return nullptr; | 160 return nullptr; |
147 } | 161 } |
148 | 162 |
149 } // namespace extensions | 163 } // namespace extensions |
OLD | NEW |