Fix how Save-Page-As responds to web requests blocked by extensions.

AdBlocker extensions exercise (via chrome.webRequest API) a code path
where ResourceHandler (and in particular SaveFileResourceHandler)
reports a failure via OnResponseCompleted without first calling
OnResponseStarted.  This code path is also executed when the request
fails before HTTP headers are received and parsed (i.e. if the host name
could not be resolved by DNS).

In this code path, SaveFileManager::SaveFinished is called before
SaveFileManager::StartSave got called.  This means that when
SaveFinished calls LookupSaveFile, it won't find anything.  This
behavior has regressed in https://crrev.com/1484093002, which removed
the "else" clause in SaveFinished method, incorrectly thinking that
save_item_id-based lookup will always succeed because of the other
changes made in the CL.

This CL fixes the problem by always calling OnSaveFinished (even if
LookupSaveFile failed).  To make this work, we need to make sure that
SavePackage lookup in SaveFinished succeeds, even if OnStartSave was not
called (this is where |package_| map was populated before the fix).  To
accomplish this, the fix moves populating the |package_| map (SaveItemId
to SavePackage* map) earlier - from OnStartSave into SaveURL method.

BUG=595345

Review URL: https://codereview.chromium.org/1812693002

Cr-Commit-Position: refs/heads/master@{#382577}
3 files changed