code cleanup

This commit is contained in:
deepak1556 2017-01-22 20:23:42 +05:30
parent de7dcdedba
commit ddc2e0df71
8 changed files with 14 additions and 16 deletions

View file

@ -7,6 +7,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "atom/browser/ui/webui/pdf_viewer_ui.h"
#include "atom/common/atom_version.h" #include "atom/common/atom_version.h"
#include "atom/common/chrome_version.h" #include "atom/common/chrome_version.h"
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
@ -115,7 +116,7 @@ void ComputeBuiltInPlugins(std::vector<content::PepperPluginInfo>* plugins) {
pdf_info.is_out_of_process = true; pdf_info.is_out_of_process = true;
pdf_info.name = "Chromium PDF Viewer"; pdf_info.name = "Chromium PDF Viewer";
pdf_info.description = "Portable Document Format"; pdf_info.description = "Portable Document Format";
pdf_info.path = base::FilePath::FromUTF8Unsafe("internal-pdf-viewer"); pdf_info.path = base::FilePath::FromUTF8Unsafe(PdfViewerUI::kOrigin);
content::WebPluginMimeType pdf_mime_type("application/x-google-chrome-pdf", content::WebPluginMimeType pdf_mime_type("application/x-google-chrome-pdf",
"pdf", "Portable Document Format"); "pdf", "Portable Document Format");
pdf_info.mime_types.push_back(pdf_mime_type); pdf_info.mime_types.push_back(pdf_mime_type);

View file

@ -7,6 +7,7 @@
#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/stream_manager.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/browser/web_contents_permission_helper.h"
#include "atom/common/platform_util.h" #include "atom/common/platform_util.h"
#include "base/guid.h" #include "base/guid.h"
@ -78,8 +79,9 @@ void OnPdfStreamCreated(
std::string view_id = base::GenerateGUID(); std::string view_id = base::GenerateGUID();
stream_manager->AddStream(std::move(stream), view_id, render_process_id, stream_manager->AddStream(std::move(stream), view_id, render_process_id,
render_frame_id); render_frame_id);
content::NavigationController::LoadURLParams params(GURL(base::StringPrintf( content::NavigationController::LoadURLParams params(
"chrome://pdf-viewer/index.html?viewId=%s", view_id.c_str()))); GURL(base::StringPrintf("%sindex.html?%s=%s", PdfViewerUI::kOrigin,
PdfViewerUI::kId, view_id.c_str())));
web_contents->GetController().LoadURLWithParams(params); web_contents->GetController().LoadURLWithParams(params);
} }
@ -128,7 +130,7 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
GURL* origin, GURL* origin,
std::string* payload) { std::string* payload) {
if (mime_type == "application/pdf") { if (mime_type == "application/pdf") {
*origin = GURL("chrome://pdf-viewer/"); *origin = GURL(PdfViewerUI::kOrigin);
return true; return true;
} }
return false; return false;

View file

@ -52,7 +52,7 @@ AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
base::SplitStringIntoKeyValuePairs(url.query(), '=', '&', &toplevel_params); base::SplitStringIntoKeyValuePairs(url.query(), '=', '&', &toplevel_params);
std::string view_id; std::string view_id;
for (const auto& param : toplevel_params) { for (const auto& param : toplevel_params) {
if (param.first == "viewId") { if (param.first == PdfViewerUI::kId) {
view_id = param.second; view_id = param.second;
break; break;
} }

View file

@ -48,8 +48,6 @@ class StreamManager {
StreamManager* stream_manager_; StreamManager* stream_manager_;
std::string view_id_; std::string view_id_;
int render_process_id_;
int render_frame_id_;
DISALLOW_COPY_AND_ASSIGN(EmbedderObserver); DISALLOW_COPY_AND_ASSIGN(EmbedderObserver);
}; };

View file

@ -21,7 +21,7 @@ namespace atom {
namespace { namespace {
std::string PathWithoutParams(const std::string& path) { std::string PathWithoutParams(const std::string& path) {
return GURL(std::string("chrome://pdf-viewer/") + path).path().substr(1); return GURL(PdfViewerUI::kOrigin + path).path().substr(1);
} }
class BundledDataSource : public content::URLDataSource { class BundledDataSource : public content::URLDataSource {
@ -79,7 +79,9 @@ class BundledDataSource : public content::URLDataSource {
} // namespace } // namespace
const char PdfViewerUI::kOrigin[] = "chrome://pdf-viewer/";
const char PdfViewerUI::kHost[] = "pdf-viewer"; const char PdfViewerUI::kHost[] = "pdf-viewer";
const char PdfViewerUI::kId[] = "viewId";
PdfViewerUI::PdfViewerUI(content::BrowserContext* browser_context, PdfViewerUI::PdfViewerUI(content::BrowserContext* browser_context,
content::WebUI* web_ui, content::WebUI* web_ui,

View file

@ -21,7 +21,9 @@ namespace atom {
class PdfViewerUI : public content::WebUIController, class PdfViewerUI : public content::WebUIController,
public content::WebContentsObserver { public content::WebContentsObserver {
public: public:
static const char kOrigin[];
static const char kHost[]; static const char kHost[];
static const char kId[];
PdfViewerUI(content::BrowserContext* browser_context, PdfViewerUI(content::BrowserContext* browser_context,
content::WebUI* web_ui, content::WebUI* web_ui,

View file

@ -13,13 +13,6 @@
#define IPC_MESSAGE_START PDFMsgStart #define IPC_MESSAGE_START PDFMsgStart
// Updates the content restrictions, i.e. to disable print/copy.
IPC_MESSAGE_ROUTED1(PDFHostMsg_PDFUpdateContentRestrictions,
int /* restrictions */)
// The currently displayed PDF has an unsupported feature.
IPC_MESSAGE_ROUTED0(PDFHostMsg_PDFHasUnsupportedFeature)
// Brings up SaveAs... dialog to save specified URL. // Brings up SaveAs... dialog to save specified URL.
IPC_MESSAGE_ROUTED2(PDFHostMsg_PDFSaveURLAs, IPC_MESSAGE_ROUTED2(PDFHostMsg_PDFSaveURLAs,
GURL /* url */, GURL /* url */,

2
vendor/pdf_viewer vendored

@ -1 +1 @@
Subproject commit bdc199ef4f310b710a1abaade293ee8763230438 Subproject commit c2c521dc2769a6a6917d246fce2af353ec7e5ede