OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/common/chrome_plugin_messages.h" |
13 #include "chrome/default_plugin/plugin_main.h" | 14 #include "chrome/default_plugin/plugin_main.h" |
14 #include "content/common/child_thread.h" | 15 #include "content/common/child_thread.h" |
15 #include "content/common/plugin_messages.h" | 16 #include "content/common/plugin_messages.h" |
16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
17 #include "grit/webkit_strings.h" | 18 #include "grit/webkit_strings.h" |
18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
20 #include "unicode/locid.h" | 21 #include "unicode/locid.h" |
21 #include "webkit/glue/webkit_glue.h" | 22 #include "webkit/glue/webkit_glue.h" |
22 #include "webkit/plugins/npapi/default_plugin_shared.h" | 23 #include "webkit/plugins/npapi/default_plugin_shared.h" |
23 | 24 |
24 static const int TOOLTIP_MAX_WIDTH = 500; | 25 static const int TOOLTIP_MAX_WIDTH = 500; |
25 | 26 |
| 27 int PluginInstallerImpl::instance_count_ = 0; |
| 28 bool PluginInstallerImpl::show_install_infobar_ = true; |
| 29 |
26 PluginInstallerImpl::PluginInstallerImpl(int16 mode) | 30 PluginInstallerImpl::PluginInstallerImpl(int16 mode) |
27 : instance_(NULL), | 31 : instance_(NULL), |
28 mode_(mode), | 32 mode_(mode), |
29 disable_plugin_finder_(false), | 33 disable_plugin_finder_(false), |
30 plugin_install_stream_(NULL), | 34 plugin_install_stream_(NULL), |
31 plugin_installer_state_(PluginInstallerStateUndefined), | 35 plugin_installer_state_(PluginInstallerStateUndefined), |
32 install_dialog_(NULL), | 36 install_dialog_(NULL), |
33 enable_click_(false), | 37 enable_click_(false), |
34 icon_(NULL), | 38 icon_(NULL), |
35 bold_font_(NULL), | 39 bold_font_(NULL), |
36 regular_font_(NULL), | 40 regular_font_(NULL), |
37 underline_font_(NULL), | 41 underline_font_(NULL), |
38 tooltip_(NULL), | 42 tooltip_(NULL), |
39 installation_job_monitor_thread_( | 43 installation_job_monitor_thread_( |
40 new PluginInstallationJobMonitorThread()), | 44 new PluginInstallationJobMonitorThread()), |
41 plugin_database_handler_(*this), | 45 plugin_database_handler_(*this), |
42 plugin_download_url_for_display_(false) { | 46 plugin_download_url_for_display_(false) { |
| 47 instance_count_++; |
43 } | 48 } |
44 | 49 |
45 PluginInstallerImpl::~PluginInstallerImpl() { | 50 PluginInstallerImpl::~PluginInstallerImpl() { |
| 51 instance_count_--; |
| 52 if (instance_count_ == 0) |
| 53 show_install_infobar_ = true; |
| 54 |
46 if (!disable_plugin_finder_) | 55 if (!disable_plugin_finder_) |
47 installation_job_monitor_thread_->Stop(); | 56 installation_job_monitor_thread_->Stop(); |
48 | 57 |
49 if (bold_font_) | 58 if (bold_font_) |
50 DeleteObject(bold_font_); | 59 DeleteObject(bold_font_); |
51 | 60 |
52 if (underline_font_) | 61 if (underline_font_) |
53 DeleteObject(underline_font_); | 62 DeleteObject(underline_font_); |
54 | 63 |
55 if (tooltip_) | 64 if (tooltip_) |
56 DestroyWindow(tooltip_); | 65 DestroyWindow(tooltip_); |
57 } | 66 } |
58 | 67 |
59 bool PluginInstallerImpl::Initialize(HINSTANCE module_handle, NPP instance, | 68 bool PluginInstallerImpl::Initialize(HINSTANCE module_handle, NPP instance, |
60 NPMIMEType mime_type, int16 argc, | 69 NPMIMEType mime_type, int16 argc, |
61 char* argn[], char* argv[]) { | 70 char* argn[], char* argv[]) { |
62 DVLOG(1) << __FUNCTION__ << " MIME Type : " << mime_type; | 71 DVLOG(1) << __FUNCTION__ << " MIME Type : " << mime_type; |
63 DCHECK(instance != NULL); | 72 DCHECK(instance != NULL); |
64 DCHECK(module_handle != NULL); | 73 DCHECK(module_handle != NULL); |
65 | 74 |
66 if (mime_type == NULL || strlen(mime_type) == 0) { | 75 if (mime_type == NULL || strlen(mime_type) == 0) { |
67 NOTREACHED() << __FUNCTION__ << " Invalid parameters passed in"; | 76 NOTREACHED() << __FUNCTION__ << " Invalid parameters passed in"; |
68 return false; | 77 return false; |
69 } | 78 } |
70 | 79 |
71 instance_ = instance; | 80 instance_ = instance; |
72 mime_type_ = mime_type; | 81 mime_type_ = mime_type; |
73 | 82 |
74 ChildThread::current()->Send( | 83 ChildThread::current()->Send( |
75 new PluginProcessHostMsg_GetPluginFinderUrl(&plugin_finder_url_)); | 84 new ChromePluginProcessHostMsg_GetPluginFinderUrl(&plugin_finder_url_)); |
76 if (plugin_finder_url_.empty()) | 85 if (plugin_finder_url_.empty()) |
77 disable_plugin_finder_ = true; | 86 disable_plugin_finder_ = true; |
78 | 87 |
79 InitializeResources(module_handle); | 88 InitializeResources(module_handle); |
80 | 89 |
81 if (!disable_plugin_finder_) { | 90 if (!disable_plugin_finder_) { |
82 if (!installation_job_monitor_thread_->Initialize()) { | 91 if (!installation_job_monitor_thread_->Initialize()) { |
83 NOTREACHED() << "Failed to initialize plugin install job"; | 92 NOTREACHED() << "Failed to initialize plugin install job"; |
84 return false; | 93 return false; |
85 } | 94 } |
86 | 95 |
87 DisplayStatus(IDS_DEFAULT_PLUGIN_GET_PLUGIN_MSG_NO_PLUGIN_NAME); | 96 DisplayStatus(IDS_DEFAULT_PLUGIN_GET_PLUGIN_MSG_NO_PLUGIN_NAME); |
88 plugin_database_handler_.DownloadPluginsFileIfNeeded(plugin_finder_url_); | 97 plugin_database_handler_.DownloadPluginsFileIfNeeded(plugin_finder_url_); |
89 } else { | 98 } else { |
90 DisplayStatus(IDS_DEFAULT_PLUGIN_GET_PLUGIN_MSG_PLUGIN_FINDER_DISABLED); | 99 DisplayStatus(IDS_DEFAULT_PLUGIN_GET_PLUGIN_MSG_PLUGIN_FINDER_DISABLED); |
91 } | 100 } |
92 | 101 return PluginInstallerBase::Initialize(module_handle, instance, mime_type, |
93 return true; | 102 argc, argn, argv); |
94 } | 103 } |
95 | 104 |
96 void PluginInstallerImpl::Shutdown() { | 105 void PluginInstallerImpl::Shutdown() { |
97 if (install_dialog_) { | 106 if (install_dialog_) { |
98 install_dialog_->RemoveInstaller(this); | 107 install_dialog_->RemoveInstaller(this); |
99 install_dialog_ = NULL; | 108 install_dialog_ = NULL; |
100 } | 109 } |
101 | 110 |
102 if (IsWindow(hwnd())) { | 111 if (IsWindow(hwnd())) { |
103 DestroyWindow(hwnd()); | 112 DestroyWindow(hwnd()); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } else { | 259 } else { |
251 DLOG(WARNING) << "Failed to download plugin list"; | 260 DLOG(WARNING) << "Failed to download plugin list"; |
252 set_plugin_installer_state(PluginListDownloadFailed); | 261 set_plugin_installer_state(PluginListDownloadFailed); |
253 | 262 |
254 plugin_database_handler_.Close(true); | 263 plugin_database_handler_.Close(true); |
255 } | 264 } |
256 | 265 |
257 if (plugin_available) { | 266 if (plugin_available) { |
258 DVLOG(1) << "Plugin available for mime type " << mime_type_; | 267 DVLOG(1) << "Plugin available for mime type " << mime_type_; |
259 DisplayAvailablePluginStatus(); | 268 DisplayAvailablePluginStatus(); |
260 NotifyPluginStatus( | |
261 webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE); | |
262 } else { | 269 } else { |
263 DLOG(WARNING) << "No plugin available for mime type " << mime_type_; | 270 DLOG(WARNING) << "No plugin available for mime type " << mime_type_; |
264 DisplayStatus(IDS_DEFAULT_PLUGIN_NO_PLUGIN_AVAILABLE_MSG); | 271 DisplayStatus(IDS_DEFAULT_PLUGIN_NO_PLUGIN_AVAILABLE_MSG); |
265 } | 272 } |
266 } | 273 } |
267 } | 274 } |
268 | 275 |
269 int16 PluginInstallerImpl::NPP_HandleEvent(void* event) { | 276 int16 PluginInstallerImpl::NPP_HandleEvent(void* event) { |
270 NPEvent* npp_event = static_cast<NPEvent*>(event); | |
271 if (npp_event->event == | |
272 webkit::npapi::default_plugin::kInstallMissingPluginMessage) { | |
273 // We could get this message because InfoBar may not be in sync with our | |
274 // internal processing. So we need to check the status. | |
275 if (plugin_installer_state() == PluginListDownloaded) { | |
276 ShowInstallDialog(); | |
277 } | |
278 } | |
279 return 0; | 277 return 0; |
280 } | 278 } |
281 | 279 |
282 std::wstring PluginInstallerImpl::ReplaceStringForPossibleEmptyReplacement( | 280 std::wstring PluginInstallerImpl::ReplaceStringForPossibleEmptyReplacement( |
283 int message_id_with_placeholders, | 281 int message_id_with_placeholders, |
284 int messsage_id_without_placeholders, | 282 int messsage_id_without_placeholders, |
285 const std::wstring& replacement_string) { | 283 const std::wstring& replacement_string) { |
286 // If the replacement_string is not empty, load the string identified by | 284 // If the replacement_string is not empty, load the string identified by |
287 // the resource id message_id_with_placeholders, and replace the | 285 // the resource id message_id_with_placeholders, and replace the |
288 // placeholder with the replacement_string. Otherwise return the string | 286 // placeholder with the replacement_string. Otherwise return the string |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 Init(parent_window, gfx::Rect(parent_rect)); | 321 Init(parent_window, gfx::Rect(parent_rect)); |
324 DCHECK(IsWindow(hwnd())); | 322 DCHECK(IsWindow(hwnd())); |
325 installation_job_monitor_thread_->set_plugin_window(hwnd()); | 323 installation_job_monitor_thread_->set_plugin_window(hwnd()); |
326 | 324 |
327 CreateToolTip(); | 325 CreateToolTip(); |
328 UpdateToolTip(); | 326 UpdateToolTip(); |
329 | 327 |
330 UpdateWindow(hwnd()); | 328 UpdateWindow(hwnd()); |
331 ShowWindow(hwnd(), SW_SHOW); | 329 ShowWindow(hwnd(), SW_SHOW); |
332 | 330 |
| 331 // Show the infobar only once. |
| 332 if (show_install_infobar_) { |
| 333 show_install_infobar_ = false; |
| 334 NotifyPluginStatus( |
| 335 webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE); |
| 336 } |
333 return true; | 337 return true; |
334 } | 338 } |
335 | 339 |
336 void PluginInstallerImpl::DownloadPlugin() { | 340 void PluginInstallerImpl::DownloadPlugin() { |
337 set_plugin_installer_state(PluginDownloadInitiated); | 341 set_plugin_installer_state(PluginDownloadInitiated); |
338 | 342 |
339 DVLOG(1) << "Initiating download for plugin URL " | 343 DVLOG(1) << "Initiating download for plugin URL " |
340 << plugin_download_url_.c_str(); | 344 << plugin_download_url_.c_str(); |
341 | 345 |
342 DisplayStatus(IDS_DEFAULT_PLUGIN_DOWNLOADING_PLUGIN_MSG); | 346 DisplayStatus(IDS_DEFAULT_PLUGIN_DOWNLOADING_PLUGIN_MSG); |
343 | 347 |
344 if (!plugin_download_url_for_display_) { | 348 if (!plugin_download_url_for_display_) { |
345 ChildThread::current()->Send(new PluginProcessHostMsg_DownloadUrl( | 349 ChildThread::current()->Send(new ChromePluginProcessHostMsg_DownloadUrl( |
346 plugin_download_url_, hwnd())); | 350 plugin_download_url_, hwnd())); |
347 } else { | 351 } else { |
348 default_plugin::g_browser->geturl(instance(), | 352 default_plugin::g_browser->geturl(instance(), |
349 plugin_download_url_.c_str(), | 353 plugin_download_url_.c_str(), |
350 "_blank"); | 354 "_blank"); |
351 set_plugin_installer_state(PluginInstallerLaunchSuccess); | 355 set_plugin_installer_state(PluginInstallerLaunchSuccess); |
352 DisplayStatus(IDS_DEFAULT_PLUGIN_REFRESH_PLUGIN_MSG); | 356 DisplayStatus(IDS_DEFAULT_PLUGIN_REFRESH_PLUGIN_MSG); |
353 enable_click_ = true; | 357 enable_click_ = true; |
354 RefreshDisplay(); | 358 RefreshDisplay(); |
355 } | 359 } |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 installation_job_monitor_thread_->AssignProcessToJob( | 621 installation_job_monitor_thread_->AssignProcessToJob( |
618 shell_execute_info.hProcess); | 622 shell_execute_info.hProcess); |
619 DisplayStatus(IDS_DEFAULT_PLUGIN_REFRESH_PLUGIN_MSG); | 623 DisplayStatus(IDS_DEFAULT_PLUGIN_REFRESH_PLUGIN_MSG); |
620 enable_click_ = true; | 624 enable_click_ = true; |
621 RefreshDisplay(); | 625 RefreshDisplay(); |
622 } | 626 } |
623 } | 627 } |
624 return 0; | 628 return 0; |
625 } | 629 } |
626 | 630 |
| 631 LRESULT PluginInstallerImpl::OnInstallPluginMessage(UINT message, |
| 632 WPARAM wparam, |
| 633 LPARAM lparam, |
| 634 BOOL& handled) { |
| 635 // We could get this message because InfoBar may not be in sync with our |
| 636 // internal processing. So we need to check the status. |
| 637 if (plugin_installer_state() == PluginListDownloaded) { |
| 638 ShowInstallDialog(); |
| 639 } |
| 640 return 0; |
| 641 } |
| 642 |
627 bool PluginInstallerImpl::InitializeResources(HINSTANCE module_handle) { | 643 bool PluginInstallerImpl::InitializeResources(HINSTANCE module_handle) { |
628 DCHECK(icon_ == NULL); | 644 DCHECK(icon_ == NULL); |
629 DCHECK(regular_font_ == NULL); | 645 DCHECK(regular_font_ == NULL); |
630 DCHECK(bold_font_ == NULL); | 646 DCHECK(bold_font_ == NULL); |
631 DCHECK(underline_font_ == NULL); | 647 DCHECK(underline_font_ == NULL); |
632 | 648 |
633 icon_ = LoadIcon(module_handle, MAKEINTRESOURCE(IDI_DEFAULT_PLUGIN_ICON)); | 649 icon_ = LoadIcon(module_handle, MAKEINTRESOURCE(IDI_DEFAULT_PLUGIN_ICON)); |
634 DCHECK(icon_ != NULL); | 650 DCHECK(icon_ != NULL); |
635 | 651 |
636 desired_language_ = "en-us"; | 652 desired_language_ = "en-us"; |
637 regular_font_ = reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)); | 653 regular_font_ = reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)); |
638 DCHECK(regular_font_ != NULL); | 654 DCHECK(regular_font_ != NULL); |
639 | 655 |
640 LOGFONT font_info = {0}; | 656 LOGFONT font_info = {0}; |
641 GetObject(regular_font_, sizeof(LOGFONT), &font_info); | 657 GetObject(regular_font_, sizeof(LOGFONT), &font_info); |
642 font_info.lfWeight |= FW_BOLD; | 658 font_info.lfWeight |= FW_BOLD; |
643 bold_font_ = CreateFontIndirect(&font_info); | 659 bold_font_ = CreateFontIndirect(&font_info); |
644 DCHECK(bold_font_ != NULL); | 660 DCHECK(bold_font_ != NULL); |
645 | 661 |
646 font_info.lfUnderline = TRUE; | 662 font_info.lfUnderline = TRUE; |
647 underline_font_ = CreateFontIndirect(&font_info); | 663 underline_font_ = CreateFontIndirect(&font_info); |
648 DCHECK(underline_font_ != NULL); | 664 DCHECK(underline_font_ != NULL); |
649 return true; | 665 return true; |
650 } | 666 } |
651 | 667 |
652 void PluginInstallerImpl::NotifyPluginStatus(int status) { | 668 void PluginInstallerImpl::NotifyPluginStatus(int status) { |
653 default_plugin::g_browser->getvalue( | 669 ChildThread::current()->Send( |
654 instance_, | 670 new ChromePluginProcessHostMsg_MissingPluginStatus( |
655 static_cast<NPNVariable>( | 671 status, |
656 webkit::npapi::default_plugin::kMissingPluginStatusStart + status), | 672 renderer_process_id(), |
657 NULL); | 673 render_view_id(), |
| 674 hwnd())); |
658 } | 675 } |
OLD | NEW |