Chromium Code Reviews| OLD | NEW |
|---|---|
| (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" | |
| 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( | |
|
benwells
2013/09/03 01:10:56
This is called from browser_navigator, and maybe o
sergeygs
2013/09/03 06:15:24
Done, return false in incognito now. This is just
| |
| 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 ExtensionService* service = | |
| 50 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 51 if (!service) | |
| 52 return false; | |
| 53 | |
| 54 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | |
| 55 iter != service->extensions()->end(); | |
| 56 ++iter) { | |
| 57 const extensions::UrlHandlerInfo* handler = | |
| 58 extensions::UrlHandlers::FindMatchingUrlHandler(*iter, url); | |
| 59 if (handler) { | |
| 60 LaunchPlatformAppWithUrl(profile, *iter, handler->id, url, referrer_url); | |
| 61 return true; | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 bool UrlRedirector::OnMessageReceived(const IPC::Message& message) { | |
| 69 bool handled = true; | |
| 70 IPC_BEGIN_MESSAGE_MAP(UrlRedirector, message) | |
| 71 IPC_MESSAGE_HANDLER(ExtensionHostMsg_RedirectUrl, | |
| 72 LaunchAppWithUrl) | |
| 73 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 74 IPC_END_MESSAGE_MAP() | |
| 75 return handled; | |
| 76 } | |
| 77 | |
| 78 void UrlRedirector::LaunchAppWithUrl(const GURL& url, | |
| 79 const GURL& referrer_url) const { | |
| 80 MaybeLaunchAppWithUrl(profile_, url, referrer_url); | |
|
benwells
2013/09/03 01:10:56
Just going by the names, I'm assuming if LaunchApp
sergeygs
2013/09/03 06:15:24
Done. Indeed, the sender should send the IPC only
| |
| 81 } | |
| 82 | |
| 83 } // namespace apps | |
| OLD | NEW |