Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: chrome/browser/ui/pdf/pdf_tab_helper.cc

Issue 477263003: pdf: Create a separate component for using the pdf pepper plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/pdf/pdf_tab_helper.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/download/download_stats.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/location_bar/location_bar.h"
13 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h"
14 #include "chrome/browser/ui/pdf/pdf_unsupported_feature.h"
15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
16 #include "chrome/common/render_messages.h"
17 #include "content/public/browser/navigation_details.h"
18
19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PDFTabHelper);
20
21 PDFTabHelper::PDFTabHelper(content::WebContents* web_contents)
22 : content::WebContentsObserver(web_contents) {
23 }
24
25 PDFTabHelper::~PDFTabHelper() {
26 }
27
28 void PDFTabHelper::ShowOpenInReaderPrompt(
29 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt) {
30 open_in_reader_prompt_ = prompt.Pass();
31 UpdateLocationBar();
32 }
33
34 bool PDFTabHelper::OnMessageReceived(const IPC::Message& message) {
35 bool handled = true;
36 IPC_BEGIN_MESSAGE_MAP(PDFTabHelper, message)
37 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature,
38 OnHasUnsupportedFeature)
39 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFSaveURLAs, OnSaveURLAs)
40 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFUpdateContentRestrictions,
41 OnUpdateContentRestrictions)
42 IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_PDFModalPromptForPassword,
43 OnModalPromptForPassword)
44 IPC_MESSAGE_UNHANDLED(handled = false)
45 IPC_END_MESSAGE_MAP()
46 return handled;
47 }
48
49 void PDFTabHelper::DidNavigateMainFrame(
50 const content::LoadCommittedDetails& details,
51 const content::FrameNavigateParams& params) {
52 if (open_in_reader_prompt_.get() &&
53 open_in_reader_prompt_->ShouldExpire(details)) {
54 open_in_reader_prompt_.reset();
55 UpdateLocationBar();
56 }
57 }
58
59 void PDFTabHelper::UpdateLocationBar() {
60 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
61 if (!browser)
62 return;
63
64 BrowserWindow* window = browser->window();
65 if (!window)
66 return;
67
68 LocationBar* location_bar = window->GetLocationBar();
69 if (!location_bar)
70 return;
71
72 location_bar->UpdateOpenPDFInReaderPrompt();
73 }
74
75 void PDFTabHelper::OnHasUnsupportedFeature() {
76 PDFHasUnsupportedFeature(web_contents());
77 }
78
79 void PDFTabHelper::OnSaveURLAs(const GURL& url,
80 const content::Referrer& referrer) {
81 RecordDownloadSource(DOWNLOAD_INITIATED_BY_PDF_SAVE);
82 web_contents()->SaveFrame(url, referrer);
83 }
84
85 void PDFTabHelper::OnUpdateContentRestrictions(int content_restrictions) {
86 CoreTabHelper* core_tab_helper =
87 CoreTabHelper::FromWebContents(web_contents());
88 // |core_tab_helper| is NULL for WebViewGuest.
89 if (core_tab_helper)
90 core_tab_helper->UpdateContentRestrictions(content_restrictions);
91 }
92
93 void PDFTabHelper::OnModalPromptForPasswordClosed(
94 IPC::Message* reply_message,
95 bool success,
96 const base::string16& actual_value) {
97 ChromeViewHostMsg_PDFModalPromptForPassword::WriteReplyParams(
98 reply_message, base::UTF16ToUTF8(actual_value));
99 Send(reply_message);
100 }
101
102 void PDFTabHelper::OnModalPromptForPassword(const std::string& prompt,
103 IPC::Message* reply_message) {
104 base::Callback<void(bool, const base::string16&)> callback =
105 base::Bind(&PDFTabHelper::OnModalPromptForPasswordClosed,
106 base::Unretained(this), reply_message);
107 ShowPDFPasswordDialog(web_contents(), base::UTF8ToUTF16(prompt), callback);
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698