| 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/default_plugin/plugin_impl_win.h" | 5 #include "chrome/default_plugin/plugin_impl_win.h" |
| 6 | 6 |
| 7 #include <shellapi.h> | 7 #include <shellapi.h> |
| 8 | 8 |
| 9 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/common/chrome_plugin_messages.h" | 14 #include "chrome/common/chrome_plugin_messages.h" |
| 14 #include "chrome/default_plugin/plugin_main.h" | 15 #include "chrome/default_plugin/plugin_main.h" |
| 15 #include "content/common/child_thread.h" | 16 #include "content/common/child_thread.h" |
| 16 #include "content/common/plugin_messages.h" | 17 #include "content/common/plugin_messages.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 #include "grit/webkit_strings.h" | 19 #include "grit/webkit_strings.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 34 plugin_install_stream_(NULL), | 35 plugin_install_stream_(NULL), |
| 35 plugin_installer_state_(PluginInstallerStateUndefined), | 36 plugin_installer_state_(PluginInstallerStateUndefined), |
| 36 install_dialog_(NULL), | 37 install_dialog_(NULL), |
| 37 enable_click_(false), | 38 enable_click_(false), |
| 38 icon_(NULL), | 39 icon_(NULL), |
| 39 bold_font_(NULL), | 40 bold_font_(NULL), |
| 40 regular_font_(NULL), | 41 regular_font_(NULL), |
| 41 underline_font_(NULL), | 42 underline_font_(NULL), |
| 42 tooltip_(NULL), | 43 tooltip_(NULL), |
| 43 installation_job_monitor_thread_( | 44 installation_job_monitor_thread_( |
| 44 new PluginInstallationJobMonitorThread()), | 45 new base::win::ProcessMonitor()), |
| 45 plugin_database_handler_(*this), | 46 plugin_database_handler_(), |
| 46 plugin_download_url_for_display_(false) { | 47 plugin_download_url_for_display_(false) { |
| 47 instance_count_++; | 48 instance_count_++; |
| 48 } | 49 } |
| 49 | 50 |
| 50 PluginInstallerImpl::~PluginInstallerImpl() { | 51 PluginInstallerImpl::~PluginInstallerImpl() { |
| 51 instance_count_--; | 52 instance_count_--; |
| 52 if (instance_count_ == 0) | 53 if (instance_count_ == 0) |
| 53 show_install_infobar_ = true; | 54 show_install_infobar_ = true; |
| 54 | 55 |
| 55 if (!disable_plugin_finder_) | 56 if (!disable_plugin_finder_) |
| 56 installation_job_monitor_thread_->Stop(); | 57 installation_job_monitor_thread_->Stop(); |
| 57 | 58 |
| 58 if (bold_font_) | 59 if (bold_font_) |
| 59 DeleteObject(bold_font_); | 60 DeleteObject(bold_font_); |
| 60 | 61 |
| 61 if (underline_font_) | 62 if (underline_font_) |
| 62 DeleteObject(underline_font_); | 63 DeleteObject(underline_font_); |
| 63 | 64 |
| 64 if (tooltip_) | 65 if (tooltip_) |
| 65 DestroyWindow(tooltip_); | 66 DestroyWindow(tooltip_); |
| 66 } | 67 } |
| 67 | 68 |
| 69 void PluginInstallerImpl::DownloadPluginList( |
| 70 const std::string& plugin_finder_url) { |
| 71 DCHECK(default_plugin::g_browser->geturlnotify); |
| 72 default_plugin::g_browser->geturlnotify( |
| 73 instance(), plugin_finder_url.c_str(), NULL, NULL); |
| 74 } |
| 75 |
| 76 void PluginInstallerImpl::OnPluginListDownloaded() { |
| 77 DVLOG(1) << "Received Done notification for plugin list download"; |
| 78 plugin_database_handler_.ParsePluginList(); |
| 79 if (plugin_database_handler_.GetPluginDetailsForMimeType( |
| 80 mime_type_.c_str(), desired_language_.c_str(), |
| 81 &plugin_download_url_, &plugin_name_, |
| 82 &plugin_download_url_for_display_)) { |
| 83 install_dialog_ = PluginInstallDialog::AddInstaller(this, plugin_name_); |
| 84 set_plugin_installer_state(PluginListDownloaded); |
| 85 } else { |
| 86 set_plugin_installer_state(PluginListDownloadedPluginNotFound); |
| 87 } |
| 88 |
| 89 plugin_database_handler_.Close(false); |
| 90 } |
| 91 |
| 68 bool PluginInstallerImpl::Initialize(HINSTANCE module_handle, NPP instance, | 92 bool PluginInstallerImpl::Initialize(HINSTANCE module_handle, NPP instance, |
| 69 NPMIMEType mime_type, int16 argc, | 93 NPMIMEType mime_type, int16 argc, |
| 70 char* argn[], char* argv[]) { | 94 char* argn[], char* argv[]) { |
| 71 DVLOG(1) << __FUNCTION__ << " MIME Type : " << mime_type; | 95 DVLOG(1) << __FUNCTION__ << " MIME Type : " << mime_type; |
| 72 DCHECK(instance != NULL); | 96 DCHECK(instance != NULL); |
| 73 DCHECK(module_handle != NULL); | 97 DCHECK(module_handle != NULL); |
| 74 | 98 |
| 75 if (mime_type == NULL || strlen(mime_type) == 0) { | 99 if (mime_type == NULL || strlen(mime_type) == 0) { |
| 76 NOTREACHED() << __FUNCTION__ << " Invalid parameters passed in"; | 100 NOTREACHED() << __FUNCTION__ << " Invalid parameters passed in"; |
| 77 return false; | 101 return false; |
| 78 } | 102 } |
| 79 | 103 |
| 80 instance_ = instance; | 104 instance_ = instance; |
| 81 mime_type_ = mime_type; | 105 mime_type_ = mime_type; |
| 82 | 106 |
| 83 ChildThread::current()->Send( | 107 ChildThread::current()->Send( |
| 84 new ChromePluginProcessHostMsg_GetPluginFinderUrl(&plugin_finder_url_)); | 108 new ChromePluginProcessHostMsg_GetPluginFinderUrl(&plugin_finder_url_)); |
| 85 if (plugin_finder_url_.empty()) | 109 if (plugin_finder_url_.empty()) |
| 86 disable_plugin_finder_ = true; | 110 disable_plugin_finder_ = true; |
| 87 | 111 |
| 88 InitializeResources(module_handle); | 112 InitializeResources(module_handle); |
| 89 | 113 |
| 90 // Set the routing IDs before downloading the plug-in file, so we can | 114 // Set the routing IDs before downloading the plug-in file, so we can |
| 91 // immediately notify the browser if a plug-in is available. | 115 // immediately notify the browser if a plug-in is available. |
| 92 PluginInstallerBase::SetRoutingIds(argc, argn, argv); | 116 PluginInstallerBase::SetRoutingIds(argc, argn, argv); |
| 93 if (!disable_plugin_finder_) { | 117 if (!disable_plugin_finder_) { |
| 94 if (!installation_job_monitor_thread_->Initialize()) { | |
| 95 NOTREACHED() << "Failed to initialize plugin install job"; | |
| 96 return false; | |
| 97 } | |
| 98 | |
| 99 DisplayStatus(IDS_DEFAULT_PLUGIN_GET_PLUGIN_MSG_NO_PLUGIN_NAME); | 118 DisplayStatus(IDS_DEFAULT_PLUGIN_GET_PLUGIN_MSG_NO_PLUGIN_NAME); |
| 100 plugin_database_handler_.DownloadPluginsFileIfNeeded(plugin_finder_url_); | 119 plugin_database_handler_.DownloadPluginsFileIfNeeded(plugin_finder_url_, |
| 120 this); |
| 101 } else { | 121 } else { |
| 102 DisplayStatus(IDS_DEFAULT_PLUGIN_GET_PLUGIN_MSG_PLUGIN_FINDER_DISABLED); | 122 DisplayStatus(IDS_DEFAULT_PLUGIN_GET_PLUGIN_MSG_PLUGIN_FINDER_DISABLED); |
| 103 } | 123 } |
| 104 return true; | 124 return true; |
| 105 } | 125 } |
| 106 | 126 |
| 107 void PluginInstallerImpl::Shutdown() { | 127 void PluginInstallerImpl::Shutdown() { |
| 108 if (install_dialog_) { | 128 if (install_dialog_) { |
| 109 install_dialog_->RemoveInstaller(this); | 129 install_dialog_->RemoveInstaller(this); |
| 110 install_dialog_ = NULL; | 130 install_dialog_ = NULL; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 NULL); | 257 NULL); |
| 238 RefreshDisplay(); | 258 RefreshDisplay(); |
| 239 } | 259 } |
| 240 | 260 |
| 241 void PluginInstallerImpl::URLNotify(const char* url, NPReason reason) { | 261 void PluginInstallerImpl::URLNotify(const char* url, NPReason reason) { |
| 242 DCHECK(plugin_installer_state_ == PluginListDownloadInitiated); | 262 DCHECK(plugin_installer_state_ == PluginListDownloadInitiated); |
| 243 | 263 |
| 244 if (plugin_installer_state_ == PluginListDownloadInitiated) { | 264 if (plugin_installer_state_ == PluginListDownloadInitiated) { |
| 245 bool plugin_available = false; | 265 bool plugin_available = false; |
| 246 if (reason == NPRES_DONE) { | 266 if (reason == NPRES_DONE) { |
| 247 DVLOG(1) << "Received Done notification for plugin list download"; | 267 OnPluginListDownloaded(); |
| 248 plugin_database_handler_.ParsePluginList(); | |
| 249 if (plugin_database_handler_.GetPluginDetailsForMimeType( | |
| 250 mime_type_.c_str(), desired_language_.c_str(), | |
| 251 &plugin_download_url_, &plugin_name_, | |
| 252 &plugin_download_url_for_display_)) { | |
| 253 plugin_available = true; | |
| 254 install_dialog_ = PluginInstallDialog::AddInstaller(this, plugin_name_); | |
| 255 set_plugin_installer_state(PluginListDownloaded); | |
| 256 } else { | |
| 257 set_plugin_installer_state(PluginListDownloadedPluginNotFound); | |
| 258 } | |
| 259 | |
| 260 plugin_database_handler_.Close(false); | |
| 261 } else { | 268 } else { |
| 262 DLOG(WARNING) << "Failed to download plugin list"; | 269 DLOG(WARNING) << "Failed to download plugin list"; |
| 263 set_plugin_installer_state(PluginListDownloadFailed); | 270 set_plugin_installer_state(PluginListDownloadFailed); |
| 264 | 271 |
| 265 plugin_database_handler_.Close(true); | 272 plugin_database_handler_.Close(true); |
| 266 } | 273 } |
| 267 | 274 |
| 268 if (plugin_available) { | 275 if (plugin_installer_state() == PluginListDownloaded) { |
| 269 DVLOG(1) << "Plugin available for mime type " << mime_type_; | 276 DVLOG(1) << "Plugin available for mime type " << mime_type_; |
| 270 NotifyPluginStatus( | 277 NotifyPluginStatus( |
| 271 webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE); | 278 webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE); |
| 272 DisplayAvailablePluginStatus(); | 279 DisplayAvailablePluginStatus(); |
| 273 } else { | 280 } else { |
| 274 DLOG(WARNING) << "No plugin available for mime type " << mime_type_; | 281 DLOG(WARNING) << "No plugin available for mime type " << mime_type_; |
| 275 DisplayStatus(IDS_DEFAULT_PLUGIN_NO_PLUGIN_AVAILABLE_MSG); | 282 DisplayStatus(IDS_DEFAULT_PLUGIN_NO_PLUGIN_AVAILABLE_MSG); |
| 276 } | 283 } |
| 277 } | 284 } |
| 278 } | 285 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 SetWindowPos(hwnd(), NULL, parent_rect.left, parent_rect.top, | 324 SetWindowPos(hwnd(), NULL, parent_rect.left, parent_rect.top, |
| 318 parent_rect.right - parent_rect.left, | 325 parent_rect.right - parent_rect.left, |
| 319 parent_rect.bottom - parent_rect.top, SWP_SHOWWINDOW); | 326 parent_rect.bottom - parent_rect.top, SWP_SHOWWINDOW); |
| 320 return true; | 327 return true; |
| 321 } | 328 } |
| 322 // First time in -- no window created by plugin yet. | 329 // First time in -- no window created by plugin yet. |
| 323 GetClientRect(parent_window, &parent_rect); | 330 GetClientRect(parent_window, &parent_rect); |
| 324 set_window_style(WS_CHILD | WS_BORDER); | 331 set_window_style(WS_CHILD | WS_BORDER); |
| 325 Init(parent_window, gfx::Rect(parent_rect)); | 332 Init(parent_window, gfx::Rect(parent_rect)); |
| 326 DCHECK(IsWindow(hwnd())); | 333 DCHECK(IsWindow(hwnd())); |
| 327 installation_job_monitor_thread_->set_plugin_window(hwnd()); | |
| 328 | 334 |
| 329 CreateToolTip(); | 335 CreateToolTip(); |
| 330 UpdateToolTip(); | 336 UpdateToolTip(); |
| 331 | 337 |
| 332 UpdateWindow(hwnd()); | 338 UpdateWindow(hwnd()); |
| 333 ShowWindow(hwnd(), SW_SHOW); | 339 ShowWindow(hwnd(), SW_SHOW); |
| 334 | 340 |
| 335 if (plugin_installer_state() == PluginListDownloaded) { | 341 if (plugin_installer_state() == PluginListDownloaded) { |
| 336 NotifyPluginStatus( | 342 NotifyPluginStatus( |
| 337 webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE); | 343 webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 | 547 |
| 542 LRESULT PluginInstallerImpl::OnLButtonDown(UINT message, WPARAM wparam, | 548 LRESULT PluginInstallerImpl::OnLButtonDown(UINT message, WPARAM wparam, |
| 543 LPARAM lparam, BOOL& handled) { | 549 LPARAM lparam, BOOL& handled) { |
| 544 if (!enable_click_) | 550 if (!enable_click_) |
| 545 return 0; | 551 return 0; |
| 546 if (plugin_installer_state() == PluginListDownloaded) { | 552 if (plugin_installer_state() == PluginListDownloaded) { |
| 547 ShowInstallDialog(); | 553 ShowInstallDialog(); |
| 548 NotifyPluginStatus( | 554 NotifyPluginStatus( |
| 549 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD); | 555 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD); |
| 550 } else if (plugin_installer_state_ == PluginInstallerLaunchSuccess) { | 556 } else if (plugin_installer_state_ == PluginInstallerLaunchSuccess) { |
| 551 DCHECK(default_plugin::g_browser); | 557 RefreshPlugins(); |
| 552 DCHECK(default_plugin::g_browser->geturl); | |
| 553 default_plugin::g_browser->geturl( | |
| 554 instance_, | |
| 555 "javascript:navigator.plugins.refresh(true)", | |
| 556 "_self"); | |
| 557 default_plugin::g_browser->geturl( | |
| 558 instance_, | |
| 559 "javascript:window.location.reload(true)", | |
| 560 "_self"); | |
| 561 } | 558 } |
| 562 | 559 |
| 563 return 0; | 560 return 0; |
| 564 } | 561 } |
| 565 | 562 |
| 566 LRESULT PluginInstallerImpl::OnSetCursor(UINT message, WPARAM wparam, | 563 LRESULT PluginInstallerImpl::OnSetCursor(UINT message, WPARAM wparam, |
| 567 LPARAM lparam, BOOL& handled) { | 564 LPARAM lparam, BOOL& handled) { |
| 568 if (enable_click_) { | 565 if (enable_click_) { |
| 569 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND))); | 566 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND))); |
| 570 return 1; | 567 return 1; |
| 571 } | 568 } |
| 572 handled = FALSE; | 569 handled = FALSE; |
| 573 return 0; | 570 return 0; |
| 574 } | 571 } |
| 575 | 572 |
| 576 LRESULT PluginInstallerImpl::OnRefreshPlugins(UINT message, WPARAM wparam, | 573 void PluginInstallerImpl::RefreshPlugins() { |
| 577 LPARAM lparam, BOOL& handled) { | |
| 578 DCHECK(default_plugin::g_browser); | 574 DCHECK(default_plugin::g_browser); |
| 579 DCHECK(default_plugin::g_browser->geturl); | 575 DCHECK(default_plugin::g_browser->geturl); |
| 580 default_plugin::g_browser->geturl( | 576 default_plugin::g_browser->geturl( |
| 581 instance_, | 577 instance_, |
| 582 "javascript:navigator.plugins.refresh(true)", | 578 "javascript:navigator.plugins.refresh(true)", |
| 583 "_self"); | 579 "_self"); |
| 584 default_plugin::g_browser->geturl( | 580 default_plugin::g_browser->geturl( |
| 585 instance_, | 581 instance_, |
| 586 "javascript:window.location.reload(true)", | 582 "javascript:window.location.reload(true)", |
| 587 "_self"); | 583 "_self"); |
| 588 return 0; | |
| 589 } | 584 } |
| 590 | 585 |
| 591 LRESULT PluginInstallerImpl::OnCopyData(UINT message, WPARAM wparam, | 586 LRESULT PluginInstallerImpl::OnCopyData(UINT message, WPARAM wparam, |
| 592 LPARAM lparam, BOOL& handled) { | 587 LPARAM lparam, BOOL& handled) { |
| 593 COPYDATASTRUCT* download_file_info = | 588 COPYDATASTRUCT* download_file_info = |
| 594 reinterpret_cast<COPYDATASTRUCT*>(lparam); | 589 reinterpret_cast<COPYDATASTRUCT*>(lparam); |
| 595 if (!download_file_info || !download_file_info->dwData) { | 590 if (!download_file_info || !download_file_info->dwData) { |
| 596 DLOG(WARNING) << "Failed to download plugin"; | 591 DLOG(WARNING) << "Failed to download plugin"; |
| 597 set_plugin_installer_state(PluginDownloadFailed); | 592 set_plugin_installer_state(PluginDownloadFailed); |
| 598 DisplayPluginDownloadFailedStatus(); | 593 DisplayPluginDownloadFailedStatus(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 615 if (!ShellExecuteEx(&shell_execute_info)) { | 610 if (!ShellExecuteEx(&shell_execute_info)) { |
| 616 DLOG(WARNING) << "Failed to launch plugin installer " | 611 DLOG(WARNING) << "Failed to launch plugin installer " |
| 617 << file_path.c_str() << " Error " | 612 << file_path.c_str() << " Error " |
| 618 << ::GetLastError(); | 613 << ::GetLastError(); |
| 619 set_plugin_installer_state(PluginInstallerLaunchFailure); | 614 set_plugin_installer_state(PluginInstallerLaunchFailure); |
| 620 DisplayStatus(IDS_DEFAULT_PLUGIN_INSTALLATION_FAILED_MSG); | 615 DisplayStatus(IDS_DEFAULT_PLUGIN_INSTALLATION_FAILED_MSG); |
| 621 NOTREACHED(); | 616 NOTREACHED(); |
| 622 } else { | 617 } else { |
| 623 DVLOG(1) << "Successfully launched plugin installer"; | 618 DVLOG(1) << "Successfully launched plugin installer"; |
| 624 set_plugin_installer_state(PluginInstallerLaunchSuccess); | 619 set_plugin_installer_state(PluginInstallerLaunchSuccess); |
| 625 installation_job_monitor_thread_->AssignProcessToJob( | 620 installation_job_monitor_thread_->Initialize( |
| 626 shell_execute_info.hProcess); | 621 shell_execute_info.hProcess, |
| 622 base::Bind(&PluginInstallerImpl::RefreshPlugins, |
| 623 base::Unretained(this))); |
| 627 DisplayStatus(IDS_DEFAULT_PLUGIN_REFRESH_PLUGIN_MSG); | 624 DisplayStatus(IDS_DEFAULT_PLUGIN_REFRESH_PLUGIN_MSG); |
| 628 enable_click_ = true; | 625 enable_click_ = true; |
| 629 RefreshDisplay(); | 626 RefreshDisplay(); |
| 630 } | 627 } |
| 631 } | 628 } |
| 632 return 0; | 629 return 0; |
| 633 } | 630 } |
| 634 | 631 |
| 635 LRESULT PluginInstallerImpl::OnInstallPluginMessage(UINT message, | 632 LRESULT PluginInstallerImpl::OnInstallPluginMessage(UINT message, |
| 636 WPARAM wparam, | 633 WPARAM wparam, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 } | 676 } |
| 680 | 677 |
| 681 ChildThread::current()->Send( | 678 ChildThread::current()->Send( |
| 682 new ChromePluginProcessHostMsg_MissingPluginStatus( | 679 new ChromePluginProcessHostMsg_MissingPluginStatus( |
| 683 status, | 680 status, |
| 684 renderer_process_id(), | 681 renderer_process_id(), |
| 685 render_view_id(), | 682 render_view_id(), |
| 686 hwnd())); | 683 hwnd())); |
| 687 #endif | 684 #endif |
| 688 } | 685 } |
| OLD | NEW |