diff options
author | scheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-22 00:41:17 +0000 |
---|---|---|
committer | scheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-22 00:41:17 +0000 |
commit | fc9bf18faf17def62fc122dd5df7bbf57c7ea0ce (patch) | |
tree | 72db1d24cf851beb0616d4dfb97d399701ed8133 /chrome/browser | |
parent | d34dbf2e0870d82bb70490f8d0a4e70046a7d15e (diff) | |
download | chromium_src-fc9bf18faf17def62fc122dd5df7bbf57c7ea0ce.zip chromium_src-fc9bf18faf17def62fc122dd5df7bbf57c7ea0ce.tar.gz chromium_src-fc9bf18faf17def62fc122dd5df7bbf57c7ea0ce.tar.bz2 |
Mouse lock content setting back-end (no UI)
BUG=100677
TEST=Manual test in ppapi/examples/mouse_lock; enter full screen and mouse lock; prompts should appear only first time.
R=jochen@chromium.org, pkasting@chromium.org, yzshen@chromium.org
Review URL: http://codereview.chromium.org/8354026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
7 files changed, 51 insertions, 8 deletions
diff --git a/chrome/browser/content_settings/content_settings_default_provider.cc b/chrome/browser/content_settings/content_settings_default_provider.cc index 4964c9e..48d2d45 100644 --- a/chrome/browser/content_settings/content_settings_default_provider.cc +++ b/chrome/browser/content_settings/content_settings_default_provider.cc @@ -38,6 +38,7 @@ const ContentSetting kDefaultSettings[] = { CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_INTENTS CONTENT_SETTING_DEFAULT, // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_FULLSCREEN + CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_MOUSELOCK }; COMPILE_ASSERT(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, default_settings_incorrect_size); diff --git a/chrome/browser/content_settings/content_settings_utils.cc b/chrome/browser/content_settings/content_settings_utils.cc index cdc8537c..2338507 100644 --- a/chrome/browser/content_settings/content_settings_utils.cc +++ b/chrome/browser/content_settings/content_settings_utils.cc @@ -31,7 +31,8 @@ const char* kTypeNames[] = { "notifications", "intents", "auto-select-certificate", - "fullscreen" + "fullscreen", + "mouselock" }; COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, type_names_incorrect_size); diff --git a/chrome/browser/content_settings/host_content_settings_map_unittest.cc b/chrome/browser/content_settings/host_content_settings_map_unittest.cc index 06ab654..208b8ba 100644 --- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc +++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc @@ -159,6 +159,8 @@ TEST_F(HostContentSettingsMapTest, IndividualSettings) { CONTENT_SETTING_ASK; desired_settings.settings[CONTENT_SETTINGS_TYPE_FULLSCREEN] = CONTENT_SETTING_ASK; + desired_settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK] = + CONTENT_SETTING_ASK; ContentSettings settings = host_content_settings_map->GetContentSettings(host, host); EXPECT_TRUE(SettingsEqual(desired_settings, settings)); @@ -618,6 +620,8 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) { CONTENT_SETTING_ASK; desired_settings.settings[CONTENT_SETTINGS_TYPE_FULLSCREEN] = CONTENT_SETTING_ASK; + desired_settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK] = + CONTENT_SETTING_ASK; ContentSettings settings = host_content_settings_map->GetContentSettings(host, host); EXPECT_TRUE(SettingsEqual(desired_settings, settings)); @@ -637,6 +641,8 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) { settings.settings[CONTENT_SETTINGS_TYPE_INTENTS]); EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_FULLSCREEN], settings.settings[CONTENT_SETTINGS_TYPE_FULLSCREEN]); + EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK], + settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK]); } TEST_F(HostContentSettingsMapTest, OffTheRecord) { diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 12f4a10..ad7b7cd 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -3963,6 +3963,7 @@ void Browser::UpdatePreferredSize(TabContents* source, } void Browser::RequestToLockMouse(TabContents* tab) { + // Mouse Lock is only permitted when browser is in tab fullscreen. if (!IsFullscreenForTab(tab)) { tab->GotResponseToLockMouseRequest(false); return; @@ -3970,10 +3971,25 @@ void Browser::RequestToLockMouse(TabContents* tab) { if (mouse_lock_state_ == MOUSELOCK_ACCEPTED) { tab->GotResponseToLockMouseRequest(true); - } else { - mouse_lock_state_ = MOUSELOCK_REQUESTED; - UpdateFullscreenExitBubbleContent(); + return; + } + + switch (GetMouseLockSetting(tab->GetURL())) { + case CONTENT_SETTING_ALLOW: + mouse_lock_state_ = MOUSELOCK_ACCEPTED; + tab->GotResponseToLockMouseRequest(true); + break; + case CONTENT_SETTING_BLOCK: + mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; + tab->GotResponseToLockMouseRequest(false); + break; + case CONTENT_SETTING_ASK: + mouse_lock_state_ = MOUSELOCK_REQUESTED; + break; + default: + NOTREACHED(); } + UpdateFullscreenExitBubbleContent(); } void Browser::LostMouseLock() { @@ -3991,17 +4007,21 @@ void Browser::OnAcceptFullscreenPermission( DCHECK(fullscreened_tab_); DCHECK_NE(tab_fullscreen_accepted_, fullscreen); + HostContentSettingsMap* settings_map = + profile()->GetHostContentSettingsMap(); if (mouse_lock) { DCHECK_EQ(mouse_lock_state_, MOUSELOCK_REQUESTED); + settings_map->SetContentSetting( + ContentSettingsPattern::FromURL(url), + ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_MOUSELOCK, + std::string(), CONTENT_SETTING_ALLOW); mouse_lock_state_ = fullscreened_tab_->tab_contents()->GotResponseToLockMouseRequest(true) ? MOUSELOCK_ACCEPTED : MOUSELOCK_NOT_REQUESTED; } if (!tab_fullscreen_accepted_) { - HostContentSettingsMap* settings_map = - profile()->GetHostContentSettingsMap(); settings_map->SetContentSetting( - ContentSettingsPattern::FromString(url.host()), + ContentSettingsPattern::FromURL(url), ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(), CONTENT_SETTING_ALLOW); tab_fullscreen_accepted_ = true; @@ -4038,6 +4058,15 @@ ContentSetting Browser::GetFullscreenSetting(const GURL& url) { CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); } +ContentSetting Browser::GetMouseLockSetting(const GURL& url) { + if (url.SchemeIsFile()) + return CONTENT_SETTING_ALLOW; + + HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); + return settings_map->GetContentSetting(url, url, + CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); +} + /////////////////////////////////////////////////////////////////////////////// // Browser, TabContentsWrapperDelegate implementation: diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index cc88061..595fe67 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -820,6 +820,7 @@ class Browser : public TabHandlerDelegate, FullscreenExitBubbleType bubble_type); void OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type); ContentSetting GetFullscreenSetting(const GURL& url); + ContentSetting GetMouseLockSetting(const GURL& url); // Figure out if there are tabs that have beforeunload handlers. bool TabsNeedBeforeUnloadFired(); diff --git a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm index 32b77af..823b450 100644 --- a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm +++ b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm @@ -58,7 +58,8 @@ TEST_F(ContentSettingBubbleControllerTest, Init) { if (i == CONTENT_SETTINGS_TYPE_NOTIFICATIONS || i == CONTENT_SETTINGS_TYPE_INTENTS || i == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE || - i == CONTENT_SETTINGS_TYPE_FULLSCREEN) { + i == CONTENT_SETTINGS_TYPE_FULLSCREEN || + i == CONTENT_SETTINGS_TYPE_MOUSELOCK) { // Notifications, web intents and auto select certificate have no bubble. continue; } diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc index 34299a3..3ccff843 100644 --- a/chrome/browser/ui/webui/options/content_settings_handler.cc +++ b/chrome/browser/ui/webui/options/content_settings_handler.cc @@ -64,6 +64,7 @@ const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { {CONTENT_SETTINGS_TYPE_INTENTS, "intents"}, {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, {CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen"}, + {CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock"}, }; COMPILE_ASSERT(arraysize(kContentSettingsTypeGroupNames) == CONTENT_SETTINGS_NUM_TYPES, @@ -414,6 +415,9 @@ void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { // TODO(koz): Implement fullscreen content settings UI. if (type == CONTENT_SETTINGS_TYPE_FULLSCREEN) continue; + // TODO(scheib): Mouse lock content settings UI. http://crbug.com/97768 + if (type == CONTENT_SETTINGS_TYPE_MOUSELOCK) + continue; UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); } } |