Fixing coding style

This commit is contained in:
Ahmed Mohamed Ali 2017-10-14 11:17:52 +02:00
parent 5030db000a
commit 8763e8ee35

View file

@ -1,172 +1,169 @@
// Copyright (c) 2015 GitHub, Inc. // Copyright (c) 2015 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be // Use of this source code is governed by the MIT license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "atom/browser/atom_resource_dispatcher_host_delegate.h" #include "atom/browser/atom_resource_dispatcher_host_delegate.h"
#include "atom/browser/atom_browser_context.h" #include "atom/browser/atom_browser_context.h"
#include "atom/browser/login_handler.h" #include "atom/browser/login_handler.h"
#include "atom/browser/web_contents_permission_helper.h" #include "atom/browser/web_contents_permission_helper.h"
#include "atom/browser/web_contents_preferences.h" #include "atom/browser/web_contents_preferences.h"
#include "atom/common/atom_constants.h" #include "atom/common/atom_constants.h"
#include "atom/common/platform_util.h" #include "atom/common/platform_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h" #include "content/public/browser/download_manager.h"
#include "content/public/browser/stream_info.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/stream_info.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "net/ssl/client_cert_store.h" #include "net/ssl/client_cert_store.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
#include "url/gurl.h" #include "url/gurl.h"
#if defined(USE_NSS_CERTS) #if defined(USE_NSS_CERTS)
#include "net/ssl/client_cert_store_nss.h" #include "net/ssl/client_cert_store_nss.h"
#elif defined(OS_WIN) #elif defined(OS_WIN)
#include "net/ssl/client_cert_store_win.h" #include "net/ssl/client_cert_store_win.h"
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
#include "net/ssl/client_cert_store_mac.h" #include "net/ssl/client_cert_store_mac.h"
#endif #endif
using content::BrowserThread; using content::BrowserThread;
namespace atom { namespace atom {
namespace { namespace {
void OnOpenExternal(const GURL& escaped_url, void OnOpenExternal(const GURL& escaped_url, bool allowed) {
bool allowed) { if (allowed)
if (allowed) platform_util::OpenExternal(
platform_util::OpenExternal( #if defined(OS_WIN)
#if defined(OS_WIN) base::UTF8ToUTF16(escaped_url.spec()),
base::UTF8ToUTF16(escaped_url.spec()), #else
#else escaped_url,
escaped_url, #endif
#endif true);
true); }
}
void HandleExternalProtocolInUI(
void HandleExternalProtocolInUI( const GURL& url,
const GURL& url, const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, bool has_user_gesture) {
bool has_user_gesture) { content::WebContents* web_contents = web_contents_getter.Run();
content::WebContents* web_contents = web_contents_getter.Run(); if (!web_contents)
if (!web_contents) return;
return;
auto permission_helper =
auto permission_helper = WebContentsPermissionHelper::FromWebContents(web_contents);
WebContentsPermissionHelper::FromWebContents(web_contents); if (!permission_helper)
if (!permission_helper) return;
return;
GURL escaped_url(net::EscapeExternalHandlerValue(url.spec()));
GURL escaped_url(net::EscapeExternalHandlerValue(url.spec())); auto callback = base::Bind(&OnOpenExternal, escaped_url);
auto callback = base::Bind(&OnOpenExternal, escaped_url); permission_helper->RequestOpenExternalPermission(callback, has_user_gesture);
permission_helper->RequestOpenExternalPermission(callback, has_user_gesture); }
}
void OnPdfResourceIntercepted(
void OnPdfResourceIntercepted( const GURL& original_url,
const GURL& original_url, int render_process_host_id,
int render_process_host_id, int render_frame_id,
int render_frame_id, const content::ResourceRequestInfo::WebContentsGetter&
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter) {
web_contents_getter) { content::WebContents* web_contents = web_contents_getter.Run();
content::WebContents* web_contents = web_contents_getter.Run(); if (!web_contents)
if (!web_contents) return;
return;
if (!WebContentsPreferences::IsPluginsEnabled(web_contents)) {
if (!WebContentsPreferences::IsPluginsEnabled(web_contents)) { auto browser_context = web_contents->GetBrowserContext();
auto browser_context = web_contents->GetBrowserContext(); auto download_manager =
auto download_manager = content::BrowserContext::GetDownloadManager(browser_context);
content::BrowserContext::GetDownloadManager(browser_context);
download_manager->DownloadUrl(
download_manager->DownloadUrl( content::DownloadUrlParameters::CreateForWebContentsMainFrame(
content::DownloadUrlParameters::CreateForWebContentsMainFrame( web_contents, original_url));
web_contents, original_url)); return;
return; }
}
// The URL passes the original pdf resource url, that will be requested
// The URL passes the original pdf resource url, that will be requested // by the webui page.
// by the webui page. // chrome://pdf-viewer/index.html?src=https://somepage/123.pdf
// chrome://pdf-viewer/index.html?src=https://somepage/123.pdf content::NavigationController::LoadURLParams params(GURL(base::StringPrintf(
content::NavigationController::LoadURLParams params(GURL(base::StringPrintf( "%sindex.html?%s=%s", kPdfViewerUIOrigin, kPdfPluginSrc,
"%sindex.html?%s=%s", kPdfViewerUIOrigin, kPdfPluginSrc, net::EscapeUrlEncodedData(original_url.spec(), false).c_str())));
net::EscapeUrlEncodedData(original_url.spec(), false).c_str())));
content::RenderFrameHost* frame_host =
content::RenderFrameHost* frame_host = content::RenderFrameHost::FromID(render_process_host_id, render_frame_id);
content::RenderFrameHost::FromID(render_process_host_id, render_frame_id); if (!frame_host) {
if (!frame_host) return;
{ }
return;
} params.frame_tree_node_id = frame_host->GetFrameTreeNodeId();
web_contents->GetController().LoadURLWithParams(params);
params.frame_tree_node_id = frame_host->GetFrameTreeNodeId(); }
web_contents->GetController().LoadURLWithParams(params);
} } // namespace
} // namespace AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() {}
AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() { bool AtomResourceDispatcherHostDelegate::HandleExternalProtocol(
} const GURL& url,
content::ResourceRequestInfo* info) {
bool AtomResourceDispatcherHostDelegate::HandleExternalProtocol( BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
const GURL& url, base::Bind(&HandleExternalProtocolInUI, url,
content::ResourceRequestInfo* info) { info->GetWebContentsGetterForRequest(),
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, info->HasUserGesture()));
base::Bind(&HandleExternalProtocolInUI, return true;
url, }
info->GetWebContentsGetterForRequest(),
info->HasUserGesture())); content::ResourceDispatcherHostLoginDelegate*
return true; AtomResourceDispatcherHostDelegate::CreateLoginDelegate(
} net::AuthChallengeInfo* auth_info,
net::URLRequest* request) {
content::ResourceDispatcherHostLoginDelegate* return new LoginHandler(auth_info, request);
AtomResourceDispatcherHostDelegate::CreateLoginDelegate( }
net::AuthChallengeInfo* auth_info,
net::URLRequest* request) { std::unique_ptr<net::ClientCertStore>
return new LoginHandler(auth_info, request); AtomResourceDispatcherHostDelegate::CreateClientCertStore(
} content::ResourceContext* resource_context) {
#if defined(USE_NSS_CERTS)
std::unique_ptr<net::ClientCertStore> return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreNSS(
AtomResourceDispatcherHostDelegate::CreateClientCertStore( net::ClientCertStoreNSS::PasswordDelegateFactory()));
content::ResourceContext* resource_context) { #elif defined(OS_WIN)
#if defined(USE_NSS_CERTS) return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreWin());
return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreNSS( #elif defined(OS_MACOSX)
net::ClientCertStoreNSS::PasswordDelegateFactory())); return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreMac());
#elif defined(OS_WIN) #elif defined(USE_OPENSSL)
return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreWin()); return std::unique_ptr<net::ClientCertStore>();
#elif defined(OS_MACOSX) #endif
return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreMac()); }
#elif defined(USE_OPENSSL)
return std::unique_ptr<net::ClientCertStore>(); bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
#endif net::URLRequest* request,
} const base::FilePath& plugin_path,
const std::string& mime_type,
bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( GURL* origin,
net::URLRequest* request, std::string* payload) {
const base::FilePath& plugin_path, const content::ResourceRequestInfo* info =
const std::string& mime_type, content::ResourceRequestInfo::ForRequest(request);
GURL* origin,
std::string* payload) { int render_process_host_id;
const content::ResourceRequestInfo* info = int render_frame_id;
content::ResourceRequestInfo::ForRequest(request); if (!info->GetAssociatedRenderFrame(&render_process_host_id,
&render_frame_id)) {
int render_process_host_id; return false;
int render_frame_id; }
if (!info->GetAssociatedRenderFrame(&render_process_host_id, &render_frame_id))
{ if (mime_type == "application/pdf") {
return false; *origin = GURL(kPdfViewerUIOrigin);
} content::BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
if (mime_type == "application/pdf") { base::Bind(&OnPdfResourceIntercepted, request->url(),
*origin = GURL(kPdfViewerUIOrigin); render_process_host_id, render_frame_id,
content::BrowserThread::PostTask( info->GetWebContentsGetterForRequest()));
BrowserThread::UI, FROM_HERE, return true;
base::Bind(&OnPdfResourceIntercepted, request->url(), }
render_process_host_id, render_frame_id, info->GetWebContentsGetterForRequest())); return false;
return true; }
}
return false; } // namespace atom
}
} // namespace atom