| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include "chrome/browser/tab_contents/spelling_menu_observer.h" | 46 #include "chrome/browser/tab_contents/spelling_menu_observer.h" |
| 47 #include "chrome/browser/translate/translate_manager.h" | 47 #include "chrome/browser/translate/translate_manager.h" |
| 48 #include "chrome/browser/translate/translate_prefs.h" | 48 #include "chrome/browser/translate/translate_prefs.h" |
| 49 #include "chrome/browser/translate/translate_tab_helper.h" | 49 #include "chrome/browser/translate/translate_tab_helper.h" |
| 50 #include "chrome/browser/ui/browser.h" | 50 #include "chrome/browser/ui/browser.h" |
| 51 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" | 51 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
| 52 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 52 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 53 #include "chrome/common/chrome_constants.h" | 53 #include "chrome/common/chrome_constants.h" |
| 54 #include "chrome/common/chrome_notification_types.h" | 54 #include "chrome/common/chrome_notification_types.h" |
| 55 #include "chrome/common/chrome_switches.h" | 55 #include "chrome/common/chrome_switches.h" |
| 56 #include "chrome/common/chrome_view_type.h" |
| 56 #include "chrome/common/extensions/extension.h" | 57 #include "chrome/common/extensions/extension.h" |
| 57 #include "chrome/common/pref_names.h" | 58 #include "chrome/common/pref_names.h" |
| 58 #include "chrome/common/print_messages.h" | 59 #include "chrome/common/print_messages.h" |
| 59 #include "chrome/common/spellcheck_messages.h" | 60 #include "chrome/common/spellcheck_messages.h" |
| 60 #include "chrome/common/url_constants.h" | 61 #include "chrome/common/url_constants.h" |
| 61 #include "content/public/browser/child_process_security_policy.h" | 62 #include "content/public/browser/child_process_security_policy.h" |
| 62 #include "content/public/browser/download_manager.h" | 63 #include "content/public/browser/download_manager.h" |
| 63 #include "content/public/browser/download_save_info.h" | 64 #include "content/public/browser/download_save_info.h" |
| 64 #include "content/public/browser/navigation_details.h" | 65 #include "content/public/browser/navigation_details.h" |
| 65 #include "content/public/browser/navigation_entry.h" | 66 #include "content/public/browser/navigation_entry.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 for (i = sorted_ids.begin(); | 518 for (i = sorted_ids.begin(); |
| 518 i != sorted_ids.end(); ++i) { | 519 i != sorted_ids.end(); ++i) { |
| 519 AppendExtensionItems(i->second, &index); | 520 AppendExtensionItems(i->second, &index); |
| 520 } | 521 } |
| 521 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | 522 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", |
| 522 base::TimeTicks::Now() - begin); | 523 base::TimeTicks::Now() - begin); |
| 523 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | 524 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); |
| 524 } | 525 } |
| 525 | 526 |
| 526 void RenderViewContextMenu::InitMenu() { | 527 void RenderViewContextMenu::InitMenu() { |
| 527 const Extension* extension = GetExtension(); | 528 content::ViewType view_type = source_web_contents_->GetViewType(); |
| 528 if (extension) { | 529 if (view_type == chrome::VIEW_TYPE_APP_SHELL) { |
| 529 if (extension->is_platform_app()) | 530 AppendPlatformAppItems(); |
| 530 AppendPlatformAppItems(extension); | 531 return; |
| 531 else | 532 } else if (view_type == chrome::VIEW_TYPE_EXTENSION_POPUP) { |
| 532 AppendPopupExtensionItems(); | 533 AppendPopupExtensionItems(); |
| 533 return; | 534 return; |
| 534 } | 535 } |
| 535 | 536 |
| 536 bool has_link = !params_.unfiltered_link_url.is_empty(); | 537 bool has_link = !params_.unfiltered_link_url.is_empty(); |
| 537 bool has_selection = !params_.selection_text.empty(); | 538 bool has_selection = !params_.selection_text.empty(); |
| 538 | 539 |
| 539 if (AppendCustomItems()) { | 540 if (AppendCustomItems()) { |
| 540 // 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, |
| 541 // 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. |
| 542 if (has_selection) { | 543 if (has_selection) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 const Extension* RenderViewContextMenu::GetExtension() const { | 626 const Extension* RenderViewContextMenu::GetExtension() const { |
| 626 ExtensionSystem* system = ExtensionSystem::Get(profile_); | 627 ExtensionSystem* system = ExtensionSystem::Get(profile_); |
| 627 // There is no process manager in some tests. | 628 // There is no process manager in some tests. |
| 628 if (!system->process_manager()) | 629 if (!system->process_manager()) |
| 629 return NULL; | 630 return NULL; |
| 630 | 631 |
| 631 return system->process_manager()->GetExtensionForRenderViewHost( | 632 return system->process_manager()->GetExtensionForRenderViewHost( |
| 632 source_web_contents_->GetRenderViewHost()); | 633 source_web_contents_->GetRenderViewHost()); |
| 633 } | 634 } |
| 634 | 635 |
| 635 void RenderViewContextMenu::AppendPlatformAppItems( | 636 void RenderViewContextMenu::AppendPlatformAppItems() { |
| 636 const Extension* platform_app) { | 637 const Extension* platform_app = GetExtension(); |
| 637 DCHECK(platform_app); | 638 DCHECK(platform_app); |
| 639 DCHECK(platform_app->is_platform_app()); |
| 640 |
| 638 int index = 0; | 641 int index = 0; |
| 639 AppendExtensionItems(platform_app->id(), &index); | 642 AppendExtensionItems(platform_app->id(), &index); |
| 640 | 643 |
| 641 // Add dev tools for unpacked extensions. | 644 // Add dev tools for unpacked extensions. |
| 642 if (platform_app->location() == Extension::LOAD) { | 645 if (platform_app->location() == Extension::LOAD) { |
| 643 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); | 646 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); |
| 644 AppendDeveloperItems(); | 647 AppendDeveloperItems(); |
| 645 } | 648 } |
| 646 } | 649 } |
| 647 | 650 |
| (...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1891 if (view) | 1894 if (view) |
| 1892 view->SetShowingContextMenu(false); | 1895 view->SetShowingContextMenu(false); |
| 1893 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); | 1896 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); |
| 1894 if (rvh) { | 1897 if (rvh) { |
| 1895 rvh->NotifyContextMenuClosed(params_.custom_context); | 1898 rvh->NotifyContextMenuClosed(params_.custom_context); |
| 1896 } | 1899 } |
| 1897 } | 1900 } |
| 1898 | 1901 |
| 1899 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { | 1902 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { |
| 1900 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) { | 1903 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) { |
| 1901 // Don't enable the web inspector if JavaScript is disabled. We don't | 1904 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 1902 // check this when this is the web contents of an extension (e.g. | 1905 if (!profile_->GetPrefs()->GetBoolean( |
| 1903 // for a popup extension or a platform app) as they have JavaScript | 1906 prefs::kWebKitGlobalJavascriptEnabled) || |
| 1904 // always enabled. | 1907 command_line->HasSwitch(switches::kDisableJavaScript)) |
| 1905 const Extension* extension = GetExtension(); | 1908 return false; |
| 1906 if (!extension) { | |
| 1907 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 1908 if (!profile_->GetPrefs()->GetBoolean( | |
| 1909 prefs::kWebKitGlobalJavascriptEnabled) || | |
| 1910 command_line->HasSwitch(switches::kDisableJavaScript)) | |
| 1911 return false; | |
| 1912 } | |
| 1913 | 1909 |
| 1914 // Don't enable the web inspector if the developer tools are disabled via | 1910 // Don't enable the web inspector if the developer tools are disabled via |
| 1915 // the preference dev-tools-disabled. | 1911 // the preference dev-tools-disabled. |
| 1916 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) | 1912 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
| 1917 return false; | 1913 return false; |
| 1918 } | 1914 } |
| 1919 | 1915 |
| 1920 return true; | 1916 return true; |
| 1921 } | 1917 } |
| 1922 | 1918 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 source_web_contents_->GetRenderViewHost()-> | 1969 source_web_contents_->GetRenderViewHost()-> |
| 1974 ExecuteMediaPlayerActionAtLocation(location, action); | 1970 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1975 } | 1971 } |
| 1976 | 1972 |
| 1977 void RenderViewContextMenu::PluginActionAt( | 1973 void RenderViewContextMenu::PluginActionAt( |
| 1978 const gfx::Point& location, | 1974 const gfx::Point& location, |
| 1979 const WebPluginAction& action) { | 1975 const WebPluginAction& action) { |
| 1980 source_web_contents_->GetRenderViewHost()-> | 1976 source_web_contents_->GetRenderViewHost()-> |
| 1981 ExecutePluginActionAtLocation(location, action); | 1977 ExecutePluginActionAtLocation(location, action); |
| 1982 } | 1978 } |
| OLD | NEW |