[Extensions] Fix lifetime bug in ExtensionAction/IconImage

ExtensionActions can lazily load the default icon image, which is
implemented as an IconImage. The IconImage, in turn, is constructed with
a BrowserContext because it needs access to the ImageLoader (a
BrowserContextKeyedService). ExtensionActions are owned by the
ExtensionActionManager (another BrowserContextKeyedService with one
instance shared across incognito and normal profiles), but took a
BrowserContext as an argument when loading the default icon image.

This all caused a problem when an incognito profile was passed in as
the browser context to load the default icon for the extension action.
The extension action would then create an IconImage with the incognito
profile as a context, but the ExtensionAction (and thus the IconImage)
are owned by the ExtensionActionManager, and are therefore not deleted
upon the incognito profile's destruction. This means that if you have a
flow where the ExtensionAction's default icon is loaded via an incognito
profile, the incognito profile is deleted, and then the icon is later
used in the normal profile, there's a crash.

Fix this by having the ExtensionActionManager assign the IconImage to
the ExtensionAction using its own profile. Since the ExtensionActions
are owned by the ExtensionActionManager, and the ExtensionActionManager
is owned by the profile by being a BrowserContextKeyedService, this is
guaranteed to be safe. This also abstracts out the context of a profile
or BrowserContext from the ExtensionAction class, keeping it more in
line with its data-structure-like concept.

Add a regression test.

BUG=663726 (and possibly others)

Review-Url: https://codereview.chromium.org/2506273002
Cr-Commit-Position: refs/heads/master@{#433361}
9 files changed