| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "webkit/default_plugin/plugin_impl_win.h" | 5 #include "webkit/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" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 ::DestroyWindow(tooltip_); | 58 ::DestroyWindow(tooltip_); |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool PluginInstallerImpl::Initialize(HINSTANCE module_handle, NPP instance, | 61 bool PluginInstallerImpl::Initialize(HINSTANCE module_handle, NPP instance, |
| 62 NPMIMEType mime_type, int16 argc, | 62 NPMIMEType mime_type, int16 argc, |
| 63 char* argn[], char* argv[]) { | 63 char* argn[], char* argv[]) { |
| 64 DLOG(INFO) << __FUNCTION__ << " Mime Type : " << mime_type; | 64 DLOG(INFO) << __FUNCTION__ << " Mime Type : " << mime_type; |
| 65 DCHECK(instance != NULL); | 65 DCHECK(instance != NULL); |
| 66 DCHECK(module_handle != NULL); | 66 DCHECK(module_handle != NULL); |
| 67 | 67 |
| 68 instance_ = instance; |
| 69 mime_type_ = mime_type; |
| 70 |
| 68 // The clsid without the {} parentheses. | 71 // The clsid without the {} parentheses. |
| 69 std::string raw_activex_clsid; | 72 std::string raw_activex_clsid; |
| 70 if (!ParseInstantiationArguments(mime_type, instance, argc, argn, argv, | 73 if (!ParseInstantiationArguments(mime_type, instance, argc, argn, argv, |
| 71 &raw_activex_clsid)) { | 74 &raw_activex_clsid, &is_activex_, |
| 75 &activex_clsid_, |
| 76 &activex_codebase_, |
| 77 &plugin_download_url_, |
| 78 &plugin_finder_url_)) { |
| 72 DLOG(ERROR) << "Incorrect arguments passed to plugin"; | 79 DLOG(ERROR) << "Incorrect arguments passed to plugin"; |
| 73 NOTREACHED(); | 80 NOTREACHED(); |
| 74 return false; | 81 return false; |
| 75 } | 82 } |
| 76 | 83 |
| 77 if (!installation_job_monitor_thread_->Initialize()) { | 84 if (!installation_job_monitor_thread_->Initialize()) { |
| 78 DLOG(ERROR) << "Failed to initialize plugin install job"; | 85 DLOG(ERROR) << "Failed to initialize plugin install job"; |
| 79 NOTREACHED(); | 86 NOTREACHED(); |
| 80 return false; | 87 return false; |
| 81 } | 88 } |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 DisplayPluginDownloadFailedStatus(); | 667 DisplayPluginDownloadFailedStatus(); |
| 661 } else { | 668 } else { |
| 662 set_plugin_installer_state(PluginInstallerLaunchFailure); | 669 set_plugin_installer_state(PluginInstallerLaunchFailure); |
| 663 DisplayStatus(IDS_DEFAULT_PLUGIN_INSTALLATION_FAILED_MSG); | 670 DisplayStatus(IDS_DEFAULT_PLUGIN_INSTALLATION_FAILED_MSG); |
| 664 } | 671 } |
| 665 return 0; | 672 return 0; |
| 666 } | 673 } |
| 667 | 674 |
| 668 std::string PluginInstallerImpl::ResolveURL(NPP instance, | 675 std::string PluginInstallerImpl::ResolveURL(NPP instance, |
| 669 const std::string& relative_url) { | 676 const std::string& relative_url) { |
| 670 NPObject* object = NULL; | 677 // The NPAPI functions may not be available if this function is called |
| 671 default_plugin::g_browser->getvalue(instance, NPNVWindowNPObject, &object); | 678 // as a result of a unit test. |
| 672 activex_shim::NPNScriptableObject window(instance, object); | 679 if (default_plugin::g_browser) { |
| 673 std::wstring url = | 680 NPObject* object = NULL; |
| 674 window.GetObjectProperty("document").GetStringProperty("URL"); | 681 default_plugin::g_browser->getvalue(instance, NPNVWindowNPObject, &object); |
| 675 GURL base(url); | 682 activex_shim::NPNScriptableObject window(instance, object); |
| 676 return base.Resolve(relative_url).spec(); | 683 std::wstring url = |
| 684 window.GetObjectProperty("document").GetStringProperty("URL"); |
| 685 GURL base(url); |
| 686 return base.Resolve(relative_url).spec(); |
| 687 } |
| 688 return relative_url; |
| 677 } | 689 } |
| 678 | 690 |
| 679 bool PluginInstallerImpl::InitializeResources(HINSTANCE module_handle) { | 691 bool PluginInstallerImpl::InitializeResources(HINSTANCE module_handle) { |
| 680 DCHECK(icon_ == NULL); | 692 DCHECK(icon_ == NULL); |
| 681 DCHECK(regular_font_ == NULL); | 693 DCHECK(regular_font_ == NULL); |
| 682 DCHECK(bold_font_ == NULL); | 694 DCHECK(bold_font_ == NULL); |
| 683 DCHECK(underline_font_ == NULL); | 695 DCHECK(underline_font_ == NULL); |
| 684 | 696 |
| 685 icon_ = LoadIcon(module_handle, MAKEINTRESOURCE(IDI_DEFAULT_PLUGIN_ICON)); | 697 icon_ = LoadIcon(module_handle, MAKEINTRESOURCE(IDI_DEFAULT_PLUGIN_ICON)); |
| 686 DCHECK(icon_ != NULL); | 698 DCHECK(icon_ != NULL); |
| 687 | 699 |
| 688 desired_language_ = "en-us"; | 700 desired_language_ = "en-us"; |
| 689 regular_font_ = reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)); | 701 regular_font_ = reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)); |
| 690 DCHECK(regular_font_ != NULL); | 702 DCHECK(regular_font_ != NULL); |
| 691 | 703 |
| 692 LOGFONT font_info = {0}; | 704 LOGFONT font_info = {0}; |
| 693 GetObject(regular_font_, sizeof(LOGFONT), &font_info); | 705 GetObject(regular_font_, sizeof(LOGFONT), &font_info); |
| 694 font_info.lfWeight |= FW_BOLD; | 706 font_info.lfWeight |= FW_BOLD; |
| 695 bold_font_ = CreateFontIndirect(&font_info); | 707 bold_font_ = CreateFontIndirect(&font_info); |
| 696 DCHECK(bold_font_ != NULL); | 708 DCHECK(bold_font_ != NULL); |
| 697 | 709 |
| 698 font_info.lfUnderline = TRUE; | 710 font_info.lfUnderline = TRUE; |
| 699 underline_font_ = CreateFontIndirect(&font_info); | 711 underline_font_ = CreateFontIndirect(&font_info); |
| 700 DCHECK(underline_font_ != NULL); | 712 DCHECK(underline_font_ != NULL); |
| 701 return true; | 713 return true; |
| 702 } | 714 } |
| 703 | 715 |
| 704 bool PluginInstallerImpl::ParseInstantiationArguments( | 716 bool PluginInstallerImpl::ParseInstantiationArguments( |
| 705 NPMIMEType mime_type, NPP instance, int16 argc, char* argn[], char* argv[], | 717 NPMIMEType mime_type, |
| 706 std::string* raw_activex_clsid) { | 718 NPP instance, |
| 707 instance_ = instance; | 719 int16 argc, |
| 708 mime_type_ = mime_type; | 720 char* argn[], |
| 721 char* argv[], |
| 722 std::string* raw_activex_clsid, |
| 723 bool* is_activex, |
| 724 std::string* activex_clsid, |
| 725 std::string* activex_codebase, |
| 726 std::string* plugin_download_url, |
| 727 std::string* plugin_finder_url) { |
| 728 |
| 729 if (!raw_activex_clsid || !is_activex || !activex_clsid || |
| 730 !plugin_download_url || !plugin_finder_url || !activex_codebase) { |
| 731 NOTREACHED(); |
| 732 return false; |
| 733 } |
| 734 |
| 735 *is_activex = false; |
| 736 |
| 737 bool valid_mime_type = (mime_type != NULL ? strlen(mime_type) > 0 : false); |
| 709 | 738 |
| 710 for (int i = 0; i < argc; ++i) { | 739 for (int i = 0; i < argc; ++i) { |
| 711 if (LowerCaseEqualsASCII(argn[i], "classid") && | 740 // We should only look for activex installation if the mime type passed in |
| 741 // is not valid. In any case this code will be taken out when we remove |
| 742 // the activex shim. |
| 743 if (!valid_mime_type && LowerCaseEqualsASCII(argn[i], "classid") && |
| 712 activex_shim::GetClsidFromClassidAttribute(argv[i], | 744 activex_shim::GetClsidFromClassidAttribute(argv[i], |
| 713 raw_activex_clsid)) { | 745 raw_activex_clsid)) { |
| 714 is_activex_ = true; | 746 *is_activex = true; |
| 715 activex_clsid_ = std::string("{") + *raw_activex_clsid + "}"; | 747 *activex_clsid = std::string("{") + *raw_activex_clsid + "}"; |
| 716 } | 748 } |
| 717 if (LowerCaseEqualsASCII(argn[i], "codebase")) { | 749 if (LowerCaseEqualsASCII(argn[i], "codebase")) { |
| 718 activex_codebase_ = ResolveURL(instance, argv[i]); | 750 *activex_codebase = ResolveURL(instance, argv[i]); |
| 719 size_t pos = activex_codebase_.find('#'); | 751 size_t pos = activex_codebase->find('#'); |
| 720 if (pos != std::string::npos) | 752 if (pos != std::string::npos) |
| 721 plugin_download_url_ = activex_codebase_.substr(0, pos); | 753 *plugin_download_url = activex_codebase->substr(0, pos); |
| 722 else | 754 else |
| 723 plugin_download_url_ = activex_codebase_; | 755 *plugin_download_url = *activex_codebase; |
| 724 } | 756 } |
| 725 } | 757 } |
| 726 | 758 |
| 727 if (!is_activex_) { | 759 if (!*is_activex) { |
| 728 if (!mime_type || !instance) { | 760 if (!valid_mime_type || !instance) { |
| 729 DLOG(WARNING) << __FUNCTION__ << " Invalid parameters passed in"; | 761 DLOG(WARNING) << __FUNCTION__ << " Invalid parameters passed in"; |
| 730 NOTREACHED(); | 762 NOTREACHED(); |
| 731 return false; | 763 return false; |
| 732 } | 764 } |
| 733 | 765 |
| 734 if (!webkit_glue::GetPluginFinderURL(&plugin_finder_url_)) { | 766 if (!webkit_glue::GetPluginFinderURL(plugin_finder_url)) { |
| 735 NOTREACHED(); | 767 NOTREACHED(); |
| 736 DLOG(WARNING) << __FUNCTION__ << " Failed to get the plugin finder URL"; | 768 DLOG(WARNING) << __FUNCTION__ << " Failed to get the plugin finder URL"; |
| 737 return false; | 769 return false; |
| 738 } | 770 } |
| 739 | 771 |
| 740 DLOG(INFO) << "Plugin finder URL is " << plugin_finder_url_.c_str(); | 772 DLOG(INFO) << "Plugin finder URL is " << plugin_finder_url->c_str(); |
| 741 } | 773 } |
| 742 | 774 |
| 743 return true; | 775 return true; |
| 744 } | 776 } |
| 745 | 777 |
| 746 void PluginInstallerImpl::NotifyPluginStatus(int status) { | 778 void PluginInstallerImpl::NotifyPluginStatus(int status) { |
| 747 default_plugin::g_browser->getvalue( | 779 default_plugin::g_browser->getvalue( |
| 748 instance_, | 780 instance_, |
| 749 static_cast<NPNVariable>( | 781 static_cast<NPNVariable>( |
| 750 default_plugin::kMissingPluginStatusStart + status), | 782 default_plugin::kMissingPluginStatusStart + status), |
| 751 NULL); | 783 NULL); |
| 752 } | 784 } |
| OLD | NEW |