summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-07 21:05:21 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-07 21:05:21 +0000
commitde4761b1a1cdea2d8c79b63052504c33a60fe4e4 (patch)
treec03d95541629198c4941e3884662c5641ec10459 /chrome
parent0cc0a246f3ef08594bb6184ba45c8742dc6c0e99 (diff)
downloadchromium_src-de4761b1a1cdea2d8c79b63052504c33a60fe4e4.zip
chromium_src-de4761b1a1cdea2d8c79b63052504c33a60fe4e4.tar.gz
chromium_src-de4761b1a1cdea2d8c79b63052504c33a60fe4e4.tar.bz2
Disable printing context menus on the print preview page. (resubmit)
BUG=none TEST=none Original review: http://codereview.chromium.org/5320001/ Review URL: http://codereview.chromium.org/5625008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68515 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc3
-rw-r--r--chrome/browser/dom_ui/print_preview_ui_uitest.cc27
-rw-r--r--chrome/browser/printing/print_preview_tab_controller.cc6
-rw-r--r--chrome/browser/printing/print_preview_tab_controller.h6
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc12
5 files changed, 44 insertions, 10 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index 1c526ef..3cbde95 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -5,6 +5,8 @@
#include "chrome/browser/automation/automation_provider_observers.h"
#include <deque>
+#include <string>
+#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
@@ -756,6 +758,7 @@ const struct CommandNotification command_notifications[] = {
// load to finish, and title to change.
{IDC_MANAGE_EXTENSIONS, NotificationType::TAB_CONTENTS_TITLE_UPDATED},
{IDC_OPTIONS, NotificationType::TAB_CONTENTS_TITLE_UPDATED},
+ {IDC_PRINT, NotificationType::TAB_CONTENTS_TITLE_UPDATED},
{IDC_SHOW_DOWNLOADS, NotificationType::TAB_CONTENTS_TITLE_UPDATED},
{IDC_SHOW_HISTORY, NotificationType::TAB_CONTENTS_TITLE_UPDATED},
};
diff --git a/chrome/browser/dom_ui/print_preview_ui_uitest.cc b/chrome/browser/dom_ui/print_preview_ui_uitest.cc
index f09cda5..4be0a28 100644
--- a/chrome/browser/dom_ui/print_preview_ui_uitest.cc
+++ b/chrome/browser/dom_ui/print_preview_ui_uitest.cc
@@ -5,6 +5,7 @@
#include "app/l10n_util.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
+#include "chrome/app/chrome_command_ids.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/automation/browser_proxy.h"
@@ -46,4 +47,30 @@ TEST_F(PrintPreviewUITest, LoadPrintPreviewByURL) {
AssertIsPrintPage(tab);
}
+TEST_F(PrintPreviewUITest, PrintCommandDisabled) {
+ scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ ASSERT_TRUE(browser.get());
+
+ // Go to the about:blank page.
+ NavigateToURL(GURL(chrome::kAboutBlankURL));
+
+ // Make sure there is 1 tab and print is enabled. Create print preview tab.
+ int tab_count;
+ ASSERT_TRUE(browser->GetTabCount(&tab_count));
+ ASSERT_EQ(1, tab_count);
+ bool enabled;
+ ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled));
+ ASSERT_TRUE(enabled);
+ ASSERT_TRUE(browser->RunCommand(IDC_PRINT));
+
+ // Make sure there are 2 tabs and print is disabled.
+ ASSERT_TRUE(browser->GetTabCount(&tab_count));
+ ASSERT_EQ(2, tab_count);
+ scoped_refptr<TabProxy> tab = browser->GetActiveTab();
+ ASSERT_TRUE(tab.get());
+ AssertIsPrintPage(tab);
+ ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled));
+ ASSERT_FALSE(enabled);
+}
+
} // namespace
diff --git a/chrome/browser/printing/print_preview_tab_controller.cc b/chrome/browser/printing/print_preview_tab_controller.cc
index 6888f5b..2cc8514 100644
--- a/chrome/browser/printing/print_preview_tab_controller.cc
+++ b/chrome/browser/printing/print_preview_tab_controller.cc
@@ -35,9 +35,6 @@ TabContents* PrintPreviewTabController::GetOrCreatePreviewTab(
TabContents* initiator_tab, int browser_window_id ) {
DCHECK(initiator_tab);
- if (IsPrintPreviewTab(initiator_tab))
- return initiator_tab;
-
// Get the print preview tab for |initiator_tab|.
TabContents* preview_tab = GetPrintPreviewForTab(initiator_tab);
if (preview_tab) {
@@ -48,6 +45,7 @@ TabContents* PrintPreviewTabController::GetOrCreatePreviewTab(
return CreatePrintPreviewTab(initiator_tab, browser_window_id);
}
+// static
bool PrintPreviewTabController::IsPrintPreviewTab(TabContents* tab) {
const GURL& url = tab->GetURL();
return (url.SchemeIs(chrome::kChromeUIScheme) &&
@@ -192,4 +190,4 @@ void PrintPreviewTabController::Observe(NotificationType type,
RemoveObservers(initiator_tab);
}
-} // namespace printing
+} // namespace printing
diff --git a/chrome/browser/printing/print_preview_tab_controller.h b/chrome/browser/printing/print_preview_tab_controller.h
index 6eec3f4..5be6118 100644
--- a/chrome/browser/printing/print_preview_tab_controller.h
+++ b/chrome/browser/printing/print_preview_tab_controller.h
@@ -43,12 +43,12 @@ class PrintPreviewTabController
const NotificationSource& source,
const NotificationDetails& details);
+ // Returns true if |tab| is a print preview tab.
+ static bool IsPrintPreviewTab(TabContents* tab);
+
private:
friend class base::RefCounted<PrintPreviewTabController>;
- // Returns true if |tab| is a print preview tab.
- bool IsPrintPreviewTab(TabContents* tab);
-
// Returns initiator tab for |preview_tab|.
// Returns NULL if no initiator tab exists for |preview_tab|.
TabContents* GetInitiatorTab(TabContents* preview_tab);
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index fddbc2f..f8f93a4 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -85,6 +85,7 @@
#include "chrome/browser/ui/find_bar/find_bar_state.h"
#include "chrome/common/bindings_policy.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/content_restriction.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_action.h"
#include "chrome/common/extensions/extension_icon_set.h"
@@ -2649,9 +2650,14 @@ void TabContents::RequestMove(const gfx::Rect& new_bounds) {
void TabContents::DidStartLoading() {
SetIsLoading(true, NULL);
- if (content_restrictions_) {
- content_restrictions_= 0;
- delegate()->ContentRestrictionsChanged(this);
+ if (delegate()) {
+ bool is_print_preview_tab =
+ printing::PrintPreviewTabController::IsPrintPreviewTab(this);
+ if (content_restrictions_ || is_print_preview_tab) {
+ content_restrictions_= is_print_preview_tab ?
+ CONTENT_RESTRICTION_PRINT : 0;
+ delegate()->ContentRestrictionsChanged(this);
+ }
}
// Notify observers about navigation.