|
@@ -5,6 +5,7 @@
|
|
|
#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
|
|
|
|
|
|
#include "atom/browser/login_handler.h"
|
|
|
+#include "atom/browser/web_contents_permission_helper.h"
|
|
|
#include "atom/common/platform_util.h"
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
#include "net/base/escape.h"
|
|
@@ -14,20 +15,46 @@ using content::BrowserThread;
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
+namespace {
|
|
|
+
|
|
|
+void OnOpenExternal(const GURL& escaped_url,
|
|
|
+ bool allowed) {
|
|
|
+ if (allowed)
|
|
|
+ platform_util::OpenExternal(escaped_url, true);
|
|
|
+}
|
|
|
+
|
|
|
+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;
|
|
|
+
|
|
|
+ GURL escaped_url(net::EscapeExternalHandlerValue(url.spec()));
|
|
|
+ auto callback = base::Bind(&OnOpenExternal, escaped_url);
|
|
|
+ auto permission_helper =
|
|
|
+ WebContentsPermissionHelper::FromWebContents(web_contents);
|
|
|
+ permission_helper->RequestOpenExternalPermission(callback, has_user_gesture);
|
|
|
+}
|
|
|
+
|
|
|
+} // namespace
|
|
|
+
|
|
|
AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() {
|
|
|
}
|
|
|
|
|
|
bool AtomResourceDispatcherHostDelegate::HandleExternalProtocol(
|
|
|
const GURL& url,
|
|
|
int child_id,
|
|
|
- const content::ResourceRequestInfo::WebContentsGetter&,
|
|
|
+ const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
|
|
|
bool is_main_frame,
|
|
|
ui::PageTransition transition,
|
|
|
bool has_user_gesture) {
|
|
|
- GURL escaped_url(net::EscapeExternalHandlerValue(url.spec()));
|
|
|
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
|
|
- base::Bind(
|
|
|
- base::IgnoreResult(platform_util::OpenExternal), escaped_url, true));
|
|
|
+ base::Bind(&HandleExternalProtocolInUI,
|
|
|
+ url,
|
|
|
+ web_contents_getter,
|
|
|
+ has_user_gesture));
|
|
|
return true;
|
|
|
}
|
|
|
|