Index: components/pdf/browser/pdf_tab_helper.cc |
diff --git a/chrome/browser/ui/pdf/pdf_tab_helper.cc b/components/pdf/browser/pdf_tab_helper.cc |
similarity index 51% |
rename from chrome/browser/ui/pdf/pdf_tab_helper.cc |
rename to components/pdf/browser/pdf_tab_helper.cc |
index 71edc67de929b744152b539232319c045feaa09d..906e95201346aa97314012f0509d0c19b3d4bd9e 100644 |
--- a/chrome/browser/ui/pdf/pdf_tab_helper.cc |
+++ b/components/pdf/browser/pdf_tab_helper.cc |
@@ -1,25 +1,23 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Copyright 2014 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 "components/pdf/browser/pdf_tab_helper.h" |
+#include "base/bind.h" |
#include "base/strings/utf_string_conversions.h" |
-#include "chrome/browser/download/download_stats.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/location_bar/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/browser/ui/tab_contents/core_tab_helper.h" |
-#include "chrome/common/render_messages.h" |
+#include "components/pdf/browser/open_pdf_in_reader_prompt_delegate.h" |
+#include "components/pdf/browser/pdf_tab_helper_delegate.h" |
+#include "components/pdf/common/pdf_messages.h" |
#include "content/public/browser/navigation_details.h" |
-DEFINE_WEB_CONTENTS_USER_DATA_KEY(PDFTabHelper); |
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFTabHelper); |
-PDFTabHelper::PDFTabHelper(content::WebContents* web_contents) |
- : content::WebContentsObserver(web_contents) { |
+namespace pdf { |
+ |
+PDFTabHelper::PDFTabHelper(content::WebContents* web_contents, |
+ scoped_ptr<PDFTabHelperDelegate> delegate) |
+ : content::WebContentsObserver(web_contents), delegate_(delegate.Pass()) { |
} |
PDFTabHelper::~PDFTabHelper() { |
@@ -34,12 +32,12 @@ void PDFTabHelper::ShowOpenInReaderPrompt( |
bool PDFTabHelper::OnMessageReceived(const IPC::Message& message) { |
bool handled = true; |
IPC_BEGIN_MESSAGE_MAP(PDFTabHelper, message) |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature, |
+ IPC_MESSAGE_HANDLER(PDFHostMsg_PDFHasUnsupportedFeature, |
OnHasUnsupportedFeature) |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFSaveURLAs, OnSaveURLAs) |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFUpdateContentRestrictions, |
+ IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnSaveURLAs) |
+ IPC_MESSAGE_HANDLER(PDFHostMsg_PDFUpdateContentRestrictions, |
OnUpdateContentRestrictions) |
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_PDFModalPromptForPassword, |
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(PDFHostMsg_PDFModalPromptForPassword, |
OnModalPromptForPassword) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
@@ -57,44 +55,28 @@ void PDFTabHelper::DidNavigateMainFrame( |
} |
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(); |
+ delegate_->UpdateLocationBar(web_contents()); |
} |
void PDFTabHelper::OnHasUnsupportedFeature() { |
- PDFHasUnsupportedFeature(web_contents()); |
+ delegate_->OnPDFHasUnsupportedFeature(web_contents()); |
} |
void PDFTabHelper::OnSaveURLAs(const GURL& url, |
const content::Referrer& referrer) { |
- RecordDownloadSource(DOWNLOAD_INITIATED_BY_PDF_SAVE); |
+ delegate_->OnSaveURL(web_contents()); |
web_contents()->SaveFrame(url, referrer); |
} |
void PDFTabHelper::OnUpdateContentRestrictions(int content_restrictions) { |
- CoreTabHelper* core_tab_helper = |
- CoreTabHelper::FromWebContents(web_contents()); |
- // |core_tab_helper| is NULL for WebViewGuest. |
- if (core_tab_helper) |
- core_tab_helper->UpdateContentRestrictions(content_restrictions); |
+ delegate_->UpdateContentRestrictions(web_contents(), content_restrictions); |
} |
void PDFTabHelper::OnModalPromptForPasswordClosed( |
IPC::Message* reply_message, |
bool success, |
const base::string16& actual_value) { |
- ChromeViewHostMsg_PDFModalPromptForPassword::WriteReplyParams( |
+ PDFHostMsg_PDFModalPromptForPassword::WriteReplyParams( |
reply_message, base::UTF16ToUTF8(actual_value)); |
Send(reply_message); |
} |
@@ -103,6 +85,20 @@ void PDFTabHelper::OnModalPromptForPassword(const std::string& prompt, |
IPC::Message* reply_message) { |
base::Callback<void(bool, const base::string16&)> callback = |
base::Bind(&PDFTabHelper::OnModalPromptForPasswordClosed, |
- base::Unretained(this), reply_message); |
- ShowPDFPasswordDialog(web_contents(), base::UTF8ToUTF16(prompt), callback); |
+ base::Unretained(this), |
+ reply_message); |
+ delegate_->OnShowPDFPasswordDialog( |
+ web_contents(), base::UTF8ToUTF16(prompt), callback); |
} |
+ |
+// static |
+void PDFTabHelper::CreateForWebContentsWithDelegate( |
+ content::WebContents* contents, |
+ scoped_ptr<PDFTabHelperDelegate> delegate) { |
+ if (FromWebContents(contents)) |
+ return; |
+ contents->SetUserData(UserDataKey(), |
+ new PDFTabHelper(contents, delegate.Pass())); |
+} |
raymes
2014/08/27 03:34:09
nit: it would be better for this to be in the same
sadrul
2014/08/27 11:49:57
Done.
|
+ |
+} // namespace pdf |