This source file includes following definitions.
- LaunchEphemeralApp
- MaybeCreateThrottleForLaunch
#include "chrome/browser/apps/ephemeral_app_throttle.h"
#include "base/command_line.h"
#include "chrome/browser/apps/ephemeral_app_launcher.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "components/navigation_interception/intercept_navigation_resource_throttle.h"
#include "components/navigation_interception/navigation_params.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_throttle.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_system.h"
#include "net/url_request/url_request.h"
using content::BrowserThread;
using content::WebContents;
using extensions::Extension;
namespace {
bool LaunchEphemeralApp(
const std::string& app_id,
content::WebContents* source,
const navigation_interception::NavigationParams& params) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (source->IsSubframe())
return false;
Profile* profile =
Profile::FromBrowserContext(source->GetBrowserContext());
if (!profile)
return false;
ExtensionService* service =
extensions::ExtensionSystem::Get(profile)->extension_service();
DCHECK(service);
const Extension* extension = service->GetInstalledExtension(app_id);
if (extension && !extension->is_app())
return false;
scoped_refptr<EphemeralAppLauncher> installer =
EphemeralAppLauncher::CreateForLink(app_id, source);
installer->Start();
return true;
}
}
content::ResourceThrottle*
EphemeralAppThrottle::MaybeCreateThrottleForLaunch(
net::URLRequest* request,
ProfileIOData* profile_io_data) {
if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableLinkableEphemeralApps))
return NULL;
if (request->method() != "GET" || !request->url().SchemeIsHTTPOrHTTPS())
return NULL;
if (profile_io_data->IsOffTheRecord())
return NULL;
if (request->referrer().find("https://www.google.com") == std::string::npos)
return NULL;
if (request->url().spec().find(
extension_urls::GetWebstoreItemDetailURLPrefix()) != 0)
return NULL;
std::string app_id(request->url().ExtractFileName());
if (!Extension::IdIsValid(app_id))
return NULL;
return new navigation_interception::InterceptNavigationResourceThrottle(
request,
base::Bind(&LaunchEphemeralApp, app_id));
}