tags:

views:

107

answers:

1

I want to develop a plugin with Safari. Now I wan to make a demo for add a button into it's MainWindow or menu into it's MenuBar. I have seen to Document WebKitPluginProgTopic and the sample:/Developer/Examples/Webkit/WebKitMoviePlugIn . But they didn't tell the full process of make a plugin with safari and how to add some menu or button in the safari window . Someone can give me some advice or simple code to resolve this problem, Thank you very much!

+3  A: 

The plug-in architecture isn't thought for enhancing the browser but to support special media formats like flash or quicktime. The problem is that the plugin is only loaded when the corresponding media type is found.

Agile Web Solutions have found a way to load the plug-in all sites in 1Password and insert code into Safari. They've documented it in their blog. For other means of injecting code have a look at this question: InputManager plug-ins in Snow Leopard.

I haven't got any experience in building menus programmatically, but it should work like this:

NSMenu *newMenu = [[[NSMenu alloc] initWithTitle:@"MyMenu"] autorelease];
NSMenu *mainMenu = [NSApp mainMenu];
[mainMenu addItem:newMenu];

Changing the windows isn't that easy. Your best guess is probably [NSApp orderedWindows], which exists only for scripting purposes, but should be usefull to your task.

Georg
It's worth noting that plug-ins that alter the UI of Safari are totally unsupported, and the only way you can make them work is through extreme hackery, as you point out.Any time Safari is updated, your hacky plug-in may (and probably will) break.
Rob Keniger