summaryrefslogtreecommitdiffstats
path: root/mojo/shell
diff options
context:
space:
mode:
authorsky <sky@chromium.org>2015-05-12 11:08:08 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-12 18:08:18 +0000
commit57439937b14ad4362ab4dde3f828b7017f4aad8d (patch)
treee160d7643d2de1f1d60d8ddcc5c51021d9d4ac15 /mojo/shell
parent11c5ff87774c88b785065f0d74681c5a867026bf (diff)
downloadchromium_src-57439937b14ad4362ab4dde3f828b7017f4aad8d.zip
chromium_src-57439937b14ad4362ab4dde3f828b7017f4aad8d.tar.gz
chromium_src-57439937b14ad4362ab4dde3f828b7017f4aad8d.tar.bz2
Makes content handlers see requestor url
Prior to this fix the incoming connection to the content handler saw an empty requesting url. This change makes the requesting url correspond to the url of the first app connecting to the content handler. BUG=none TEST=covered by test R=ben@chromium.org Review URL: https://codereview.chromium.org/1130353005 Cr-Commit-Position: refs/heads/master@{#329441}
Diffstat (limited to 'mojo/shell')
-rw-r--r--mojo/shell/application_manager.cc25
-rw-r--r--mojo/shell/application_manager.h9
-rw-r--r--mojo/shell/application_manager_unittest.cc80
3 files changed, 105 insertions, 9 deletions
diff --git a/mojo/shell/application_manager.cc b/mojo/shell/application_manager.cc
index c8aa78a..5d1a9fe 100644
--- a/mojo/shell/application_manager.cc
+++ b/mojo/shell/application_manager.cc
@@ -35,14 +35,15 @@ class ApplicationManager::ContentHandlerConnection : public ErrorHandler {
public:
ContentHandlerConnection(ApplicationManager* manager,
const GURL& content_handler_url,
+ const GURL& requestor_url,
const std::string& qualifier)
: manager_(manager),
content_handler_url_(content_handler_url),
content_handler_qualifier_(qualifier) {
ServiceProviderPtr services;
manager->ConnectToApplicationWithParameters(
- content_handler_url, qualifier, GURL(), GetProxy(&services), nullptr,
- base::Closure(), std::vector<std::string>());
+ content_handler_url, qualifier, requestor_url, GetProxy(&services),
+ nullptr, base::Closure(), std::vector<std::string>());
MessagePipe pipe;
content_handler_.Bind(pipe.handle0.Pass());
services->ConnectToService(ContentHandler::Name_, pipe.handle1.Pass());
@@ -165,6 +166,12 @@ void ApplicationManager::ConnectToApplicationWithParameters(
base::Passed(exposed_services.Pass()), on_application_end,
pre_redirect_parameters);
+ if (delegate_->CreateFetcher(
+ resolved_url,
+ base::Bind(callback, NativeApplicationCleanup::DONT_DELETE))) {
+ return;
+ }
+
if (resolved_url.SchemeIsFile()) {
new LocalFetcher(
resolved_url, GetBaseURLAndQuery(resolved_url, nullptr),
@@ -311,7 +318,7 @@ void ApplicationManager::HandleFetchCallback(
std::string shebang;
if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) {
LoadWithContentHandler(
- content_handler_url, qualifier, request.Pass(),
+ content_handler_url, requestor_url, qualifier, request.Pass(),
fetcher->AsURLResponse(blocking_pool_,
static_cast<int>(shebang.size())));
return;
@@ -319,7 +326,8 @@ void ApplicationManager::HandleFetchCallback(
MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType());
if (iter != mime_type_to_url_.end()) {
- LoadWithContentHandler(iter->second, qualifier, request.Pass(),
+ LoadWithContentHandler(iter->second, requestor_url, qualifier,
+ request.Pass(),
fetcher->AsURLResponse(blocking_pool_, 0));
return;
}
@@ -345,8 +353,8 @@ void ApplicationManager::HandleFetchCallback(
qualifier = alias_iter->second.second;
}
- LoadWithContentHandler(alias_iter->second.first, qualifier, request.Pass(),
- response.Pass());
+ LoadWithContentHandler(alias_iter->second.first, requestor_url, qualifier,
+ request.Pass(), response.Pass());
return;
}
@@ -417,6 +425,7 @@ void ApplicationManager::RegisterApplicationPackageAlias(
void ApplicationManager::LoadWithContentHandler(
const GURL& content_handler_url,
+ const GURL& requestor_url,
const std::string& qualifier,
InterfaceRequest<Application> application_request,
URLResponsePtr url_response) {
@@ -426,8 +435,8 @@ void ApplicationManager::LoadWithContentHandler(
if (iter != url_to_content_handler_.end()) {
connection = iter->second;
} else {
- connection =
- new ContentHandlerConnection(this, content_handler_url, qualifier);
+ connection = new ContentHandlerConnection(this, content_handler_url,
+ requestor_url, qualifier);
url_to_content_handler_[key] = connection;
}
diff --git a/mojo/shell/application_manager.h b/mojo/shell/application_manager.h
index 5db7467..8cdf89b 100644
--- a/mojo/shell/application_manager.h
+++ b/mojo/shell/application_manager.h
@@ -16,6 +16,7 @@
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include "mojo/services/network/public/interfaces/network_service.mojom.h"
#include "mojo/shell/application_loader.h"
+#include "mojo/shell/fetcher.h"
#include "mojo/shell/identity.h"
#include "mojo/shell/native_runner.h"
#include "url/gurl.h"
@@ -28,7 +29,6 @@ class SequencedWorkerPool;
namespace mojo {
namespace shell {
-class Fetcher;
class ShellImpl;
class ApplicationManager {
@@ -43,6 +43,12 @@ class ApplicationManager {
// |url| if the scheme is not 'mojo'.
virtual GURL ResolveMojoURL(const GURL& url) = 0;
+ // Asks the delegate to create a Fetcher for the specified url. Return
+ // true on success, false if the default fetcher should be created.
+ virtual bool CreateFetcher(
+ const GURL& url,
+ const Fetcher::FetchCallback& loader_callback) = 0;
+
protected:
virtual ~Delegate() {}
};
@@ -210,6 +216,7 @@ class ApplicationManager {
bool path_exists);
void LoadWithContentHandler(const GURL& content_handler_url,
+ const GURL& requestor_url,
const std::string& qualifier,
InterfaceRequest<Application> application_request,
URLResponsePtr url_response);
diff --git a/mojo/shell/application_manager_unittest.cc b/mojo/shell/application_manager_unittest.cc
index ef77f2f..d77a9aa 100644
--- a/mojo/shell/application_manager_unittest.cc
+++ b/mojo/shell/application_manager_unittest.cc
@@ -15,6 +15,7 @@
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include "mojo/shell/application_loader.h"
#include "mojo/shell/application_manager.h"
+#include "mojo/shell/fetcher.h"
#include "mojo/shell/test.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -26,6 +27,36 @@ const char kTestURLString[] = "test:testService";
const char kTestAURLString[] = "test:TestA";
const char kTestBURLString[] = "test:TestB";
+const char kTestMimeType[] = "test/mime-type";
+
+class TestMimeTypeFetcher : public Fetcher {
+ public:
+ explicit TestMimeTypeFetcher(const FetchCallback& fetch_callback)
+ : Fetcher(fetch_callback), url_("xxx") {
+ loader_callback_.Run(make_scoped_ptr(this));
+ }
+ ~TestMimeTypeFetcher() override {}
+
+ // Fetcher:
+ const GURL& GetURL() const override { return url_; }
+ GURL GetRedirectURL() const override { return GURL("yyy"); }
+ URLResponsePtr AsURLResponse(base::TaskRunner* task_runner,
+ uint32_t skip) override {
+ return URLResponse::New().Pass();
+ }
+ void AsPath(
+ base::TaskRunner* task_runner,
+ base::Callback<void(const base::FilePath&, bool)> callback) override {}
+ std::string MimeType() override { return kTestMimeType; }
+ bool HasMojoMagic() override { return false; }
+ bool PeekFirstLine(std::string* line) override { return false; }
+
+ private:
+ const GURL url_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestMimeTypeFetcher);
+};
+
struct TestContext {
TestContext() : num_impls(0), num_loader_deletes(0) {}
std::string last_test_string;
@@ -115,6 +146,7 @@ class TestApplicationLoader : public ApplicationLoader,
void set_context(TestContext* context) { context_ = context; }
int num_loads() const { return num_loads_; }
const std::vector<std::string>& GetArgs() const { return test_app_->args(); }
+ const GURL& last_requestor_url() const { return last_requestor_url_; }
private:
// ApplicationLoader implementation.
@@ -127,6 +159,7 @@ class TestApplicationLoader : public ApplicationLoader,
// ApplicationDelegate implementation.
bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
connection->AddService(this);
+ last_requestor_url_ = GURL(connection->GetRemoteApplicationURL());
return true;
}
@@ -139,6 +172,8 @@ class TestApplicationLoader : public ApplicationLoader,
scoped_ptr<ApplicationImpl> test_app_;
TestContext* context_;
int num_loads_;
+ GURL last_requestor_url_;
+
DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader);
};
@@ -393,8 +428,15 @@ class Tester : public ApplicationDelegate,
class TestDelegate : public ApplicationManager::Delegate {
public:
+ TestDelegate() : create_test_fetcher_(false) {}
+ ~TestDelegate() override {}
+
void AddMapping(const GURL& from, const GURL& to) { mappings_[from] = to; }
+ void set_create_test_fetcher(bool create_test_fetcher) {
+ create_test_fetcher_ = create_test_fetcher;
+ }
+
// ApplicationManager::Delegate
GURL ResolveMappings(const GURL& url) override {
auto it = mappings_.find(url);
@@ -412,9 +454,19 @@ class TestDelegate : public ApplicationManager::Delegate {
}
return mapped_url;
}
+ bool CreateFetcher(const GURL& url,
+ const Fetcher::FetchCallback& loader_callback) override {
+ if (!create_test_fetcher_)
+ return false;
+ new TestMimeTypeFetcher(loader_callback);
+ return true;
+ }
private:
std::map<GURL, GURL> mappings_;
+ bool create_test_fetcher_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestDelegate);
};
class ApplicationManagerTest : public testing::Test {
@@ -739,6 +791,34 @@ TEST_F(ApplicationManagerTest, TestEndApplicationClosure) {
EXPECT_TRUE(called);
}
+TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) {
+ const GURL content_handler_url("http://test.content.handler");
+ const GURL requestor_url("http://requestor.url");
+ TestContext test_context;
+ base::MessageLoop loop;
+ TestDelegate test_delegate;
+ test_delegate.set_create_test_fetcher(true);
+ ApplicationManager application_manager(&test_delegate);
+ application_manager.set_default_loader(nullptr);
+ application_manager.RegisterContentHandler(kTestMimeType,
+ content_handler_url);
+
+ TestApplicationLoader* loader = new TestApplicationLoader;
+ loader->set_context(&test_context);
+ application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader),
+ content_handler_url);
+
+ bool called = false;
+ application_manager.ConnectToApplication(
+ GURL("test:test"), requestor_url, nullptr, nullptr,
+ base::Bind(&QuitClosure, base::Unretained(&called)));
+ loop.Run();
+ EXPECT_TRUE(called);
+
+ ASSERT_EQ(1, loader->num_loads());
+ EXPECT_EQ(requestor_url, loader->last_requestor_url());
+}
+
} // namespace
} // namespace shell
} // namespace mojo