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/memory/ptr_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "components/pdf/browser/pdf_web_contents_helper_client.h" | 12 #include "components/pdf/browser/pdf_web_contents_helper_client.h" |
12 | 13 |
13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFWebContentsHelper); | 14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFWebContentsHelper); |
14 | 15 |
15 namespace pdf { | 16 namespace pdf { |
16 | 17 |
17 // static | 18 // static |
18 void PDFWebContentsHelper::CreateForWebContentsWithClient( | 19 void PDFWebContentsHelper::CreateForWebContentsWithClient( |
19 content::WebContents* contents, | 20 content::WebContents* contents, |
20 std::unique_ptr<PDFWebContentsHelperClient> client) { | 21 std::unique_ptr<PDFWebContentsHelperClient> client) { |
21 if (FromWebContents(contents)) | 22 if (FromWebContents(contents)) |
22 return; | 23 return; |
23 contents->SetUserData(UserDataKey(), | 24 contents->SetUserData( |
24 new PDFWebContentsHelper(contents, std::move(client))); | 25 UserDataKey(), |
| 26 base::WrapUnique(new PDFWebContentsHelper(contents, std::move(client)))); |
25 } | 27 } |
26 | 28 |
27 PDFWebContentsHelper::PDFWebContentsHelper( | 29 PDFWebContentsHelper::PDFWebContentsHelper( |
28 content::WebContents* web_contents, | 30 content::WebContents* web_contents, |
29 std::unique_ptr<PDFWebContentsHelperClient> client) | 31 std::unique_ptr<PDFWebContentsHelperClient> client) |
30 : content::WebContentsObserver(web_contents), | 32 : content::WebContentsObserver(web_contents), |
31 pdf_service_bindings_(web_contents, this), | 33 pdf_service_bindings_(web_contents, this), |
32 client_(std::move(client)) {} | 34 client_(std::move(client)) {} |
33 | 35 |
34 PDFWebContentsHelper::~PDFWebContentsHelper() { | 36 PDFWebContentsHelper::~PDFWebContentsHelper() { |
35 } | 37 } |
36 | 38 |
37 void PDFWebContentsHelper::HasUnsupportedFeature() { | 39 void PDFWebContentsHelper::HasUnsupportedFeature() { |
38 client_->OnPDFHasUnsupportedFeature(web_contents()); | 40 client_->OnPDFHasUnsupportedFeature(web_contents()); |
39 } | 41 } |
40 | 42 |
41 void PDFWebContentsHelper::SaveUrlAs(const GURL& url, | 43 void PDFWebContentsHelper::SaveUrlAs(const GURL& url, |
42 const content::Referrer& referrer) { | 44 const content::Referrer& referrer) { |
43 client_->OnSaveURL(web_contents()); | 45 client_->OnSaveURL(web_contents()); |
44 web_contents()->SaveFrame(url, referrer); | 46 web_contents()->SaveFrame(url, referrer); |
45 } | 47 } |
46 | 48 |
47 void PDFWebContentsHelper::UpdateContentRestrictions( | 49 void PDFWebContentsHelper::UpdateContentRestrictions( |
48 int32_t content_restrictions) { | 50 int32_t content_restrictions) { |
49 client_->UpdateContentRestrictions(web_contents(), content_restrictions); | 51 client_->UpdateContentRestrictions(web_contents(), content_restrictions); |
50 } | 52 } |
51 | 53 |
52 } // namespace pdf | 54 } // namespace pdf |
OLD | NEW |