blob: e425338678771061207216a310fe8f6df4a5dc43 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/pdf/browser/pdf_web_contents_helper.h"
#include <utility>
#include "base/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "components/pdf/browser/pdf_web_contents_helper_client.h"
#include "components/pdf/common/pdf_messages.h"
DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFWebContentsHelper);
namespace pdf {
// static
void PDFWebContentsHelper::CreateForWebContentsWithClient(
content::WebContents* contents,
std::unique_ptr<PDFWebContentsHelperClient> client) {
if (FromWebContents(contents))
return;
contents->SetUserData(UserDataKey(),
new PDFWebContentsHelper(contents, std::move(client)));
}
PDFWebContentsHelper::PDFWebContentsHelper(
content::WebContents* web_contents,
std::unique_ptr<PDFWebContentsHelperClient> client)
: content::WebContentsObserver(web_contents), client_(std::move(client)) {}
PDFWebContentsHelper::~PDFWebContentsHelper() {
}
bool PDFWebContentsHelper::OnMessageReceived(
const IPC::Message& message,
content::RenderFrameHost* render_frame_host) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PDFWebContentsHelper, message)
IPC_MESSAGE_HANDLER(PDFHostMsg_PDFHasUnsupportedFeature,
OnHasUnsupportedFeature)
IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnSaveURLAs)
IPC_MESSAGE_HANDLER(PDFHostMsg_PDFUpdateContentRestrictions,
OnUpdateContentRestrictions)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void PDFWebContentsHelper::OnHasUnsupportedFeature() {
client_->OnPDFHasUnsupportedFeature(web_contents());
}
void PDFWebContentsHelper::OnSaveURLAs(const GURL& url,
const content::Referrer& referrer) {
client_->OnSaveURL(web_contents());
web_contents()->SaveFrame(url, referrer);
}
void PDFWebContentsHelper::OnUpdateContentRestrictions(
int content_restrictions) {
client_->UpdateContentRestrictions(web_contents(), content_restrictions);
}
} // namespace pdf