| OLD | NEW |
| 1 // Copyright 2014 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 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h" | 5 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h" |
| 6 | 6 |
| 7 #include "chrome/browser/download/download_stats.h" | 7 #include "chrome/browser/download/download_stats.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | |
| 11 #include "chrome/browser/ui/location_bar/location_bar.h" | |
| 12 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 10 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 13 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" | 11 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" |
| 14 | 12 |
| 15 namespace { | 13 namespace { |
| 16 | 14 |
| 17 content::WebContents* GetWebContentsToUse( | 15 content::WebContents* GetWebContentsToUse( |
| 18 content::WebContents* web_contents) { | 16 content::WebContents* web_contents) { |
| 19 // If we're viewing the PDF in a MimeHandlerViewGuest, use its embedder | 17 // If we're viewing the PDF in a MimeHandlerViewGuest, use its embedder |
| 20 // WebContents. | 18 // WebContents. |
| 21 auto guest_view = | 19 auto guest_view = |
| 22 extensions::MimeHandlerViewGuest::FromWebContents(web_contents); | 20 extensions::MimeHandlerViewGuest::FromWebContents(web_contents); |
| 23 if (guest_view) | 21 if (guest_view) |
| 24 return guest_view->embedder_web_contents(); | 22 return guest_view->embedder_web_contents(); |
| 25 return web_contents; | 23 return web_contents; |
| 26 } | 24 } |
| 27 | 25 |
| 28 } // namespace | 26 } // namespace |
| 29 | 27 |
| 30 ChromePDFWebContentsHelperClient::ChromePDFWebContentsHelperClient() { | 28 ChromePDFWebContentsHelperClient::ChromePDFWebContentsHelperClient() { |
| 31 } | 29 } |
| 32 | 30 |
| 33 ChromePDFWebContentsHelperClient::~ChromePDFWebContentsHelperClient() { | 31 ChromePDFWebContentsHelperClient::~ChromePDFWebContentsHelperClient() { |
| 34 } | 32 } |
| 35 | 33 |
| 36 void ChromePDFWebContentsHelperClient::UpdateLocationBar( | |
| 37 content::WebContents* contents) { | |
| 38 Browser* browser = chrome::FindBrowserWithWebContents(contents); | |
| 39 if (!browser) | |
| 40 return; | |
| 41 | |
| 42 BrowserWindow* window = browser->window(); | |
| 43 if (!window) | |
| 44 return; | |
| 45 | |
| 46 LocationBar* location_bar = window->GetLocationBar(); | |
| 47 if (!location_bar) | |
| 48 return; | |
| 49 | |
| 50 location_bar->UpdateOpenPDFInReaderPrompt(); | |
| 51 } | |
| 52 | |
| 53 void ChromePDFWebContentsHelperClient::UpdateContentRestrictions( | 34 void ChromePDFWebContentsHelperClient::UpdateContentRestrictions( |
| 54 content::WebContents* contents, | 35 content::WebContents* contents, |
| 55 int content_restrictions) { | 36 int content_restrictions) { |
| 56 CoreTabHelper* core_tab_helper = | 37 CoreTabHelper* core_tab_helper = |
| 57 CoreTabHelper::FromWebContents(GetWebContentsToUse(contents)); | 38 CoreTabHelper::FromWebContents(GetWebContentsToUse(contents)); |
| 58 // |core_tab_helper| is NULL for WebViewGuest. | 39 // |core_tab_helper| is NULL for WebViewGuest. |
| 59 if (core_tab_helper) | 40 if (core_tab_helper) |
| 60 core_tab_helper->UpdateContentRestrictions(content_restrictions); | 41 core_tab_helper->UpdateContentRestrictions(content_restrictions); |
| 61 } | 42 } |
| 62 | 43 |
| 63 void ChromePDFWebContentsHelperClient::OnPDFHasUnsupportedFeature( | 44 void ChromePDFWebContentsHelperClient::OnPDFHasUnsupportedFeature( |
| 64 content::WebContents* contents) { | 45 content::WebContents* contents) { |
| 65 // There is no more Adobe pluging for PDF so there is not much we can do in | 46 // There is no more Adobe pluging for PDF so there is not much we can do in |
| 66 // this case. Maybe simply download the file. | 47 // this case. Maybe simply download the file. |
| 67 } | 48 } |
| 68 | 49 |
| 69 void ChromePDFWebContentsHelperClient::OnSaveURL( | 50 void ChromePDFWebContentsHelperClient::OnSaveURL( |
| 70 content::WebContents* contents) { | 51 content::WebContents* contents) { |
| 71 RecordDownloadSource(DOWNLOAD_INITIATED_BY_PDF_SAVE); | 52 RecordDownloadSource(DOWNLOAD_INITIATED_BY_PDF_SAVE); |
| 72 } | 53 } |
| OLD | NEW |