diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.cc b/atom/browser/atom_resource_dispatcher_host_delegate.cc index 7ee1df4a8d..aa65203caf 100644 --- a/atom/browser/atom_resource_dispatcher_host_delegate.cc +++ b/atom/browser/atom_resource_dispatcher_host_delegate.cc @@ -7,8 +7,8 @@ #include "atom/browser/atom_browser_context.h" #include "atom/browser/login_handler.h" #include "atom/browser/stream_manager.h" -#include "atom/browser/ui/webui/pdf_viewer_ui.h" #include "atom/browser/web_contents_permission_helper.h" +#include "atom/common/atom_constants.h" #include "atom/common/platform_util.h" #include "base/guid.h" #include "base/strings/stringprintf.h" @@ -81,8 +81,8 @@ void OnPdfStreamCreated( stream_manager->AddStream(std::move(stream), view_id, render_process_id, render_frame_id); content::NavigationController::LoadURLParams params(GURL(base::StringPrintf( - "%sindex.html?%s=%s&%s=%s", PdfViewerUI::kOrigin, PdfViewerUI::kId, - view_id.c_str(), PdfViewerUI::kSrc, original_url.spec().c_str()))); + "%sindex.html?%s=%s&%s=%s", kPdfViewerUIOrigin, kPdfViewerUIId, + view_id.c_str(), kPdfPluginSrc, original_url.spec().c_str()))); web_contents->GetController().LoadURLWithParams(params); } @@ -131,7 +131,7 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( GURL* origin, std::string* payload) { if (mime_type == "application/pdf") { - *origin = GURL(PdfViewerUI::kOrigin); + *origin = GURL(kPdfViewerUIOrigin); return true; } return false; diff --git a/atom/browser/atom_web_ui_controller_factory.cc b/atom/browser/atom_web_ui_controller_factory.cc index b945ae02f2..0172a3c4c7 100644 --- a/atom/browser/atom_web_ui_controller_factory.cc +++ b/atom/browser/atom_web_ui_controller_factory.cc @@ -7,6 +7,7 @@ #include #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" @@ -25,7 +26,7 @@ AtomWebUIControllerFactory::~AtomWebUIControllerFactory() {} content::WebUI::TypeID AtomWebUIControllerFactory::GetWebUIType( content::BrowserContext* browser_context, const GURL& url) const { - if (url.host() == PdfViewerUI::kHost) { + if (url.host() == kPdfViewerUIHost) { return const_cast(this); } @@ -47,14 +48,14 @@ bool AtomWebUIControllerFactory::UseWebUIBindingsForURL( content::WebUIController* AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui, const GURL& url) const { - if (url.host() == PdfViewerUI::kHost) { + if (url.host() == kPdfViewerUIHost) { base::StringPairs toplevel_params; base::SplitStringIntoKeyValuePairs(url.query(), '=', '&', &toplevel_params); std::string view_id, src; for (const auto& param : toplevel_params) { - if (param.first == PdfViewerUI::kId) { + if (param.first == kPdfViewerUIId) { view_id = param.second; - } else if (param.first == PdfViewerUI::kSrc) { + } else if (param.first == kPdfPluginSrc) { src = param.second; } } diff --git a/atom/browser/ui/webui/pdf_viewer_handler.cc b/atom/browser/ui/webui/pdf_viewer_handler.cc index 37b18de39e..6c86173043 100644 --- a/atom/browser/ui/webui/pdf_viewer_handler.cc +++ b/atom/browser/ui/webui/pdf_viewer_handler.cc @@ -4,6 +4,7 @@ #include "atom/browser/ui/webui/pdf_viewer_handler.h" +#include "atom/common/atom_constants.h" #include "base/bind.h" #include "base/values.h" #include "content/public/browser/stream_handle.h" @@ -11,6 +12,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" #include "content/public/common/page_zoom.h" +#include "content/public/common/url_constants.h" #include "net/http/http_response_headers.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/webui/web_ui_util.h" @@ -145,7 +147,6 @@ void PdfViewerHandler::GetStrings(const base::ListValue* args) { SET_STRING("labelPageNumber", "Page number"); SET_STRING("tooltipRotateCW", "Rotate clockwise"); SET_STRING("tooltipDownload", "Download"); - SET_STRING("tooltipPrint", "Print"); SET_STRING("tooltipFitToPage", "Fit to page"); SET_STRING("tooltipFitToWidth", "Fit to width"); SET_STRING("tooltipZoomIn", "Zoom in"); @@ -161,7 +162,8 @@ void PdfViewerHandler::OnZoomLevelChanged( const content::HostZoomMap::ZoomLevelChange& change) { // TODO(deepak1556): This will work only if zoom level is changed through host // zoom map. - if (change.scheme == "chrome" && change.host == "pdf-viewer") { + if (change.scheme == content::kChromeUIScheme && + change.host == kPdfViewerUIHost) { CallJavascriptFunction( "cr.webUIListenerCallback", base::StringValue("onZoomLevelChanged"), base::FundamentalValue( diff --git a/atom/browser/ui/webui/pdf_viewer_ui.cc b/atom/browser/ui/webui/pdf_viewer_ui.cc index 0c642a28ee..029a8e6dfb 100644 --- a/atom/browser/ui/webui/pdf_viewer_ui.cc +++ b/atom/browser/ui/webui/pdf_viewer_ui.cc @@ -9,6 +9,7 @@ #include "atom/browser/atom_browser_context.h" #include "atom/browser/stream_manager.h" #include "atom/browser/ui/webui/pdf_viewer_handler.h" +#include "atom/common/atom_constants.h" #include "components/pdf/common/pdf_messages.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/url_data_source.h" @@ -23,7 +24,7 @@ namespace atom { namespace { std::string PathWithoutParams(const std::string& path) { - return GURL(PdfViewerUI::kOrigin + path).path().substr(1); + return GURL(kPdfViewerUIOrigin + path).path().substr(1); } class BundledDataSource : public content::URLDataSource { @@ -41,7 +42,7 @@ class BundledDataSource : public content::URLDataSource { } // content::URLDataSource implementation. - std::string GetSource() const override { return PdfViewerUI::kHost; } + std::string GetSource() const override { return kPdfViewerUIHost; } void StartDataRequest(const std::string& path, int render_process_id, @@ -83,11 +84,6 @@ class BundledDataSource : public content::URLDataSource { } // namespace -const char PdfViewerUI::kOrigin[] = "chrome://pdf-viewer/"; -const char PdfViewerUI::kHost[] = "pdf-viewer"; -const char PdfViewerUI::kId[] = "viewId"; -const char PdfViewerUI::kSrc[] = "src"; - PdfViewerUI::PdfViewerUI(content::BrowserContext* browser_context, content::WebUI* web_ui, const std::string& view_id, diff --git a/atom/browser/ui/webui/pdf_viewer_ui.h b/atom/browser/ui/webui/pdf_viewer_ui.h index d81e12d69b..02a1f01af5 100644 --- a/atom/browser/ui/webui/pdf_viewer_ui.h +++ b/atom/browser/ui/webui/pdf_viewer_ui.h @@ -22,11 +22,6 @@ namespace atom { class PdfViewerUI : public content::WebUIController, public content::WebContentsObserver { public: - static const char kOrigin[]; - static const char kHost[]; - static const char kId[]; - static const char kSrc[]; - PdfViewerUI(content::BrowserContext* browser_context, content::WebUI* web_ui, const std::string& view_id, diff --git a/atom/common/atom_constants.cc b/atom/common/atom_constants.cc index e8a7c2f7aa..42f0d0031a 100644 --- a/atom/common/atom_constants.cc +++ b/atom/common/atom_constants.cc @@ -26,5 +26,10 @@ const char kSecureProtocolDescription[] = const char kPdfPluginMimeType[] = "application/x-google-chrome-pdf"; const char kPdfPluginPath[] = "chrome://pdf-viewer/"; +const char kPdfPluginSrc[] = "src"; + +const char kPdfViewerUIOrigin[] = "chrome://pdf-viewer/"; +const char kPdfViewerUIHost[] = "pdf-viewer"; +const char kPdfViewerUIId[] = "viewId"; } // namespace atom diff --git a/atom/common/atom_constants.h b/atom/common/atom_constants.h index 24186cf92c..ddd27d87ac 100644 --- a/atom/common/atom_constants.h +++ b/atom/common/atom_constants.h @@ -23,6 +23,12 @@ extern const char kSecureProtocolDescription[]; // The MIME type used for the PDF plugin. extern const char kPdfPluginMimeType[]; extern const char kPdfPluginPath[]; +extern const char kPdfPluginSrc[]; + +// Constants for PDF viewer webui. +extern const char kPdfViewerUIOrigin[]; +extern const char kPdfViewerUIHost[]; +extern const char kPdfViewerUIId[]; } // namespace atom