Index: components/pdf/browser/pdf_tab_helper.cc |
diff --git a/components/pdf/browser/pdf_tab_helper.cc b/components/pdf/browser/pdf_tab_helper.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..aca6d7b96d625a30379b6b967aa36d36b3e7653a |
--- /dev/null |
+++ b/components/pdf/browser/pdf_tab_helper.cc |
@@ -0,0 +1,104 @@ |
+// Copyright 2014 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_tab_helper.h" |
+ |
+#include "base/bind.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "components/pdf/browser/open_pdf_in_reader_prompt_delegate.h" |
+#include "components/pdf/browser/pdf_tab_helper_delegate.h" |
+#include "components/pdf/common/pdf_messages.h" |
+#include "content/public/browser/navigation_details.h" |
+ |
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFTabHelper); |
+ |
+namespace pdf { |
+ |
+PDFTabHelper::PDFTabHelper(content::WebContents* web_contents, |
+ scoped_ptr<PDFTabHelperDelegate> delegate) |
+ : content::WebContentsObserver(web_contents), delegate_(delegate.Pass()) { |
+} |
+ |
+PDFTabHelper::~PDFTabHelper() { |
+} |
+ |
+void PDFTabHelper::ShowOpenInReaderPrompt( |
+ scoped_ptr<OpenPDFInReaderPromptDelegate> prompt) { |
+ open_in_reader_prompt_ = prompt.Pass(); |
+ UpdateLocationBar(); |
+} |
+ |
+bool PDFTabHelper::OnMessageReceived(const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(PDFTabHelper, message) |
+ IPC_MESSAGE_HANDLER(PDFHostMsg_PDFHasUnsupportedFeature, |
Lei Zhang
2014/08/26 22:41:30
nit: indent?
sadrul
2014/08/27 00:09:52
Done. (I blame 'git cl format'!)
|
+ OnHasUnsupportedFeature) |
+ IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnSaveURLAs) |
+ IPC_MESSAGE_HANDLER(PDFHostMsg_PDFUpdateContentRestrictions, |
+ OnUpdateContentRestrictions) |
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(PDFHostMsg_PDFModalPromptForPassword, |
+ OnModalPromptForPassword) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void PDFTabHelper::DidNavigateMainFrame( |
+ const content::LoadCommittedDetails& details, |
+ const content::FrameNavigateParams& params) { |
+ if (open_in_reader_prompt_.get() && |
+ open_in_reader_prompt_->ShouldExpire(details)) { |
+ open_in_reader_prompt_.reset(); |
+ UpdateLocationBar(); |
+ } |
+} |
+ |
+void PDFTabHelper::UpdateLocationBar() { |
+ delegate_->UpdateLocationBar(web_contents()); |
+} |
+ |
+void PDFTabHelper::OnHasUnsupportedFeature() { |
+ delegate_->OnPDFHasUnsupportedFeature(web_contents()); |
+} |
+ |
+void PDFTabHelper::OnSaveURLAs(const GURL& url, |
+ const content::Referrer& referrer) { |
+ delegate_->OnSaveURL(web_contents()); |
+ web_contents()->SaveFrame(url, referrer); |
+} |
+ |
+void PDFTabHelper::OnUpdateContentRestrictions(int content_restrictions) { |
+ delegate_->UpdateContentRestrictions(web_contents(), content_restrictions); |
+} |
+ |
+void PDFTabHelper::OnModalPromptForPasswordClosed( |
+ IPC::Message* reply_message, |
+ bool success, |
+ const base::string16& actual_value) { |
+ PDFHostMsg_PDFModalPromptForPassword::WriteReplyParams( |
+ reply_message, base::UTF16ToUTF8(actual_value)); |
+ Send(reply_message); |
+} |
+ |
+void PDFTabHelper::OnModalPromptForPassword(const std::string& prompt, |
+ IPC::Message* reply_message) { |
+ base::Callback<void(bool, const base::string16&)> callback = |
+ base::Bind(&PDFTabHelper::OnModalPromptForPasswordClosed, |
+ base::Unretained(this), |
+ reply_message); |
+ delegate_->OnShowPDFPasswordDialog( |
+ web_contents(), base::UTF8ToUTF16(prompt), callback); |
+} |
+ |
+// static |
+void PDFTabHelper::CreateForWebContentsWithDelegate( |
+ content::WebContents* contents, |
+ scoped_ptr<PDFTabHelperDelegate> delegate) { |
+ if (FromWebContents(contents)) |
+ return; |
+ contents->SetUserData(UserDataKey(), |
+ new PDFTabHelper(contents, delegate.Pass())); |
+} |
+ |
+} // namespace pdf |