| 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" | |
| 12 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 14 #include "base/location.h" | 13 #include "base/location.h" |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/message_loop/message_loop_proxy.h" | 16 #include "base/message_loop/message_loop_proxy.h" |
| 18 #include "base/values.h" | 17 #include "base/values.h" |
| 19 #include "chrome/browser/browser_process.h" | 18 #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" | 20 #include "components/policy/core/common/policy_service.h" |
| 22 #include "extensions/common/constants.h" | 21 #include "extensions/common/constants.h" |
| 23 #include "extensions/common/switches.h" | |
| 24 #include "extensions/common/url_pattern.h" | 22 #include "extensions/common/url_pattern.h" |
| 25 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
| 26 #include "remoting/host/chromoting_host_context.h" | 24 #include "remoting/host/chromoting_host_context.h" |
| 27 #include "remoting/host/it2me/it2me_native_messaging_host.h" | 25 #include "remoting/host/it2me/it2me_native_messaging_host.h" |
| 28 #include "ui/gfx/native_widget_types.h" | 26 #include "ui/gfx/native_widget_types.h" |
| 29 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 30 | 28 |
| 31 namespace extensions { | 29 namespace extensions { |
| 32 | 30 |
| 33 namespace { | 31 namespace { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 }; | 87 }; |
| 90 | 88 |
| 91 struct BuiltInHost { | 89 struct BuiltInHost { |
| 92 const char* const name; | 90 const char* const name; |
| 93 const char* const* const allowed_origins; | 91 const char* const* const allowed_origins; |
| 94 int allowed_origins_count; | 92 int allowed_origins_count; |
| 95 scoped_ptr<NativeMessageHost>(*create_function)(); | 93 scoped_ptr<NativeMessageHost>(*create_function)(); |
| 96 }; | 94 }; |
| 97 | 95 |
| 98 scoped_ptr<NativeMessageHost> CreateIt2MeHost() { | 96 scoped_ptr<NativeMessageHost> CreateIt2MeHost() { |
| 99 if (CommandLine::ForCurrentProcess()->HasSwitch( | 97 scoped_ptr<remoting::It2MeHostFactory> host_factory( |
| 100 switches::kEnableRemoteAssistance)) { | 98 new remoting::It2MeHostFactory()); |
| 101 scoped_ptr<remoting::It2MeHostFactory> host_factory( | 99 host_factory->set_policy_service(g_browser_process->policy_service()); |
| 102 new remoting::It2MeHostFactory()); | 100 scoped_ptr<remoting::ChromotingHostContext> context = |
| 103 host_factory->set_policy_service(g_browser_process->policy_service()); | 101 remoting::ChromotingHostContext::CreateForChromeOS( |
| 104 scoped_ptr<remoting::ChromotingHostContext> context = | 102 make_scoped_refptr(g_browser_process->system_request_context())); |
| 105 remoting::ChromotingHostContext::CreateForChromeOS( | 103 scoped_ptr<NativeMessageHost> host(new remoting::It2MeNativeMessagingHost( |
| 106 make_scoped_refptr(g_browser_process->system_request_context())); | 104 context.Pass(), host_factory.Pass())); |
| 107 scoped_ptr<NativeMessageHost> host(new remoting::It2MeNativeMessagingHost( | 105 return host.Pass(); |
| 108 context.Pass(), host_factory.Pass())); | |
| 109 return host.Pass(); | |
| 110 } | |
| 111 return nullptr; | |
| 112 } | 106 } |
| 113 | 107 |
| 114 // If you modify the list of allowed_origins, don't forget to update | 108 // If you modify the list of allowed_origins, don't forget to update |
| 115 // remoting/host/it2me/com.google.chrome.remote_assistance.json.jinja2 | 109 // remoting/host/it2me/com.google.chrome.remote_assistance.json.jinja2 |
| 116 // to keep the two lists in sync. | 110 // to keep the two lists in sync. |
| 117 // TODO(kelvinp): Load the native messaging manifest as a resource file into | 111 // 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 | 112 // chrome and fetch the list of allowed_origins from the manifest (see |
| 119 // crbug/424743). | 113 // crbug/424743). |
| 120 const char* const kRemotingIt2MeOrigins[] = { | 114 const char* const kRemotingIt2MeOrigins[] = { |
| 121 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", | 115 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 160 } |
| 167 *error = kForbiddenError; | 161 *error = kForbiddenError; |
| 168 return nullptr; | 162 return nullptr; |
| 169 } | 163 } |
| 170 } | 164 } |
| 171 *error = kNotFoundError; | 165 *error = kNotFoundError; |
| 172 return nullptr; | 166 return nullptr; |
| 173 } | 167 } |
| 174 | 168 |
| 175 } // namespace extensions | 169 } // namespace extensions |
| OLD | NEW |