Showing posts with label internet explorer. Show all posts
Showing posts with label internet explorer. Show all posts

Saturday, September 6, 2008

Google Chrome: Better than Firefox, Internet Explorer

I installed Chrome when it came out last week and after only a day of using it I did the unthinkable: I made it my default browser. This is a big deal. I resisted making Firefox my default browser out of a very strong sense of loyalty to Internet Explorer. Chrome, however, is what I have always wanted a web browser to be: useful.

Let us start with the obvious things. The Tab UI is awesome. I have never liked the Firefox Tab UI. I think the IE Tab UI looks good, but they (we) never really nailed all the little quirks. Putting it up in the non-client area seems like such a no-brainer now. The UI is snappy, the animations are good looking, but subtle enough not to get in the way of using the product.



The MFU with thumbnails on the new-tab page is nice, though I wish it was more than just the top nine pages. I find it odd that I like it so much because I was really against doing something like this for IE (but I also never thought it could be made so fast in IE). I love the history-as-a-webpage feature. I am a little disappointed that I can not find a shortcut key to get to bookmarks. I don't want to take up screen space by having the bookmarks bar visible (though it is nice UI if you do turn it on). I know I can just type the name of the bookmark in the address bar, but I actually have long lists of bookmarks that I like to visit every day in a specific order. Instead I use CTRL+T to get a new tab then click the bookmark button.

I love the simplicity. We tried to make IE7 simple by getting rid of the menu bars and re-working things into the command bar. Chrome takes it all the way though.

The only UI I think looks wonky is the little pop-up in the bottom corner of the screen that appears when you hover over links. But I do like the little drop-down find box.

And of course, it would be nice if it worked with the ajax-y features of Facebook and Netflix.

Wednesday, July 2, 2008

firefox 3: better than internet explorer 7

This is a difficult thing for me to admit, but I think Firefox 3 is better than Internet Explorer 7. Having worked on the IE team, I am the first one to defend it, apologize for it, and staunchly refuse to use anything else. So how could this have happened?

Well, the product I work on now is a plug-in for both Firefox and IE. Since I am primarily responsible for the IE version, and I do most of my development and debugging of our product when it is running inside IE. As a result I am forced to use Firefox to read e-mail and such while my IE install is in a bad state.

Firefox 2 was usable, but I liked IE much better still. A lot of really good UI work went into IE 7 around the Tab UI and optimizing away the old menu bar. Sure, it has its faults and quirks, but I still felt more at home in IE.

Now that Firefox 3 is out, I basically have been converted without even thinking about it. And that's the key: when I use Firefox 3, I don't notice that it isn't IE. The only time I notice it's Firefox is when it does something better than IE, like spell checking my edit boxes, or remembering the URLs from my last session.

It's the little things that matter.

When I use IE now, it feels slow and poorly put together. Firefox is snappy; the UI is more polished. They stole some ideas from IE (The Gold Bar) and made them better. They have some ideas of their own (disjoint search term matching in autocomplete) that are great, too.

And as a good friend of mine used to say, "if it ain't snappy, it's crappy."

So Firefox 3 sets a high bar for the IE team to meet. I sincerely hope they blow it away. I think it is way too early to judge the IE8 UI; I will just have to wait and see how it shapes up.

Sunday, June 22, 2008

your bho and your activex control can't be the same object

Frequently I see people writing a BHO, and at some point they realize they need to make a way for a webpage to call some function implemented by the BHO. The best way to do this is to expose an ActiveX control. The most common mistake I see is trying to make the ActiveX control be the same C++ object as the BHO.

This is wrong for several reasons.

It violates good coding practice.

The whole point of object level encapsulation is that each object does one thing. If your BHO is your ActiveX control, now it does two things. It may seem at first that you're really just adding a new method to your BHO, but you have to take into account all that goes along with being an ActiveX control. Implementing IDispatch, loading and dealing with the type library, implementing IObjectSafety, etc.

Your site will be wrong.

Pretty much every IE extension type--toolbands, BHOs, toolbar buttons, ActiveX controls--implements IObjectWithSite. If you make one object be two different types of extension, they will share IObjectWithSite implementations. And they all have a different IE object that is their site.

For example, a toolbar button's site will be an object in IE's toolbar code. A BHO's site is a completely different object in ieframe.dll that knows how to create and interact with a BHO. Explorer bars are sited to an object in ieframe.dll that hosts an explorer bar. And ActiveX controls are sited to an object in mshtml.dll that knows how to host ActiveX controls and implements several DOM interfaces (IHTMLElement, etc) as well.

So if you make your BHO and your ActiveX control the same object, the BHO will be instantiated first and IE will call your IObjectWithSite::SetSite() method with a pointer to one type of object. Then, when your ActiveX control is created later on, IE will call the IObjectWithSite::SetSite() method again, but this time with a different internal IE object's address. Now your BHO is broken. And debugging this sort of thing may take you a long time.

What we Learned Today

Every IE extension you implement must be it's own object, or bad things will start to happen.

Saturday, June 21, 2008

the internet explorer object cookbook

When you start writing Internet Explorer extensions, or dealing with the DOM and the Webbrowser control at all, you frequently find you have an object of type X and you need to get the corresponding object of type Y. There is a lot of myth and bad advice on the web surrounding how to do some of these things.

The "site" in all of the following refer to the IUnknown you are given by Internet Explorer when it calls your IObjectWithSite::SetSite() method.

IWebBrowser2 from site

1. QueryInterface() your site for IID_IServiceProvider.
2. QueryService() the IServiceProvider for SID_STopLevelBrowser, IID_IServiceProvider.
3. QueryService() the top level IServiceProvider for SID_SWebBrowserApp, IID_IWebBrowser2.

IHTMLDocument2 from IWebBrowser2

1. Call IWebBrowser2::get_Document().
2. QueryInterface() the resulting IDispatch pointer for IID_IHTMLDocument2.

IHTMLDocument2 from site

1. Follow steps for "IWebBrowser2 from site" above.
2. Follow steps for "IHTMLDocument2 from IWebBrowser2" above.

IWebBrowser2 from IHTMLDocument2

1. QueryInterface() the IHTMLDocument2 for IID_IServiceProvider.
2. QueryService() the IServiceProvider for SID_SWebBrowserApp, IID_IWebBrowser2.

IHTMLDocument2 from IHTMLElement

1. Call IHTMLElement::get_Document();
2. QueryInterface() the resulting IDispatch pointer for IID_IHTMLDocument2.

IHTMLDocument2 from HWND

1. Use the accessibility hack described at here.

Saturday, May 31, 2008

the TIF really is a cache -- and it acts like one

It seems obvious, but I guess it has to be said. Internet Explorer's Temporary Internet Files folder is a cache. From Wikipedia: a cache is a temporary storage area where frequently accessed data can be stored for rapid access. Please note the use of the word temporary. This means that the data you want may not actually be there.

I frequently see questions along the lines of "How can I find this image/page in the cache?" or, even better, "How come this page I viewed isn't in the cache?" I love it when the askers of the latter form imply that this is a bug.

Files in the cache can be deleted at anytime. You can be looking at a page and then go to the cache and find it isn't there. There are many scenarios where this is legitimate. For example, if, while you are viewing this page, you go to Tools->Delete Browsing History and then clear your Temporary Internet Files, the only representation that IE will have of this page and all of its elements is the one in memory. Close the browser and that memory is freed and now its gone until you download it from the webserver again.

The page you are viewing may use the no-cache http header. The cache manager may have decided its time to scavenge. There may have even been an error writing to the cache and the cache has become corrupt.

I am sure there are other scenarios as well. The point is, you cannot rely on data to always be there. You must either capture the data in some other way, or be prepared to make a request to the server.

Thursday, May 29, 2008

to help or not to help

More and more I am confronted with a sort of moral dilemma. I read and post to the IE development forums over at MSDN. Frequently I see posts like this:

i want a BHO which continuously observe IE activity and send the URLs visited and time of visit and time of outfocus of them as soon as they are available,to listening java servlet. Now Please suggest me how to do this,perticularly this sending of url and their time details to java servlet.


He does not ask for help with a specific problem or bug he has encountered in the process. He does not tell us what he has done or post a sample of code he can not get to work. He simply asks, "how do I do this?" His masterful command of English does not help his case.

This guy is probably up to no good.

I can only think of one semi-legit use for such a thing, which would be for employers or parents to spy on their employees or children. And I'm not sure I can even get behind that.

So my dilemma becomes, do I help this guy? Do I tell him what to do? On the one hand, I do not want to be enabling spyware makers in anyway. On the other hand, if someone is paying him to do this thing, he is going to write the program whether I help him or not. Given that, is it better to make sure he does it right? I mean, which is better, crashing spyware or non-crashing spyware?

Anyway, today I am not helping this guy.

Tuesday, February 19, 2008

how to create an activex control that fires events to javascript (without using ATL)

Creating ActiveX Controls that Fire Events (without ATL)

I recently spent a fair bit of time at work figuring out how to write all the COM and OLE goo to make this work. There are lots of articles that tell you how to use ATL, but I am against ATL and I wanted to do it the old fashioned way. Here is a summary of what I learned.

The scenario was this: I wanted to have an ActiveX control that would download some file on a worker thread, then fire events that could be handled by JScript before, during and after the download. The general outline would look like this:

1. Page loads, control instantiated via object tag.
2. JScript calls attachEvent() to setup event handlers for the control.
3. JScript calls a method to start download.
4. Control spins up a worker thread which calls URLDownloadToFile().
5. The worker thread receives progress notifications via IBindStatusCallback(). Control fires events to JScript (from the worker thread) to inform JScript of progress.
6. Download completes, worker thread fires event to JScript.

I will call my control the Downloader and his CLSID is CLSID_DownloaderCtrl.

To make this happen your control must implement (and respond to in IUnknown::QueryInterface()):

1. IUnknown
2. IDispatch
3. IProvideClassInfo, IProvideClassInfo2
4. IObjectWithSite
5. IConnectionPointContainer
6. IDownloader (this is the dual interface for scripts to call methods the control exposes)
7. IObjectSafety
8. IServiceProvider (for URLDownloadToFile() to work properly)
9. IBindStatusCallback (optional -- only if you want download progess)

You will also need to implement IConnectionPoint, but do not repsond to it in QueryInterface. More on this later.

IUnknown

I assume you know how to implement IUnknown. Read Raymond's post on getting it wrong to make sure you know how to implement it.

Type Libraries

Before we can do much more we need a type library. To get this working, you have to create an .idl file that contains definitions. There are four important parts. Each one has its own GUID. They are specified in the .idl and MIDL will generate a header file and c file that defines them.

1. The outgoing event (disp)interface. DIID_DDownloaderEvents
2. The incoming (dual) interface. IID_IDownloader
3. The coclass goo. CLSID_DownloaderCtrl
4. The library. LIBID_Downloader

Your .idl should look something like this:

[
uuid(00000000-0000-0000-0000-000000000000),
version(1.0)
]
library Downloader
{
[
uuid(11111111-1111-1111-1111-111111111111),
hidden
]
dispinterface DDownloaderEvents
{
properties:
methods:
[id(DISPID_PROGRESS)] void Progress();
[id(DISPID_COMPLETE)] void Complete();
}

[
dual,
uuid(22222222-2222-2222-2222-222222222222)
]
interface IDownloader : IDispatch
{
[id(DISPID_DOWNLOAD)] HRESULT download(BSTR bstrFile);
}

[
uuid(33333333-3333-3333-3333-333333333333)
]
coclass DownloaderCtrl
{
[default] interface IDownloader;
[source, default] dispinterface DDownloaderEvents;
}
}



MIDL will generate a .tlb file from this. You must include this type library as a resource in your .dll. To do that, add a line like the following:

1 TYPELIB "downloader.tlb"

Now you can call LoadTypeLib() using your module's path to get the type library, which you will need to use in your IDispatch implementation.

IDispatch

I am going to assume you know mostly know how to implement this as well. It is well documented. The important thing is to make sure you expose your typelib correctly.

IProvideClassInfo, IProvideClassInfo2

These are pretty straight-forward. In GetGUID() return your outgoing event interface, DIID_DDownloaderEvents.

The only tricky part is in GetClassInfo. You should call LoadTypeLib() then call ITypeLib->GetTypeInfoOfGuid(). The question is, which GUID do you use? The correct answer is CLSID_DownloaderCtrl. This gets the type info of your coclass, which Internet Explorer can use to figure out what your outgoing event interface is.

IConnectionPointContainer

When you call attachEvent() in JScript, IE will ask for this interface to try to find a connection point for your outgoing event interface. You have to implement FindConnectionPoint(). I found EnumConnectionPoints() and to not be called by Internet Explorer. However, you may experience different results here. Set breakpoints and/or use asserts() to make sure anything you E_NOTIMPL isn't called, otherwise you may find yourself debugging into the wee hours.

IConnectionPoint

FindConnectionPoint() gives out a pointer to an IConnectionPoint, which should really be a different object than your IConnectionPointContainer. See the documentation. We don't respond to IConnectionPoint in QueryInterface, since the only allowed way of getting it is via FindConnectionPoint().

You have to implement Advise() and Unadvise(). The remaining methods were never called for my implementation. However, as above, your milage may vary. Everytime IE calls Advise(), it will pass you an IUnknown. QueryInterface() for IID_IDispatch and remember that pointer. Make sure you associate it with the cookie you give back (std::map is one option, if you go in for that sort of thing).

When you want to fire your event, simply call the Invoke() member of all the IDispatch pointers you are holding on to, passing whatever parameters you want and the DISPID of whatever event you want to send.

Important: Before you use this pointer, read the bit about marshalling below.

IObjectWithSite

This is simple as well. Make sure you respond to SetSite(NULL) by releasing all the pointers you acquired from your site. Also, this is your queue that your control is going away soon.

IServiceProvider

All you have to do here is QueryInterface your site for IServiceProvider and thunk the call to QueryService() through to your site's implementation. If you're using the Vista SDK, you can use IUnknown_QueryService().

If you don't implement this, URLDownloadToFile() may not be able to get access to certain security information and your life will be harder.

IObjectSafety

You should implement this to make instantiating your control easier and safer. Refer to the documentation and plentiful on-line examples.

A Word on Marshalling

My object operates on two threads--the IE Tab thread that it is created on, and a worker thread that does the heavy lifting. The point of using a worker thread is to not hang the UI while the download happens. This gives a nice experience, but makes implementation harder.

The one thing to remember, is all of IE's interaction with your object will happen on it's thread. You will receive IDispatch pointers on this thread. You cannot use these pointers in a different apartment (which means, you cannot use them on the worker thread).

In order to fire events from the worker thread, you must marshal the IDispatch pointers. You have two options for doing this:

1) Call CoMarshalInterThreadInterfaceInStream() on the IE thread, then CoGetInterfaceAndReleaseStream() on the worker thread. Do this for every IDispatch pointer and use the pointer returned on the worker thread.
2) Use the GIT (Global Interface Table). You're on your own with that one -- see the documentation.

If you try to use the pointer on the wrong thread, your Invoke() call will fail silently and the event will not be fired.

Setting up the JScript

1. Create your object using the object tag. You cannot use new ActiveXObject() because IE will not hook-up the events for you.
2. Give your object tag and ID, such as ID="downloader".
3. In the onLoad handler for the body element, call a function that uses the ID to attach the event handlers to events. E.g., downloader.attachEvent('Progress', onProgressEvent). Then simply implement the onProgressEvent() in JScript in the script section of your HTML.

Conclusion

Well, I hope that helps someone. If you have anything to add, please leave a comment.

Wednesday, February 6, 2008

PicLens 1.6.1 for Internet Explorer

As promised, we have just released PicLens 1.6.1 for Internet Explorer. You can download it by visiting http://www.piclens.com.



This is what I have been working on for the last month. It was quite a challenge, and luckily I had a fairly extensive background in Internet Explorer's extensibility model in order to make it happen. There are huge differences between the way Internet Explorer and FireFox are architected. For example, in FireFox all tabs run on the same thread. Since Internet Explorer creates a seperate UI thread for each Tab, I had to write code to demultiplex events coming from the tabs to our single PicLens thread that we create. This was done by careful use of DHTMLWindowEvents2's OnBlur and OnFocus events, as well as DWebBrowserEvents2's WindowStateChanged event. Keeping track of which of PicLens' Browser Helper Object instances (IE creates one per tab) was the "active" window was non-trivial, especially since we had to support IE6 and IE7.

In the end though I think we have a really solid product. If you notice any bugs or have any feedback, please feel free to leave me a comment or e-mail feedback@piclens.com.

Thursday, December 27, 2007

why doesn't the favicon for my site appear in IE7?

This is a re-posting of a post originally published on 2007-03-01. The original can be found here. This version has been updated to match what is currently reality.

When I was at Microsoft, I was the developer tasked with fixing the Favicon story for IE7. The original IE6 behavior was to download the favicon once--when a user made a site a Favorite. I do not want to go too deep into the details of how this craziness works, but the key piece of information to understanding why it seemed so broken is this: a mapping between the url of the site the url for the site's Favicon would be stored in IE's History database and the actually bits of the icon would be stored in the temporary Internet files folder. Thus, if you cleared your history or your cache, or the item expired out of either one, the icon would be gone forever.

Fast-forward to IE7. It has been over two (three?) years since IE6 shipped. We want to implement tabbed browsing, and we want the tabs to display the correct Favicons. So I updated the Favicon code to always download the icon on a first visit. The code also remembers if there is no Favicon (404) or it was invalid in some way (ExtractIcon() failed).

Here is a Mini-Faq (with one bonus question at the end) that I wrote while I was at Microsoft:

Q: How do I make a favicon appear for my site in IE7?
A: There are two ways. The first is to put a file in the root of your domain called favicon.ico. The second is to use a <link> tag with the rel="shortcut icon" value and the href value set to the URL for the Icon you wish to display.

Q: How often does IE download the favicon?
A: IE will download the icon when a user first visits the site. The icon is stored in the Temporary Internet Files folder on the client machine. Additional metadata about the favicon is stored in the user's Url History database. If either store is cleared, or items relating to the favicon have naturally expired, then the icon will be downloaded again on the next visit. If more than one page (or site) shares the same favicon, it is only downloaded once. IE takes great pains to download the icon as few times as possible to reduce load on the server.

Q: I see the wrong favicon for some sites I visit. How do I fix this?
A: If the history database has become corrupted in some way, this can happen. The simplest solution is just to use Delete Browsing History (on the Tools menu) to clear the cache and the history store.

Q: I put a favicon.ico on my site as you described, but it still doesn't appear.
A: It must actually be a .ico (an Icon) file. Bitmaps, pngs, gifs, etc, will not work. IE7 will download your favicon to the Temporary Internet Files folder and call ExtractIcon() on the file. If this fails, we will show the default icon instead of your favicon.

Q: I verified that my favicon really is an icon, but it still doesn't appear.
A: Since IE loads your icon out of the Temporary Internet Files folder, it must be able to actually store it there. If you are setting the no-cache directive for the icon file, then IE will not be able to display your icon and will display the default icon instead. You can use Fiddler to verify.

Q: How do I create a different favicon for every page on my site?
A: Put a different tag on each page, pointing to a different icon.

Q: I changed my site's favicon to a different icon, but the old one still shows in IE. How do I force IE to update?
A: If you just put the favicon.ico file in the root of your domain, IE doesn't have any way of knowing if it changed. To force an update, you need to use a tag and point to a different filename than you previously used. The current filename is compared against the known filename stored in the Url History database. When IE sees the filename has changed, it will download your new icon. Alternatively, you can ask your users to clear their history and cache (Tools->Internet Options->Delete Browsing History), which will also force IE to download the new file.

Q: What is still broken?
A: Two things: (1) If you specify an alternate location via <link> tag, the href member must be fully-qualified and does not respect the <base> tag. (2) The <link> tag must have "shortcut icon" as the rel value, but this is in violation of the W3C spec that says whitespace in the rel tag denotes a list of values. IE treats "shortcut icon" as a single value. Luckily this still works for other browsers who see "shortcut" and ignore it and only pay attention to the "icon" string.

That should cover most of the questions I've received about favicons in IE7. If you have more questions, feel free to ask.

Wednesday, December 5, 2007

the importance of context: security and the dom

This is a re-posting of a post originally published on 2004-07-22. The original can be found here. This version has been updated to match what is currently reality.

Almost every navigation in Internet Explorer results in a flurry of security checks. Many of these checks are fairly obvious things, such as checking the URL of the current location (the context URL) and the pending navigation's destination URL to see if their zones, domains, protocols, etc are the same, different, acceptable, etc. When I worked on Internet Explorer, I spent a significant amount of time debugging strange combinations and ways of navigating. I will not bore you with the details; my goal is to emphasize the importance of context. I will mainly speak to the Internet Explorer Pop-up Blocker's dependence on the context URL.

The Pop-up Blocker is dependent on the context URL. When the page attempts to open a new window, the HTML rendering engine queries the Pop-up Blocker. The Pop-up Blocker looks in the white list to see if this page is exempt from new window management. If, for some reason, the context URL provided is NULL, then obviously it cannot be matched to a domain in the white list.

So let us examine the following:
var oSpan = document.createElement("span");
oSpan.innerHTML =
"<a href="http://www.blogger.com/" target="'_blank'">Microsoft.com</a>";

When the anchor causes the browser to navigate, it will see the _blank and attempt to open a new window. This attempt will have to be verified by Pop-up Blocker. But the span is not parented to anything, thus it has no context. Elements with no context get the default context, which is about:blank, which confers no rights.

The moral of this story is always remember to parent your dynamically created elements to something in the document:

document.appendChild(oSpan);


It's been pointed out that the W3C specification says something about what should happen here and that IE does something wrong (or fails to do something). That may be the case. I was not responsible for the code the implemented the DOM.

Furthermore, adding about:blank to your white list doesn't work either, since it has no domain and the whitelist requires domains.

Sunday, December 2, 2007

the internet explorer pop-up manager and your webbrowser control host

This is a re-posting of a post originally published on 2004-01-26. The original can be found here. This version has been updated to match what is currently reality.

Overview
With the introduction of Windows XP Service Pack 2, Internet Explorer 6 (and up) introduced a built-in pop-up window manager. If your program is going to host the webbrowser control, you may or may not want the pop-up blocker's functionality. This post will describe how to alter, override or enable the pop-up blocker's functionality for application.

Implement INewWindowManager
The basic Implement INewWindowManager. The webbrowser control will QueryInterface its site for this method. You should implement this in the same place you (would) implement IDocHostUIHandler.

When webbrowser control detects a new window is being requested, it will call the EvaluateNewWindow() method on the interface. Just about any method for opening a new window should trigger this call. What follows is boiler-plate for various scenarios:

I Do Not Want Any Pop-up Management
This is the easy case, since pop-up management is opt-in. Simply do nothing. The webbrowser control will query you for INWM. If the query fails, no pop-up management will occur. This decision was made so that applications that already exist would not have to change when Windows XP Service Pack 2 shipped.

I Want Exactly What Internet Explorer Does
This is easy too. Simply implement INWM::ENW() and return E_NOTIMPL. You will get all the same functionality, including checking against the user's white list and action according to the user's preferences.

CMyObject::EvaluateNewWindow(...)
{
return E_NOTIMPL;
}
When the webbrowser control sees the failure code, it will fall back to the default pop-up management.

I Want My Own Logic
Implement INWM::ENW() and use the parameters to decide whether or not to block the new window. Return S_FALSE to block the window and S_OK to allow it:

CMyObject::EvaluateNewWindow(...)
{
HRESULT hr = S_OK;
if (/* your logic here */)
{
hr = S_FALSE;
}
else if (/* more of your logic here */)
{
hr = S_FALSE;
}
// ... and so on ...

// Now update your UI.
switch(hr)
{
case S_OK:
OnPopupNotBlocked(...);
break;

case S_FALSE:
OnPopupBlocked(...);
break;
}

return hr;
}
Developer's Note
I will admit right now, this is the first public interface I ever designed. I was young and stupid and the Interface was not subject to a lot of review by people with more expertise. If I was doing it all over again, I would probably not have done it this way. But it works.