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

Side by Side Diff: remoting/host/plugin/host_script_object.cc

Issue 10823083: [Chromoting] Implement the host domain policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync. Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/plugin/host_script_object.h ('k') | remoting/host/remoting_me2me_host.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "remoting/host/plugin/host_script_object.h" 5 #include "remoting/host/plugin/host_script_object.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "base/string_util.h"
12 #include "base/sys_string_conversions.h" 13 #include "base/sys_string_conversions.h"
13 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "net/base/net_util.h" 17 #include "net/base/net_util.h"
17 #include "remoting/base/auth_token_util.h" 18 #include "remoting/base/auth_token_util.h"
18 #include "remoting/host/chromoting_host.h" 19 #include "remoting/host/chromoting_host.h"
19 #include "remoting/host/chromoting_host_context.h" 20 #include "remoting/host/chromoting_host_context.h"
20 #include "remoting/host/desktop_environment.h" 21 #include "remoting/host/desktop_environment.h"
21 #include "remoting/host/host_config.h" 22 #include "remoting/host/host_config.h"
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), 536 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this),
536 uid, auth_token, auth_service)); 537 uid, auth_token, auth_service));
537 return; 538 return;
538 } 539 }
539 540
540 if (state_ != kStarting) { 541 if (state_ != kStarting) {
541 // Host has been stopped while we were fetching policy. 542 // Host has been stopped while we were fetching policy.
542 return; 543 return;
543 } 544 }
544 545
546 // Check the host domain policy.
547 if (!required_host_domain_.empty() &&
548 !EndsWith(uid, std::string("@") + required_host_domain_, false)) {
549 SetState(kError);
550 return;
551 }
552
545 // Verify that DesktopEnvironment has been created. 553 // Verify that DesktopEnvironment has been created.
546 if (desktop_environment_.get() == NULL) { 554 if (desktop_environment_.get() == NULL) {
547 SetState(kError); 555 SetState(kError);
548 return; 556 return;
549 } 557 }
550 558
551 // Generate a key pair for the Host to use. 559 // Generate a key pair for the Host to use.
552 // TODO(wez): Move this to the worker thread. 560 // TODO(wez): Move this to the worker thread.
553 host_key_pair_.Generate(); 561 host_key_pair_.Generate();
554 562
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 case kStarting: 877 case kStarting:
870 SetState(kDisconnecting); 878 SetState(kDisconnecting);
871 SetState(kDisconnected); 879 SetState(kDisconnected);
872 disconnected_event_.Signal(); 880 disconnected_event_.Signal();
873 return; 881 return;
874 882
875 case kDisconnecting: 883 case kDisconnecting:
876 return; 884 return;
877 885
878 default: 886 default:
879 DCHECK(host_);
880 SetState(kDisconnecting); 887 SetState(kDisconnecting);
881 888
889 if (!host_) {
890 OnShutdownFinished();
891 return;
892 }
882 // ChromotingHost::Shutdown() may destroy SignalStrategy 893 // ChromotingHost::Shutdown() may destroy SignalStrategy
883 // synchronously, bug SignalStrategy::Listener handlers are not 894 // synchronously, but SignalStrategy::Listener handlers are not
884 // allowed to destroy SignalStrategy, so post task to call 895 // allowed to destroy SignalStrategy, so post task to call
885 // Shutdown() later. 896 // Shutdown() later.
886 host_context_->network_task_runner()->PostTask( 897 host_context_->network_task_runner()->PostTask(
887 FROM_HERE, base::Bind( 898 FROM_HERE, base::Bind(
888 &ChromotingHost::Shutdown, host_, 899 &ChromotingHost::Shutdown, host_,
889 base::Bind(&HostNPScriptObject::OnShutdownFinished, 900 base::Bind(&HostNPScriptObject::OnShutdownFinished,
890 base::Unretained(this)))); 901 base::Unretained(this))));
902 return;
891 } 903 }
892 } 904 }
893 905
894 void HostNPScriptObject::OnShutdownFinished() { 906 void HostNPScriptObject::OnShutdownFinished() {
895 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 907 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
896 908
897 disconnected_event_.Signal(); 909 disconnected_event_.Signal();
898 } 910 }
899 911
900 void HostNPScriptObject::OnPolicyUpdate( 912 void HostNPScriptObject::OnPolicyUpdate(
901 scoped_ptr<base::DictionaryValue> policies) { 913 scoped_ptr<base::DictionaryValue> policies) {
902 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 914 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
903 host_context_->network_task_runner()->PostTask( 915 host_context_->network_task_runner()->PostTask(
904 FROM_HERE, 916 FROM_HERE,
905 base::Bind(&HostNPScriptObject::OnPolicyUpdate, 917 base::Bind(&HostNPScriptObject::OnPolicyUpdate,
906 base::Unretained(this), base::Passed(&policies))); 918 base::Unretained(this), base::Passed(&policies)));
907 return; 919 return;
908 } 920 }
909 921
910 bool bool_value; 922 bool nat_policy;
911 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, 923 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName,
912 &bool_value)) { 924 &nat_policy)) {
913 OnNatPolicyUpdate(bool_value); 925 UpdateNatPolicy(nat_policy);
926 }
927 std::string host_domain;
928 if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName,
929 &host_domain)) {
930 UpdateHostDomainPolicy(host_domain);
931 }
932
933 {
934 base::AutoLock lock(nat_policy_lock_);
935 policy_received_ = true;
936 }
937
938 if (!pending_connect_.is_null()) {
939 pending_connect_.Run();
940 pending_connect_.Reset();
914 } 941 }
915 } 942 }
916 943
917 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { 944 void HostNPScriptObject::UpdateNatPolicy(bool nat_traversal_enabled) {
918 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 945 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
919 host_context_->network_task_runner()->PostTask(
920 FROM_HERE,
921 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate,
922 base::Unretained(this), nat_traversal_enabled));
923 return;
924 }
925 946
926 VLOG(2) << "OnNatPolicyUpdate: " << nat_traversal_enabled; 947 VLOG(2) << "UpdateNatPolicy: " << nat_traversal_enabled;
927 948
928 // When transitioning from enabled to disabled, force disconnect any 949 // When transitioning from enabled to disabled, force disconnect any
929 // existing session. 950 // existing session.
930 if (nat_traversal_enabled_ && !nat_traversal_enabled) { 951 if (nat_traversal_enabled_ && !nat_traversal_enabled) {
931 DisconnectInternal(); 952 DisconnectInternal();
932 } 953 }
933 954
934 { 955 {
935 base::AutoLock lock(nat_policy_lock_); 956 base::AutoLock lock(nat_policy_lock_);
936 policy_received_ = true;
937 nat_traversal_enabled_ = nat_traversal_enabled; 957 nat_traversal_enabled_ = nat_traversal_enabled;
938 } 958 }
939 959
940 UpdateWebappNatPolicy(nat_traversal_enabled_); 960 UpdateWebappNatPolicy(nat_traversal_enabled_);
961 }
941 962
942 if (!pending_connect_.is_null()) { 963 void HostNPScriptObject::UpdateHostDomainPolicy(
943 pending_connect_.Run(); 964 const std::string& host_domain) {
944 pending_connect_.Reset(); 965 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
966
967 VLOG(2) << "UpdateHostDomainPolicy: " << host_domain;
968
969 // When setting a host domain policy, force disconnect any existing session.
970 if (!host_domain.empty() && state_ != kStarting) {
971 DisconnectInternal();
945 } 972 }
973
974 required_host_domain_ = host_domain;
946 } 975 }
947 976
948 void HostNPScriptObject::OnReceivedSupportID( 977 void HostNPScriptObject::OnReceivedSupportID(
949 bool success, 978 bool success,
950 const std::string& support_id, 979 const std::string& support_id,
951 const base::TimeDelta& lifetime) { 980 const base::TimeDelta& lifetime) {
952 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 981 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
953 982
954 if (!success) { 983 if (!success) {
955 SetState(kError); 984 SetState(kError);
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 return is_good; 1291 return is_good;
1263 } 1292 }
1264 1293
1265 void HostNPScriptObject::SetException(const std::string& exception_string) { 1294 void HostNPScriptObject::SetException(const std::string& exception_string) {
1266 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1295 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1267 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1296 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1268 LOG(INFO) << exception_string; 1297 LOG(INFO) << exception_string;
1269 } 1298 }
1270 1299
1271 } // namespace remoting 1300 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/plugin/host_script_object.h ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698