#include "content/public/renderer/render_view.h"
#include "content/public/renderer/web_preferences.h"
#include "grit/browser_resources.h"
-#include "grit/generated_resources.h"
#include "net/base/escape.h"
#include "printing/metafile.h"
#include "printing/metafile_impl.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/WebSettings.h"
#include "third_party/WebKit/public/web/WebView.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"
} // 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::WebLocalFrame* frame = blink::WebLocalFrame::create(NULL);
web_view->setMainFrame(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());
+ 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;
}
}
// Prints |frame| which called window.print().
-void PrintWebViewHelper::PrintPage(blink::WebFrame* frame,
+void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
bool user_initiated) {
DCHECK(frame);
return;
blink::WebDocument document = main_frame->document();
- // <object> with id="pdf-viewer" is created in
+ // <object>/<iframe> with id="pdf-viewer" is created in
// chrome/browser/resources/print_preview/print_preview.js
blink::WebElement pdf_element = document.getElementById("pdf-viewer");
if (pdf_element.isNull()) {
return;
}
+ // The out-of-process plugin element is nested within a frame.
+ blink::WebLocalFrame* plugin_frame = pdf_element.document().frame();
+ blink::WebElement plugin_element = pdf_element;
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kOutOfProcessPdf)) {
+ if (!pdf_element.hasTagName("iframe")) {
+ NOTREACHED();
+ return;
+ }
+ plugin_frame = blink::WebLocalFrame::fromFrameOwnerElement(pdf_element);
+ // <object> with id="plugin" is created in
+ // chrome/browser/resources/pdf/pdf.js.
+ plugin_element = plugin_frame->document().getElementById("plugin");
+ if (plugin_element.isNull()) {
+ NOTREACHED();
+ return;
+ }
+ }
+
// Set |print_for_preview_| flag and autoreset it to back to original
// on return.
base::AutoReset<bool> set_printing_flag(&print_for_preview_, true);
- blink::WebFrame* pdf_frame = pdf_element.document().frame();
- if (!UpdatePrintSettings(pdf_frame, pdf_element, job_settings)) {
+ if (!UpdatePrintSettings(plugin_frame, plugin_element, job_settings)) {
LOG(ERROR) << "UpdatePrintSettings failed";
DidFinishPrinting(FAIL_PRINT);
return;
print_params.printable_area = gfx::Rect(print_params.page_size);
// Render Pages for printing.
- if (!RenderPagesForPrint(pdf_frame, pdf_element)) {
+ if (!RenderPagesForPrint(plugin_frame, plugin_element)) {
LOG(ERROR) << "RenderPagesForPrint 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;
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 fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node));
if (!InitPrintSettings(fit_to_paper_size)) {
notify_browser_of_print_failure_ = false;
- render_view()->RunModalAlertDialog(
- frame,
- l10n_util::GetStringUTF16(IDS_PRINT_INVALID_PRINTER_SETTINGS));
+ Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id()));
return false;
}
}
bool PrintWebViewHelper::UpdatePrintSettings(
- blink::WebFrame* frame,
+ blink::WebLocalFrame* frame,
const blink::WebNode& node,
const base::DictionaryValue& passed_job_settings) {
DCHECK(is_preview_enabled_);
print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
if (!PrintMsg_Print_Params_IsValid(settings.params)) {
- if (!print_for_preview_) {
+ if (!print_for_preview_)
print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
- } else {
- // PrintForPrintPreview
- blink::WebFrame* print_frame = NULL;
- // This may not be the right frame, but the alert will be modal,
- // therefore it works well enough.
- GetPrintFrame(&print_frame);
- if (print_frame) {
- render_view()->RunModalAlertDialog(
- print_frame,
- l10n_util::GetStringUTF16(
- IDS_PRINT_INVALID_PRINTER_SETTINGS));
- }
- }
+ else
+ Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id()));
+
return false;
}
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;
}
void PrintWebViewHelper::PrintPreviewContext::InitWithFrame(
- blink::WebFrame* web_frame) {
+ blink::WebLocalFrame* web_frame) {
DCHECK(web_frame);
DCHECK(!IsRendering());
state_ = INITIALIZED;
error_ = error;
}
-blink::WebFrame* PrintWebViewHelper::PrintPreviewContext::source_frame() {
+blink::WebLocalFrame* PrintWebViewHelper::PrintPreviewContext::source_frame() {
DCHECK(state_ != UNINITIALIZED);
return source_frame_.GetFrame();
}
return source_node_;
}
-blink::WebFrame* PrintWebViewHelper::PrintPreviewContext::prepared_frame() {
+blink::WebLocalFrame*
+PrintWebViewHelper::PrintPreviewContext::prepared_frame() {
DCHECK(state_ != UNINITIALIZED);
return prep_frame_view_->frame();
}