summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-15 18:05:16 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-15 18:05:16 +0000
commit31682283d0eefd0b64065144478b0b6a4eda093e (patch)
treeef12420b8f1dd403c748ad9673a6f57df7a59ace /chrome
parentc651176e09906e3aa6986e282011babe4ed8777e (diff)
downloadchromium_src-31682283d0eefd0b64065144478b0b6a4eda093e.zip
chromium_src-31682283d0eefd0b64065144478b0b6a4eda093e.tar.gz
chromium_src-31682283d0eefd0b64065144478b0b6a4eda093e.tar.bz2
Enable the context menu and developer menu "View source" items at the same time.
This fixes issue 2028 which didn't enable the context menu item for new tabs. BUG=2028 TEST=Open a new tab and verify that the 'View page source' context menu is enabled. Original review: http://codereview.chromium.org/541016 Patch by Aaron Kemp git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36367 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser.cc7
-rw-r--r--chrome/browser/tab_contents/navigation_controller.cc9
-rw-r--r--chrome/browser/tab_contents/navigation_controller.h3
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc2
4 files changed, 15 insertions, 6 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 0cfbe13..0f00ab4 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -73,7 +73,6 @@
#include "grit/locale_settings.h"
#include "net/base/cookie_monster.h"
#include "net/base/cookie_policy.h"
-#include "net/base/mime_util.h"
#include "net/base/net_util.h"
#include "net/base/registry_controlled_domain.h"
#include "net/url_request/url_request_context.h"
@@ -2630,9 +2629,6 @@ void Browser::UpdateCommandsForTabState() {
// Current navigation entry, may be NULL.
NavigationEntry* active_entry = current_tab->controller().GetActiveEntry();
- bool is_source_viewable =
- net::IsSupportedNonImageMimeType(
- current_tab->contents_mime_type().c_str());
// Page-related commands
window_->SetStarredState(current_tab->is_starred());
@@ -2642,8 +2638,7 @@ void Browser::UpdateCommandsForTabState() {
// View-source should not be enabled if already in view-source mode or
// the source is not viewable.
command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
- active_entry && !active_entry->IsViewSourceMode() &&
- is_source_viewable);
+ current_tab->controller().CanViewSource());
// Instead of using GetURL here, we use url() (which is the "real" url of the
// page) from the NavigationEntry because its reflects their origin rather
diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc
index 3cbe29c..83e7ba5 100644
--- a/chrome/browser/tab_contents/navigation_controller.cc
+++ b/chrome/browser/tab_contents/navigation_controller.cc
@@ -29,6 +29,7 @@
#include "grit/app_resources.h"
#include "net/base/escape.h"
#include "net/base/net_util.h"
+#include "net/base/mime_util.h"
#include "webkit/glue/webkit_glue.h"
namespace {
@@ -244,6 +245,14 @@ NavigationEntry* NavigationController::GetLastCommittedEntry() const {
return entries_[last_committed_entry_index_].get();
}
+bool NavigationController::CanViewSource() const {
+ bool is_supported_mime_type = net::IsSupportedNonImageMimeType(
+ tab_contents_->contents_mime_type().c_str());
+ NavigationEntry* active_entry = GetActiveEntry();
+ return active_entry && !active_entry->IsViewSourceMode() &&
+ is_supported_mime_type;
+}
+
NavigationEntry* NavigationController::GetEntryAtOffset(int offset) const {
int index = (transient_entry_index_ != -1) ?
transient_entry_index_ + offset :
diff --git a/chrome/browser/tab_contents/navigation_controller.h b/chrome/browser/tab_contents/navigation_controller.h
index 5378546..2aba4fe 100644
--- a/chrome/browser/tab_contents/navigation_controller.h
+++ b/chrome/browser/tab_contents/navigation_controller.h
@@ -176,6 +176,9 @@ class NavigationController {
// committed entries.
NavigationEntry* GetLastCommittedEntry() const;
+ // Returns true if the source for the current entry can be viewed.
+ bool CanViewSource() const;
+
// Returns the index of the last committed entry.
int last_committed_entry_index() const {
return last_committed_entry_index_;
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 19ff3c1..4bb701f 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -374,6 +374,8 @@ bool RenderViewContextMenu::IsItemCommandEnabled(int id) const {
case IDS_CONTENT_CONTEXT_VIEWPAGESOURCE:
case IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE:
+ return source_tab_contents_->controller().CanViewSource();
+
case IDS_CONTENT_CONTEXT_INSPECTELEMENT:
// Viewing page info is not a developer command but is meaningful for the
// same set of pages which developer commands are meaningful for.