Commit c75c1a00 authored by ddkilzer@apple.com's avatar ddkilzer@apple.com

WebKit/mac:

2009-01-05  David Kilzer  <ddkilzer@apple.com>

        Add SPI to enable, disable and check state of WebIconDatabase

        Reviewed by Darin Adler & Timothy Hatcher.

        Add -[WebIconDatabase isEnabled] and -[WebIconDatabase setEnabled:]
        SPI to make it possible to enable, disable and check the state of
        the icon database.

        * Misc/WebIconDatabase.mm:
        (-[WebIconDatabase init]): Extracted code into -_startUpIconDatabase.
        (-[WebIconDatabase iconForURL:withSize:cache:]): Switched to use
        -isEnabled instead of -_isEnabled.
        (-[WebIconDatabase iconURLForURL:]): Ditto.
        (-[WebIconDatabase retainIconForURL:]): Ditto.
        (-[WebIconDatabase releaseIconForURL:]): Ditto.
        (-[WebIconDatabase isEnabled]): Renamed from -_isEnabled in
        WebInternal category.
        (-[WebIconDatabase setEnabled:]): Added.  Takes care of changing
        the enabled/disabled state of the icon database.
        (-[WebIconDatabase removeAllIcons]): Switched to use -isEnabled
        instead of -_isEnabled.
        (-[WebIconDatabase _startUpIconDatabase]): Added.  Extrated from
        -init.
        (-[WebIconDatabase _shutDownIconDatabase]): Added.  Remove
        observers when the icon database is disabled.
        * Misc/WebIconDatabaseInternal.h: Added declarations for
        -_startUpIconDatabase and -_shutDownIconDatabase.
        * Misc/WebIconDatabasePrivate.h: Added declarations for
        -isEnabled and -setEnabled:.

WebKit/win:

2009-01-05  David Kilzer  <ddkilzer@apple.com>

        Add API to enable, disable and check state of WebIconDatabase

        Reviewed by Darin Adler & Timothy Hatcher.

        Add WebIconDatabase::isEnabled() and WebIconDatabase::setEnabled()
        API to make it possible to enable, disable and check the state of
        the icon database.

        * Interfaces/IWebIconDatabase.idl: Declared isEnabled() and
        setEnabled() methods.
        * WebIconDatabase.cpp:
        (WebIconDatabase::init): Extracted code into startUpIconDatabase().
        (WebIconDatabase::startUpIconDatabase): Added.  Extracted from
        init().
        (WebIconDatabase::shutDownIconDatabase): Added.  Method is empty
        since there is nothing to do yet on Windows.
        (isEnabled): Added.
        (setEnabled): Added.
        * WebIconDatabase.h: Added method declarations.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@39641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 6b8fefe6
2009-01-05 David Kilzer <ddkilzer@apple.com>
Add SPI to enable, disable and check state of WebIconDatabase
Reviewed by Darin Adler & Timothy Hatcher.
Add -[WebIconDatabase isEnabled] and -[WebIconDatabase setEnabled:]
SPI to make it possible to enable, disable and check the state of
the icon database.
* Misc/WebIconDatabase.mm:
(-[WebIconDatabase init]): Extracted code into -_startUpIconDatabase.
(-[WebIconDatabase iconForURL:withSize:cache:]): Switched to use
-isEnabled instead of -_isEnabled.
(-[WebIconDatabase iconURLForURL:]): Ditto.
(-[WebIconDatabase retainIconForURL:]): Ditto.
(-[WebIconDatabase releaseIconForURL:]): Ditto.
(-[WebIconDatabase isEnabled]): Renamed from -_isEnabled in
WebInternal category.
(-[WebIconDatabase setEnabled:]): Added. Takes care of changing
the enabled/disabled state of the icon database.
(-[WebIconDatabase removeAllIcons]): Switched to use -isEnabled
instead of -_isEnabled.
(-[WebIconDatabase _startUpIconDatabase]): Added. Extrated from
-init.
(-[WebIconDatabase _shutDownIconDatabase]): Added. Remove
observers when the icon database is disabled.
* Misc/WebIconDatabaseInternal.h: Added declarations for
-_startUpIconDatabase and -_shutDownIconDatabase.
* Misc/WebIconDatabasePrivate.h: Added declarations for
-isEnabled and -setEnabled:.
2009-01-05 Brady Eidson <beidson@apple.com>
Reviewed by Jon Honeycutt
......
/*
* Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -70,7 +70,6 @@ static WebIconDatabaseClient* defaultClient()
}
@interface WebIconDatabase (WebReallyInternal)
- (BOOL)_isEnabled;
- (void)_sendNotificationForURL:(NSString *)URL;
- (void)_sendDidRemoveAllIconsNotification;
- (NSImage *)_iconForFileURL:(NSString *)fileURL withSize:(NSSize)size;
......@@ -108,37 +107,8 @@ static WebIconDatabaseClient* defaultClient()
[initialDefaults release];
BOOL enabled = [defaults boolForKey:WebIconDatabaseEnabledDefaultsKey];
iconDatabase()->setEnabled(enabled);
if (!enabled)
return self;
iconDatabase()->setClient(defaultClient());
// Figure out the directory we should be using for the icon.db
NSString *databaseDirectory = [self _databaseDirectory];
// Rename legacy icon database files to the new icon database name
BOOL isDirectory = NO;
NSString *legacyDB = [databaseDirectory stringByAppendingPathComponent:@"icon.db"];
NSFileManager *defaultManager = [NSFileManager defaultManager];
if ([defaultManager fileExistsAtPath:legacyDB isDirectory:&isDirectory] && !isDirectory) {
NSString *newDB = [databaseDirectory stringByAppendingPathComponent:iconDatabase()->defaultDatabaseFilename()];
if (![defaultManager fileExistsAtPath:newDB])
rename([legacyDB fileSystemRepresentation], [newDB fileSystemRepresentation]);
}
// Set the private browsing pref then open the WebCore icon database
iconDatabase()->setPrivateBrowsingEnabled([[WebPreferences standardPreferences] privateBrowsingEnabled]);
if (!iconDatabase()->open(databaseDirectory))
LOG_ERROR("Unable to open icon database");
// Register for important notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_applicationWillTerminate:)
name:NSApplicationWillTerminateNotification
object:NSApp];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(_resetCachedWebPreferences:)
name:WebPreferencesChangedNotification object:nil];
if (enabled)
[self _startUpIconDatabase];
return self;
}
......@@ -148,7 +118,7 @@ static WebIconDatabaseClient* defaultClient()
ASSERT(size.width);
ASSERT(size.height);
if (!URL || ![self _isEnabled])
if (!URL || ![self isEnabled])
return [self defaultIconForURL:URL withSize:size];
// FIXME - <rdar://problem/4697934> - Move the handling of FileURLs to WebCore and implement in ObjC++
......@@ -168,7 +138,7 @@ static WebIconDatabaseClient* defaultClient()
- (NSString *)iconURLForURL:(NSString *)URL
{
if (![self _isEnabled])
if (![self isEnabled])
return nil;
ASSERT_MAIN_THREAD();
......@@ -196,7 +166,7 @@ static WebIconDatabaseClient* defaultClient()
{
ASSERT_MAIN_THREAD();
ASSERT(URL);
if (![self _isEnabled])
if (![self isEnabled])
return;
iconDatabase()->retainIconForPageURL(URL);
......@@ -206,7 +176,7 @@ static WebIconDatabaseClient* defaultClient()
{
ASSERT_MAIN_THREAD();
ASSERT(pageURL);
if (![self _isEnabled])
if (![self isEnabled])
return;
iconDatabase()->releaseIconForPageURL(pageURL);
......@@ -242,10 +212,27 @@ static WebIconDatabaseClient* defaultClient()
@implementation WebIconDatabase (WebPendingPublic)
- (BOOL)isEnabled
{
return iconDatabase()->isEnabled();
}
- (void)setEnabled:(BOOL)flag
{
BOOL currentlyEnabled = [self isEnabled];
if (currentlyEnabled && !flag) {
iconDatabase()->setEnabled(false);
[self _shutDownIconDatabase];
} else if (!currentlyEnabled && flag) {
iconDatabase()->setEnabled(true);
[self _startUpIconDatabase];
}
}
- (void)removeAllIcons
{
ASSERT_MAIN_THREAD();
if (![self _isEnabled])
if (![self isEnabled])
return;
// Via the IconDatabaseClient interface, removeAllIcons() will send the WebIconDatabaseDidRemoveAllIconsNotification
......@@ -265,11 +252,6 @@ static WebIconDatabaseClient* defaultClient()
@implementation WebIconDatabase (WebInternal)
- (BOOL)_isEnabled
{
return iconDatabase()->isEnabled();
}
- (void)_sendNotificationForURL:(NSString *)URL
{
ASSERT(URL);
......@@ -289,6 +271,50 @@ static WebIconDatabaseClient* defaultClient()
userInfo:nil];
}
- (void)_startUpIconDatabase
{
iconDatabase()->setClient(defaultClient());
// Figure out the directory we should be using for the icon.db
NSString *databaseDirectory = [self _databaseDirectory];
// Rename legacy icon database files to the new icon database name
BOOL isDirectory = NO;
NSString *legacyDB = [databaseDirectory stringByAppendingPathComponent:@"icon.db"];
NSFileManager *defaultManager = [NSFileManager defaultManager];
if ([defaultManager fileExistsAtPath:legacyDB isDirectory:&isDirectory] && !isDirectory) {
NSString *newDB = [databaseDirectory stringByAppendingPathComponent:iconDatabase()->defaultDatabaseFilename()];
if (![defaultManager fileExistsAtPath:newDB])
rename([legacyDB fileSystemRepresentation], [newDB fileSystemRepresentation]);
}
// Set the private browsing pref then open the WebCore icon database
iconDatabase()->setPrivateBrowsingEnabled([[WebPreferences standardPreferences] privateBrowsingEnabled]);
if (!iconDatabase()->open(databaseDirectory))
LOG_ERROR("Unable to open icon database");
// Register for important notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_applicationWillTerminate:)
name:NSApplicationWillTerminateNotification
object:NSApp];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_resetCachedWebPreferences:)
name:WebPreferencesChangedNotification
object:nil];
}
- (void)_shutDownIconDatabase
{
// Unregister for important notifications
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSApplicationWillTerminateNotification
object:NSApp];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:WebPreferencesChangedNotification
object:nil];
}
- (void)_applicationWillTerminate:(NSNotification *)notification
{
iconDatabase()->close();
......
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -43,6 +43,8 @@ namespace WebCore {
@interface WebIconDatabase (WebInternal)
- (void)_sendNotificationForURL:(NSString *)URL;
- (void)_sendDidRemoveAllIconsNotification;
- (void)_shutDownIconDatabase;
- (void)_startUpIconDatabase;
@end
extern bool importToWebCoreFormat();
......
/*
* Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -43,7 +43,21 @@ extern NSString *WebIconDatabaseImportDirectoryDefaultsKey;
@interface WebIconDatabase (WebPendingPublic)
/*!
@method removeAllIcons:
@method isEnabled
@discussion Returns true if the icon database is currently enabled, or false if it
is disabled.
*/
- (BOOL)isEnabled;
/*!
@method setEnabled:
@discussion Enables or disables the icon database based on the flag passed in.
@param flag Pass true to enable the icon database, or false to disable it.
*/
- (void)setEnabled:(BOOL)flag;
/*!
@method removeAllIcons
@discussion Causes the icon database to delete all of the images that it has stored,
and to send out the notification WebIconDatabaseDidRemoveAllIconsNotification.
*/
......
2009-01-05 David Kilzer <ddkilzer@apple.com>
Add API to enable, disable and check state of WebIconDatabase
Reviewed by Darin Adler & Timothy Hatcher.
Add WebIconDatabase::isEnabled() and WebIconDatabase::setEnabled()
API to make it possible to enable, disable and check the state of
the icon database.
* Interfaces/IWebIconDatabase.idl: Declared isEnabled() and
setEnabled() methods.
* WebIconDatabase.cpp:
(WebIconDatabase::init): Extracted code into startUpIconDatabase().
(WebIconDatabase::startUpIconDatabase): Added. Extracted from
init().
(WebIconDatabase::shutDownIconDatabase): Added. Method is empty
since there is nothing to do yet on Windows.
(isEnabled): Added.
(setEnabled): Added.
* WebIconDatabase.h: Added method declarations.
2009-01-05 Anders Carlsson <andersca@apple.com>
Reviewed by Jon Honeycutt.
......
/*
* Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -148,4 +148,20 @@ interface IWebIconDatabase : IUnknown
- (NSString *)iconURLForURL:(NSString *)URL;
*/
HRESULT iconURLForURL([in] BSTR url, [out, retval] BSTR* iconURL);
/*!
@method isEnabled
@discussion Returns true if the icon database is currently enabled, or false if it
is disabled.
- (BOOL)isEnabled;
*/
HRESULT STDMETHODCALLTYPE isEnabled([out, retval] BOOL *result);
/*!
@method setEnabled:
@discussion Enables or disables the icon database based on the flag passed in.
@param flag Pass true to enable the icon database, or false to disable it.
- (void)setEnabled:(BOOL)flag;
*/
HRESULT STDMETHODCALLTYPE setEnabled([in] BOOL flag);
}
/*
* Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -71,7 +71,14 @@ void WebIconDatabase::init()
LOG_ERROR("Unable to get icon database enabled preference");
}
iconDatabase()->setEnabled(!!enabled);
if (!(!!enabled))
return;
startUpIconDatabase();
}
void WebIconDatabase::startUpIconDatabase()
{
iconDatabase()->setClient(this);
BSTR prefDatabasePath = 0;
......@@ -91,6 +98,10 @@ void WebIconDatabase::init()
LOG_ERROR("Failed to open icon database path");
}
void WebIconDatabase::shutDownIconDatabase()
{
}
WebIconDatabase* WebIconDatabase::createInstance()
{
WebIconDatabase* instance = new WebIconDatabase();
......@@ -225,6 +236,28 @@ HRESULT STDMETHODCALLTYPE WebIconDatabase::iconURLForURL(
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE isEnabled(
/* [retval][out] */ BOOL *result)
{
*result = iconDatabase()->isEnabled();
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE setEnabled(
/* [in] */ BOOL flag)
{
BOOL currentlyEnabled;
isEnabled(&currentlyEnabled);
if (currentlyEnabled && !flag) {
iconDatabase()->setEnabled(false);
shutDownIconDatabase();
} else if (!currentlyEnabled && flag) {
iconDatabase()->setEnabled(true);
startUpIconDatabase();
}
return S_OK;
}
HBITMAP createDIB(LPSIZE size)
{
HBITMAP result;
......
/*
* Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -57,6 +57,8 @@ private:
WebIconDatabase();
~WebIconDatabase();
void init();
void startUpIconDatabase();
void shutDownIconDatabase();
public:
// IUnknown
......@@ -94,6 +96,12 @@ public:
/* [in] */ BSTR url,
/* [retval][out] */ BSTR *iconURL);
virtual HRESULT STDMETHODCALLTYPE isEnabled(
/* [retval][out] */ BOOL *result);
virtual HRESULT STDMETHODCALLTYPE setEnabled(
/* [in] */ BOOL /*flag*/);
// IconDatabaseClient
virtual void dispatchDidRemoveAllIcons();
virtual void dispatchDidAddIconForPageURL(const WebCore::String&);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment