1 // Copyright 2015 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.
4
5 #include "chrome/renderer/plugins/non_loadable_plugin_placeholder.h"
6
7 #include "base/files/file_path.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "chrome/common/plugin.mojom.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "chrome/grit/renderer_resources.h"
13 #include "components/plugins/renderer/plugin_placeholder.h"
14 #include "components/strings/grit/components_strings.h"
15 #include "content/public/renderer/render_frame.h"
16 #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
17 #include "third_party/blink/public/strings/grit/blink_strings.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/base/webui/jstemplate_builder.h"
21
22 namespace {
23
CreateNonLoadablePlaceholderHelper(content::RenderFrame * render_frame,const blink::WebPluginParams & params,const std::string & message)24 plugins::PluginPlaceholder* CreateNonLoadablePlaceholderHelper(
25 content::RenderFrame* render_frame,
26 const blink::WebPluginParams& params,
27 const std::string& message) {
28 std::string template_html =
29 ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
30 IDR_BLOCKED_PLUGIN_HTML);
31
32 base::DictionaryValue values;
33 values.SetString("name", "");
34 values.SetString("message", message);
35
36 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
37
38 // PluginPlaceholder will destroy itself when its WebViewPlugin is going away.
39 return new plugins::PluginPlaceholder(render_frame, params, html_data);
40 }
41
42 } // namespace
43
44 // static
45 plugins::PluginPlaceholder*
CreateNotSupportedPlugin(content::RenderFrame * render_frame,const blink::WebPluginParams & params)46 NonLoadablePluginPlaceholder::CreateNotSupportedPlugin(
47 content::RenderFrame* render_frame,
48 const blink::WebPluginParams& params) {
49 return CreateNonLoadablePlaceholderHelper(
50 render_frame, params, l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_SUPPORTED));
51 }
52
53 // static
54 plugins::PluginPlaceholder*
CreateFlashDeprecatedPlaceholder(content::RenderFrame * render_frame,const blink::WebPluginParams & params)55 NonLoadablePluginPlaceholder::CreateFlashDeprecatedPlaceholder(
56 content::RenderFrame* render_frame,
57 const blink::WebPluginParams& params) {
58 return CreateNonLoadablePlaceholderHelper(
59 render_frame, params,
60 l10n_util::GetStringFUTF8(IDS_PLUGIN_DEPRECATED,
61 base::ASCIIToUTF16("Adobe Flash Player")));
62 }
63
64 // static
CreateErrorPlugin(content::RenderFrame * render_frame,const base::FilePath & file_path)65 plugins::PluginPlaceholder* NonLoadablePluginPlaceholder::CreateErrorPlugin(
66 content::RenderFrame* render_frame,
67 const base::FilePath& file_path) {
68 base::DictionaryValue values;
69 values.SetString("name", "");
70 values.SetString("message",
71 l10n_util::GetStringUTF8(IDS_PLUGIN_INITIALIZATION_ERROR));
72
73 std::string template_html =
74 ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
75 IDR_BLOCKED_PLUGIN_HTML);
76 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
77
78 blink::WebPluginParams params;
79 // PluginPlaceholder will destroy itself when its WebViewPlugin is going away.
80 plugins::PluginPlaceholder* plugin =
81 new plugins::PluginPlaceholder(render_frame, params, html_data);
82
83 mojo::AssociatedRemote<chrome::mojom::PluginHost> plugin_host;
84 render_frame->GetRemoteAssociatedInterfaces()->GetInterface(&plugin_host);
85 plugin_host->CouldNotLoadPlugin(file_path);
86
87 return plugin;
88 }
89