2017-01-21 14:57:29 +00:00
|
|
|
// Copyright (c) 2017 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_UI_WEBUI_PDF_VIEWER_UI_H_
|
|
|
|
#define SHELL_BROWSER_UI_WEBUI_PDF_VIEWER_UI_H_
|
2017-01-21 14:57:29 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
2017-01-21 14:57:29 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "base/macros.h"
|
2017-01-21 19:52:23 +00:00
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
2017-01-21 14:57:29 +00:00
|
|
|
#include "content/public/browser/web_ui_controller.h"
|
2017-01-21 19:52:23 +00:00
|
|
|
#include "ipc/ipc_message.h"
|
2017-01-21 14:57:29 +00:00
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class BrowserContext;
|
2017-01-23 22:49:18 +00:00
|
|
|
struct StreamInfo;
|
2018-04-18 01:44:10 +00:00
|
|
|
} // namespace content
|
2017-01-21 14:57:29 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2017-01-21 14:57:29 +00:00
|
|
|
|
2017-02-27 06:10:49 +00:00
|
|
|
class PdfViewerHandler;
|
|
|
|
|
2017-01-21 19:52:23 +00:00
|
|
|
class PdfViewerUI : public content::WebUIController,
|
2017-02-27 15:01:54 +00:00
|
|
|
public content::WebContentsObserver {
|
2017-01-21 14:57:29 +00:00
|
|
|
public:
|
|
|
|
PdfViewerUI(content::BrowserContext* browser_context,
|
|
|
|
content::WebUI* web_ui,
|
2017-01-23 11:12:39 +00:00
|
|
|
const std::string& src);
|
2017-01-21 19:52:23 +00:00
|
|
|
~PdfViewerUI() override;
|
2017-01-21 14:57:29 +00:00
|
|
|
|
2017-01-21 19:52:23 +00:00
|
|
|
// content::WebContentsObserver:
|
|
|
|
bool OnMessageReceived(const IPC::Message& message,
|
|
|
|
content::RenderFrameHost* render_frame_host) override;
|
2017-02-27 06:10:49 +00:00
|
|
|
void RenderFrameCreated(content::RenderFrameHost* rfh) override;
|
|
|
|
|
2017-01-21 14:57:29 +00:00
|
|
|
private:
|
2017-02-27 15:01:54 +00:00
|
|
|
using StreamResponseCallback =
|
|
|
|
base::OnceCallback<void(std::unique_ptr<content::StreamInfo>)>;
|
|
|
|
class ResourceRequester;
|
|
|
|
|
2017-02-27 06:10:49 +00:00
|
|
|
void OnPdfStreamCreated(std::unique_ptr<content::StreamInfo> stream_info);
|
2017-01-21 19:52:23 +00:00
|
|
|
void OnSaveURLAs(const GURL& url, const content::Referrer& referrer);
|
|
|
|
|
2017-02-03 10:16:23 +00:00
|
|
|
// Source URL from where the PDF originates.
|
2017-01-23 11:12:39 +00:00
|
|
|
std::string src_;
|
2017-02-27 06:10:49 +00:00
|
|
|
|
|
|
|
PdfViewerHandler* pdf_handler_;
|
|
|
|
|
2017-02-27 15:01:54 +00:00
|
|
|
scoped_refptr<ResourceRequester> resource_requester_;
|
|
|
|
|
2017-02-27 06:10:49 +00:00
|
|
|
// Pdf Resource stream.
|
2017-01-23 11:12:39 +00:00
|
|
|
std::unique_ptr<content::StreamInfo> stream_;
|
|
|
|
|
2017-01-21 14:57:29 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(PdfViewerUI);
|
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2017-01-21 14:57:29 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_UI_WEBUI_PDF_VIEWER_UI_H_
|