Force flash and silverlight plugins to windowless mode when using off-screen rendering (issue #518).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1285 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2013-06-24 16:40:40 +00:00
parent d6d93bd490
commit 7e259aa9f2
4 changed files with 99 additions and 3 deletions

View File

@ -260,10 +260,12 @@ bool CefBrowserImpl::SendProcessMessage(CefProcessId target_process,
CefBrowserImpl::CefBrowserImpl(content::RenderView* render_view, CefBrowserImpl::CefBrowserImpl(content::RenderView* render_view,
int browser_id, int browser_id,
bool is_popup) bool is_popup,
bool is_window_rendering_disabled)
: content::RenderViewObserver(render_view), : content::RenderViewObserver(render_view),
browser_id_(browser_id), browser_id_(browser_id),
is_popup_(is_popup), is_popup_(is_popup),
is_window_rendering_disabled_(is_window_rendering_disabled),
last_focused_frame_id_(kInvalidFrameId) { last_focused_frame_id_(kInvalidFrameId) {
response_manager_.reset(new CefResponseManager); response_manager_.reset(new CefResponseManager);
} }

View File

@ -79,7 +79,8 @@ class CefBrowserImpl : public CefBrowser,
CefBrowserImpl(content::RenderView* render_view, CefBrowserImpl(content::RenderView* render_view,
int browser_id, int browser_id,
bool is_popup); bool is_popup,
bool is_window_rendering_disabled);
virtual ~CefBrowserImpl(); virtual ~CefBrowserImpl();
void LoadRequest(const CefMsg_LoadRequest_Params& params); void LoadRequest(const CefMsg_LoadRequest_Params& params);
@ -99,6 +100,9 @@ class CefBrowserImpl : public CefBrowser,
int browser_id() const { return browser_id_; } int browser_id() const { return browser_id_; }
bool is_popup() const { return is_popup_; } bool is_popup() const { return is_popup_; }
bool is_window_rendering_disabled() const {
return is_window_rendering_disabled_;
}
content::RenderView* render_view() { content::RenderView* render_view() {
return content::RenderViewObserver::render_view(); return content::RenderViewObserver::render_view();
} }
@ -124,6 +128,7 @@ class CefBrowserImpl : public CefBrowser,
// same browser ID. // same browser ID.
int browser_id_; int browser_id_;
bool is_popup_; bool is_popup_;
bool is_window_rendering_disabled_;
// Id of the last frame that had focus. // Id of the last frame that had focus.
int64 last_focused_frame_id_; int64 last_focused_frame_id_;

View File

@ -34,15 +34,19 @@ MSVC_POP_WARNING();
#include "content/child/child_thread.h" #include "content/child/child_thread.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/common/content_constants.h"
#include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h" #include "content/public/renderer/render_view.h"
#include "content/renderer/render_view_impl.h"
#include "ipc/ipc_sync_channel.h" #include "ipc/ipc_sync_channel.h"
#include "media/base/media.h" #include "media/base/media.h"
#include "third_party/WebKit/public/platform/WebPrerenderingSupport.h" #include "third_party/WebKit/public/platform/WebPrerenderingSupport.h"
#include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h" #include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/platform/WebWorkerRunLoop.h" #include "third_party/WebKit/public/platform/WebWorkerRunLoop.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFrame.h" #include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebPluginParams.h"
#include "third_party/WebKit/public/web/WebPrerendererClient.h" #include "third_party/WebKit/public/web/WebPrerendererClient.h"
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h" #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#include "third_party/WebKit/public/web/WebSecurityPolicy.h" #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
@ -432,7 +436,8 @@ void CefContentRendererClient::RenderViewCreated(
#endif #endif
CefRefPtr<CefBrowserImpl> browser = CefRefPtr<CefBrowserImpl> browser =
new CefBrowserImpl(render_view, params.browser_id, params.is_popup); new CefBrowserImpl(render_view, params.browser_id, params.is_popup,
params.is_window_rendering_disabled);
browsers_.insert(std::make_pair(render_view, browser)); browsers_.insert(std::make_pair(render_view, browser));
new CefPrerendererClient(render_view); new CefPrerendererClient(render_view);
@ -447,6 +452,85 @@ void CefContentRendererClient::RenderViewCreated(
} }
} }
bool CefContentRendererClient::OverrideCreatePlugin(
content::RenderView* render_view,
WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params,
WebKit::WebPlugin** plugin) {
CefRefPtr<CefBrowserImpl> browser =
CefBrowserImpl::GetBrowserForMainFrame(frame->top());
if (!browser || !browser->is_window_rendering_disabled())
return false;
#if defined(ENABLE_PLUGINS)
if (UTF16ToASCII(params.mimeType) == content::kBrowserPluginMimeType)
return false;
content::RenderViewImpl* render_view_impl =
static_cast<content::RenderViewImpl*>(render_view);
webkit::WebPluginInfo info;
std::string mime_type;
bool found = render_view_impl->GetPluginInfo(params.url,
frame->top()->document().url(),
params.mimeType.utf8(),
&info,
&mime_type);
if (!found)
return false;
bool flash = LowerCaseEqualsASCII(mime_type,
"application/x-shockwave-flash");
bool silverlight = StartsWithASCII(mime_type,
"application/x-silverlight", false);
if (flash) {
// "wmode" values of "opaque" or "transparent" are allowed.
size_t size = params.attributeNames.size();
for (size_t i = 0; i < size; ++i) {
std::string name = params.attributeNames[i].utf8();
if (name == "wmode") {
std::string value = params.attributeValues[i].utf8();
if (value == "opaque" || value == "transparent")
flash = false;
break;
}
}
}
if (flash || silverlight) {
// Force Flash and Silverlight plugins to use windowless mode.
WebKit::WebPluginParams params_to_use = params;
params_to_use.mimeType = WebKit::WebString::fromUTF8(mime_type);
size_t size = params.attributeNames.size();
WebKit::WebVector<WebKit::WebString> new_names(size+1),
new_values(size+1);
for (size_t i = 0; i < size; ++i) {
new_names[i] = params.attributeNames[i];
new_values[i] = params.attributeValues[i];
}
if (flash) {
new_names[size] = "wmode";
new_values[size] = "opaque";
} else if (silverlight) {
new_names[size] = "windowless";
new_values[size] = "true";
}
params_to_use.attributeNames.swap(new_names);
params_to_use.attributeValues.swap(new_values);
*plugin = render_view_impl->CreatePlugin(frame, info, params_to_use);
return true;
}
#endif // defined(ENABLE_PLUGINS)
return false;
}
bool CefContentRendererClient::HandleNavigation( bool CefContentRendererClient::HandleNavigation(
WebKit::WebFrame* frame, WebKit::WebFrame* frame,
const WebKit::WebURLRequest& request, const WebKit::WebURLRequest& request,

View File

@ -76,6 +76,11 @@ class CefContentRendererClient : public content::ContentRendererClient,
// ContentRendererClient implementation. // ContentRendererClient implementation.
virtual void RenderThreadStarted() OVERRIDE; virtual void RenderThreadStarted() OVERRIDE;
virtual void RenderViewCreated(content::RenderView* render_view) OVERRIDE; virtual void RenderViewCreated(content::RenderView* render_view) OVERRIDE;
virtual bool OverrideCreatePlugin(
content::RenderView* render_view,
WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params,
WebKit::WebPlugin** plugin) OVERRIDE;
virtual bool HandleNavigation(WebKit::WebFrame* frame, virtual bool HandleNavigation(WebKit::WebFrame* frame,
const WebKit::WebURLRequest& request, const WebKit::WebURLRequest& request,
WebKit::WebNavigationType type, WebKit::WebNavigationType type,