Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_PDF_PDF_TAB_HELPER_H_ | 5 #ifndef COMPONENTS_PDF_BROWSER_PDF_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_UI_PDF_PDF_TAB_HELPER_H_ | 6 #define COMPONENTS_PDF_BROWSER_PDF_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
| 13 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
| 14 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
| 15 | 15 |
| 16 class OpenPDFInReaderPromptDelegate; | |
| 17 | |
| 18 namespace content { | 16 namespace content { |
| 19 class WebContents; | 17 class WebContents; |
| 20 } | 18 } |
| 21 | 19 |
| 22 // Per-tab class to handle PDF messages. | 20 namespace pdf { |
| 21 | |
| 22 class OpenPDFInReaderPromptDelegate; | |
| 23 class PDFTabHelperDelegate; | |
| 24 | |
| 25 // Per-WebContents class to handle PDF messages. | |
| 23 class PDFTabHelper : public content::WebContentsObserver, | 26 class PDFTabHelper : public content::WebContentsObserver, |
|
blundell
2014/08/27 09:12:32
optional nit: PDFTabHelper might not be the approp
sadrul
2014/08/27 11:49:57
Happy to rename. What would you suggest? PDFWebCon
| |
| 24 public content::WebContentsUserData<PDFTabHelper> { | 27 public content::WebContentsUserData<PDFTabHelper> { |
| 25 public: | 28 public: |
| 26 | 29 static void CreateForWebContentsWithDelegate( |
| 27 explicit PDFTabHelper(content::WebContents* web_contents); | 30 content::WebContents* contents, |
| 28 virtual ~PDFTabHelper(); | 31 scoped_ptr<PDFTabHelperDelegate> delegate); |
| 29 | 32 |
| 30 OpenPDFInReaderPromptDelegate* open_in_reader_prompt() const { | 33 OpenPDFInReaderPromptDelegate* open_in_reader_prompt() const { |
| 31 return open_in_reader_prompt_.get(); | 34 return open_in_reader_prompt_.get(); |
| 32 } | 35 } |
| 33 | 36 |
| 34 void ShowOpenInReaderPrompt(scoped_ptr<OpenPDFInReaderPromptDelegate> prompt); | 37 void ShowOpenInReaderPrompt(scoped_ptr<OpenPDFInReaderPromptDelegate> prompt); |
| 35 | 38 |
| 36 private: | 39 private: |
| 40 PDFTabHelper(content::WebContents* web_contents, | |
| 41 scoped_ptr<PDFTabHelperDelegate> delegate); | |
| 42 virtual ~PDFTabHelper(); | |
| 43 | |
| 37 // content::WebContentsObserver overrides: | 44 // content::WebContentsObserver overrides: |
| 38 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 45 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 39 virtual void DidNavigateMainFrame( | 46 virtual void DidNavigateMainFrame( |
| 40 const content::LoadCommittedDetails& details, | 47 const content::LoadCommittedDetails& details, |
| 41 const content::FrameNavigateParams& params) OVERRIDE; | 48 const content::FrameNavigateParams& params) OVERRIDE; |
| 42 | 49 |
| 43 // Internal helpers ---------------------------------------------------------- | 50 // Internal helpers ---------------------------------------------------------- |
| 44 | 51 |
| 45 void UpdateLocationBar(); | 52 void UpdateLocationBar(); |
| 46 void OnModalPromptForPasswordClosed(IPC::Message* reply_message, | 53 void OnModalPromptForPasswordClosed(IPC::Message* reply_message, |
| 47 bool success, | 54 bool success, |
| 48 const base::string16& actual_value); | 55 const base::string16& actual_value); |
| 49 | 56 |
| 50 // Message handlers. | 57 // Message handlers. |
| 51 void OnHasUnsupportedFeature(); | 58 void OnHasUnsupportedFeature(); |
| 52 void OnSaveURLAs(const GURL& url, | 59 void OnSaveURLAs(const GURL& url, const content::Referrer& referrer); |
| 53 const content::Referrer& referrer); | |
| 54 void OnUpdateContentRestrictions(int content_restrictions); | 60 void OnUpdateContentRestrictions(int content_restrictions); |
| 55 void OnModalPromptForPassword(const std::string& prompt, | 61 void OnModalPromptForPassword(const std::string& prompt, |
| 56 IPC::Message* reply_message); | 62 IPC::Message* reply_message); |
| 57 | 63 |
| 58 // The model for the confirmation prompt to open a PDF in Adobe Reader. | 64 // The model for the confirmation prompt to open a PDF in Adobe Reader. |
| 59 scoped_ptr<OpenPDFInReaderPromptDelegate> open_in_reader_prompt_; | 65 scoped_ptr<OpenPDFInReaderPromptDelegate> open_in_reader_prompt_; |
| 66 scoped_ptr<PDFTabHelperDelegate> delegate_; | |
| 60 | 67 |
| 61 DISALLOW_COPY_AND_ASSIGN(PDFTabHelper); | 68 DISALLOW_COPY_AND_ASSIGN(PDFTabHelper); |
| 62 }; | 69 }; |
| 63 | 70 |
| 64 typedef base::Callback<void(bool /* success */, | 71 } // namespace pdf |
| 65 const base::string16& /* password */)> | |
| 66 PasswordDialogClosedCallback; | |
| 67 | 72 |
| 68 // Shows a tab-modal dialog to get a password for a PDF document. | 73 #endif // COMPONENTS_PDF_BROWSER_PDF_TAB_HELPER_H_ |
| 69 void ShowPDFPasswordDialog(content::WebContents* web_contents, | |
| 70 const base::string16& prompt, | |
| 71 const PasswordDialogClosedCallback& callback); | |
| 72 | |
| 73 #endif // CHROME_BROWSER_UI_PDF_PDF_TAB_HELPER_H_ | |
| OLD | NEW |