blob: 3e3bfcb36ed3566239e348521478ed90def17c7c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/pdf/pdf_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h"
#include "chrome/browser/ui/pdf/pdf_unsupported_feature.h"
#include "chrome/common/render_messages.h"
#include "content/public/browser/navigation_details.h"
DEFINE_WEB_CONTENTS_USER_DATA_KEY(PDFTabHelper);
PDFTabHelper::PDFTabHelper(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {
}
PDFTabHelper::~PDFTabHelper() {
}
void PDFTabHelper::ShowOpenInReaderPrompt(
scoped_ptr<OpenPDFInReaderPromptDelegate> prompt) {
open_in_reader_prompt_ = prompt.Pass();
UpdateLocationBar();
}
bool PDFTabHelper::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PDFTabHelper, message)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature,
OnPDFHasUnsupportedFeature)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void PDFTabHelper::DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) {
if (open_in_reader_prompt_.get() &&
open_in_reader_prompt_->ShouldExpire(details)) {
open_in_reader_prompt_.reset();
UpdateLocationBar();
}
}
void PDFTabHelper::UpdateLocationBar() {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
if (!browser)
return;
BrowserWindow* window = browser->window();
if (!window)
return;
LocationBar* location_bar = window->GetLocationBar();
if (!location_bar)
return;
location_bar->UpdateOpenPDFInReaderPrompt();
}
void PDFTabHelper::OnPDFHasUnsupportedFeature() {
PDFHasUnsupportedFeature(web_contents());
}
|