initial import
[vuplus_webkit] / Source / WebKit / mac / Plugins / WebPluginController.mm
1 /*
2  * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer. 
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution. 
13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14  *     its contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission. 
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29
30 #import "WebPluginController.h"
31
32 #import "DOMNodeInternal.h"
33 #import "WebDataSourceInternal.h"
34 #import "WebFrameInternal.h"
35 #import "WebFrameView.h"
36 #import "WebHTMLViewPrivate.h"
37 #import "WebKitErrorsPrivate.h"
38 #import "WebKitLogging.h"
39 #import "WebNSObjectExtras.h"
40 #import "WebNSURLExtras.h"
41 #import "WebNSViewExtras.h"
42 #import "WebPlugin.h"
43 #import "WebPluginContainer.h"
44 #import "WebPluginContainerCheck.h"
45 #import "WebPluginPackage.h"
46 #import "WebPluginPrivate.h"
47 #import "WebPluginViewFactory.h"
48 #import "WebUIDelegate.h"
49 #import "WebViewInternal.h"
50 #import <Foundation/NSURLRequest.h>
51 #import <WebCore/DocumentLoader.h>
52 #import <WebCore/Frame.h>
53 #import <WebCore/FrameLoader.h>
54 #import <WebCore/HTMLMediaElement.h>
55 #import <WebCore/HTMLNames.h>
56 #import <WebCore/MediaPlayerProxy.h>
57 #import <WebCore/PlatformString.h>
58 #import <WebCore/ResourceRequest.h>
59 #import <WebCore/ScriptController.h>
60 #import <WebCore/WebCoreURLResponse.h>
61 #import <objc/objc-runtime.h>
62 #import <runtime/JSLock.h>
63
64 using namespace WebCore;
65 using namespace HTMLNames;
66
67 @interface NSView (PluginSecrets)
68 - (void)setContainingWindow:(NSWindow *)w;
69 @end
70
71 // For compatibility only.
72 @interface NSObject (OldPluginAPI)
73 + (NSView *)pluginViewWithArguments:(NSDictionary *)arguments;
74 @end
75
76 @interface NSView (OldPluginAPI)
77 - (void)pluginInitialize;
78 - (void)pluginStart;
79 - (void)pluginStop;
80 - (void)pluginDestroy;
81 @end
82
83 static bool isKindOfClass(id, NSString* className);
84 static void installFlip4MacPlugInWorkaroundIfNecessary();
85
86
87 static NSMutableSet *pluginViews = nil;
88
89 @implementation WebPluginController
90
91 + (NSView *)plugInViewWithArguments:(NSDictionary *)arguments fromPluginPackage:(WebPluginPackage *)pluginPackage
92 {
93     [pluginPackage load];
94     Class viewFactory = [pluginPackage viewFactory];
95     
96     NSView *view = nil;
97
98     if ([viewFactory respondsToSelector:@selector(plugInViewWithArguments:)]) {
99         JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
100         view = [viewFactory plugInViewWithArguments:arguments];
101     } else if ([viewFactory respondsToSelector:@selector(pluginViewWithArguments:)]) {
102         JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
103         view = [viewFactory pluginViewWithArguments:arguments];
104     }
105     
106     if (view == nil) {
107         return nil;
108     }
109     
110     if (pluginViews == nil) {
111         pluginViews = [[NSMutableSet alloc] init];
112     }
113     [pluginViews addObject:view];
114     
115     return view;
116 }
117
118 + (BOOL)isPlugInView:(NSView *)view
119 {
120     return [pluginViews containsObject:view];
121 }
122
123 - (id)initWithDocumentView:(NSView *)view
124 {
125     self = [super init];
126     if (!self)
127         return nil;
128     _documentView = view;
129     _views = [[NSMutableArray alloc] init];
130     _checksInProgress = (NSMutableSet *)CFMakeCollectable(CFSetCreateMutable(NULL, 0, NULL));
131     return self;
132 }
133
134 - (void)setDataSource:(WebDataSource *)dataSource
135 {
136     _dataSource = dataSource;    
137 }
138
139 - (void)dealloc
140 {
141     [_views release];
142     [_checksInProgress release];
143 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
144     [_viewsNotInDocument release];
145 #endif
146     [super dealloc];
147 }
148
149 - (void)stopOnePlugin:(NSView *)view
150 {
151     if ([view respondsToSelector:@selector(webPlugInStop)]) {
152         JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
153         [view webPlugInStop];
154     } else if ([view respondsToSelector:@selector(pluginStop)]) {
155         JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
156         [view pluginStop];
157     }
158 }
159
160 - (void)destroyOnePlugin:(NSView *)view
161 {
162     if ([view respondsToSelector:@selector(webPlugInDestroy)]) {
163         JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
164         [view webPlugInDestroy];
165     } else if ([view respondsToSelector:@selector(pluginDestroy)]) {
166         JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
167         [view pluginDestroy];
168     }
169 }
170
171 - (void)startAllPlugins
172 {
173     if (_started)
174         return;
175     
176     if ([_views count] > 0)
177         LOG(Plugins, "starting WebKit plugins : %@", [_views description]);
178     
179     int count = [_views count];
180     for (int i = 0; i < count; i++) {
181         id aView = [_views objectAtIndex:i];
182         if ([aView respondsToSelector:@selector(webPlugInStart)]) {
183             JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
184             [aView webPlugInStart];
185         } else if ([aView respondsToSelector:@selector(pluginStart)]) {
186             JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
187             [aView pluginStart];
188         }
189     }
190     _started = YES;
191 }
192
193 - (void)stopAllPlugins
194 {
195     if (!_started)
196         return;
197
198     if ([_views count] > 0) {
199         LOG(Plugins, "stopping WebKit plugins: %@", [_views description]);
200     }
201     
202     int viewsCount = [_views count];
203     for (int i = 0; i < viewsCount; i++)
204         [self stopOnePlugin:[_views objectAtIndex:i]];
205
206 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
207     int viewsNotInDocumentCount = [_viewsNotInDocument count];
208     for (int i = 0; i < viewsNotInDocumentCount; i++)
209         [self stopOnePlugin:[_viewsNotInDocument objectAtIndex:i]];
210 #endif
211
212     _started = NO;
213 }
214
215 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
216 - (void)pluginViewCreated:(NSView *)view
217 {
218     if (!_viewsNotInDocument)
219         _viewsNotInDocument= [[NSMutableArray alloc] init];
220     if (![_viewsNotInDocument containsObject:view])
221         [_viewsNotInDocument addObject:view];
222 }
223
224 + (void)pluginViewHidden:(NSView *)view
225 {
226     [pluginViews removeObject:view];
227 }
228 #endif
229
230 - (void)addPlugin:(NSView *)view
231 {
232     if (!_documentView) {
233         LOG_ERROR("can't add a plug-in to a defunct WebPluginController");
234         return;
235     }
236     
237     if (![_views containsObject:view]) {
238         [_views addObject:view];
239         [[_documentView _webView] addPluginInstanceView:view];
240
241 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
242         if ([_viewsNotInDocument containsObject:view])
243             [_viewsNotInDocument removeObject:view];
244 #endif
245
246         BOOL oldDefersCallbacks = [[self webView] defersCallbacks];
247         if (!oldDefersCallbacks)
248             [[self webView] setDefersCallbacks:YES];
249
250         if (isKindOfClass(view, @"WmvPlugin"))
251             installFlip4MacPlugInWorkaroundIfNecessary();
252
253         LOG(Plugins, "initializing plug-in %@", view);
254         if ([view respondsToSelector:@selector(webPlugInInitialize)]) {
255             JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
256             [view webPlugInInitialize];
257         } else if ([view respondsToSelector:@selector(pluginInitialize)]) {
258             JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
259             [view pluginInitialize];
260         }
261
262         if (!oldDefersCallbacks)
263             [[self webView] setDefersCallbacks:NO];
264         
265         if (_started) {
266             LOG(Plugins, "starting plug-in %@", view);
267             if ([view respondsToSelector:@selector(webPlugInStart)]) {
268                 JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
269                 [view webPlugInStart];
270             } else if ([view respondsToSelector:@selector(pluginStart)]) {
271                 JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
272                 [view pluginStart];
273             }
274             
275             if ([view respondsToSelector:@selector(setContainingWindow:)]) {
276                 JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
277                 [view setContainingWindow:[_documentView window]];
278             }
279         }
280     }
281 }
282
283 - (void)destroyPlugin:(NSView *)view
284 {
285 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
286     if ([_views containsObject:view] || [_viewsNotInDocument containsObject:view]) {
287 #else
288     if ([_views containsObject:view]) {
289 #endif
290         if (_started)
291             [self stopOnePlugin:view];
292         [self destroyOnePlugin:view];
293         
294 #if ENABLE(NETSCAPE_PLUGIN_API)
295         if (Frame* frame = core([self webFrame]))
296             frame->script()->cleanupScriptObjectsForPlugin(self);
297 #endif
298         
299         [pluginViews removeObject:view];
300         [[_documentView _webView] removePluginInstanceView:view];
301         [_views removeObject:view];
302 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
303         [_viewsNotInDocument removeObject:view];
304 #endif
305     }
306 }
307
308 - (void)_webPluginContainerCancelCheckIfAllowedToLoadRequest:(id)checkIdentifier
309 {
310     [checkIdentifier cancel];
311     [_checksInProgress removeObject:checkIdentifier];
312 }
313
314 static void cancelOutstandingCheck(const void *item, void *context)
315 {
316     [(id)item cancel];
317 }
318
319 - (void)_cancelOutstandingChecks
320 {
321     if (_checksInProgress) {
322         CFSetApplyFunction((CFSetRef)_checksInProgress, cancelOutstandingCheck, NULL);
323         [_checksInProgress release];
324         _checksInProgress = nil;
325     }
326 }
327
328 - (void)destroyAllPlugins
329 {    
330     [self stopAllPlugins];
331
332     if ([_views count] > 0) {
333         LOG(Plugins, "destroying WebKit plugins: %@", [_views description]);
334     }
335
336     [self _cancelOutstandingChecks];
337     
338     int viewsCount = [_views count];
339     for (int i = 0; i < viewsCount; i++) {
340         id aView = [_views objectAtIndex:i];
341         [self destroyOnePlugin:aView];
342         
343 #if ENABLE(NETSCAPE_PLUGIN_API)
344         if (Frame* frame = core([self webFrame]))
345             frame->script()->cleanupScriptObjectsForPlugin(self);
346 #endif
347         
348         [pluginViews removeObject:aView];
349         [[_documentView _webView] removePluginInstanceView:aView];
350     }
351
352 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
353     int viewsNotInDocumentCount = [_viewsNotInDocument count];
354     for (int i = 0; i < viewsNotInDocumentCount; i++)
355         [self destroyOnePlugin:[_viewsNotInDocument objectAtIndex:i]];
356 #endif
357
358     [_views makeObjectsPerformSelector:@selector(removeFromSuperviewWithoutNeedingDisplay)];
359     [_views release];
360     _views = nil;
361
362     _documentView = nil;
363 }
364
365 - (id)_webPluginContainerCheckIfAllowedToLoadRequest:(NSURLRequest *)request inFrame:(NSString *)target resultObject:(id)obj selector:(SEL)selector
366 {
367     WebPluginContainerCheck *check = [WebPluginContainerCheck checkWithRequest:request target:target resultObject:obj selector:selector controller:self contextInfo:nil];
368     [_checksInProgress addObject:check];
369     [check start];
370
371     return check;
372 }
373
374 - (void)webPlugInContainerLoadRequest:(NSURLRequest *)request inFrame:(NSString *)target
375 {
376     if (!request) {
377         LOG_ERROR("nil URL passed");
378         return;
379     }
380     if (!_documentView) {
381         LOG_ERROR("could not load URL %@ because plug-in has already been destroyed", request);
382         return;
383     }
384     WebFrame *frame = [_dataSource webFrame];
385     if (!frame) {
386         LOG_ERROR("could not load URL %@ because plug-in has already been stopped", request);
387         return;
388     }
389     if (!target) {
390         target = @"_top";
391     }
392     NSString *JSString = [[request URL] _webkit_scriptIfJavaScriptURL];
393     if (JSString) {
394         if ([frame findFrameNamed:target] != frame) {
395             LOG_ERROR("JavaScript requests can only be made on the frame that contains the plug-in");
396             return;
397         }
398         [frame _stringByEvaluatingJavaScriptFromString:JSString];
399     } else {
400         if (!request) {
401             LOG_ERROR("could not load URL %@", [request URL]);
402             return;
403         }
404         core(frame)->loader()->load(request, target, false);
405     }
406 }
407
408 - (void)webPlugInContainerShowStatus:(NSString *)message
409 {
410     if (!message)
411         message = @"";
412
413     WebView *v = [_dataSource _webView];
414     [[v _UIDelegateForwarder] webView:v setStatusText:message];
415 }
416
417 // For compatibility only.
418 - (void)showStatus:(NSString *)message
419 {
420     [self webPlugInContainerShowStatus:message];
421 }
422
423 - (NSColor *)webPlugInContainerSelectionColor
424 {
425     bool primary = true;
426     if (Frame* frame = core([self webFrame]))
427         primary = frame->selection()->isFocusedAndActive();
428     return primary ? [NSColor selectedTextBackgroundColor] : [NSColor secondarySelectedControlColor];
429 }
430
431 // For compatibility only.
432 - (NSColor *)selectionColor
433 {
434     return [self webPlugInContainerSelectionColor];
435 }
436
437 - (WebFrame *)webFrame
438 {
439     return [_dataSource webFrame];
440 }
441
442 - (WebView *)webView
443 {
444     return [[self webFrame] webView];
445 }
446
447 - (NSString *)URLPolicyCheckReferrer
448 {
449     NSURL *responseURL = [[[[self webFrame] _dataSource] response] URL];
450     ASSERT(responseURL);
451     return [responseURL _web_originalDataAsString];
452 }
453
454 - (void)pluginView:(NSView *)pluginView receivedResponse:(NSURLResponse *)response
455 {    
456     if ([pluginView respondsToSelector:@selector(webPlugInMainResourceDidReceiveResponse:)])
457         [pluginView webPlugInMainResourceDidReceiveResponse:response];
458     else {
459         // Cancel the load since this plug-in does its own loading.
460         // FIXME: See <rdar://problem/4258008> for a problem with this.
461         NSError *error = [[NSError alloc] _initWithPluginErrorCode:WebKitErrorPlugInWillHandleLoad
462                                                         contentURL:[response URL]
463                                                      pluginPageURL:nil
464                                                         pluginName:nil // FIXME: Get this from somewhere
465                                                           MIMEType:[response MIMEType]];
466         [_dataSource _documentLoader]->cancelMainResourceLoad(error);
467         [error release];
468     }        
469 }
470
471 - (void)pluginView:(NSView *)pluginView receivedData:(NSData *)data
472 {
473     if ([pluginView respondsToSelector:@selector(webPlugInMainResourceDidReceiveData:)])
474         [pluginView webPlugInMainResourceDidReceiveData:data];
475 }
476
477 - (void)pluginView:(NSView *)pluginView receivedError:(NSError *)error
478 {
479     if ([pluginView respondsToSelector:@selector(webPlugInMainResourceDidFailWithError:)])
480         [pluginView webPlugInMainResourceDidFailWithError:error];
481 }
482
483 - (void)pluginViewFinishedLoading:(NSView *)pluginView
484 {
485     if ([pluginView respondsToSelector:@selector(webPlugInMainResourceDidFinishLoading)])
486         [pluginView webPlugInMainResourceDidFinishLoading];
487 }
488
489 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
490 static WebCore::HTMLMediaElement* mediaProxyClient(DOMElement* element)
491 {
492     if (!element) {
493         LOG_ERROR("nil element passed");
494         return nil;
495     }
496
497     Element* node = core(element);
498     if (!node || (!node->hasTagName(HTMLNames::videoTag) && !node->hasTagName(HTMLNames::audioTag))) {
499         LOG_ERROR("invalid media element passed");
500         return nil;
501     }
502
503     return static_cast<WebCore::HTMLMediaElement*>(node);
504 }
505
506 - (void)_webPluginContainerSetMediaPlayerProxy:(WebMediaPlayerProxy *)proxy forElement:(DOMElement *)element
507 {
508     WebCore::HTMLMediaElement* client = mediaProxyClient(element);
509     if (client)
510         client->setMediaPlayerProxy(proxy);
511 }
512
513 - (void)_webPluginContainerPostMediaPlayerNotification:(int)notification forElement:(DOMElement *)element
514 {
515     WebCore::HTMLMediaElement* client = mediaProxyClient(element);
516     if (client)
517         client->deliverNotification((MediaPlayerProxyNotificationType)notification);
518 }
519 #endif
520
521 @end
522
523 static bool isKindOfClass(id object, NSString *className)
524 {
525     Class cls = NSClassFromString(className);
526
527     if (!cls)
528         return false;
529
530     return [object isKindOfClass:cls];
531 }
532
533
534 // Existing versions of the Flip4Mac WebKit plug-in have an object lifetime bug related to an NSAlert that is
535 // used to notify the user about updates to the plug-in. This bug can result in Safari crashing if the page
536 // containing the plug-in navigates while the alert is displayed (<rdar://problem/7313430>).
537 //
538 // The gist of the bug is thus: Flip4Mac sets an instance of the TSUpdateCheck class as the modal delegate of the
539 // NSAlert instance. This TSUpdateCheck instance itself has a delegate. The delegate is set to the WmvPlugin
540 // instance which is the NSView subclass that is exposed to WebKit as the plug-in view. Since this relationship
541 // is that of delegates the TSUpdateCheck does not retain the WmvPlugin. This leads to a bug if the WmvPlugin
542 // instance is destroyed before the TSUpdateCheck instance as the TSUpdateCheck instance will be left with a
543 // pointer to a stale object. This will happen if a page containing the Flip4Mac plug-in triggers a navigation
544 // while the update sheet is visible as the WmvPlugin instance is removed from the view hierarchy and there are
545 // no other references to keep the object alive.
546 //
547 // We work around this bug by patching the following two messages:
548 //
549 // 1) -[NSAlert beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:]
550 // 2) -[TSUpdateCheck alertDidEnd:returnCode:contextInfo:]
551 //
552 // Our override of 1) detects whether it is Flip4Mac's update sheet triggering the alert by checking whether the
553 // modal delegate is an instance of TSUpdateCheck. If it is, it retains the modal delegate's delegate.
554 //
555 // Our override of 2) then autoreleases the delegate, balancing the retain we added in 1).
556 //
557 // These two overrides have the effect of ensuring that the WmvPlugin instance will always outlive the TSUpdateCheck
558 // instance, preventing the TSUpdateCheck instance from accessing a stale delegate pointer and crashing the application.
559
560
561 typedef void (*beginSheetModalForWindowIMP)(id, SEL, NSWindow *, id, SEL, void*);
562 static beginSheetModalForWindowIMP original_NSAlert_beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_;
563
564 typedef void (*alertDidEndIMP)(id, SEL, NSAlert *, NSInteger, void*);
565 static alertDidEndIMP original_TSUpdateCheck_alertDidEnd_returnCode_contextInfo_;
566
567 static void WebKit_TSUpdateCheck_alertDidEnd_returnCode_contextInfo_(id object, SEL selector, NSAlert *alert, NSInteger returnCode, void* contextInfo)
568 {
569     [[object delegate] autorelease];
570
571     original_TSUpdateCheck_alertDidEnd_returnCode_contextInfo_(object, selector, alert, returnCode, contextInfo);
572 }
573
574 static void WebKit_NSAlert_beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(id object, SEL selector, NSWindow *window, id modalDelegate, SEL didEndSelector, void* contextInfo)
575 {
576     if (isKindOfClass(modalDelegate, @"TSUpdateCheck"))
577         [[modalDelegate delegate] retain];
578
579     original_NSAlert_beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(object, selector, window, modalDelegate, didEndSelector, contextInfo);
580 }
581
582 static void installFlip4MacPlugInWorkaroundIfNecessary()
583 {
584     static bool hasInstalledFlip4MacPlugInWorkaround;
585     if (!hasInstalledFlip4MacPlugInWorkaround) {
586         Class TSUpdateCheck = objc_lookUpClass("TSUpdateCheck");
587         if (!TSUpdateCheck)
588             return;
589
590         Method methodToPatch = class_getInstanceMethod(TSUpdateCheck, @selector(alertDidEnd:returnCode:contextInfo:));
591         if (!methodToPatch)
592             return;
593
594         IMP originalMethod = method_setImplementation(methodToPatch, reinterpret_cast<IMP>(WebKit_TSUpdateCheck_alertDidEnd_returnCode_contextInfo_));
595         original_TSUpdateCheck_alertDidEnd_returnCode_contextInfo_ = reinterpret_cast<alertDidEndIMP>(originalMethod);
596
597         methodToPatch = class_getInstanceMethod(objc_getRequiredClass("NSAlert"), @selector(beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:));
598         originalMethod = method_setImplementation(methodToPatch, reinterpret_cast<IMP>(WebKit_NSAlert_beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_));
599         original_NSAlert_beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_ = reinterpret_cast<beginSheetModalForWindowIMP>(originalMethod);
600
601         hasInstalledFlip4MacPlugInWorkaround = true;
602     }
603 }