Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(752)

Side by Side Diff: chrome/browser/tab_contents/render_view_context_menu.cc

Issue 10907243: Add "inspect background page" to platform app right-click menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <utility> 7 #include <utility>
8 8
9 #include "chrome/browser/tab_contents/render_view_context_menu.h" 9 #include "chrome/browser/tab_contents/render_view_context_menu.h"
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "chrome/app/chrome_command_ids.h" 18 #include "chrome/app/chrome_command_ids.h"
19 #include "chrome/browser/api/prefs/pref_member.h" 19 #include "chrome/browser/api/prefs/pref_member.h"
20 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 20 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
21 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 21 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
22 #include "chrome/browser/autocomplete/autocomplete_match.h" 22 #include "chrome/browser/autocomplete/autocomplete_match.h"
23 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/debugger/devtools_window.h" 24 #include "chrome/browser/debugger/devtools_window.h"
25 #include "chrome/browser/download/download_service.h" 25 #include "chrome/browser/download/download_service.h"
26 #include "chrome/browser/download/download_service_factory.h" 26 #include "chrome/browser/download/download_service_factory.h"
27 #include "chrome/browser/download/download_util.h" 27 #include "chrome/browser/download/download_util.h"
28 #include "chrome/browser/extensions/extension_host.h"
28 #include "chrome/browser/extensions/extension_service.h" 29 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/extensions/extension_system.h" 30 #include "chrome/browser/extensions/extension_system.h"
30 #include "chrome/browser/google/google_util.h" 31 #include "chrome/browser/google/google_util.h"
31 #include "chrome/browser/prefs/incognito_mode_prefs.h" 32 #include "chrome/browser/prefs/incognito_mode_prefs.h"
32 #include "chrome/browser/prefs/pref_service.h" 33 #include "chrome/browser/prefs/pref_service.h"
33 #include "chrome/browser/printing/print_preview_context_menu_observer.h" 34 #include "chrome/browser/printing/print_preview_context_menu_observer.h"
34 #include "chrome/browser/printing/print_preview_tab_controller.h" 35 #include "chrome/browser/printing/print_preview_tab_controller.h"
35 #include "chrome/browser/printing/print_view_manager.h" 36 #include "chrome/browser/printing/print_view_manager.h"
36 #include "chrome/browser/profiles/profile.h" 37 #include "chrome/browser/profiles/profile.h"
37 #include "chrome/browser/profiles/profile_io_data.h" 38 #include "chrome/browser/profiles/profile_io_data.h"
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 else if (has_selection) 668 else if (has_selection)
668 AppendCopyItem(); 669 AppendCopyItem();
669 670
670 int index = 0; 671 int index = 0;
671 AppendExtensionItems(platform_app->id(), &index); 672 AppendExtensionItems(platform_app->id(), &index);
672 673
673 // Add dev tools for unpacked extensions. 674 // Add dev tools for unpacked extensions.
674 if (platform_app->location() == Extension::LOAD) { 675 if (platform_app->location() == Extension::LOAD) {
675 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); 676 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD);
676 AppendDeveloperItems(); 677 AppendDeveloperItems();
678 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE,
679 IDS_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE);
677 } 680 }
678 } 681 }
679 682
680 void RenderViewContextMenu::AppendPopupExtensionItems() { 683 void RenderViewContextMenu::AppendPopupExtensionItems() {
681 bool has_selection = !params_.selection_text.empty(); 684 bool has_selection = !params_.selection_text.empty();
682 685
683 if (params_.is_editable) 686 if (params_.is_editable)
684 AppendEditableItems(); 687 AppendEditableItems();
685 else if (has_selection) 688 else if (has_selection)
686 AppendCopyItem(); 689 AppendCopyItem();
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 CoreTabHelperDelegate* core_delegate = 1159 CoreTabHelperDelegate* core_delegate =
1157 tab_contents->core_tab_helper()->delegate(); 1160 tab_contents->core_tab_helper()->delegate();
1158 return !core_delegate || core_delegate->CanReloadContents(tab_contents); 1161 return !core_delegate || core_delegate->CanReloadContents(tab_contents);
1159 } 1162 }
1160 1163
1161 case IDC_VIEW_SOURCE: 1164 case IDC_VIEW_SOURCE:
1162 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE: 1165 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE:
1163 return source_web_contents_->GetController().CanViewSource(); 1166 return source_web_contents_->GetController().CanViewSource();
1164 1167
1165 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: 1168 case IDC_CONTENT_CONTEXT_INSPECTELEMENT:
1169 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE:
1166 return IsDevCommandEnabled(id); 1170 return IsDevCommandEnabled(id);
1167 1171
1168 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: 1172 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO:
1169 if (source_web_contents_->GetController().GetActiveEntry() == NULL) 1173 if (source_web_contents_->GetController().GetActiveEntry() == NULL)
1170 return false; 1174 return false;
1171 // Disabled if no browser is associated (e.g. desktop notifications). 1175 // Disabled if no browser is associated (e.g. desktop notifications).
1172 if (browser::FindBrowserWithWebContents(source_web_contents_) == NULL) 1176 if (browser::FindBrowserWithWebContents(source_web_contents_) == NULL)
1173 return false; 1177 return false;
1174 return true; 1178 return true;
1175 1179
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 break; 1729 break;
1726 1730
1727 case IDC_VIEW_SOURCE: 1731 case IDC_VIEW_SOURCE:
1728 source_web_contents_->ViewSource(); 1732 source_web_contents_->ViewSource();
1729 break; 1733 break;
1730 1734
1731 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: 1735 case IDC_CONTENT_CONTEXT_INSPECTELEMENT:
1732 Inspect(params_.x, params_.y); 1736 Inspect(params_.x, params_.y);
1733 break; 1737 break;
1734 1738
1739 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE: {
1740 const Extension* platform_app = GetExtension();
1741 DCHECK(platform_app);
1742 DCHECK(platform_app->is_platform_app());
1743
1744 extensions::ExtensionHost* host = profile_->GetExtensionProcessManager()->
1745 GetBackgroundHostForExtension(platform_app->id());
1746 DCHECK(host);
Marijn Kruisselbrink 2012/09/14 21:15:18 Antony: is this safe, or are there possible situat
asargent_no_longer_on_chrome 2012/09/14 21:57:41 Let's refactor out the C++ code that the chrome://
1747
1748 DevToolsWindow::OpenDevToolsWindow(host->render_view_host());
1749 break;
1750 }
1751
1735 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: { 1752 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: {
1736 NavigationController* controller = &source_web_contents_->GetController(); 1753 NavigationController* controller = &source_web_contents_->GetController();
1737 NavigationEntry* nav_entry = controller->GetActiveEntry(); 1754 NavigationEntry* nav_entry = controller->GetActiveEntry();
1738 Browser* browser = 1755 Browser* browser =
1739 browser::FindBrowserWithWebContents(source_web_contents_); 1756 browser::FindBrowserWithWebContents(source_web_contents_);
1740 chrome::ShowPageInfo(browser, source_web_contents_, nav_entry->GetURL(), 1757 chrome::ShowPageInfo(browser, source_web_contents_, nav_entry->GetURL(),
1741 nav_entry->GetSSL(), true); 1758 nav_entry->GetSSL(), true);
1742 break; 1759 break;
1743 } 1760 }
1744 1761
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 rvh->NotifyContextMenuClosed(params_.custom_context); 1966 rvh->NotifyContextMenuClosed(params_.custom_context);
1950 } 1967 }
1951 1968
1952 content::NotificationService::current()->Notify( 1969 content::NotificationService::current()->Notify(
1953 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_CLOSED, 1970 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_CLOSED,
1954 content::Source<RenderViewContextMenu>(this), 1971 content::Source<RenderViewContextMenu>(this),
1955 content::NotificationService::NoDetails()); 1972 content::NotificationService::NoDetails());
1956 } 1973 }
1957 1974
1958 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { 1975 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const {
1959 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) { 1976 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT ||
1977 id == IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE) {
1960 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 1978 const CommandLine* command_line = CommandLine::ForCurrentProcess();
1961 if (!profile_->GetPrefs()->GetBoolean(prefs::kWebKitJavascriptEnabled) || 1979 if (!profile_->GetPrefs()->GetBoolean(prefs::kWebKitJavascriptEnabled) ||
1962 command_line->HasSwitch(switches::kDisableJavaScript)) 1980 command_line->HasSwitch(switches::kDisableJavaScript))
1963 return false; 1981 return false;
1964 1982
1965 // Don't enable the web inspector if the developer tools are disabled via 1983 // Don't enable the web inspector if the developer tools are disabled via
1966 // the preference dev-tools-disabled. 1984 // the preference dev-tools-disabled.
1967 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) 1985 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
1968 return false; 1986 return false;
1969 } 1987 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 source_web_contents_->GetRenderViewHost()-> 2042 source_web_contents_->GetRenderViewHost()->
2025 ExecuteMediaPlayerActionAtLocation(location, action); 2043 ExecuteMediaPlayerActionAtLocation(location, action);
2026 } 2044 }
2027 2045
2028 void RenderViewContextMenu::PluginActionAt( 2046 void RenderViewContextMenu::PluginActionAt(
2029 const gfx::Point& location, 2047 const gfx::Point& location,
2030 const WebPluginAction& action) { 2048 const WebPluginAction& action) {
2031 source_web_contents_->GetRenderViewHost()-> 2049 source_web_contents_->GetRenderViewHost()->
2032 ExecutePluginActionAtLocation(location, action); 2050 ExecutePluginActionAtLocation(location, action);
2033 } 2051 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698