Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Unified Diff: chrome/browser/android/offline_pages/prerendering_offliner.cc

Issue 2683493002: Get signals working in the EXTRA_DATA section of MHTML (Closed)
Patch Set: CR Feedback per FGorski Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/offline_pages/prerendering_offliner.cc
diff --git a/chrome/browser/android/offline_pages/prerendering_offliner.cc b/chrome/browser/android/offline_pages/prerendering_offliner.cc
index a6564ad078d662af7b164c009e039d8dd89aa383..2cf2cbe1ae18bc73407ad20799a6e61ffa43b300 100644
--- a/chrome/browser/android/offline_pages/prerendering_offliner.cc
+++ b/chrome/browser/android/offline_pages/prerendering_offliner.cc
@@ -16,8 +16,13 @@
#include "components/offline_pages/core/downloads/download_ui_adapter.h"
#include "components/offline_pages/core/offline_page_model.h"
#include "content/public/browser/browser_context.h"
+#include "content/public/browser/mhtml_extra_data.h"
#include "content/public/browser/web_contents.h"
+namespace {
+const char kApplicationJson[] = "application/json";
+} // namespace
+
namespace offline_pages {
PrerenderingOffliner::PrerenderingOffliner(
@@ -83,6 +88,21 @@ void PrerenderingOffliner::OnLoadPageDone(
else if (save_page_params.url != request.url())
save_page_params.original_url = request.url();
+#ifndef NDEBUG
Dmitry Titov 2017/03/29 18:53:06 why this specific part is debug-only?
Pete Williamson 2017/03/29 22:05:42 My intent here is that we only write the signals i
Dmitry Titov 2017/03/29 23:26:29 So what is the plan? Do we build debug to run in h
Pete Williamson 2017/03/31 00:29:48 After offline discussion, we decided on a new comm
+ // Stash loading signals for writing when we write out the MHTML.
+ std::string body = SerializeLoadingSignalData();
+ std::string content_type = kApplicationJson;
+ std::string content_location = "cid:signal-data-" +
+ std::to_string(request.request_id()) +
+ "@mhtml.blink";
+
+ content::MHTMLExtraData* extra_data =
+ content::MHTMLExtraData::FromWebContents(web_contents);
+ DCHECK(extra_data);
+
+ extra_data->AddExtraMHTMLPart(content_type, content_location, body);
+#endif
+
SavePage(save_page_params, std::move(archiver),
base::Bind(&PrerenderingOffliner::OnSavePageDone,
weak_ptr_factory_.GetWeakPtr(), request));
@@ -94,6 +114,19 @@ void PrerenderingOffliner::OnLoadPageDone(
}
}
+std::string PrerenderingOffliner::SerializeLoadingSignalData() {
+ // Write the signal data into a single string.
+ std::string signal_string;
+ const std::vector<std::string>& signals = loader_->GetLoadingSignalData();
+
+ // TODO(petewil): Convert this to JSON, use json_writer.h
Dmitry Titov 2017/03/29 18:53:06 either do this in this patch, or it should remain
Pete Williamson 2017/03/29 22:05:42 Changed to text/plain for now.
+ for (std::string signal : signals) {
+ signal_string += signal;
+ signal_string += "\r\n";
Dmitry Titov 2017/03/29 18:53:06 does it have to be \r\n in the body?
Pete Williamson 2017/03/29 22:05:42 No, but it does make it easier to read and parse u
Dmitry Titov 2017/03/29 23:26:29 What I meant is why both, the regular "\n" would s
Pete Williamson 2017/03/31 00:29:48 Ah, that's different. I was copying what I saw el
Dmitry Titov 2017/03/31 18:05:53 The other places are in header/boundary parts, it'
Pete Williamson 2017/03/31 21:58:03 OK, done, and added the Content-Transfer-Encoding
+ }
+ return signal_string;
+}
+
void PrerenderingOffliner::OnSavePageDone(
const SavePageRequest& request,
SavePageResult save_result,

Powered by Google App Engine
This is Rietveld 408576698