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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
7 #include "chrome/browser/download/download_stats.h"
8 #include "chrome/browser/ui/browser.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/pdf/pdf_unsupported_feature.h"
13 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
14 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
18 content::WebContents
* GetWebContentsToUse(
19 content::WebContents
* web_contents
) {
20 // If we're viewing the PDF in a MimeHandlerViewGuest, use its embedder
23 extensions::MimeHandlerViewGuest::FromWebContents(web_contents
);
25 return guest_view
->embedder_web_contents();
31 ChromePDFWebContentsHelperClient::ChromePDFWebContentsHelperClient() {
34 ChromePDFWebContentsHelperClient::~ChromePDFWebContentsHelperClient() {
37 void ChromePDFWebContentsHelperClient::UpdateLocationBar(
38 content::WebContents
* contents
) {
39 Browser
* browser
= chrome::FindBrowserWithWebContents(contents
);
43 BrowserWindow
* window
= browser
->window();
47 LocationBar
* location_bar
= window
->GetLocationBar();
51 location_bar
->UpdateOpenPDFInReaderPrompt();
54 void ChromePDFWebContentsHelperClient::UpdateContentRestrictions(
55 content::WebContents
* contents
,
56 int content_restrictions
) {
57 CoreTabHelper
* core_tab_helper
=
58 CoreTabHelper::FromWebContents(GetWebContentsToUse(contents
));
59 // |core_tab_helper| is NULL for WebViewGuest.
61 core_tab_helper
->UpdateContentRestrictions(content_restrictions
);
64 void ChromePDFWebContentsHelperClient::OnPDFHasUnsupportedFeature(
65 content::WebContents
* contents
) {
66 PDFHasUnsupportedFeature(GetWebContentsToUse(contents
));
69 void ChromePDFWebContentsHelperClient::OnSaveURL(
70 content::WebContents
* contents
) {
71 RecordDownloadSource(DOWNLOAD_INITIATED_BY_PDF_SAVE
);