| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/default_plugin/plugin_impl_mac.h" | |
| 6 | |
| 7 #import <Cocoa/Cocoa.h> | |
| 8 | |
| 9 #include "base/file_util.h" | |
| 10 #include "base/path_service.h" | |
| 11 #include "base/string_util.h" | |
| 12 #include "chrome/common/chrome_plugin_messages.h" | |
| 13 #include "chrome/default_plugin/plugin_main.h" | |
| 14 #include "content/common/child_thread.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 #include "grit/default_plugin_resources.h" | |
| 17 #include "grit/webkit_strings.h" | |
| 18 #include "ui/base/l10n/l10n_util.h" | |
| 19 #include "ui/base/l10n/l10n_util_mac.h" | |
| 20 #include "ui/base/resource/resource_bundle.h" | |
| 21 #include "ui/gfx/image/image.h" | |
| 22 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | |
| 23 #include "unicode/locid.h" | |
| 24 #include "webkit/glue/webkit_glue.h" | |
| 25 #include "webkit/plugins/npapi/default_plugin_shared.h" | |
| 26 | |
| 27 // TODO(thakis): Most methods in this class are stubbed out and need to be | |
| 28 // implemented. | |
| 29 | |
| 30 PluginInstallerImpl::PluginInstallerImpl(int16 mode) | |
| 31 : image_(nil), | |
| 32 command_(nil) { | |
| 33 } | |
| 34 | |
| 35 PluginInstallerImpl::~PluginInstallerImpl() { | |
| 36 [command_ release]; | |
| 37 } | |
| 38 | |
| 39 bool PluginInstallerImpl::Initialize(void* module_handle, NPP instance, | |
| 40 NPMIMEType mime_type, int16 argc, | |
| 41 char* argn[], char* argv[]) { | |
| 42 DVLOG(1) << __FUNCTION__ << " MIME Type : " << mime_type; | |
| 43 DCHECK(instance != NULL); | |
| 44 | |
| 45 if (mime_type == NULL || strlen(mime_type) == 0) { | |
| 46 DLOG(WARNING) << __FUNCTION__ << " Invalid parameters passed in"; | |
| 47 NOTREACHED(); | |
| 48 return false; | |
| 49 } | |
| 50 | |
| 51 instance_ = instance; | |
| 52 mime_type_ = mime_type; | |
| 53 | |
| 54 command_ = [l10n_util::FixUpWindowsStyleLabel(l10n_util::GetStringUTF16( | |
| 55 IDS_DEFAULT_PLUGIN_NO_PLUGIN_AVAILABLE_MSG)) retain]; | |
| 56 | |
| 57 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 58 image_ = rb.GetNativeImageNamed(IDR_PLUGIN_ICON); | |
| 59 | |
| 60 PluginInstallerBase::SetRoutingIds(argc, argn, argv); | |
| 61 return true; | |
| 62 } | |
| 63 | |
| 64 bool PluginInstallerImpl::NPP_SetWindow(NPWindow* window_info) { | |
| 65 width_ = window_info->width; | |
| 66 height_ = window_info->height; | |
| 67 return true; | |
| 68 } | |
| 69 | |
| 70 void PluginInstallerImpl::Shutdown() { | |
| 71 } | |
| 72 | |
| 73 void PluginInstallerImpl::NewStream(NPStream* stream) { | |
| 74 plugin_install_stream_ = stream; | |
| 75 } | |
| 76 | |
| 77 void PluginInstallerImpl::DestroyStream(NPStream* stream, NPError reason) { | |
| 78 if (stream == plugin_install_stream_) | |
| 79 plugin_install_stream_ = NULL; | |
| 80 } | |
| 81 | |
| 82 bool PluginInstallerImpl::WriteReady(NPStream* stream) { | |
| 83 bool ready_to_accept_data = false; | |
| 84 return ready_to_accept_data; | |
| 85 } | |
| 86 | |
| 87 int32 PluginInstallerImpl::Write(NPStream* stream, int32 offset, | |
| 88 int32 buffer_length, void* buffer) { | |
| 89 return true; | |
| 90 } | |
| 91 | |
| 92 void PluginInstallerImpl::ClearDisplay() { | |
| 93 } | |
| 94 | |
| 95 void PluginInstallerImpl::RefreshDisplay() { | |
| 96 } | |
| 97 | |
| 98 bool PluginInstallerImpl::CreateToolTip() { | |
| 99 return true; | |
| 100 } | |
| 101 | |
| 102 void PluginInstallerImpl::UpdateToolTip() { | |
| 103 } | |
| 104 | |
| 105 void PluginInstallerImpl::DisplayAvailablePluginStatus() { | |
| 106 } | |
| 107 | |
| 108 void PluginInstallerImpl::DisplayStatus(int message_resource_id) { | |
| 109 } | |
| 110 | |
| 111 void PluginInstallerImpl::DisplayPluginDownloadFailedStatus() { | |
| 112 } | |
| 113 | |
| 114 void PluginInstallerImpl::URLNotify(const char* url, NPReason reason) { | |
| 115 } | |
| 116 | |
| 117 int16 PluginInstallerImpl::NPP_HandleEvent(void* event) { | |
| 118 NPCocoaEvent* npp_event = static_cast<NPCocoaEvent*>(event); | |
| 119 | |
| 120 if (npp_event->type == NPCocoaEventDrawRect) { | |
| 121 CGContextRef context = npp_event->data.draw.context; | |
| 122 CGRect rect = CGRectMake(npp_event->data.draw.x, | |
| 123 npp_event->data.draw.y, | |
| 124 npp_event->data.draw.width, | |
| 125 npp_event->data.draw.height); | |
| 126 return OnDrawRect(context, rect); | |
| 127 } | |
| 128 return 0; | |
| 129 } | |
| 130 | |
| 131 std::wstring PluginInstallerImpl::ReplaceStringForPossibleEmptyReplacement( | |
| 132 int message_id_with_placeholders, | |
| 133 int messsage_id_without_placeholders, | |
| 134 const std::wstring& replacement_string) { | |
| 135 return L""; | |
| 136 } | |
| 137 | |
| 138 void PluginInstallerImpl::DownloadPlugin() { | |
| 139 } | |
| 140 | |
| 141 void PluginInstallerImpl::DownloadCancelled() { | |
| 142 DisplayAvailablePluginStatus(); | |
| 143 } | |
| 144 | |
| 145 int16 PluginInstallerImpl::OnDrawRect(CGContextRef context, CGRect dirty_rect) { | |
| 146 gfx::ScopedNSGraphicsContextSaveGState scoped_state; | |
| 147 NSGraphicsContext* ns_context = [NSGraphicsContext | |
| 148 graphicsContextWithGraphicsPort:context flipped:YES]; | |
| 149 [NSGraphicsContext setCurrentContext:ns_context]; | |
| 150 | |
| 151 // Fill background. | |
| 152 NSColor* bg_color = [NSColor colorWithCalibratedRed:252 / 255.0 | |
| 153 green:235 / 255.0 | |
| 154 blue:162 / 255.0 | |
| 155 alpha:1.0]; | |
| 156 [bg_color setFill]; | |
| 157 NSRectFill(NSRectFromCGRect(dirty_rect)); | |
| 158 | |
| 159 [[NSColor blackColor] set]; | |
| 160 NSFrameRect(NSMakeRect(0, 0, width_, height_)); | |
| 161 | |
| 162 // Drag image. | |
| 163 DCHECK(image_); | |
| 164 if (image_) { | |
| 165 NSPoint point = NSMakePoint((width_ - [image_ size].width) / 2, | |
| 166 (height_ + [image_ size].height) / 2); | |
| 167 [image_ dissolveToPoint:point fraction:1.0]; | |
| 168 } | |
| 169 | |
| 170 // Draw text. | |
| 171 NSShadow* shadow = [[[NSShadow alloc] init] autorelease]; | |
| 172 [shadow setShadowColor:[NSColor colorWithDeviceWhite:1.0 alpha:0.5]]; | |
| 173 [shadow setShadowOffset:NSMakeSize(0, -1)]; | |
| 174 NSFont* font = [NSFont systemFontOfSize: | |
| 175 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]; | |
| 176 NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: | |
| 177 font, NSFontAttributeName, | |
| 178 [NSColor blackColor], NSForegroundColorAttributeName, | |
| 179 shadow, NSShadowAttributeName, | |
| 180 nil]; | |
| 181 | |
| 182 NSSize text_size = [command_ sizeWithAttributes:attributes]; | |
| 183 NSPoint label_point = NSMakePoint((width_ - text_size.width) / 2, | |
| 184 (height_ - text_size.height) / 2); | |
| 185 if (image_) | |
| 186 label_point.y += [image_ size].height / 2 + text_size.height / 2 + 10; | |
| 187 label_point = NSMakePoint(roundf(label_point.x), roundf(label_point.y)); | |
| 188 [command_ drawAtPoint:label_point withAttributes:attributes]; | |
| 189 | |
| 190 return 1; | |
| 191 } | |
| 192 | |
| 193 | |
| 194 void PluginInstallerImpl::ShowInstallDialog() { | |
| 195 } | |
| 196 | |
| 197 void PluginInstallerImpl::NotifyPluginStatus(int status) { | |
| 198 ChildThread::current()->Send( | |
| 199 new ChromePluginProcessHostMsg_MissingPluginStatus( | |
| 200 status, | |
| 201 renderer_process_id(), | |
| 202 render_view_id(), | |
| 203 0)); | |
| 204 } | |
| OLD | NEW |