| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/plugins/plugin_observer.h" | 5 #include "chrome/browser/plugins/plugin_observer.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/browser/web_contents_delegate.h" | 27 #include "content/public/browser/web_contents_delegate.h" |
| 28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 29 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 32 #include "webkit/plugins/webplugininfo.h" | 32 #include "webkit/plugins/webplugininfo.h" |
| 33 | 33 |
| 34 #if defined(ENABLE_PLUGIN_INSTALLATION) | 34 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 35 #if defined(OS_WIN) |
| 36 #include "base/win/metro.h" |
| 37 #endif |
| 35 #include "chrome/browser/plugins/plugin_installer.h" | 38 #include "chrome/browser/plugins/plugin_installer.h" |
| 36 #include "chrome/browser/plugins/plugin_installer_observer.h" | 39 #include "chrome/browser/plugins/plugin_installer_observer.h" |
| 37 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 40 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
| 38 #endif // defined(ENABLE_PLUGIN_INSTALLATION) | 41 #endif // defined(ENABLE_PLUGIN_INSTALLATION) |
| 39 | 42 |
| 40 #if defined(OS_WIN) | |
| 41 #include "base/win/metro.h" | |
| 42 #endif | |
| 43 | |
| 44 using content::OpenURLParams; | 43 using content::OpenURLParams; |
| 45 using content::PluginService; | 44 using content::PluginService; |
| 46 using content::Referrer; | 45 using content::Referrer; |
| 47 using content::WebContents; | 46 using content::WebContents; |
| 48 | 47 |
| 49 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PluginObserver); | 48 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PluginObserver); |
| 50 | 49 |
| 51 namespace { | 50 namespace { |
| 52 | 51 |
| 53 #if defined(ENABLE_PLUGIN_INSTALLATION) | 52 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 #endif | 181 #endif |
| 183 } | 182 } |
| 184 | 183 |
| 185 void PluginObserver::PluginCrashed(const FilePath& plugin_path) { | 184 void PluginObserver::PluginCrashed(const FilePath& plugin_path) { |
| 186 DCHECK(!plugin_path.value().empty()); | 185 DCHECK(!plugin_path.value().empty()); |
| 187 | 186 |
| 188 string16 plugin_name = | 187 string16 plugin_name = |
| 189 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); | 188 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); |
| 190 gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 189 gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 191 IDR_INFOBAR_PLUGIN_CRASHED); | 190 IDR_INFOBAR_PLUGIN_CRASHED); |
| 192 InfoBarService* infobar_service = | 191 SimpleAlertInfoBarDelegate::Create( |
| 193 InfoBarService::FromWebContents(web_contents()); | 192 InfoBarService::FromWebContents(web_contents()), icon, |
| 194 infobar_service->AddInfoBar( | 193 l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), true); |
| 195 new SimpleAlertInfoBarDelegate( | |
| 196 infobar_service, | |
| 197 icon, | |
| 198 l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), | |
| 199 true)); | |
| 200 } | 194 } |
| 201 | 195 |
| 202 bool PluginObserver::OnMessageReceived(const IPC::Message& message) { | 196 bool PluginObserver::OnMessageReceived(const IPC::Message& message) { |
| 203 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) | 197 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) |
| 204 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, | 198 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, |
| 205 OnBlockedOutdatedPlugin) | 199 OnBlockedOutdatedPlugin) |
| 206 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedUnauthorizedPlugin, | 200 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedUnauthorizedPlugin, |
| 207 OnBlockedUnauthorizedPlugin) | 201 OnBlockedUnauthorizedPlugin) |
| 208 #if defined(ENABLE_PLUGIN_INSTALLATION) | 202 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 209 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FindMissingPlugin, | 203 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FindMissingPlugin, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 220 | 214 |
| 221 IPC_MESSAGE_UNHANDLED(return false) | 215 IPC_MESSAGE_UNHANDLED(return false) |
| 222 IPC_END_MESSAGE_MAP() | 216 IPC_END_MESSAGE_MAP() |
| 223 | 217 |
| 224 return true; | 218 return true; |
| 225 } | 219 } |
| 226 | 220 |
| 227 void PluginObserver::OnBlockedUnauthorizedPlugin( | 221 void PluginObserver::OnBlockedUnauthorizedPlugin( |
| 228 const string16& name, | 222 const string16& name, |
| 229 const std::string& identifier) { | 223 const std::string& identifier) { |
| 230 InfoBarService* infobar_service = | 224 UnauthorizedPluginInfoBarDelegate::Create( |
| 231 InfoBarService::FromWebContents(web_contents()); | 225 InfoBarService::FromWebContents(web_contents()), |
| 232 infobar_service->AddInfoBar( | 226 Profile::FromBrowserContext(web_contents()->GetBrowserContext())-> |
| 233 new UnauthorizedPluginInfoBarDelegate( | 227 GetHostContentSettingsMap(), |
| 234 infobar_service, | 228 name, identifier); |
| 235 Profile::FromBrowserContext(web_contents()->GetBrowserContext())-> | |
| 236 GetHostContentSettingsMap(), | |
| 237 name, identifier)); | |
| 238 } | 229 } |
| 239 | 230 |
| 240 void PluginObserver::OnBlockedOutdatedPlugin(int placeholder_id, | 231 void PluginObserver::OnBlockedOutdatedPlugin(int placeholder_id, |
| 241 const std::string& identifier) { | 232 const std::string& identifier) { |
| 242 #if defined(ENABLE_PLUGIN_INSTALLATION) | 233 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 243 PluginFinder* finder = PluginFinder::GetInstance(); | 234 PluginFinder* finder = PluginFinder::GetInstance(); |
| 244 // Find plugin to update. | 235 // Find plugin to update. |
| 245 PluginInstaller* installer = NULL; | 236 PluginInstaller* installer = NULL; |
| 246 scoped_ptr<PluginMetadata> plugin; | 237 scoped_ptr<PluginMetadata> plugin; |
| 247 if (!finder->FindPluginWithIdentifier(identifier, &installer, &plugin)) { | 238 if (!finder->FindPluginWithIdentifier(identifier, &installer, &plugin)) { |
| 248 NOTREACHED(); | 239 NOTREACHED(); |
| 249 return; | 240 return; |
| 250 } | 241 } |
| 251 | 242 |
| 252 plugin_placeholders_[placeholder_id] = | 243 plugin_placeholders_[placeholder_id] = |
| 253 new PluginPlaceholderHost(this, placeholder_id, | 244 new PluginPlaceholderHost(this, placeholder_id, |
| 254 plugin->name(), installer); | 245 plugin->name(), installer); |
| 255 InfoBarService* infobar_service = | 246 OutdatedPluginInfoBarDelegate::Create( |
| 256 InfoBarService::FromWebContents(web_contents()); | 247 InfoBarService::FromWebContents(web_contents()), installer, |
| 257 infobar_service->AddInfoBar( | 248 plugin.Pass()); |
| 258 OutdatedPluginInfoBarDelegate::Create(web_contents(), | |
| 259 installer, plugin.Pass())); | |
| 260 #else | 249 #else |
| 261 // If we don't support third-party plug-in installation, we shouldn't have | 250 // If we don't support third-party plug-in installation, we shouldn't have |
| 262 // outdated plug-ins. | 251 // outdated plug-ins. |
| 263 NOTREACHED(); | 252 NOTREACHED(); |
| 264 #endif // defined(ENABLE_PLUGIN_INSTALLATION) | 253 #endif // defined(ENABLE_PLUGIN_INSTALLATION) |
| 265 } | 254 } |
| 266 | 255 |
| 267 #if defined(ENABLE_PLUGIN_INSTALLATION) | 256 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 268 void PluginObserver::OnFindMissingPlugin(int placeholder_id, | 257 void PluginObserver::OnFindMissingPlugin(int placeholder_id, |
| 269 const std::string& mime_type) { | 258 const std::string& mime_type) { |
| 270 std::string lang = "en-US"; // Oh yes. | 259 std::string lang = "en-US"; // Oh yes. |
| 271 scoped_ptr<PluginMetadata> plugin_metadata; | 260 scoped_ptr<PluginMetadata> plugin_metadata; |
| 272 PluginInstaller* installer = NULL; | 261 PluginInstaller* installer = NULL; |
| 273 bool found_plugin = PluginFinder::GetInstance()->FindPlugin( | 262 bool found_plugin = PluginFinder::GetInstance()->FindPlugin( |
| 274 mime_type, lang, &installer, &plugin_metadata); | 263 mime_type, lang, &installer, &plugin_metadata); |
| 275 if (!found_plugin) { | 264 if (!found_plugin) { |
| 276 Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id)); | 265 Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id)); |
| 277 return; | 266 return; |
| 278 } | 267 } |
| 279 DCHECK(installer); | 268 DCHECK(installer); |
| 280 DCHECK(plugin_metadata.get()); | 269 DCHECK(plugin_metadata.get()); |
| 281 | 270 |
| 282 plugin_placeholders_[placeholder_id] = | 271 plugin_placeholders_[placeholder_id] = |
| 283 new PluginPlaceholderHost(this, placeholder_id, | 272 new PluginPlaceholderHost(this, placeholder_id, |
| 284 plugin_metadata->name(), | 273 plugin_metadata->name(), |
| 285 installer); | 274 installer); |
| 286 PluginInstallerInfoBarDelegate::InstallCallback callback = | 275 PluginInstallerInfoBarDelegate::Create( |
| 276 InfoBarService::FromWebContents(web_contents()), installer, |
| 277 plugin_metadata.Pass(), |
| 287 base::Bind(&PluginObserver::InstallMissingPlugin, | 278 base::Bind(&PluginObserver::InstallMissingPlugin, |
| 288 weak_ptr_factory_.GetWeakPtr(), installer); | 279 weak_ptr_factory_.GetWeakPtr(), installer)); |
| 289 InfoBarService* infobar_service = | |
| 290 InfoBarService::FromWebContents(web_contents()); | |
| 291 InfoBarDelegate* delegate; | |
| 292 #if !defined(OS_WIN) | |
| 293 delegate = PluginInstallerInfoBarDelegate::Create( | |
| 294 infobar_service, installer, plugin_metadata.Pass(), callback); | |
| 295 #else | |
| 296 delegate = base::win::IsMetroProcess() ? | |
| 297 new PluginMetroModeInfoBarDelegate( | |
| 298 infobar_service, | |
| 299 PluginMetroModeInfoBarDelegate::MISSING_PLUGIN, | |
| 300 plugin_metadata->name()) : | |
| 301 PluginInstallerInfoBarDelegate::Create( | |
| 302 infobar_service, installer, plugin_metadata.Pass(), callback); | |
| 303 #endif | |
| 304 infobar_service->AddInfoBar(delegate); | |
| 305 } | 280 } |
| 306 | 281 |
| 307 void PluginObserver::InstallMissingPlugin( | 282 void PluginObserver::InstallMissingPlugin( |
| 308 PluginInstaller* installer, | 283 PluginInstaller* installer, |
| 309 const PluginMetadata* plugin_metadata) { | 284 const PluginMetadata* plugin_metadata) { |
| 310 if (plugin_metadata->url_for_display()) { | 285 if (plugin_metadata->url_for_display()) { |
| 311 installer->OpenDownloadURL(plugin_metadata->plugin_url(), web_contents()); | 286 installer->OpenDownloadURL(plugin_metadata->plugin_url(), web_contents()); |
| 312 } else { | 287 } else { |
| 313 TabModalConfirmDialog::Create( | 288 TabModalConfirmDialog::Create( |
| 314 new ConfirmInstallDialogDelegate( | 289 new ConfirmInstallDialogDelegate( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 334 GURL(chrome::kAboutPluginsURL), | 309 GURL(chrome::kAboutPluginsURL), |
| 335 content::Referrer(web_contents()->GetURL(), | 310 content::Referrer(web_contents()->GetURL(), |
| 336 WebKit::WebReferrerPolicyDefault), | 311 WebKit::WebReferrerPolicyDefault), |
| 337 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); | 312 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); |
| 338 } | 313 } |
| 339 | 314 |
| 340 void PluginObserver::OnCouldNotLoadPlugin(const FilePath& plugin_path) { | 315 void PluginObserver::OnCouldNotLoadPlugin(const FilePath& plugin_path) { |
| 341 g_browser_process->metrics_service()->LogPluginLoadingError(plugin_path); | 316 g_browser_process->metrics_service()->LogPluginLoadingError(plugin_path); |
| 342 string16 plugin_name = | 317 string16 plugin_name = |
| 343 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); | 318 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); |
| 344 InfoBarService* infobar_service = | 319 SimpleAlertInfoBarDelegate::Create( |
| 345 InfoBarService::FromWebContents(web_contents()); | 320 InfoBarService::FromWebContents(web_contents()), |
| 346 infobar_service->AddInfoBar(new SimpleAlertInfoBarDelegate( | |
| 347 infobar_service, | |
| 348 &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 321 &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 349 IDR_INFOBAR_PLUGIN_CRASHED), | 322 IDR_INFOBAR_PLUGIN_CRASHED), |
| 350 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT, | 323 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT, |
| 351 plugin_name), | 324 plugin_name), |
| 352 true /* auto_expire */)); | 325 true /* auto_expire */); |
| 353 } | 326 } |
| 354 | 327 |
| 355 void PluginObserver::OnNPAPINotSupported(const std::string& identifier) { | 328 void PluginObserver::OnNPAPINotSupported(const std::string& identifier) { |
| 356 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | 329 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) |
| 357 DCHECK(base::win::IsMetroProcess()); | 330 DCHECK(base::win::IsMetroProcess()); |
| 358 Profile* profile = | 331 Profile* profile = |
| 359 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 332 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 360 if (profile->IsOffTheRecord()) | 333 if (profile->IsOffTheRecord()) |
| 361 return; | 334 return; |
| 362 HostContentSettingsMap* content_settings = | 335 HostContentSettingsMap* content_settings = |
| 363 profile->GetHostContentSettingsMap(); | 336 profile->GetHostContentSettingsMap(); |
| 364 if (content_settings->GetContentSetting( | 337 if (content_settings->GetContentSetting( |
| 365 web_contents()->GetURL(), | 338 web_contents()->GetURL(), |
| 366 web_contents()->GetURL(), | 339 web_contents()->GetURL(), |
| 367 CONTENT_SETTINGS_TYPE_METRO_SWITCH_TO_DESKTOP, | 340 CONTENT_SETTINGS_TYPE_METRO_SWITCH_TO_DESKTOP, |
| 368 std::string()) == CONTENT_SETTING_BLOCK) | 341 std::string()) == CONTENT_SETTING_BLOCK) |
| 369 return; | 342 return; |
| 370 | 343 |
| 371 scoped_ptr<PluginMetadata> plugin; | 344 scoped_ptr<PluginMetadata> plugin; |
| 372 if (!PluginFinder::GetInstance()->FindPluginWithIdentifier( | 345 if (!PluginFinder::GetInstance()->FindPluginWithIdentifier( |
| 373 identifier, NULL, &plugin)) { | 346 identifier, NULL, &plugin)) { |
| 374 NOTREACHED(); | 347 NOTREACHED(); |
| 375 return; | 348 return; |
| 376 } | 349 } |
| 377 | 350 |
| 378 InfoBarService* infobar_service = | 351 PluginMetroModeInfoBarDelegate::Create( |
| 379 InfoBarService::FromWebContents(web_contents()); | 352 InfoBarService::FromWebContents(web_contents()), |
| 380 infobar_service->AddInfoBar( | 353 PluginMetroModeInfoBarDelegate::DESKTOP_MODE_REQUIRED, plugin->name()); |
| 381 new PluginMetroModeInfoBarDelegate( | |
| 382 infobar_service, | |
| 383 PluginMetroModeInfoBarDelegate::DESKTOP_MODE_REQUIRED, | |
| 384 plugin->name())); | |
| 385 #else | 354 #else |
| 386 NOTREACHED(); | 355 NOTREACHED(); |
| 387 #endif | 356 #endif |
| 388 } | 357 } |
| OLD | NEW |