diff options
Diffstat (limited to 'extensions')
-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); |