Commit e0e9686b authored by Jian Li's avatar Jian Li Committed by Commit Bot

Process intent data embedded in the custom offline headers

When an intent with file:// or content:// URL is opened, a custom
offline header will be set to use the file:// or content:// from this
intent once the validation passes. OfflinePageRequestJob will try to
read from the passing file:// or content:// instead.

Bug: 758690
Change-Id: I69c75a73c02377f62ab0c6f97013be78b149ba7e
Reviewed-on: https://chromium-review.googlesource.com/942466Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarDmitry Titov <dimich@chromium.org>
Commit-Queue: Jian Li <jianli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541270}
parent f4cbba88
......@@ -100,6 +100,12 @@ class OfflinePageRequestJob : public net::URLRequestJob {
// Launched due to hitting the reload button or hitting enter in the
// omnibox.
RELOAD = 6,
// Launched due to clicking a notification.
NOTIFICATION = 7,
// Launched due to processing a file URL intent to view MHTML file.
FILE_URL_INTENT = 8,
// Launched due to processing a content URL intent to view MHTML content.
CONTENT_URL_INTENT = 9,
COUNT
};
......@@ -206,11 +212,21 @@ class OfflinePageRequestJob : public net::URLRequestJob {
const OfflinePageItem& GetCurrentOfflinePage() const;
bool IsProcessingFileOrContentUrlIntent() const;
void OnTrustedOfflinePageFound();
void VisitTrustedOfflinePage();
void SetOfflinePageNavigationUIData(bool is_offline_page);
void Redirect(const GURL& redirected_url);
void OpenFile(const net::CompletionCallback& callback);
void OpenFile(const base::FilePath& file_path,
const net::CompletionCallback& callback);
void UpdateDigestOnBackground(
scoped_refptr<net::IOBuffer> buffer,
size_t len,
base::OnceCallback<void(void)> digest_updated_callback);
void FinalizeDigestOnBackground(
base::OnceCallback<void(const std::string&)> digest_finalized_callback);
// All the work related to validations.
void ValidateFile();
......@@ -219,13 +235,16 @@ class OfflinePageRequestJob : public net::URLRequestJob {
void DidOpenForValidation(int result);
void ReadForValidation();
void DidReadForValidation(int result);
void DidComputeActualDigest(const std::string& actual_digest);
void DidComputeActualDigestForValidation(const std::string& actual_digest);
void OnFileValidationDone(FileValidationResult result);
// All the work related to serving from the archive file.
void DidOpenForServing(int result);
void DidSeekForServing(int64_t result);
void DidReadForServing(scoped_refptr<net::IOBuffer> buf, int result);
void NotifyReadRawDataComplete(int result);
void DidComputeActualDigestForServing(int result,
const std::string& actual_digest);
std::unique_ptr<Delegate> delegate_;
......@@ -252,7 +271,6 @@ class OfflinePageRequestJob : public net::URLRequestJob {
// For the purpose of serving from the archive file.
base::FilePath file_path_;
std::unique_ptr<net::FileStream> stream_;
int64_t remaining_bytes_;
bool has_range_header_;
base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_;
......
......@@ -312,6 +312,11 @@ void OfflinePageTabHelper::SetOfflinePage(
provisional_offline_info_.is_showing_offline_preview = is_offline_preview;
}
void OfflinePageTabHelper::ClearOfflinePage() {
provisional_offline_info_.Clear();
offline_info_.Clear();
}
bool OfflinePageTabHelper::IsShowingTrustedOfflinePage() const {
return offline_info_.offline_page && offline_info_.is_trusted;
}
......
......@@ -36,6 +36,8 @@ class OfflinePageTabHelper :
bool is_trusted,
bool is_offline_preview);
void ClearOfflinePage();
const OfflinePageItem* offline_page() {
return offline_info_.offline_page.get();
}
......
......@@ -41,26 +41,27 @@ bool ParseOfflineHeaderValue(const std::string& header_value,
if (pos == std::string::npos)
return false;
std::string key = base::ToLowerASCII(pair.substr(0, pos));
std::string value = base::ToLowerASCII(pair.substr(pos + 1));
std::string value = pair.substr(pos + 1);
std::string lower_value = base::ToLowerASCII(value);
if (key == kOfflinePageHeaderPersistKey) {
if (value == "1")
if (lower_value == "1")
*need_to_persist = true;
else if (value == "0")
else if (lower_value == "0")
*need_to_persist = false;
else
return false;
} else if (key == kOfflinePageHeaderReasonKey) {
if (value == kOfflinePageHeaderReasonValueDueToNetError)
if (lower_value == kOfflinePageHeaderReasonValueDueToNetError)
*reason = OfflinePageHeader::Reason::NET_ERROR;
else if (value == kOfflinePageHeaderReasonValueFromDownload)
else if (lower_value == kOfflinePageHeaderReasonValueFromDownload)
*reason = OfflinePageHeader::Reason::DOWNLOAD;
else if (value == kOfflinePageHeaderReasonValueReload)
else if (lower_value == kOfflinePageHeaderReasonValueReload)
*reason = OfflinePageHeader::Reason::RELOAD;
else if (value == kOfflinePageHeaderReasonValueFromNotification)
else if (lower_value == kOfflinePageHeaderReasonValueFromNotification)
*reason = OfflinePageHeader::Reason::NOTIFICATION;
else if (value == kOfflinePageHeaderReasonFileUrlIntent)
else if (lower_value == kOfflinePageHeaderReasonFileUrlIntent)
*reason = OfflinePageHeader::Reason::FILE_URL_INTENT;
else if (value == kOfflinePageHeaderReasonContentUrlIntent)
else if (lower_value == kOfflinePageHeaderReasonContentUrlIntent)
*reason = OfflinePageHeader::Reason::CONTENT_URL_INTENT;
else
return false;
......
......@@ -124,22 +124,22 @@ TEST_F(OfflinePageHeaderTest, Parse) {
EXPECT_FALSE(ParseFromHeaderValue("intent_url=://foo/bar", &need_to_persist,
&reason, &id, &intent_url));
EXPECT_TRUE(ParseFromHeaderValue("intent_url=file://foo/bar",
EXPECT_TRUE(ParseFromHeaderValue("intent_url=file://foo/Bar",
&need_to_persist, &reason, &id,
&intent_url));
EXPECT_FALSE(need_to_persist);
EXPECT_EQ(OfflinePageHeader::Reason::NONE, reason);
EXPECT_EQ("", id);
EXPECT_EQ(GURL("file://foo/bar"), intent_url);
EXPECT_EQ(GURL("file://foo/Bar"), intent_url);
// Parse multiple fields.
EXPECT_TRUE(ParseFromHeaderValue(
"persist=1 reason=download id=a1b2 intent_url=file://foo/bar",
"persist=1 reason=download id=a1b2 intent_url=file://foo/Bar",
&need_to_persist, &reason, &id, &intent_url));
EXPECT_TRUE(need_to_persist);
EXPECT_EQ(OfflinePageHeader::Reason::DOWNLOAD, reason);
EXPECT_EQ("a1b2", id);
EXPECT_EQ(GURL("file://foo/bar"), intent_url);
EXPECT_EQ(GURL("file://foo/Bar"), intent_url);
}
TEST_F(OfflinePageHeaderTest, ToString) {
......@@ -147,10 +147,10 @@ TEST_F(OfflinePageHeaderTest, ToString) {
header.need_to_persist = true;
header.reason = OfflinePageHeader::Reason::DOWNLOAD;
header.id = "a1b2";
header.intent_url = GURL("file://foo/bar");
header.intent_url = GURL("file://foo/Bar");
EXPECT_EQ(
"X-Chrome-offline: persist=1 reason=download id=a1b2 "
"intent_url=file://foo/bar",
"intent_url=file://foo/Bar",
header.GetCompleteHeaderString());
}
......
......@@ -32126,6 +32126,9 @@ Called by update_net_trust_anchors.py.-->
<int value="4" label="CCT"/>
<int value="5" label="Clicking link"/>
<int value="6" label="Reloading page"/>
<int value="7" label="Clicking notification"/>
<int value="8" label="File URL intent"/>
<int value="9" label="Content URL intent"/>
</enum>
<enum name="OfflinePagesAggregatedRequestResult">
......@@ -57045,6 +57045,18 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>
<histogram name="OfflinePages.RequestJob.IntentDataChangedAfterValidation"
enum="BooleanChanged">
<owner>jianli@chromium.org</owner>
<summary>
Records whether the content read from intent URI (file:// or content://)
changed after the initial validation that was done to route the request when
the intent was received. This is recorded at the time that Offline Page
Request Handler tried to read the data, in preparation to show an offline
page to a user.
</summary>
</histogram>
<histogram name="OfflinePages.RequestJob.OpenFileErrorCode"
enum="NetErrorCodes">
<owner>jianli@chromium.org</owner>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment