#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "content/public/common/web_preferences.h"
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
-#include "content/public/renderer/web_preferences.h"
#include "net/base/escape.h"
-#include "printing/metafile.h"
-#include "printing/metafile_impl.h"
+#include "printing/pdf_metafile_skia.h"
#include "printing/units.h"
#include "skia/ext/vector_platform_device_skia.h"
#include "third_party/WebKit/public/platform/WebSize.h"
#include "third_party/WebKit/public/web/WebConsoleMessage.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
-#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebFrameClient.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebPlugin.h"
#include "third_party/WebKit/public/web/WebPluginDocument.h"
#include "third_party/WebKit/public/web/WebPrintParams.h"
#include "third_party/WebKit/public/web/WebViewClient.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
-#include "webkit/common/webpreferences.h"
// This code is copied from chrome/renderer/printing. Code is slightly
// modified to run it with webview, and the modifications are marked
// using OS_ANDROID.
// TODO(sgurun): remove the code as part of componentization of printing.
+using content::WebPreferences;
+
namespace printing {
namespace {
// Invalid page size and/or margins. We just use the default setting.
if (new_content_width < 1 || new_content_height < 1) {
- CHECK(frame != NULL);
+ CHECK(frame);
page_css_params = GetCssPrintParams(NULL, page_index, page_params);
return page_css_params;
}
} // namespace
-FrameReference::FrameReference(blink::WebFrame* frame) {
+FrameReference::FrameReference(blink::WebLocalFrame* frame) {
Reset(frame);
}
FrameReference::~FrameReference() {
}
-void FrameReference::Reset(blink::WebFrame* frame) {
+void FrameReference::Reset(blink::WebLocalFrame* frame) {
if (frame) {
view_ = frame->view();
frame_ = frame;
}
}
-blink::WebFrame* FrameReference::GetFrame() {
+blink::WebLocalFrame* FrameReference::GetFrame() {
if (view_ == NULL || frame_ == NULL)
return NULL;
for (blink::WebFrame* frame = view_->mainFrame(); frame != NULL;
frame = frame->traverseNext(false)) {
if (frame == frame_)
- return frame;
+ return frame_;
}
return NULL;
}
blink::WebView* web_view = blink::WebView::create(NULL);
web_view->settings()->setJavaScriptEnabled(true);
- blink::WebFrame* frame = blink::WebFrame::create(NULL)
+ blink::WebFrame* frame = blink::WebLocalFrame::create(NULL)
web_view->setMainFrame(web_frame);
base::StringValue html(
public blink::WebFrameClient {
public:
PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& params,
- blink::WebFrame* frame,
+ blink::WebLocalFrame* frame,
const blink::WebNode& node,
bool ignore_css_margins);
virtual ~PrepareFrameAndViewForPrint();
// Prepares frame for printing.
void StartPrinting();
- blink::WebFrame* frame() {
+ blink::WebLocalFrame* frame() {
return frame_.GetFrame();
}
return owns_web_view_ && frame() && frame()->isLoading();
}
+ // TODO(ojan): Remove this override and have this class use a non-null
+ // layerTreeView.
+ // blink::WebViewClient override:
+ virtual bool allowsBrokenNullLayerTreeView() const;
+
protected:
// blink::WebViewClient override:
virtual void didStopLoading();
// blink::WebFrameClient override:
- virtual blink::WebFrame* createChildFrame(blink::WebFrame* parent,
+ virtual blink::WebFrame* createChildFrame(blink::WebLocalFrame* parent,
const blink::WebString& name);
virtual void frameDetached(blink::WebFrame* frame);
PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint(
const PrintMsg_Print_Params& params,
- blink::WebFrame* frame,
+ blink::WebLocalFrame* frame,
const blink::WebNode& node,
bool ignore_css_margins)
: weak_ptr_factory_(this),
blink::WebView* web_view = blink::WebView::create(this);
owns_web_view_ = true;
- content::ApplyWebPreferences(prefs, web_view);
-
- web_view->setMainFrame(blink::WebFrame::create(this));
- frame_.Reset(web_view->mainFrame());
+ content::RenderView::ApplyWebPreferences(prefs, web_view);
+ web_view->setMainFrame(blink::WebLocalFrame::create(this));
+ frame_.Reset(web_view->mainFrame()->toWebLocalFrame());
node_to_print_.reset();
// When loading is done this will call didStopLoading() and that will do the
frame()->loadRequest(blink::WebURLRequest(GURL(url_str)));
}
+bool PrepareFrameAndViewForPrint::allowsBrokenNullLayerTreeView() const {
+ return true;
+}
+
void PrepareFrameAndViewForPrint::didStopLoading() {
DCHECK(!on_ready_.is_null());
// Don't call callback here, because it can delete |this| and WebView that is
}
blink::WebFrame* PrepareFrameAndViewForPrint::createChildFrame(
- blink::WebFrame* parent,
+ blink::WebLocalFrame* parent,
const blink::WebString& name) {
- blink::WebFrame* frame = blink::WebFrame::create(this);
+ blink::WebFrame* frame = blink::WebLocalFrame::create(this);
parent->appendChild(frame);
return frame;
}
}
void PrepareFrameAndViewForPrint::FinishPrinting() {
- blink::WebFrame* frame = frame_.GetFrame();
+ blink::WebLocalFrame* frame = frame_.GetFrame();
if (frame) {
blink::WebView* web_view = frame->view();
if (is_printing_started_) {
}
// Prints |frame| which called window.print().
-void PrintWebViewHelper::PrintPage(blink::WebFrame* frame,
+void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
bool user_initiated) {
DCHECK(frame);
// on return.
base::AutoReset<bool> set_printing_flag(&print_for_preview_, true);
- blink::WebFrame* pdf_frame = pdf_element.document().frame();
+ blink::WebLocalFrame* pdf_frame = pdf_element.document().frame();
if (!UpdatePrintSettings(pdf_frame, pdf_element, job_settings)) {
LOG(ERROR) << "UpdatePrintSettings failed";
DidFinishPrinting(FAIL_PRINT);
}
}
-bool PrintWebViewHelper::GetPrintFrame(blink::WebFrame** frame) {
+bool PrintWebViewHelper::GetPrintFrame(blink::WebLocalFrame** frame) {
DCHECK(frame);
blink::WebView* webView = render_view()->GetWebView();
DCHECK(webView);
// If the user has selected text in the currently focused frame we print
// only that frame (this makes print selection work for multiple frames).
- blink::WebFrame* focusedFrame = webView->focusedFrame();
- *frame = focusedFrame->hasSelection() ? focusedFrame : webView->mainFrame();
+ blink::WebLocalFrame* focusedFrame =
+ webView->focusedFrame()->toWebLocalFrame();
+ *frame = focusedFrame->hasSelection()
+ ? focusedFrame
+ : webView->mainFrame()->toWebLocalFrame();
return true;
}
void PrintWebViewHelper::OnPrintPages() {
- blink::WebFrame* frame;
+ blink::WebLocalFrame* frame;
if (GetPrintFrame(&frame))
Print(frame, blink::WebNode());
}
void PrintWebViewHelper::OnPrintForSystemDialog() {
- blink::WebFrame* frame = print_preview_context_.source_frame();
+ blink::WebLocalFrame* frame = print_preview_context_.source_frame();
if (!frame) {
NOTREACHED();
return;
print_preview_context_.FinalizePrintReadyDocument();
// Get the size of the resulting metafile.
- PreviewMetafile* metafile = print_preview_context_.metafile();
+ PdfMetafileSkia* metafile = print_preview_context_.metafile();
uint32 buf_size = metafile->GetDataSize();
DCHECK_GT(buf_size, 0u);
void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) {
DCHECK(is_preview_enabled_);
- blink::WebFrame* frame = NULL;
+ blink::WebLocalFrame* frame = NULL;
GetPrintFrame(&frame);
DCHECK(frame);
print_preview_context_.InitWithFrame(frame);
print_node_in_progress_ = false;
}
-void PrintWebViewHelper::Print(blink::WebFrame* frame,
+void PrintWebViewHelper::Print(blink::WebLocalFrame* frame,
const blink::WebNode& node) {
// If still not finished with earlier print request simply ignore.
if (prep_frame_view_)
return result;
}
-bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebFrame* frame,
+bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebLocalFrame* frame,
const blink::WebNode& node,
int* number_of_pages) {
DCHECK(frame);
}
bool PrintWebViewHelper::UpdatePrintSettings(
- blink::WebFrame* frame,
+ blink::WebLocalFrame* frame,
const blink::WebNode& node,
const base::DictionaryValue& passed_job_settings) {
DCHECK(is_preview_enabled_);
return (print_settings.params.dpi && print_settings.params.document_cookie);
}
-bool PrintWebViewHelper::RenderPagesForPrint(blink::WebFrame* frame,
+bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame,
const blink::WebNode& node) {
if (!frame || prep_frame_view_)
return false;
const PrintMsg_PrintPages_Params& params = *print_pages_params_;
const PrintMsg_Print_Params& print_params = params.params;
- prep_frame_view_.reset(
- new PrepareFrameAndViewForPrint(print_params, frame, node,
- ignore_css_margins_));
+ prep_frame_view_.reset(new PrepareFrameAndViewForPrint(
+ print_params, frame, node, ignore_css_margins_));
DCHECK(!print_pages_params_->params.selection_only ||
print_pages_params_->pages.empty());
prep_frame_view_->CopySelectionIfNeeded(
#if defined(OS_POSIX)
bool PrintWebViewHelper::CopyMetafileDataToSharedMem(
- Metafile* metafile,
+ PdfMetafileSkia* metafile,
base::SharedMemoryHandle* shared_mem_handle) {
uint32 buf_size = metafile->GetDataSize();
scoped_ptr<base::SharedMemory> shared_buf(
}
bool PrintWebViewHelper::PreviewPageRendered(int page_number,
- Metafile* metafile) {
+ PdfMetafileSkia* metafile) {
DCHECK_GE(page_number, FIRST_PAGE_INDEX);
// For non-modifiable files, |metafile| should be NULL, so do not bother
}
void PrintWebViewHelper::PrintPreviewContext::InitWithFrame(
- blink::WebFrame* web_frame) {
+ blink::WebLocalFrame* web_frame) {
DCHECK(web_frame);
DCHECK(!IsRendering());
state_ = INITIALIZED;
return false;
}
- metafile_.reset(new PreviewMetafile);
+ metafile_.reset(new PdfMetafileSkia);
if (!metafile_->Init()) {
set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED);
- LOG(ERROR) << "PreviewMetafile Init failed";
+ LOG(ERROR) << "PdfMetafileSkia Init failed";
return false;
}
error_ = error;
}
-blink::WebFrame* PrintWebViewHelper::PrintPreviewContext::source_frame() {
- DCHECK(state_ != UNINITIALIZED);
+blink::WebLocalFrame* PrintWebViewHelper::PrintPreviewContext::source_frame() {
+ DCHECK_NE(UNINITIALIZED, state_);
return source_frame_.GetFrame();
}
const blink::WebNode&
PrintWebViewHelper::PrintPreviewContext::source_node() const {
- DCHECK(state_ != UNINITIALIZED);
+ DCHECK_NE(UNINITIALIZED, state_);
return source_node_;
}
-blink::WebFrame* PrintWebViewHelper::PrintPreviewContext::prepared_frame() {
- DCHECK(state_ != UNINITIALIZED);
+blink::WebLocalFrame*
+PrintWebViewHelper::PrintPreviewContext::prepared_frame() {
+ DCHECK_NE(UNINITIALIZED, state_);
return prep_frame_view_->frame();
}
const blink::WebNode&
PrintWebViewHelper::PrintPreviewContext::prepared_node() const {
- DCHECK(state_ != UNINITIALIZED);
+ DCHECK_NE(UNINITIALIZED, state_);
return prep_frame_view_->node();
}
int PrintWebViewHelper::PrintPreviewContext::total_page_count() const {
- DCHECK(state_ != UNINITIALIZED);
+ DCHECK_NE(UNINITIALIZED, state_);
return total_page_count_;
}
return generate_draft_pages_;
}
-PreviewMetafile* PrintWebViewHelper::PrintPreviewContext::metafile() {
+PdfMetafileSkia* PrintWebViewHelper::PrintPreviewContext::metafile() {
DCHECK(IsRendering());
return metafile_.get();
}