Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/pdf/browser/pdf_tab_helper.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "components/pdf/browser/open_pdf_in_reader_prompt_delegate.h" | |
| 10 #include "components/pdf/browser/pdf_tab_helper_delegate.h" | |
| 11 #include "components/pdf/common/pdf_messages.h" | |
| 12 #include "content/public/browser/navigation_details.h" | |
| 13 | |
| 14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFTabHelper); | |
| 15 | |
| 16 namespace pdf { | |
| 17 | |
| 18 PDFTabHelper::PDFTabHelper(content::WebContents* web_contents, | |
| 19 scoped_ptr<PDFTabHelperDelegate> delegate) | |
| 20 : content::WebContentsObserver(web_contents), delegate_(delegate.Pass()) { | |
| 21 } | |
| 22 | |
| 23 PDFTabHelper::~PDFTabHelper() { | |
| 24 } | |
| 25 | |
| 26 void PDFTabHelper::ShowOpenInReaderPrompt( | |
| 27 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt) { | |
| 28 open_in_reader_prompt_ = prompt.Pass(); | |
| 29 UpdateLocationBar(); | |
| 30 } | |
| 31 | |
| 32 bool PDFTabHelper::OnMessageReceived(const IPC::Message& message) { | |
| 33 bool handled = true; | |
| 34 IPC_BEGIN_MESSAGE_MAP(PDFTabHelper, message) | |
| 35 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'!)
| |
| 36 OnHasUnsupportedFeature) | |
| 37 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnSaveURLAs) | |
| 38 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFUpdateContentRestrictions, | |
| 39 OnUpdateContentRestrictions) | |
| 40 IPC_MESSAGE_HANDLER_DELAY_REPLY(PDFHostMsg_PDFModalPromptForPassword, | |
| 41 OnModalPromptForPassword) | |
| 42 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 43 IPC_END_MESSAGE_MAP() | |
| 44 return handled; | |
| 45 } | |
| 46 | |
| 47 void PDFTabHelper::DidNavigateMainFrame( | |
| 48 const content::LoadCommittedDetails& details, | |
| 49 const content::FrameNavigateParams& params) { | |
| 50 if (open_in_reader_prompt_.get() && | |
| 51 open_in_reader_prompt_->ShouldExpire(details)) { | |
| 52 open_in_reader_prompt_.reset(); | |
| 53 UpdateLocationBar(); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 void PDFTabHelper::UpdateLocationBar() { | |
| 58 delegate_->UpdateLocationBar(web_contents()); | |
| 59 } | |
| 60 | |
| 61 void PDFTabHelper::OnHasUnsupportedFeature() { | |
| 62 delegate_->OnPDFHasUnsupportedFeature(web_contents()); | |
| 63 } | |
| 64 | |
| 65 void PDFTabHelper::OnSaveURLAs(const GURL& url, | |
| 66 const content::Referrer& referrer) { | |
| 67 delegate_->OnSaveURL(web_contents()); | |
| 68 web_contents()->SaveFrame(url, referrer); | |
| 69 } | |
| 70 | |
| 71 void PDFTabHelper::OnUpdateContentRestrictions(int content_restrictions) { | |
| 72 delegate_->UpdateContentRestrictions(web_contents(), content_restrictions); | |
| 73 } | |
| 74 | |
| 75 void PDFTabHelper::OnModalPromptForPasswordClosed( | |
| 76 IPC::Message* reply_message, | |
| 77 bool success, | |
| 78 const base::string16& actual_value) { | |
| 79 PDFHostMsg_PDFModalPromptForPassword::WriteReplyParams( | |
| 80 reply_message, base::UTF16ToUTF8(actual_value)); | |
| 81 Send(reply_message); | |
| 82 } | |
| 83 | |
| 84 void PDFTabHelper::OnModalPromptForPassword(const std::string& prompt, | |
| 85 IPC::Message* reply_message) { | |
| 86 base::Callback<void(bool, const base::string16&)> callback = | |
| 87 base::Bind(&PDFTabHelper::OnModalPromptForPasswordClosed, | |
| 88 base::Unretained(this), | |
| 89 reply_message); | |
| 90 delegate_->OnShowPDFPasswordDialog( | |
| 91 web_contents(), base::UTF8ToUTF16(prompt), callback); | |
| 92 } | |
| 93 | |
| 94 // static | |
| 95 void PDFTabHelper::CreateForWebContentsWithDelegate( | |
| 96 content::WebContents* contents, | |
| 97 scoped_ptr<PDFTabHelperDelegate> delegate) { | |
| 98 if (FromWebContents(contents)) | |
| 99 return; | |
| 100 contents->SetUserData(UserDataKey(), | |
| 101 new PDFTabHelper(contents, delegate.Pass())); | |
| 102 } | |
| 103 | |
| 104 } // namespace pdf | |
| OLD | NEW |