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

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: fix comment in test 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
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::ExtensionSystem::Get(profile_)->extension_service()->
1745 InspectBackgroundPage(platform_app);
1746 break;
1747 }
1748
1735 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: { 1749 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: {
1736 NavigationController* controller = &source_web_contents_->GetController(); 1750 NavigationController* controller = &source_web_contents_->GetController();
1737 NavigationEntry* nav_entry = controller->GetActiveEntry(); 1751 NavigationEntry* nav_entry = controller->GetActiveEntry();
1738 Browser* browser = 1752 Browser* browser =
1739 browser::FindBrowserWithWebContents(source_web_contents_); 1753 browser::FindBrowserWithWebContents(source_web_contents_);
1740 chrome::ShowPageInfo(browser, source_web_contents_, nav_entry->GetURL(), 1754 chrome::ShowPageInfo(browser, source_web_contents_, nav_entry->GetURL(),
1741 nav_entry->GetSSL(), true); 1755 nav_entry->GetSSL(), true);
1742 break; 1756 break;
1743 } 1757 }
1744 1758
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 rvh->NotifyContextMenuClosed(params_.custom_context); 1963 rvh->NotifyContextMenuClosed(params_.custom_context);
1950 } 1964 }
1951 1965
1952 content::NotificationService::current()->Notify( 1966 content::NotificationService::current()->Notify(
1953 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_CLOSED, 1967 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_CLOSED,
1954 content::Source<RenderViewContextMenu>(this), 1968 content::Source<RenderViewContextMenu>(this),
1955 content::NotificationService::NoDetails()); 1969 content::NotificationService::NoDetails());
1956 } 1970 }
1957 1971
1958 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { 1972 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const {
1959 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) { 1973 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT ||
1974 id == IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE) {
1960 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 1975 const CommandLine* command_line = CommandLine::ForCurrentProcess();
1961 if (!profile_->GetPrefs()->GetBoolean(prefs::kWebKitJavascriptEnabled) || 1976 if (!profile_->GetPrefs()->GetBoolean(prefs::kWebKitJavascriptEnabled) ||
1962 command_line->HasSwitch(switches::kDisableJavaScript)) 1977 command_line->HasSwitch(switches::kDisableJavaScript))
1963 return false; 1978 return false;
1964 1979
1965 // Don't enable the web inspector if the developer tools are disabled via 1980 // Don't enable the web inspector if the developer tools are disabled via
1966 // the preference dev-tools-disabled. 1981 // the preference dev-tools-disabled.
1967 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) 1982 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
1968 return false; 1983 return false;
1969 } 1984 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 source_web_contents_->GetRenderViewHost()-> 2039 source_web_contents_->GetRenderViewHost()->
2025 ExecuteMediaPlayerActionAtLocation(location, action); 2040 ExecuteMediaPlayerActionAtLocation(location, action);
2026 } 2041 }
2027 2042
2028 void RenderViewContextMenu::PluginActionAt( 2043 void RenderViewContextMenu::PluginActionAt(
2029 const gfx::Point& location, 2044 const gfx::Point& location,
2030 const WebPluginAction& action) { 2045 const WebPluginAction& action) {
2031 source_web_contents_->GetRenderViewHost()-> 2046 source_web_contents_->GetRenderViewHost()->
2032 ExecutePluginActionAtLocation(location, action); 2047 ExecutePluginActionAtLocation(location, action);
2033 } 2048 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698