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

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: Updated for feedback Created 8 years, 11 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 && extension->is_platform_app()) {
530 AppendPlatformAppItems(extension);
530 return; 531 return;
531 } 532 }
532 533
533 bool has_link = !params_.unfiltered_link_url.is_empty(); 534 bool has_link = !params_.unfiltered_link_url.is_empty();
534 bool has_selection = !params_.selection_text.empty(); 535 bool has_selection = !params_.selection_text.empty();
535 536
536 if (AppendCustomItems()) { 537 if (AppendCustomItems()) {
537 // If there's a selection, don't early return when there are custom items, 538 // 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. 539 // but fall through to adding the normal ones after the custom ones.
539 if (has_selection) { 540 if (has_selection) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 624
624 if (!print_preview_menu_observer_.get()) { 625 if (!print_preview_menu_observer_.get()) {
625 TabContentsWrapper* wrapper = 626 TabContentsWrapper* wrapper =
626 TabContentsWrapper::GetCurrentWrapperForContents(source_web_contents_); 627 TabContentsWrapper::GetCurrentWrapperForContents(source_web_contents_);
627 print_preview_menu_observer_.reset( 628 print_preview_menu_observer_.reset(
628 new PrintPreviewContextMenuObserver(wrapper)); 629 new PrintPreviewContextMenuObserver(wrapper));
629 } 630 }
630 observers_.AddObserver(print_preview_menu_observer_.get()); 631 observers_.AddObserver(print_preview_menu_observer_.get());
631 } 632 }
632 633
633 const Extension* RenderViewContextMenu::GetPlatformApp() const { 634 const Extension* RenderViewContextMenu::GetExtension() const {
634 ExtensionProcessManager* process_manager = 635 ExtensionProcessManager* process_manager =
635 profile_->GetExtensionProcessManager(); 636 profile_->GetExtensionProcessManager();
636 // There is no process manager in some tests. 637 // There is no process manager in some tests.
637 if (!process_manager) { 638 if (!process_manager) {
638 return NULL; 639 return NULL;
639 } 640 }
640 641
641 ExtensionProcessManager::const_iterator iter; 642 ExtensionProcessManager::const_iterator iter;
642 for (iter = process_manager->begin(); iter != process_manager->end(); 643 for (iter = process_manager->begin(); iter != process_manager->end();
643 ++iter) { 644 ++iter) {
644 ExtensionHost* host = *iter; 645 ExtensionHost* host = *iter;
645 if (host->host_contents() == source_web_contents_) { 646 if (host->host_contents() == source_web_contents_) {
646 if (host->extension() && host->extension()->is_platform_app()) { 647 const Extension* extension = host->extension();
647 return host->extension(); 648 if (extension)
648 } 649 return extension;
650 return NULL;
649 } 651 }
650 } 652 }
651 653
652 return NULL; 654 return NULL;
653 } 655 }
654 656
655 void RenderViewContextMenu::AppendPlatformAppItems() { 657 void RenderViewContextMenu::AppendPlatformAppItems(
656 const Extension* platform_app = GetPlatformApp(); 658 const Extension* platform_app) {
657 DCHECK(platform_app); 659 DCHECK(platform_app);
658 int index = 0; 660 int index = 0;
659 AppendExtensionItems(platform_app->id(), &index); 661 AppendExtensionItems(platform_app->id(), &index);
662
663 // Add dev tools for unpacked extensions.
664 if (platform_app->location() == Extension::LOAD)
665 AppendDeveloperItems();
660 } 666 }
661 667
662 void RenderViewContextMenu::LookUpInDictionary() { 668 void RenderViewContextMenu::LookUpInDictionary() {
663 // Used only in the Mac port. 669 // Used only in the Mac port.
664 NOTREACHED(); 670 NOTREACHED();
665 } 671 }
666 672
667 void RenderViewContextMenu::AddMenuItem(int command_id, 673 void RenderViewContextMenu::AddMenuItem(int command_id,
668 const string16& title) { 674 const string16& title) {
669 menu_model_.AddItem(command_id, title); 675 menu_model_.AddItem(command_id, title);
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 if (view) 1861 if (view)
1856 view->ShowingContextMenu(false); 1862 view->ShowingContextMenu(false);
1857 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); 1863 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost();
1858 if (rvh) { 1864 if (rvh) {
1859 rvh->NotifyContextMenuClosed(params_.custom_context); 1865 rvh->NotifyContextMenuClosed(params_.custom_context);
1860 } 1866 }
1861 } 1867 }
1862 1868
1863 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { 1869 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const {
1864 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) { 1870 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) {
1865 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 1871 // Don't enable the web inspector if JavaScript is disabled. We don't
1866 TabContentsWrapper* tab_contents_wrapper = 1872 // check this when this is the web contents of an extension (e.g.
1867 TabContentsWrapper::GetCurrentWrapperForContents( 1873 // for a popup extension or a platform app) as they have javascript
Mihai Parparita -not on Chrome 2012/01/23 23:17:29 Nit: Capitalize JavaScript.
benwells 2012/01/27 07:15:58 Done.
1868 source_web_contents_); 1874 // always enabled.
1869 if (!tab_contents_wrapper) 1875 if (!GetExtension()) {
1870 return false; 1876 TabContentsWrapper* contents_wrapper =
1871 // Don't enable the web inspector if JavaScript is disabled. 1877 TabContentsWrapper::GetCurrentWrapperForContents(
1872 if (!tab_contents_wrapper->prefs_tab_helper()->per_tab_prefs()->GetBoolean( 1878 source_web_contents_);
1873 prefs::kWebKitJavascriptEnabled) || 1879 if (!contents_wrapper)
1874 command_line.HasSwitch(switches::kDisableJavaScript)) 1880 return false;
1875 return false; 1881 const CommandLine* command_line = CommandLine::ForCurrentProcess();
1882 if (!contents_wrapper->prefs_tab_helper()->per_tab_prefs()->GetBoolean(
1883 prefs::kWebKitJavascriptEnabled) ||
1884 command_line->HasSwitch(switches::kDisableJavaScript))
1885 return false;
1886 }
1887
1876 // Don't enable the web inspector if the developer tools are disabled via 1888 // Don't enable the web inspector if the developer tools are disabled via
1877 // the preference dev-tools-disabled. 1889 // the preference dev-tools-disabled.
1878 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) 1890 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
1879 return false; 1891 return false;
1880 } 1892 }
1881 1893
1882 return true; 1894 return true;
1883 } 1895 }
1884 1896
1885 string16 RenderViewContextMenu::PrintableSelectionText() { 1897 string16 RenderViewContextMenu::PrintableSelectionText() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 source_web_contents_->GetRenderViewHost()-> 1947 source_web_contents_->GetRenderViewHost()->
1936 ExecuteMediaPlayerActionAtLocation(location, action); 1948 ExecuteMediaPlayerActionAtLocation(location, action);
1937 } 1949 }
1938 1950
1939 void RenderViewContextMenu::PluginActionAt( 1951 void RenderViewContextMenu::PluginActionAt(
1940 const gfx::Point& location, 1952 const gfx::Point& location,
1941 const WebPluginAction& action) { 1953 const WebPluginAction& action) {
1942 source_web_contents_->GetRenderViewHost()-> 1954 source_web_contents_->GetRenderViewHost()->
1943 ExecutePluginActionAtLocation(location, action); 1955 ExecutePluginActionAtLocation(location, action);
1944 } 1956 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu.h ('k') | chrome/browser/ui/views/extensions/extension_popup.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698