OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <set> | 10 #include <set> |
(...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1420 bool enabled = false; | 1420 bool enabled = false; |
1421 if (RenderViewContextMenuBase::IsCommandIdKnown(id, &enabled)) | 1421 if (RenderViewContextMenuBase::IsCommandIdKnown(id, &enabled)) |
1422 return enabled; | 1422 return enabled; |
1423 } | 1423 } |
1424 | 1424 |
1425 CoreTabHelper* core_tab_helper = | 1425 CoreTabHelper* core_tab_helper = |
1426 CoreTabHelper::FromWebContents(source_web_contents_); | 1426 CoreTabHelper::FromWebContents(source_web_contents_); |
1427 int content_restrictions = 0; | 1427 int content_restrictions = 0; |
1428 if (core_tab_helper) | 1428 if (core_tab_helper) |
1429 content_restrictions = core_tab_helper->content_restrictions(); | 1429 content_restrictions = core_tab_helper->content_restrictions(); |
1430 if (id == IDC_PRINT && (content_restrictions & CONTENT_RESTRICTION_PRINT)) | |
Lei Zhang
2016/08/04 23:54:08
Maybe just leave this check in since it's relative
takumif
2016/08/05 00:40:08
Done.
| |
1431 return false; | |
1432 | 1430 |
1433 if (id == IDC_SAVE_PAGE && | 1431 if (id == IDC_SAVE_PAGE && |
1434 (content_restrictions & CONTENT_RESTRICTION_SAVE)) { | 1432 (content_restrictions & CONTENT_RESTRICTION_SAVE)) { |
1435 return false; | 1433 return false; |
1436 } | 1434 } |
1437 | 1435 |
1438 PrefService* prefs = GetPrefs(browser_context_); | 1436 PrefService* prefs = GetPrefs(browser_context_); |
1439 | 1437 |
1440 // Allow Spell Check language items on sub menu for text area context menu. | 1438 // Allow Spell Check language items on sub menu for text area context menu. |
1441 if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && | 1439 if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1576 | 1574 |
1577 case IDC_CONTENT_CONTEXT_SELECTALL: | 1575 case IDC_CONTENT_CONTEXT_SELECTALL: |
1578 return !!(params_.edit_flags & WebContextMenuData::CanSelectAll); | 1576 return !!(params_.edit_flags & WebContextMenuData::CanSelectAll); |
1579 | 1577 |
1580 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: | 1578 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: |
1581 return !browser_context_->IsOffTheRecord() && | 1579 return !browser_context_->IsOffTheRecord() && |
1582 params_.link_url.is_valid() && | 1580 params_.link_url.is_valid() && |
1583 incognito_avail != IncognitoModePrefs::DISABLED; | 1581 incognito_avail != IncognitoModePrefs::DISABLED; |
1584 | 1582 |
1585 case IDC_PRINT: | 1583 case IDC_PRINT: |
1586 return prefs->GetBoolean(prefs::kPrintingEnabled) && | 1584 return IsPrintPreviewEnabled(); |
1587 (params_.media_type == WebContextMenuData::MediaTypeNone || | |
1588 params_.media_flags & WebContextMenuData::MediaCanPrint); | |
1589 | 1585 |
1590 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: | 1586 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: |
1591 case IDC_CONTENT_CONTEXT_GOTOURL: | 1587 case IDC_CONTENT_CONTEXT_GOTOURL: |
1592 case IDC_SPELLPANEL_TOGGLE: | 1588 case IDC_SPELLPANEL_TOGGLE: |
1593 case IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS: | 1589 case IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS: |
1594 return true; | 1590 return true; |
1595 case IDC_CHECK_SPELLING_WHILE_TYPING: | 1591 case IDC_CHECK_SPELLING_WHILE_TYPING: |
1596 return prefs->GetBoolean(prefs::kEnableContinuousSpellcheck); | 1592 return prefs->GetBoolean(prefs::kEnableContinuousSpellcheck); |
1597 | 1593 |
1598 #if !defined(OS_MACOSX) && defined(OS_POSIX) | 1594 #if !defined(OS_MACOSX) && defined(OS_POSIX) |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2075 | 2071 |
2076 bool RenderViewContextMenu::IsPasteAndMatchStyleEnabled() const { | 2072 bool RenderViewContextMenu::IsPasteAndMatchStyleEnabled() const { |
2077 if (!(params_.edit_flags & WebContextMenuData::CanPaste)) | 2073 if (!(params_.edit_flags & WebContextMenuData::CanPaste)) |
2078 return false; | 2074 return false; |
2079 | 2075 |
2080 return ui::Clipboard::GetForCurrentThread()->IsFormatAvailable( | 2076 return ui::Clipboard::GetForCurrentThread()->IsFormatAvailable( |
2081 ui::Clipboard::GetPlainTextFormatType(), | 2077 ui::Clipboard::GetPlainTextFormatType(), |
2082 ui::CLIPBOARD_TYPE_COPY_PASTE); | 2078 ui::CLIPBOARD_TYPE_COPY_PASTE); |
2083 } | 2079 } |
2084 | 2080 |
2081 bool RenderViewContextMenu::IsPrintPreviewEnabled() const { | |
2082 Browser* browser = chrome::FindLastActive(); | |
Lei Zhang
2016/08/04 23:54:09
Seems everyone else here is calling chrome::FindBr
takumif
2016/08/05 00:40:08
chrome::FindBrowserWithWebContents returns null in
Lei Zhang
2016/08/05 01:48:47
How is checking chrome::FindBrowserWithWebContents
takumif
2016/08/05 18:12:29
It was unexpected to me that chrome::FindBrowserWi
| |
2083 return browser && | |
2084 chrome::CanPrint(browser) && | |
2085 (params_.media_type == WebContextMenuData::MediaTypeNone || | |
Lei Zhang
2016/08/04 23:54:09
Check these separately first because it is the che
takumif
2016/08/05 00:40:08
Done.
| |
2086 params_.media_flags & WebContextMenuData::MediaCanPrint); | |
2087 } | |
2088 | |
2085 bool RenderViewContextMenu::IsRouteMediaEnabled() const { | 2089 bool RenderViewContextMenu::IsRouteMediaEnabled() const { |
2086 if (!media_router::MediaRouterEnabled(browser_context_)) | 2090 if (!media_router::MediaRouterEnabled(browser_context_)) |
2087 return false; | 2091 return false; |
2088 | 2092 |
2089 Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents_); | 2093 Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents_); |
2090 if (!browser) | 2094 if (!browser) |
2091 return false; | 2095 return false; |
2092 | 2096 |
2093 // Disable the command if there is an active modal dialog. | 2097 // Disable the command if there is an active modal dialog. |
2094 // We don't use |source_web_contents_| here because it could be the | 2098 // We don't use |source_web_contents_| here because it could be the |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2438 source_web_contents_->GetRenderViewHost()-> | 2442 source_web_contents_->GetRenderViewHost()-> |
2439 ExecuteMediaPlayerActionAtLocation(location, action); | 2443 ExecuteMediaPlayerActionAtLocation(location, action); |
2440 } | 2444 } |
2441 | 2445 |
2442 void RenderViewContextMenu::PluginActionAt( | 2446 void RenderViewContextMenu::PluginActionAt( |
2443 const gfx::Point& location, | 2447 const gfx::Point& location, |
2444 const WebPluginAction& action) { | 2448 const WebPluginAction& action) { |
2445 source_web_contents_->GetRenderViewHost()-> | 2449 source_web_contents_->GetRenderViewHost()-> |
2446 ExecutePluginActionAtLocation(location, action); | 2450 ExecutePluginActionAtLocation(location, action); |
2447 } | 2451 } |
OLD | NEW |