move pdf viewer behind feature flag

This commit is contained in:
deepak1556 2018-03-15 17:51:48 +09:00 committed by Aleksei Kuzmin
parent c1908147a9
commit 4b39d17e5f
21 changed files with 159 additions and 63 deletions

View file

@ -9,7 +9,6 @@
#include "atom/browser/atom_access_token_store.h"
#include "atom/browser/atom_browser_client.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_web_ui_controller_factory.h"
#include "atom/browser/bridge_task_runner.h"
#include "atom/browser/browser.h"
#include "atom/browser/javascript_environment.h"
@ -33,6 +32,10 @@
#include "ui/events/devices/x11/touch_factory_x11.h"
#endif
#if defined(ENABLE_PDF_VIEWER)
#include "atom/browser/atom_web_ui_controller_factory.h"
#endif // defined(ENABLE_PDF_VIEWER)
namespace atom {
namespace {
@ -186,8 +189,10 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {
base::Bind(&v8::Isolate::LowMemoryNotification,
base::Unretained(js_env_->isolate())));
#if defined(ENABLE_PDF_VIEWER)
content::WebUIControllerFactory::RegisterFactory(
AtomWebUIControllerFactory::GetInstance());
#endif // defined(ENABLE_PDF_VIEWER)
brightray::BrowserMainParts::PreMainMessageLoopRun();
bridge_task_runner_->MessageLoopIsReady();

View file

@ -8,17 +8,13 @@
#include "atom/browser/login_handler.h"
#include "atom/browser/web_contents_permission_helper.h"
#include "atom/browser/web_contents_preferences.h"
#include "atom/common/atom_constants.h"
#include "atom/common/platform_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/stream_info.h"
#include "net/base/escape.h"
#include "net/ssl/client_cert_store.h"
#include "net/url_request/url_request.h"
#include "url/gurl.h"
#if defined(USE_NSS_CERTS)
@ -29,6 +25,14 @@
#include "net/ssl/client_cert_store_mac.h"
#endif
#if defined(ENABLE_PDF_VIEWER)
#include "atom/common/atom_constants.h"
#include "base/strings/stringprintf.h"
#include "content/public/browser/stream_info.h"
#include "net/url_request/url_request.h"
#endif // defined(ENABLE_PDF_VIEWER)
using content::BrowserThread;
namespace atom {
@ -65,6 +69,7 @@ void HandleExternalProtocolInUI(
url);
}
#if defined(ENABLE_PDF_VIEWER)
void OnPdfResourceIntercepted(
const GURL& original_url,
int render_process_host_id,
@ -102,6 +107,7 @@ void OnPdfResourceIntercepted(
params.frame_tree_node_id = frame_host->GetFrameTreeNodeId();
web_contents->GetController().LoadURLWithParams(params);
}
#endif // defined(ENABLE_PDF_VIEWER)
} // namespace
@ -145,6 +151,7 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
const std::string& mime_type,
GURL* origin,
std::string* payload) {
#if defined(ENABLE_PDF_VIEWER)
const content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request);
@ -164,6 +171,7 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
info->GetWebContentsGetterForRequest()));
return true;
}
#endif // defined(ENABLE_PDF_VIEWER)
return false;
}

View file

@ -6,12 +6,14 @@
#include <string>
#if defined(ENABLE_PDF_VIEWER)
#include "atom/browser/ui/webui/pdf_viewer_ui.h"
#include "atom/common/atom_constants.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "content/public/browser/web_contents.h"
#include "net/base/escape.h"
#endif // defined(ENABLE_PDF_VIEWER)
namespace atom {
@ -27,9 +29,11 @@ AtomWebUIControllerFactory::~AtomWebUIControllerFactory() {}
content::WebUI::TypeID AtomWebUIControllerFactory::GetWebUIType(
content::BrowserContext* browser_context,
const GURL& url) const {
#if defined(ENABLE_PDF_VIEWER)
if (url.host() == kPdfViewerUIHost) {
return const_cast<AtomWebUIControllerFactory*>(this);
}
#endif // defined(ENABLE_PDF_VIEWER)
return content::WebUI::kNoWebUI;
}
@ -49,6 +53,7 @@ bool AtomWebUIControllerFactory::UseWebUIBindingsForURL(
content::WebUIController*
AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
const GURL& url) const {
#if defined(ENABLE_PDF_VIEWER)
if (url.host() == kPdfViewerUIHost) {
base::StringPairs toplevel_params;
base::SplitStringIntoKeyValuePairs(url.query(), '=', '&', &toplevel_params);
@ -70,6 +75,7 @@ AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
auto browser_context = web_ui->GetWebContents()->GetBrowserContext();
return new PdfViewerUI(browser_context, web_ui, src);
}
#endif // defined(ENABLE_PDF_VIEWER)
return nullptr;
}

View file

@ -2,6 +2,10 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ENABLE_PDF_VIEWER
#error("This header can only be used when enable_pdf_viewer gyp flag is enabled")
#endif // defined(ENABLE_PDF_VIEWER)
#include "atom/browser/ui/webui/pdf_viewer_handler.h"
#include "atom/common/atom_constants.h"

View file

@ -2,6 +2,10 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ENABLE_PDF_VIEWER
#error("This header can only be used when enable_pdf_viewer gyp flag is enabled")
#endif // defined(ENABLE_PDF_VIEWER)
#ifndef ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_HANDLER_H_
#define ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_HANDLER_H_

View file

@ -2,6 +2,10 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ENABLE_PDF_VIEWER
#error("This header can only be used when enable_pdf_viewer gyp flag is enabled")
#endif // defined(ENABLE_PDF_VIEWER)
#include "atom/browser/ui/webui/pdf_viewer_ui.h"
#include <map>

View file

@ -2,6 +2,10 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ENABLE_PDF_VIEWER
#error("This header can only be used when enable_pdf_viewer gyp flag is enabled")
#endif // defined(ENABLE_PDF_VIEWER)
#ifndef ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_UI_H_
#define ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_UI_H_