2015-09-30 02:56:42 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
|
|
|
|
|
2015-10-28 07:34:41 +00:00
|
|
|
#include "atom/browser/login_handler.h"
|
2016-04-20 16:55:15 +00:00
|
|
|
#include "atom/browser/web_contents_permission_helper.h"
|
2015-09-30 02:56:42 +00:00
|
|
|
#include "atom/common/platform_util.h"
|
2016-07-11 08:11:05 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2015-09-30 02:56:42 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "net/base/escape.h"
|
|
|
|
#include "url/gurl.h"
|
|
|
|
|
|
|
|
using content::BrowserThread;
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2016-04-20 16:55:15 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void OnOpenExternal(const GURL& escaped_url,
|
|
|
|
bool allowed) {
|
|
|
|
if (allowed)
|
2016-07-11 08:11:05 +00:00
|
|
|
platform_util::OpenExternal(
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
base::UTF8ToUTF16(escaped_url.spec()),
|
|
|
|
#else
|
|
|
|
escaped_url,
|
|
|
|
#endif
|
|
|
|
true);
|
2016-04-20 16:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HandleExternalProtocolInUI(
|
|
|
|
const GURL& url,
|
|
|
|
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
|
|
|
|
bool has_user_gesture) {
|
|
|
|
content::WebContents* web_contents = web_contents_getter.Run();
|
|
|
|
if (!web_contents)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto permission_helper =
|
|
|
|
WebContentsPermissionHelper::FromWebContents(web_contents);
|
2016-06-08 12:34:03 +00:00
|
|
|
if (!permission_helper)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GURL escaped_url(net::EscapeExternalHandlerValue(url.spec()));
|
|
|
|
auto callback = base::Bind(&OnOpenExternal, escaped_url);
|
2016-04-20 16:55:15 +00:00
|
|
|
permission_helper->RequestOpenExternalPermission(callback, has_user_gesture);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-09-30 02:56:42 +00:00
|
|
|
AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AtomResourceDispatcherHostDelegate::HandleExternalProtocol(
|
|
|
|
const GURL& url,
|
2016-03-08 14:28:53 +00:00
|
|
|
int child_id,
|
2016-04-20 16:55:15 +00:00
|
|
|
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
|
2015-09-30 02:56:42 +00:00
|
|
|
bool is_main_frame,
|
|
|
|
ui::PageTransition transition,
|
|
|
|
bool has_user_gesture) {
|
|
|
|
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
2016-04-20 16:55:15 +00:00
|
|
|
base::Bind(&HandleExternalProtocolInUI,
|
|
|
|
url,
|
|
|
|
web_contents_getter,
|
|
|
|
has_user_gesture));
|
2015-09-30 02:56:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-28 07:34:41 +00:00
|
|
|
content::ResourceDispatcherHostLoginDelegate*
|
|
|
|
AtomResourceDispatcherHostDelegate::CreateLoginDelegate(
|
|
|
|
net::AuthChallengeInfo* auth_info,
|
|
|
|
net::URLRequest* request) {
|
|
|
|
return new LoginHandler(auth_info, request);
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:56:42 +00:00
|
|
|
} // namespace atom
|