| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/plugins/missing_plugin.h" | 5 #include "chrome/renderer/plugins/missing_plugin.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
| 9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 void MissingPlugin::HideCallback(const CppArgumentList& args, | 92 void MissingPlugin::HideCallback(const CppArgumentList& args, |
| 93 CppVariant* result) { | 93 CppVariant* result) { |
| 94 RenderThread::Get()->RecordUserMetrics("MissingPlugin_Hide_Click"); | 94 RenderThread::Get()->RecordUserMetrics("MissingPlugin_Hide_Click"); |
| 95 HidePluginInternal(); | 95 HidePluginInternal(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void MissingPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) { | 98 void MissingPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) { |
| 99 WebContextMenuData menu_data; | 99 WebContextMenuData menu_data; |
| 100 | 100 |
| 101 WebVector<WebMenuItemInfo> custom_items(static_cast<size_t>(3)); | 101 WebVector<WebMenuItemInfo> custom_items(static_cast<size_t>(4)); |
| 102 | 102 |
| 103 size_t i = 0; | 103 size_t i = 0; |
| 104 WebMenuItemInfo mime_type_item; | 104 WebMenuItemInfo mime_type_item; |
| 105 mime_type_item.label = mime_type_; | 105 mime_type_item.label = mime_type_; |
| 106 mime_type_item.hasTextDirectionOverride = false; | 106 mime_type_item.hasTextDirectionOverride = false; |
| 107 mime_type_item.textDirection = WebKit::WebTextDirectionDefault; | 107 mime_type_item.textDirection = WebKit::WebTextDirectionDefault; |
| 108 custom_items[i++] = mime_type_item; | 108 custom_items[i++] = mime_type_item; |
| 109 | 109 |
| 110 WebMenuItemInfo separator_item; | 110 WebMenuItemInfo separator_item; |
| 111 separator_item.type = WebMenuItemInfo::Separator; | 111 separator_item.type = WebMenuItemInfo::Separator; |
| 112 custom_items[i++] = separator_item; | 112 custom_items[i++] = separator_item; |
| 113 | 113 |
| 114 WebMenuItemInfo hide_item; | 114 WebMenuItemInfo hide_item; |
| 115 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE; | 115 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE; |
| 116 hide_item.enabled = true; | 116 hide_item.enabled = true; |
| 117 hide_item.label = WebString::fromUTF8( | 117 hide_item.label = WebString::fromUTF8( |
| 118 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str()); | 118 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str()); |
| 119 hide_item.hasTextDirectionOverride = false; | 119 hide_item.hasTextDirectionOverride = false; |
| 120 hide_item.textDirection = WebKit::WebTextDirectionDefault; | 120 hide_item.textDirection = WebKit::WebTextDirectionDefault; |
| 121 custom_items[i++] = hide_item; | 121 custom_items[i++] = hide_item; |
| 122 | 122 |
| 123 WebMenuItemInfo install_item; |
| 124 install_item.action = chrome::MENU_COMMAND_PLUGIN_INSTALL; |
| 125 install_item.enabled = false; |
| 126 install_item.label = WebString::fromUTF8( |
| 127 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_INSTALL).c_str()); |
| 128 install_item.hasTextDirectionOverride = false; |
| 129 install_item.textDirection = WebKit::WebTextDirectionDefault; |
| 130 custom_items[i++] = install_item; |
| 131 |
| 123 menu_data.customItems.swap(custom_items); | 132 menu_data.customItems.swap(custom_items); |
| 124 menu_data.mousePosition = WebPoint(event.windowX, event.windowY); | 133 menu_data.mousePosition = WebPoint(event.windowX, event.windowY); |
| 125 render_view()->ShowContextMenu(NULL, menu_data); | 134 render_view()->ShowContextMenu(NULL, menu_data); |
| 126 g_last_active_menu = this; | 135 g_last_active_menu = this; |
| 127 } | 136 } |
| 128 | 137 |
| 129 bool MissingPlugin::OnMessageReceived(const IPC::Message& message) { | 138 bool MissingPlugin::OnMessageReceived(const IPC::Message& message) { |
| 130 bool handled = true; | 139 bool handled = true; |
| 131 IPC_BEGIN_MESSAGE_MAP(MissingPlugin, message) | 140 IPC_BEGIN_MESSAGE_MAP(MissingPlugin, message) |
| 132 IPC_MESSAGE_HANDLER(ChromeViewMsg_FoundMissingPlugin, | 141 IPC_MESSAGE_HANDLER(ChromeViewMsg_FoundMissingPlugin, |
| 133 OnFoundMissingPlugin) | 142 OnFoundMissingPlugin) |
| 134 IPC_MESSAGE_HANDLER(ChromeViewMsg_DidNotFindMissingPlugin, | 143 IPC_MESSAGE_HANDLER(ChromeViewMsg_DidNotFindMissingPlugin, |
| 135 OnDidNotFindMissingPlugin) | 144 OnDidNotFindMissingPlugin) |
| 145 IPC_MESSAGE_HANDLER(ChromeViewMsg_StartedDownloadingPlugin, |
| 146 OnStartedDownloadingPlugin) |
| 147 IPC_MESSAGE_HANDLER(ChromeViewMsg_FinishedDownloadingPlugin, |
| 148 OnFinishedDownloadingPlugin) |
| 136 IPC_MESSAGE_UNHANDLED(handled = false) | 149 IPC_MESSAGE_UNHANDLED(handled = false) |
| 137 IPC_END_MESSAGE_MAP() | 150 IPC_END_MESSAGE_MAP() |
| 138 | 151 |
| 139 return handled; | 152 return handled; |
| 140 } | 153 } |
| 141 | 154 |
| 142 void MissingPlugin::OnFoundMissingPlugin(const string16& plugin_name) { | 155 void MissingPlugin::OnFoundMissingPlugin(const string16& plugin_name) { |
| 143 SetMessage(l10n_util::GetStringFUTF16(IDS_PLUGIN_FOUND, plugin_name)); | 156 SetMessage(l10n_util::GetStringFUTF16(IDS_PLUGIN_FOUND, plugin_name)); |
| 144 } | 157 } |
| 145 | 158 |
| 146 void MissingPlugin::OnDidNotFindMissingPlugin() { | 159 void MissingPlugin::OnDidNotFindMissingPlugin() { |
| 147 SetMessage(l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_FOUND)); | 160 SetMessage(l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_FOUND)); |
| 148 } | 161 } |
| 149 | 162 |
| 163 void MissingPlugin::OnStartedDownloadingPlugin() { |
| 164 SetMessage(l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOADING)); |
| 165 } |
| 166 |
| 167 void MissingPlugin::OnFinishedDownloadingPlugin() { |
| 168 SetMessage(l10n_util::GetStringUTF16(IDS_PLUGIN_INSTALLING)); |
| 169 } |
| 170 |
| 150 void MissingPlugin::SetMessage(const string16& message) { | 171 void MissingPlugin::SetMessage(const string16& message) { |
| 151 message_ = message; | 172 message_ = message; |
| 152 if (!plugin()->web_view()->mainFrame()->isLoading()) | 173 if (!plugin()->web_view()->mainFrame()->isLoading()) |
| 153 UpdateMessage(); | 174 UpdateMessage(); |
| 154 } | 175 } |
| 155 | 176 |
| 156 void MissingPlugin::UpdateMessage() { | 177 void MissingPlugin::UpdateMessage() { |
| 157 DCHECK(!plugin()->web_view()->mainFrame()->isLoading()); | 178 DCHECK(!plugin()->web_view()->mainFrame()->isLoading()); |
| 158 std::string script = "window.setMessage(" + | 179 std::string script = "window.setMessage(" + |
| 159 base::GetDoubleQuotedJson(message_) + ")"; | 180 base::GetDoubleQuotedJson(message_) + ")"; |
| 160 plugin()->web_view()->mainFrame()->executeScript( | 181 plugin()->web_view()->mainFrame()->executeScript( |
| 161 WebScriptSource(ASCIIToUTF16(script))); | 182 WebScriptSource(ASCIIToUTF16(script))); |
| 162 } | 183 } |
| 163 | 184 |
| 164 void MissingPlugin::ContextMenuAction(unsigned id) { | 185 void MissingPlugin::ContextMenuAction(unsigned id) { |
| 165 if (g_last_active_menu != this) | 186 if (g_last_active_menu != this) |
| 166 return; | 187 return; |
| 167 if (id == chrome::MENU_COMMAND_PLUGIN_HIDE) { | 188 if (id == chrome::MENU_COMMAND_PLUGIN_HIDE) { |
| 168 RenderThread::Get()->RecordUserMetrics("MissingPlugin_Hide_Menu"); | 189 RenderThread::Get()->RecordUserMetrics("MissingPlugin_Hide_Menu"); |
| 169 HidePluginInternal(); | 190 HidePluginInternal(); |
| 170 } else { | 191 } else { |
| 171 NOTREACHED(); | 192 NOTREACHED(); |
| 172 } | 193 } |
| 173 } | 194 } |
| 174 | 195 |
| 175 void MissingPlugin::DidFinishLoading() { | 196 void MissingPlugin::DidFinishLoading() { |
| 176 if (message_.length() > 0) | 197 if (message_.length() > 0) |
| 177 UpdateMessage(); | 198 UpdateMessage(); |
| 178 } | 199 } |
| OLD | NEW |