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 "components/pdf/browser/pdf_web_contents_helper.h" | 5 #include "components/pdf/browser/pdf_web_contents_helper.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "components/pdf/browser/pdf_web_contents_helper_client.h" | 11 #include "components/pdf/browser/pdf_web_contents_helper_client.h" |
12 #include "components/pdf/common/pdf_messages.h" | |
13 | 12 |
14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFWebContentsHelper); | 13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFWebContentsHelper); |
15 | 14 |
16 namespace pdf { | 15 namespace pdf { |
17 | 16 |
18 // static | 17 // static |
19 void PDFWebContentsHelper::CreateForWebContentsWithClient( | 18 void PDFWebContentsHelper::CreateForWebContentsWithClient( |
20 content::WebContents* contents, | 19 content::WebContents* contents, |
21 std::unique_ptr<PDFWebContentsHelperClient> client) { | 20 std::unique_ptr<PDFWebContentsHelperClient> client) { |
22 if (FromWebContents(contents)) | 21 if (FromWebContents(contents)) |
23 return; | 22 return; |
24 contents->SetUserData(UserDataKey(), | 23 contents->SetUserData(UserDataKey(), |
25 new PDFWebContentsHelper(contents, std::move(client))); | 24 new PDFWebContentsHelper(contents, std::move(client))); |
26 } | 25 } |
27 | 26 |
28 PDFWebContentsHelper::PDFWebContentsHelper( | 27 PDFWebContentsHelper::PDFWebContentsHelper( |
29 content::WebContents* web_contents, | 28 content::WebContents* web_contents, |
30 std::unique_ptr<PDFWebContentsHelperClient> client) | 29 std::unique_ptr<PDFWebContentsHelperClient> client) |
31 : content::WebContentsObserver(web_contents), client_(std::move(client)) {} | 30 : content::WebContentsObserver(web_contents), |
| 31 pdf_service_bindings_(web_contents, this), |
| 32 client_(std::move(client)) {} |
32 | 33 |
33 PDFWebContentsHelper::~PDFWebContentsHelper() { | 34 PDFWebContentsHelper::~PDFWebContentsHelper() { |
34 } | 35 } |
35 | 36 |
36 bool PDFWebContentsHelper::OnMessageReceived( | 37 void PDFWebContentsHelper::HasUnsupportedFeature() { |
37 const IPC::Message& message, | |
38 content::RenderFrameHost* render_frame_host) { | |
39 bool handled = true; | |
40 IPC_BEGIN_MESSAGE_MAP(PDFWebContentsHelper, message) | |
41 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFHasUnsupportedFeature, | |
42 OnHasUnsupportedFeature) | |
43 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnSaveURLAs) | |
44 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFUpdateContentRestrictions, | |
45 OnUpdateContentRestrictions) | |
46 IPC_MESSAGE_UNHANDLED(handled = false) | |
47 IPC_END_MESSAGE_MAP() | |
48 return handled; | |
49 } | |
50 | |
51 void PDFWebContentsHelper::OnHasUnsupportedFeature() { | |
52 client_->OnPDFHasUnsupportedFeature(web_contents()); | 38 client_->OnPDFHasUnsupportedFeature(web_contents()); |
53 } | 39 } |
54 | 40 |
55 void PDFWebContentsHelper::OnSaveURLAs(const GURL& url, | 41 void PDFWebContentsHelper::SaveUrlAs(const GURL& url, |
56 const content::Referrer& referrer) { | 42 const content::Referrer& referrer) { |
57 client_->OnSaveURL(web_contents()); | 43 client_->OnSaveURL(web_contents()); |
58 web_contents()->SaveFrame(url, referrer); | 44 web_contents()->SaveFrame(url, referrer); |
59 } | 45 } |
60 | 46 |
61 void PDFWebContentsHelper::OnUpdateContentRestrictions( | 47 void PDFWebContentsHelper::UpdateContentRestrictions( |
62 int content_restrictions) { | 48 int32_t content_restrictions) { |
63 client_->UpdateContentRestrictions(web_contents(), content_restrictions); | 49 client_->UpdateContentRestrictions(web_contents(), content_restrictions); |
64 } | 50 } |
65 | 51 |
66 } // namespace pdf | 52 } // namespace pdf |
OLD | NEW |