Skip to content

Commit

Permalink
Restrict the Chromoting client plugin to use by extensions & apps.
Browse files Browse the repository at this point in the history
BUG=160456


Review URL: https://chromiumcodereview.appspot.com/11365276

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168289 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
wez@chromium.org committed Nov 16, 2012
1 parent c4a5d6e commit 21fdcdd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions remoting/client/plugin/chromoting_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "media/base/media.h"
#include "net/socket/ssl_server_socket.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/dev/url_util_dev.h"
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/mouse_cursor.h"
#include "ppapi/cpp/rect.h"
Expand Down Expand Up @@ -55,6 +56,9 @@ const int kBytesPerPixel = 4;

const int kPerfStatsIntervalMs = 1000;

// URL scheme used by Chrome apps and extensions.
const char kChromeExtensionUrlScheme[] = "chrome-extension";

std::string ConnectionStateToString(protocol::ConnectionToHost::State state) {
// Values returned by this function must match the
// remoting.ClientSession.State enum in JS code.
Expand Down Expand Up @@ -217,6 +221,12 @@ bool ChromotingInstance::Init(uint32_t argc,
return false;
}

// Check that the calling content is part of an app or extension.
if (!IsCallerAppOrExtension()) {
LOG(ERROR) << "Not an app or extension";
return false;
}

// Enable support for SSL server sockets, which must be done as early as
// possible, preferably before any NSS SSL sockets (client or server) have
// been created.
Expand Down Expand Up @@ -754,6 +764,22 @@ void ChromotingInstance::ProcessLogToUI(const std::string& message) {
g_logging_to_plugin = false;
}

bool ChromotingInstance::IsCallerAppOrExtension() {
const pp::URLUtil_Dev* url_util = pp::URLUtil_Dev::Get();
if (!url_util)
return false;

PP_URLComponents_Dev url_components;
pp::Var url_var = url_util->GetDocumentURL(this, &url_components);
if (!url_var.is_string())
return false;

std::string url = url_var.AsString();
std::string url_scheme = url.substr(url_components.scheme.begin,
url_components.scheme.len);
return url_scheme == kChromeExtensionUrlScheme;
}

bool ChromotingInstance::IsConnected() {
return host_connection_.get() &&
(host_connection_->state() == protocol::ConnectionToHost::CONNECTED);
Expand Down
3 changes: 3 additions & 0 deletions remoting/client/plugin/chromoting_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ class ChromotingInstance :

void ProcessLogToUI(const std::string& message);

// Returns true if the hosting content has the chrome-extension:// scheme.
bool IsCallerAppOrExtension();

// Returns true if there is a ConnectionToHost and it is connected.
bool IsConnected();

Expand Down

0 comments on commit 21fdcdd

Please sign in to comment.