summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/guest_view
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/renderer/guest_view')
-rw-r--r--extensions/renderer/guest_view/extensions_guest_view_container.cc181
-rw-r--r--extensions/renderer/guest_view/extensions_guest_view_container.h90
-rw-r--r--extensions/renderer/guest_view/guest_view_container.cc209
-rw-r--r--extensions/renderer/guest_view/guest_view_container.h84
-rw-r--r--extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc16
-rw-r--r--extensions/renderer/guest_view/mime_handler_view_container.cc56
-rw-r--r--extensions/renderer/guest_view/mime_handler_view_container.h37
7 files changed, 391 insertions, 282 deletions
diff --git a/extensions/renderer/guest_view/extensions_guest_view_container.cc b/extensions/renderer/guest_view/extensions_guest_view_container.cc
new file mode 100644
index 0000000..3790d56
--- /dev/null
+++ b/extensions/renderer/guest_view/extensions_guest_view_container.cc
@@ -0,0 +1,181 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/renderer/guest_view/extensions_guest_view_container.h"
+
+#include "content/public/renderer/render_frame.h"
+#include "content/public/renderer/render_view.h"
+#include "extensions/common/extension_messages.h"
+#include "extensions/common/guest_view/guest_view_constants.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
+#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
+#include "third_party/WebKit/public/web/WebView.h"
+
+namespace {
+typedef std::pair<int, int> GuestViewID;
+typedef std::map<GuestViewID, extensions::ExtensionsGuestViewContainer*>
+ ExtensionsGuestViewContainerMap;
+static base::LazyInstance<ExtensionsGuestViewContainerMap>
+ g_guest_view_container_map = LAZY_INSTANCE_INITIALIZER;
+} // namespace
+
+namespace extensions {
+
+ExtensionsGuestViewContainer::AttachRequest::AttachRequest(
+ int element_instance_id,
+ int guest_instance_id,
+ scoped_ptr<base::DictionaryValue> params,
+ v8::Handle<v8::Function> callback,
+ v8::Isolate* isolate)
+ : element_instance_id_(element_instance_id),
+ guest_instance_id_(guest_instance_id),
+ params_(params.Pass()),
+ callback_(callback),
+ isolate_(isolate) {
+}
+
+ExtensionsGuestViewContainer::AttachRequest::~AttachRequest() {
+}
+
+bool ExtensionsGuestViewContainer::AttachRequest::HasCallback() const {
+ return !callback_.IsEmpty();
+}
+
+v8::Handle<v8::Function>
+ExtensionsGuestViewContainer::AttachRequest::GetCallback() const {
+ return callback_.NewHandle(isolate_);
+}
+
+ExtensionsGuestViewContainer::ExtensionsGuestViewContainer(
+ content::RenderFrame* render_frame)
+ : GuestViewContainer(render_frame),
+ ready_(false) {
+}
+
+ExtensionsGuestViewContainer::~ExtensionsGuestViewContainer() {
+ if (element_instance_id() != guestview::kInstanceIDNone) {
+ g_guest_view_container_map.Get().erase(
+ GuestViewID(render_view_routing_id(), element_instance_id()));
+ }
+}
+
+ExtensionsGuestViewContainer* ExtensionsGuestViewContainer::FromID(
+ int render_view_routing_id,
+ int element_instance_id) {
+ ExtensionsGuestViewContainerMap* guest_view_containers =
+ g_guest_view_container_map.Pointer();
+ ExtensionsGuestViewContainerMap::iterator it = guest_view_containers->find(
+ GuestViewID(render_view_routing_id, element_instance_id));
+ return it == guest_view_containers->end() ? NULL : it->second;
+}
+
+void ExtensionsGuestViewContainer::AttachGuest(
+ linked_ptr<AttachRequest> request) {
+ EnqueueAttachRequest(request);
+ PerformPendingAttachRequest();
+}
+
+void ExtensionsGuestViewContainer::SetElementInstanceID(
+ int element_instance_id) {
+ GuestViewContainer::SetElementInstanceID(element_instance_id);
+
+ GuestViewID guest_view_id(render_view_routing_id(), element_instance_id);
+ DCHECK(g_guest_view_container_map.Get().find(guest_view_id) ==
+ g_guest_view_container_map.Get().end());
+ g_guest_view_container_map.Get().insert(std::make_pair(guest_view_id, this));
+}
+
+void ExtensionsGuestViewContainer::Ready() {
+ ready_ = true;
+ CHECK(!pending_response_.get());
+ PerformPendingAttachRequest();
+}
+
+bool ExtensionsGuestViewContainer::HandlesMessage(const IPC::Message& message) {
+ return message.type() == ExtensionMsg_GuestAttached::ID;
+}
+
+bool ExtensionsGuestViewContainer::OnMessage(const IPC::Message& message) {
+ bool handled = false;
+ IPC_BEGIN_MESSAGE_MAP(ExtensionsGuestViewContainer, message)
+ IPC_MESSAGE_HANDLER(ExtensionMsg_GuestAttached, OnGuestAttached)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void ExtensionsGuestViewContainer::OnGuestAttached(int /* unused */,
+ int guest_proxy_routing_id) {
+ // Handle the callback for the current request with a pending response.
+ HandlePendingResponseCallback(guest_proxy_routing_id);
+ // Perform the subsequent attach request if one exists.
+ PerformPendingAttachRequest();
+}
+
+void ExtensionsGuestViewContainer::AttachGuestInternal(
+ linked_ptr<AttachRequest> request) {
+ CHECK(!pending_response_.get());
+ // Step 1, send the attach params to chrome/.
+ render_frame()->Send(
+ new ExtensionHostMsg_AttachGuest(render_view_routing_id(),
+ request->element_instance_id(),
+ request->guest_instance_id(),
+ *request->attach_params()));
+
+ // Step 2, attach plugin through content/.
+ render_frame()->AttachGuest(request->element_instance_id());
+
+ pending_response_ = request;
+}
+
+void ExtensionsGuestViewContainer::EnqueueAttachRequest(
+ linked_ptr<AttachRequest> request) {
+ pending_requests_.push_back(request);
+}
+
+void ExtensionsGuestViewContainer::PerformPendingAttachRequest() {
+ if (!ready_ || pending_requests_.empty() || pending_response_.get())
+ return;
+
+ linked_ptr<AttachRequest> pending_request = pending_requests_.front();
+ pending_requests_.pop_front();
+ AttachGuestInternal(pending_request);
+}
+
+void ExtensionsGuestViewContainer::HandlePendingResponseCallback(
+ int guest_proxy_routing_id) {
+ CHECK(pending_response_.get());
+ linked_ptr<AttachRequest> pending_response(pending_response_.release());
+
+ // If we don't have a callback then there's nothing more to do.
+ if (!pending_response->HasCallback())
+ return;
+
+ content::RenderView* guest_proxy_render_view =
+ content::RenderView::FromRoutingID(guest_proxy_routing_id);
+ // TODO(fsamuel): Should we be reporting an error to JavaScript or DCHECKing?
+ if (!guest_proxy_render_view)
+ return;
+
+ v8::HandleScope handle_scope(pending_response->isolate());
+ v8::Handle<v8::Function> callback = pending_response->GetCallback();
+ v8::Handle<v8::Context> context = callback->CreationContext();
+ if (context.IsEmpty())
+ return;
+
+ blink::WebFrame* frame = guest_proxy_render_view->GetWebView()->mainFrame();
+ v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global();
+
+ const int argc = 1;
+ v8::Handle<v8::Value> argv[argc] = { window };
+
+ v8::Context::Scope context_scope(context);
+ blink::WebScopedMicrotaskSuppression suppression;
+
+ // Call the AttachGuest API's callback with the guest proxy as the first
+ // parameter.
+ callback->Call(context->Global(), argc, argv);
+}
+
+} // namespace extensions
diff --git a/extensions/renderer/guest_view/extensions_guest_view_container.h b/extensions/renderer/guest_view/extensions_guest_view_container.h
new file mode 100644
index 0000000..9b1424d
--- /dev/null
+++ b/extensions/renderer/guest_view/extensions_guest_view_container.h
@@ -0,0 +1,90 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_
+#define EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_
+
+#include <queue>
+
+#include "base/memory/linked_ptr.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "extensions/renderer/guest_view/guest_view_container.h"
+#include "extensions/renderer/scoped_persistent.h"
+
+namespace extensions {
+
+class ExtensionsGuestViewContainer : public GuestViewContainer {
+ public:
+ // This class represents an AttachGuest request from Javascript. It includes
+ // the input parameters and the callback function. The Attach operation may
+ // not execute immediately, if the container is not ready or if there are
+ // other attach operations in flight.
+ class AttachRequest {
+ public:
+ AttachRequest(int element_instance_id,
+ int guest_instance_id,
+ scoped_ptr<base::DictionaryValue> params,
+ v8::Handle<v8::Function> callback,
+ v8::Isolate* isolate);
+ ~AttachRequest();
+
+ int element_instance_id() const { return element_instance_id_; }
+
+ int guest_instance_id() const { return guest_instance_id_; }
+
+ base::DictionaryValue* attach_params() const {
+ return params_.get();
+ }
+
+ bool HasCallback() const;
+
+ v8::Handle<v8::Function> GetCallback() const;
+
+ v8::Isolate* isolate() const { return isolate_; }
+
+ private:
+ const int element_instance_id_;
+ const int guest_instance_id_;
+ scoped_ptr<base::DictionaryValue> params_;
+ ScopedPersistent<v8::Function> callback_;
+ v8::Isolate* const isolate_;
+ };
+
+ explicit ExtensionsGuestViewContainer(content::RenderFrame* render_frame);
+ ~ExtensionsGuestViewContainer() override;
+
+ static ExtensionsGuestViewContainer* FromID(int render_view_routing_id,
+ int element_instance_id);
+
+ void AttachGuest(linked_ptr<AttachRequest> request);
+
+ // BrowserPluginDelegate implementation.
+ void SetElementInstanceID(int element_instance_id) override;
+ void Ready() override;
+
+ // GuestViewContainer override.
+ bool HandlesMessage(const IPC::Message& message) override;
+ bool OnMessage(const IPC::Message& message) override;
+
+ private:
+ void OnGuestAttached(int element_instance_id,
+ int guest_proxy_routing_id);
+
+ void AttachGuestInternal(linked_ptr<AttachRequest> request);
+ void EnqueueAttachRequest(linked_ptr<AttachRequest> request);
+ void PerformPendingAttachRequest();
+ void HandlePendingResponseCallback(int guest_proxy_routing_id);
+
+ bool ready_;
+
+ std::deque<linked_ptr<AttachRequest> > pending_requests_;
+ linked_ptr<AttachRequest> pending_response_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionsGuestViewContainer);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_
diff --git a/extensions/renderer/guest_view/guest_view_container.cc b/extensions/renderer/guest_view/guest_view_container.cc
index 7810270..44ef046 100644
--- a/extensions/renderer/guest_view/guest_view_container.cc
+++ b/extensions/renderer/guest_view/guest_view_container.cc
@@ -4,110 +4,23 @@
#include "extensions/renderer/guest_view/guest_view_container.h"
-#include "content/public/renderer/browser_plugin_delegate.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_view.h"
-#include "extensions/common/extension_messages.h"
#include "extensions/common/guest_view/guest_view_constants.h"
-#include "third_party/WebKit/public/web/WebLocalFrame.h"
-#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
-#include "third_party/WebKit/public/web/WebView.h"
-
-namespace {
-typedef std::pair<int, int> GuestViewID;
-typedef std::map<GuestViewID, extensions::GuestViewContainer*>
- GuestViewContainerMap;
-static base::LazyInstance<GuestViewContainerMap> g_guest_view_container_map =
- LAZY_INSTANCE_INITIALIZER;
-} // namespace
namespace extensions {
-GuestViewContainer::AttachRequest::AttachRequest(
- int element_instance_id,
- int guest_instance_id,
- scoped_ptr<base::DictionaryValue> params,
- v8::Handle<v8::Function> callback,
- v8::Isolate* isolate)
- : element_instance_id_(element_instance_id),
- guest_instance_id_(guest_instance_id),
- params_(params.Pass()),
- callback_(callback),
- isolate_(isolate) {
-}
-
-GuestViewContainer::AttachRequest::~AttachRequest() {
-}
-
-bool GuestViewContainer::AttachRequest::HasCallback() const {
- return !callback_.IsEmpty();
-}
-
-v8::Handle<v8::Function>
-GuestViewContainer::AttachRequest::GetCallback() const {
- return callback_.NewHandle(isolate_);
-}
-
-GuestViewContainer::GuestViewContainer(
- content::RenderFrame* render_frame,
- const std::string& mime_type)
- : content::BrowserPluginDelegate(render_frame, mime_type),
- content::RenderFrameObserver(render_frame),
- mime_type_(mime_type),
+GuestViewContainer::GuestViewContainer(content::RenderFrame* render_frame)
+ : content::RenderFrameObserver(render_frame),
element_instance_id_(guestview::kInstanceIDNone),
- render_view_routing_id_(render_frame->GetRenderView()->GetRoutingID()),
- attached_(false),
- ready_(false) {
-}
-
-GuestViewContainer::~GuestViewContainer() {
- if (element_instance_id_ != guestview::kInstanceIDNone) {
- g_guest_view_container_map.Get().erase(
- GuestViewID(render_view_routing_id_, element_instance_id_));
- }
+ render_view_routing_id_(render_frame->GetRenderView()->GetRoutingID()) {
}
-GuestViewContainer* GuestViewContainer::FromID(int render_view_routing_id,
- int element_instance_id) {
- GuestViewContainerMap* guest_view_containers =
- g_guest_view_container_map.Pointer();
- GuestViewContainerMap::iterator it = guest_view_containers->find(
- GuestViewID(render_view_routing_id, element_instance_id));
- return it == guest_view_containers->end() ? NULL : it->second;
-}
-
-void GuestViewContainer::AttachGuest(linked_ptr<AttachRequest> request) {
- EnqueueAttachRequest(request);
- PerformPendingAttachRequest();
-}
+GuestViewContainer::~GuestViewContainer() {}
void GuestViewContainer::SetElementInstanceID(int element_instance_id) {
- GuestViewID guest_view_id(render_view_routing_id_, element_instance_id);
DCHECK_EQ(element_instance_id_, guestview::kInstanceIDNone);
- DCHECK(g_guest_view_container_map.Get().find(guest_view_id) ==
- g_guest_view_container_map.Get().end());
element_instance_id_ = element_instance_id;
- g_guest_view_container_map.Get().insert(std::make_pair(guest_view_id, this));
-}
-
-void GuestViewContainer::DidFinishLoading() {
- if (mime_type_.empty())
- return;
-
- DCHECK_NE(element_instance_id_, guestview::kInstanceIDNone);
- render_frame()->Send(new ExtensionHostMsg_CreateMimeHandlerViewGuest(
- routing_id(), html_string_, mime_type_, element_instance_id_));
-}
-
-void GuestViewContainer::DidReceiveData(const char* data, int data_length) {
- std::string value(data, data_length);
- html_string_ += value;
-}
-
-void GuestViewContainer::Ready() {
- ready_ = true;
- CHECK(!pending_response_.get());
- PerformPendingAttachRequest();
}
void GuestViewContainer::OnDestruct() {
@@ -115,8 +28,9 @@ void GuestViewContainer::OnDestruct() {
// RenderFrameObserver self-destruct here.
}
-bool GuestViewContainer::OnMessageReceived(const IPC::Message& message) {
- if (!ShouldHandleMessage(message))
+bool GuestViewContainer::OnMessageReceived(
+ const IPC::Message& message) {
+ if (!HandlesMessage(message))
return false;
DCHECK_NE(element_instance_id_, guestview::kInstanceIDNone);
@@ -127,114 +41,7 @@ bool GuestViewContainer::OnMessageReceived(const IPC::Message& message) {
if (element_instance_id != element_instance_id_)
return false;
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(GuestViewContainer, message)
- IPC_MESSAGE_HANDLER(ExtensionMsg_CreateMimeHandlerViewGuestACK,
- OnCreateMimeHandlerViewGuestACK)
- IPC_MESSAGE_HANDLER(ExtensionMsg_GuestAttached, OnGuestAttached)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
-void GuestViewContainer::OnCreateMimeHandlerViewGuestACK(
- int element_instance_id) {
- DCHECK_NE(element_instance_id_, guestview::kInstanceIDNone);
- DCHECK_EQ(element_instance_id_, element_instance_id);
- DCHECK(!mime_type_.empty());
- render_frame()->AttachGuest(element_instance_id);
-}
-
-void GuestViewContainer::OnGuestAttached(int element_instance_id,
- int guest_proxy_routing_id) {
- attached_ = true;
-
- if (!mime_type_.empty()) {
- // MimeHandlerView's creation and attachment is not done via JS API.
- return;
- }
-
- // Handle the callback for the current request with a pending response.
- HandlePendingResponseCallback(guest_proxy_routing_id);
- // Perform the subsequent attach request if one exists.
- PerformPendingAttachRequest();
-}
-
-void GuestViewContainer::AttachGuestInternal(
- linked_ptr<AttachRequest> request) {
- CHECK(!pending_response_.get());
- // Step 1, send the attach params to chrome/.
- render_frame()->Send(
- new ExtensionHostMsg_AttachGuest(render_view_routing_id_,
- request->element_instance_id(),
- request->guest_instance_id(),
- *request->attach_params()));
-
- // Step 2, attach plugin through content/.
- render_frame()->AttachGuest(request->element_instance_id());
-
- pending_response_ = request;
-}
-
-void GuestViewContainer::EnqueueAttachRequest(
- linked_ptr<AttachRequest> request) {
- pending_requests_.push_back(request);
-}
-
-void GuestViewContainer::PerformPendingAttachRequest() {
- if (!ready_ || pending_requests_.empty() || pending_response_.get())
- return;
-
- linked_ptr<AttachRequest> pending_request = pending_requests_.front();
- pending_requests_.pop_front();
- AttachGuestInternal(pending_request);
-}
-
-void GuestViewContainer::HandlePendingResponseCallback(
- int guest_proxy_routing_id) {
- CHECK(pending_response_.get());
- linked_ptr<AttachRequest> pending_response(pending_response_.release());
-
- // If we don't have a callback then there's nothing more to do.
- if (!pending_response->HasCallback())
- return;
-
- content::RenderView* guest_proxy_render_view =
- content::RenderView::FromRoutingID(guest_proxy_routing_id);
- // TODO(fsamuel): Should we be reporting an error to JavaScript or DCHECKing?
- if (!guest_proxy_render_view)
- return;
-
- v8::HandleScope handle_scope(pending_response->isolate());
- v8::Handle<v8::Function> callback = pending_response->GetCallback();
- v8::Handle<v8::Context> context = callback->CreationContext();
- if (context.IsEmpty())
- return;
-
- blink::WebFrame* frame = guest_proxy_render_view->GetWebView()->mainFrame();
- v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global();
-
- const int argc = 1;
- v8::Handle<v8::Value> argv[argc] = { window };
-
- v8::Context::Scope context_scope(context);
- blink::WebScopedMicrotaskSuppression suppression;
-
- // Call the AttachGuest API's callback with the guest proxy as the first
- // parameter.
- callback->Call(context->Global(), argc, argv);
-}
-
-// static
-bool GuestViewContainer::ShouldHandleMessage(const IPC::Message& message) {
- switch (message.type()) {
- case ExtensionMsg_CreateMimeHandlerViewGuestACK::ID:
- case ExtensionMsg_GuestAttached::ID:
- return true;
- default:
- break;
- }
- return false;
+ return OnMessage(message);
}
} // namespace extensions
diff --git a/extensions/renderer/guest_view/guest_view_container.h b/extensions/renderer/guest_view/guest_view_container.h
index d891775..96fd637 100644
--- a/extensions/renderer/guest_view/guest_view_container.h
+++ b/extensions/renderer/guest_view/guest_view_container.h
@@ -2,104 +2,42 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_
-#define CHROME_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_
+#ifndef EXTENSIONS_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_
+#define EXTENSIONS_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_
-#include <queue>
-
-#include "base/memory/linked_ptr.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/values.h"
#include "content/public/renderer/browser_plugin_delegate.h"
#include "content/public/renderer/render_frame_observer.h"
-#include "extensions/renderer/scoped_persistent.h"
+#include "ipc/ipc_message.h"
namespace extensions {
class GuestViewContainer : public content::BrowserPluginDelegate,
public content::RenderFrameObserver {
public:
- // This class represents an AttachGuest request from Javascript. It includes
- // the input parameters and the callback function. The Attach operation may
- // not execute immediately, if the container is not ready or if there are
- // other attach operations in flight.
- class AttachRequest {
- public:
- AttachRequest(int element_instance_id,
- int guest_instance_id,
- scoped_ptr<base::DictionaryValue> params,
- v8::Handle<v8::Function> callback,
- v8::Isolate* isolate);
- ~AttachRequest();
-
- int element_instance_id() const { return element_instance_id_; }
-
- int guest_instance_id() const { return guest_instance_id_; }
-
- base::DictionaryValue* attach_params() const {
- return params_.get();
- }
-
- bool HasCallback() const;
-
- v8::Handle<v8::Function> GetCallback() const;
-
- v8::Isolate* isolate() const { return isolate_; }
-
- private:
- const int element_instance_id_;
- const int guest_instance_id_;
- scoped_ptr<base::DictionaryValue> params_;
- ScopedPersistent<v8::Function> callback_;
- v8::Isolate* const isolate_;
- };
-
- GuestViewContainer(content::RenderFrame* render_frame,
- const std::string& mime_type);
+ explicit GuestViewContainer(content::RenderFrame* render_frame);
~GuestViewContainer() override;
- static GuestViewContainer* FromID(int render_view_routing_id,
- int element_instance_id);
-
- void AttachGuest(linked_ptr<AttachRequest> request);
-
// BrowserPluginDelegate implementation.
void SetElementInstanceID(int element_instance_id) override;
- void DidFinishLoading() override;
- void DidReceiveData(const char* data, int data_length) override;
- void Ready() override;
// RenderFrameObserver override.
void OnDestruct() override;
bool OnMessageReceived(const IPC::Message& message) override;
- private:
- void OnCreateMimeHandlerViewGuestACK(int element_instance_id);
- void OnGuestAttached(int element_instance_id, int guest_proxy_routing_id);
-
- void AttachGuestInternal(linked_ptr<AttachRequest> request);
- void EnqueueAttachRequest(linked_ptr<AttachRequest> request);
- void PerformPendingAttachRequest();
- void HandlePendingResponseCallback(int guest_proxy_routing_id);
+ virtual bool HandlesMessage(const IPC::Message& message) = 0;
+ virtual bool OnMessage(const IPC::Message& message) = 0;
- static bool ShouldHandleMessage(const IPC::Message& mesage);
+ protected:
+ int element_instance_id() const { return element_instance_id_; }
+ int render_view_routing_id() const { return render_view_routing_id_; }
- const std::string mime_type_;
+ private:
int element_instance_id_;
- std::string html_string_;
- // Save the RenderView RoutingID here so that we can use it during
- // destruction.
int render_view_routing_id_;
- bool attached_;
- bool ready_;
-
- std::deque<linked_ptr<AttachRequest> > pending_requests_;
- linked_ptr<AttachRequest> pending_response_;
-
DISALLOW_COPY_AND_ASSIGN(GuestViewContainer);
};
} // namespace extensions
-#endif // CHROME_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_
+#endif // EXTENSIONS_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_
diff --git a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc
index 356fac3..69f70e8 100644
--- a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc
+++ b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc
@@ -11,7 +11,7 @@
#include "content/public/renderer/v8_value_converter.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_messages.h"
-#include "extensions/renderer/guest_view/guest_view_container.h"
+#include "extensions/renderer/guest_view/extensions_guest_view_container.h"
#include "extensions/renderer/script_context.h"
#include "v8/include/v8.h"
@@ -41,11 +41,11 @@ void GuestViewInternalCustomBindings::AttachGuest(
CHECK(args.Length() < 4 || args[3]->IsFunction());
int element_instance_id = args[0]->Int32Value();
- // An element instance ID uniquely identifies a GuestViewContainer within
- // a RenderView.
- GuestViewContainer* guest_view_container =
- GuestViewContainer::FromID(context()->GetRenderView()->GetRoutingID(),
- element_instance_id);
+ // An element instance ID uniquely identifies a ExtensionsGuestViewContainer
+ // within a RenderView.
+ ExtensionsGuestViewContainer* guest_view_container =
+ ExtensionsGuestViewContainer::FromID(
+ context()->GetRenderView()->GetRoutingID(), element_instance_id);
// TODO(fsamuel): Should we be reporting an error if the element instance ID
// is invalid?
@@ -64,8 +64,8 @@ void GuestViewInternalCustomBindings::AttachGuest(
static_cast<base::DictionaryValue*>(params_as_value.release()));
}
- linked_ptr<GuestViewContainer::AttachRequest> request(
- new GuestViewContainer::AttachRequest(
+ linked_ptr<ExtensionsGuestViewContainer::AttachRequest> request(
+ new ExtensionsGuestViewContainer::AttachRequest(
element_instance_id,
guest_instance_id,
params.Pass(),
diff --git a/extensions/renderer/guest_view/mime_handler_view_container.cc b/extensions/renderer/guest_view/mime_handler_view_container.cc
new file mode 100644
index 0000000..ce2868c
--- /dev/null
+++ b/extensions/renderer/guest_view/mime_handler_view_container.cc
@@ -0,0 +1,56 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/renderer/guest_view/mime_handler_view_container.h"
+
+#include "content/public/renderer/render_frame.h"
+#include "extensions/common/extension_messages.h"
+#include "extensions/common/guest_view/guest_view_constants.h"
+
+namespace extensions {
+
+MimeHandlerViewContainer::MimeHandlerViewContainer(
+ content::RenderFrame* render_frame,
+ const std::string& mime_type)
+ : GuestViewContainer(render_frame),
+ mime_type_(mime_type) {
+ DCHECK(!mime_type_.empty());
+}
+
+MimeHandlerViewContainer::~MimeHandlerViewContainer() {}
+
+void MimeHandlerViewContainer::DidFinishLoading() {
+ DCHECK_NE(element_instance_id(), guestview::kInstanceIDNone);
+ render_frame()->Send(new ExtensionHostMsg_CreateMimeHandlerViewGuest(
+ routing_id(), html_string_, mime_type_, element_instance_id()));
+}
+
+void MimeHandlerViewContainer::DidReceiveData(const char* data,
+ int data_length) {
+ std::string value(data, data_length);
+ html_string_ += value;
+}
+
+bool MimeHandlerViewContainer::HandlesMessage(const IPC::Message& message) {
+ return message.type() == ExtensionMsg_CreateMimeHandlerViewGuestACK::ID;
+}
+
+bool MimeHandlerViewContainer::OnMessage(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(MimeHandlerViewContainer, message)
+ IPC_MESSAGE_HANDLER(ExtensionMsg_CreateMimeHandlerViewGuestACK,
+ OnCreateMimeHandlerViewGuestACK)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void MimeHandlerViewContainer::OnCreateMimeHandlerViewGuestACK(
+ int element_instance_id) {
+ DCHECK_NE(this->element_instance_id(), guestview::kInstanceIDNone);
+ DCHECK_EQ(this->element_instance_id(), element_instance_id);
+ render_frame()->AttachGuest(element_instance_id);
+}
+
+} // namespace extensions
diff --git a/extensions/renderer/guest_view/mime_handler_view_container.h b/extensions/renderer/guest_view/mime_handler_view_container.h
new file mode 100644
index 0000000..72c9347
--- /dev/null
+++ b/extensions/renderer/guest_view/mime_handler_view_container.h
@@ -0,0 +1,37 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_
+#define EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_
+
+#include "extensions/renderer/guest_view/guest_view_container.h"
+
+namespace extensions {
+
+class MimeHandlerViewContainer : public GuestViewContainer {
+ public:
+ MimeHandlerViewContainer(content::RenderFrame* render_frame,
+ const std::string& mime_type);
+ ~MimeHandlerViewContainer() override;
+
+ // BrowserPluginDelegate implementation.
+ void DidFinishLoading() override;
+ void DidReceiveData(const char* data, int data_length) override;
+
+ // GuestViewContainer override.
+ bool HandlesMessage(const IPC::Message& message) override;
+ bool OnMessage(const IPC::Message& message) override;
+
+ private:
+ void OnCreateMimeHandlerViewGuestACK(int element_instance_id);
+
+ const std::string mime_type_;
+ std::string html_string_;
+
+ DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewContainer);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_