1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/renderer/plugins/shadow_dom_plugin_placeholder.h"
7 #include "base/command_line.h"
8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/render_messages.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "chrome/renderer/plugins/plugin_uma.h"
12 #include "content/public/renderer/render_frame.h"
13 #include "third_party/WebKit/public/web/WebDocument.h"
14 #include "third_party/WebKit/public/web/WebLocalFrame.h"
15 #include "third_party/WebKit/public/web/WebPluginParams.h"
16 #include "ui/base/l10n/l10n_util.h"
20 class MissingPluginPlaceholder
: public blink::WebPluginPlaceholder
{
22 // blink::WebPluginPlaceholder overrides
23 blink::WebString
message() const override
{
24 // TODO(jbroman): IDS_PLUGIN_SEARCHING if ENABLE_PLUGIN_INSTALLATION
25 return l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED
);
31 bool ShadowDOMPluginPlaceholderEnabled() {
32 return base::CommandLine::ForCurrentProcess()->HasSwitch(
33 switches::kEnablePluginPlaceholderShadowDom
);
36 scoped_ptr
<blink::WebPluginPlaceholder
> CreateShadowDOMPlaceholderForPluginInfo(
37 content::RenderFrame
* render_frame
,
38 blink::WebLocalFrame
* frame
,
39 const blink::WebPluginParams
& orig_params
) {
40 using Status
= ChromeViewHostMsg_GetPluginInfo_Status
;
42 if (!ShadowDOMPluginPlaceholderEnabled())
45 std::string orig_mime_type
= orig_params
.mimeType
.utf8();
46 // TODO(jbroman): Investigate whether browser plugin needs special handling.
47 ChromeViewHostMsg_GetPluginInfo_Output output
;
48 #if defined(ENABLE_PLUGINS)
50 new ChromeViewHostMsg_GetPluginInfo(render_frame
->GetRoutingID(),
51 GURL(orig_params
.url
),
52 frame
->top()->document().url(),
56 output
.status
.value
= Status::kNotFound
;
59 if (output
.status
.value
== Status::kNotFound
) {
60 // TODO(jbroman): Handle YouTube specially here, as in
61 // ChromeContentRendererClient::CreatePlugin.
62 PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type
,
64 return CreateShadowDOMPlaceholderForMissingPlugin();
70 scoped_ptr
<blink::WebPluginPlaceholder
>
71 CreateShadowDOMPlaceholderForMissingPlugin() {
72 return make_scoped_ptr(new MissingPluginPlaceholder
);