Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Unified Diff: components/dom_distiller/content/dom_distiller_viewer_source.cc

Issue 1125343004: Add a "Simplify Page" option to the print preview dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update AUTHORS file to reflect the correct HP name used in the CLA Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/dom_distiller/content/dom_distiller_viewer_source.cc
diff --git a/components/dom_distiller/content/dom_distiller_viewer_source.cc b/components/dom_distiller/content/dom_distiller_viewer_source.cc
index f1ed1a8932e8c4bba3a7ebb1c13d6338ed3de2e3..d4a18d5b1b2aff150792a11f1f950429b55ea5c5 100644
--- a/components/dom_distiller/content/dom_distiller_viewer_source.cc
+++ b/components/dom_distiller/content/dom_distiller_viewer_source.cc
@@ -80,7 +80,7 @@ class DomDistillerViewerSource::RequestViewerHandle
void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) override;
- private:
+ protected:
// Sends JavaScript to the attached Viewer, buffering data if the viewer isn't
// ready.
void SendJavaScript(const std::string& buffer) override;
@@ -189,6 +189,73 @@ void DomDistillerViewerSource::RequestViewerHandle::DidFinishLoad(
buffer_.clear();
}
+class DomDistillerViewerSource::PrintPreviewRequestViewerHandle
cjhopman 2015/05/20 02:00:02 We probably don't want any printpreview-specific s
arjunpatel 2015/05/26 21:40:44 We've been investigating how to remove the print p
+ : public DomDistillerViewerSource::RequestViewerHandle {
+ public:
+ explicit PrintPreviewRequestViewerHandle(
+ content::WebContents* web_contents,
+ const std::string& expected_scheme,
+ const std::string& expected_request_path,
+ scoped_ptr<ContentDataCallback> callback,
+ DistilledPagePrefs* distilled_page_prefs);
+ ~PrintPreviewRequestViewerHandle() override;
+
+ // ViewRequestDelegate implementation:
+ void OnArticleReady(const DistilledArticleProto* article_proto) override;
+ void OnArticleUpdated(ArticleDistillationUpdate article_update) override;
+
+ private:
+ // DistilledPagePrefs::Observer implementation:
+ void OnChangeFontFamily(
+ DistilledPagePrefs::FontFamily new_font_family) override;
+ void OnChangeTheme(DistilledPagePrefs::Theme new_theme) override;
+};
+
+DomDistillerViewerSource::
+ PrintPreviewRequestViewerHandle::PrintPreviewRequestViewerHandle(
+ content::WebContents* web_contents,
+ const std::string& expected_scheme,
+ const std::string& expected_request_path,
+ scoped_ptr<ContentDataCallback> callback,
+ DistilledPagePrefs* distilled_page_prefs)
+ : DomDistillerViewerSource::RequestViewerHandle(
+ web_contents,
+ expected_scheme,
+ expected_request_path,
+ callback.Pass(),
+ distilled_page_prefs) {
+}
+
+DomDistillerViewerSource::
+ PrintPreviewRequestViewerHandle::~PrintPreviewRequestViewerHandle() {
+}
+
+void DomDistillerViewerSource::PrintPreviewRequestViewerHandle::OnArticleReady(
+ const DistilledArticleProto* article_proto) {
+ std::string content = dom_distiller::viewer::GetUnsafePrintPreviewHtml(
+ article_proto,
+ distilled_page_prefs_->GetTheme(),
+ distilled_page_prefs_->GetFontFamily());
+ callback_->RunCallback(content);
+
+ // No need to hold on to the ViewerHandle now that distillation is complete.
+ viewer_handle_.reset();
+}
+
+void DomDistillerViewerSource::
+ PrintPreviewRequestViewerHandle::OnArticleUpdated(
+ ArticleDistillationUpdate article_update) {
+}
+
+void DomDistillerViewerSource::PrintPreviewRequestViewerHandle::OnChangeTheme(
+ DistilledPagePrefs::Theme new_theme) {
+}
+
+void DomDistillerViewerSource::
+ PrintPreviewRequestViewerHandle::OnChangeFontFamily(
+ DistilledPagePrefs::FontFamily new_font) {
+}
+
DomDistillerViewerSource::DomDistillerViewerSource(
DomDistillerServiceInterface* dom_distiller_service,
const std::string& scheme,
@@ -222,6 +289,10 @@ void DomDistillerViewerSource::StartDataRequest(
std::string css = viewer::GetCss();
callback.Run(base::RefCountedString::TakeString(&css));
return;
+ } else if (kPrintPreviewViewerCssPath == path) {
+ std::string css = viewer::GetPrintPreviewCss();
+ callback.Run(base::RefCountedString::TakeString(&css));
+ return;
} else if (kViewerJsPath == path) {
std::string js = viewer::GetJavaScript();
callback.Run(base::RefCountedString::TakeString(&js));
@@ -248,15 +319,28 @@ void DomDistillerViewerSource::StartDataRequest(
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
DCHECK(web_contents);
- // An empty |path| is invalid, but guard against it. If not empty, assume
- // |path| starts with '?', which is stripped away.
+
scoped_ptr<ContentDataCallback> data_callback(
new ContentDataCallback(callback));
- const std::string path_after_query_separator =
- path.size() > 0 ? path.substr(1) : "";
- RequestViewerHandle* request_viewer_handle = new RequestViewerHandle(
+ RequestViewerHandle* request_viewer_handle = NULL;
+ std::string print_prefix = "printing/";
+ if (path.compare(0, print_prefix.length(), print_prefix) == 0) {
+ const std::string path_after_query_separator =
+ path.substr(print_prefix.length() + 1);
+ request_viewer_handle = new PrintPreviewRequestViewerHandle(
web_contents, scheme_, path_after_query_separator, data_callback.Pass(),
dom_distiller_service_->GetDistilledPagePrefs());
+
+ } else {
+ // An empty |path| is invalid, but guard against it. If not empty, assume
+ // |path| starts with '?', which is stripped away.
+ const std::string path_after_query_separator =
+ path.size() > 0 ? path.substr(1) : "";
+ request_viewer_handle = new RequestViewerHandle(
+ web_contents, scheme_, path_after_query_separator, data_callback.Pass(),
+ dom_distiller_service_->GetDistilledPagePrefs());
+ }
+
scoped_ptr<ViewerHandle> viewer_handle = viewer::CreateViewRequest(
dom_distiller_service_, path, request_viewer_handle,
web_contents->GetContainerBounds().size());

Powered by Google App Engine
This is Rietveld 408576698