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

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

Issue 9235002: Enable devtools via context menu in platform apps and popup extensions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Menu for popup extensions Created 8 years, 10 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
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
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 for (i = sorted_ids.begin(); 518 for (i = sorted_ids.begin();
519 i != sorted_ids.end(); ++i) { 519 i != sorted_ids.end(); ++i) {
520 AppendExtensionItems(i->second, &index); 520 AppendExtensionItems(i->second, &index);
521 } 521 }
522 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", 522 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime",
523 base::TimeTicks::Now() - begin); 523 base::TimeTicks::Now() - begin);
524 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); 524 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index);
525 } 525 }
526 526
527 void RenderViewContextMenu::InitMenu() { 527 void RenderViewContextMenu::InitMenu() {
528 if (GetPlatformApp()) { 528 const Extension* extension = GetExtension();
529 AppendPlatformAppItems(); 529 if (extension) {
530 if (extension->is_platform_app())
531 AppendPlatformAppItems(extension);
532 else
533 AppendPopupExtensionItems();
530 return; 534 return;
531 } 535 }
532 536
533 bool has_link = !params_.unfiltered_link_url.is_empty(); 537 bool has_link = !params_.unfiltered_link_url.is_empty();
534 bool has_selection = !params_.selection_text.empty(); 538 bool has_selection = !params_.selection_text.empty();
535 539
536 if (AppendCustomItems()) { 540 if (AppendCustomItems()) {
537 // If there's a selection, don't early return when there are custom items, 541 // If there's a selection, don't early return when there are custom items,
538 // but fall through to adding the normal ones after the custom ones. 542 // but fall through to adding the normal ones after the custom ones.
539 if (has_selection) { 543 if (has_selection) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 627
624 if (!print_preview_menu_observer_.get()) { 628 if (!print_preview_menu_observer_.get()) {
625 TabContentsWrapper* wrapper = 629 TabContentsWrapper* wrapper =
626 TabContentsWrapper::GetCurrentWrapperForContents(source_web_contents_); 630 TabContentsWrapper::GetCurrentWrapperForContents(source_web_contents_);
627 print_preview_menu_observer_.reset( 631 print_preview_menu_observer_.reset(
628 new PrintPreviewContextMenuObserver(wrapper)); 632 new PrintPreviewContextMenuObserver(wrapper));
629 } 633 }
630 observers_.AddObserver(print_preview_menu_observer_.get()); 634 observers_.AddObserver(print_preview_menu_observer_.get());
631 } 635 }
632 636
633 const Extension* RenderViewContextMenu::GetPlatformApp() const { 637 const Extension* RenderViewContextMenu::GetExtension() const {
634 ExtensionProcessManager* process_manager = 638 ExtensionProcessManager* process_manager =
635 profile_->GetExtensionProcessManager(); 639 profile_->GetExtensionProcessManager();
636 // There is no process manager in some tests. 640 // There is no process manager in some tests.
637 if (!process_manager) { 641 if (!process_manager) {
638 return NULL; 642 return NULL;
639 } 643 }
640 644
641 ExtensionProcessManager::const_iterator iter; 645 ExtensionProcessManager::const_iterator iter;
642 for (iter = process_manager->begin(); iter != process_manager->end(); 646 for (iter = process_manager->begin(); iter != process_manager->end();
643 ++iter) { 647 ++iter) {
644 ExtensionHost* host = *iter; 648 ExtensionHost* host = *iter;
645 if (host->host_contents() == source_web_contents_) { 649 if (host->host_contents() == source_web_contents_) {
646 if (host->extension() && host->extension()->is_platform_app()) { 650 const Extension* extension = host->extension();
msw 2012/02/03 07:57:24 Why not just return host->extension(); here? The N
benwells 2012/02/06 03:40:46 Done.
647 return host->extension(); 651 if (extension)
648 } 652 return extension;
653 return NULL;
649 } 654 }
650 } 655 }
651 656
652 return NULL; 657 return NULL;
653 } 658 }
654 659
655 void RenderViewContextMenu::AppendPlatformAppItems() { 660 void RenderViewContextMenu::AppendPlatformAppItems(
656 const Extension* platform_app = GetPlatformApp(); 661 const Extension* platform_app) {
657 DCHECK(platform_app); 662 DCHECK(platform_app);
658 int index = 0; 663 int index = 0;
659 AppendExtensionItems(platform_app->id(), &index); 664 AppendExtensionItems(platform_app->id(), &index);
665
666 // Add dev tools for unpacked extensions.
667 if (platform_app->location() == Extension::LOAD)
668 AppendDeveloperItems();
669 }
670
671 void RenderViewContextMenu::AppendPopupExtensionItems() {
672 bool has_selection = !params_.selection_text.empty();
673
674 if (params_.is_editable) {
675 // Add a menu item that shows suggestions.
676 if (!spelling_menu_observer_.get()) {
msw 2012/02/03 07:57:24 nit: Drop the braces for a single-line if block.
benwells 2012/02/06 03:40:46 Needs braces after change for next comment.
677 spelling_menu_observer_.reset(new SpellingMenuObserver(this));
678 }
679 if (spelling_menu_observer_.get()) {
msw 2012/02/03 07:57:24 Is this check necessary? The above conditional ens
benwells 2012/02/06 03:40:46 I put in an else.
benwells 2012/02/06 04:31:27 Arg, just reread the original code. Will fix as su
680 observers_.AddObserver(spelling_menu_observer_.get());
681 spelling_menu_observer_->InitMenu(params_);
682 }
683 }
684
685 if (params_.is_editable)
msw 2012/02/03 07:57:24 There's an if (params_.is_editable) block just abo
benwells 2012/02/06 03:40:46 Done.
686 AppendEditableItems();
687 else if (has_selection)
688 AppendCopyItem();
689
690 if (has_selection)
691 AppendSearchProvider();
692
693 if (!IsDevToolsURL(params_.page_url))
694 AppendAllExtensionItems();
695
696 AppendDeveloperItems();
660 } 697 }
661 698
662 void RenderViewContextMenu::LookUpInDictionary() { 699 void RenderViewContextMenu::LookUpInDictionary() {
663 // Used only in the Mac port. 700 // Used only in the Mac port.
664 NOTREACHED(); 701 NOTREACHED();
665 } 702 }
666 703
667 void RenderViewContextMenu::AddMenuItem(int command_id, 704 void RenderViewContextMenu::AddMenuItem(int command_id,
668 const string16& title) { 705 const string16& title) {
669 menu_model_.AddItem(command_id, title); 706 menu_model_.AddItem(command_id, title);
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1865 if (view) 1902 if (view)
1866 view->ShowingContextMenu(false); 1903 view->ShowingContextMenu(false);
1867 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); 1904 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost();
1868 if (rvh) { 1905 if (rvh) {
1869 rvh->NotifyContextMenuClosed(params_.custom_context); 1906 rvh->NotifyContextMenuClosed(params_.custom_context);
1870 } 1907 }
1871 } 1908 }
1872 1909
1873 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { 1910 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const {
1874 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) { 1911 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) {
1875 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 1912 // Don't enable the web inspector if JavaScript is disabled. We don't
msw 2012/02/03 07:57:24 Why skip these checks for extensions? I prefer cod
benwells 2012/02/06 03:40:46 The code below doesn't work for popup extensions o
1876 TabContentsWrapper* tab_contents_wrapper = 1913 // check this when this is the web contents of an extension (e.g.
1877 TabContentsWrapper::GetCurrentWrapperForContents( 1914 // for a popup extension or a platform app) as they have JavaScript
1878 source_web_contents_); 1915 // always enabled.
1879 if (!tab_contents_wrapper) 1916 const Extension* extension = GetExtension();
1880 return false; 1917 if (!extension) {
1881 // Don't enable the web inspector if JavaScript is disabled. 1918 TabContentsWrapper* contents_wrapper =
1882 if (!tab_contents_wrapper->prefs_tab_helper()->per_tab_prefs()->GetBoolean( 1919 TabContentsWrapper::GetCurrentWrapperForContents(
1883 prefs::kWebKitJavascriptEnabled) || 1920 source_web_contents_);
1884 command_line.HasSwitch(switches::kDisableJavaScript)) 1921 if (!contents_wrapper)
1885 return false; 1922 return false;
1923 const CommandLine* command_line = CommandLine::ForCurrentProcess();
1924 if (!contents_wrapper->prefs_tab_helper()->per_tab_prefs()->GetBoolean(
1925 prefs::kWebKitJavascriptEnabled) ||
1926 command_line->HasSwitch(switches::kDisableJavaScript))
1927 return false;
1928 #if defined(TOOLKIT_GTK) || defined(OS_MAC)
msw 2012/02/03 07:57:24 Instead, check #if !defined(TOOLKIT_VIEWS)
benwells 2012/02/06 03:40:46 Done.
1929 } else {
1930 // Disable dev tools for popup extensions for non-views builds, as the
1931 // extension popups for these builds do not support dynamically inspecting
1932 // the popups.
1933 // TODO(benwells): Add support for these builds and remote this #if.
msw 2012/02/03 07:57:24 s/remote/remove
benwells 2012/02/06 03:40:46 Done.
1934 if (!extension->is_app())
1935 return false;
1936 #endif
1937 }
1938
1886 // Don't enable the web inspector if the developer tools are disabled via 1939 // Don't enable the web inspector if the developer tools are disabled via
1887 // the preference dev-tools-disabled. 1940 // the preference dev-tools-disabled.
1888 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) 1941 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
1889 return false; 1942 return false;
1890 } 1943 }
1891 1944
1892 return true; 1945 return true;
1893 } 1946 }
1894 1947
1895 string16 RenderViewContextMenu::PrintableSelectionText() { 1948 string16 RenderViewContextMenu::PrintableSelectionText() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 source_web_contents_->GetRenderViewHost()-> 1998 source_web_contents_->GetRenderViewHost()->
1946 ExecuteMediaPlayerActionAtLocation(location, action); 1999 ExecuteMediaPlayerActionAtLocation(location, action);
1947 } 2000 }
1948 2001
1949 void RenderViewContextMenu::PluginActionAt( 2002 void RenderViewContextMenu::PluginActionAt(
1950 const gfx::Point& location, 2003 const gfx::Point& location,
1951 const WebPluginAction& action) { 2004 const WebPluginAction& action) {
1952 source_web_contents_->GetRenderViewHost()-> 2005 source_web_contents_->GetRenderViewHost()->
1953 ExecutePluginActionAtLocation(location, action); 2006 ExecutePluginActionAtLocation(location, action);
1954 } 2007 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698