blob: ab364af49904c59e62f6745df27790c38d3ea6b4 [file] [log] [blame]
tommycli425d69652015-06-11 22:20:141// 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/values.h"
Nicholas Verne1e3c25bfd2017-09-07 04:24:299#include "chrome/common/plugin.mojom.h"
tommycli425d69652015-06-11 22:20:1410#include "chrome/grit/renderer_resources.h"
11#include "components/plugins/renderer/plugin_placeholder.h"
sdefresne6c550eed2016-02-17 18:45:4712#include "components/strings/grit/components_strings.h"
tommycli425d69652015-06-11 22:20:1413#include "content/app/strings/grit/content_strings.h"
Nicholas Verne1e3c25bfd2017-09-07 04:24:2914#include "content/public/renderer/render_frame.h"
Blink Reformata30d4232018-04-07 15:31:0615#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
tommycli425d69652015-06-11 22:20:1416#include "ui/base/l10n/l10n_util.h"
17#include "ui/base/resource/resource_bundle.h"
18#include "ui/base/webui/jstemplate_builder.h"
19
20// static
21plugins::PluginPlaceholder*
22NonLoadablePluginPlaceholder::CreateNotSupportedPlugin(
23 content::RenderFrame* render_frame,
tommycli425d69652015-06-11 22:20:1424 const blink::WebPluginParams& params) {
25 const base::StringPiece template_html(
Lei Zhang7640d542017-10-03 16:26:4926 ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
tommycli425d69652015-06-11 22:20:1427 IDR_BLOCKED_PLUGIN_HTML));
28
29 base::DictionaryValue values;
30 values.SetString("message",
31 l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_SUPPORTED));
32
33 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
34
35 // PluginPlaceholder will destroy itself when its WebViewPlugin is going away.
thestigf7d2fa12017-05-05 19:11:4336 return new plugins::PluginPlaceholder(render_frame, params, html_data);
tommycli425d69652015-06-11 22:20:1437}
38
39// static
40plugins::PluginPlaceholder* NonLoadablePluginPlaceholder::CreateErrorPlugin(
41 content::RenderFrame* render_frame,
42 const base::FilePath& file_path) {
43 base::DictionaryValue values;
44 values.SetString("message",
45 l10n_util::GetStringUTF8(IDS_PLUGIN_INITIALIZATION_ERROR));
46
47 const base::StringPiece template_html(
Lei Zhang7640d542017-10-03 16:26:4948 ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
tommycli425d69652015-06-11 22:20:1449 IDR_BLOCKED_PLUGIN_HTML));
50 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
51
52 blink::WebPluginParams params;
53 // PluginPlaceholder will destroy itself when its WebViewPlugin is going away.
54 plugins::PluginPlaceholder* plugin =
thestigf7d2fa12017-05-05 19:11:4355 new plugins::PluginPlaceholder(render_frame, params, html_data);
tommycli425d69652015-06-11 22:20:1456
Nicholas Verne1e3c25bfd2017-09-07 04:24:2957 chrome::mojom::PluginHostAssociatedPtr plugin_host;
58 render_frame->GetRemoteAssociatedInterfaces()->GetInterface(&plugin_host);
59 plugin_host->CouldNotLoadPlugin(file_path);
60
tommycli425d69652015-06-11 22:20:1461 return plugin;
62}