diff options
author | jamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-05 20:08:41 +0000 |
---|---|---|
committer | jamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-05 20:08:41 +0000 |
commit | 7363262974510e07662671585faa2f90af20703a (patch) | |
tree | 3c0fbb02c305b087c8fe04bc6bd8b346bb4afd74 /remoting | |
parent | e7df0f88d1afc197cbb741d425d7625e4e59a180 (diff) | |
download | chromium_src-7363262974510e07662671585faa2f90af20703a.zip chromium_src-7363262974510e07662671585faa2f90af20703a.tar.gz chromium_src-7363262974510e07662671585faa2f90af20703a.tar.bz2 |
Show warning if NAT is disabled.
BUG=96735
TEST=Start sharing on a machine on which NAT traversal is disabled. You should (eventually) see an info box at the bottom of the page.
Review URL: http://codereview.chromium.org/8136015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104163 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/plugin/host_script_object.cc | 53 | ||||
-rw-r--r-- | remoting/host/plugin/host_script_object.h | 7 | ||||
-rw-r--r-- | remoting/webapp/me2mom/_locales/en/messages.json | 4 | ||||
-rw-r--r-- | remoting/webapp/me2mom/choice.css | 11 | ||||
-rw-r--r-- | remoting/webapp/me2mom/choice.html | 7 | ||||
-rw-r--r-- | remoting/webapp/me2mom/client_session.js | 1 | ||||
-rw-r--r-- | remoting/webapp/me2mom/host_plugin_proto.js | 3 | ||||
-rw-r--r-- | remoting/webapp/me2mom/remoting.js | 7 |
8 files changed, 89 insertions, 4 deletions
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc index 76441fe..6f900af 100644 --- a/remoting/host/plugin/host_script_object.cc +++ b/remoting/host/plugin/host_script_object.cc @@ -41,6 +41,7 @@ namespace remoting { // } // // attribute Function void logDebugInfo(string); +// attribute Function void onNatTraversalPolicyChanged(boolean); // attribute Function void onStateChanged(); // // // The |auth_service_with_token| parameter should be in the format @@ -56,6 +57,8 @@ const char* kAttrNameAccessCodeLifetime = "accessCodeLifetime"; const char* kAttrNameClient = "client"; const char* kAttrNameState = "state"; const char* kAttrNameLogDebugInfo = "logDebugInfo"; +const char* kAttrNameOnNatTraversalPolicyChanged = + "onNatTraversalPolicyChanged"; const char* kAttrNameOnStateChanged = "onStateChanged"; const char* kFuncNameConnect = "connect"; const char* kFuncNameDisconnect = "disconnect"; @@ -180,6 +183,7 @@ bool HostNPScriptObject::HasProperty(const std::string& property_name) { property_name == kAttrNameClient || property_name == kAttrNameState || property_name == kAttrNameLogDebugInfo || + property_name == kAttrNameOnNatTraversalPolicyChanged || property_name == kAttrNameOnStateChanged || property_name == kAttrNameDisconnected || property_name == kAttrNameStarting || @@ -199,7 +203,10 @@ bool HostNPScriptObject::GetProperty(const std::string& property_name, return false; } - if (property_name == kAttrNameOnStateChanged) { + if (property_name == kAttrNameOnNatTraversalPolicyChanged) { + OBJECT_TO_NPVARIANT(on_nat_traversal_policy_changed_func_.get(), *result); + return true; + } else if (property_name == kAttrNameOnStateChanged) { OBJECT_TO_NPVARIANT(on_state_changed_func_.get(), *result); return true; } else if (property_name == kAttrNameLogDebugInfo) { @@ -251,6 +258,26 @@ bool HostNPScriptObject::SetProperty(const std::string& property_name, VLOG(2) << "SetProperty " << property_name; CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); + if (property_name == kAttrNameOnNatTraversalPolicyChanged) { + if (NPVARIANT_IS_OBJECT(*value)) { + on_nat_traversal_policy_changed_func_ = NPVARIANT_TO_OBJECT(*value); + bool policy_received, nat_traversal_enabled; + { + base::AutoLock lock(nat_policy_lock_); + policy_received = policy_received_; + nat_traversal_enabled = nat_traversal_enabled_; + } + if (policy_received) { + UpdateWebappNatPolicy(nat_traversal_enabled); + } + return true; + } else { + SetException("SetProperty: unexpected type for property " + + property_name); + } + return false; + } + if (property_name == kAttrNameOnStateChanged) { if (NPVARIANT_IS_OBJECT(*value)) { on_state_changed_func_ = NPVARIANT_TO_OBJECT(*value); @@ -578,8 +605,13 @@ void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { DisconnectInternal(); } - policy_received_ = true; - nat_traversal_enabled_ = nat_traversal_enabled; + { + base::AutoLock lock(nat_policy_lock_); + policy_received_ = true; + nat_traversal_enabled_ = nat_traversal_enabled; + } + + UpdateWebappNatPolicy(nat_traversal_enabled_); if (!pending_connect_.is_null()) { pending_connect_.Run(); @@ -765,6 +797,21 @@ bool HostNPScriptObject::LocalizeString(NPObject* localize_func, return true; } +void HostNPScriptObject::UpdateWebappNatPolicy(bool nat_traversal_enabled) { + if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { + plugin_message_loop_proxy_->PostTask( + FROM_HERE, base::Bind(&HostNPScriptObject::UpdateWebappNatPolicy, + base::Unretained(this), nat_traversal_enabled)); + return; + } + if (on_nat_traversal_policy_changed_func_.get()) { + NPVariant policy; + BOOLEAN_TO_NPVARIANT(nat_traversal_enabled, policy); + InvokeAndIgnoreResult(on_nat_traversal_policy_changed_func_.get(), + &policy, 1); + } +} + bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func, const NPVariant* args, uint32_t argCount) { diff --git a/remoting/host/plugin/host_script_object.h b/remoting/host/plugin/host_script_object.h index 2ae146e..bfcdf31 100644 --- a/remoting/host/plugin/host_script_object.h +++ b/remoting/host/plugin/host_script_object.h @@ -150,6 +150,10 @@ class HostNPScriptObject : public HostStatusObserver { bool LocalizeString(NPObject* localize_func, const char* tag, string16* result); + // If the web-app has registered a callback to be notified of changes to the + // NAT traversal policy, notify it. + void UpdateWebappNatPolicy(bool nat_traversal_enabled); + // Helper function for executing InvokeDefault on an NPObject, and ignoring // the return value. bool InvokeAndIgnoreResult(NPObject* func, @@ -169,6 +173,7 @@ class HostNPScriptObject : public HostStatusObserver { std::string client_username_; ScopedRefNPObject log_debug_info_func_; + ScopedRefNPObject on_nat_traversal_policy_changed_func_; ScopedRefNPObject on_state_changed_func_; base::PlatformThreadId np_thread_id_; scoped_refptr<PluginMessageLoopProxy> plugin_message_loop_proxy_; @@ -189,6 +194,8 @@ class HostNPScriptObject : public HostStatusObserver { // True if we're in the middle of handling a log message. bool am_currently_logging_; + base::Lock nat_policy_lock_; + scoped_ptr<policy_hack::NatPolicy> nat_policy_; // Host the current nat traversal policy setting. diff --git a/remoting/webapp/me2mom/_locales/en/messages.json b/remoting/webapp/me2mom/_locales/en/messages.json index 597bf56..7c1feee 100644 --- a/remoting/webapp/me2mom/_locales/en/messages.json +++ b/remoting/webapp/me2mom/_locales/en/messages.json @@ -206,5 +206,9 @@ "VERIFYING_CODE": { "message": "Verifying access code\u2026", "description": "Message displayed on the client while the access code is verified." + }, + "WARNING_NAT_DISABLED": { + "message": "NOTE: Policy settings permit connections only between computers within your network.", + "description": "Message displayed at the bottom of the host screen if local policy dictates that NAT traversal is disabled, meaning that connections outside the local network will not work." } } diff --git a/remoting/webapp/me2mom/choice.css b/remoting/webapp/me2mom/choice.css index d99415e..2dd1b01 100644 --- a/remoting/webapp/me2mom/choice.css +++ b/remoting/webapp/me2mom/choice.css @@ -135,6 +135,17 @@ label { vertical-align: top; } +.information-box { + background-color: #f9e9be; + border: 1px solid #cacaca; + bottom: 8px; + color: black; + padding: 20px; + position: absolute; + text-align: center; + width: 600px; /* body width - 2*padding */ +} + .message { text-align:center; margin-bottom: 10px; diff --git a/remoting/webapp/me2mom/choice.html b/remoting/webapp/me2mom/choice.html index d303cf4..4dd6a97 100644 --- a/remoting/webapp/me2mom/choice.html +++ b/remoting/webapp/me2mom/choice.html @@ -230,6 +230,13 @@ found in the LICENSE file. i18n-content="CANCEL"> </button> </div> <!-- waiting-footer --> + + <div id="nat-box-container" hidden> + <div class="information-box" + i18n-content="WARNING_NAT_DISABLED" + data-ui-mode="host.waiting-for-code host.waiting-for-connection"> + </div> + </div> <!-- nat-box-container --> </footer> </div> <!-- main --> diff --git a/remoting/webapp/me2mom/client_session.js b/remoting/webapp/me2mom/client_session.js index 47eab31..49ca19a 100644 --- a/remoting/webapp/me2mom/client_session.js +++ b/remoting/webapp/me2mom/client_session.js @@ -355,7 +355,6 @@ remoting.ClientSession.prototype.onDesktopSizeChanged_ = function() { * Refreshes the plugin's dimensions, taking into account the sizes of the * remote desktop and client window, and the current scale-to-fit setting. * - * @param {boolean} shouldScale If the plugin should scale itself. * @return {void} Nothing. */ remoting.ClientSession.prototype.updateDimensions = function() { diff --git a/remoting/webapp/me2mom/host_plugin_proto.js b/remoting/webapp/me2mom/host_plugin_proto.js index 59addc6..1b10240 100644 --- a/remoting/webapp/me2mom/host_plugin_proto.js +++ b/remoting/webapp/me2mom/host_plugin_proto.js @@ -38,3 +38,6 @@ remoting.HostPlugin.prototype.localize = function(callback) {}; /** @type {number} */ remoting.HostPlugin.prototype.accessCodeLifetime; /** @type {string} */ remoting.HostPlugin.prototype.client; + +/** @type {function(boolean):void} */ +remoting.HostPlugin.prototype.onNatTraversalPolicyChanged; diff --git a/remoting/webapp/me2mom/remoting.js b/remoting/webapp/me2mom/remoting.js index 966d495..d40c841 100644 --- a/remoting/webapp/me2mom/remoting.js +++ b/remoting/webapp/me2mom/remoting.js @@ -246,6 +246,8 @@ remoting.tryShare = function() { plugin.width = 0; plugin.height = 0; div.appendChild(plugin); + onNatTraversalPolicyChanged_(true); // Hide warning by default. + plugin.onNatTraversalPolicyChanged = onNatTraversalPolicyChanged_; plugin.onStateChanged = onStateChanged_; plugin.logDebugInfo = debugInfoCallback_; plugin.localize(chrome.i18n.getMessage); @@ -303,6 +305,11 @@ remoting.updateAccessCodeTimeoutElement_ = function() { } } +function onNatTraversalPolicyChanged_(enabled) { + var container = document.getElementById('nat-box-container'); + container.hidden = enabled; +} + function onStateChanged_() { var plugin = /** @type {remoting.HostPlugin} */ document.getElementById(remoting.HOST_PLUGIN_ID); |