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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_PDF_PDF_TAB_HELPER_H_ 6 #define CHROME_BROWSER_UI_PDF_PDF_TAB_HELPER_H_ 7 8 #include <string> 9 10 #include "base/callback.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_user_data.h" 14 #include "ipc/ipc_message.h" 15 16 class OpenPDFInReaderPromptDelegate; 17 18 namespace content { 19 class WebContents; 20 } 21 22 // Per-tab class to handle PDF messages. 23 class PDFTabHelper : public content::WebContentsObserver, 24 public content::WebContentsUserData<PDFTabHelper> { 25 public: 26 27 explicit PDFTabHelper(content::WebContents* web_contents); 28 virtual ~PDFTabHelper(); 29 30 OpenPDFInReaderPromptDelegate* open_in_reader_prompt() const { 31 return open_in_reader_prompt_.get(); 32 } 33 34 void ShowOpenInReaderPrompt(scoped_ptr<OpenPDFInReaderPromptDelegate> prompt); 35 36 private: 37 // content::WebContentsObserver overrides: 38 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 39 virtual void DidNavigateMainFrame( 40 const content::LoadCommittedDetails& details, 41 const content::FrameNavigateParams& params) OVERRIDE; 42 43 // Internal helpers ---------------------------------------------------------- 44 45 void UpdateLocationBar(); 46 void OnModalPromptForPasswordClosed(IPC::Message* reply_message, 47 bool success, 48 const base::string16& actual_value); 49 50 // Message handlers. 51 void OnHasUnsupportedFeature(); 52 void OnSaveURLAs(const GURL& url, 53 const content::Referrer& referrer); 54 void OnUpdateContentRestrictions(int content_restrictions); 55 void OnModalPromptForPassword(const std::string& prompt, 56 IPC::Message* reply_message); 57 58 // The model for the confirmation prompt to open a PDF in Adobe Reader. 59 scoped_ptr<OpenPDFInReaderPromptDelegate> open_in_reader_prompt_; 60 61 DISALLOW_COPY_AND_ASSIGN(PDFTabHelper); 62 }; 63 64 #if !defined(TOOLKIT_GTK) 65 typedef base::Callback<void(bool /* success */, 66 const base::string16& /* password */)> 67 PasswordDialogClosedCallback; 68 69 // Shows a tab-modal dialog to get a password for a PDF document. 70 void ShowPDFPasswordDialog(content::WebContents* web_contents, 71 const base::string16& prompt, 72 const PasswordDialogClosedCallback& callback); 73 #endif // !TOOLKIT_GTK 74 75 #endif // CHROME_BROWSER_UI_PDF_PDF_TAB_HELPER_H_ 76