| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" | 5 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/download/download_stats.h" | 8 #include "chrome/browser/download/download_stats.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/location_bar/location_bar.h" | 12 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 13 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" | 13 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" |
| 14 #include "chrome/browser/ui/pdf/pdf_unsupported_feature.h" | 14 #include "chrome/browser/ui/pdf/pdf_unsupported_feature.h" |
| 15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 16 #include "chrome/common/render_messages.h" | 16 #include "components/pdf/common/pdf_messages.h" |
| 17 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
| 18 | 18 |
| 19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PDFTabHelper); | 19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PDFTabHelper); |
| 20 | 20 |
| 21 PDFTabHelper::PDFTabHelper(content::WebContents* web_contents) | 21 PDFTabHelper::PDFTabHelper(content::WebContents* web_contents) |
| 22 : content::WebContentsObserver(web_contents) { | 22 : content::WebContentsObserver(web_contents) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 PDFTabHelper::~PDFTabHelper() { | 25 PDFTabHelper::~PDFTabHelper() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 void PDFTabHelper::ShowOpenInReaderPrompt( | 28 void PDFTabHelper::ShowOpenInReaderPrompt( |
| 29 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt) { | 29 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt) { |
| 30 open_in_reader_prompt_ = prompt.Pass(); | 30 open_in_reader_prompt_ = prompt.Pass(); |
| 31 UpdateLocationBar(); | 31 UpdateLocationBar(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool PDFTabHelper::OnMessageReceived(const IPC::Message& message) { | 34 bool PDFTabHelper::OnMessageReceived(const IPC::Message& message) { |
| 35 bool handled = true; | 35 bool handled = true; |
| 36 IPC_BEGIN_MESSAGE_MAP(PDFTabHelper, message) | 36 IPC_BEGIN_MESSAGE_MAP(PDFTabHelper, message) |
| 37 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature, | 37 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFHasUnsupportedFeature, |
| 38 OnHasUnsupportedFeature) | 38 OnHasUnsupportedFeature) |
| 39 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFSaveURLAs, OnSaveURLAs) | 39 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnSaveURLAs) |
| 40 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFUpdateContentRestrictions, | 40 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFUpdateContentRestrictions, |
| 41 OnUpdateContentRestrictions) | 41 OnUpdateContentRestrictions) |
| 42 IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_PDFModalPromptForPassword, | 42 IPC_MESSAGE_HANDLER_DELAY_REPLY(PDFHostMsg_PDFModalPromptForPassword, |
| 43 OnModalPromptForPassword) | 43 OnModalPromptForPassword) |
| 44 IPC_MESSAGE_UNHANDLED(handled = false) | 44 IPC_MESSAGE_UNHANDLED(handled = false) |
| 45 IPC_END_MESSAGE_MAP() | 45 IPC_END_MESSAGE_MAP() |
| 46 return handled; | 46 return handled; |
| 47 } | 47 } |
| 48 | 48 |
| 49 void PDFTabHelper::DidNavigateMainFrame( | 49 void PDFTabHelper::DidNavigateMainFrame( |
| 50 const content::LoadCommittedDetails& details, | 50 const content::LoadCommittedDetails& details, |
| 51 const content::FrameNavigateParams& params) { | 51 const content::FrameNavigateParams& params) { |
| 52 if (open_in_reader_prompt_.get() && | 52 if (open_in_reader_prompt_.get() && |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 CoreTabHelper::FromWebContents(web_contents()); | 87 CoreTabHelper::FromWebContents(web_contents()); |
| 88 // |core_tab_helper| is NULL for WebViewGuest. | 88 // |core_tab_helper| is NULL for WebViewGuest. |
| 89 if (core_tab_helper) | 89 if (core_tab_helper) |
| 90 core_tab_helper->UpdateContentRestrictions(content_restrictions); | 90 core_tab_helper->UpdateContentRestrictions(content_restrictions); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void PDFTabHelper::OnModalPromptForPasswordClosed( | 93 void PDFTabHelper::OnModalPromptForPasswordClosed( |
| 94 IPC::Message* reply_message, | 94 IPC::Message* reply_message, |
| 95 bool success, | 95 bool success, |
| 96 const base::string16& actual_value) { | 96 const base::string16& actual_value) { |
| 97 ChromeViewHostMsg_PDFModalPromptForPassword::WriteReplyParams( | 97 PDFHostMsg_PDFModalPromptForPassword::WriteReplyParams( |
| 98 reply_message, base::UTF16ToUTF8(actual_value)); | 98 reply_message, base::UTF16ToUTF8(actual_value)); |
| 99 Send(reply_message); | 99 Send(reply_message); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void PDFTabHelper::OnModalPromptForPassword(const std::string& prompt, | 102 void PDFTabHelper::OnModalPromptForPassword(const std::string& prompt, |
| 103 IPC::Message* reply_message) { | 103 IPC::Message* reply_message) { |
| 104 base::Callback<void(bool, const base::string16&)> callback = | 104 base::Callback<void(bool, const base::string16&)> callback = |
| 105 base::Bind(&PDFTabHelper::OnModalPromptForPasswordClosed, | 105 base::Bind(&PDFTabHelper::OnModalPromptForPasswordClosed, |
| 106 base::Unretained(this), reply_message); | 106 base::Unretained(this), reply_message); |
| 107 ShowPDFPasswordDialog(web_contents(), base::UTF8ToUTF16(prompt), callback); | 107 ShowPDFPasswordDialog(web_contents(), base::UTF8ToUTF16(prompt), callback); |
| 108 } | 108 } |
| OLD | NEW |