Commit 040df725 authored by Ehsan Karamad's avatar Ehsan Karamad Committed by Commit Bot

Refactor MimeHandlerViewContainer to use with cross-process version

MimeHandlerViewContainer implements the renderer side of logic for
embedding the MimeHandlerView extension. The logic is currently based
on a GuestViewContainer which internally uses a WebPlugin
(BrowserPlugin).

MimeHandlerView will eventually get implemented on top of cross-process
frames architecture; requiring its owner container class on the
embedder side.

This CL will extract the common code between the current BrowserPlugin
version and the forthcoming frame-based version into a base class so
that the similar code between the two containers is not duplicated.

The common code includes a) logic in creating MimeHandlerViewGuest,
b) support for network service and c) support for post message.

Bug: 659750
Change-Id: Iabe44b1438fc22aa052b1ebf6d8696bdca00d0c9
Reviewed-on: https://chromium-review.googlesource.com/1170564Reviewed-by: default avatarJames MacLean <wjmaclean@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarEhsan Karamad <ekaramad@chromium.org>
Commit-Queue: Ehsan Karamad <ekaramad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582504}
parent 3f46aed8
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h" #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container_base.h"
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_EXTENSIONS)
ChromePrintRenderFrameHelperDelegate::ChromePrintRenderFrameHelperDelegate() = ChromePrintRenderFrameHelperDelegate::ChromePrintRenderFrameHelperDelegate() =
...@@ -75,8 +75,8 @@ bool ChromePrintRenderFrameHelperDelegate::OverridePrint( ...@@ -75,8 +75,8 @@ bool ChromePrintRenderFrameHelperDelegate::OverridePrint(
if (!frame->GetDocument().IsPluginDocument()) if (!frame->GetDocument().IsPluginDocument())
return false; return false;
std::vector<extensions::MimeHandlerViewContainer*> mime_handlers = std::vector<extensions::MimeHandlerViewContainerBase*> mime_handlers =
extensions::MimeHandlerViewContainer::FromRenderFrame( extensions::MimeHandlerViewContainerBase::FromRenderFrame(
content::RenderFrame::FromWebFrame(frame)); content::RenderFrame::FromWebFrame(frame));
if (!mime_handlers.empty()) { if (!mime_handlers.empty()) {
// This message is handled in chrome/browser/resources/pdf/pdf_viewer.js and // This message is handled in chrome/browser/resources/pdf/pdf_viewer.js and
......
...@@ -139,6 +139,8 @@ jumbo_source_set("renderer") { ...@@ -139,6 +139,8 @@ jumbo_source_set("renderer") {
"guest_view/guest_view_internal_custom_bindings.h", "guest_view/guest_view_internal_custom_bindings.h",
"guest_view/mime_handler_view/mime_handler_view_container.cc", "guest_view/mime_handler_view/mime_handler_view_container.cc",
"guest_view/mime_handler_view/mime_handler_view_container.h", "guest_view/mime_handler_view/mime_handler_view_container.h",
"guest_view/mime_handler_view/mime_handler_view_container_base.cc",
"guest_view/mime_handler_view/mime_handler_view_container_base.h",
"i18n_custom_bindings.cc", "i18n_custom_bindings.cc",
"i18n_custom_bindings.h", "i18n_custom_bindings.h",
"i18n_hooks_delegate.cc", "i18n_hooks_delegate.cc",
......
...@@ -10,28 +10,12 @@ ...@@ -10,28 +10,12 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h" #include "base/optional.h"
#include "components/guest_view/renderer/guest_view_container.h" #include "components/guest_view/renderer/guest_view_container.h"
#include "content/public/common/transferrable_url_loader.mojom.h" #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container_base.h"
#include "extensions/common/api/mime_handler.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "third_party/blink/public/web/web_associated_url_loader_client.h"
#include "ui/gfx/geometry/size.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
namespace blink {
class WebAssociatedURLLoader;
} // namespace blink
namespace content {
class URLLoaderThrottle;
struct WebPluginInfo;
} // namespace content
namespace extensions { namespace extensions {
// A container for loading up an extension inside a BrowserPlugin to handle a // A container for loading up an extension inside a BrowserPlugin to handle a
...@@ -51,17 +35,13 @@ namespace extensions { ...@@ -51,17 +35,13 @@ namespace extensions {
// |didFinishLoading| (from WebAssociatedURLLoaderClient) when data is // |didFinishLoading| (from WebAssociatedURLLoaderClient) when data is
// received and when it has finished being received. // received and when it has finished being received.
class MimeHandlerViewContainer : public guest_view::GuestViewContainer, class MimeHandlerViewContainer : public guest_view::GuestViewContainer,
public blink::WebAssociatedURLLoaderClient, public MimeHandlerViewContainerBase {
public mime_handler::BeforeUnloadControl {
public: public:
MimeHandlerViewContainer(content::RenderFrame* render_frame, MimeHandlerViewContainer(content::RenderFrame* render_frame,
const content::WebPluginInfo& info, const content::WebPluginInfo& info,
const std::string& mime_type, const std::string& mime_type,
const GURL& original_url); const GURL& original_url);
static std::vector<MimeHandlerViewContainer*> FromRenderFrame(
content::RenderFrame* render_frame);
// GuestViewContainer implementation. // GuestViewContainer implementation.
bool OnMessage(const IPC::Message& message) override; bool OnMessage(const IPC::Message& message) override;
void OnReady() override; void OnReady() override;
...@@ -79,30 +59,21 @@ class MimeHandlerViewContainer : public guest_view::GuestViewContainer, ...@@ -79,30 +59,21 @@ class MimeHandlerViewContainer : public guest_view::GuestViewContainer,
// GuestViewContainer overrides. // GuestViewContainer overrides.
void OnRenderFrameDestroyed() override; void OnRenderFrameDestroyed() override;
// Post a JavaScript message to the guest.
void PostJavaScriptMessage(v8::Isolate* isolate,
v8::Local<v8::Value> message);
// Post |message| to the guest.
void PostMessageFromValue(const base::Value& message);
// If the URL matches the same URL that this object has created and it hasn't
// added a throttle yet, it will return a new one for the purpose of
// intercepting it.
std::unique_ptr<content::URLLoaderThrottle> MaybeCreatePluginThrottle(
const GURL& url);
protected: protected:
~MimeHandlerViewContainer() override; ~MimeHandlerViewContainer() override;
private: private:
class PluginResourceThrottle; // MimeHandlerViewContainerBase override.
content::RenderFrame* GetEmbedderRenderFrame() const final;
void CreateMimeHandlerViewGuestIfNecessary() final;
blink::WebFrame* GetGuestProxyFrame() const final;
int32_t GetInstanceId() const final;
gfx::Size GetElementSize() const final;
// Called for embedded plugins when network service is enabled. This is called // mime_handler::BeforeUnloadControl implementation.
// by the URLLoaderThrottle which intercepts the resource load, which is then void SetShowBeforeUnloadDialog(
// sent to the browser to be handed off to the plugin. bool show_dialog,
void SetEmbeddedLoader( SetShowBeforeUnloadDialogCallback callback) override;
content::mojom::TransferrableURLLoaderPtr transferrable_url_loader);
// Message handlers. // Message handlers.
void OnCreateMimeHandlerViewGuestACK(int element_instance_id); void OnCreateMimeHandlerViewGuestACK(int element_instance_id);
...@@ -110,65 +81,12 @@ class MimeHandlerViewContainer : public guest_view::GuestViewContainer, ...@@ -110,65 +81,12 @@ class MimeHandlerViewContainer : public guest_view::GuestViewContainer,
int guest_proxy_routing_id); int guest_proxy_routing_id);
void OnMimeHandlerViewGuestOnLoadCompleted(int element_instance_id); void OnMimeHandlerViewGuestOnLoadCompleted(int element_instance_id);
// Creates a guest when a geometry and the URL of the extension to navigate
// to are available.
void CreateMimeHandlerViewGuestIfNecessary();
// mime_handler::BeforeUnloadControl implementation.
void SetShowBeforeUnloadDialog(
bool show_dialog,
SetShowBeforeUnloadDialogCallback callback) override;
// Path of the plugin.
const std::string plugin_path_;
// The MIME type of the plugin.
const std::string mime_type_;
// The URL of the extension to navigate to.
std::string view_id_;
// Whether the plugin is embedded or not.
bool is_embedded_;
// The original URL of the plugin.
GURL original_url_;
// The RenderView routing ID of the guest. // The RenderView routing ID of the guest.
int guest_proxy_routing_id_; int guest_proxy_routing_id_;
// Used when network service is enabled:
bool waiting_to_create_throttle_ = false;
content::mojom::TransferrableURLLoaderPtr transferrable_url_loader_;
// Used when network service is disabled:
// A URL loader to load the |original_url_| when the plugin is embedded. In
// the embedded case, no URL request is made automatically.
std::unique_ptr<blink::WebAssociatedURLLoader> loader_;
// The scriptable object that backs the plugin.
v8::Global<v8::Object> scriptable_object_;
// Pending postMessage messages that need to be sent to the guest. These are
// queued while the guest is loading and once it is fully loaded they are
// delivered so that messages aren't lost.
std::vector<v8::Global<v8::Value>> pending_messages_;
// True if a guest process has been requested.
bool guest_created_ = false;
// True if the guest page has fully loaded and its JavaScript onload function
// has been called.
bool guest_loaded_;
// The size of the element. // The size of the element.
base::Optional<gfx::Size> element_size_; base::Optional<gfx::Size> element_size_;
mojo::Binding<mime_handler::BeforeUnloadControl>
before_unload_control_binding_;
base::WeakPtrFactory<MimeHandlerViewContainer> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewContainer); DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewContainer);
}; };
......
// Copyright 2018 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_MIME_HANDLER_VIEW_CONTAINER_BASE_H_
#define EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_VIEW_CONTAINER_BASE_H_
#include <vector>
#include "base/macros.h"
#include "content/public/common/transferrable_url_loader.mojom.h"
#include "extensions/common/api/mime_handler.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "third_party/blink/public/web/web_associated_url_loader_client.h"
#include "ui/gfx/geometry/size.h"
#include "url/gurl.h"
#include "v8/include/v8.h"
namespace blink {
class WebAssociatedURLLoader;
class WebFrame;
} // namespace blink
namespace content {
class RenderFrame;
class URLLoaderThrottle;
struct WebPluginInfo;
} // namespace content
namespace extensions {
// A base class for MimeHandlerViewContainer which provides a way of reusing the
// common logic between the BrowserPlugin-based and frame-based container.
class MimeHandlerViewContainerBase : public blink::WebAssociatedURLLoaderClient,
public mime_handler::BeforeUnloadControl {
public:
MimeHandlerViewContainerBase(content::RenderFrame* embedder_render_frame,
const content::WebPluginInfo& info,
const std::string& mime_type,
const GURL& original_url);
~MimeHandlerViewContainerBase() override;
static std::vector<MimeHandlerViewContainerBase*> FromRenderFrame(
content::RenderFrame* render_frame);
// If the URL matches the same URL that this object has created and it hasn't
// added a throttle yet, it will return a new one for the purpose of
// intercepting it.
std::unique_ptr<content::URLLoaderThrottle> MaybeCreatePluginThrottle(
const GURL& url);
// Post a JavaScript message to the guest.
void PostJavaScriptMessage(v8::Isolate* isolate,
v8::Local<v8::Value> message);
// Post |message| to the guest.
void PostMessageFromValue(const base::Value& message);
protected:
// Returns the frame which is embedding the corresponding plugin element.
virtual content::RenderFrame* GetEmbedderRenderFrame() const;
virtual void CreateMimeHandlerViewGuestIfNecessary() = 0;
virtual blink::WebFrame* GetGuestProxyFrame() const = 0;
virtual int32_t GetInstanceId() const = 0;
virtual gfx::Size GetElementSize() const = 0;
void DidCompleteLoad();
void SendResourceRequest();
void EmbedderRenderFrameWillBeGone();
v8::Local<v8::Object> GetScriptableObject(v8::Isolate* isolate);
bool guest_created() const { return guest_created_; }
// Used when network service is enabled:
bool waiting_to_create_throttle_ = false;
// The URL of the extension to navigate to.
std::string view_id_;
// Whether the plugin is embedded or not.
bool is_embedded_;
private:
class PluginResourceThrottle;
// Called for embedded plugins when network service is enabled. This is called
// by the URLLoaderThrottle which intercepts the resource load, which is then
// sent to the browser to be handed off to the plugin.
void SetEmbeddedLoader(
content::mojom::TransferrableURLLoaderPtr transferrable_url_loader);
// Path of the plugin.
const std::string plugin_path_;
// The MIME type of the plugin.
const std::string mime_type_;
// The original URL of the plugin.
const GURL original_url_;
// Used when network service is enabled:
content::mojom::TransferrableURLLoaderPtr transferrable_url_loader_;
// Used when network service is disabled:
// A URL loader to load the |original_url_| when the plugin is embedded. In
// the embedded case, no URL request is made automatically.
std::unique_ptr<blink::WebAssociatedURLLoader> loader_;
// The scriptable object that backs the plugin.
v8::Global<v8::Object> scriptable_object_;
// Pending postMessage messages that need to be sent to the guest. These are
// queued while the guest is loading and once it is fully loaded they are
// delivered so that messages aren't lost.
std::vector<v8::Global<v8::Value>> pending_messages_;
// True if a guest process has been requested.
bool guest_created_ = false;
// True if the guest page has fully loaded and its JavaScript onload function
// has been called.
bool guest_loaded_ = false;
mojo::Binding<mime_handler::BeforeUnloadControl>
before_unload_control_binding_;
base::WeakPtrFactory<MimeHandlerViewContainerBase> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewContainerBase);
};
} // namespace extensions
#endif // EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_VIEW_CONTAINER_BASE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment