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 "chrome/browser/download/download_util.h" |
7 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
9 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
10 #include "chrome/browser/ui/omnibox/location_bar.h" | 11 #include "chrome/browser/ui/omnibox/location_bar.h" |
11 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" | 12 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" |
12 #include "chrome/browser/ui/pdf/pdf_unsupported_feature.h" | 13 #include "chrome/browser/ui/pdf/pdf_unsupported_feature.h" |
| 14 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
13 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
14 #include "content/public/browser/navigation_details.h" | 16 #include "content/public/browser/navigation_details.h" |
15 | 17 |
16 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PDFTabHelper); | 18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PDFTabHelper); |
17 | 19 |
18 PDFTabHelper::PDFTabHelper(content::WebContents* web_contents) | 20 PDFTabHelper::PDFTabHelper(content::WebContents* web_contents) |
19 : content::WebContentsObserver(web_contents) { | 21 : content::WebContentsObserver(web_contents) { |
20 } | 22 } |
21 | 23 |
22 PDFTabHelper::~PDFTabHelper() { | 24 PDFTabHelper::~PDFTabHelper() { |
23 } | 25 } |
24 | 26 |
25 void PDFTabHelper::ShowOpenInReaderPrompt( | 27 void PDFTabHelper::ShowOpenInReaderPrompt( |
26 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt) { | 28 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt) { |
27 open_in_reader_prompt_ = prompt.Pass(); | 29 open_in_reader_prompt_ = prompt.Pass(); |
28 UpdateLocationBar(); | 30 UpdateLocationBar(); |
29 } | 31 } |
30 | 32 |
31 bool PDFTabHelper::OnMessageReceived(const IPC::Message& message) { | 33 bool PDFTabHelper::OnMessageReceived(const IPC::Message& message) { |
32 bool handled = true; | 34 bool handled = true; |
33 IPC_BEGIN_MESSAGE_MAP(PDFTabHelper, message) | 35 IPC_BEGIN_MESSAGE_MAP(PDFTabHelper, message) |
34 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature, | 36 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature, |
35 OnPDFHasUnsupportedFeature) | 37 OnHasUnsupportedFeature) |
| 38 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFSaveURLAs, OnSaveURLAs) |
| 39 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFUpdateContentRestrictions, |
| 40 OnUpdateContentRestrictions) |
36 IPC_MESSAGE_UNHANDLED(handled = false) | 41 IPC_MESSAGE_UNHANDLED(handled = false) |
37 IPC_END_MESSAGE_MAP() | 42 IPC_END_MESSAGE_MAP() |
38 return handled; | 43 return handled; |
39 } | 44 } |
40 | 45 |
41 void PDFTabHelper::DidNavigateMainFrame( | 46 void PDFTabHelper::DidNavigateMainFrame( |
42 const content::LoadCommittedDetails& details, | 47 const content::LoadCommittedDetails& details, |
43 const content::FrameNavigateParams& params) { | 48 const content::FrameNavigateParams& params) { |
44 if (open_in_reader_prompt_.get() && | 49 if (open_in_reader_prompt_.get() && |
45 open_in_reader_prompt_->ShouldExpire(details)) { | 50 open_in_reader_prompt_->ShouldExpire(details)) { |
(...skipping 11 matching lines...) Expand all Loading... |
57 if (!window) | 62 if (!window) |
58 return; | 63 return; |
59 | 64 |
60 LocationBar* location_bar = window->GetLocationBar(); | 65 LocationBar* location_bar = window->GetLocationBar(); |
61 if (!location_bar) | 66 if (!location_bar) |
62 return; | 67 return; |
63 | 68 |
64 location_bar->UpdateOpenPDFInReaderPrompt(); | 69 location_bar->UpdateOpenPDFInReaderPrompt(); |
65 } | 70 } |
66 | 71 |
67 void PDFTabHelper::OnPDFHasUnsupportedFeature() { | 72 void PDFTabHelper::OnHasUnsupportedFeature() { |
68 PDFHasUnsupportedFeature(web_contents()); | 73 PDFHasUnsupportedFeature(web_contents()); |
69 } | 74 } |
| 75 |
| 76 void PDFTabHelper::OnSaveURLAs(const GURL& url, |
| 77 const content::Referrer& referrer) { |
| 78 download_util::RecordDownloadSource(download_util::INITIATED_BY_PDF_SAVE); |
| 79 web_contents()->SaveFrame(url, referrer); |
| 80 } |
| 81 |
| 82 void PDFTabHelper::OnUpdateContentRestrictions(int content_restrictions) { |
| 83 CoreTabHelper* core_tab_helper = |
| 84 CoreTabHelper::FromWebContents(web_contents()); |
| 85 core_tab_helper->UpdateContentRestrictions(content_restrictions); |
| 86 } |
OLD | NEW |