summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-03 22:23:48 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-03 22:23:48 +0000
commita2da49a5570cef35c57acd35f842cb3f368619a1 (patch)
tree19a3e3c869765668949e9e9cb1041c9309e2c685 /chrome/browser
parent9a11fde9886808967843fce8ee7e07d250025b06 (diff)
downloadchromium_src-a2da49a5570cef35c57acd35f842cb3f368619a1.zip
chromium_src-a2da49a5570cef35c57acd35f842cb3f368619a1.tar.gz
chromium_src-a2da49a5570cef35c57acd35f842cb3f368619a1.tar.bz2
Disable printing context menus on the print preview page.
BUG=none TEST=none Review URL: http://codereview.chromium.org/5320001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68228 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/dom_ui/print_preview_ui_uitest.cc34
-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
4 files changed, 48 insertions, 10 deletions
diff --git a/chrome/browser/dom_ui/print_preview_ui_uitest.cc b/chrome/browser/dom_ui/print_preview_ui_uitest.cc
index f09cda5..138559e 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"
@@ -24,6 +25,14 @@ class PrintPreviewUITest : public UITest {
}
void AssertIsPrintPage(TabProxy* tab) {
+ // Wait for '#mainview' to become visible to make sure the document is
+ // mostly loaded. Otherwise GetTabTitle() below is flaky.
+ scoped_refptr<DOMElementProxy> dom(tab->GetDOMDocument());
+ ASSERT_TRUE(dom.get());
+ scoped_refptr<DOMElementProxy> mainview = dom->WaitFor1VisibleElement(
+ DOMElementProxy::By::Selectors("#mainview"));
+ ASSERT_TRUE(mainview.get());
+
std::wstring title;
ASSERT_TRUE(tab->GetTabTitle(&title));
string16 expected_title =
@@ -46,4 +55,29 @@ 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->RunCommandAsync(IDC_PRINT));
+
+ // Make sure there are 2 tabs and print is disabled.
+ WaitUntilTabCount(2);
+ 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 371e221..013fc49 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"
@@ -2645,9 +2646,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.