BYOB: Build Your Own Browser, Part 3
Pages: 1, 2
The apply and windowDidBecomeKey methods are inverses
of each other; apply sets values into WebPreferences and MyDocument
and windowDidBecomeKey looks up values in WebPreferences and MyDocument.
One odd thing that happens is that we setAutosaves every time to
YES in the WebPreferences object, p. This is not strictly
necessary, but we do this to ensure that the preferences are being saved, on
the off chance that the value has changed since the last time we accessed it.
Here is the code for apply and windowDidBecomeKey:
- (IBAction)apply:(id)sender
{
NSUserDefaults *defaults;
defaults = [NSUserDefaults standardUserDefaults];
NSString* dHomepage = [defaultHomepage stringValue];
[defaults setObject:dHomepage forKey:@"defaultHomepage"];
[md setDefaultHomepage:dHomepage];
NSString* iContent = [ignoreContent stringValue];
[defaults setObject:iContent forKey:@"ignoreContent"];
[md setIgnoreContent:iContent];
[p setAutosaves:YES];
if ([autoloadImages state] == NSOffState){
[p setLoadsImagesAutomatically:NO];
}
else {
[p setLoadsImagesAutomatically:YES];
}
if ([allowAnimatedImages state] == NSOffState){
[p setAllowsAnimatedImageLooping:NO];
}
else {
[p setAllowsAnimatedImageLooping:YES];
}
if ([javascriptEnabled state] == NSOffState){
[p setJavaScriptEnabled:NO];
}
else {
[p setJavaScriptEnabled:YES];
}
}
- (void)windowDidBecomeKey:(NSNotification *)aNotification
{
[defaultHomepage setStringValue:[md getDefaultHomepage]];
[ignoreContent setStringValue:[md getIgnoreContent]];
[p setAutosaves:YES];
if ([p loadsImagesAutomatically]){
[autoloadImages setState:NSOnState];
}
else {
[autoloadImages setState:NSOffState];
}
if ([p allowsAnimatedImageLooping]){
[allowAnimatedImages setState:NSOnState];
}
else {
[allowAnimatedImages setState:NSOffState];
}
if ([p isJavaScriptEnabled]){
[javascriptEnabled setState:NSOnState];
}
else {
[javascriptEnabled setState:NSOffState];
}
}
You probably noticed that we made use of the NSUserDefaults classes
in all three methods to save the information for default homepage. NSUserDefaults
allows developers to save information into the user's defaults database that
can be reused between instance of the program. This is very convenient and makes
it so that developers do not need to make awkward preferences files that are
lost if they are not in a specific location.
While I don't go into details about using this here, NSUserDefaults
is well documented on Apple's
developer site. You may also want to check out the defaults
command to see what the defaults are for this and other applications.
Once all the code is written and saved, you're done. When you run the code, you should see that preferences first come up with the default values that you set in Interface Builder. But if you change them, quit and run the browser again; the values you entered on the preference pane should be saved. Adding additional preference variables, or other variables that might be interesting for you (for instance, the value for our Content Eliminator) is pretty straightforward. Build up the interface in Interface Builder and then connect the pieces by adding to each of the methods in Controller.
Content Eliminator
The final feature we're going to add to our browser is a content eliminator. Put simply, a content eliminator will prevent any content from being downloaded if its URL contains certain substrings. For instance, let's say you're sick of the number of banner ads that are on the pages you read. You still want to be able to download the pages that the ads are on, but you don't want to see the ads. If the ads come from a site named singlebutton.com, you would add that string to the content eliminator's list of strings to avoid, and it will prevent the content from being downloaded.
This feature can be used to prevent downloading from ad sites, as a child-guard-type system, or can even be reversed, to only allow content from certain URLs to be used in a kiosk-type application. If you are planning to use this in a kiosk-type application, make sure that you are very careful with the way that you check the strings, or else you may end up with people accessing yoursite.porno-site.com instead of yoursite.com.
To add a content eliminator to our browser, we need to use another of WebView's
delegates, this time the policyDelegate. The policyDelegate
allows an external application to make decisions about content, specifically
how it is to be downloaded and how it is to be displayed. There are several
methods that this delegate provides for policy decisions that need to be made.
The method that we will be using to make policy decisions is:
decidePolicyForNavigationAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
frame:(WebFrame *)frame
decisionListener:(id<WebPolicyDecisionListener<)listener
When this method is called by WebView, WebView sends it information about the request being made in several objects, and a listener whose job is to report back to WebView what the method has decided to do about the request. When we implement the method, our code needs to comb through the information that is provided about the request and tell the listener what policy decision was made based on that information.
Before we get too far, the first thing that we need for our content eliminator
is to tell the WebView what the policyDelegate is going to be.
We do this the same way we did with the UIDelegate and the frameDelegate,
by adding:
[webView setPolicyDelegate:self];
to the windowControllerDidLoadNIB method.
Once that is added, we need a static list of sites from which we do not want
content to be downloaded. To accomplish this, we are going to use a semi-colon
delimited static NSString named ignoreContent. Since
our NSString is static, we need to declare it in the MyDocuments
implementation file, MyDocument.m, as we did our defaultHomepage
variable:
static NSString *ignoreContent = @"site1.com; site2.com;site3.com";
Now we need to build a decidePolicyActionForNavigation method
that does four things:
- Figure out what the URL is.
- Convert the semi-colon delimited list into an array.
- Go through the array and decide if the content needs to be eliminated; if so, tell the listener to ignore it.
- If nothing needs to be eliminated, then let the content go through.
The implementation of the method follows these parameters:
- (void)webView:(WebView *)sender decidePolicyForNavigationAction:
(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:
(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener
{
NSString* urlKey = [[actionInformation objectForKey:WebActionOriginalURLKey] host];
if(ignoreContent == nil){
[listener use];
return;
}
if (urlKey == nil){
[listener ignore];
return;
}
NSArray* theList = [ignoreContent componentsSeparatedByString:@";"];
int count = [theList count];
while(count > 0 ){
NSRange range = [urlKey rangeOfString:[theList objectAtIndex:--count]];
if(range.length >0){
[listener ignore];
return;
}
}
[listener use];
}
Once the method has been added, test it out and see if you can block some
content or even entire sites. While I left it out of the article, if you follow
the instructions in the preferences section, the ignoreContent
string is one of the variables that can be added to both the user default database
and the preferences window. While this is a simple of example of what a policy
delegate can do, policy delegates can be used for any number of interesting
filtering-type applications
Final Thoughts
As you can see, WebKit provides the custom browser developer with loads of features that can be used in custom browsers, kiosk applications, browsers built in to other applications, or, really, whatever browsing application you can imagine. Hopefully, you will be inspired to create cool applications that really test the bounds of what WebKit can do.
Good luck developing your browser! Drop us a line if you find any interesting links or if you create any interesting WebKit-based projects.
Andrew Anderson is a software developer and consultant in Chicago who's been using and programming on the Mac as long as he can remember.
Return to the Mac DevCenter
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 37 of 37.
-
Unknown variables
2008-07-09 04:41:58 Dev_Dave [Reply | View]
I know its been years since this article was written, but I've been having some trouble with it. I've noticed the UI has been changed a bit, but I've managed ok. My problem is that it doesn't reognise getIgnoreContent or setIgnoreContent. In fact, its not declared anywhere. Should it be? Noone else seems to have this trouble, so I'm guessing its not supposed to be declared by me. In that case, am I missing a header? Any ideas? Thanks.
-
For all you askting
2008-04-09 20:52:08 MaxApps [Reply | View]
For all you asking here's how you would add a google search box.
set a variable for text box "search" to googlesearch
the make another line with.
goto URL "http://www.google.com/search?q=" & googlesearch
cause if you type http://www.google.com/search?q= in firefox (or IE or any other browser) and type your search after that, it googles it.
BAM.
hope you found this helpfull =]
-
Tabbed browser
2008-03-08 10:15:49 Abhi1907 [Reply | View]
Hi Andrew,
I am building an application or a web browsre, and this article has been very helpful for me so far. Thanks a lot!!!
Now, I need to incorporate some advanced features like "tabbed browser support", "cookies", "context menus" etc. in my browser. Please help me out to find out the relevant help topics.
Thanks,
- Abhishek
-
Display Page Title
2007-07-07 13:29:24 ALEPETY [Reply | View]
Hi everyone!
To display page title add this to implementation file (mydocument.m)
- (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame
{
// Report feedback only for the main frame.
if (frame == [sender mainFrame]){
[[sender window] setTitle:title];
}
}
This was taken from http://developer.apple.com/documentation/Cocoa/Conceptual/DisplayWebContent/
-
Setting URL Textveiw to current
2006-04-07 17:55:43 rcran [Reply | View]
Does anyone know how to set the URL NSTextview to be the current URL?
-
Errors
2006-01-30 21:41:36 something2sea [Reply | View]
I'm getting 3 errors (and 8 warnings, but we'll forget about those)
error: parse error before ':' token
error: 'apply' undeclared (first use of this function)
- (IBAction)apply:(id)sender
(I was ment declare it in "Controller.h" and i suppose this was ment to declare it: - (IBAction)apply:(id)sender;)
Error: redefinition of 'dHomepage'
NSString* dHomepage = [defaultHomepage stringValue];
(I don't get this one!!)
please help me, thanx
- Ben
-
Downloading support
2006-01-28 15:45:56 something2sea [Reply | View]
Hi, this series of tutorials has been GREAT, thankyou, i've already added my own support for the page titles in the window title area!!
I was wondering how I would go about adding downloading support to my browser, in the "Examples > Webkit" folder there's an example called "Downloader" I built that and it seems to be the type of functionallity I would like to add to my browser. Does anybody know of an easy way to eather incorporate that downloader example into my browser of a simple way to include Downloading support to our browsers?
thanks in advance
- Ben
-
WebKit References?
2005-12-20 11:15:17 Tipo61 [Reply | View]
Everything works fine for me, and I am down to one build error, that build error says that severeal things were referenced in webkit, and were expected to be defined in ApplicationServices. Any Ideas on how to fix this?
-
Error addition
2005-12-03 22:16:01 cuddlespowell [Reply | View]
It also gives me the error:
Error 5: SIGTRAP
What does this mean?????
-
Error
2005-12-03 22:06:48 cuddlespowell [Reply | View]
The browser that I made has more than one webview organized by tabviews. When I set the preference ID to BYOB on to all of the webviews, I saved and quit. When I tried to reopen it, it gave the message:
While opening “MainMenu.nib”, the following error occured:
*** -[NSCFString identifier]: selector not recognized [self = 0x4bf140]
What does this mean????
-
Adding Search Fields
2005-06-30 18:43:57 Abcu [Reply | View]
I know this is slightly off-topic, but how would I go about adding a search field to my browser? In this case, I'm trying to make one like the one in Safari, one that links to Google. I've made the field itself with the recent history menu, but I have no idea how to link it to something else to make it work.
Also, I would like to know how to implement a search inside the document itself, so if you have any ideas as to how I could do that, it would be greatly appreciated.
-
6 Warnings and 4 Errors prevent Compiling
2005-02-28 13:35:33 ratpack [Reply | View]
I am brand new to Cocoa and objective-C, but I'm pretty strong with PHP, JavaScript and the like.
Anyway.. I've gone through part 3 of BYOB several times from beginning to end. I started by typing everything myself at least 3 times. Convinced I was an idiot and had been making typo after typo, I copied and pasted the code from the tutorial into my project.
I keep getting the same 6 warning (4 if I remove the ignorecontent bits) and 4 errors and can't figure out what I've done wrong.
Any help would be greatly appreciated.
The warnings/errors I get are:
Cannot find method `-setIgnoreContent:'; return type `id` assumed
`MyDocument` may not respond to `-setIgnoreContent:`
cannot find method `-getDefaultHomepage`; return type `id` assumed
`MyDocument may not respond to `-getDefaultHomeage`
cannot find method `-getIgnoreContent'; return type `id' assumed
`MyDocument' may not respond to `-getIgnoreContent'
error: `autoloadImages' undeclared (first use in this function ) (Each undeclared identifier is reported only once for each function it appears in.)
error: `javascriptEnabled' undeclared (first use in this function)
error: `autoloadImages' undeclared (first use in this function)
error: `javascriptEnabled' undeclared (first use in this function)
I realize that these are stating that I have an undeclared function somewhere, but I can't find it and I can't find reference to declaring this function in the tutorial.
I don't see anybody else with a mention of this type of problem, so I'm back to assuming my own idiocy has caused this issue.
Below is my Controller.h file
/* Controller */
#import <Cocoa/Cocoa.h>
#import <WebKit/WebPreferences.h>
#import <WebKit/WebView.h>
#import "MyDocument.h"
@interface Controller : NSObject
{
IBOutlet id allowAnimatedImages;
IBOutlet id autoLoadImages;
IBOutlet id defaultHomepage;
IBOutlet id javaScriptEnabled;
IBOutlet id ignoreContent;
WebPreferences *p;
MyDocument *md;
}
- (IBAction)apply:(id)sender;
@end
and here is my Controller.m file:
#import "Controller.h"
@implementation Controller
- (void)awakeFromNib
{
md = [MyDocument alloc];
[md init];
WebView *wv = [WebView alloc];
[wv init];
[wv setPreferencesIdentifier:@"jomplomp"];
p = [wv preferences];
[p setAutosaves:YES];
NSUserDefaults *defaults;
defaults = [NSUserDefaults standardUserDefaults];
NSString * dHomepage = [defaults stringForKey:@"defaultHomepage"];
if (dHomepage != nil) {
[md setDefaultHomepage:dHomepage];
}
}
- (IBAction)apply:(id)sender
{
NSUserDefaults *defaults;
defaults = [NSUserDefaults standardUserDefaults];
NSString* dHomepage = [defaultHomepage stringValue];
[defaults setObject:dHomepage forKey:@"defaultHomepage"];
[md setDefaultHomepage:dHomepage];
[p setAutosaves:YES];
if ([autoloadImages state] == NSOffState){
[p setLoadsImagesAutomatically:NO];
}
else {
[p setLoadsImagesAutomatically:YES];
}
if ([allowAnimatedImages state] == NSOffState){
[p setAllowsAnimatedImageLooping:NO];
}
else {
[p setAllowsAnimatedImageLooping:YES];
}
if ([javascriptEnabled state] == NSOffState){
[p setJavaScriptEnabled:NO];
}
else {
[p setJavaScriptEnabled:YES];
}
NSString* iContent = [ignoreContent stringValue];
[defaults setObject:iContent forKey:@"ignoreContent"];
[md setIgnoreContent:iContent];
}
- (void)windowDidBecomeKey:(NSNotification *)aNotification
{
[defaultHomepage setStringValue:[md getDefaultHomepage]];
[ignoreContent setStringValue:[md getIgnoreContent]];
[p setAutosaves:YES];
if ([p loadsImagesAutomatically]){
[autoloadImages setState:NSOnState];
}
else {
[autoloadImages setState:NSOffState];
}
if ([p allowsAnimatedImageLooping]){
[allowAnimatedImages setState:NSOnState];
}
else {
[allowAnimatedImages setState:NSOffState];
}
if ([p isJavaScriptEnabled]){
[javascriptEnabled setState:NSOnState];
}
else {
[javascriptEnabled setState:NSOffState];
}
}
@end
As I said, any help would be appreciated as I'm new to Objective-C and cocoa.
Thank you.
BTW: I think the tutorials up to this point have been great! They helped me quickly understand something up to a point that was total greek to me prior to your series.
-
preferences not saving
2005-02-27 10:21:53 pack [Reply | View]
I've gone over the code and tutorial multple times.
I seem to be having the same issue as an earlier poster. Default homepage saves but the rest of the preferences don't. I have quadruple checked all the actions and outlets and ib relationships. I have removed all ignorecontent code but atlas can't get autoload images to save or javascript. if I reverse the yes and the NO here then atleast images load.:
if ([autoloadImages state] == NSOffState){
[p setLoadsImagesAutomatically:NO];
}
else {
[p setLoadsImagesAutomatically:YES];
}
any help would be greatly appreciated
here is all the code for controller.m:
#import "Controller.h"
#import <WebKit/WebPreferences.h>
@implementation Controller
- (void)awakeFromNib
{
md = [MyDocument alloc];
[md init];
WebView *wv = [WebView alloc];
[wv init];
[wv setPreferencesIdentifier:@"PREF"];
p = [wv preferences];
[p setAutosaves:YES];
NSUserDefaults *defaults;
defaults = [NSUserDefaults standardUserDefaults];
NSString * dHomepage = [defaults stringForKey:@"defaultHomepage"];
if (dHomepage != nil) {
[md setDefaultHomepage:dHomepage];
}
}
- (IBAction)apply:(id)sender
{
NSUserDefaults *defaults;
defaults = [NSUserDefaults standardUserDefaults];
NSString* dHomepage = [defaultHomepage stringValue];
[defaults setObject:dHomepage forKey:@"defaultHomepage"];
[md setDefaultHomepage:dHomepage];
[p setAutosaves:YES];
if ([autoloadImages state] == NSOffState){
[p setLoadsImagesAutomatically:NO];
}
else {
[p setLoadsImagesAutomatically:YES];
}
if ([allowAnimatedImages state] == NSOffState){
[p setAllowsAnimatedImageLooping:NO];
}
else {
[p setAllowsAnimatedImageLooping:YES];
}
if ([javascriptEnabled state] == NSOffState){
[p setJavaScriptEnabled:NO];
}
else {
[p setJavaScriptEnabled:YES];
}
}
- (void)windowDidBecomeKey:(NSNotification *)aNotification
{
[defaultHomepage setStringValue:[md getDefaultHomepage]];
[p setAutosaves:YES];
if ([p loadsImagesAutomatically]){
[autoloadImages setState:NSOnState];
}
else {
[autoloadImages setState:NSOffState];
}
if ([p allowsAnimatedImageLooping]){
[allowAnimatedImages setState:NSOnState];
}
else {
[allowAnimatedImages setState:NSOffState];
}
if ([p isJavaScriptEnabled]){
[javascriptEnabled setState:NSOnState];
}
else {
[javascriptEnabled setState:NSOffState];
}
}
@end
here is the code for controller.h:
/* Controller */
#import <Cocoa/Cocoa.h>
#import <WebKit/WebPreferences.h>
#import <WebKit/WebView.h>
#import "MyDocument.h"
@interface Controller : NSObject
{
IBOutlet id allowAnimatedImages;
IBOutlet id autoloadImages;
IBOutlet id defaultHomepage;
IBOutlet id javascriptEnabled;
WebPreferences *p;
MyDocument *md;
}
- (IBAction)apply:(id)sender;
@end
-
Displaying an Error warning
2004-11-21 17:27:33 Shizil [Reply | View]
I want to implement a NSRunAlertPanel for when a page cannot be loaded or an Internet connection can't be found, but I am having trouble. Does anybody have any ideas on this one. I was thinking it should be something like the alert that shows up in Safari when you cannot find a page.
-
Prefrences
2004-11-12 15:27:04 Nemisis [Reply | View]
What am I doing wrong? I'v done everything how it say's but prefreces wont apply or save, but defualt homepage does?
if i add
[p setLoadsImagesAutomatically:YES];
to
- (void)awakeFromNib
then images will load, but they dont work from
- (IBAction)apply:(id)sender
apply saves the homepage but not the prefrences and doesn't apply the prefrences. -
Prefrences
2004-11-13 03:22:15 Nemisis [Reply | View]
I'v found the problem, I was testing the prefrences befor adding the ignore content code so when apply called to save conntent on the lines above prefrences it exits the apply call, to solve this with out add ignore conntent code, either comment it out or more it to the bottom of the function.
-
https support
2004-08-04 11:53:36 Steve.Haun [Reply | View]
It seems that the browser hangs when I tried to connect a secure site (https). I would like to know how to enhance this code to support https protocol.
-
Lost...
2004-08-04 09:28:02 Zarac [Reply | View]
I've enjoyed this series tremendously, but am frustrated I can't implement the last piece. I was doing okay until I tried to compile this:
- (void)webView:(WebView *)sender decidePolicyForNavigationAction:
(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:
(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener
{
NSString* urlKey = [[actionInformation objectForKey:WebActionOriginalURLKey] host];
The compiler balks at <WebPolicyDecisionListener> and WebActionOriginalURLKey and I haven't found any other references to these values.
Coming from Java, I don't get the
id<WebPolicyDecisionListener> syntax. -
Lost...
2004-08-05 05:55:19 Andrew Anderson | [Reply | View]
WebActionOriginalURLKey is a constant defined in WebPolicyDelegate.h. Make sure you are importing the file, if not include:
#import <WebKit/WebPolicyDelegate.h>
in either your MyDocument.m or MyDocument.h file.
Andrew
-
Running in another computer
2004-08-02 16:17:08 aceM [Reply | View]
Hi.
Good work... I did a really usefull application to our intranet.
But... where can I find about How to make de application run in another computer than the one I used to create the application? The applications begin and quit because don't find frameworks or files that are located in the computer I created the application.
8(
Thanks -
Running in another computer
2005-01-19 07:12:12 tf23 [Reply | View]
you need to turn off Zero link.
the app in part one walks you through that. the second app that you build, turning off Zero link is skipped.
If Zero link is on, the app seems to only want to exec on the machine you built it on. -
Running in another computer
2004-08-05 05:51:07 Andrew Anderson | [Reply | View]
You would need to install (or force to install) the WebKit framework on the other computer... instructions for installing it are in Part 1 of the article.
-
Thanks for the great articles
2004-06-25 18:02:16 Beowulf [Reply | View]
There are some people grumbling on these boards that this (at least the first) article is a bit too simplistic. But for people like me, I loved it!
My programming experience is a bit of BASIC in high school (1985!) and Fortran in college. I also kinda taught myself some of Pascal.
I changed my career path and programming was not part of it, but I always had a desire to learn new languages. I never really followed through. I had a couple of C tutorials, and a java one here and there, but never got past the first few pages.
I always used windoze in my schooling and at work. But when it came time for me to get a laptop, I chose a Mac. Somewhat to be different and somewhat to see what I was missing.
Anyway, I'm rambling, but I came across this site when searching for tips on digital photography. I then saw the this article. I went right home to try it out. I never knew this stuff was on my computer!
I'm working thru articles 2 & 3. Since I don't have any real experience with C, it's a bit tough.
But Thanks for rekindling the "programmer" in me, and writing an article at my level.
As for the boo birds in the crowd: If the article is too easy, skip to the next one....There isn't a finite # of things that are on here, so the simple article won't take the place of the serious stuff you are looking for...
-
Just remember why I hate C and his friends
2004-06-12 14:12:21 zeus [Reply | View]
Hy everyone,
I just lost 10 mn finding why this ?!? program will not compile with about 10 errors and 25 warning at first. And I found this was because I misspelled the:
#import "MyDocument.h"
guess what I get error about unknown variables mp, etc. But at no time I get an error saying that#impotrwas an unknow directive of the precompiler.
If you just play a bit with Java and his compiler I thing you see what I mean, because javac takes you by the hand and tells you nearly what to change in order to remove your errors.
I know this is the price to pay for weak | no typed language, but it's horrible for misspelling.
Here we see clearly that Obj-C is coming from SmallTalk (for those who tried VisualWorks just remember where appeard the "compile" error).
Quite long comment, very useless, full of non english sentence's construction, BUT really entertaining between two exam's revision.
Hope to see a new "tutorial" of Andrew soon.
Jerome
-
Not so good...
2004-06-07 07:18:30 johnts [Reply | View]
Is it just me or is this article a little confusing? The whole bit about the ignoreContent was sort of thrown in - the ignoreContent member variable would clash with the static variable.. I had to comment out a bunch of stuff in the awakeFromNib method and the apply: method just to get it to compile. I guess that some of that was put in there so we could finish it, but leaving it halfway done doesn't help! I had to add a couple of missing #imports too.
Not to mention, there's no way to access the preference window! I know it's just hooking it up to the menu, but not even a mention.
I'm going to try to sort this out, but I came out more confused than I started. -
re: Not so good...
2004-06-07 07:59:29 Andrew Anderson | [Reply | View]
sorry about missing the preference window hook up, it was a paragraph that fell out while editing it on my side. I will get the editors to put the paragraph in as soon as possible.
what did you need to comment out in awakefromnib to get it working ? this error seems strange since the code comes from a perfectly working version that I built. Not having an import statement for MyDocument.h would force the compile to fail, but that is in the code in the article. Can you post the errors that you are getting ?
ignoreContent wasn't just as you say "thrown in". it was a way to demonstrate the policy delegate, within the confines of an article of resonable length. as for the issue with the two variables named "ignoreContent", they are in two different objects; one is in Controller the other is in MyDocument so there will be no collision problems.
andrew
-
re: Not so good...
2004-06-07 18:48:29 johnts [Reply | View]
Well I played around with it, and put a new text box in the preference window for the ignore content items. I also hooked up the Preferences menu item to show the window.
The only thing that doesn't happen is the ignore content preference isn't saved. Quitting and restarting the app and the ignore content pref goes back to the default. -
re: Not so good...
2004-06-07 19:50:11 Andrew Anderson | [Reply | View]
That section was intentionally left as to the reader to implement. It's verystraightforward if you follow the example for the default homepage
andrew -
Problem Closing Windows
2005-08-01 09:06:13 Roalkl [Reply | View]
Ok, so I know that this article has been out there for some time, but I was wondering if I could get some help with a problem I have had. Everything I have seems to work ok, but when a javascript opened window is closed, my program bombs out.
I have been checking a few places, but thought that as others may have this problem, this would ve the best place to start.
Thanks in advance. -
re: Not so good...
2004-06-07 22:01:47 johnts [Reply | View]
Isn't that what this bit does?
NSString* iContent = [ignoreContent stringValue];
[defaults setObject:iContent forKey:@"ignoreContent"];
[md setIgnoreContent:iContent];
-
re: Not so good...
2004-06-08 05:17:58 Andrew Anderson | [Reply | View]
This part is in the "apply" method and sets the value into the static variable and handles saving the values to the user defaults, but does not handle loading it.
Look in Controller's "awakeFromNib" method, which handles loading the values for the defaultHomepage. -
re: Not so good...
2004-06-07 18:28:11 johnts [Reply | View]
I had to comment out everything that had to do with setting and getting the ignorecontent preferences:
in the @interface section
IBOutlet id ignoreContent;
NSString* iContent = [ignoreContent stringValue];
[defaults setObject:iContent forKey:@"ignoreContent"];
[md setIgnoreContent:iContent];
and
[ignoreContent setStringValue:[md getIgnoreContent]];
By "thrown in" I meant as I was typing in the apply: method (yeah, I typed it in, not copy and paste, figure I'd remember it better), I saw those lines and thought I had missed something.





