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 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 | 623 |
| 624 if (!print_preview_menu_observer_.get()) { | 624 if (!print_preview_menu_observer_.get()) { |
| 625 TabContentsWrapper* wrapper = | 625 TabContentsWrapper* wrapper = |
| 626 TabContentsWrapper::GetCurrentWrapperForContents(source_web_contents_); | 626 TabContentsWrapper::GetCurrentWrapperForContents(source_web_contents_); |
| 627 print_preview_menu_observer_.reset( | 627 print_preview_menu_observer_.reset( |
| 628 new PrintPreviewContextMenuObserver(wrapper)); | 628 new PrintPreviewContextMenuObserver(wrapper)); |
| 629 } | 629 } |
| 630 observers_.AddObserver(print_preview_menu_observer_.get()); | 630 observers_.AddObserver(print_preview_menu_observer_.get()); |
| 631 } | 631 } |
| 632 | 632 |
| 633 const Extension* RenderViewContextMenu::GetPlatformApp() const { | 633 const Extension* RenderViewContextMenu::GetExtension() const { |
| 634 ExtensionProcessManager* process_manager = | 634 ExtensionProcessManager* process_manager = |
| 635 profile_->GetExtensionProcessManager(); | 635 profile_->GetExtensionProcessManager(); |
| 636 // There is no process manager in some tests. | 636 // There is no process manager in some tests. |
| 637 if (!process_manager) { | 637 if (!process_manager) { |
| 638 return NULL; | 638 return NULL; |
| 639 } | 639 } |
| 640 | 640 |
| 641 ExtensionProcessManager::const_iterator iter; | 641 ExtensionProcessManager::const_iterator iter; |
| 642 for (iter = process_manager->begin(); iter != process_manager->end(); | 642 for (iter = process_manager->begin(); iter != process_manager->end(); |
| 643 ++iter) { | 643 ++iter) { |
| 644 ExtensionHost* host = *iter; | 644 ExtensionHost* host = *iter; |
| 645 if (host->host_contents() == source_web_contents_) { | 645 if (host->host_contents() == source_web_contents_) { |
| 646 if (host->extension() && host->extension()->is_platform_app()) { | 646 if (host->extension()) { |
| 647 return host->extension(); | 647 return host->extension(); |
| 648 } else { | |
| 649 return NULL; | |
| 648 } | 650 } |
|
not at google - send to devlin
2012/01/23 05:43:51
nit sort of stuff:
Might be nice to save a refere
benwells
2012/01/23 06:42:23
Done.
| |
| 649 } | 651 } |
| 650 } | 652 } |
| 651 | 653 |
| 652 return NULL; | 654 return NULL; |
| 653 } | 655 } |
| 654 | 656 |
| 657 const Extension* RenderViewContextMenu::GetPlatformApp() const { | |
| 658 const Extension* extension = GetExtension(); | |
| 659 if (extension && extension->is_platform_app()) { | |
| 660 return extension; | |
| 661 } else { | |
| 662 return NULL; | |
| 663 } | |
| 664 } | |
| 665 | |
| 655 void RenderViewContextMenu::AppendPlatformAppItems() { | 666 void RenderViewContextMenu::AppendPlatformAppItems() { |
|
not at google - send to devlin
2012/01/23 05:43:51
how about passing in the Extension*, save needing
benwells
2012/01/23 06:42:23
Done.
| |
| 656 const Extension* platform_app = GetPlatformApp(); | 667 const Extension* platform_app = GetPlatformApp(); |
| 657 DCHECK(platform_app); | 668 DCHECK(platform_app); |
| 658 int index = 0; | 669 int index = 0; |
| 659 AppendExtensionItems(platform_app->id(), &index); | 670 AppendExtensionItems(platform_app->id(), &index); |
| 671 | |
| 672 // Add dev tools for unpacked extensions. | |
| 673 if (platform_app->location() == Extension::LOAD) | |
| 674 AppendDeveloperItems(); | |
| 660 } | 675 } |
| 661 | 676 |
| 662 void RenderViewContextMenu::LookUpInDictionary() { | 677 void RenderViewContextMenu::LookUpInDictionary() { |
| 663 // Used only in the Mac port. | 678 // Used only in the Mac port. |
| 664 NOTREACHED(); | 679 NOTREACHED(); |
| 665 } | 680 } |
| 666 | 681 |
| 667 void RenderViewContextMenu::AddMenuItem(int command_id, | 682 void RenderViewContextMenu::AddMenuItem(int command_id, |
| 668 const string16& title) { | 683 const string16& title) { |
| 669 menu_model_.AddItem(command_id, title); | 684 menu_model_.AddItem(command_id, title); |
| (...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1855 if (view) | 1870 if (view) |
| 1856 view->ShowingContextMenu(false); | 1871 view->ShowingContextMenu(false); |
| 1857 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); | 1872 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); |
| 1858 if (rvh) { | 1873 if (rvh) { |
| 1859 rvh->NotifyContextMenuClosed(params_.custom_context); | 1874 rvh->NotifyContextMenuClosed(params_.custom_context); |
| 1860 } | 1875 } |
| 1861 } | 1876 } |
| 1862 | 1877 |
| 1863 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { | 1878 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { |
| 1864 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) { | 1879 if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) { |
| 1865 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 1880 // Don't enable the web inspector if JavaScript is disabled. We don't |
| 1866 TabContentsWrapper* tab_contents_wrapper = | 1881 // check this when this is the web contents of an extension (e.g. |
| 1867 TabContentsWrapper::GetCurrentWrapperForContents( | 1882 // for a popup extension or a platform app) as they have javascript |
| 1868 source_web_contents_); | 1883 // always enabled. |
| 1869 if (!tab_contents_wrapper) | 1884 if (!GetExtension()) { |
| 1870 return false; | 1885 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
|
not at google - send to devlin
2012/01/23 05:43:51
I'd move this down to right before it's used. Also
benwells
2012/01/23 06:42:23
Ya much nicer. Done.
| |
| 1871 // Don't enable the web inspector if JavaScript is disabled. | 1886 TabContentsWrapper* contents_wrapper = |
| 1872 if (!tab_contents_wrapper->prefs_tab_helper()->per_tab_prefs()->GetBoolean( | 1887 TabContentsWrapper::GetCurrentWrapperForContents( |
| 1873 prefs::kWebKitJavascriptEnabled) || | 1888 source_web_contents_); |
| 1874 command_line.HasSwitch(switches::kDisableJavaScript)) | 1889 if (!contents_wrapper) |
| 1875 return false; | 1890 return false; |
| 1891 if (!contents_wrapper->prefs_tab_helper()->per_tab_prefs()->GetBoolean( | |
| 1892 prefs::kWebKitJavascriptEnabled) || | |
|
not at google - send to devlin
2012/01/23 05:43:51
<- 2 indent
benwells
2012/01/23 06:42:23
I think it is right as is? There is an extra four
| |
| 1893 command_line.HasSwitch(switches::kDisableJavaScript)) | |
| 1894 return false; | |
| 1895 } | |
| 1896 | |
| 1876 // Don't enable the web inspector if the developer tools are disabled via | 1897 // Don't enable the web inspector if the developer tools are disabled via |
| 1877 // the preference dev-tools-disabled. | 1898 // the preference dev-tools-disabled. |
| 1878 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) | 1899 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
| 1879 return false; | 1900 return false; |
| 1880 } | 1901 } |
| 1881 | 1902 |
| 1882 return true; | 1903 return true; |
| 1883 } | 1904 } |
| 1884 | 1905 |
| 1885 string16 RenderViewContextMenu::PrintableSelectionText() { | 1906 string16 RenderViewContextMenu::PrintableSelectionText() { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1935 source_web_contents_->GetRenderViewHost()-> | 1956 source_web_contents_->GetRenderViewHost()-> |
| 1936 ExecuteMediaPlayerActionAtLocation(location, action); | 1957 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1937 } | 1958 } |
| 1938 | 1959 |
| 1939 void RenderViewContextMenu::PluginActionAt( | 1960 void RenderViewContextMenu::PluginActionAt( |
| 1940 const gfx::Point& location, | 1961 const gfx::Point& location, |
| 1941 const WebPluginAction& action) { | 1962 const WebPluginAction& action) { |
| 1942 source_web_contents_->GetRenderViewHost()-> | 1963 source_web_contents_->GetRenderViewHost()-> |
| 1943 ExecutePluginActionAtLocation(location, action); | 1964 ExecutePluginActionAtLocation(location, action); |
| 1944 } | 1965 } |
| OLD | NEW |