Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / components / pdf / browser / pdf_web_contents_helper.cc
blobb1b8cd146b39053086a820b911ac5533fd5b0750
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.
5 #include "components/pdf/browser/pdf_web_contents_helper.h"
7 #include "base/bind.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/pdf/browser/open_pdf_in_reader_prompt_client.h"
10 #include "components/pdf/browser/pdf_web_contents_helper_client.h"
11 #include "components/pdf/common/pdf_messages.h"
12 #include "content/public/browser/navigation_details.h"
14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFWebContentsHelper);
16 namespace pdf {
18 // static
19 void PDFWebContentsHelper::CreateForWebContentsWithClient(
20 content::WebContents* contents,
21 scoped_ptr<PDFWebContentsHelperClient> client) {
22 if (FromWebContents(contents))
23 return;
24 contents->SetUserData(UserDataKey(),
25 new PDFWebContentsHelper(contents, client.Pass()));
28 PDFWebContentsHelper::PDFWebContentsHelper(
29 content::WebContents* web_contents,
30 scoped_ptr<PDFWebContentsHelperClient> client)
31 : content::WebContentsObserver(web_contents), client_(client.Pass()) {
34 PDFWebContentsHelper::~PDFWebContentsHelper() {
37 void PDFWebContentsHelper::ShowOpenInReaderPrompt(
38 scoped_ptr<OpenPDFInReaderPromptClient> prompt) {
39 open_in_reader_prompt_ = prompt.Pass();
40 UpdateLocationBar();
43 bool PDFWebContentsHelper::OnMessageReceived(const IPC::Message& message) {
44 bool handled = true;
45 IPC_BEGIN_MESSAGE_MAP(PDFWebContentsHelper, message)
46 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFHasUnsupportedFeature,
47 OnHasUnsupportedFeature)
48 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnSaveURLAs)
49 IPC_MESSAGE_HANDLER(PDFHostMsg_PDFUpdateContentRestrictions,
50 OnUpdateContentRestrictions)
51 IPC_MESSAGE_UNHANDLED(handled = false)
52 IPC_END_MESSAGE_MAP()
53 return handled;
56 void PDFWebContentsHelper::DidNavigateMainFrame(
57 const content::LoadCommittedDetails& details,
58 const content::FrameNavigateParams& params) {
59 if (open_in_reader_prompt_.get() &&
60 open_in_reader_prompt_->ShouldExpire(details)) {
61 open_in_reader_prompt_.reset();
62 UpdateLocationBar();
66 void PDFWebContentsHelper::UpdateLocationBar() {
67 client_->UpdateLocationBar(web_contents());
70 void PDFWebContentsHelper::OnHasUnsupportedFeature() {
71 client_->OnPDFHasUnsupportedFeature(web_contents());
74 void PDFWebContentsHelper::OnSaveURLAs(const GURL& url,
75 const content::Referrer& referrer) {
76 client_->OnSaveURL(web_contents());
77 web_contents()->SaveFrame(url, referrer);
80 void PDFWebContentsHelper::OnUpdateContentRestrictions(
81 int content_restrictions) {
82 client_->UpdateContentRestrictions(web_contents(), content_restrictions);
85 } // namespace pdf