diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 21:29:08 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 21:29:08 +0000 |
commit | cff6677d1dbc8c6f2c7291402ae2796836246cc5 (patch) | |
tree | 4245a804c348f0dd22537d8aedda160314efb087 /webkit | |
parent | 57b9d1b1590c6e34c54c59817b5c3dcce81a1243 (diff) | |
download | chromium_src-cff6677d1dbc8c6f2c7291402ae2796836246cc5.zip chromium_src-cff6677d1dbc8c6f2c7291402ae2796836246cc5.tar.gz chromium_src-cff6677d1dbc8c6f2c7291402ae2796836246cc5.tar.bz2 |
Mac: First steps for default plugin
BUG=17392
TEST=Go to http://www.adobe.com/shockwave/welcome/. The task manager should show that the default plugin is running, and the "Missing Plug-in" text should look slightly different than it did before. (this test depends on a small webkit patch)
Requires commenting out
if (objectContentType(url, mimeType) != ObjectContentNetscapePlugin)
return 0;
in WebKit/WebKit/chromium/src/FrameLoaderClientImpl.cpp's createPlugin() as well, else the default plugin won't load.
Review URL: http://codereview.chromium.org/2075006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47726 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/default_plugin/default_plugin.gyp | 45 | ||||
-rw-r--r-- | webkit/default_plugin/plugin_impl_mac.h | 68 | ||||
-rw-r--r-- | webkit/default_plugin/plugin_impl_mac.mm | 179 | ||||
-rw-r--r-- | webkit/default_plugin/plugin_impl_win.cc | 5 | ||||
-rw-r--r-- | webkit/default_plugin/plugin_impl_win.h | 6 | ||||
-rw-r--r-- | webkit/default_plugin/plugin_main.cc | 63 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list.cc | 2 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 |
8 files changed, 288 insertions, 82 deletions
diff --git a/webkit/default_plugin/default_plugin.gyp b/webkit/default_plugin/default_plugin.gyp index 10450d6..4092a2e 100644 --- a/webkit/default_plugin/default_plugin.gyp +++ b/webkit/default_plugin/default_plugin.gyp @@ -3,10 +3,13 @@ # found in the LICENSE file. { + 'variables': { + 'chromium_code': 1, + }, 'targets': [ ], 'conditions': [ - ['OS=="win"', { + ['OS=="win" or OS=="mac"', { 'targets': [ { 'target_name': 'default_plugin', @@ -17,8 +20,6 @@ '../../third_party/icu/icu.gyp:icuuc', '../../third_party/libxml/libxml.gyp:libxml', '../../third_party/npapi/npapi.gyp:npapi', - '../support/webkit_support.gyp:webkit_resources', - '../support/webkit_support.gyp:webkit_strings', ], 'include_dirs': [ '../..', @@ -26,28 +27,42 @@ # TODO(bradnelson): this should fall out of the dependencies. '<(SHARED_INTERMEDIATE_DIR)/webkit', ], - 'msvs_guid': '5916D37D-8C97-424F-A904-74E52594C2D6', 'sources': [ 'default_plugin.cc', - 'default_plugin_resources.h', 'default_plugin_shared.h', - 'install_dialog.cc', - 'install_dialog.h', - 'plugin_database_handler.cc', - 'plugin_database_handler.h', + 'plugin_impl_mac.h', + 'plugin_impl_mac.mm', 'plugin_impl_win.cc', 'plugin_impl_win.h', - 'plugin_install_job_monitor.cc', - 'plugin_install_job_monitor.h', 'plugin_main.cc', 'plugin_main.h', ], - 'link_settings': { - 'libraries': ['-lurlmon.lib'], - }, + 'conditions': [ + ['OS=="win"', { + 'dependencies': [ + # TODO(thakis): These throw a CircularException on mac. + # Figure out why once they're needed. + '../support/webkit_support.gyp:webkit_resources', + '../support/webkit_support.gyp:webkit_strings', + ], + 'msvs_guid': '5916D37D-8C97-424F-A904-74E52594C2D6', + 'link_settings': { + 'libraries': ['-lurlmon.lib'], + }, + 'sources': [ + 'default_plugin_resources.h', + 'install_dialog.cc', + 'install_dialog.h', + 'plugin_database_handler.cc', + 'plugin_database_handler.h', + 'plugin_install_job_monitor.cc', + 'plugin_install_job_monitor.h', + ], + }], + ], }, ], - },], + }], ], } diff --git a/webkit/default_plugin/plugin_impl_mac.h b/webkit/default_plugin/plugin_impl_mac.h index bd9cd77..96686a3 100644 --- a/webkit/default_plugin/plugin_impl_mac.h +++ b/webkit/default_plugin/plugin_impl_mac.h @@ -9,9 +9,7 @@ #include <vector> #include "third_party/npapi/bindings/npapi.h" -// #include "webkit/default_plugin/install_dialog.h" -// #include "webkit/default_plugin/plugin_database_handler.h" -// #include "webkit/default_plugin/plugin_install_job_monitor.h" +#include "gfx/native_widget_types.h" // Possible plugin installer states. enum PluginInstallerState { @@ -58,14 +56,14 @@ class PluginInstallerImpl { bool Initialize(void *module_handle, NPP instance, NPMIMEType mime_type, int16 argc, char* argn[], char* argv[]); - // Displays the default plugin UI. + // Informs the plugin of its window information. // // Parameters: - // parent_window - // Handle to the parent window. - bool SetWindow(gfx::NativeView parent_view); + // window_info + // The window info passed to npapi. + bool NPP_SetWindow(NPWindow* window_info); - // Destroys the install dialog and the plugin window. + // Destroys the install dialog. void Shutdown(); // Starts plugin download. Spawns the plugin installer after it is @@ -127,7 +125,9 @@ class PluginInstallerImpl { // Describes why the notification was sent. void URLNotify(const char* url, NPReason reason); - // gfx::NativeView window() const { return m_hWnd; } + // Used by the renderer to indicate plugin install through the infobar. + int16 NPP_HandleEvent(void* event); + const std::string& mime_type() const { return mime_type_; } // Replaces a resource string with the placeholder passed in as an argument @@ -168,6 +168,8 @@ class PluginInstallerImpl { bool IsRTLLayout() const; protected: + int16 OnDrawRect(CGContextRef context, CGRect dirty_rect); + // Displays the plugin install confirmation dialog. void ShowInstallDialog(); @@ -266,57 +268,15 @@ class PluginInstallerImpl { // The plugins opaque instance handle NPP instance_; - // If this is to install activex - bool is_activex_; - // The plugin instantiation mode (NP_FULL or NP_EMBED) - int16 mode_; - // The handle to the icon displayed in the plugin installation window. - // HICON icon_; - // The Get plugin link message string displayed at the top left corner of - // the plugin window. - std::wstring get_plugin_link_message_; - // The command string displayed in the plugin installation window. - std::wstring command_; - // An additional message displayed at times by the plugin. - std::wstring optional_additional_message_; // The current stream. NPStream* plugin_install_stream_; - // The plugin finder URL. - std::string plugin_finder_url_; // The desired mime type. std::string mime_type_; - // The desired language. - std::string desired_language_; - // The plugin name. - std::wstring plugin_name_; - // The actual download URL. - std::string plugin_download_url_; - // Indicates if the plugin download URL points to an exe. - bool plugin_download_url_for_display_; // The current state of the plugin installer. PluginInstallerState plugin_installer_state_; - // Used to display the UI for plugin installation. - // PluginInstallDialog install_dialog_; - // To enable auto refresh of the plugin window once the installation - // is complete, we spawn the installation process in a job, and monitor - // IO completion events on the job. When the active process count of the - // job falls to zero, we initiate an auto refresh of the plugin list - // which enables the downloaded plugin to be instantiated. - // The completion events from the job are monitored in an independent - // thread. - // scoped_refptr<PluginInstallationJobMonitorThread> - // installation_job_monitor_thread_; - // This object handles download and parsing of the plugins database. - // PluginDatabaseHandler plugin_database_handler_; - // Indicates if the left click to download/refresh should be enabled or not. - bool enable_click_; - // Handles to the fonts used to display text in the plugin window. - // HFONT bold_font_; - // HFONT regular_font_; - // HFONT underline_font_; - // Tooltip Window. - gfx::NativeWindow tooltip_; - + // Dimensions of the plugin + uint32_t width_; + uint32_t height_; DISALLOW_EVIL_CONSTRUCTORS(PluginInstallerImpl); }; diff --git a/webkit/default_plugin/plugin_impl_mac.mm b/webkit/default_plugin/plugin_impl_mac.mm new file mode 100644 index 0000000..290fa1c --- /dev/null +++ b/webkit/default_plugin/plugin_impl_mac.mm @@ -0,0 +1,179 @@ +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/default_plugin/plugin_impl_mac.h" + +#import <Cocoa/Cocoa.h> + +#include "base/file_util.h" +#include "base/path_service.h" +#include "base/string_util.h" +#include "googleurl/src/gurl.h" +#include "grit/webkit_strings.h" +#include "unicode/locid.h" +#include "webkit/default_plugin/default_plugin_shared.h" +#include "webkit/default_plugin/plugin_main.h" +#include "webkit/glue/webkit_glue.h" + +// TODO(thakis): Most methods in this class are stubbed out and need to be +// implemented. + +PluginInstallerImpl::PluginInstallerImpl(int16 mode) { +} + +PluginInstallerImpl::~PluginInstallerImpl() { +} + +bool PluginInstallerImpl::Initialize(void* module_handle, NPP instance, + NPMIMEType mime_type, int16 argc, + char* argn[], char* argv[]) { + DLOG(INFO) << __FUNCTION__ << " MIME Type : " << mime_type; + DCHECK(instance != NULL); + + if (mime_type == NULL || strlen(mime_type) == 0) { + DLOG(WARNING) << __FUNCTION__ << " Invalid parameters passed in"; + NOTREACHED(); + return false; + } + + instance_ = instance; + mime_type_ = mime_type; + + return true; +} + +bool PluginInstallerImpl::NPP_SetWindow(NPWindow* window_info) { + width_ = window_info->width; + height_ = window_info->height; + return true; +} + +void PluginInstallerImpl::Shutdown() { +} + +void PluginInstallerImpl::NewStream(NPStream* stream) { + plugin_install_stream_ = stream; +} + +void PluginInstallerImpl::DestroyStream(NPStream* stream, NPError reason) { + if (stream == plugin_install_stream_) + plugin_install_stream_ = NULL; +} + +bool PluginInstallerImpl::WriteReady(NPStream* stream) { + bool ready_to_accept_data = false; + return ready_to_accept_data; +} + +int32 PluginInstallerImpl::Write(NPStream* stream, int32 offset, + int32 buffer_length, void* buffer) { + return true; +} + +void PluginInstallerImpl::ClearDisplay() { +} + +void PluginInstallerImpl::RefreshDisplay() { +} + +bool PluginInstallerImpl::CreateToolTip() { + return true; +} + +void PluginInstallerImpl::UpdateToolTip() { +} + +void PluginInstallerImpl::DisplayAvailablePluginStatus() { +} + +void PluginInstallerImpl::DisplayStatus(int message_resource_id) { +} + +void PluginInstallerImpl::DisplayPluginDownloadFailedStatus() { +} + +void PluginInstallerImpl::URLNotify(const char* url, NPReason reason) { +} + +int16 PluginInstallerImpl::NPP_HandleEvent(void* event) { + NPCocoaEvent* npp_event = static_cast<NPCocoaEvent*>(event); + + if (npp_event->type == NPCocoaEventDrawRect) { + CGContextRef context = npp_event->data.draw.context; + CGRect rect = CGRectMake(npp_event->data.draw.x, + npp_event->data.draw.y, + npp_event->data.draw.width, + npp_event->data.draw.height); + return OnDrawRect(context, rect); + } + return 0; +} + +std::wstring PluginInstallerImpl::ReplaceStringForPossibleEmptyReplacement( + int message_id_with_placeholders, + int messsage_id_without_placeholders, + const std::wstring& replacement_string) { + return L""; +} + +void PluginInstallerImpl::DownloadPlugin() { +} + +void PluginInstallerImpl::DownloadCancelled() { + DisplayAvailablePluginStatus(); +} + +int16 PluginInstallerImpl::OnDrawRect(CGContextRef context, CGRect dirty_rect) { + const NSString* text = @"Missing Plug-in"; + const float kTextMarginX = 6; + const float kTextMarginY = 1; + NSSize bounds = NSMakeSize(width_, height_); + + [NSGraphicsContext saveGraphicsState]; + NSGraphicsContext* ns_context = [NSGraphicsContext + graphicsContextWithGraphicsPort:context flipped:YES]; + [NSGraphicsContext setCurrentContext:ns_context]; + + NSShadow* shadow = [[[NSShadow alloc] init] autorelease]; + [shadow setShadowColor:[NSColor colorWithDeviceWhite:0.0 alpha:0.5]]; + [shadow setShadowOffset:NSMakeSize(0, -1)]; + NSFont* font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]]; + NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: + font, NSFontAttributeName, + [NSColor whiteColor], NSForegroundColorAttributeName, + shadow, NSShadowAttributeName, + nil]; + + NSSize text_size = [text sizeWithAttributes:attributes]; + NSRect text_rect; + text_rect.size.width = text_size.width + 2*kTextMarginX; + text_rect.size.height = text_size.height + 2*kTextMarginY; + text_rect.origin.x = (bounds.width - NSWidth(text_rect))/2; + text_rect.origin.y = (bounds.height - NSHeight(text_rect))/2; + + [[NSColor colorWithCalibratedWhite:0.52 alpha:1.0] setFill]; + [[NSBezierPath bezierPathWithRoundedRect:text_rect + xRadius:NSHeight(text_rect)/2 + yRadius:NSHeight(text_rect)/2] fill]; + + NSPoint label_point = NSMakePoint( + roundf(text_rect.origin.x + (text_rect.size.width - text_size.width)/2), + roundf(text_rect.origin.y + (text_rect.size.height - text_size.height)/2)); + [text drawAtPoint:label_point withAttributes:attributes]; + + [NSGraphicsContext restoreGraphicsState]; + return 1; +} + + +void PluginInstallerImpl::ShowInstallDialog() { +} + +void PluginInstallerImpl::NotifyPluginStatus(int status) { + default_plugin::g_browser->getvalue( + instance_, + static_cast<NPNVariable>( + default_plugin::kMissingPluginStatusStart + status), + NULL); +} diff --git a/webkit/default_plugin/plugin_impl_win.cc b/webkit/default_plugin/plugin_impl_win.cc index 2a62a1c..4920240 100644 --- a/webkit/default_plugin/plugin_impl_win.cc +++ b/webkit/default_plugin/plugin_impl_win.cc @@ -52,7 +52,7 @@ PluginInstallerImpl::~PluginInstallerImpl() { bool PluginInstallerImpl::Initialize(HINSTANCE module_handle, NPP instance, NPMIMEType mime_type, int16 argc, char* argn[], char* argv[]) { - DLOG(INFO) << __FUNCTION__ << " Mime Type : " << mime_type; + DLOG(INFO) << __FUNCTION__ << " MIME Type : " << mime_type; DCHECK(instance != NULL); DCHECK(module_handle != NULL); @@ -287,7 +287,8 @@ std::wstring PluginInstallerImpl::ReplaceStringForPossibleEmptyReplacement( } } -bool PluginInstallerImpl::SetWindow(HWND parent_window) { +bool PluginInstallerImpl::NPP_SetWindow(NPWindow* window_info) { + HWND parent_window = reinterpret_cast<HWND>(window_info->window); if (!IsWindow(parent_window)) { // No window created yet. Ignore this call. if (!IsWindow(hwnd())) diff --git a/webkit/default_plugin/plugin_impl_win.h b/webkit/default_plugin/plugin_impl_win.h index c1aa535..bc110ec 100644 --- a/webkit/default_plugin/plugin_impl_win.h +++ b/webkit/default_plugin/plugin_impl_win.h @@ -74,9 +74,9 @@ class PluginInstallerImpl : public app::WindowImpl { // Displays the default plugin UI. // // Parameters: - // parent_window - // Handle to the parent window. - bool SetWindow(HWND parent_window); + // window_info + // The window info passed to npapi. + bool NPP_SetWindow(NPWindow* window_info); // Destroys the install dialog and the plugin window. void Shutdown(); diff --git a/webkit/default_plugin/plugin_main.cc b/webkit/default_plugin/plugin_main.cc index 95dda07..a4dacc5 100644 --- a/webkit/default_plugin/plugin_main.cc +++ b/webkit/default_plugin/plugin_main.cc @@ -10,6 +10,8 @@ #include "webkit/glue/webkit_glue.h" namespace default_plugin { + +#if defined(OS_WIN) // // Forward declare the linker-provided pseudo variable for the // current module handle. @@ -20,6 +22,7 @@ extern "C" IMAGE_DOS_HEADER __ImageBase; inline HMODULE GetCurrentModuleHandle() { return reinterpret_cast<HINSTANCE>(&__ImageBase); } +#endif // Initialized in NP_Initialize. NPNetscapeFuncs* g_browser = NULL; @@ -71,13 +74,53 @@ void SignalTestResult(NPP instance) { static_cast<unsigned int>(script.length()); NPVariant result_var; - NPError result = g_browser->evaluate(instance, window_obj, - &script_string, &result_var); + g_browser->evaluate(instance, window_obj, + &script_string, &result_var); g_browser->releaseobject(window_obj); } } // namespace CHROMIUM_DefaultPluginTest +bool NegotiateModels(NPP instance) { +#if defined(OS_MACOSX) + NPError err; + // Set drawing model to core graphics + NPBool supportsCoreGraphics = FALSE; + err = g_browser->getvalue(instance, + NPNVsupportsCoreGraphicsBool, + &supportsCoreGraphics); + if (err != NPERR_NO_ERROR || !supportsCoreGraphics) { + NOTREACHED(); + return false; + } + err = g_browser->setvalue(instance, + NPPVpluginDrawingModel, + (void*)NPDrawingModelCoreGraphics); + if (err != NPERR_NO_ERROR) { + NOTREACHED(); + return false; + } + + // Set event model to cocoa + NPBool supportsCocoaEvents = FALSE; + err = g_browser->getvalue(instance, + NPNVsupportsCocoaBool, + &supportsCocoaEvents); + if (err != NPERR_NO_ERROR || !supportsCocoaEvents) { + NOTREACHED(); + return false; + } + err = g_browser->setvalue(instance, + NPPVpluginEventModel, + (void*)NPEventModelCocoa); + if (err != NPERR_NO_ERROR) { + NOTREACHED(); + return false; + } +#endif + return true; +} + NPError NPP_New(NPMIMEType plugin_type, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved) { if (instance == NULL) @@ -95,10 +138,19 @@ NPError NPP_New(NPMIMEType plugin_type, NPP instance, uint16 mode, int16 argc, return NPERR_GENERIC_ERROR; } - + if (!NegotiateModels(instance)) + return NPERR_INCOMPATIBLE_VERSION_ERROR; + PluginInstallerImpl* plugin_impl = new PluginInstallerImpl(mode); - plugin_impl->Initialize(GetCurrentModuleHandle(), instance, plugin_type, argc, + plugin_impl->Initialize( +#if defined(OS_WIN) + GetCurrentModuleHandle(), +#else + NULL, +#endif + instance, plugin_type, argc, argn, argv); + instance->pdata = reinterpret_cast<void*>(plugin_impl); return NPERR_NO_ERROR; } @@ -139,8 +191,7 @@ NPError NPP_SetWindow(NPP instance, NPWindow* window_info) { return NPERR_GENERIC_ERROR; } - HWND window_handle = reinterpret_cast<HWND>(window_info->window); - if (!plugin_impl->SetWindow(window_handle)) { + if (!plugin_impl->NPP_SetWindow(window_info)) { delete plugin_impl; return NPERR_GENERIC_ERROR; } diff --git a/webkit/glue/plugins/plugin_list.cc b/webkit/glue/plugins/plugin_list.cc index 7640b0c63..d0a628d 100644 --- a/webkit/glue/plugins/plugin_list.cc +++ b/webkit/glue/plugins/plugin_list.cc @@ -141,7 +141,7 @@ PluginList::PluginList() : plugins_loaded_(false), plugins_need_refresh_(false) { PlatformInit(); -#if defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_MACOSX) const PluginVersionInfo default_plugin = { FilePath(kDefaultPluginLibraryName), L"Default Plug-in", diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index f357109..3c42c6b 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -366,7 +366,7 @@ 'plugins/plugin_stubs.cc', ], }], - ['inside_chromium_build==1 and OS=="win"', { + ['inside_chromium_build==1 and (OS=="mac" or OS=="win")', { 'dependencies': [ '<(DEPTH)/webkit/default_plugin/default_plugin.gyp:default_plugin', ], |