Chromium Code Reviews| Index: chrome/browser/tab_contents/render_view_context_menu.cc |
| diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc |
| index 3e41d8855baa1137b923cba5d79d8c9d650dd07c..51494310c414bab608079c0598b42e09feb14816 100644 |
| --- a/chrome/browser/tab_contents/render_view_context_menu.cc |
| +++ b/chrome/browser/tab_contents/render_view_context_menu.cc |
| @@ -525,8 +525,12 @@ void RenderViewContextMenu::AppendAllExtensionItems() { |
| } |
| void RenderViewContextMenu::InitMenu() { |
| - if (GetPlatformApp()) { |
| - AppendPlatformAppItems(); |
| + const Extension* extension = GetExtension(); |
| + if (extension) { |
| + if (extension->is_platform_app()) |
| + AppendPlatformAppItems(extension); |
| + else |
| + AppendPopupExtensionItems(); |
| return; |
| } |
| @@ -630,7 +634,7 @@ void RenderViewContextMenu::InitMenu() { |
| observers_.AddObserver(print_preview_menu_observer_.get()); |
| } |
| -const Extension* RenderViewContextMenu::GetPlatformApp() const { |
| +const Extension* RenderViewContextMenu::GetExtension() const { |
| ExtensionProcessManager* process_manager = |
| profile_->GetExtensionProcessManager(); |
| // There is no process manager in some tests. |
| @@ -642,21 +646,47 @@ const Extension* RenderViewContextMenu::GetPlatformApp() const { |
| for (iter = process_manager->begin(); iter != process_manager->end(); |
| ++iter) { |
| ExtensionHost* host = *iter; |
| - if (host->host_contents() == source_web_contents_) { |
| - if (host->extension() && host->extension()->is_platform_app()) { |
| - return host->extension(); |
| - } |
| - } |
| + if (host->host_contents() == source_web_contents_) |
| + return host->extension(); |
| } |
| return NULL; |
| } |
| -void RenderViewContextMenu::AppendPlatformAppItems() { |
| - const Extension* platform_app = GetPlatformApp(); |
| +void RenderViewContextMenu::AppendPlatformAppItems( |
| + const Extension* platform_app) { |
| DCHECK(platform_app); |
| int index = 0; |
| AppendExtensionItems(platform_app->id(), &index); |
| + |
| + // Add dev tools for unpacked extensions. |
| + if (platform_app->location() == Extension::LOAD) |
| + AppendDeveloperItems(); |
| +} |
| + |
| +void RenderViewContextMenu::AppendPopupExtensionItems() { |
| + bool has_selection = !params_.selection_text.empty(); |
| + |
| + if (params_.is_editable) { |
| + // 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
|
| + 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
|
| + spelling_menu_observer_.reset(new SpellingMenuObserver(this)); |
| + } |
| + DCHECK(spelling_menu_observer_.get()); |
| + 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
|
| + spelling_menu_observer_->InitMenu(params_); |
| + AppendEditableItems(); |
| + } else if (has_selection) { |
| + AppendCopyItem(); |
| + } |
| + |
| + if (has_selection) |
| + AppendSearchProvider(); |
| + |
| + if (!IsDevToolsURL(params_.page_url)) |
| + AppendAllExtensionItems(); |
| + |
| + AppendDeveloperItems(); |
| } |
| void RenderViewContextMenu::LookUpInDictionary() { |
| @@ -1872,17 +1902,33 @@ void RenderViewContextMenu::MenuClosed(ui::SimpleMenuModel* source) { |
| bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { |
| if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT) { |
| - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| - TabContentsWrapper* tab_contents_wrapper = |
| - TabContentsWrapper::GetCurrentWrapperForContents( |
| - source_web_contents_); |
| - if (!tab_contents_wrapper) |
| - return false; |
| - // Don't enable the web inspector if JavaScript is disabled. |
| - if (!tab_contents_wrapper->prefs_tab_helper()->per_tab_prefs()->GetBoolean( |
| - prefs::kWebKitJavascriptEnabled) || |
| - command_line.HasSwitch(switches::kDisableJavaScript)) |
| - return false; |
| + // Don't enable the web inspector if JavaScript is disabled. We don't |
| + // check this when this is the web contents of an extension (e.g. |
| + // for a popup extension or a platform app) as they have JavaScript |
| + // always enabled. |
| + const Extension* extension = GetExtension(); |
| + if (!extension) { |
| + TabContentsWrapper* contents_wrapper = |
| + TabContentsWrapper::GetCurrentWrapperForContents( |
| + source_web_contents_); |
| + if (!contents_wrapper) |
| + return false; |
| + const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + if (!contents_wrapper->prefs_tab_helper()->per_tab_prefs()->GetBoolean( |
| + prefs::kWebKitJavascriptEnabled) || |
| + command_line->HasSwitch(switches::kDisableJavaScript)) |
| + return false; |
| +#if !defined(TOOLKIT_VIEWS) |
| + } else { |
| + // Disable dev tools for popup extensions for non-views builds, as the |
| + // extension popups for these builds do not support dynamically inspecting |
| + // the popups. |
| + // TODO(benwells): Add support for these builds and remove this #if. |
| + if (!extension->is_platform_app()) |
| + return false; |
| +#endif |
| + } |
| + |
| // Don't enable the web inspector if the developer tools are disabled via |
| // the preference dev-tools-disabled. |
| if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |