OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "webkit/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 "googleurl/src/gurl.h" | |
13 #include "grit/webkit_strings.h" | |
14 #include "unicode/locid.h" | |
15 #include "webkit/default_plugin/default_plugin_shared.h" | |
16 #include "webkit/default_plugin/plugin_main.h" | |
17 #include "webkit/glue/webkit_glue.h" | |
18 | |
19 // TODO(thakis): Most methods in this class are stubbed out and need to be | |
20 // implemented. | |
21 | |
22 PluginInstallerImpl::PluginInstallerImpl(int16 mode) { | |
23 } | |
24 | |
25 PluginInstallerImpl::~PluginInstallerImpl() { | |
26 } | |
27 | |
28 bool PluginInstallerImpl::Initialize(void* module_handle, NPP instance, | |
29 NPMIMEType mime_type, int16 argc, | |
30 char* argn[], char* argv[]) { | |
31 DLOG(INFO) << __FUNCTION__ << " MIME Type : " << mime_type; | |
32 DCHECK(instance != NULL); | |
33 | |
34 if (mime_type == NULL || strlen(mime_type) == 0) { | |
35 DLOG(WARNING) << __FUNCTION__ << " Invalid parameters passed in"; | |
36 NOTREACHED(); | |
37 return false; | |
38 } | |
39 | |
40 instance_ = instance; | |
41 mime_type_ = mime_type; | |
42 | |
43 return true; | |
44 } | |
45 | |
46 bool PluginInstallerImpl::NPP_SetWindow(NPWindow* window_info) { | |
47 width_ = window_info->width; | |
48 height_ = window_info->height; | |
49 return true; | |
50 } | |
51 | |
52 void PluginInstallerImpl::Shutdown() { | |
53 } | |
54 | |
55 void PluginInstallerImpl::NewStream(NPStream* stream) { | |
56 plugin_install_stream_ = stream; | |
57 } | |
58 | |
59 void PluginInstallerImpl::DestroyStream(NPStream* stream, NPError reason) { | |
60 if (stream == plugin_install_stream_) | |
61 plugin_install_stream_ = NULL; | |
62 } | |
63 | |
64 bool PluginInstallerImpl::WriteReady(NPStream* stream) { | |
65 bool ready_to_accept_data = false; | |
66 return ready_to_accept_data; | |
67 } | |
68 | |
69 int32 PluginInstallerImpl::Write(NPStream* stream, int32 offset, | |
70 int32 buffer_length, void* buffer) { | |
71 return true; | |
72 } | |
73 | |
74 void PluginInstallerImpl::ClearDisplay() { | |
75 } | |
76 | |
77 void PluginInstallerImpl::RefreshDisplay() { | |
78 } | |
79 | |
80 bool PluginInstallerImpl::CreateToolTip() { | |
81 return true; | |
82 } | |
83 | |
84 void PluginInstallerImpl::UpdateToolTip() { | |
85 } | |
86 | |
87 void PluginInstallerImpl::DisplayAvailablePluginStatus() { | |
88 } | |
89 | |
90 void PluginInstallerImpl::DisplayStatus(int message_resource_id) { | |
91 } | |
92 | |
93 void PluginInstallerImpl::DisplayPluginDownloadFailedStatus() { | |
94 } | |
95 | |
96 void PluginInstallerImpl::URLNotify(const char* url, NPReason reason) { | |
97 } | |
98 | |
99 int16 PluginInstallerImpl::NPP_HandleEvent(void* event) { | |
100 NPCocoaEvent* npp_event = static_cast<NPCocoaEvent*>(event); | |
101 | |
102 if (npp_event->type == NPCocoaEventDrawRect) { | |
103 CGContextRef context = npp_event->data.draw.context; | |
104 CGRect rect = CGRectMake(npp_event->data.draw.x, | |
105 npp_event->data.draw.y, | |
106 npp_event->data.draw.width, | |
107 npp_event->data.draw.height); | |
108 return OnDrawRect(context, rect); | |
109 } | |
110 return 0; | |
111 } | |
112 | |
113 std::wstring PluginInstallerImpl::ReplaceStringForPossibleEmptyReplacement( | |
114 int message_id_with_placeholders, | |
115 int messsage_id_without_placeholders, | |
116 const std::wstring& replacement_string) { | |
117 return L""; | |
118 } | |
119 | |
120 void PluginInstallerImpl::DownloadPlugin() { | |
121 } | |
122 | |
123 void PluginInstallerImpl::DownloadCancelled() { | |
124 DisplayAvailablePluginStatus(); | |
125 } | |
126 | |
127 int16 PluginInstallerImpl::OnDrawRect(CGContextRef context, CGRect dirty_rect) { | |
128 const NSString* text = @"Missing Plug-in"; | |
129 const float kTextMarginX = 6; | |
130 const float kTextMarginY = 1; | |
131 NSSize bounds = NSMakeSize(width_, height_); | |
132 | |
133 [NSGraphicsContext saveGraphicsState]; | |
134 NSGraphicsContext* ns_context = [NSGraphicsContext | |
135 graphicsContextWithGraphicsPort:context flipped:YES]; | |
136 [NSGraphicsContext setCurrentContext:ns_context]; | |
137 | |
138 NSShadow* shadow = [[[NSShadow alloc] init] autorelease]; | |
139 [shadow setShadowColor:[NSColor colorWithDeviceWhite:0.0 alpha:0.5]]; | |
140 [shadow setShadowOffset:NSMakeSize(0, -1)]; | |
141 NSFont* font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]]; | |
142 NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: | |
143 font, NSFontAttributeName, | |
144 [NSColor whiteColor], NSForegroundColorAttributeName, | |
145 shadow, NSShadowAttributeName, | |
146 nil]; | |
147 | |
148 NSSize text_size = [text sizeWithAttributes:attributes]; | |
149 NSRect text_rect; | |
150 text_rect.size.width = text_size.width + 2*kTextMarginX; | |
151 text_rect.size.height = text_size.height + 2*kTextMarginY; | |
152 text_rect.origin.x = (bounds.width - NSWidth(text_rect))/2; | |
153 text_rect.origin.y = (bounds.height - NSHeight(text_rect))/2; | |
154 | |
155 [[NSColor colorWithCalibratedWhite:0.52 alpha:1.0] setFill]; | |
156 [[NSBezierPath bezierPathWithRoundedRect:text_rect | |
157 xRadius:NSHeight(text_rect)/2 | |
158 yRadius:NSHeight(text_rect)/2] fill]; | |
159 | |
160 NSPoint label_point = NSMakePoint( | |
161 roundf(text_rect.origin.x + (text_rect.size.width - text_size.width)/2), | |
162 roundf(text_rect.origin.y + (text_rect.size.height - text_size.height)/2))
; | |
163 [text drawAtPoint:label_point withAttributes:attributes]; | |
164 | |
165 [NSGraphicsContext restoreGraphicsState]; | |
166 return 1; | |
167 } | |
168 | |
169 | |
170 void PluginInstallerImpl::ShowInstallDialog() { | |
171 } | |
172 | |
173 void PluginInstallerImpl::NotifyPluginStatus(int status) { | |
174 default_plugin::g_browser->getvalue( | |
175 instance_, | |
176 static_cast<NPNVariable>( | |
177 default_plugin::kMissingPluginStatusStart + status), | |
178 NULL); | |
179 } | |
OLD | NEW |