Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / pdf / chrome_pdf_web_contents_helper_client.cc
blobf0c165bd6d07b53d754ed9bd9e3d5cf9855fc16e
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"
16 namespace {
18 content::WebContents* GetWebContentsToUse(
19 content::WebContents* web_contents) {
20 // If we're viewing the PDF in a MimeHandlerViewGuest, use its embedder
21 // WebContents.
22 auto guest_view =
23 extensions::MimeHandlerViewGuest::FromWebContents(web_contents);
24 if (guest_view)
25 return guest_view->embedder_web_contents();
26 return web_contents;
29 } // namespace
31 ChromePDFWebContentsHelperClient::ChromePDFWebContentsHelperClient() {
34 ChromePDFWebContentsHelperClient::~ChromePDFWebContentsHelperClient() {
37 void ChromePDFWebContentsHelperClient::UpdateLocationBar(
38 content::WebContents* contents) {
39 Browser* browser = chrome::FindBrowserWithWebContents(contents);
40 if (!browser)
41 return;
43 BrowserWindow* window = browser->window();
44 if (!window)
45 return;
47 LocationBar* location_bar = window->GetLocationBar();
48 if (!location_bar)
49 return;
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.
60 if (core_tab_helper)
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);