diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 23:36:00 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 23:36:00 +0000 |
commit | 9e823663aa2491262162657c6528123999e0dbb2 (patch) | |
tree | aa8a190b4e960f70b0ec4e9a6741c65a7db36cac | |
parent | 196e469886b723e8f3531a1fe51204e4dc50dc8b (diff) | |
download | chromium_src-9e823663aa2491262162657c6528123999e0dbb2.zip chromium_src-9e823663aa2491262162657c6528123999e0dbb2.tar.gz chromium_src-9e823663aa2491262162657c6528123999e0dbb2.tar.bz2 |
Use CommandUpdater for disabling commands that were disabled by plugins.
Review URL: http://codereview.chromium.org/3742002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62475 0039d316-1c4b-4281-b951-d872f2087c98
20 files changed, 113 insertions, 62 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index d450835..c8f3ceb 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -91,6 +91,7 @@ #include "chrome/browser/window_sizer.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/content_restriction.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" #include "chrome/common/page_transition_types.h" @@ -231,6 +232,10 @@ Browser::Browser(Type type, Profile* profile) registrar_.Add(this, NotificationType::EXTENSION_READY_FOR_INSTALL, NotificationService::AllSources()); + PrefService* local_state = g_browser_process->local_state(); + if (local_state) + printing_enabled_.Init(prefs::kPrintingEnabled, local_state, this); + InitCommandState(); BrowserList::AddBrowser(this); @@ -255,15 +260,6 @@ Browser::Browser(Type type, Profile* profile) profile_->GetProfileSyncService()->AddObserver(this); CreateInstantIfNecessary(); - - PrefService *local_state = g_browser_process->local_state(); - if (local_state) { - printing_enabled_.Init(prefs::kPrintingEnabled, local_state, this); - command_updater_.UpdateCommandEnabled(IDC_PRINT, - printing_enabled_.GetValue()); - } else { - command_updater_.UpdateCommandEnabled(IDC_PRINT, true); - } } Browser::~Browser() { @@ -3138,6 +3134,10 @@ void Browser::OnDidGetApplicationInfo(TabContents* tab_contents, pending_web_app_action_ = NONE; } +void Browser::ContentRestrictionsChanged(TabContents* source) { + UpdateCommandsForContentRestrictionState(); +} + /////////////////////////////////////////////////////////////////////////////// // Browser, SelectFileDialog::Listener implementation: @@ -3283,8 +3283,7 @@ void Browser::Observe(NotificationType type, if (pref_name == prefs::kUseVerticalTabs) { UseVerticalTabsChanged(); } else if (pref_name == prefs::kPrintingEnabled) { - command_updater_.UpdateCommandEnabled(IDC_PRINT, - printing_enabled_.GetValue()); + UpdatePrintingState(0); } else if (pref_name == prefs::kInstantEnabled) { if (!InstantController::IsEnabled(profile())) { if (instant()) { @@ -3417,11 +3416,6 @@ void Browser::InitCommandState() { command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); - // Clipboard commands - command_updater_.UpdateCommandEnabled(IDC_CUT, true); - command_updater_.UpdateCommandEnabled(IDC_COPY, true); - command_updater_.UpdateCommandEnabled(IDC_PASTE, true); - // Zoom command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); @@ -3507,6 +3501,8 @@ void Browser::InitCommandState() { // Initialize other commands whose state changes based on fullscreen mode. UpdateCommandsForFullscreenMode(false); + + UpdateCommandsForContentRestrictionState(); } void Browser::UpdateCommandsForTabState() { @@ -3563,6 +3559,33 @@ void Browser::UpdateCommandsForTabState() { command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, web_app::IsValidUrl(current_tab->GetURL())); #endif + + UpdateCommandsForContentRestrictionState(); +} + +void Browser::UpdateCommandsForContentRestrictionState() { + int restrictions = 0; + TabContents* current_tab = GetSelectedTabContents(); + if (current_tab) + restrictions = current_tab->content_restrictions(); + + command_updater_.UpdateCommandEnabled( + IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY)); + command_updater_.UpdateCommandEnabled( + IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT)); + command_updater_.UpdateCommandEnabled( + IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE)); + UpdatePrintingState(restrictions); +} + +void Browser::UpdatePrintingState(int content_restrictions) { + bool enabled = true; + if (content_restrictions & CONTENT_RESTRICTION_PRINT) { + enabled = false; + } else if (g_browser_process->local_state()) { + enabled = printing_enabled_.GetValue(); + } + command_updater_.UpdateCommandEnabled(IDC_PRINT, enabled); } void Browser::UpdateReloadStopState(bool is_loading, bool force) { diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 21b43a6..85a3ea40 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -778,6 +778,7 @@ class Browser : public TabHandlerDelegate, NavigationType::Type navigation_type); virtual void OnDidGetApplicationInfo(TabContents* tab_contents, int32 page_id); + virtual void ContentRestrictionsChanged(TabContents* source); // Overridden from SelectFileDialog::Listener: virtual void FileSelected(const FilePath& path, int index, void* params); @@ -805,6 +806,12 @@ class Browser : public TabHandlerDelegate, // Update commands whose state depends on the tab's state. void UpdateCommandsForTabState(); + // Updates commands when the content's restrictions change. + void UpdateCommandsForContentRestrictionState(); + + // Updates the printing command state. + void UpdatePrintingState(int content_restrictions); + // Ask the Reload/Stop button to change its icon, and update the Stop command // state. |is_loading| is true if the current TabContents is loading. // |force| is true if the button should change its icon immediately. diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 7219c26..c91671f 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -888,7 +888,8 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_DetectedPhishingSite, OnDetectedPhishingSite) IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptEvalResponse, OnScriptEvalResponse) - IPC_MESSAGE_HANDLER(ViewHostMsg_DisableCommand, OnDisableCommand) + IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions, + OnUpdateContentRestrictions) // Have the super handle all other messages. IPC_MESSAGE_UNHANDLED(RenderWidgetHost::OnMessageReceived(msg)) IPC_END_MESSAGE_MAP_EX() @@ -2135,6 +2136,6 @@ void RenderViewHost::OnScriptEvalResponse(int id, bool result) { Details<std::pair<int, Value*> >(&details)); } -void RenderViewHost::OnDisableCommand(int command_id) { - delegate_->DisableCommand(command_id); +void RenderViewHost::OnUpdateContentRestrictions(int restrictions) { + delegate_->UpdateContentRestrictions(restrictions); } diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 8efed62..76f1f01 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -699,7 +699,7 @@ class RenderViewHost : public RenderWidgetHost { double phishing_score, const SkBitmap& thumbnail); void OnScriptEvalResponse(int id, bool result); - void OnDisableCommand(int command_id); + void OnUpdateContentRestrictions(int restrictions); private: friend class TestRenderViewHost; diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index bc4ebc9..d0c88d6 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -847,8 +847,8 @@ class RenderViewHostDelegate { int maximum_percent, bool remember) {} - // Disables a command (i.e. print/copy). - virtual void DisableCommand(int command_id) {} + // Update the content restrictions, i.e. disable print/copy. + virtual void UpdateContentRestrictions(int restrictions) {} protected: virtual ~RenderViewHostDelegate() {} diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index ccdbf39..1b5af98 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -42,6 +42,7 @@ #include "chrome/browser/translate/translate_manager.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/content_restriction.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "gfx/favicon_size.h" @@ -735,8 +736,11 @@ ExtensionMenuItem* RenderViewContextMenu::GetExtensionMenuItem(int id) const { // Menu delegate functions ----------------------------------------------------- bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { - if (source_tab_contents_->IsCommandDisabled(id)) + if (id == IDC_PRINT && + (source_tab_contents_->content_restrictions() & + CONTENT_RESTRICTION_PRINT)) { return false; + } // Allow Spell Check language items on sub menu for text area context menu. if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index fa50b41..ebf4756 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -373,7 +373,8 @@ TabContents::TabContents(Profile* profile, static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), maximum_zoom_percent_( static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), - temporary_zoom_settings_(false) { + temporary_zoom_settings_(false), + content_restrictions_(0) { renderer_preferences_util::UpdateFromSystemSettings( &renderer_preferences_, profile); @@ -1464,14 +1465,6 @@ int TabContents::GetZoomPercent(bool* enable_increment, return percent; } -bool TabContents::IsCommandDisabled(int command_id) const { - for (size_t i = 0; i < disabled_commands_.size(); ++i) { - if (disabled_commands_[i] == command_id) - return true; - } - return false; -} - // Notifies the RenderWidgetHost instance about the fact that the page is // loading, or done loading and calls the base implementation. void TabContents::SetIsLoading(bool is_loading, @@ -2605,7 +2598,10 @@ void TabContents::RequestMove(const gfx::Rect& new_bounds) { void TabContents::DidStartLoading() { SetIsLoading(true, NULL); - disabled_commands_.clear(); + if (content_restrictions_) { + content_restrictions_= 0; + delegate()->ContentRestrictionsChanged(this); + } } void TabContents::DidStopLoading() { @@ -2973,8 +2969,9 @@ void TabContents::UpdateZoomLimits(int minimum_percent, temporary_zoom_settings_ = !remember; } -void TabContents::DisableCommand(int command_id) { - disabled_commands_.push_back(command_id); +void TabContents::UpdateContentRestrictions(int restrictions) { + content_restrictions_ = restrictions; + delegate()->ContentRestrictionsChanged(this); } void TabContents::BeforeUnloadFiredFromRenderManager( diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index a06bf16..1f16a74 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -708,8 +708,7 @@ class TabContents : public PageNavigator, int minimum_zoom_percent() const { return minimum_zoom_percent_; } int maximum_zoom_percent() const { return maximum_zoom_percent_; } - // Returns true if the given command is disabled. - bool IsCommandDisabled(int command_id) const; + int content_restrictions() const { return content_restrictions_; } private: friend class NavigationController; @@ -993,7 +992,7 @@ class TabContents : public PageNavigator, virtual void UpdateZoomLimits(int minimum_percent, int maximum_percent, bool remember); - virtual void DisableCommand(int command_id); + virtual void UpdateContentRestrictions(int restrictions); // RenderViewHostManager::Delegate ------------------------------------------- @@ -1289,8 +1288,9 @@ class TabContents : public PageNavigator, // remember it. bool temporary_zoom_settings_; - // Disabled commands. Only expect a few, so vector is fine. - std::vector<int> disabled_commands_; + // Content restrictions, used to disable print/copy etc based on content's + // (full-page plugins for now only) permissions. + int content_restrictions_; // --------------------------------------------------------------------------- diff --git a/chrome/browser/tab_contents/tab_contents_delegate.cc b/chrome/browser/tab_contents/tab_contents_delegate.cc index 518ad72..674fd75 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.cc +++ b/chrome/browser/tab_contents/tab_contents_delegate.cc @@ -195,5 +195,8 @@ void TabContentsDelegate::OnSetSuggestResult(int32 page_id, const std::string& result) { } +void TabContentsDelegate::ContentRestrictionsChanged(TabContents* source) { +} + TabContentsDelegate::~TabContentsDelegate() { } diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index c12db61..dca24b4 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -307,6 +307,10 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { // Notifies the delegate that the page has a suggest result. virtual void OnSetSuggestResult(int32 page_id, const std::string& result); + // Notifies the delegate that the content restrictions for this tab has + // changed. + virtual void ContentRestrictionsChanged(TabContents* source); + protected: virtual ~TabContentsDelegate(); }; diff --git a/chrome/browser/views/wrench_menu.cc b/chrome/browser/views/wrench_menu.cc index a49cb06..0c51c68 100644 --- a/chrome/browser/views/wrench_menu.cc +++ b/chrome/browser/views/wrench_menu.cc @@ -600,10 +600,6 @@ bool WrenchMenu::IsCommandEnabled(int id) const { if (id == 0) return false; // The root item. - TabContents* selected_tab = browser_->GetSelectedTabContents(); - if (selected_tab && selected_tab->IsCommandDisabled(id)) - return false; - const Entry& entry = id_to_entry_.find(id)->second; int command_id = entry.first->GetCommandIdAt(entry.second); // The items representing the cut (cut/copy/paste) and zoom menu diff --git a/chrome/browser/wrench_menu_model.cc b/chrome/browser/wrench_menu_model.cc index 8a6b5ae..61045a5 100644 --- a/chrome/browser/wrench_menu_model.cc +++ b/chrome/browser/wrench_menu_model.cc @@ -246,10 +246,6 @@ bool WrenchMenuModel::IsCommandIdChecked(int command_id) const { } bool WrenchMenuModel::IsCommandIdEnabled(int command_id) const { - TabContents* selected_tab = browser_->GetSelectedTabContents(); - if (selected_tab && selected_tab->IsCommandDisabled(command_id)) - return false; - #if defined(OS_CHROMEOS) // Special case because IDC_NEW_WINDOW item should be disabled in BWSI mode, // but accelerator should work. diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index b9e2806..00b42b6 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -42,6 +42,7 @@ 'common/chrome_counters.h', 'common/common_param_traits.cc', 'common/common_param_traits.h', + 'common/content_restriction.h', 'common/content_settings.cc', 'common/content_settings.h', 'common/content_settings_helper.cc', diff --git a/chrome/common/content_restriction.h b/chrome/common/content_restriction.h new file mode 100644 index 0000000..46fa522 --- /dev/null +++ b/chrome/common/content_restriction.h @@ -0,0 +1,18 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_CONTENT_RESTRICTION_H_ +#define CHROME_COMMON_CONTENT_RESTRICTION_H_ +#pragma once + +// Used by a full-page plugin to disable browser commands because of +// restrictions on how the data is to be used (i.e. can't copy/print). +enum ContentRestriction { + CONTENT_RESTRICTION_COPY = 1 << 0, + CONTENT_RESTRICTION_CUT = 1 << 1, + CONTENT_RESTRICTION_PASTE = 1 << 2, + CONTENT_RESTRICTION_PRINT = 1 << 3 +}; + +#endif // CHROME_COMMON_CONTENT_RESTRICTION_H_ diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 73cc18a..62a0b88 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -2970,8 +2970,8 @@ IPC_BEGIN_MESSAGES(ViewHost) int /* id */, bool /* result */) - // Disables a UI command (i.e. print/copy). - IPC_MESSAGE_ROUTED1(ViewHostMsg_DisableCommand, - int /* command_id */) + // Updates the content restrictions, i.e. to disable print/copy. + IPC_MESSAGE_ROUTED1(ViewHostMsg_UpdateContentRestrictions, + int /* restrictions */) IPC_END_MESSAGES(ViewHost) diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc index 2a9cadf..a3e18fe 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.cc +++ b/chrome/renderer/pepper_plugin_delegate_impl.cc @@ -766,7 +766,7 @@ void PepperPluginDelegateImpl::DidStopLoading() { render_view_->DidStopLoadingForPlugin(); } -void PepperPluginDelegateImpl::DisableCommand(int command_id) { - render_view_->Send( - new ViewHostMsg_DisableCommand(render_view_->routing_id(), command_id)); +void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { + render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( + render_view_->routing_id(), restrictions)); } diff --git a/chrome/renderer/pepper_plugin_delegate_impl.h b/chrome/renderer/pepper_plugin_delegate_impl.h index 839eb9d..790be75 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.h +++ b/chrome/renderer/pepper_plugin_delegate_impl.h @@ -107,7 +107,7 @@ class PepperPluginDelegateImpl virtual std::string ResolveProxy(const GURL& url); virtual void DidStartLoading(); virtual void DidStopLoading(); - virtual void DisableCommand(int command_id); + virtual void SetContentRestriction(int restrictions); private: // Pointer to the RenderView that owns us. diff --git a/webkit/glue/plugins/pepper_plugin_delegate.h b/webkit/glue/plugins/pepper_plugin_delegate.h index 6173af7..f080f34 100644 --- a/webkit/glue/plugins/pepper_plugin_delegate.h +++ b/webkit/glue/plugins/pepper_plugin_delegate.h @@ -216,8 +216,8 @@ class PluginDelegate { virtual void DidStartLoading() = 0; virtual void DidStopLoading() = 0; - // Disables the given UI command item (i.e. print/copy). - virtual void DisableCommand(int command_id) = 0; + // Sets restrictions on how the content can be used (i.e. no print/copy). + virtual void SetContentRestriction(int restrictions) = 0; }; } // namespace pepper diff --git a/webkit/glue/plugins/pepper_private.cc b/webkit/glue/plugins/pepper_private.cc index de4d180..ae4db34 100644 --- a/webkit/glue/plugins/pepper_private.cc +++ b/webkit/glue/plugins/pepper_private.cc @@ -241,11 +241,11 @@ void DidStopLoading(PP_Instance instance_id) { instance->delegate()->DidStopLoading(); } -void DisableCommand(PP_Instance instance_id, int command_id) { +void SetContentRestriction(PP_Instance instance_id, int restrictions) { PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return; - instance->delegate()->DisableCommand(command_id); + instance->delegate()->SetContentRestriction(restrictions); } const PPB_Private ppb_private = { @@ -256,7 +256,7 @@ const PPB_Private ppb_private = { &SearchString, &DidStartLoading, &DidStopLoading, - &DisableCommand + &SetContentRestriction }; } // namespace diff --git a/webkit/glue/plugins/ppb_private.h b/webkit/glue/plugins/ppb_private.h index 9f8b93c..a60194c 100644 --- a/webkit/glue/plugins/ppb_private.h +++ b/webkit/glue/plugins/ppb_private.h @@ -118,8 +118,9 @@ struct PPB_Private { void (*DidStartLoading)(PP_Instance instance); void (*DidStopLoading)(PP_Instance instance); - // Disables the given command (i.e. print/copy). - void (*DisableCommand)(PP_Instance instance, int command_id); + // Sets content restriction for a full-page plugin (i.e. can't copy/print). + // The value is a bitfield of ContentRestriction enums. + void (*SetContentRestriction)(PP_Instance instance, int restrictions); }; #endif // WEBKIT_GLUE_PLUGINS_PPB_PRIVATE_H_ |