Skip to content

Commit

Permalink
Revert of Make CapabilityFilter be part of Identity (patchset chromiu…
Browse files Browse the repository at this point in the history
…m#15 id:280001 of https://codereview.chromium.org/1354003002/ )

Reason for revert:
Reverting for test breakage, more info on the bug.
BUG=534227

Original issue's description:
> Make CapabilityFilter be part of Identity
>
> R=yzshen@chromium.org
> http://crbug.com/533085
>
> Committed: https://crrev.com/5403e28c9d9bfcf00b12721b6dc96c00f6d1ed24
> Cr-Commit-Position: refs/heads/master@{#349815}

TBR=yzshen@chromium.org,ben@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review URL: https://codereview.chromium.org/1351443004

Cr-Commit-Position: refs/heads/master@{#349907}
  • Loading branch information
vabr authored and Commit bot committed Sep 21, 2015
1 parent 4316e6a commit 3cc0843
Show file tree
Hide file tree
Showing 21 changed files with 247 additions and 200 deletions.
8 changes: 4 additions & 4 deletions content/browser/mojo/mojo_shell_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ void MojoShellContext::ConnectToApplicationOnOwnThread(
const mojo::Shell::ConnectToApplicationCallback& callback) {
scoped_ptr<mojo::shell::ConnectToApplicationParams> params(
new mojo::shell::ConnectToApplicationParams);
params->set_source(
mojo::shell::Identity(requestor_url, std::string(),
mojo::shell::GetPermissiveCapabilityFilter()));
params->SetTarget(mojo::shell::Identity(url, std::string(), filter));
params->set_originator_identity(mojo::shell::Identity(requestor_url));
params->set_originator_filter(mojo::shell::GetPermissiveCapabilityFilter());
params->SetURLInfo(url);
params->set_services(request.Pass());
params->set_exposed_services(exposed_services.Pass());
params->set_filter(filter);
params->set_on_application_end(base::Bind(&base::DoNothing));
params->set_connect_callback(callback);
application_manager_->ConnectToApplication(params.Pass());
Expand Down
5 changes: 4 additions & 1 deletion mojo/fetcher/about_fetcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ class AboutFetcherTest : public testing::Test {
service_provider.set_connection_error_handler(
[&run_loop]() { run_loop.Quit(); });

URLRequestPtr request(URLRequest::New());
request->url = url;

scoped_ptr<shell::ConnectToApplicationParams> params(
new shell::ConnectToApplicationParams);
params->SetTargetURL(GURL(url));
params->SetURLInfo(request.Pass());
params->set_services(service_provider_request.Pass());
application_manager_->ConnectToApplication(params.Pass());

Expand Down
16 changes: 12 additions & 4 deletions mojo/runner/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ void InitDevToolsServiceIfNeeded(shell::ApplicationManager* manager,
ServiceProviderPtr devtools_service_provider;
scoped_ptr<shell::ConnectToApplicationParams> params(
new shell::ConnectToApplicationParams);
params->set_source(shell::Identity(GURL("mojo:shell")));
params->SetTargetURL(GURL("mojo:devtools_service"));
params->set_originator_identity(shell::Identity(GURL("mojo:shell")));
params->set_originator_filter(shell::GetPermissiveCapabilityFilter());
params->SetURLInfo(GURL("mojo:devtools_service"));
params->set_services(GetProxy(&devtools_service_provider));
params->set_filter(shell::GetPermissiveCapabilityFilter());
manager->ConnectToApplication(params.Pass());

devtools_service::DevToolsCoordinatorPtr devtools_coordinator;
Expand Down Expand Up @@ -205,12 +207,15 @@ bool Context::Init() {
ServiceProviderPtr service_provider_ptr;
ServiceProviderPtr tracing_service_provider_ptr;
new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr));
mojo::URLRequestPtr request(mojo::URLRequest::New());
request->url = mojo::String::From("mojo:tracing");

scoped_ptr<shell::ConnectToApplicationParams> params(
new shell::ConnectToApplicationParams);
params->SetTargetURL(GURL("mojo:tracing"));
params->SetURLInfo(request.Pass());
params->set_services(GetProxy(&service_provider_ptr));
params->set_exposed_services(tracing_service_provider_ptr.Pass());
params->set_filter(shell::GetPermissiveCapabilityFilter());
application_manager_->ConnectToApplication(params.Pass());

// Record the shell startup metrics used for performance testing.
Expand Down Expand Up @@ -259,12 +264,15 @@ void Context::Run(const GURL& url) {
ServiceProviderPtr exposed_services;

app_urls_.insert(url);
mojo::URLRequestPtr request(mojo::URLRequest::New());
request->url = mojo::String::From(url.spec());

scoped_ptr<shell::ConnectToApplicationParams> params(
new shell::ConnectToApplicationParams);
params->SetTargetURL(url);
params->SetURLInfo(request.Pass());
params->set_services(GetProxy(&services));
params->set_exposed_services(exposed_services.Pass());
params->set_filter(shell::GetPermissiveCapabilityFilter());
params->set_on_application_end(
base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url));
application_manager_->ConnectToApplication(params.Pass());
Expand Down
5 changes: 4 additions & 1 deletion mojo/runner/native_runner_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ TEST_F(NativeApplicationLoaderTest, DoesNotExist) {
GURL url(util::FilePathToFileURL(temp_dir.path().Append(nonexistent_file)));
InterfaceRequest<ServiceProvider> services;
ServiceProviderPtr service_provider;
mojo::URLRequestPtr request(mojo::URLRequest::New());
request->url = mojo::String::From(url.spec());

scoped_ptr<shell::ConnectToApplicationParams> params(
new shell::ConnectToApplicationParams);
params->SetTargetURL(url);
params->SetURLInfo(request.Pass());
params->set_services(services.Pass());
params->set_exposed_services(service_provider.Pass());
params->set_filter(shell::GetPermissiveCapabilityFilter());
context_->application_manager()->ConnectToApplication(params.Pass());
EXPECT_FALSE(state_.runner_was_created);
EXPECT_FALSE(state_.runner_was_started);
Expand Down
6 changes: 4 additions & 2 deletions mojo/runner/shell_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ ScopedMessagePipeHandle ShellTestBase::ConnectToService(
const GURL& application_url,
const std::string& service_name) {
ServiceProviderPtr services;
mojo::URLRequestPtr request(mojo::URLRequest::New());
request->url = mojo::String::From(application_url.spec());

scoped_ptr<shell::ConnectToApplicationParams> params(
new shell::ConnectToApplicationParams);
params->SetTarget(shell::Identity(application_url, std::string(),
shell::GetPermissiveCapabilityFilter()));
params->SetURLInfo(request.Pass());
params->set_services(GetProxy(&services));
params->set_filter(shell::GetPermissiveCapabilityFilter());
params->set_on_application_end(base::Bind(&QuitIfRunning));
shell_context_.application_manager()->ConnectToApplication(params.Pass());
MessagePipe pipe;
Expand Down
57 changes: 38 additions & 19 deletions mojo/shell/application_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,38 @@

namespace mojo {
namespace shell {
namespace {

// It's valid to specify mojo: URLs in the filter either as mojo:foo or
// mojo://foo/ - but we store the filter in the latter form.
CapabilityFilter CanonicalizeFilter(const CapabilityFilter& filter) {
CapabilityFilter canonicalized;
for (CapabilityFilter::const_iterator it = filter.begin();
it != filter.end();
++it) {
if (it->first == "*")
canonicalized[it->first] = it->second;
else
canonicalized[GURL(it->first).spec()] = it->second;
}
return canonicalized;
}

} // namespace

ApplicationInstance::ApplicationInstance(
ApplicationPtr application,
ApplicationManager* manager,
const Identity& originator_identity,
const Identity& identity,
const CapabilityFilter& filter,
uint32_t requesting_content_handler_id,
const base::Closure& on_application_end)
: manager_(manager),
originator_identity_(originator_identity),
identity_(identity),
allow_any_application_(identity.filter().size() == 1 &&
identity.filter().count("*") == 1),
filter_(CanonicalizeFilter(filter)),
allow_any_application_(filter.size() == 1 && filter.count("*") == 1),
requesting_content_handler_id_(requesting_content_handler_id),
on_application_end_(on_application_end),
application_(application.Pass()),
Expand All @@ -42,7 +63,7 @@ ApplicationInstance::~ApplicationInstance() {
void ApplicationInstance::InitializeApplication() {
ShellPtr shell;
binding_.Bind(GetProxy(&shell));
application_->Initialize(shell.Pass(), identity_.url().spec());
application_->Initialize(shell.Pass(), identity_.url.spec());
}

void ApplicationInstance::ConnectToClient(
Expand All @@ -69,25 +90,23 @@ void ApplicationInstance::ConnectToApplication(
callback.Run(kInvalidContentHandlerID);
return;
}
if (allow_any_application_ ||
identity_.filter().find(url.spec()) != identity_.filter().end()) {
if (allow_any_application_ || filter_.find(url.spec()) != filter_.end()) {
CapabilityFilter capability_filter = GetPermissiveCapabilityFilter();
if (!filter.is_null())
capability_filter = filter->filter.To<CapabilityFilter>();

scoped_ptr<ConnectToApplicationParams> params(
new ConnectToApplicationParams);
params->SetSource(this);
params->SetTargetURLRequest(
app_request.Pass(),
Identity(GURL(app_request->url), std::string(), capability_filter));
params->SetOriginatorInfo(this);
params->SetURLInfo(app_request.Pass());
params->set_services(services.Pass());
params->set_exposed_services(exposed_services.Pass());
params->set_filter(capability_filter);
params->set_connect_callback(callback);
manager_->ConnectToApplication(params.Pass());
} else {
LOG(WARNING) << "CapabilityFilter prevented connection from: " <<
identity_.url() << " to: " << url.spec();
identity_.url << " to: " << url.spec();
callback.Run(kInvalidContentHandlerID);
}
}
Expand All @@ -104,13 +123,13 @@ void ApplicationInstance::CallAcceptConnection(
params->connect_callback().Run(requesting_content_handler_id_);
AllowedInterfaces interfaces;
interfaces.insert("*");
if (!params->source().is_null())
interfaces = GetAllowedInterfaces(params->source().filter(), identity_);
if (!params->originator_identity().is_null())
interfaces = GetAllowedInterfaces(params->originator_filter(), identity_);

application_->AcceptConnection(
params->source().url().spec(), params->TakeServices(),
params->originator_identity().url.spec(), params->TakeServices(),
params->TakeExposedServices(), Array<String>::From(interfaces).Pass(),
params->target().url().spec());
params->app_url().spec());
}

void ApplicationInstance::OnConnectionError() {
Expand All @@ -123,8 +142,8 @@ void ApplicationInstance::OnConnectionError() {
// If any queued requests came to shell during time it was shutting down,
// start them now.
for (auto request : queued_client_requests) {
// Unfortunately, it is possible that |request->target_url_request()| is
// null at this point. Consider the following sequence:
// Unfortunately, it is possible that |request->app_url_request()| is null
// at this point. Consider the following sequence:
// 1) connect_request_1 arrives at the application manager; the manager
// decides to fetch the app.
// 2) connect_request_2 arrives for the same app; because the app is not
Expand All @@ -141,10 +160,10 @@ void ApplicationInstance::OnConnectionError() {
// before starting the fetch. So at step (2) the application manager knows
// that it can wait for the first fetch to complete instead of doing a
// second one directly.
if (!request->target_url_request()) {
if (!request->app_url_request()) {
URLRequestPtr url_request = mojo::URLRequest::New();
url_request->url = request->target().url().spec();
request->SetTargetURLRequest(url_request.Pass(), request->target());
url_request->url = request->app_url().spec();
request->SetURLInfo(url_request.Pass());
}
manager->ConnectToApplication(make_scoped_ptr(request));
}
Expand Down
7 changes: 6 additions & 1 deletion mojo/shell/application_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class ApplicationInstance : public Shell {
// is kInvalidContentHandlerID.
ApplicationInstance(ApplicationPtr application,
ApplicationManager* manager,
const Identity& identity,
const Identity& originator_identity,
const Identity& resolved_identity,
const CapabilityFilter& filter,
uint32_t requesting_content_handler_id,
const base::Closure& on_application_end);

Expand All @@ -43,6 +45,7 @@ class ApplicationInstance : public Shell {

Application* application() { return application_.get(); }
const Identity& identity() const { return identity_; }
const CapabilityFilter& filter() const { return filter_; }
base::Closure on_application_end() const { return on_application_end_; }
void set_requesting_content_handler_id(uint32_t id) {
requesting_content_handler_id_ = id;
Expand All @@ -68,7 +71,9 @@ class ApplicationInstance : public Shell {
void OnQuitRequestedResult(bool can_quit);

ApplicationManager* const manager_;
const Identity originator_identity_;
const Identity identity_;
const CapabilityFilter filter_;
const bool allow_any_application_;
uint32_t requesting_content_handler_id_;
base::Closure on_application_end_;
Expand Down
Loading

0 comments on commit 3cc0843

Please sign in to comment.