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

@ -14,8 +14,8 @@
#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"
@ -35,8 +35,7 @@ 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)
@ -66,55 +65,52 @@ void HandleExternalProtocolInUI(
} }
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(); params.frame_tree_node_id = frame_host->GetFrameTreeNodeId();
web_contents->GetController().LoadURLWithParams(params); web_contents->GetController().LoadURLWithParams(params);
} }
} // namespace } // namespace
AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() { AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() {}
}
bool AtomResourceDispatcherHostDelegate::HandleExternalProtocol( bool AtomResourceDispatcherHostDelegate::HandleExternalProtocol(
const GURL& url, const GURL& url,
content::ResourceRequestInfo* info) { content::ResourceRequestInfo* info) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&HandleExternalProtocolInUI, base::Bind(&HandleExternalProtocolInUI, url,
url,
info->GetWebContentsGetterForRequest(), info->GetWebContentsGetterForRequest(),
info->HasUserGesture())); info->HasUserGesture()));
return true; return true;
@ -130,43 +126,44 @@ AtomResourceDispatcherHostDelegate::CreateLoginDelegate(
std::unique_ptr<net::ClientCertStore> std::unique_ptr<net::ClientCertStore>
AtomResourceDispatcherHostDelegate::CreateClientCertStore( AtomResourceDispatcherHostDelegate::CreateClientCertStore(
content::ResourceContext* resource_context) { content::ResourceContext* resource_context) {
#if defined(USE_NSS_CERTS) #if defined(USE_NSS_CERTS)
return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreNSS( return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreNSS(
net::ClientCertStoreNSS::PasswordDelegateFactory())); net::ClientCertStoreNSS::PasswordDelegateFactory()));
#elif defined(OS_WIN) #elif defined(OS_WIN)
return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreWin()); return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreWin());
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreMac()); return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreMac());
#elif defined(USE_OPENSSL) #elif defined(USE_OPENSSL)
return std::unique_ptr<net::ClientCertStore>(); return std::unique_ptr<net::ClientCertStore>();
#endif #endif
} }
bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
net::URLRequest* request, net::URLRequest* request,
const base::FilePath& plugin_path, const base::FilePath& plugin_path,
const std::string& mime_type, const std::string& mime_type,
GURL* origin, GURL* origin,
std::string* payload) { std::string* payload) {
const content::ResourceRequestInfo* info = const content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request); content::ResourceRequestInfo::ForRequest(request);
int render_process_host_id; int render_process_host_id;
int render_frame_id; int render_frame_id;
if (!info->GetAssociatedRenderFrame(&render_process_host_id, &render_frame_id)) if (!info->GetAssociatedRenderFrame(&render_process_host_id,
{ &render_frame_id)) {
return false; return false;
} }
if (mime_type == "application/pdf") { if (mime_type == "application/pdf") {
*origin = GURL(kPdfViewerUIOrigin); *origin = GURL(kPdfViewerUIOrigin);
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(&OnPdfResourceIntercepted, request->url(), base::Bind(&OnPdfResourceIntercepted, request->url(),
render_process_host_id, render_frame_id, info->GetWebContentsGetterForRequest())); render_process_host_id, render_frame_id,
return true; info->GetWebContentsGetterForRequest()));
} return true;
return false; }
return false;
} }
} // namespace atom } // namespace atom