diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-21 21:47:50 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-21 21:47:50 +0000 |
commit | e397a447a14e56d04c8c352ddced4f2cab071934 (patch) | |
tree | 0add0266b1e2fc3315948120ca46ea4fd91822d5 | |
parent | 4d58969fb88c8131afba405daa4f4bf85e9acaa3 (diff) | |
download | chromium_src-e397a447a14e56d04c8c352ddced4f2cab071934.zip chromium_src-e397a447a14e56d04c8c352ddced4f2cab071934.tar.gz chromium_src-e397a447a14e56d04c8c352ddced4f2cab071934.tar.bz2 |
Allow keyboard shortcuts on interstitial pages.
BUG=98430
TEST=open https URL with invalid cert or URL on safebrowsing list, try to use keyboard shortcuts on interstitial page (ctrl-w, ctrl-t, etc). Print, save, view-source should be disabled.
Review URL: http://codereview.chromium.org/8430023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115409 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/browser.cc | 19 | ||||
-rw-r--r-- | chrome/browser/ui/browser_browsertest.cc | 58 | ||||
-rw-r--r-- | content/browser/tab_contents/interstitial_page.cc | 17 | ||||
-rw-r--r-- | content/browser/tab_contents/interstitial_page.h | 4 | ||||
-rw-r--r-- | content/browser/tab_contents/navigation_controller.cc | 2 | ||||
-rw-r--r-- | content/public/browser/notification_types.h | 4 |
6 files changed, 101 insertions, 3 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 438f744..9f2b127 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -3262,6 +3262,9 @@ void Browser::TabInsertedAt(TabContentsWrapper* contents, registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, content::Source<TabContents>(contents->tab_contents())); + + registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, + content::Source<TabContents>(contents->tab_contents())); } void Browser::TabClosingAt(TabStripModel* tab_strip_model, @@ -4220,6 +4223,12 @@ void Browser::Observe(int type, case content::NOTIFICATION_INTERSTITIAL_ATTACHED: UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); + UpdateCommandsForTabState(); + break; + + case content::NOTIFICATION_INTERSTITIAL_DETACHED: + UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); + UpdateCommandsForTabState(); break; default: @@ -4595,7 +4604,8 @@ void Browser::UpdateCommandsForTabState() { command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false); // Changing the encoding is not possible on Chrome-internal webpages. - bool is_chrome_internal = HasInternalURL(nc.GetActiveEntry()); + bool is_chrome_internal = HasInternalURL(nc.GetActiveEntry()) || + current_tab->showing_interstitial_page(); command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, !is_chrome_internal && SavePackage::IsSavableContents( current_tab->contents_mime_type())); @@ -5095,6 +5105,8 @@ void Browser::TabDetachedAtImpl(TabContentsWrapper* contents, int index, registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, content::Source<TabContents>(contents->tab_contents())); + registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, + content::Source<TabContents>(contents->tab_contents())); registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, content::Source<TabContents>(contents->tab_contents())); } @@ -5267,8 +5279,11 @@ int Browser::GetContentRestrictionsForSelectedTab() { content_restrictions = current_tab->content_restrictions(); NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); // See comment in UpdateCommandsForTabState about why we call url(). - if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) + if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL()) + || current_tab->showing_interstitial_page()) content_restrictions |= content::CONTENT_RESTRICTION_SAVE; + if (current_tab->showing_interstitial_page()) + content_restrictions |= content::CONTENT_RESTRICTION_PRINT; } return content_restrictions; } diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc index c34d6b2..91bedf1 100644 --- a/chrome/browser/ui/browser_browsertest.cc +++ b/chrome/browser/ui/browser_browsertest.cc @@ -43,6 +43,7 @@ #include "chrome/test/base/ui_test_utils.h" #include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/renderer_host/render_view_host.h" +#include "content/browser/tab_contents/interstitial_page.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" @@ -139,6 +140,20 @@ void RunCloseWithAppMenuCallback(Browser* browser) { browser->ShowAppMenu(); } +// Displays "INTERSTITIAL" while the interstitial is attached. +// (InterstitialPage can be used in a test directly, but there would be no way +// to visually tell if it is showing or not.) +class TestInterstitialPage : public InterstitialPage { + public: + TestInterstitialPage(TabContents* tab, bool new_navigation, const GURL& url) + : InterstitialPage(tab, new_navigation, url) { } + virtual ~TestInterstitialPage() { } + + virtual std::string GetHTMLContents() OVERRIDE { + return "<h1>INTERSTITIAL</h1>"; + } +}; + } // namespace class BrowserTest : public ExtensionBrowserTest { @@ -1315,6 +1330,49 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, PageZoom) { browser()->Zoom(content::PAGE_ZOOM_RESET); } +IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialCommandDisable) { + ASSERT_TRUE(test_server()->Start()); + host_resolver()->AddRule("www.example.com", "127.0.0.1"); + GURL url(test_server()->GetURL("empty.html")); + ui_test_utils::NavigateToURL(browser(), url); + + CommandUpdater* command_updater = browser()->command_updater(); + EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_VIEW_SOURCE)); + EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_PRINT)); + EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SAVE_PAGE)); + EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_ENCODING_MENU)); + + TabContents* contents = browser()->GetSelectedTabContents(); + TestInterstitialPage* interstitial = new TestInterstitialPage( + contents, false, GURL()); + + ui_test_utils::WindowedNotificationObserver interstitial_observer( + content::NOTIFICATION_INTERSTITIAL_ATTACHED, + content::Source<TabContents>(contents)); + interstitial->Show(); + interstitial_observer.Wait(); + + EXPECT_TRUE(contents->showing_interstitial_page()); + + EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_VIEW_SOURCE)); + EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_PRINT)); + EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SAVE_PAGE)); + EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_ENCODING_MENU)); + + ui_test_utils::WindowedNotificationObserver interstitial_detach_observer( + content::NOTIFICATION_INTERSTITIAL_DETACHED, + content::Source<TabContents>(contents)); + interstitial->Proceed(); + interstitial_detach_observer.Wait(); + // interstitial is deleted now. + + EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_VIEW_SOURCE)); + EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_PRINT)); + EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SAVE_PAGE)); + EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_ENCODING_MENU)); + +} + // TODO(ben): this test was never enabled. It has bit-rotted since being added. // It originally lived in browser_unittest.cc, but has been moved here to make // room for real browser unit tests. diff --git a/content/browser/tab_contents/interstitial_page.cc b/content/browser/tab_contents/interstitial_page.cc index 407086f..0b66184 100644 --- a/content/browser/tab_contents/interstitial_page.cc +++ b/content/browser/tab_contents/interstitial_page.cc @@ -241,6 +241,12 @@ void InterstitialPage::Hide() { entry->set_title(original_tab_title_); tab_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TITLE); } + + content::NotificationService::current()->Notify( + content::NOTIFICATION_INTERSTITIAL_DETACHED, + content::Source<TabContents>(tab_), + content::NotificationService::NoDetails()); + delete this; } @@ -398,6 +404,17 @@ WebPreferences InterstitialPage::GetWebkitPrefs() { render_view_host()); } +bool InterstitialPage::PreHandleKeyboardEvent( + const NativeWebKeyboardEvent& event, + bool* is_keyboard_shortcut) { + return tab_->PreHandleKeyboardEvent(event, is_keyboard_shortcut); +} + +void InterstitialPage::HandleKeyboardEvent( + const NativeWebKeyboardEvent& event) { + return tab_->HandleKeyboardEvent(event); +} + RenderViewHost* InterstitialPage::CreateRenderViewHost() { RenderViewHost* render_view_host = new RenderViewHost( SiteInstance::CreateSiteInstance(tab()->browser_context()), diff --git a/content/browser/tab_contents/interstitial_page.h b/content/browser/tab_contents/interstitial_page.h index b4ebbdd..eb06f7c 100644 --- a/content/browser/tab_contents/interstitial_page.h +++ b/content/browser/tab_contents/interstitial_page.h @@ -132,6 +132,10 @@ class CONTENT_EXPORT InterstitialPage : public content::NotificationObserver, virtual content::RendererPreferences GetRendererPrefs( content::BrowserContext* browser_context) const OVERRIDE; virtual WebPreferences GetWebkitPrefs() OVERRIDE; + virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, + bool* is_keyboard_shortcut) OVERRIDE; + virtual void HandleKeyboardEvent( + const NativeWebKeyboardEvent& event) OVERRIDE; // Invoked with the NavigationEntry that is going to be added to the // navigation controller. diff --git a/content/browser/tab_contents/navigation_controller.cc b/content/browser/tab_contents/navigation_controller.cc index 81f141a..f0ef65f 100644 --- a/content/browser/tab_contents/navigation_controller.cc +++ b/content/browser/tab_contents/navigation_controller.cc @@ -331,7 +331,7 @@ bool NavigationController::CanViewSource() const { tab_contents_->contents_mime_type().c_str()); NavigationEntry* active_entry = GetActiveEntry(); return active_entry && !active_entry->IsViewSourceMode() && - is_supported_mime_type; + is_supported_mime_type && !tab_contents_->interstitial_page(); } NavigationEntry* NavigationController::GetEntryAtOffset(int offset) const { diff --git a/content/public/browser/notification_types.h b/content/public/browser/notification_types.h index 57cd41e..50a3101 100644 --- a/content/public/browser/notification_types.h +++ b/content/public/browser/notification_types.h @@ -272,6 +272,10 @@ enum NotificationType { // source is the TabContents, the details not used. NOTIFICATION_INTERSTITIAL_ATTACHED, + // Notification than an interstitial has become detached from a tab. The + // source is the TabContents, the details not used. + NOTIFICATION_INTERSTITIAL_DETACHED, + // Indicates that a RenderProcessHost was created and its handle is now // available. The source will be the RenderProcessHost that corresponds to // the process. |