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

Unified Diff: chrome/browser/apps/app_url_redirector.cc

Issue 23847004: "Redirecting URLs to Packaged Apps" implementation: revised (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed an editing error Created 7 years, 3 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/apps/app_url_redirector.cc
diff --git a/chrome/browser/apps/app_url_redirector.cc b/chrome/browser/apps/app_url_redirector.cc
new file mode 100644
index 0000000000000000000000000000000000000000..de593ac6eda06b04a270843a8c966c22fabcd2d1
--- /dev/null
+++ b/chrome/browser/apps/app_url_redirector.cc
@@ -0,0 +1,80 @@
+// Copyright 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/apps/app_url_redirector.h"
+
+#include "apps/launcher.h"
+#include "base/logging.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h"
+#include "chrome/common/extensions/extension_messages.h"
+#include "chrome/common/extensions/extension_set.h"
+#include "ipc/ipc_message.h"
+#include "ipc/ipc_message_macros.h"
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(AppUrlRedirector);
+
+AppUrlRedirector::AppUrlRedirector(content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents),
+ profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) {
+ // We don't want to ever send visited URLs to apps in incognito. Technically,
+ // apps are not supported in incognito, but explicitly check for that.
+ // See b/240879, which tracks incognito support for v2 apps.
+ CHECK(!profile_->IsOffTheRecord());
+}
+
+AppUrlRedirector::~AppUrlRedirector() {
+}
+
+// static
not at google - send to devlin 2013/09/04 15:37:21 See comment at caller in the other file (can't rem
sergeygs 2013/09/05 09:19:03 Obsolete.
+bool AppUrlRedirector::MaybeLaunchAppWithUrl(
+ Profile* profile,
+ const GURL& url,
+ const GURL& referrer_url) {
+ // Even with the about CHECK in the constructor, this method still can be
+ // invoked in icognito, since it is static. Handle that here just in case.
+ if (profile->IsOffTheRecord())
+ return false;
+
+ ExtensionService* service =
+ extensions::ExtensionSystem::Get(profile)->extension_service();
+ if (!service)
not at google - send to devlin 2013/09/04 15:37:21 I wish this check wasn't necessary and that we can
sergeygs 2013/09/05 09:19:03 Obsolete.
+ return false;
+
+ for (ExtensionSet::const_iterator iter = service->extensions()->begin();
+ iter != service->extensions()->end();
+ ++iter) {
+ const extensions::UrlHandlerInfo* handler =
+ extensions::UrlHandlers::FindMatchingUrlHandler(*iter, url);
+ if (handler) {
+ apps::LaunchPlatformAppWithUrl(
+ profile, *iter, handler->id, url, referrer_url);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool AppUrlRedirector::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(AppUrlRedirector, message)
+ IPC_MESSAGE_HANDLER(ExtensionHostMsg_RedirectUrl,
+ LaunchAppWithUrl)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void AppUrlRedirector::LaunchAppWithUrl(const GURL& url,
+ const GURL& referrer_url) const {
+ // This is a ExtensionHostMsg_RedirectUrl handler. The sender is expected
+ // to check that an appropriate app to handle |url| indeed exists, so
not at google - send to devlin 2013/09/04 15:37:21 s/indeed //
sergeygs 2013/09/05 09:19:03 Obsolete.
+ // the launch here should always succeed.
+ // See ChromeContentRendererClient::HandleNavigation for an example.
+ const bool launched = MaybeLaunchAppWithUrl(profile_, url, referrer_url);
+ DCHECK(launched);
+}

Powered by Google App Engine
This is Rietveld 408576698