Fix scale on axis may be negative.
[chromium-blink-merge.git] / chrome / browser / guestview / webview / plugin_permission_helper.cc
bloba014c530b76683547fa3089d244bc419432a52dc
1 // Copyright 2014 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/browser/guestview/webview/plugin_permission_helper.h"
7 #include "chrome/browser/guestview/webview/webview_guest.h"
8 #include "chrome/browser/guestview/webview/webview_permission_types.h"
9 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
10 #include "chrome/common/render_messages.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/user_metrics.h"
15 using content::BrowserPluginGuestDelegate;
16 using content::RenderViewHost;
17 using content::WebContents;
19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PluginPermissionHelper);
21 PluginPermissionHelper::PluginPermissionHelper(WebContents* contents)
22 : content::WebContentsObserver(contents),
23 weak_factory_(this) {
26 PluginPermissionHelper::~PluginPermissionHelper() {
29 bool PluginPermissionHelper::OnMessageReceived(const IPC::Message& message) {
30 IPC_BEGIN_MESSAGE_MAP(PluginPermissionHelper, message)
31 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedUnauthorizedPlugin,
32 OnBlockedUnauthorizedPlugin)
33 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin,
34 OnCouldNotLoadPlugin)
35 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin,
36 OnBlockedOutdatedPlugin)
37 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_NPAPINotSupported,
38 OnNPAPINotSupported)
39 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins,
40 OnOpenAboutPlugins)
41 #if defined(ENABLE_PLUGIN_INSTALLATION)
42 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FindMissingPlugin,
43 OnFindMissingPlugin)
44 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost,
45 OnRemovePluginPlaceholderHost)
46 #endif
47 IPC_MESSAGE_UNHANDLED(return false)
48 IPC_END_MESSAGE_MAP()
50 return true;
53 void PluginPermissionHelper::OnBlockedUnauthorizedPlugin(
54 const base::string16& name,
55 const std::string& identifier) {
56 const char kPluginName[] = "name";
57 const char kPluginIdentifier[] = "identifier";
59 WebViewGuest* webview = WebViewGuest::FromWebContents(web_contents());
60 if (!webview)
61 return;
63 base::DictionaryValue info;
64 info.SetString(std::string(kPluginName), name);
65 info.SetString(std::string(kPluginIdentifier), identifier);
66 webview->RequestPermission(static_cast<BrowserPluginPermissionType>(
67 WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN),
68 info,
69 base::Bind(&PluginPermissionHelper::OnPermissionResponse,
70 weak_factory_.GetWeakPtr(),
71 identifier),
72 true /* allowed_by_default */);
73 content::RecordAction(
74 base::UserMetricsAction("WebView.Guest.PluginLoadRequest"));
77 void PluginPermissionHelper::OnCouldNotLoadPlugin(
78 const base::FilePath& plugin_path) {
81 void PluginPermissionHelper::OnBlockedOutdatedPlugin(
82 int placeholder_id,
83 const std::string& identifier) {
86 void PluginPermissionHelper::OnNPAPINotSupported(const std::string& id) {
89 void PluginPermissionHelper::OnOpenAboutPlugins() {
92 #if defined(ENABLE_PLUGIN_INSTALLATION)
93 void PluginPermissionHelper::OnFindMissingPlugin(int placeholder_id,
94 const std::string& mime_type) {
95 Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id));
98 void PluginPermissionHelper::OnRemovePluginPlaceholderHost(int placeholder_id) {
100 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
102 void PluginPermissionHelper::OnPermissionResponse(const std::string& identifier,
103 bool allow,
104 const std::string& input) {
105 if (allow) {
106 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins(
107 web_contents(), true, identifier);