Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1504)

Unified Diff: chrome/browser/extensions/platform_app_redirector.cc

Issue 22944002: Implementation of the "Redirect URLs to Packaged Apps" feature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review comments + lint errors Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5a7d72cf92841a78973a487bb7cffe7fc9ed3dca
--- /dev/null
+++ b/chrome/browser/extensions/platform_app_redirector.cc
@@ -0,0 +1,84 @@
+// 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()) {
+ // NOTE: This is just an explicit extra precaution. Platform apps are not
+ // supported in incognito mode, so even if we registered for the notification,
+ // the functionality wouldn't ever get activated.
+ // See ChromeContentRendererClient, which initiates the chain of app
+ // invocation for a given URL.
+ // Also see bug 240879, which tracks incognito support for v2 apps.
+ if (!profile->IsOffTheRecord()) {
not at google - send to devlin 2013/08/30 17:07:58 I think you're better off CHECKing here, and makin
sergeygs 2013/09/02 07:36:22 Done. This is harmless anyway, since apps are not
+ // Limit app launching to the originating profile only.
+ registrar_.Add(this,
+ content::NOTIFICATION_HANDLE_URL_IN_BROWSER,
+ content::Source<Profile>(profile));
+ }
+}
+
+PlatformAppRedirector::~PlatformAppRedirector() {
+}
+
+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: {
+ // 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
benwells 2013/08/30 05:41:39 Nit: must what?
sergeygs 2013/09/02 07:36:22 Done.
+ // exists before sending this notification.
+ DCHECK(launched);
+ break;
+ }
+
+ default:
+ NOTREACHED() << "Unexpected notification type.";
+ }
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698