summaryrefslogtreecommitdiffstats
path: root/content/renderer
diff options
context:
space:
mode:
authorlukasza <lukasza@chromium.org>2015-12-09 08:46:34 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-09 16:48:10 +0000
commit4a96a1f0d90dbc44bf9b1d4ac630d9cd9b50b5c1 (patch)
tree5e9a463a9cd1ac37354ef2ab401e42d2c2b2ab3f /content/renderer
parentd375d6955484a4987540374e519163af36998f0c (diff)
downloadchromium_src-4a96a1f0d90dbc44bf9b1d4ac630d9cd9b50b5c1.zip
chromium_src-4a96a1f0d90dbc44bf9b1d4ac630d9cd9b50b5c1.tar.gz
chromium_src-4a96a1f0d90dbc44bf9b1d4ac630d9cd9b50b5c1.tar.bz2
Passing url -> local_path map as a std::map rather than as 2 vectors.
When serializing "complete html", the serializer needs a map providing local paths for resources being saved. In a future CL we will want to pass a separate mapping for savable resources (with URL used as a key) and a separate mapping for frames (seperate frames should be distinguished even if they have the same URL). This CL cleans up how the map is passed over IPC, to prepare the code for the future CL. After this CL we pass over IPC a std::map<GURL, base::FilePath> (instead of passing a std::vector<GURL> and another std::vector<base::FilePath>). Note that there is no established way to pass a map over Blink's public API (i.e. see [1]) - we need to pass a vector of pairs to Blink. Additionally this CL makes the map self-contained, by having base::FilePaths already include a potential directory path (rather than separately passing it over IPC and having separate code dealing with it in content/renderer and in third_party/WebKit). [1] https://groups.google.com/a/chromium.org/d/topic/blink-dev/KmuzvTgXqFs/discussion BUG=106364 Review URL: https://codereview.chromium.org/1440843002 Cr-Commit-Position: refs/heads/master@{#364084}
Diffstat (limited to 'content/renderer')
-rw-r--r--content/renderer/dom_serializer_browsertest.cc21
-rw-r--r--content/renderer/render_frame_impl.cc34
-rw-r--r--content/renderer/render_frame_impl.h4
3 files changed, 25 insertions, 34 deletions
diff --git a/content/renderer/dom_serializer_browsertest.cc b/content/renderer/dom_serializer_browsertest.cc
index 5dc4c68..1737cac 100644
--- a/content/renderer/dom_serializer_browsertest.cc
+++ b/content/renderer/dom_serializer_browsertest.cc
@@ -77,9 +77,7 @@ class LoadObserver : public RenderViewObserver {
class DomSerializerTests : public ContentBrowserTest,
public WebPageSerializerClient {
public:
- DomSerializerTests()
- : serialization_reported_end_of_data_(false),
- local_directory_name_(FILE_PATH_LITERAL("./dummy_files/")) {}
+ DomSerializerTests() : serialization_reported_end_of_data_(false) {}
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(switches::kSingleProcess);
@@ -161,18 +159,14 @@ class DomSerializerTests : public ContentBrowserTest,
// Find corresponding WebFrame according to frame_url.
WebFrame* web_frame = FindSubFrameByURL(frame_url);
ASSERT_TRUE(web_frame != NULL);
- WebVector<WebURL> links;
- links.assign(&frame_url, 1);
WebString file_path =
base::FilePath(FILE_PATH_LITERAL("c:\\dummy.htm")).AsUTF16Unsafe();
- WebVector<WebString> local_paths;
- local_paths.assign(&file_path, 1);
+ std::vector<std::pair<WebURL, WebString>> url_to_local_path;
+ url_to_local_path.push_back(std::make_pair(WebURL(frame_url), file_path));
// Start serializing DOM.
- bool result = WebPageSerializer::serialize(web_frame->toWebLocalFrame(),
- static_cast<WebPageSerializerClient*>(this),
- links,
- local_paths,
- local_directory_name_.AsUTF16Unsafe());
+ bool result = WebPageSerializer::serialize(
+ web_frame->toWebLocalFrame(),
+ static_cast<WebPageSerializerClient*>(this), url_to_local_path);
ASSERT_TRUE(result);
}
@@ -615,9 +609,6 @@ class DomSerializerTests : public ContentBrowserTest,
int32 render_view_routing_id_;
std::string serialized_contents_;
bool serialization_reported_end_of_data_;
- // The local_directory_name_ is dummy relative path of directory which
- // contain all saved auxiliary files included all sub frames and resources.
- const base::FilePath local_directory_name_;
};
// If original contents have document type, the serialized contents also have
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
index bd59811..17d8764 100644
--- a/content/renderer/render_frame_impl.cc
+++ b/content/renderer/render_frame_impl.cc
@@ -568,6 +568,13 @@ RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl =
void OnGotContentHandlerID(uint32_t content_handler_id) {}
+WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) {
+ DCHECK(!path.IsAbsolute());
+ return WebString::fromUTF8(
+ std::string("./") +
+ path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe());
+}
+
} // namespace
// static
@@ -4637,25 +4644,20 @@ void RenderFrameImpl::OnGetSavableResourceLinks() {
}
void RenderFrameImpl::OnGetSerializedHtmlWithLocalLinks(
- std::vector<GURL> original_urls,
- std::vector<base::FilePath> equivalent_local_paths,
- base::FilePath local_directory_path) {
- // Only DCHECK, since the message comes from the trusted browser process.
- DCHECK(original_urls.size() == equivalent_local_paths.size());
-
- // Convert std::vector of GURLs to WebVector<WebURL>
- WebVector<WebURL> weburl_links(original_urls);
-
- // Convert std::vector of base::FilePath to WebVector<WebString>
- WebVector<WebString> webstring_paths(equivalent_local_paths.size());
- for (size_t i = 0; i < equivalent_local_paths.size(); i++)
- webstring_paths[i] = equivalent_local_paths[i].AsUTF16Unsafe();
+ const std::map<GURL, base::FilePath>& url_to_local_path) {
+ // Convert input to the canonical way of passing a map into a Blink API.
+ std::vector<std::pair<WebURL, WebString>> weburl_to_local_path;
+ for (const auto& it : url_to_local_path) {
+ const GURL& url = it.first;
+ const base::FilePath& local_path = it.second;
+ weburl_to_local_path.push_back(std::make_pair(
+ WebURL(url), ConvertRelativePathToHtmlAttribute(local_path)));
+ }
// Serialize the frame (without recursing into subframes).
WebPageSerializer::serialize(GetWebFrame(),
- this, // WebPageSerializerClient.
- weburl_links, webstring_paths,
- local_directory_path.AsUTF16Unsafe());
+ this, // WebPageSerializerClient.
+ weburl_to_local_path);
}
void RenderFrameImpl::OpenURL(const GURL& url,
diff --git a/content/renderer/render_frame_impl.h b/content/renderer/render_frame_impl.h
index 4fdad7f..8d3c4f3 100644
--- a/content/renderer/render_frame_impl.h
+++ b/content/renderer/render_frame_impl.h
@@ -763,9 +763,7 @@ class CONTENT_EXPORT RenderFrameImpl
int error_code);
void OnGetSavableResourceLinks();
void OnGetSerializedHtmlWithLocalLinks(
- std::vector<GURL> original_urls,
- std::vector<base::FilePath> equivalent_local_paths,
- base::FilePath local_directory_path);
+ const std::map<GURL, base::FilePath>& url_to_local_path);
// Requests that the browser process navigates to |url|. If
// |is_history_navigation_in_new_child| is true, the browser process should