Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 return host->extension(); |
| 647 return host->extension(); | |
| 648 } | |
| 649 } | |
| 650 } | 651 } |
| 651 | 652 |
| 652 return NULL; | 653 return NULL; |
| 653 } | 654 } |
| 654 | 655 |
| 655 void RenderViewContextMenu::AppendPlatformAppItems() { | 656 void RenderViewContextMenu::AppendPlatformAppItems( |
| 656 const Extension* platform_app = GetPlatformApp(); | 657 const Extension* platform_app) { |
| 657 DCHECK(platform_app); | 658 DCHECK(platform_app); |
| 658 int index = 0; | 659 int index = 0; |
| 659 AppendExtensionItems(platform_app->id(), &index); | 660 AppendExtensionItems(platform_app->id(), &index); |
| 661 | |
| 662 // Add dev tools for unpacked extensions. | |
| 663 if (platform_app->location() == Extension::LOAD) | |
| 664 AppendDeveloperItems(); | |
| 665 } | |
| 666 | |
| 667 void RenderViewContextMenu::AppendPopupExtensionItems() { | |
| 668 bool has_selection = !params_.selection_text.empty(); | |
| 669 | |
| 670 if (params_.is_editable) { | |
| 671 // Add a menu item that shows suggestions. | |
|
msw
2012/02/07 00:34:57
This block is copied from RenderViewContextMenu::I
benwells
2012/02/08 03:49:16
OK I've refactored it somewhat. There is still cod
| |
| 672 if (!spelling_menu_observer_.get()) { | |
|
msw
2012/02/07 00:34:57
repeat nit: Drop the braces for a single-line if b
benwells
2012/02/08 03:49:16
Yeah sorry that comment didn't make sense after th
| |
| 673 spelling_menu_observer_.reset(new SpellingMenuObserver(this)); | |
| 674 } | |
| 675 DCHECK(spelling_menu_observer_.get()); | |
| 676 observers_.AddObserver(spelling_menu_observer_.get()); | |
|
msw
2012/02/07 00:34:57
Can a RenderViewContextMenu be InitMenu'ed twice?
benwells
2012/02/08 03:49:16
I've removed the DCHECK. This doesn't change the l
| |
| 677 spelling_menu_observer_->InitMenu(params_); | |
| 678 AppendEditableItems(); | |
| 679 } else if (has_selection) { | |
| 680 AppendCopyItem(); | |
| 681 } | |
| 682 | |
| 683 if (has_selection) | |
| 684 AppendSearchProvider(); | |
| 685 | |
| 686 if (!IsDevToolsURL(params_.page_url)) | |
| 687 AppendAllExtensionItems(); | |
| 688 | |
| 689 AppendDeveloperItems(); | |
| 660 } | 690 } |
| 661 | 691 |
| 662 void RenderViewContextMenu::LookUpInDictionary() { | 692 void RenderViewContextMenu::LookUpInDictionary() { |
| 663 // Used only in the Mac port. | 693 // Used only in the Mac port. |
| 664 NOTREACHED(); | 694 NOTREACHED(); |
| 665 } | 695 } |
| 666 | 696 |
| 667 void RenderViewContextMenu::AddMenuItem(int command_id, | 697 void RenderViewContextMenu::AddMenuItem(int command_id, |
| 668 const string16& title) { | 698 const string16& title) { |
| 669 menu_model_.AddItem(command_id, title); | 699 menu_model_.AddItem(command_id, title); |
| (...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1865 if (view) | 1895 if (view) |
| 1866 view->ShowingContextMenu(false); | 1896 view->ShowingContextMenu(false); |
| 1867 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); | 1897 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); |
| 1868 if (rvh) { | 1898 if (rvh) { |
| 1869 rvh->NotifyContextMenuClosed(params_.custom_context); | 1899 rvh->NotifyContextMenuClosed(params_.custom_context); |
| 1870 } | 1900 } |
| 1871 } | 1901 } |
| 1872 | 1902 |
| 1873 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { | 1903 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { |
| 1874 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) { | 1904 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) { |
| 1875 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 1905 // Don't enable the web inspector if JavaScript is disabled. We don't |
| 1876 TabContentsWrapper* tab_contents_wrapper = | 1906 // check this when this is the web contents of an extension (e.g. |
| 1877 TabContentsWrapper::GetCurrentWrapperForContents( | 1907 // for a popup extension or a platform app) as they have JavaScript |
| 1878 source_web_contents_); | 1908 // always enabled. |
| 1879 if (!tab_contents_wrapper) | 1909 const Extension* extension = GetExtension(); |
| 1880 return false; | 1910 if (!extension) { |
| 1881 // Don't enable the web inspector if JavaScript is disabled. | 1911 TabContentsWrapper* contents_wrapper = |
| 1882 if (!tab_contents_wrapper->prefs_tab_helper()->per_tab_prefs()->GetBoolean( | 1912 TabContentsWrapper::GetCurrentWrapperForContents( |
| 1883 prefs::kWebKitJavascriptEnabled) || | 1913 source_web_contents_); |
| 1884 command_line.HasSwitch(switches::kDisableJavaScript)) | 1914 if (!contents_wrapper) |
| 1885 return false; | 1915 return false; |
| 1916 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 1917 if (!contents_wrapper->prefs_tab_helper()->per_tab_prefs()->GetBoolean( | |
| 1918 prefs::kWebKitJavascriptEnabled) || | |
| 1919 command_line->HasSwitch(switches::kDisableJavaScript)) | |
| 1920 return false; | |
| 1921 #if !defined(TOOLKIT_VIEWS) | |
| 1922 } else { | |
| 1923 // Disable dev tools for popup extensions for non-views builds, as the | |
| 1924 // extension popups for these builds do not support dynamically inspecting | |
| 1925 // the popups. | |
| 1926 // TODO(benwells): Add support for these builds and remove this #if. | |
| 1927 if (!extension->is_platform_app()) | |
| 1928 return false; | |
| 1929 #endif | |
| 1930 } | |
| 1931 | |
| 1886 // Don't enable the web inspector if the developer tools are disabled via | 1932 // Don't enable the web inspector if the developer tools are disabled via |
| 1887 // the preference dev-tools-disabled. | 1933 // the preference dev-tools-disabled. |
| 1888 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) | 1934 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
| 1889 return false; | 1935 return false; |
| 1890 } | 1936 } |
| 1891 | 1937 |
| 1892 return true; | 1938 return true; |
| 1893 } | 1939 } |
| 1894 | 1940 |
| 1895 string16 RenderViewContextMenu::PrintableSelectionText() { | 1941 string16 RenderViewContextMenu::PrintableSelectionText() { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1945 source_web_contents_->GetRenderViewHost()-> | 1991 source_web_contents_->GetRenderViewHost()-> |
| 1946 ExecuteMediaPlayerActionAtLocation(location, action); | 1992 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1947 } | 1993 } |
| 1948 | 1994 |
| 1949 void RenderViewContextMenu::PluginActionAt( | 1995 void RenderViewContextMenu::PluginActionAt( |
| 1950 const gfx::Point& location, | 1996 const gfx::Point& location, |
| 1951 const WebPluginAction& action) { | 1997 const WebPluginAction& action) { |
| 1952 source_web_contents_->GetRenderViewHost()-> | 1998 source_web_contents_->GetRenderViewHost()-> |
| 1953 ExecutePluginActionAtLocation(location, action); | 1999 ExecutePluginActionAtLocation(location, action); |
| 1954 } | 2000 } |
| OLD | NEW |