• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting started with WebKit plugins
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting started with WebKit plugins


  • Subject: Re: Getting started with WebKit plugins
  • From: Christopher Drum <email@hidden>
  • Date: Tue, 10 Jan 2006 22:02:24 -0800

Many thanks to Severin and Rudi who wrote with help on my struggle to understand WebKit plugins. I got my plugin to work like a champ. As documentation for future research (because I'm sure I'll forget something, and I'll probably search the lists for the answer again), here's what I did.

1. Create a new project in Xcode under New Project > Bundle > Cocoa Bundle.

2. To the project's Classes folder I added a new file, choosing the template for Objective-C NSView subclass

3. I changed the Info.plist file as recommended by Severin and Rudi.
a. CFBundlePackageType set to WBPL
b. NSPrincipalClass set to match the name of the new NSView subclass I created in step 2.
c. WebPluginDescription set to something readable that makes sense for the project
d. WebPluginMIMETypes - This part confused me as a MIME newbie. I see now that this is where you register what types of file extension calls in the webpage will trigger the use of the custom plugin. I created my own custom MIME type that will only be used internally with a corresponding custom extension to represent that "filetype". The key to my understanding this was Rudi's point that Safari loads my plugin because it "matched an incoming MIME type to my Info.plist setting".
e. WebPluginName again set to something readable that makes sense for the project


4. In mimicking how the Apple samples work, I created an instance variable of type NSDictionary named *arguments to hold the arguments passed to the class by the web browser, and a corresponding setArguments: method.

5. Implemented the one method that is 100% necessary for WebKit plugins to work
+(NSView *)plugInViewWithArguments:(NSDictionary *)arguments;


6. Implemented the methods I want my plugin to call.

7. Implemented an optional method (which, upon reading the docs more closely, isn't necessary for my simple test plugin which only has two methods and I want both exposed anyway)
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector


8. Implemented -(id)objectForWebScript, returning self

Now, I've only ever sudied C++ and Objective-C / Cocoa (with a teeny bit of Java and HTML thrown in). Not understanding how the HTML and Javascript trigger WebKit plugins and obtain an instance of my plugin's class was a big mystery to me.

8. Following Apple's sample code, I put an <embed> whose type is of the same custom MIME type I created in step 2d and whose source (src) references a nonexistent file with an extension that matches the one I created in step 2d. This allowed me to simply trigger the plugin to verify something was happening.

9. Using JavaScript's document.embeds[0] command, I was able to obtain the instance of my plugin. With that in hand, calling the Javascript-accessible functions was simplicity itself, using dot notation and underscores (in place of Obj-C colons). I understand now that I could make the methods I exposed more friendly to use by implementing webScriptNameForSelector: in my NSView subclass.

10. Finally, I found it useful to know if something was happening, say on plugin initialization or any other method that didn't do something obvious. I put NSAlert calls in each method so I could get visible confirmation that the plugin loaded and such. At one point I found that the plugin was initializing, but nothing further happened. The NSAlerts helped me track down a bug in my HTML file that wasn't utilizing the plugin properly.

Thanks again for everyone's help! The explanations helped me make sense of what I was reading in the Apple docs, and it's all much clearer to me now.

Christopher Drum
http://homepage.mac.com/christopherdrum

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Getting started with WebKit plugins
      • From: Rudi Sherry <email@hidden>
References: 
 >Re: Getting started with WebKit plugins (From: Severin Kurpiers <email@hidden>)

  • Prev by Date: Crash in AppKit.subproj/NSViewHierarchyLock.m:444
  • Next by Date: Re: Crash in AppKit.subproj/NSViewHierarchyLock.m:444
  • Previous by thread: Re: Getting started with WebKit plugins
  • Next by thread: Re: Getting started with WebKit plugins
  • Index(es):
    • Date
    • Thread