summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-21 00:34:09 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-21 00:34:09 +0000
commit6641bf667244ed108b2d300766896f6fa84a6f4e (patch)
tree2e82c7be2c10139bddf35f8e72b47b49bcbb3ce0 /chrome
parent92ac0b815ab28656139ecbbe3af11edaecfce61a (diff)
downloadchromium_src-6641bf667244ed108b2d300766896f6fa84a6f4e.zip
chromium_src-6641bf667244ed108b2d300766896f6fa84a6f4e.tar.gz
chromium_src-6641bf667244ed108b2d300766896f6fa84a6f4e.tar.bz2
Don't show "Inspect Element" in the context menu if we can't inspect.
Ubuntu want to ship with the inspector files in a separate package and having menu items which are broken isn't nice. http://codereview.chromium.org/174162 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23927 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_main.cc4
-rw-r--r--chrome/browser/browser_process.h9
-rw-r--r--chrome/browser/browser_process_impl.cc31
-rw-r--r--chrome/browser/browser_process_impl.h12
-rw-r--r--chrome/browser/gtk/standard_menus.cc17
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc7
-rw-r--r--chrome/browser/views/toolbar_view.cc6
-rw-r--r--chrome/test/testing_browser_process.h3
8 files changed, 81 insertions, 8 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index b1fddf6..d6dd7e2 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -782,6 +782,10 @@ int BrowserMain(const MainFunctionParams& parameters) {
if (parsed_command_line.HasSwitch(switches::kEnableWebResources))
profile->InitWebResources();
+ // Stat the directory with the inspector's files so that we can know if we
+ // should display the entry in the context menu or not.
+ browser_process->CheckForInspectorFiles();
+
int result_code = ResultCodes::NORMAL_EXIT;
if (parameters.ui_task) {
// We are in test mode. Run one task and enter the main message loop.
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h
index 281e330..ba24f6c 100644
--- a/chrome/browser/browser_process.h
+++ b/chrome/browser/browser_process.h
@@ -138,6 +138,15 @@ class BrowserProcess {
return user_data_dir_profiles_;
}
+ // Trigger an asynchronous check to see if we have the inspector's files on
+ // disk.
+ virtual void CheckForInspectorFiles() = 0;
+
+ // Return true iff we found the inspector files on disk. It's possible to
+ // call this function before we have a definite answer from the disk. In that
+ // case, we default to returning true.
+ virtual bool have_inspector_files() const = 0;
+
private:
// User-data-dir based profiles.
std::vector<std::wstring> user_data_dir_profiles_;
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 2168d64..8024370 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -7,6 +7,7 @@
#include "app/l10n_util.h"
#include "base/clipboard.h"
#include "base/command_line.h"
+#include "base/file_util.h"
#include "base/path_service.h"
#include "base/thread.h"
#include "base/waitable_event.h"
@@ -130,7 +131,8 @@ BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
module_ref_count_(0),
memory_model_(HIGH_MEMORY_MODEL),
checked_for_new_frames_(false),
- using_new_frames_(false) {
+ using_new_frames_(false),
+ have_inspector_files_(true) {
g_browser_process = this;
clipboard_.reset(new Clipboard);
main_notification_service_.reset(new NotificationService);
@@ -422,3 +424,30 @@ void BrowserProcessImpl::CreateGoogleURLTracker() {
scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
google_url_tracker_.swap(google_url_tracker);
}
+
+// The BrowserProcess object must outlive the file thread so we use traits
+// which don't do any management.
+template <>
+struct RunnableMethodTraits<BrowserProcessImpl> {
+ static void RetainCallee(BrowserProcessImpl*) {}
+ static void ReleaseCallee(BrowserProcessImpl*) {}
+};
+
+void BrowserProcessImpl::CheckForInspectorFiles() {
+ file_thread()->message_loop()->PostTask
+ (FROM_HERE,
+ NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck));
+}
+
+void BrowserProcessImpl::DoInspectorFilesCheck() {
+ // Runs on FILE thread.
+ DCHECK(file_thread_->message_loop() == MessageLoop::current());
+ bool result = false;
+
+ FilePath inspector_dir;
+ if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) {
+ result = file_util::PathExists(inspector_dir);
+ }
+
+ have_inspector_files_ = result;
+}
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index ac0edde..3840836 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -189,6 +189,12 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe {
return shutdown_event_.get();
}
+ virtual void CheckForInspectorFiles();
+
+ virtual bool have_inspector_files() const {
+ return have_inspector_files_;
+ }
+
private:
void CreateResourceDispatcherHost();
void CreatePrefService();
@@ -276,6 +282,12 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe {
// An event that notifies when we are shutting-down.
scoped_ptr<base::WaitableEvent> shutdown_event_;
+ // Runs on the file thread and stats the inspector's directory, filling in
+ // have_inspector_files_ with the result.
+ void DoInspectorFilesCheck();
+ // Our best estimate about the existence of the inspector directory.
+ bool have_inspector_files_;
+
DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl);
};
diff --git a/chrome/browser/gtk/standard_menus.cc b/chrome/browser/gtk/standard_menus.cc
index a634f9d..e9863f4 100644
--- a/chrome/browser/gtk/standard_menus.cc
+++ b/chrome/browser/gtk/standard_menus.cc
@@ -10,6 +10,7 @@
#include "app/l10n_util.h"
#include "base/basictypes.h"
#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/encoding_menu_controller.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -36,6 +37,14 @@ struct MenuCreateMaterial developer_menu_materials[] = {
{ MENU_END }
};
+struct MenuCreateMaterial developer_menu_materials_no_inspector[] = {
+ { MENU_NORMAL, IDC_VIEW_SOURCE, IDS_VIEW_SOURCE, 0, NULL,
+ GDK_u, GDK_CONTROL_MASK },
+ { MENU_NORMAL, IDC_TASK_MANAGER, IDS_TASK_MANAGER, 0, NULL,
+ GDK_Escape, GDK_SHIFT_MASK },
+ { MENU_END }
+};
+
struct MenuCreateMaterial standard_page_menu_materials[] = {
{ MENU_NORMAL, IDC_CREATE_SHORTCUTS, IDS_CREATE_SHORTCUTS },
{ MENU_SEPARATOR },
@@ -52,8 +61,8 @@ struct MenuCreateMaterial standard_page_menu_materials[] = {
// The encoding menu submenu is filled in by code below.
{ MENU_NORMAL, IDC_ENCODING_MENU, IDS_ENCODING_MENU },
{ MENU_SEPARATOR },
- { MENU_NORMAL, IDC_DEVELOPER_MENU, IDS_DEVELOPER_MENU, 0,
- developer_menu_materials },
+ // The developer menu submenu is filled in by code below.
+ { MENU_NORMAL, IDC_DEVELOPER_MENU, IDS_DEVELOPER_MENU },
// The Report Bug menu hasn't been implemented yet. Remove it until it is.
// http://code.google.com/p/chromium/issues/detail?id=11600
@@ -106,7 +115,9 @@ const MenuCreateMaterial* GetStandardPageMenu(MenuGtk* encodings_menu) {
entry->type != MENU_END; ++entry) {
if (entry->id == IDC_ENCODING_MENU) {
entry->custom_submenu = encodings_menu;
- break;
+ } else if (entry->id == IDC_DEVELOPER_MENU) {
+ entry->submenu = g_browser_process->have_inspector_files() ?
+ developer_menu_materials : developer_menu_materials_no_inspector;
}
}
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 62cfdbc..c9fbea1 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -83,12 +83,15 @@ void RenderViewContextMenu::InitMenu(ContextNodeType node_type,
if (node_type.type & ContextNodeType::SELECTION)
AppendSearchProvider();
- AppendSeparator();
+
AppendDeveloperItems();
}
void RenderViewContextMenu::AppendDeveloperItems() {
- AppendMenuItem(IDS_CONTENT_CONTEXT_INSPECTELEMENT);
+ if (g_browser_process->have_inspector_files()) {
+ AppendSeparator();
+ AppendMenuItem(IDS_CONTENT_CONTEXT_INSPECTELEMENT);
+ }
}
void RenderViewContextMenu::AppendLinkItems() {
diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc
index 577ccfe..64ebc25 100644
--- a/chrome/browser/views/toolbar_view.cc
+++ b/chrome/browser/views/toolbar_view.cc
@@ -1043,8 +1043,10 @@ void ToolbarView::CreateDevToolsMenuContents() {
devtools_menu_contents_.reset(new views::SimpleMenuModel(this));
devtools_menu_contents_->AddItem(IDC_VIEW_SOURCE,
l10n_util::GetString(IDS_VIEW_SOURCE));
- devtools_menu_contents_->AddItem(IDC_DEV_TOOLS,
- l10n_util::GetString(IDS_DEV_TOOLS));
+ if (g_browser_process->have_inspector_files()) {
+ devtools_menu_contents_->AddItem(IDC_DEV_TOOLS,
+ l10n_util::GetString(IDS_DEV_TOOLS));
+ }
devtools_menu_contents_->AddItem(IDC_TASK_MANAGER,
l10n_util::GetString(IDS_TASK_MANAGER));
}
diff --git a/chrome/test/testing_browser_process.h b/chrome/test/testing_browser_process.h
index 2391a53..b4bc3fc 100644
--- a/chrome/test/testing_browser_process.h
+++ b/chrome/test/testing_browser_process.h
@@ -140,6 +140,9 @@ class TestingBrowserProcess : public BrowserProcess {
return shutdown_event_.get();
}
+ virtual void CheckForInspectorFiles() {}
+ virtual bool have_inspector_files() const { return true; }
+
private:
NotificationService notification_service_;
scoped_ptr<base::WaitableEvent> shutdown_event_;