Commit 88d96e66 authored by rockot's avatar rockot Committed by Commit bot

Content verification: Don't fail on non-existence.

This prevents content verification (when active) from disabling
an extension when the extension attempts to load a non-existent
resource in its own chrome-extension URL space.

BUG=404802

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

Cr-Commit-Position: refs/heads/master@{#292095}
parent be8f40e6
......@@ -35,6 +35,7 @@ ContentHashReader::ContentHashReader(const std::string& extension_id,
relative_path_(relative_path),
key_(key),
status_(NOT_INITIALIZED),
content_exists_(false),
have_verified_contents_(false),
have_computed_hashes_(false),
block_size_(0) {
......@@ -50,6 +51,13 @@ bool ContentHashReader::Init() {
base::FilePath verified_contents_path =
file_util::GetVerifiedContentsPath(extension_root_);
// Check that this is a valid resource to verify (i.e., it exists).
base::FilePath content_path = extension_root_.Append(relative_path_);
if (!base::PathExists(content_path))
return false;
content_exists_ = true;
if (!base::PathExists(verified_contents_path))
return false;
......
......@@ -40,11 +40,15 @@ class ContentHashReader : public base::RefCountedThreadSafe<ContentHashReader> {
// should likely be discarded.
bool Init();
// Indicates whether the content in question exists in the local extension
// installation. This may be |false| if Init fails.
bool content_exists() const { return content_exists_; }
// These return whether we found valid verified_contents.json /
// computed_hashes.json files respectively. Note that both of these can be
// true but we still didn't find an entry for |relative_path_| in them.
bool have_verified_contents() { return have_verified_contents_; }
bool have_computed_hashes() { return have_computed_hashes_; }
bool have_verified_contents() const { return have_verified_contents_; }
bool have_computed_hashes() const { return have_computed_hashes_; }
// Return the number of blocks and block size, respectively. Only valid after
// calling Init().
......@@ -69,6 +73,8 @@ class ContentHashReader : public base::RefCountedThreadSafe<ContentHashReader> {
InitStatus status_;
bool content_exists_;
bool have_verified_contents_;
bool have_computed_hashes_;
......
......@@ -152,11 +152,15 @@ bool ContentVerifyJob::FinishBlock() {
void ContentVerifyJob::OnHashesReady(bool success) {
if (!success && !g_test_delegate) {
if (hash_reader_->have_verified_contents() &&
hash_reader_->have_computed_hashes())
if (!hash_reader_->content_exists()) {
// Ignore verification of non-existent resources.
return;
} else if (hash_reader_->have_verified_contents() &&
hash_reader_->have_computed_hashes()) {
DispatchFailureCallback(NO_HASHES_FOR_FILE);
else
} else {
DispatchFailureCallback(MISSING_ALL_HASHES);
}
return;
}
......
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