Use the navigation IsolationInfo for downloading an opened PDF
What: When downloading a PDF that is already opened, use the original
navigation isolation info.
Why: When a subframe PDF is opened and then is manually downloaded, the
network isolation key for the 2 requests are inconsistent. The
navigation request is using <top frame origin, subframe origin>, whereas
the download request is using the <pdf url origin (== subframe origin),
pdf url origin>.
This not only has the typical performance & privacy problem, but also
could give the user an unexpected cached PDF instead of the latest
PDF opened -- if there are 2 PDFs opened with the same URL but different
contents, and we try to save the latest one. (Note that the fundamental
issue is not solvable by fixing the isolation info per
https://bugs.chromium.org/p/chromium/issues/detail?id=1171524#c20,
but making it download the latest opened PDF is still more desirable
than making it download an old one).
How: Add a |rfh| parameter in WebContents::SaveFrame(WithHeaders), to
denote the original navigation targeted frame, so that we can recover
the origin navigation isolation info from there. Fill in this info in
the caller sites:
1. PDFWebContentsHelper::SaveUrlAs
2. RenderViewContextMenu::ExecSaveAs
3. WebContentsImpl::OnSavePage
Specifically, if we have an inner-web-contents PDF, we will pass its
outer-web-contents-frame; otherwise, pass the current frame host.
In download_utils.cc::CreateResourceRequest, if the isolation_info is
already filled in, use the given isolation info & site-for-cookies;
otherwise, keep the existing behavior i.e. use <url origin, url origin>
as the isolation key.
Bug: 1174216
Change-Id: Ibba85358a4da9efedaa5510b70f7279412685d56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2689861
Reviewed-by: Nasko Oskov <[email protected]>
Reviewed-by: Istiaque Ahmed <[email protected]>
Reviewed-by: K. Moon <[email protected]>
Reviewed-by: Matt Menke <[email protected]>
Reviewed-by: Min Qin <[email protected]>
Commit-Queue: Yao Xiao <[email protected]>
Cr-Commit-Position: refs/heads/master@{#857983}
diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h
index f1bdd0c..f7c4564 100644
--- a/content/public/browser/web_contents.h
+++ b/content/public/browser/web_contents.h
@@ -832,19 +832,24 @@
const base::FilePath& dir_path,
SavePageType save_type) = 0;
- // Saves the given frame's URL to the local filesystem.
+ // Saves the given frame's URL to the local filesystem. If `rfh` is provided,
+ // the saving is performed in its context. For example, the associated
+ // navigation isolation info will be used for making the network request.
virtual void SaveFrame(const GURL& url,
- const Referrer& referrer) = 0;
+ const Referrer& referrer,
+ RenderFrameHost* rfh) = 0;
// Saves the given frame's URL to the local filesystem. The headers, if
// provided, is used to make a request to the URL rather than using cache.
// Format of |headers| is a new line separated list of key value pairs:
- // "<key1>: <value1>\r\n<key2>: <value2>".
- virtual void SaveFrameWithHeaders(
- const GURL& url,
- const Referrer& referrer,
- const std::string& headers,
- const base::string16& suggested_filename) = 0;
+ // "<key1>: <value1>\r\n<key2>: <value2>". If `rfh` is provided, the saving is
+ // performed in its context. For example, the associated navigation isolation
+ // info will be used for making the network request.
+ virtual void SaveFrameWithHeaders(const GURL& url,
+ const Referrer& referrer,
+ const std::string& headers,
+ const base::string16& suggested_filename,
+ RenderFrameHost* rfh) = 0;
// Generate an MHTML representation of the current page conforming to the
// settings provided by |params| and returning final status information via