Allows URL queries to be passed to contet handlers.

R=ppi@chromium.org
BUG=Fixes https://github.com/domokit/mojo/issues/559

Review URL: https://codereview.chromium.org/1472923002 .
diff --git a/shell/application_manager/application_manager.cc b/shell/application_manager/application_manager.cc
index 8453f1c..c87f511 100644
--- a/shell/application_manager/application_manager.cc
+++ b/shell/application_manager/application_manager.cc
@@ -31,6 +31,9 @@
 
 namespace {
 
+// Create identity that depends on the query.
+const bool kDoNotStripQuery = false;
+
 // Used by TestAPI.
 bool has_created_instance = false;
 
@@ -100,6 +103,7 @@
 }
 
 bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const {
+  DCHECK(!url.has_query());
   return manager_->identity_to_shell_impl_.find(Identity(url)) !=
          manager_->identity_to_shell_impl_.end();
 }
@@ -266,15 +270,17 @@
   return true;
 }
 
-Identity ApplicationManager::MakeApplicationIdentity(const GURL& resolved_url) {
+Identity ApplicationManager::MakeApplicationIdentity(const GURL& resolved_url,
+                                                     bool strip_query) {
   static uint64_t unique_id_number = 1;
+  GURL stripped_url = GetBaseURLAndQuery(resolved_url, nullptr);
+  GURL url = strip_query ? stripped_url : resolved_url;
   bool new_process_per_connection =
-      GetNativeApplicationOptionsForURL(
-          GetBaseURLAndQuery(resolved_url, nullptr))
+      GetNativeApplicationOptionsForURL(stripped_url)
           ->new_process_per_connection;
   return new_process_per_connection
-             ? Identity(resolved_url, base::Uint64ToString(unique_id_number++))
-             : Identity(resolved_url);
+             ? Identity(url, base::Uint64ToString(unique_id_number++))
+             : Identity(url);
 }
 
 InterfaceRequest<Application> ApplicationManager::RegisterShell(
@@ -302,6 +308,7 @@
 // (such that multiple requests for a service result in unique processes), then
 // 'GetShellImpl' should return nullptr.
 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) {
+  DCHECK(!url.has_query());
   const auto& shell_it = identity_to_shell_impl_.find(Identity(url));
   if (shell_it != identity_to_shell_impl_.end())
     return shell_it->second.get();
@@ -437,7 +444,10 @@
     InterfaceRequest<Application> application_request,
     mojo::URLResponsePtr url_response) {
   ContentHandlerConnection* connection = nullptr;
-  Identity content_handler_id = MakeApplicationIdentity(content_handler_url);
+  // If two content handler urls differ by query parameter, we want to create a
+  // separate connection for each.
+  Identity content_handler_id =
+      MakeApplicationIdentity(content_handler_url, kDoNotStripQuery);
   auto it = identity_to_content_handler_.find(content_handler_id);
   if (it != identity_to_content_handler_.end()) {
     connection = it->second.get();
diff --git a/shell/application_manager/application_manager.h b/shell/application_manager/application_manager.h
index 3be4992..f3224f1 100644
--- a/shell/application_manager/application_manager.h
+++ b/shell/application_manager/application_manager.h
@@ -178,8 +178,10 @@
   // Creates an Identity for the service identified by |resolved_url|.
   // If |new_process_per_connection| is true for the URL's options, then the
   // identity is unique. Otherwise, repeated invocations with the same
-  // |resolved_url| will result in an equivalent Identity.
-  Identity MakeApplicationIdentity(const GURL& resolved_url);
+  // |resolved_url| will result in an equivalent Identity. If |strip_query| is
+  // true, the query is stripped before creating the Identity.
+  Identity MakeApplicationIdentity(const GURL& resolved_url,
+                                   bool strip_query = true);
 
   mojo::InterfaceRequest<mojo::Application> RegisterShell(
       // The URL after resolution and redirects, including the querystring.
diff --git a/shell/application_manager/identity.cc b/shell/application_manager/identity.cc
index c40a73c..b273f99 100644
--- a/shell/application_manager/identity.cc
+++ b/shell/application_manager/identity.cc
@@ -9,12 +9,9 @@
 namespace shell {
 
 Identity::Identity(const GURL& url, const std::string& qualifier)
-    : url(GetBaseURLAndQuery(url, nullptr)), qualifier(qualifier) {
-}
+    : url(url), qualifier(qualifier) {}
 
-Identity::Identity(const GURL& base_url)
-    : url(GetBaseURLAndQuery(base_url, nullptr)), qualifier(url.spec()) {
-}
+Identity::Identity(const GURL& url) : url(url), qualifier(url.spec()) {}
 
 bool Identity::operator<(const Identity& other) const {
   if (url != other.url)