| 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/open_pdf_in_reader_prompt_client.h" | |
| 12 #include "components/pdf/browser/pdf_web_contents_helper_client.h" | 11 #include "components/pdf/browser/pdf_web_contents_helper_client.h" |
| 13 #include "components/pdf/common/pdf_messages.h" | 12 #include "components/pdf/common/pdf_messages.h" |
| 14 #include "content/public/browser/navigation_details.h" | |
| 15 | 13 |
| 16 DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFWebContentsHelper); | 14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFWebContentsHelper); |
| 17 | 15 |
| 18 namespace pdf { | 16 namespace pdf { |
| 19 | 17 |
| 20 // static | 18 // static |
| 21 void PDFWebContentsHelper::CreateForWebContentsWithClient( | 19 void PDFWebContentsHelper::CreateForWebContentsWithClient( |
| 22 content::WebContents* contents, | 20 content::WebContents* contents, |
| 23 std::unique_ptr<PDFWebContentsHelperClient> client) { | 21 std::unique_ptr<PDFWebContentsHelperClient> client) { |
| 24 if (FromWebContents(contents)) | 22 if (FromWebContents(contents)) |
| 25 return; | 23 return; |
| 26 contents->SetUserData(UserDataKey(), | 24 contents->SetUserData(UserDataKey(), |
| 27 new PDFWebContentsHelper(contents, std::move(client))); | 25 new PDFWebContentsHelper(contents, std::move(client))); |
| 28 } | 26 } |
| 29 | 27 |
| 30 PDFWebContentsHelper::PDFWebContentsHelper( | 28 PDFWebContentsHelper::PDFWebContentsHelper( |
| 31 content::WebContents* web_contents, | 29 content::WebContents* web_contents, |
| 32 std::unique_ptr<PDFWebContentsHelperClient> client) | 30 std::unique_ptr<PDFWebContentsHelperClient> client) |
| 33 : content::WebContentsObserver(web_contents), client_(std::move(client)) {} | 31 : content::WebContentsObserver(web_contents), client_(std::move(client)) {} |
| 34 | 32 |
| 35 PDFWebContentsHelper::~PDFWebContentsHelper() { | 33 PDFWebContentsHelper::~PDFWebContentsHelper() { |
| 36 } | 34 } |
| 37 | 35 |
| 38 void PDFWebContentsHelper::ShowOpenInReaderPrompt( | |
| 39 std::unique_ptr<OpenPDFInReaderPromptClient> prompt) { | |
| 40 open_in_reader_prompt_ = std::move(prompt); | |
| 41 UpdateLocationBar(); | |
| 42 } | |
| 43 | |
| 44 bool PDFWebContentsHelper::OnMessageReceived( | 36 bool PDFWebContentsHelper::OnMessageReceived( |
| 45 const IPC::Message& message, | 37 const IPC::Message& message, |
| 46 content::RenderFrameHost* render_frame_host) { | 38 content::RenderFrameHost* render_frame_host) { |
| 47 bool handled = true; | 39 bool handled = true; |
| 48 IPC_BEGIN_MESSAGE_MAP(PDFWebContentsHelper, message) | 40 IPC_BEGIN_MESSAGE_MAP(PDFWebContentsHelper, message) |
| 49 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFHasUnsupportedFeature, | 41 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFHasUnsupportedFeature, |
| 50 OnHasUnsupportedFeature) | 42 OnHasUnsupportedFeature) |
| 51 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnSaveURLAs) | 43 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnSaveURLAs) |
| 52 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFUpdateContentRestrictions, | 44 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFUpdateContentRestrictions, |
| 53 OnUpdateContentRestrictions) | 45 OnUpdateContentRestrictions) |
| 54 IPC_MESSAGE_UNHANDLED(handled = false) | 46 IPC_MESSAGE_UNHANDLED(handled = false) |
| 55 IPC_END_MESSAGE_MAP() | 47 IPC_END_MESSAGE_MAP() |
| 56 return handled; | 48 return handled; |
| 57 } | 49 } |
| 58 | 50 |
| 59 void PDFWebContentsHelper::DidNavigateMainFrame( | |
| 60 const content::LoadCommittedDetails& details, | |
| 61 const content::FrameNavigateParams& params) { | |
| 62 if (open_in_reader_prompt_.get() && | |
| 63 open_in_reader_prompt_->ShouldExpire(details)) { | |
| 64 open_in_reader_prompt_.reset(); | |
| 65 UpdateLocationBar(); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void PDFWebContentsHelper::UpdateLocationBar() { | |
| 70 client_->UpdateLocationBar(web_contents()); | |
| 71 } | |
| 72 | |
| 73 void PDFWebContentsHelper::OnHasUnsupportedFeature() { | 51 void PDFWebContentsHelper::OnHasUnsupportedFeature() { |
| 74 client_->OnPDFHasUnsupportedFeature(web_contents()); | 52 client_->OnPDFHasUnsupportedFeature(web_contents()); |
| 75 } | 53 } |
| 76 | 54 |
| 77 void PDFWebContentsHelper::OnSaveURLAs(const GURL& url, | 55 void PDFWebContentsHelper::OnSaveURLAs(const GURL& url, |
| 78 const content::Referrer& referrer) { | 56 const content::Referrer& referrer) { |
| 79 client_->OnSaveURL(web_contents()); | 57 client_->OnSaveURL(web_contents()); |
| 80 web_contents()->SaveFrame(url, referrer); | 58 web_contents()->SaveFrame(url, referrer); |
| 81 } | 59 } |
| 82 | 60 |
| 83 void PDFWebContentsHelper::OnUpdateContentRestrictions( | 61 void PDFWebContentsHelper::OnUpdateContentRestrictions( |
| 84 int content_restrictions) { | 62 int content_restrictions) { |
| 85 client_->UpdateContentRestrictions(web_contents(), content_restrictions); | 63 client_->UpdateContentRestrictions(web_contents(), content_restrictions); |
| 86 } | 64 } |
| 87 | 65 |
| 88 } // namespace pdf | 66 } // namespace pdf |
| OLD | NEW |