Skip to content

Commit

Permalink
Remove Simplify Page option from Print Preview
Browse files Browse the repository at this point in the history
BUG=620382
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2108833002
Cr-Commit-Position: refs/heads/master@{#402876}
  • Loading branch information
leizleiz authored and Commit bot committed Jun 29, 2016
1 parent e5bd187 commit a223560
Show file tree
Hide file tree
Showing 30 changed files with 43 additions and 816 deletions.
9 changes: 0 additions & 9 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -5456,12 +5456,6 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_FAST_UNLOAD_DESCRIPTION" desc="Description of the 'Fast Unload' lab.">
Enables fast tab/window closing - runs a tab's onunload js handler independently of the GUI.
</message>
<message name="IDS_FLAGS_DISTILLER_IN_PRINT_PREVIEW_NAME" desc="Name of the 'enable simplify on print preview' lab">
Simplify page on print preview
</message>
<message name="IDS_FLAGS_DISTILLER_IN_PRINT_PREVIEW_DESCRIPTION" desc="Description of the 'enable simplify on print preview' lab">
Enables the simplify page check box on the print preview dialog
</message>
<message name="IDS_FLAGS_APP_WINDOW_CONTROLS_NAME" desc="Name of the 'Enable 'window-controls' element' lab.">
'Window-controls' element
</message>
Expand Down Expand Up @@ -8602,9 +8596,6 @@ I don't think this site should be blocked!
<message name="IDS_PRINT_PREVIEW_OPTIONS_LABEL" desc="Options label currently providing the choice to print headers and footers.">
Options
</message>
<message name="IDS_PRINT_PREVIEW_OPTION_DISTILL_PAGE" desc="Checkbox label that provides a choice to print a simplified version of the page.">
Simplify page
</message>
<message name="IDS_PRINT_PREVIEW_OPTION_HEADER_FOOTER" desc="Checkbox label that provides a choice to print the headers and footers.">
Headers and footers
</message>
Expand Down
9 changes: 0 additions & 9 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@
#include "extensions/common/switches.h"
#endif

#if defined(ENABLE_PRINT_PREVIEW)
#include "chrome/browser/ui/webui/print_preview/print_preview_distiller.h"
#endif

#if defined(USE_ASH)
#include "ash/common/ash_switches.h"
#endif
Expand Down Expand Up @@ -1166,11 +1162,6 @@ const FeatureEntry kFeatureEntries[] = {
IDS_FLAGS_PRINT_PREVIEW_REGISTER_PROMOS_DESCRIPTION, kOsDesktop,
SINGLE_VALUE_TYPE(switches::kEnablePrintPreviewRegisterPromos)},
#endif // ENABLE_SERVICE_DISCOVERY
#if defined(ENABLE_PRINT_PREVIEW)
{"enable-print-preview-simplify", IDS_FLAGS_DISTILLER_IN_PRINT_PREVIEW_NAME,
IDS_FLAGS_DISTILLER_IN_PRINT_PREVIEW_DESCRIPTION, kOsDesktop,
FEATURE_VALUE_TYPE(PrintPreviewDistiller::kFeature)},
#endif
#if defined(OS_WIN)
{"enable-cloud-print-xps", IDS_FLAGS_CLOUD_PRINT_XPS_NAME,
IDS_FLAGS_CLOUD_PRINT_XPS_DESCRIPTION, kOsWin,
Expand Down
50 changes: 21 additions & 29 deletions chrome/browser/dom_distiller/profile_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,37 @@
#include "components/dom_distiller/core/dom_distiller_switches.h"
#include "components/dom_distiller/core/url_constants.h"

#if defined(ENABLE_PRINT_PREVIEW)
#include "chrome/browser/ui/webui/print_preview/print_preview_distiller.h"
#endif // defined(ENABLE_PRINT_PREVIEW)

#if BUILDFLAG(ANDROID_JAVA_UI)
#include "chrome/browser/android/dom_distiller/distiller_ui_handle_android.h"
#endif // BUILDFLAG(ANDROID_JAVA_UI)

void RegisterDomDistillerViewerSource(Profile* profile) {
namespace dom_distiller {

void RegisterViewerSource(Profile* profile) {
bool enabled_distiller = base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableDomDistiller);
#if defined(ENABLE_PRINT_PREVIEW)
if (PrintPreviewDistiller::IsEnabled())
enabled_distiller = true;
#endif // defined(ENABLE_PRINT_PREVIEW)
if (!enabled_distiller)
return;

if (enabled_distiller) {
dom_distiller::DomDistillerServiceFactory* dom_distiller_service_factory =
dom_distiller::DomDistillerServiceFactory::GetInstance();
// The LazyDomDistillerService deletes itself when the profile is destroyed.
dom_distiller::LazyDomDistillerService* lazy_service =
new dom_distiller::LazyDomDistillerService(
profile, dom_distiller_service_factory);
std::unique_ptr<dom_distiller::DistillerUIHandle> ui_handle;
DomDistillerServiceFactory* dom_distiller_service_factory =
DomDistillerServiceFactory::GetInstance();
// The LazyDomDistillerService deletes itself when the profile is destroyed.
LazyDomDistillerService* lazy_service =
new LazyDomDistillerService(profile, dom_distiller_service_factory);
std::unique_ptr<DistillerUIHandle> ui_handle;

#if BUILDFLAG(ANDROID_JAVA_UI)
ui_handle.reset(
new dom_distiller::android::DistillerUIHandleAndroid());
ui_handle.reset(new dom_distiller::android::DistillerUIHandleAndroid());
#endif // BUILDFLAG(ANDROID_JAVA_UI)

// Set the JavaScript world ID.
if (!dom_distiller::DistillerJavaScriptWorldIdIsSet()) {
dom_distiller::SetDistillerJavaScriptWorldId(
chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL);
}

content::URLDataSource::Add(
profile, new dom_distiller::DomDistillerViewerSource(
lazy_service, dom_distiller::kDomDistillerScheme,
std::move(ui_handle)));
// Set the JavaScript world ID.
if (!DistillerJavaScriptWorldIdIsSet()) {
SetDistillerJavaScriptWorldId(chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL);
}

content::URLDataSource::Add(
profile, new DomDistillerViewerSource(lazy_service, kDomDistillerScheme,
std::move(ui_handle)));
}

} // namespace dom_distiller
6 changes: 5 additions & 1 deletion chrome/browser/dom_distiller/profile_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

#include "chrome/browser/profiles/profile.h"

namespace dom_distiller {

// Setup URLDataSource for the chrome-distiller:// scheme for the given
// |profile|.
void RegisterDomDistillerViewerSource(Profile* profile);
void RegisterViewerSource(Profile* profile);

} // namespace dom_distiller

#endif // CHROME_BROWSER_DOM_DISTILLER_PROFILE_UTILS_H_
35 changes: 4 additions & 31 deletions chrome/browser/printing/print_preview_dialog_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,16 @@ WebContents* PrintPreviewDialogController::GetOrCreatePreviewDialog(

// Get the print preview dialog for |initiator|.
WebContents* preview_dialog = GetPrintPreviewForContents(initiator);
if (preview_dialog) {
// Show the initiator holding the existing preview dialog.
initiator->GetDelegate()->ActivateContents(initiator);
return preview_dialog;
}

// We should only create a dialog if the initiator has not been proxied.
if (GetProxyDialogTarget(initiator) == initiator)
if (!preview_dialog)
return CreatePrintPreviewDialog(initiator);

return nullptr;
// Show the initiator holding the existing preview dialog.
initiator->GetDelegate()->ActivateContents(initiator);
return preview_dialog;
}

WebContents* PrintPreviewDialogController::GetPrintPreviewForContents(
WebContents* contents) const {
// If this WebContents relies on another for its preview dialog, we
// need to act as if we are looking for the proxied content's dialog.
contents = GetProxyDialogTarget(contents);

// |preview_dialog_map_| is keyed by the preview dialog, so if find()
// succeeds, then |contents| is the preview dialog.
PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents);
Expand Down Expand Up @@ -395,24 +386,6 @@ WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog(
return preview_dialog;
}

void PrintPreviewDialogController::AddProxyDialogForWebContents(
WebContents* source,
WebContents* target) {
proxied_dialog_map_[source] = target;
}

void PrintPreviewDialogController::RemoveProxyDialogForWebContents(
WebContents* source) {
proxied_dialog_map_.erase(source);
}

WebContents* PrintPreviewDialogController::GetProxyDialogTarget(
WebContents* source) const {
PrintPreviewDialogMap::const_iterator proxied =
proxied_dialog_map_.find(source);
return proxied == proxied_dialog_map_.end() ? source : proxied->second;
}

void PrintPreviewDialogController::SaveInitiatorTitle(
WebContents* preview_dialog) {
WebContents* initiator = GetInitiator(preview_dialog);
Expand Down
11 changes: 0 additions & 11 deletions chrome/browser/printing/print_preview_dialog_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ class PrintPreviewDialogController
return is_creating_print_preview_dialog_;
}

void AddProxyDialogForWebContents(content::WebContents* source,
content::WebContents* target);

void RemoveProxyDialogForWebContents(content::WebContents* source);

// Returns |source|'s |target| if it's a proxy, otherwise returns |source|.
content::WebContents* GetProxyDialogTarget(
content::WebContents* source) const;

private:
friend class base::RefCounted<PrintPreviewDialogController>;

Expand Down Expand Up @@ -131,8 +122,6 @@ class PrintPreviewDialogController
// Mapping between print preview dialog and the corresponding initiator.
PrintPreviewDialogMap preview_dialog_map_;

PrintPreviewDialogMap proxied_dialog_map_;

// A registrar for listening to notifications.
content::NotificationRegistrar registrar_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,89 +129,6 @@ TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogs) {
EXPECT_EQ(tab_1_index, tab_strip_model->active_index());
}

// Get a preview dialog for a proxied initiator should work.
TEST_F(PrintPreviewDialogControllerUnitTest, ProxyGetOrCreatePreviewDialog) {
// Lets start with one window with one tab.
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
EXPECT_EQ(0, browser()->tab_strip_model()->count());
chrome::NewTab(browser());
EXPECT_EQ(1, browser()->tab_strip_model()->count());

// Create a reference to initiator contents.
WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents();

PrintPreviewDialogController* dialog_controller =
PrintPreviewDialogController::GetInstance();
ASSERT_TRUE(dialog_controller);

// Get the preview dialog for initiator.
PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(false);
WebContents* preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(initiator);

// New print preview dialog is a constrained window, so the number of tabs is
// still 1.
EXPECT_EQ(1, browser()->tab_strip_model()->count());
EXPECT_NE(initiator, preview_dialog);

// Create the proxy web contents.
std::unique_ptr<WebContents> proxy(
content::WebContentsTester::CreateTestWebContents(profile(), nullptr));
TestWebContentsDelegate delegate;
proxy->SetDelegate(&delegate);
dialog_controller->AddProxyDialogForWebContents(proxy.get(), initiator);

// Get the print preview dialog for the initiator and proxy.
WebContents* initiator_preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(initiator);
WebContents* proxy_preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(proxy.get());

// Preview dialog already exists. Tab count remains the same.
EXPECT_EQ(1, browser()->tab_strip_model()->count());

// 1:1 relationship between initiator and preview dialog.
EXPECT_EQ(initiator_preview_dialog, preview_dialog);
EXPECT_EQ(proxy_preview_dialog, preview_dialog);

dialog_controller->RemoveProxyDialogForWebContents(proxy.get());
}

// Create a preview dialog for a proxied initiator should fail.
TEST_F(PrintPreviewDialogControllerUnitTest, ProxyNoGetOrCreatePreviewDialog) {
// Lets start with one window with one tab.
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
EXPECT_EQ(0, browser()->tab_strip_model()->count());
chrome::NewTab(browser());
EXPECT_EQ(1, browser()->tab_strip_model()->count());

// Create a reference to initiator contents.
WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents();

PrintPreviewDialogController* dialog_controller =
PrintPreviewDialogController::GetInstance();
ASSERT_TRUE(dialog_controller);

// Create the proxy web contents.
std::unique_ptr<WebContents> proxy(
content::WebContentsTester::CreateTestWebContents(profile(), nullptr));
TestWebContentsDelegate delegate;
proxy->SetDelegate(&delegate);
dialog_controller->AddProxyDialogForWebContents(proxy.get(), initiator);

// Get the print preview dialog for the proxy.
WebContents* proxy_preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(proxy.get());

// Preview dialog shouldn't be created. Tab count remains the same.
EXPECT_EQ(1, browser()->tab_strip_model()->count());

// A proxy should not create a dialog, only re-use.
EXPECT_EQ(proxy_preview_dialog, nullptr);

dialog_controller->RemoveProxyDialogForWebContents(proxy.get());
}

// Check clearing the initiator details associated with a print preview dialog
// allows the initiator to create another print preview dialog.
TEST_F(PrintPreviewDialogControllerUnitTest, ClearInitiatorDetails) {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/profiles/off_the_record_profile_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void OffTheRecordProfileImpl::Init() {

// The DomDistillerViewerSource is not a normal WebUI so it must be registered
// as a URLDataSource early.
RegisterDomDistillerViewerSource(this);
dom_distiller::RegisterViewerSource(this);
}

OffTheRecordProfileImpl::~OffTheRecordProfileImpl() {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/profiles/profile_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ void ProfileImpl::DoFinalInit() {

// The DomDistillerViewerSource is not a normal WebUI so it must be registered
// as a URLDataSource early.
RegisterDomDistillerViewerSource(this);
dom_distiller::RegisterViewerSource(this);

#if defined(OS_CHROMEOS)
if (chromeos::UserSessionManager::GetInstance()
Expand Down
12 changes: 0 additions & 12 deletions chrome/browser/resources/print_preview/data/print_ticket_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,6 @@ cr.define('print_preview', function() {
this.selectionOnly_ =
new print_preview.ticket_items.SelectionOnly(this.documentInfo_);

/**
* Print friendly ticket item.
* @type {!print_preview.ticket_items.DistillPage}
* @private
*/
this.distillPage_ = new print_preview.ticket_items.DistillPage(
this.documentInfo_);

/**
* Vendor ticket items.
* @type {!print_preview.ticket_items.VendorItems}
Expand Down Expand Up @@ -275,10 +267,6 @@ cr.define('print_preview', function() {
return this.headerFooter_;
},

get distillPage() {
return this.distillPage_;
},

get mediaSize() {
return this.mediaSize_;
},
Expand Down
Loading

0 comments on commit a223560

Please sign in to comment.