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

Side by Side Diff: apps/url_redirector.cc

Issue 23847004: "Redirecting URLs to Packaged Apps" implementation: revised (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed the comment in app_window_contents.cc 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "apps/url_redirector.h"
6
7 #include "apps/launcher.h"
8 #include "base/command_line.h"
9 #include "base/logging.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h"
14 #include "chrome/common/extensions/extension_messages.h"
15 #include "chrome/common/extensions/extension_set.h"
jam 2013/09/03 15:25:16 I'll defer to the apps folks, but it's not obvious
sergeygs 2013/09/03 16:43:04 This class launches v2 apps. chrome/, and even ext
not at google - send to devlin 2013/09/03 17:39:52 Honestly I thought it was the other way around, th
sergeygs 2013/09/04 03:29:17 As discussed offline, you are right. I'm going to
16 #include "extensions/common/switches.h"
17 #include "ipc/ipc_message.h"
18 #include "ipc/ipc_message_macros.h"
19
20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(apps::UrlRedirector);
21
22 namespace apps {
23
24 UrlRedirector::UrlRedirector(content::WebContents* web_contents)
25 : content::WebContentsObserver(web_contents),
26 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) {
27 // We don't want to ever send visited URLs to apps in incognito. Technically,
28 // apps are not supported in incognito, but explicitly check for that.
29 // See b/240879, which tracks incognito support for v2 apps.
30 CHECK(!profile_->IsOffTheRecord());
31 }
32
33 UrlRedirector::~UrlRedirector() {
34 }
35
36 // static
37 bool UrlRedirector::MaybeLaunchAppWithUrl(
38 Profile* profile,
39 const GURL& url,
40 const GURL& referrer_url) {
41 // This should never happen unless the switch is specified; if it's not,
42 // originators of the invocation chain should not call us
43 // (ChromeContentRenderClient::HandleNavigation, chrome::Navigate).
44 // TODO(sergeygs): Remove this and update includes once url_handlers are
45 // moved out of experimental.
46 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
47 extensions::switches::kEnableExperimentalExtensionApis));
48
49 // Even with the about CHECK in the constructor, this method still can be
50 // invoked in icognito, since it is static. Handle that here just in case.
51 if (profile->IsOffTheRecord())
52 return false;
53
54 ExtensionService* service =
55 extensions::ExtensionSystem::Get(profile)->extension_service();
56 if (!service)
57 return false;
58
59 for (ExtensionSet::const_iterator iter = service->extensions()->begin();
60 iter != service->extensions()->end();
61 ++iter) {
62 const extensions::UrlHandlerInfo* handler =
63 extensions::UrlHandlers::FindMatchingUrlHandler(*iter, url);
64 if (handler) {
65 LaunchPlatformAppWithUrl(profile, *iter, handler->id, url, referrer_url);
66 return true;
67 }
68 }
69
70 return false;
71 }
72
73 bool UrlRedirector::OnMessageReceived(const IPC::Message& message) {
74 bool handled = true;
75 IPC_BEGIN_MESSAGE_MAP(UrlRedirector, message)
76 IPC_MESSAGE_HANDLER(ExtensionHostMsg_RedirectUrl,
77 LaunchAppWithUrl)
78 IPC_MESSAGE_UNHANDLED(handled = false)
79 IPC_END_MESSAGE_MAP()
80 return handled;
81 }
82
83 void UrlRedirector::LaunchAppWithUrl(const GURL& url,
84 const GURL& referrer_url) const {
85 // This is a ExtensionHostMsg_RedirectUrl handler. The sender is expected
86 // to check that an appropriate app to handle |url| indeed exists, so
87 // the launch here should always succeed.
88 // See ChromeContentRendererClient::HandleNavigation for an example.
89 const bool launched = MaybeLaunchAppWithUrl(profile_, url, referrer_url);
90 DCHECK(launched);
91 }
92
93 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698