diff options
author | sammc <sammc@chromium.org> | 2015-01-23 23:10:14 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-24 07:11:31 +0000 |
commit | da51fc6ff30169780c2e6b8076e12d8d7b398f5a (patch) | |
tree | 0812c9c0052d060e7044c35249975034c9cbf762 /extensions/renderer/guest_view | |
parent | 70e58ead2e061d1044b10a3781f9c21d3ed10e0c (diff) | |
download | chromium_src-da51fc6ff30169780c2e6b8076e12d8d7b398f5a.zip chromium_src-da51fc6ff30169780c2e6b8076e12d8d7b398f5a.tar.gz chromium_src-da51fc6ff30169780c2e6b8076e12d8d7b398f5a.tar.bz2 |
OOP PDF: Override printing for MimeHandlerViewContainers.
Previously, calling print() on the window object for a plugin document
resulted in printing a blank page. This adds an OverridePrint method to
PrintWebViewHelper::Delegate so MimeHandlerViewContainers can replace
the default print behavior with posting a print message to the mime
handler.
BUG=448720
Review URL: https://codereview.chromium.org/858363002
Cr-Commit-Position: refs/heads/master@{#313011}
Diffstat (limited to 'extensions/renderer/guest_view')
-rw-r--r-- | extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc | 41 | ||||
-rw-r--r-- | extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h | 9 |
2 files changed, 50 insertions, 0 deletions
diff --git a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc index 59f3e29..9c50256 100644 --- a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc +++ b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc @@ -4,8 +4,12 @@ #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h" +#include <map> +#include <set> + #include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_view.h" +#include "content/public/renderer/v8_value_converter.h" #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_constants.h" #include "extensions/common/extension_messages.h" #include "extensions/common/guest_view/guest_view_constants.h" @@ -71,6 +75,12 @@ class ScriptableObject : public gin::Wrappable<ScriptableObject>, // static gin::WrapperInfo ScriptableObject::kWrapperInfo = { gin::kEmbedderNativeGin }; +// Maps from content::RenderFrame to the set of MimeHandlerViewContainers within +// it. +base::LazyInstance< + std::map<content::RenderFrame*, std::set<MimeHandlerViewContainer*>>> + g_mime_handler_view_container_map = LAZY_INSTANCE_INITIALIZER; + } // namespace MimeHandlerViewContainer::MimeHandlerViewContainer( @@ -85,11 +95,27 @@ MimeHandlerViewContainer::MimeHandlerViewContainer( weak_factory_(this) { DCHECK(!mime_type_.empty()); is_embedded_ = !render_frame->GetWebFrame()->document().isPluginDocument(); + g_mime_handler_view_container_map.Get()[render_frame].insert(this); } MimeHandlerViewContainer::~MimeHandlerViewContainer() { if (loader_) loader_->cancel(); + + g_mime_handler_view_container_map.Get()[render_frame()].erase(this); + if (g_mime_handler_view_container_map.Get()[render_frame()].empty()) + g_mime_handler_view_container_map.Get().erase(render_frame()); +} + +// static +std::vector<MimeHandlerViewContainer*> +MimeHandlerViewContainer::FromRenderFrame(content::RenderFrame* render_frame) { + auto it = g_mime_handler_view_container_map.Get().find(render_frame); + if (it == g_mime_handler_view_container_map.Get().end()) + return std::vector<MimeHandlerViewContainer*>(); + + return std::vector<MimeHandlerViewContainer*>(it->second.begin(), + it->second.end()); } void MimeHandlerViewContainer::Ready() { @@ -197,6 +223,21 @@ void MimeHandlerViewContainer::PostMessage(v8::Isolate* isolate, args); } +void MimeHandlerViewContainer::PostMessageFromValue( + const base::Value& message) { + blink::WebFrame* frame = render_frame()->GetWebFrame(); + if (!frame) + return; + + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::HandleScope handle_scope(isolate); + v8::Context::Scope context_scope(frame->mainWorldScriptContext()); + scoped_ptr<content::V8ValueConverter> converter( + content::V8ValueConverter::create()); + PostMessage(isolate, + converter->ToV8Value(&message, frame->mainWorldScriptContext())); +} + void MimeHandlerViewContainer::OnCreateMimeHandlerViewGuestACK( int element_instance_id) { DCHECK_NE(this->element_instance_id(), guestview::kInstanceIDNone); diff --git a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h index 105323d..86183f1 100644 --- a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h +++ b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h @@ -5,6 +5,9 @@ #ifndef EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_ #define EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_ +#include <string> +#include <vector> + #include "base/memory/linked_ptr.h" #include "base/memory/weak_ptr.h" #include "extensions/renderer/guest_view/guest_view_container.h" @@ -41,6 +44,9 @@ class MimeHandlerViewContainer : public GuestViewContainer, const GURL& original_url); ~MimeHandlerViewContainer() override; + static std::vector<MimeHandlerViewContainer*> FromRenderFrame( + content::RenderFrame* render_frame); + // BrowserPluginDelegate implementation. void Ready() override; void DidFinishLoading() override; @@ -63,6 +69,9 @@ class MimeHandlerViewContainer : public GuestViewContainer, void PostMessage(v8::Isolate* isolate, v8::Handle<v8::Value> message); + // Post |message| to the guest. + void PostMessageFromValue(const base::Value& message); + private: // Message handlers. void OnCreateMimeHandlerViewGuestACK(int element_instance_id); |