Index: chrome/browser/extensions/platform_app_redirector.cc |
diff --git a/chrome/browser/extensions/platform_app_redirector.cc b/chrome/browser/extensions/platform_app_redirector.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..769c50c5d86efe57cb4f79a5ce36beb3567019bb |
--- /dev/null |
+++ b/chrome/browser/extensions/platform_app_redirector.cc |
@@ -0,0 +1,78 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/extensions/platform_app_redirector.h" |
+ |
+#include "base/logging.h" |
+#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" |
+#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/extensions/extension_system.h" |
+#include "chrome/browser/extensions/platform_app_launcher.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/common/chrome_notification_types.h" |
+#include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h" |
+#include "chrome/common/extensions/extension_set.h" |
+#include "content/public/browser/notification_details.h" |
+#include "content/public/browser/notification_service.h" |
+#include "content/public/browser/notification_source.h" |
+#include "content/public/browser/render_process_host.h" |
+#include "content/public/browser/url_handling_notifications.h" |
+#include "googleurl/src/gurl.h" |
+ |
+namespace extensions { |
+ |
+PlatformAppRedirector::PlatformAppRedirector(Profile* profile) |
+ : profile_(profile), |
+ extensions_(extensions::ExtensionSystem::Get(profile)-> |
+ extension_service()->extensions()) { |
+ registrar_.Add(this, content::NOTIFICATION_HANDLE_URL_IN_BROWSER, |
+ content::NotificationService::AllBrowserContextsAndSources()); |
not at google - send to devlin
2013/08/29 17:35:56
All profiles? really? If you register this only fo
sergeygs
2013/08/30 00:39:44
Done. Great catch.
|
+} |
+ |
+bool PlatformAppRedirector::MaybeLaunchPlatformAppWithUrl( |
+ const GURL& url, |
+ const GURL& referrer_url) const { |
+ for (ExtensionSet::const_iterator it = extensions_->begin(); |
+ it != extensions_->end(); ++it) { |
+ const extensions::UrlHandlerInfo* handler = |
+ UrlHandlers::FindMatchingUrlHandler(*it, url); |
+ if (handler) { |
+ extensions::LaunchPlatformAppWithUrl( |
+ profile_, *it, handler->id, url, referrer_url); |
+ return true; |
+ } |
+ } |
+ return false; |
+} |
+ |
+void PlatformAppRedirector::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ switch (type) { |
+ case content::NOTIFICATION_HANDLE_URL_IN_BROWSER: { |
not at google - send to devlin
2013/08/29 17:35:56
It would be really nice if you could not use a not
sergeygs
2013/08/30 00:39:44
It seemed really hard to connect the two communica
not at google - send to devlin
2013/08/30 17:07:58
So this class can't implement URL filter or someth
sergeygs
2013/09/02 07:36:21
This completely goes away in the 2nd round of smal
|
+ // Limit app launching to the originating profile only. |
+ if (profile_ != |
+ Profile::FromBrowserContext( |
+ content::Source<content::RenderProcessHost>(source).ptr()-> |
+ GetBrowserContext())) { |
+ break; |
+ } |
+ // Attempt to launch the app. |
+ content::ForwardUrlToBrowserDetails* launch = |
+ content::Details<content::ForwardUrlToBrowserDetails>(details).ptr(); |
+ const bool launched = |
+ MaybeLaunchPlatformAppWithUrl(launch->url, launch->referrer_url); |
+ // The issuer of this notification must that a handling app |
+ // exists before sending this notification. |
+ DCHECK(launched); |
+ break; |
+ } |
+ |
+ default: |
+ NOTREACHED() << "Unexpected notification type."; |
not at google - send to devlin
2013/08/29 17:35:56
just DCHECK(type == content::NOTIFICATION_HANDLE_U
sergeygs
2013/08/30 00:39:44
The way it is now is a common pattern around the c
|
+ } |
+} |
+ |
+} // namespace extensions |