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 #ifndef CHROME_BROWSER_UI_PDF_PDF_TAB_HELPER_H_ | 5 #ifndef COMPONENTS_PDF_BROWSER_PDF_WEB_CONTENTS_HELPER_H_ |
6 #define CHROME_BROWSER_UI_PDF_PDF_TAB_HELPER_H_ | 6 #define COMPONENTS_PDF_BROWSER_PDF_WEB_CONTENTS_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 { |
23 class PDFTabHelper : public content::WebContentsObserver, | 21 |
24 public content::WebContentsUserData<PDFTabHelper> { | 22 class OpenPDFInReaderPromptClient; |
| 23 class PDFWebContentsHelperClient; |
| 24 |
| 25 // Per-WebContents class to handle PDF messages. |
| 26 class PDFWebContentsHelper |
| 27 : public content::WebContentsObserver, |
| 28 public content::WebContentsUserData<PDFWebContentsHelper> { |
25 public: | 29 public: |
| 30 static void CreateForWebContentsWithClient( |
| 31 content::WebContents* contents, |
| 32 scoped_ptr<PDFWebContentsHelperClient> client); |
26 | 33 |
27 explicit PDFTabHelper(content::WebContents* web_contents); | 34 OpenPDFInReaderPromptClient* open_in_reader_prompt() const { |
28 virtual ~PDFTabHelper(); | |
29 | |
30 OpenPDFInReaderPromptDelegate* open_in_reader_prompt() const { | |
31 return open_in_reader_prompt_.get(); | 35 return open_in_reader_prompt_.get(); |
32 } | 36 } |
33 | 37 |
34 void ShowOpenInReaderPrompt(scoped_ptr<OpenPDFInReaderPromptDelegate> prompt); | 38 void ShowOpenInReaderPrompt(scoped_ptr<OpenPDFInReaderPromptClient> prompt); |
35 | 39 |
36 private: | 40 private: |
| 41 PDFWebContentsHelper(content::WebContents* web_contents, |
| 42 scoped_ptr<PDFWebContentsHelperClient> client); |
| 43 virtual ~PDFWebContentsHelper(); |
| 44 |
37 // content::WebContentsObserver overrides: | 45 // content::WebContentsObserver overrides: |
38 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 46 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
39 virtual void DidNavigateMainFrame( | 47 virtual void DidNavigateMainFrame( |
40 const content::LoadCommittedDetails& details, | 48 const content::LoadCommittedDetails& details, |
41 const content::FrameNavigateParams& params) OVERRIDE; | 49 const content::FrameNavigateParams& params) OVERRIDE; |
42 | 50 |
43 // Internal helpers ---------------------------------------------------------- | 51 // Internal helpers ---------------------------------------------------------- |
44 | 52 |
45 void UpdateLocationBar(); | 53 void UpdateLocationBar(); |
46 void OnModalPromptForPasswordClosed(IPC::Message* reply_message, | 54 void OnModalPromptForPasswordClosed(IPC::Message* reply_message, |
47 bool success, | 55 bool success, |
48 const base::string16& actual_value); | 56 const base::string16& actual_value); |
49 | 57 |
50 // Message handlers. | 58 // Message handlers. |
51 void OnHasUnsupportedFeature(); | 59 void OnHasUnsupportedFeature(); |
52 void OnSaveURLAs(const GURL& url, | 60 void OnSaveURLAs(const GURL& url, const content::Referrer& referrer); |
53 const content::Referrer& referrer); | |
54 void OnUpdateContentRestrictions(int content_restrictions); | 61 void OnUpdateContentRestrictions(int content_restrictions); |
55 void OnModalPromptForPassword(const std::string& prompt, | 62 void OnModalPromptForPassword(const std::string& prompt, |
56 IPC::Message* reply_message); | 63 IPC::Message* reply_message); |
57 | 64 |
58 // The model for the confirmation prompt to open a PDF in Adobe Reader. | 65 // The model for the confirmation prompt to open a PDF in Adobe Reader. |
59 scoped_ptr<OpenPDFInReaderPromptDelegate> open_in_reader_prompt_; | 66 scoped_ptr<OpenPDFInReaderPromptClient> open_in_reader_prompt_; |
| 67 scoped_ptr<PDFWebContentsHelperClient> client_; |
60 | 68 |
61 DISALLOW_COPY_AND_ASSIGN(PDFTabHelper); | 69 DISALLOW_COPY_AND_ASSIGN(PDFWebContentsHelper); |
62 }; | 70 }; |
63 | 71 |
64 typedef base::Callback<void(bool /* success */, | 72 } // namespace pdf |
65 const base::string16& /* password */)> | |
66 PasswordDialogClosedCallback; | |
67 | 73 |
68 // Shows a tab-modal dialog to get a password for a PDF document. | 74 #endif // COMPONENTS_PDF_BROWSER_PDF_WEB_CONTENTS_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 |