diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-17 20:21:04 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-17 20:21:04 +0000 |
commit | 5d9163e2136f0b4eef4aac3e650f1b6e655118fd (patch) | |
tree | ed86b9c0422989d8c4d90cf628ca9f6239bd5d8b /chrome/browser | |
parent | 87c23d51618a288127eed63419e4f26d770f74c5 (diff) | |
download | chromium_src-5d9163e2136f0b4eef4aac3e650f1b6e655118fd.zip chromium_src-5d9163e2136f0b4eef4aac3e650f1b6e655118fd.tar.gz chromium_src-5d9163e2136f0b4eef4aac3e650f1b6e655118fd.tar.bz2 |
Remove vestigial cookie/web app permissions prompting UI now that the async UI has been approved for M7.This allows me to more easily change the way the appmodal dialog system works.
http://crbug.com/55121
TEST=existing tests
Review URL: http://codereview.chromium.org/3299020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59838 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
45 files changed, 19 insertions, 2351 deletions
diff --git a/chrome/browser/appcache/chrome_appcache_service.cc b/chrome/browser/appcache/chrome_appcache_service.cc index 6188a3f..58a398e 100644 --- a/chrome/browser/appcache/chrome_appcache_service.cc +++ b/chrome/browser/appcache/chrome_appcache_service.cc @@ -7,8 +7,6 @@ #include "base/file_path.h" #include "base/file_util.h" #include "chrome/browser/browser_list.h" -#include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" -#include "chrome/browser/message_box_handler.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/notification_service.h" @@ -17,32 +15,6 @@ static bool has_initialized_thread_ids; -// ChromeAppCacheService cannot just subclass the delegate interface -// because we may have several prompts pending. -class ChromeAppCacheService::PromptDelegate - : public CookiePromptModalDialogDelegate { - public: - PromptDelegate(ChromeAppCacheService* service, - const GURL& manifest_url, net::CompletionCallback* callback) - : service_(service), manifest_url_(manifest_url), callback_(callback) { - } - - virtual void AllowSiteData(bool session_expire) { - service_->DidPrompt(net::OK, manifest_url_, callback_); - delete this; - } - - virtual void BlockSiteData() { - service_->DidPrompt(net::ERR_ACCESS_DENIED, manifest_url_, callback_); - delete this; - } - - private: - scoped_refptr<ChromeAppCacheService> service_; - GURL manifest_url_; - net::CompletionCallback* callback_; -}; - // ---------------------------------------------------------------------------- ChromeAppCacheService::ChromeAppCacheService() { @@ -106,58 +78,10 @@ int ChromeAppCacheService::CanCreateAppCache( ContentSetting setting = host_contents_settings_map_->GetContentSetting( manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); DCHECK(setting != CONTENT_SETTING_DEFAULT); - if (setting == CONTENT_SETTING_ASK) { - ChromeThread::PostTask( - ChromeThread::UI, FROM_HERE, - NewRunnableMethod(this, &ChromeAppCacheService::DoPrompt, - manifest_url, callback)); - return net::ERR_IO_PENDING; - } return (setting != CONTENT_SETTING_BLOCK) ? net::OK : net::ERR_ACCESS_DENIED; } -void ChromeAppCacheService::DoPrompt( - const GURL& manifest_url, net::CompletionCallback* callback) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - // The setting may have changed (due to the "remember" option) - ContentSetting setting = host_contents_settings_map_->GetContentSetting( - manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); - if (setting != CONTENT_SETTING_ASK) { - int rv = (setting != CONTENT_SETTING_BLOCK) ? net::OK : - net::ERR_ACCESS_DENIED; - DidPrompt(rv, manifest_url, callback); - return; - } - - // Show the prompt on top of the current tab. - Browser* browser = BrowserList::GetLastActive(); - if (!browser || !browser->GetSelectedTabContents()) { - DidPrompt(net::ERR_ACCESS_DENIED, manifest_url, callback); - return; - } - - RunAppCachePrompt(browser->GetSelectedTabContents(), - host_contents_settings_map_, manifest_url, - new PromptDelegate(this, manifest_url, callback)); -} - -void ChromeAppCacheService::DidPrompt( - int rv, const GURL& manifest_url, net::CompletionCallback* callback) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - ChromeThread::PostTask( - ChromeThread::IO, FROM_HERE, - NewRunnableMethod(this, &ChromeAppCacheService::CallCallback, - rv, callback)); -} - -void ChromeAppCacheService::CallCallback( - int rv, net::CompletionCallback* callback) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - callback->Run(rv); -} - void ChromeAppCacheService::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/appcache/chrome_appcache_service.h b/chrome/browser/appcache/chrome_appcache_service.h index 25b2eee..9c33c04 100644 --- a/chrome/browser/appcache/chrome_appcache_service.h +++ b/chrome/browser/appcache/chrome_appcache_service.h @@ -48,8 +48,6 @@ class ChromeAppCacheService friend class ChromeThread; friend class DeleteTask<ChromeAppCacheService>; - class PromptDelegate; - virtual ~ChromeAppCacheService(); // AppCachePolicy overrides @@ -57,13 +55,6 @@ class ChromeAppCacheService virtual int CanCreateAppCache(const GURL& manifest_url, net::CompletionCallback* callback); - // The DoPrompt and DidPrrompt methods are called on the UI thread, and - // the following CallCallback method is called on the IO thread. - void DoPrompt(const GURL& manifest_url, net::CompletionCallback* callback); - void DidPrompt(int rv, const GURL& manifest_url, - net::CompletionCallback* callback); - void CallCallback(int rv, net::CompletionCallback* callback); - // NotificationObserver override virtual void Observe(NotificationType type, const NotificationSource& source, diff --git a/chrome/browser/cocoa/content_exceptions_window_controller.h b/chrome/browser/cocoa/content_exceptions_window_controller.h index 49975e0..ede76f7 100644 --- a/chrome/browser/cocoa/content_exceptions_window_controller.h +++ b/chrome/browser/cocoa/content_exceptions_window_controller.h @@ -32,9 +32,6 @@ class UpdatingContentSettingsObserver; // Is set if "Session" should be a valid option in the "action" popup. BOOL showSession_; - // Is set if the cookie prompt should be disabled. - BOOL disableCookiePrompt_; - // Is set if adding and editing exceptions for the current OTR session should // be allowed. BOOL otrAllowed_; diff --git a/chrome/browser/cocoa/content_exceptions_window_controller.mm b/chrome/browser/cocoa/content_exceptions_window_controller.mm index f8ab91d..e671492 100644 --- a/chrome/browser/cocoa/content_exceptions_window_controller.mm +++ b/chrome/browser/cocoa/content_exceptions_window_controller.mm @@ -135,13 +135,6 @@ const ContentSetting kSessionSettings[] = { CONTENT_SETTING_ALLOW, CONTENT_SETTING_SESSION_ONLY, CONTENT_SETTING_BLOCK }; -// The settings shown in the combobox if show_session_ is true, and we still -// offer the cookie prompt mode. -const ContentSetting kSessionAskSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_ASK, - CONTENT_SETTING_SESSION_ONLY, - CONTENT_SETTING_BLOCK }; - } // namespace //////////////////////////////////////////////////////////////////////////////// @@ -178,8 +171,6 @@ static ContentExceptionsWindowController* model_.reset(new ContentExceptionsTableModel( settingsMap_, otrSettingsMap_, settingsType_)); showSession_ = settingsType_ == CONTENT_SETTINGS_TYPE_COOKIES; - disableCookiePrompt_ = !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCookiePrompt); otrAllowed_ = otrSettingsMap != NULL; tableObserver_.reset(new UpdatingContentSettingsObserver(self)); updatesEnabled_ = YES; @@ -505,12 +496,8 @@ static ContentExceptionsWindowController* } - (size_t)menuItemCount { - if (showSession_) { - return disableCookiePrompt_ ? - arraysize(kSessionSettings) : arraysize(kSessionAskSettings); - } else { - return arraysize(kNoSessionSettings); - } + return showSession_ ? arraysize(kSessionSettings) + : arraysize(kNoSessionSettings); } - (NSString*)titleForIndex:(size_t)index { @@ -519,8 +506,6 @@ static ContentExceptionsWindowController* return l10n_util::GetNSStringWithFixup(IDS_EXCEPTIONS_ALLOW_BUTTON); case CONTENT_SETTING_BLOCK: return l10n_util::GetNSStringWithFixup(IDS_EXCEPTIONS_BLOCK_BUTTON); - case CONTENT_SETTING_ASK: - return l10n_util::GetNSStringWithFixup(IDS_EXCEPTIONS_ASK_BUTTON); case CONTENT_SETTING_SESSION_ONLY: return l10n_util::GetNSStringWithFixup( IDS_EXCEPTIONS_SESSION_ONLY_BUTTON); @@ -531,12 +516,7 @@ static ContentExceptionsWindowController* } - (ContentSetting)settingForIndex:(size_t)index { - if (showSession_) { - return disableCookiePrompt_ ? - kSessionSettings[index] : kSessionAskSettings[index]; - } else { - return kNoSessionSettings[index]; - } + return showSession_ ? kSessionSettings[index] : kNoSessionSettings[index]; } - (size_t)indexForSetting:(ContentSetting)setting { diff --git a/chrome/browser/cocoa/content_setting_bubble_cocoa.mm b/chrome/browser/cocoa/content_setting_bubble_cocoa.mm index c3c8110..6250b8c 100644 --- a/chrome/browser/cocoa/content_setting_bubble_cocoa.mm +++ b/chrome/browser/cocoa/content_setting_bubble_cocoa.mm @@ -436,18 +436,6 @@ NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { [[self window] setFrame:frame display:NO]; } -- (void)removeInfoButton { - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCookiePrompt)) { - // Remove info button and resize vertically. - int deltaY = NSHeight([infoButton_ frame]); - [infoButton_ removeFromSuperview]; - NSRect frame = [[self window] frame]; - frame.size.height -= deltaY; - [[self window] setFrame:frame display:NO]; - } -} - - (void)awakeFromNib { [[self bubble] setBubbleType:info_bubble::kWhiteInfoBubble]; [[self bubble] setArrowLocation:info_bubble::kTopRight]; @@ -462,8 +450,6 @@ NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { [self sizeToFitLoadPluginsButton]; [self initializeBlockedPluginsList]; } - if (type == CONTENT_SETTINGS_TYPE_COOKIES) - [self removeInfoButton]; if (allowBlockRadioGroup_) // not bound in cookie bubble xib [self initializeRadioGroup]; diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.h b/chrome/browser/cocoa/content_settings_dialog_controller.h index 703b9fb..d48b962 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.h +++ b/chrome/browser/cocoa/content_settings_dialog_controller.h @@ -16,8 +16,7 @@ const NSInteger kContentSettingsDisabledIndex = 1; // Indices of the various cookie settings in the cookie radio group. const NSInteger kCookieEnabledIndex = 0; -const NSInteger kCookieAskIndex = 1; -const NSInteger kCookieDisabledIndex = 2; +const NSInteger kCookieDisabledIndex = 1; // Indices of the various plugin settings in the plugins radio group. const NSInteger kPluginsAllowIndex = 0; @@ -49,7 +48,6 @@ class Profile; IBOutlet NSTabView* tabView_; IBOutlet TabViewPickerTable* tabViewPicker_; Profile* profile_; // weak - BOOL disableCookiePrompt_; IntegerPrefMember lastSelectedTab_; BooleanPrefMember clearSiteDataOnExit_; scoped_ptr<ContentSettingsDialogControllerInternal::PrefObserverBridge> diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.mm b/chrome/browser/cocoa/content_settings_dialog_controller.mm index fdfa5a4..0c71fd9 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.mm +++ b/chrome/browser/cocoa/content_settings_dialog_controller.mm @@ -126,8 +126,6 @@ class PrefObserverDisabler { - (id)initWithProfile:(Profile*)profile { DCHECK(profile); - disableCookiePrompt_ = !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCookiePrompt); NSString* nibpath = [mac_util::MainAppBundle() pathForResource:@"ContentSettings" ofType:@"nib"]; @@ -182,9 +180,6 @@ class PrefObserverDisabler { DCHECK(tabViewPicker_); DCHECK_EQ(self, [[self window] delegate]); - [tabView_ removeTabViewItem:[tabView_ - tabViewItemAtIndex:disableCookiePrompt_ ? 0 : 1]]; - // Adapt views to potentially long localized strings. CGFloat windowDelta = 0; for (NSTabViewItem* tab in [tabView_ tabViewItems]) { @@ -243,13 +238,8 @@ class PrefObserverDisabler { - (void)setCookieSettingIndex:(NSInteger)value { ContentSetting setting = CONTENT_SETTING_DEFAULT; - // If the cookie prompt is disabled, the radio button for "block" is at the - // position of the "ask" radio in the old dialog. - if (disableCookiePrompt_ && value == kCookieAskIndex) - value = kCookieDisabledIndex; switch (value) { case kCookieEnabledIndex: setting = CONTENT_SETTING_ALLOW; break; - case kCookieAskIndex: setting = CONTENT_SETTING_ASK; break; case kCookieDisabledIndex: setting = CONTENT_SETTING_BLOCK; break; default: NOTREACHED(); @@ -265,12 +255,7 @@ class PrefObserverDisabler { switch (profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( CONTENT_SETTINGS_TYPE_COOKIES)) { case CONTENT_SETTING_ALLOW: return kCookieEnabledIndex; - case CONTENT_SETTING_ASK: return kCookieAskIndex; - // If the cookie prompt is disabled, the radio button for "block" is at the - // position of the "ask" radio in the old dialog. - case CONTENT_SETTING_BLOCK: return disableCookiePrompt_ ? - kCookieAskIndex : - kCookieDisabledIndex; + case CONTENT_SETTING_BLOCK: return kCookieDisabledIndex; default: NOTREACHED(); return kCookieEnabledIndex; diff --git a/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm b/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm index 75445d4..9298349 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm +++ b/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm @@ -58,9 +58,7 @@ TEST_F(ContentSettingsDialogControllerTest, CookieSetting) { settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); - // Since the cookie prompt is disabled per default, the index of the block - // radio is actually 1 == kCookieAskIndex. - EXPECT_EQ([controller_ cookieSettingIndex], kCookieAskIndex); + EXPECT_EQ([controller_ cookieSettingIndex], kCookieDisabledIndex); // Change dialog property, check setting. NSInteger setting; @@ -69,9 +67,7 @@ TEST_F(ContentSettingsDialogControllerTest, CookieSetting) { settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); EXPECT_EQ(setting, CONTENT_SETTING_ALLOW); - // Since the cookie prompt is disabled per default, the index of the block - // radio is actually 1 == kCookieAskIndex. - [controller_ setCookieSettingIndex:kCookieAskIndex]; + [controller_ setCookieSettingIndex:kCookieDisabledIndex]; setting = settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); EXPECT_EQ(setting, CONTENT_SETTING_BLOCK); diff --git a/chrome/browser/cocoa/cookie_details.h b/chrome/browser/cocoa/cookie_details.h index ce50dd9..09511f0 100644 --- a/chrome/browser/cocoa/cookie_details.h +++ b/chrome/browser/cocoa/cookie_details.h @@ -189,11 +189,6 @@ enum CocoaCookieDetailsType { // the cookie tree in |treeNode|. + (CocoaCookieDetails*)createFromCookieTreeNode:(CookieTreeNode*)treeNode; -// A factory method to create a configured instance given a cookie prompt -// modal dialog in |dialog|. -+ (CocoaCookieDetails*)createFromPromptModalDialog: - (CookiePromptModalDialog*)dialog; - @end // The subpanes of the cookie details view expect to be able to bind to methods diff --git a/chrome/browser/cocoa/cookie_details.mm b/chrome/browser/cocoa/cookie_details.mm index e2b6626..d1d812b 100644 --- a/chrome/browser/cocoa/cookie_details.mm +++ b/chrome/browser/cocoa/cookie_details.mm @@ -8,7 +8,6 @@ #import "base/i18n/time_formatting.h" #include "base/sys_string_conversions.h" #include "grit/generated_resources.h" -#include "chrome/browser/cookie_modal_dialog.h" #include "chrome/browser/cookies_tree_model.h" #include "webkit/appcache/appcache_service.h" @@ -256,39 +255,6 @@ } } -+ (CocoaCookieDetails*)createFromPromptModalDialog:(CookiePromptModalDialog*) - dialog { - CookiePromptModalDialog::DialogType type(dialog->dialog_type()); - CocoaCookieDetails* details = nil; - if (type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE) { - net::CookieMonster::ParsedCookie pc(dialog->cookie_line()); - net::CookieMonster::CanonicalCookie cookie(dialog->origin(), pc); - const std::string& domain(pc.HasDomain() ? pc.Domain() : - dialog->origin().host()); - NSString* domainString = base::SysUTF8ToNSString(domain); - details = [[CocoaCookieDetails alloc] initWithCookie:&cookie - origin:domainString - canEditExpiration:YES]; - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE) { - details = [[CocoaCookieDetails alloc] - initWithLocalStorage:dialog->origin().host() - key:dialog->local_storage_key() - value:dialog->local_storage_value()]; - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_DATABASE) { - details = [[CocoaCookieDetails alloc] - initWithDatabase:dialog->origin().host() - databaseName:dialog->database_name() - databaseDescription:dialog->display_name() - fileSize:dialog->estimated_size()]; - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_APPCACHE) { - details = [[CocoaCookieDetails alloc] - initWithAppCacheManifestURL:dialog->appcache_manifest_url().spec()]; - } else { - NOTIMPLEMENTED(); - } - return [details autorelease]; -} - @end #pragma mark Content Object Adapter diff --git a/chrome/browser/cocoa/cookie_details_view_controller.mm b/chrome/browser/cocoa/cookie_details_view_controller.mm index 01341d5..885779b 100644 --- a/chrome/browser/cocoa/cookie_details_view_controller.mm +++ b/chrome/browser/cocoa/cookie_details_view_controller.mm @@ -9,7 +9,6 @@ #import "base/mac_util.h" #include "base/sys_string_conversions.h" #import "chrome/browser/cocoa/cookie_tree_node.h" -#import "chrome/browser/cookie_modal_dialog.h" #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" namespace { diff --git a/chrome/browser/cocoa/cookie_details_view_controller_unittest.mm b/chrome/browser/cocoa/cookie_details_view_controller_unittest.mm index 76f6e56..a1df90e 100644 --- a/chrome/browser/cocoa/cookie_details_view_controller_unittest.mm +++ b/chrome/browser/cocoa/cookie_details_view_controller_unittest.mm @@ -6,7 +6,6 @@ #include "chrome/browser/cocoa/cocoa_test_helper.h" #include "chrome/browser/cocoa/cookie_details.h" #include "chrome/browser/cocoa/cookie_details_view_controller.h" -#include "chrome/browser/cookie_modal_dialog.h" namespace { diff --git a/chrome/browser/cocoa/cookie_prompt_window_controller.h b/chrome/browser/cocoa/cookie_prompt_window_controller.h deleted file mode 100644 index 0969a9b..0000000 --- a/chrome/browser/cocoa/cookie_prompt_window_controller.h +++ /dev/null @@ -1,65 +0,0 @@ -// 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. - -#import <Cocoa/Cocoa.h> - -#include "base/cocoa_protocols_mac.h" -#include "base/scoped_nsobject.h" - -class CookiePromptModalDialog; -class CookieTreeNode; - -@class CookieDetailsViewController; -@class CocoaCookieTreeNode; - -// This class is the controller for the window displayed -// to the user as a modal dialog prompting them to accept or -// block new cookies and other browser data. -@interface CookiePromptWindowController : NSWindowController { - @private - // Provides access to platform independent information for - // the cookie prompt dialog. - CookiePromptModalDialog* dialog_; // weak; - - // The controller managing the instances of the cookies details view - // embedded in the prompt window. - scoped_nsobject<CookieDetailsViewController> detailsViewController_; - - // The adapter object that supplies the methods expected by - // the cookie details view. - scoped_nsobject<NSObject> selectionAdapterObject_; - - // Outlets to provide quick access to subviews - // in the prompt window. - IBOutlet NSTextField* description_; - IBOutlet NSView* disclosedViewPlaceholder_; - IBOutlet NSButton* disclosureButton_; - IBOutlet NSView* disclosureButtonSuperView_; - IBOutlet NSMatrix* radioGroupMatrix_; - IBOutlet NSButtonCell* rememberChoiceCell_; -} - -// Designated initializer. -- (id)initWithDialog:(CookiePromptModalDialog*)bridge; - -// Performs the modal dialog loop for the cookie prompt dialog -// and processes the result. -- (void)doModalDialog:(void*)context; - -// Handles the toggling of the disclosure triangle -// to reveal cookie data -- (IBAction)disclosureButtonPressed:(id)sender; - -// Callback for "block" button. -- (IBAction)block:(id)sender; - -// Callback for "accept" button. -- (IBAction)accept:(id)sender; - -// Processes the selection result code made in the cookie prompt. -// Part of the public interface for the tests. -- (void)processModalDialogResult:(void*)contextInfo - returnCode:(int)returnCode; - -@end diff --git a/chrome/browser/cocoa/cookie_prompt_window_controller.mm b/chrome/browser/cocoa/cookie_prompt_window_controller.mm deleted file mode 100644 index 345aefb..0000000 --- a/chrome/browser/cocoa/cookie_prompt_window_controller.mm +++ /dev/null @@ -1,214 +0,0 @@ -// 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. - -#import "chrome/browser/cocoa/cookie_prompt_window_controller.h" - -#include <string> -#include <vector> - -#include "app/l10n_util_mac.h" -#include "app/resource_bundle.h" -#import "base/mac_util.h" -#include "base/sys_string_conversions.h" -#import "chrome/browser/cocoa/cookie_details_view_controller.h" -#include "chrome/browser/cocoa/cookie_tree_node.h" -#include "chrome/browser/cookie_modal_dialog.h" -#include "chrome/browser/cookies_tree_model.h" -#include "grit/generated_resources.h" -#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" - -namespace { -static const CGFloat kExtraMarginForDetailsView = 10; -} - -@implementation CookiePromptWindowController - -- (id)initWithDialog:(CookiePromptModalDialog*)dialog { - NSString* nibpath = [mac_util::MainAppBundle() - pathForResource:@"CookiePrompt" - ofType:@"nib"]; - if ((self = [super initWithWindowNibPath:nibpath owner:self])) { - dialog_ = dialog; - CocoaCookieDetails* details = [CocoaCookieDetails - createFromPromptModalDialog:dialog]; - selectionAdapterObject_.reset([[CookiePromptContentDetailsAdapter alloc] - initWithDetails:details]); - } - return self; -} - -// Ensures that all parameterized localized strings are filled in. -- (void)doLocalizationTweaks { - int descriptionStringId = 0; - switch (dialog_->dialog_type()) { - case CookiePromptModalDialog::DIALOG_TYPE_COOKIE: - descriptionStringId = IDS_COOKIE_ALERT_LABEL; - break; - case CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE: - case CookiePromptModalDialog::DIALOG_TYPE_DATABASE: - case CookiePromptModalDialog::DIALOG_TYPE_APPCACHE: - descriptionStringId = IDS_DATA_ALERT_LABEL; - break; - default: - NOTREACHED(); - break; - } - - string16 displayHost = UTF8ToUTF16(dialog_->origin().host()); - NSString* description = l10n_util::GetNSStringF( - descriptionStringId, displayHost); - [description_ setStringValue:description]; - - // Add the host to the "remember for future prompts" radio button. - NSString* allowText = l10n_util::GetNSStringWithFixup( - IDS_COOKIE_ALERT_REMEMBER_RADIO); - NSString* replacedCellText = base::SysUTF16ToNSString( - ReplaceStringPlaceholders(base::SysNSStringToUTF16(allowText), - displayHost, NULL)); - [rememberChoiceCell_ setTitle:replacedCellText]; -} - -// Adjust the vertical layout of the views in the window so that -// they are spaced correctly with their fully localized contents. -- (void)doLayoutTweaks { - // Wrap the description text. - CGFloat sizeDelta = [GTMUILocalizerAndLayoutTweaker - sizeToFitFixedWidthTextField:description_]; - NSRect descriptionFrame = [description_ frame]; - descriptionFrame.origin.y -= sizeDelta; - [description_ setFrame:descriptionFrame]; - - // |wrapRadioGroupForWidth:| takes the font that is set on the - // radio group to do the wrapping. It must be set explicitly, otherwise - // the wrapping is based on the |NSRegularFontSize| rather than - // |NSSmallFontSize| - CGFloat fontSize = [NSFont systemFontSizeForControlSize:NSSmallControlSize]; - [radioGroupMatrix_ setFont:[NSFont controlContentFontOfSize:fontSize]]; - - // Wrap the radio buttons to fit if necessary. - [GTMUILocalizerAndLayoutTweaker - wrapRadioGroupForWidth:radioGroupMatrix_]; - sizeDelta += [GTMUILocalizerAndLayoutTweaker - sizeToFitView:radioGroupMatrix_].height; - NSRect radioGroupFrame = [radioGroupMatrix_ frame]; - radioGroupFrame.origin.y -= sizeDelta; - [radioGroupMatrix_ setFrame:radioGroupFrame]; - - // Adjust views location, they may have moved through the - // expansion of the radio buttons and description text. - NSRect disclosureViewFrame = [disclosureButtonSuperView_ frame]; - disclosureViewFrame.origin.y -= sizeDelta; - [disclosureButtonSuperView_ setFrame:disclosureViewFrame]; - - // Adjust the final window size by the size of the cookie details - // view, since it will be initially hidden. - NSRect detailsViewRect = [disclosedViewPlaceholder_ frame]; - sizeDelta -= detailsViewRect.size.height; - sizeDelta -= kExtraMarginForDetailsView; - - // Final resize the window to fit all of the adjustments - NSRect frame = [[self window] frame]; - frame.origin.y -= sizeDelta; - frame.size.height += sizeDelta; - [[self window] setFrame:frame display:NO animate:NO]; -} - -- (void)replaceCookieDetailsView { - detailsViewController_.reset([[CookieDetailsViewController alloc] init]); - - [detailsViewController_ setContentObject:selectionAdapterObject_.get()]; - - [[disclosedViewPlaceholder_ superview] - replaceSubview:disclosedViewPlaceholder_ - with:[detailsViewController_ view]]; - - [detailsViewController_ shrinkViewToFit]; -} - -- (void)awakeFromNib { - DCHECK(disclosureButton_); - DCHECK(radioGroupMatrix_); - DCHECK(disclosedViewPlaceholder_); - DCHECK(disclosureButtonSuperView_); - - [self doLocalizationTweaks]; - [self doLayoutTweaks]; - [self replaceCookieDetailsView]; - - [[detailsViewController_ view] setHidden:YES]; -} - -- (void)windowWillClose:(NSNotification*)notif { - [self autorelease]; -} - -// |contextInfo| is the bridge back to the C++ CookiePromptModalDialog. -- (void)processModalDialogResult:(void*)contextInfo - returnCode:(int)returnCode { - CookiePromptModalDialog* bridge = - reinterpret_cast<CookiePromptModalDialog*>(contextInfo); - bool remember = [radioGroupMatrix_ selectedRow] == 0; - switch (returnCode) { - case NSAlertFirstButtonReturn: { // OK - bool sessionExpire = ![detailsViewController_.get() hasExpiration]; - bridge->AllowSiteData(remember, sessionExpire); - break; - } - case NSAlertSecondButtonReturn: { // Cancel - bridge->BlockSiteData(remember); - break; - } - default: { - NOTREACHED(); - remember = false; - bridge->BlockSiteData(remember); - } - } -} - -- (void)doModalDialog:(void*)context { - NSInteger returnCode = [NSApp runModalForWindow:[self window]]; - [self processModalDialogResult:context returnCode:returnCode]; -} - -- (IBAction)disclosureButtonPressed:(id)sender { - NSWindow* window = [self window]; - NSRect frame = [[self window] frame]; - CGFloat sizeChange = [[detailsViewController_.get() view] frame].size.height + - kExtraMarginForDetailsView; - switch ([sender state]) { - case NSOnState: - frame.size.height += sizeChange; - frame.origin.y -= sizeChange; - break; - case NSOffState: - frame.size.height -= sizeChange; - frame.origin.y += sizeChange; - break; - default: - NOTREACHED(); - break; - } - if ([sender state] == NSOffState) { - [[detailsViewController_ view] setHidden:YES]; - } - [window setFrame:frame display:YES animate:YES]; - if ([sender state] == NSOnState) { - [[detailsViewController_ view] setHidden:NO]; - } -} - -// Callback for "accept" button. -- (IBAction)accept:(id)sender { - [[self window] close]; - [NSApp stopModalWithCode:NSAlertFirstButtonReturn]; -} - -// Callback for "block" button. -- (IBAction)block:(id)sender { - [[self window] close]; - [NSApp stopModalWithCode:NSAlertSecondButtonReturn]; -} - -@end diff --git a/chrome/browser/cocoa/cookie_prompt_window_controller_unittest.mm b/chrome/browser/cocoa/cookie_prompt_window_controller_unittest.mm deleted file mode 100644 index eeb8e25..0000000 --- a/chrome/browser/cocoa/cookie_prompt_window_controller_unittest.mm +++ /dev/null @@ -1,243 +0,0 @@ -// 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. - -#include "base/message_loop.h" -#include "base/sys_string_conversions.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/browser/cocoa/cocoa_test_helper.h" -#include "chrome/browser/cocoa/cookie_prompt_window_controller.h" -#include "chrome/browser/cookie_modal_dialog.h" -#include "chrome/browser/host_content_settings_map.h" -#include "chrome/test/testing_profile.h" - -// A mock class which implements just enough functionality to -// act as a radio with a pre-specified selected button. -@interface MockRadioButtonMatrix : NSObject { - @private - NSInteger selectedRow_; -} -- (NSInteger)selectedRow; -@end - -@implementation MockRadioButtonMatrix - -- (id)initWithSelectedRow:(NSInteger)selectedRow { - if ((self = [super init])) { - selectedRow_ = selectedRow; - } - return self; -} - -- (NSInteger)selectedRow { - return selectedRow_; -} -@end - -namespace { - -// A subclass of the |CookiePromptModalDialog| that allows tests of -// some of the prompt window controller's functionality without having -// a full environment by overriding select methods and intercepting -// calls that would otherwise rely on behavior only present in a full -// environment. -class CookiePromptModalDialogMock : public CookiePromptModalDialog { - public: - CookiePromptModalDialogMock(const GURL& origin, - const std::string& cookieLine, - HostContentSettingsMap* hostContentSettingsMap); - - virtual void AllowSiteData(bool remember, bool session_expire); - virtual void BlockSiteData(bool remember); - - bool allow() const { return allow_; } - bool remember() const { return remember_; } - - private: - - // The result of the block/unblock decision. - bool allow_; - - // Whether the block/accept decision should be remembered. - bool remember_; -}; - -CookiePromptModalDialogMock::CookiePromptModalDialogMock( - const GURL& origin, - const std::string& cookieLine, - HostContentSettingsMap* hostContentSettingsMap) - : CookiePromptModalDialog(NULL, hostContentSettingsMap, origin, cookieLine, - NULL), - allow_(false), - remember_(false) { -} - -void CookiePromptModalDialogMock::AllowSiteData(bool remember, - bool session_expire) { - remember_ = remember; - allow_ = true; -} - -void CookiePromptModalDialogMock::BlockSiteData(bool remember) { - remember_ = remember; - allow_ = false; -} - -class CookiePromptWindowControllerTest : public CocoaTest { - public: - CookiePromptWindowControllerTest() - : ui_thread_(ChromeThread::UI, &message_loop_) { - hostContentSettingsMap_ = profile_.GetHostContentSettingsMap(); - } - - MessageLoopForUI message_loop_; - ChromeThread ui_thread_; - TestingProfile profile_; - scoped_refptr<HostContentSettingsMap> hostContentSettingsMap_; -}; - -TEST_F(CookiePromptWindowControllerTest, CreateForCookie) { - GURL url("http://chromium.org"); - std::string cookieLine( - "PHPSESSID=0123456789abcdef0123456789abcdef; path=/"); - scoped_ptr<CookiePromptModalDialog> dialog( - new CookiePromptModalDialog(NULL, hostContentSettingsMap_, url, - cookieLine, NULL)); - scoped_nsobject<CookiePromptWindowController> controller( - [[CookiePromptWindowController alloc] initWithDialog:dialog.get()]); - EXPECT_TRUE(controller.get()); - EXPECT_TRUE([controller.get() window]); -} - -TEST_F(CookiePromptWindowControllerTest, CreateForDatabase) { - GURL url("http://google.com"); - string16 databaseName(base::SysNSStringToUTF16(@"some database")); - string16 databaseDescription(base::SysNSStringToUTF16(@"some desc")); - scoped_ptr<CookiePromptModalDialog> dialog( - new CookiePromptModalDialog(NULL, hostContentSettingsMap_, - url, databaseName, databaseDescription, 3456, - NULL)); - scoped_nsobject<CookiePromptWindowController> controller( - [[CookiePromptWindowController alloc] initWithDialog:dialog.get()]); - EXPECT_TRUE(controller.get()); - EXPECT_TRUE([controller.get() window]); -} - -TEST_F(CookiePromptWindowControllerTest, CreateForLocalStorage) { - GURL url("http://chromium.org"); - string16 key(base::SysNSStringToUTF16(@"key")); - string16 value(base::SysNSStringToUTF16(@"value")); - scoped_ptr<CookiePromptModalDialog> dialog( - new CookiePromptModalDialog(NULL, hostContentSettingsMap_, url, key, - value, NULL)); - scoped_nsobject<CookiePromptWindowController> controller( - [[CookiePromptWindowController alloc] initWithDialog:dialog.get()]); - EXPECT_TRUE(controller.get()); - EXPECT_TRUE([controller.get() window]); -} - -TEST_F(CookiePromptWindowControllerTest, RememberMyChoiceAllow) { - GURL url("http://chromium.org"); - std::string cookieLine( - "PHPSESSID=0123456789abcdef0123456789abcdef; path=/"); - scoped_ptr<CookiePromptModalDialogMock> dialog( - new CookiePromptModalDialogMock(url, cookieLine, - hostContentSettingsMap_)); - scoped_nsobject<CookiePromptWindowController> controller( - [[CookiePromptWindowController alloc] initWithDialog:dialog.get()]); - scoped_nsobject<MockRadioButtonMatrix> checkbox([[MockRadioButtonMatrix alloc] - initWithSelectedRow:0]); - [controller.get() setValue:checkbox.get() forKey:@"radioGroupMatrix_"]; - - [controller.get() processModalDialogResult:dialog.get() - returnCode:NSAlertFirstButtonReturn]; - - // Need to make sure that the retainCount for the mock radio button - // goes back down to 1--the controller won't do it for us. And - // even calling setValue:forKey: again with a nil doesn't - // decrement it. Ugly, but otherwise valgrind complains. - [checkbox.get() release]; - - EXPECT_TRUE(dialog->remember()); - EXPECT_TRUE(dialog->allow()); -} - -TEST_F(CookiePromptWindowControllerTest, RememberMyChoiceBlock) { - GURL url("http://codereview.chromium.org"); - std::string cookieLine( - "PHPSESSID=0123456789abcdef0123456789abcdef; path=/"); - scoped_ptr<CookiePromptModalDialogMock> dialog( - new CookiePromptModalDialogMock(url, cookieLine, - hostContentSettingsMap_)); - scoped_nsobject<CookiePromptWindowController> controller( - [[CookiePromptWindowController alloc] initWithDialog:dialog.get()]); - scoped_nsobject<MockRadioButtonMatrix> checkbox([[MockRadioButtonMatrix alloc] - initWithSelectedRow:0]); - [controller.get() setValue:checkbox.get() forKey:@"radioGroupMatrix_"]; - - [controller.get() processModalDialogResult:dialog.get() - returnCode:NSAlertSecondButtonReturn]; - - // Need to make sure that the retainCount for the mock radio button - // goes back down to 1--the controller won't do it for us. And - // even calling setValue:forKey: again with nil doesn't - // decrement it. Ugly, but otherwise valgrind complains. - [checkbox.get() release]; - - EXPECT_TRUE(dialog->remember()); - EXPECT_FALSE(dialog->allow()); -} - -TEST_F(CookiePromptWindowControllerTest, DontRememberMyChoiceAllow) { - GURL url("http://chromium.org"); - std::string cookieLine( - "PHPSESSID=0123456789abcdef0123456789abcdef; path=/"); - scoped_ptr<CookiePromptModalDialogMock> dialog( - new CookiePromptModalDialogMock(url, cookieLine, - hostContentSettingsMap_)); - scoped_nsobject<CookiePromptWindowController> controller( - [[CookiePromptWindowController alloc] initWithDialog:dialog.get()]); - scoped_nsobject<MockRadioButtonMatrix> checkbox([[MockRadioButtonMatrix alloc] - initWithSelectedRow:1]); - [controller.get() setValue:checkbox.get() forKey:@"radioGroupMatrix_"]; - - [controller.get() processModalDialogResult:dialog.get() - returnCode:NSAlertFirstButtonReturn]; - - // Need to make sure that the retainCount for the mock radio button - // goes back down to 1--the controller won't do it for us. And - // even calling setValue:forKey: again with a nil doesn't - // decrement it. Ugly, but otherwise valgrind complains. - [checkbox.get() release]; - - EXPECT_FALSE(dialog->remember()); - EXPECT_TRUE(dialog->allow()); -} - -TEST_F(CookiePromptWindowControllerTest, DontRememberMyChoiceBlock) { - GURL url("http://codereview.chromium.org"); - std::string cookieLine( - "PHPSESSID=0123456789abcdef0123456789abcdef; path=/"); - scoped_ptr<CookiePromptModalDialogMock> dialog( - new CookiePromptModalDialogMock(url, cookieLine, - hostContentSettingsMap_)); - scoped_nsobject<CookiePromptWindowController> controller( - [[CookiePromptWindowController alloc] initWithDialog:dialog.get()]); - scoped_nsobject<MockRadioButtonMatrix> checkbox([[MockRadioButtonMatrix alloc] - initWithSelectedRow:1]); - [controller.get() setValue:checkbox.get() forKey:@"radioGroupMatrix_"]; - - [controller.get() processModalDialogResult:dialog.get() - returnCode:NSAlertSecondButtonReturn]; - - // Need to make sure that the retainCount for the mock radio button - // goes back down to 1--the controller won't do it for us. And - // even calling setValue:forKey: again with a nil doesn't - // decrement it. Ugly, but otherwise valgrind complains. - [checkbox.get() release]; - - EXPECT_FALSE(dialog->remember()); - EXPECT_FALSE(dialog->allow()); -} - -} // namespace diff --git a/chrome/browser/content_exceptions_table_model.cc b/chrome/browser/content_exceptions_table_model.cc index e8bb22f..bf32612 100644 --- a/chrome/browser/content_exceptions_table_model.cc +++ b/chrome/browser/content_exceptions_table_model.cc @@ -105,8 +105,6 @@ std::wstring ContentExceptionsTableModel::GetText(int row, int column_id) { return l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON); case CONTENT_SETTING_BLOCK: return l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON); - case CONTENT_SETTING_ASK: - return l10n_util::GetString(IDS_EXCEPTIONS_ASK_BUTTON); case CONTENT_SETTING_SESSION_ONLY: return l10n_util::GetString(IDS_EXCEPTIONS_SESSION_ONLY_BUTTON); default: diff --git a/chrome/browser/content_setting_bubble_model.cc b/chrome/browser/content_setting_bubble_model.cc index ed0700a..71055a6 100644 --- a/chrome/browser/content_setting_bubble_model.cc +++ b/chrome/browser/content_setting_bubble_model.cc @@ -88,9 +88,7 @@ class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { tab_contents()->GetTabSpecificContentSettings()->IsContentAccessed( content_type()) && !tab_contents()->GetTabSpecificContentSettings()->IsContentBlocked( - content_type()) && - !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCookiePrompt)) { + content_type())) { title_ids = kAccessedTitleIDs; } else if (!bubble_content().resource_identifiers.empty()) { title_ids = kResourceSpecificBlockedTitleIDs; @@ -127,9 +125,7 @@ class ContentSettingTitleLinkAndInfoModel Profile* profile, ContentSettingsType content_type) : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCookiePrompt)) - SetInfoLink(); + SetInfoLink(); } private: diff --git a/chrome/browser/content_setting_combo_model.cc b/chrome/browser/content_setting_combo_model.cc index a26f9f4..c1fabfc 100644 --- a/chrome/browser/content_setting_combo_model.cc +++ b/chrome/browser/content_setting_combo_model.cc @@ -21,31 +21,18 @@ const ContentSetting kSessionSettings[] = { CONTENT_SETTING_ALLOW, CONTENT_SETTING_SESSION_ONLY, CONTENT_SETTING_BLOCK }; -// The settings shown in the combobox if show_session_ is true, and we still -// offer the cookie prompt mode. -const ContentSetting kSessionAskSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_ASK, - CONTENT_SETTING_SESSION_ONLY, - CONTENT_SETTING_BLOCK }; - } // namespace ContentSettingComboModel::ContentSettingComboModel(bool show_session) - : show_session_(show_session), - disable_cookie_prompt_(!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCookiePrompt)) { + : show_session_(show_session) { } ContentSettingComboModel::~ContentSettingComboModel() { } int ContentSettingComboModel::GetItemCount() { - if (show_session_) { - return disable_cookie_prompt_ ? - arraysize(kSessionSettings) : arraysize(kSessionAskSettings); - } else { - return arraysize(kNoSessionSettings); - } + return show_session_ ? arraysize(kSessionSettings) + : arraysize(kNoSessionSettings); } string16 ContentSettingComboModel::GetItemAt(int index) { @@ -54,8 +41,6 @@ string16 ContentSettingComboModel::GetItemAt(int index) { return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON); case CONTENT_SETTING_BLOCK: return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON); - case CONTENT_SETTING_ASK: - return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ASK_BUTTON); case CONTENT_SETTING_SESSION_ONLY: return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_SESSION_ONLY_BUTTON); default: @@ -65,12 +50,7 @@ string16 ContentSettingComboModel::GetItemAt(int index) { } ContentSetting ContentSettingComboModel::SettingForIndex(int index) { - if (show_session_) { - return disable_cookie_prompt_ ? - kSessionSettings[index] : kSessionAskSettings[index]; - } else { - return kNoSessionSettings[index]; - } + return show_session_ ? kSessionSettings[index] : kNoSessionSettings[index]; } int ContentSettingComboModel::IndexForSetting(ContentSetting setting) { diff --git a/chrome/browser/content_setting_combo_model.h b/chrome/browser/content_setting_combo_model.h index dac487f..6e9a740 100644 --- a/chrome/browser/content_setting_combo_model.h +++ b/chrome/browser/content_setting_combo_model.h @@ -27,8 +27,6 @@ class ContentSettingComboModel : public ComboboxModel { private: const bool show_session_; - const bool disable_cookie_prompt_; - DISALLOW_COPY_AND_ASSIGN(ContentSettingComboModel); }; diff --git a/chrome/browser/content_setting_image_model.cc b/chrome/browser/content_setting_image_model.cc index 0593991..84d19cd 100644 --- a/chrome/browser/content_setting_image_model.cc +++ b/chrome/browser/content_setting_image_model.cc @@ -92,9 +92,7 @@ void ContentSettingBlockedImageModel::UpdateFromTabContents( if (content_settings->IsContentBlocked(get_content_settings_type())) { icon_ids = kBlockedIconIDs; tooltip_ids = kBlockedTooltipIDs; - } else if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCookiePrompt) && - tab_contents->profile()->GetHostContentSettingsMap()-> + } else if (tab_contents->profile()->GetHostContentSettingsMap()-> GetDefaultContentSetting(get_content_settings_type()) == CONTENT_SETTING_BLOCK && content_settings->IsContentAccessed(get_content_settings_type())) { diff --git a/chrome/browser/cookie_modal_dialog.cc b/chrome/browser/cookie_modal_dialog.cc deleted file mode 100644 index 568c00e..0000000 --- a/chrome/browser/cookie_modal_dialog.cc +++ /dev/null @@ -1,152 +0,0 @@ -// 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. - -#include "chrome/browser/cookie_modal_dialog.h" - -#include "app/message_box_flags.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/host_content_settings_map.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/pref_names.h" - -// Cookies -CookiePromptModalDialog::CookiePromptModalDialog( - TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& origin, - const std::string& cookie_line, - CookiePromptModalDialogDelegate* delegate) - : AppModalDialog(tab_contents, std::wstring()), - host_content_settings_map_(host_content_settings_map), - dialog_type_(DIALOG_TYPE_COOKIE), - origin_(origin), - cookie_line_(cookie_line), - estimated_size_(0), - delegate_(delegate) { -} - -// LocalStorage -CookiePromptModalDialog::CookiePromptModalDialog( - TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& origin, - const string16& key, - const string16& value, - CookiePromptModalDialogDelegate* delegate) - : AppModalDialog(tab_contents, std::wstring()), - host_content_settings_map_(host_content_settings_map), - dialog_type_(DIALOG_TYPE_LOCAL_STORAGE), - origin_(origin), - local_storage_key_(key), - local_storage_value_(value), - estimated_size_(0), - delegate_(delegate) { -} - -// Database -CookiePromptModalDialog::CookiePromptModalDialog( - TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& origin, - const string16& database_name, - const string16& display_name, - unsigned long estimated_size, - CookiePromptModalDialogDelegate* delegate) - : AppModalDialog(tab_contents, std::wstring()), - host_content_settings_map_(host_content_settings_map), - dialog_type_(DIALOG_TYPE_DATABASE), - origin_(origin), - database_name_(database_name), - display_name_(display_name), - estimated_size_(estimated_size), - delegate_(delegate) { -} - -// AppCache -CookiePromptModalDialog::CookiePromptModalDialog( - TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& appcache_manifest_url, - CookiePromptModalDialogDelegate* delegate) - : AppModalDialog(tab_contents, std::wstring()), - host_content_settings_map_(host_content_settings_map), - dialog_type_(DIALOG_TYPE_APPCACHE), - origin_(appcache_manifest_url.GetOrigin()), - estimated_size_(0), - appcache_manifest_url_(appcache_manifest_url), - delegate_(delegate) { -} - -CookiePromptModalDialog::~CookiePromptModalDialog() { -} - -bool CookiePromptModalDialog::IsValid() { - ContentSetting content_setting = - host_content_settings_map_->GetContentSetting( - origin_, CONTENT_SETTINGS_TYPE_COOKIES, ""); - if (content_setting != CONTENT_SETTING_ASK) { - if (content_setting == CONTENT_SETTING_ALLOW) { - AllowSiteData(false, false); - } else if (content_setting == CONTENT_SETTING_SESSION_ONLY) { - AllowSiteData(false, true); - } else { - DCHECK(content_setting == CONTENT_SETTING_BLOCK); - BlockSiteData(false); - } - return false; - } - return !skip_this_dialog_; -} - -void CookiePromptModalDialog::AllowSiteData(bool remember, - bool session_expire) { - if (remember) { - // Make sure there is no entry that would override the pattern we are about - // to insert for exactly this URL. - host_content_settings_map_->SetContentSetting( - HostContentSettingsMap::Pattern::FromURLNoWildcard(origin_), - CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_DEFAULT); - host_content_settings_map_->SetContentSetting( - HostContentSettingsMap::Pattern::FromURL(origin_), - CONTENT_SETTINGS_TYPE_COOKIES, - "", - session_expire ? CONTENT_SETTING_SESSION_ONLY : CONTENT_SETTING_ALLOW); - } - - if (delegate_) { - delegate_->AllowSiteData(session_expire); - delegate_ = NULL; // It can be deleted at any point now. - } -} - -void CookiePromptModalDialog::BlockSiteData(bool remember) { - if (remember) { - // Make sure there is no entry that would override the pattern we are about - // to insert for exactly this URL. - host_content_settings_map_->SetContentSetting( - HostContentSettingsMap::Pattern::FromURLNoWildcard(origin_), - CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_DEFAULT); - host_content_settings_map_->SetContentSetting( - HostContentSettingsMap::Pattern::FromURL(origin_), - CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); - } - - if (delegate_) { - delegate_->BlockSiteData(); - delegate_ = NULL; // It can be deleted at any point now. - } -} - -// static -void CookiePromptModalDialog::RegisterUserPrefs(PrefService* prefs) { - prefs->RegisterBooleanPref(prefs::kCookiePromptExpanded, false); -} - -int CookiePromptModalDialog::GetDialogButtons() { - // Enable the automation interface to accept/dismiss this dialog. - return MessageBoxFlags::DIALOGBUTTON_OK | - MessageBoxFlags::DIALOGBUTTON_CANCEL; -} diff --git a/chrome/browser/cookie_modal_dialog.h b/chrome/browser/cookie_modal_dialog.h deleted file mode 100644 index 8b7d333..0000000 --- a/chrome/browser/cookie_modal_dialog.h +++ /dev/null @@ -1,155 +0,0 @@ -// 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_BROWSER_COOKIE_MODAL_DIALOG_H_ -#define CHROME_BROWSER_COOKIE_MODAL_DIALOG_H_ -#pragma once - -#include <string> - -#include "base/ref_counted.h" -#include "chrome/browser/app_modal_dialog.h" -#include "chrome/browser/browsing_data_local_storage_helper.h" -#include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" -#include "googleurl/src/gurl.h" - -#if defined(OS_LINUX) -#include "app/gtk_signal.h" -#endif - -#if defined(OS_MACOSX) -#if __OBJC__ -@class NSWindow; -#else -class NSWindow; -#endif -#endif - -class HostContentSettingsMap; -class PrefService; - -#if defined(OS_LINUX) -typedef struct _GtkWidget GtkWidget; -typedef struct _GParamSpec GParamSpec; -#endif - -// A controller+model class for cookie and local storage warning prompt. -// |NativeDialog| is a platform specific view. -class CookiePromptModalDialog : public AppModalDialog { - public: - enum DialogType { - DIALOG_TYPE_COOKIE = 0, - DIALOG_TYPE_LOCAL_STORAGE, - DIALOG_TYPE_DATABASE, - DIALOG_TYPE_APPCACHE - }; - - // A union of data necessary to determine the type of message box to - // show. - CookiePromptModalDialog(TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& origin, - const std::string& cookie_line, - CookiePromptModalDialogDelegate* delegate); - CookiePromptModalDialog(TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& origin, - const string16& key, - const string16& value, - CookiePromptModalDialogDelegate* delegate); - CookiePromptModalDialog(TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& origin, - const string16& database_name, - const string16& display_name, - unsigned long estimated_size, - CookiePromptModalDialogDelegate* delegate); - CookiePromptModalDialog(TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& appcache_manifest_url, - CookiePromptModalDialogDelegate* delegate); - virtual ~CookiePromptModalDialog(); - - static void RegisterUserPrefs(PrefService* prefs); - - // AppModalDialog overrides. -#if defined(OS_POSIX) - virtual void CreateAndShowDialog(); -#endif - virtual int GetDialogButtons(); - virtual void AcceptWindow(); - virtual void CancelWindow(); - virtual bool IsValid(); - -#if defined(OS_MACOSX) - virtual void CloseModalDialog(); -#endif - - DialogType dialog_type() const { return dialog_type_; } - const GURL& origin() const { return origin_; } - const std::string& cookie_line() const { return cookie_line_; } - const string16& local_storage_key() const { return local_storage_key_; } - const string16& local_storage_value() const { return local_storage_value_; } - const string16& database_name() const { return database_name_; } - const string16& display_name() const { return display_name_; } - unsigned long estimated_size() const { return estimated_size_; } - const GURL& appcache_manifest_url() const { return appcache_manifest_url_; } - TabContents* tab_contents() const { return tab_contents_; } - - // Implement CookiePromptModalDialogDelegate. - virtual void AllowSiteData(bool remember, bool session_expire); - virtual void BlockSiteData(bool remember); - - protected: - // AppModalDialog overrides. - virtual NativeDialog CreateNativeDialog(); -#if defined(TOOLKIT_USES_GTK) - virtual void HandleDialogResponse(GtkDialog* dialog, gint response_id); - CHROMEGTK_CALLBACK_1(CookiePromptModalDialog, - void, - OnExpanderActivate, - GParamSpec*); -#endif - - private: - -#if defined(OS_MACOSX) - NSWindow* dialog_; -#endif - - // Used to verify our request is still necessary and when the response should - // persist. - scoped_refptr<HostContentSettingsMap> host_content_settings_map_; - - const DialogType dialog_type_; - - // The origin connected to this request. - const GURL origin_; - - // Which data members are relevant depends on the dialog_type. - const std::string cookie_line_; - const string16 local_storage_key_; - const string16 local_storage_value_; - const string16 database_name_; - const string16 display_name_; - unsigned long estimated_size_; - const GURL appcache_manifest_url_; - - // The caller should provide a delegate in order to receive results - // from this delegate. Any time after calling one of these methods, the - // delegate could be deleted - CookiePromptModalDialogDelegate* delegate_; - -#if defined(TOOLKIT_USES_GTK) - // The "remember this choice" radio button in the dialog. - GtkWidget* remember_radio_; - - // The cookie view; we keep this to querry the result combobox. - GtkWidget* cookie_view_; -#endif - - DISALLOW_COPY_AND_ASSIGN(CookiePromptModalDialog); -}; - -#endif // CHROME_BROWSER_COOKIE_MODAL_DIALOG_H_ diff --git a/chrome/browser/cookie_modal_dialog_gtk.cc b/chrome/browser/cookie_modal_dialog_gtk.cc deleted file mode 100644 index 8e39948..0000000 --- a/chrome/browser/cookie_modal_dialog_gtk.cc +++ /dev/null @@ -1,154 +0,0 @@ -// 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. - -#include "chrome/browser/cookie_modal_dialog.h" - -#include "app/l10n_util.h" -#include "base/logging.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/gtk/gtk_chrome_cookie_view.h" -#include "chrome/browser/gtk/gtk_chrome_link_button.h" -#include "chrome/browser/gtk/gtk_util.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/views/cookie_prompt_view.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/pref_names.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" - -void CookiePromptModalDialog::CreateAndShowDialog() { - dialog_ = CreateNativeDialog(); - gtk_util::ShowModalDialogWithMinLocalizedWidth(GTK_WIDGET(dialog_), - IDS_ALERT_DIALOG_WIDTH_CHARS); -} - -void CookiePromptModalDialog::AcceptWindow() { - HandleDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); -} - -void CookiePromptModalDialog::CancelWindow() { - HandleDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_REJECT); -} - -NativeDialog CookiePromptModalDialog::CreateNativeDialog() { - gtk_util::MakeAppModalWindowGroup(); - - gfx::NativeWindow window = tab_contents_->GetMessageBoxRootWindow(); - CookiePromptModalDialog::DialogType type = dialog_type(); - NativeDialog dialog = gtk_dialog_new_with_buttons( - l10n_util::GetStringFUTF8( - type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE ? - IDS_COOKIE_ALERT_TITLE : IDS_DATA_ALERT_TITLE, - UTF8ToUTF16(origin().host())).c_str(), - window, - static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), - l10n_util::GetStringUTF8(IDS_COOKIE_ALERT_BLOCK_BUTTON).c_str(), - GTK_RESPONSE_REJECT, - l10n_util::GetStringUTF8(IDS_COOKIE_ALERT_ALLOW_BUTTON).c_str(), - GTK_RESPONSE_ACCEPT, - NULL); - gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); - - GtkWidget* content_area = GTK_DIALOG(dialog)->vbox; - gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); - - string16 display_host = UTF8ToUTF16(origin().host()); - GtkWidget* label = gtk_util::LeftAlignMisc(gtk_label_new( - l10n_util::GetStringFUTF8( - type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE ? - IDS_COOKIE_ALERT_LABEL : IDS_DATA_ALERT_LABEL, - display_host).c_str())); - gtk_box_pack_start(GTK_BOX(content_area), label, FALSE, FALSE, 0); - - // Create a vbox for all the radio buttons so they aren't too far away from - // each other. - GtkWidget* radio_box = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - remember_radio_ = gtk_radio_button_new_with_label(NULL, - l10n_util::GetStringFUTF8(IDS_COOKIE_ALERT_REMEMBER_RADIO, - display_host).c_str()); - gtk_box_pack_start(GTK_BOX(radio_box), remember_radio_, FALSE, FALSE, 0); - - GtkWidget* ask_radio = gtk_radio_button_new_with_label_from_widget( - GTK_RADIO_BUTTON(remember_radio_), - l10n_util::GetStringUTF8(IDS_COOKIE_ALERT_ASK_RADIO).c_str()); - gtk_box_pack_start(GTK_BOX(radio_box), ask_radio, FALSE, FALSE, 0); - - gtk_box_pack_start(GTK_BOX(content_area), radio_box, FALSE, FALSE, 0); - - GtkWidget* expander = gtk_expander_new( - l10n_util::GetStringUTF8(IDS_COOKIE_SHOW_DETAILS_LABEL).c_str()); - gtk_expander_set_expanded(GTK_EXPANDER(expander), - tab_contents_->profile()->GetPrefs()-> - GetBoolean(prefs::kCookiePromptExpanded)); - g_signal_connect(expander, "notify::expanded", - G_CALLBACK(OnExpanderActivateThunk), this); - cookie_view_ = gtk_chrome_cookie_view_new(TRUE); - gtk_chrome_cookie_view_clear(GTK_CHROME_COOKIE_VIEW(cookie_view_)); - if (type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE) { - gtk_chrome_cookie_view_display_cookie_string( - GTK_CHROME_COOKIE_VIEW(cookie_view_), - origin(), cookie_line()); - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE) { - gtk_chrome_cookie_view_display_local_storage_item( - GTK_CHROME_COOKIE_VIEW(cookie_view_), - origin().host(), - local_storage_key(), - local_storage_value()); - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_DATABASE) { - gtk_chrome_cookie_view_display_database_accessed( - GTK_CHROME_COOKIE_VIEW(cookie_view_), - origin().host(), - database_name(), - display_name(), - estimated_size()); - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_APPCACHE) { - gtk_chrome_cookie_view_display_appcache_created( - GTK_CHROME_COOKIE_VIEW(cookie_view_), - appcache_manifest_url()); - } else { - NOTIMPLEMENTED(); - } - gtk_container_add(GTK_CONTAINER(expander), cookie_view_); - - gtk_box_pack_end(GTK_BOX(content_area), GTK_WIDGET(expander), - FALSE, FALSE, 0); - - gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); - g_signal_connect(dialog, "response", - G_CALLBACK(AppModalDialog::OnDialogResponse), - reinterpret_cast<AppModalDialog*>(this)); - - return dialog; -} - -void CookiePromptModalDialog::HandleDialogResponse(GtkDialog* dialog, - gint response_id) { - bool remember_radio = gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(remember_radio_)); - if (response_id == GTK_RESPONSE_REJECT) { - BlockSiteData(remember_radio); - } else if (response_id == GTK_RESPONSE_ACCEPT) { - bool expires = gtk_chrome_cookie_view_session_expires( - GTK_CHROME_COOKIE_VIEW(cookie_view_)); - AllowSiteData(remember_radio, expires); - } else { - BlockSiteData(false); - } - gtk_widget_destroy(GTK_WIDGET(dialog)); - - CompleteDialog(); - - gtk_util::AppModalDismissedUngroupWindows(); - delete this; -} - -void CookiePromptModalDialog::OnExpanderActivate(GtkWidget* expander, - GParamSpec* property) { - tab_contents_->profile()->GetPrefs()-> - SetBoolean(prefs::kCookiePromptExpanded, - gtk_expander_get_expanded(GTK_EXPANDER(expander))); -} diff --git a/chrome/browser/cookie_modal_dialog_mac.mm b/chrome/browser/cookie_modal_dialog_mac.mm deleted file mode 100644 index 35a54e0..0000000 --- a/chrome/browser/cookie_modal_dialog_mac.mm +++ /dev/null @@ -1,48 +0,0 @@ -// 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. - -#include "chrome/browser/cookie_modal_dialog.h" -#import "chrome/browser/cocoa/cookie_prompt_window_controller.h" - -#import <Cocoa/Cocoa.h> - -#include "app/l10n_util_mac.h" -#import "base/cocoa_protocols_mac.h" -#include "base/mac_util.h" -#include "base/scoped_nsobject.h" -#include "base/logging.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "grit/generated_resources.h" - -void CookiePromptModalDialog::CreateAndShowDialog() { - scoped_nsobject<CookiePromptWindowController> controller( - [[CookiePromptWindowController alloc] initWithDialog:this]); - [controller.get() doModalDialog:this]; - - // Other than JavaScriptAppModalDialog, the cross-platform part of this class - // does not call |CompleteDialog()|, an explicit call is required. - CompleteDialog(); - Cleanup(); - delete this; -} - -// The functions below are used by the automation framework. - -void CookiePromptModalDialog::AcceptWindow() { - NOTIMPLEMENTED(); -} - -void CookiePromptModalDialog::CancelWindow() { - NOTIMPLEMENTED(); -} - -void CookiePromptModalDialog::CloseModalDialog() { - dialog_ = nil; -} - -// This is only used by the app-modal dialog machinery on windows. -NativeDialog CookiePromptModalDialog::CreateNativeDialog() { - NOTIMPLEMENTED(); - return nil; -} diff --git a/chrome/browser/cookie_modal_dialog_uitest.cc b/chrome/browser/cookie_modal_dialog_uitest.cc deleted file mode 100644 index 1c85bed..0000000 --- a/chrome/browser/cookie_modal_dialog_uitest.cc +++ /dev/null @@ -1,65 +0,0 @@ -// 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. - -#include "chrome/browser/net/url_request_mock_http_job.h" -#include "chrome/test/automation/tab_proxy.h" -#include "chrome/test/ui/ui_test.h" - -class CookieModalDialogTest : public UITest { - public: - void RunBasicTest(MessageBoxFlags::DialogButton button_to_press, - const std::wstring& expected_title) { - scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); - ASSERT_TRUE(browser); - - ASSERT_TRUE(browser->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, - CONTENT_SETTING_ASK)); - - GURL url(URLRequestMockHTTPJob::GetMockUrl( - FilePath(FILE_PATH_LITERAL("cookie2.html")))); - - scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); - ASSERT_TRUE(tab_proxy); - - int64 last_navigation_time; - ASSERT_TRUE(tab_proxy->GetLastNavigationTime(&last_navigation_time)); - ASSERT_TRUE(tab_proxy->NavigateToURLAsync(url)); - - // cookie2.html sets a cookie and then reads back the cookie within onload, - // which means that the navigation will not complete until the cookie - // prompt is dismissed. - - bool modal_dialog_showing = false; - MessageBoxFlags::DialogButton available_buttons; - ASSERT_TRUE(automation()->WaitForAppModalDialog()); - ASSERT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, - &available_buttons)); - ASSERT_TRUE(modal_dialog_showing); - ASSERT_NE((button_to_press & available_buttons), 0); - ASSERT_TRUE(automation()->ClickAppModalDialogButton(button_to_press)); - - // Now, the cookie prompt is dismissed, and we can wait for the navigation - // to complete. Before returning from onload, the test updates the title. - // We can therefore be sure that upon return from WaitForNavigation that - // the title has been updated with the final test result. - - ASSERT_TRUE(tab_proxy->WaitForNavigation(last_navigation_time)); - - std::wstring title; - ASSERT_TRUE(tab_proxy->GetTabTitle(&title)); - - EXPECT_EQ(expected_title, title); - } -}; - -// TODO(port): Enable these once the cookie dialogs are fully implemented. -#if defined(OS_WIN) -TEST_F(CookieModalDialogTest, AllowCookies) { - RunBasicTest(MessageBoxFlags::DIALOGBUTTON_OK, L"cookie allowed"); -} - -TEST_F(CookieModalDialogTest, BlockCookies) { - RunBasicTest(MessageBoxFlags::DIALOGBUTTON_CANCEL, L"cookie blocked"); -} -#endif diff --git a/chrome/browser/cookie_modal_dialog_views.cc b/chrome/browser/cookie_modal_dialog_views.cc deleted file mode 100644 index 94c3f6f..0000000 --- a/chrome/browser/cookie_modal_dialog_views.cc +++ /dev/null @@ -1,41 +0,0 @@ -// 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. - -#include "chrome/browser/cookie_modal_dialog.h" - -#include "base/logging.h" -#include "chrome/browser/views/cookie_prompt_view.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "views/window/window.h" - - -// TODO(zelidrag): Make this work on Linux (views). - -void CookiePromptModalDialog::AcceptWindow() { -#if defined(OS_WIN) - views::DialogClientView* client_view = - dialog_->window()->GetClientView()->AsDialogClientView(); - client_view->AcceptWindow(); -#endif -} - -void CookiePromptModalDialog::CancelWindow() { -#if defined(OS_WIN) - views::DialogClientView* client_view = - dialog_->window()->GetClientView()->AsDialogClientView(); - client_view->CancelWindow(); -#endif -} - - -NativeDialog CookiePromptModalDialog::CreateNativeDialog() { -#if defined(OS_WIN) - return new CookiePromptView(this, - tab_contents_->GetMessageBoxRootWindow(), - tab_contents_->profile()); -#else - NOTIMPLEMENTED(); - return NULL; -#endif -} diff --git a/chrome/browser/cookie_prompt_modal_dialog_delegate.h b/chrome/browser/cookie_prompt_modal_dialog_delegate.h deleted file mode 100644 index 1a89eaa..0000000 --- a/chrome/browser/cookie_prompt_modal_dialog_delegate.h +++ /dev/null @@ -1,26 +0,0 @@ -// 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_BROWSER_COOKIE_PROMPT_MODAL_DIALOG_DELEGATE_H_ -#define CHROME_BROWSER_COOKIE_PROMPT_MODAL_DIALOG_DELEGATE_H_ -#pragma once - -// Delegate for handling modal dialog results from CookiePromptModalDialog. -// The implementer of this MUST guarentee that from the time it's passed to the -// CookieModalDialog until one of these methods are called it will not be -// deleted. -class CookiePromptModalDialogDelegate { - public: - // Allow site data to be set. - virtual void AllowSiteData(bool session_expire) = 0; - - // Block site data from being stored. - virtual void BlockSiteData() = 0; - - protected: - virtual ~CookiePromptModalDialogDelegate() {} -}; - -#endif // CHROME_BROWSER_COOKIE_PROMPT_MODAL_DIALOG_DELEGATE_H_ - diff --git a/chrome/browser/dom_ui/content_settings_handler.cc b/chrome/browser/dom_ui/content_settings_handler.cc index d15671d..b40317f 100644 --- a/chrome/browser/dom_ui/content_settings_handler.cc +++ b/chrome/browser/dom_ui/content_settings_handler.cc @@ -210,12 +210,6 @@ void ContentSettingsHandler::Initialize() { dom_ui_->CallJavascriptFunction( L"ContentSettings.setBlockThirdPartyCookies", *block_3rd_party.get()); - scoped_ptr<Value> show_cookies_prompt(Value::CreateBooleanValue( - CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCookiePrompt))); - dom_ui_->CallJavascriptFunction( - L"ContentSettings.setCookiesPromptEnabled", *show_cookies_prompt.get()); - UpdateAllExceptionsViewsFromModel(); notification_registrar_.Add( this, NotificationType::CONTENT_SETTINGS_CHANGED, diff --git a/chrome/browser/gtk/options/cookie_filter_page_gtk.cc b/chrome/browser/gtk/options/cookie_filter_page_gtk.cc index 1826694..4bf3701 100644 --- a/chrome/browser/gtk/options/cookie_filter_page_gtk.cc +++ b/chrome/browser/gtk/options/cookie_filter_page_gtk.cc @@ -66,9 +66,6 @@ void CookieFilterPageGtk::HighlightGroup(OptionsGroup highlight_group) { } GtkWidget* CookieFilterPageGtk::InitCookieStoringGroup() { - bool disable_cookie_prompt = !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCookiePrompt); - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); allow_radio_ = gtk_radio_button_new_with_label(NULL, @@ -77,15 +74,6 @@ GtkWidget* CookieFilterPageGtk::InitCookieStoringGroup() { G_CALLBACK(OnCookiesAllowToggledThunk), this); gtk_box_pack_start(GTK_BOX(vbox), allow_radio_, FALSE, FALSE, 0); - if (!disable_cookie_prompt) { - ask_every_time_radio_ = gtk_radio_button_new_with_label_from_widget( - GTK_RADIO_BUTTON(allow_radio_), - l10n_util::GetStringUTF8(IDS_COOKIES_ASK_EVERY_TIME_RADIO).c_str()); - g_signal_connect(G_OBJECT(ask_every_time_radio_), "toggled", - G_CALLBACK(OnCookiesAllowToggledThunk), this); - gtk_box_pack_start(GTK_BOX(vbox), ask_every_time_radio_, FALSE, FALSE, 0); - } - block_radio_ = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(allow_radio_), l10n_util::GetStringUTF8(IDS_COOKIES_BLOCK_RADIO).c_str()); diff --git a/chrome/browser/host_content_settings_map.cc b/chrome/browser/host_content_settings_map.cc index c018219..e5c8bc4 100644 --- a/chrome/browser/host_content_settings_map.cc +++ b/chrome/browser/host_content_settings_map.cc @@ -804,13 +804,10 @@ void HostContentSettingsMap::GetSettingsFromDictionary( } } } - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCookiePrompt)) { - // Migrate obsolete cookie prompt mode. - if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] == - CONTENT_SETTING_ASK) - settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; - } + // Migrate obsolete cookie prompt mode. + if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] == + CONTENT_SETTING_ASK) + settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; } void HostContentSettingsMap::GetResourceSettingsFromDictionary( diff --git a/chrome/browser/in_process_webkit/dom_storage_area.cc b/chrome/browser/in_process_webkit/dom_storage_area.cc index 4fa247f..d16e99a 100644 --- a/chrome/browser/in_process_webkit/dom_storage_area.cc +++ b/chrome/browser/in_process_webkit/dom_storage_area.cc @@ -9,7 +9,6 @@ #include "chrome/browser/in_process_webkit/dom_storage_context.h" #include "chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h" #include "chrome/browser/in_process_webkit/dom_storage_namespace.h" -#include "chrome/browser/in_process_webkit/dom_storage_permission_request.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/common/render_messages.h" #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" @@ -98,18 +97,5 @@ bool DOMStorageArea::CheckContentSetting( ContentSetting content_setting = host_content_settings_map_->GetContentSetting( origin_url_, CONTENT_SETTINGS_TYPE_COOKIES, ""); - - if (content_setting == CONTENT_SETTING_ASK) { - DOMStoragePermissionRequest request(origin_url_, key, value, - host_content_settings_map_); - ChromeThread::PostTask( - ChromeThread::UI, FROM_HERE, - NewRunnableFunction(&DOMStoragePermissionRequest::PromptUser, - &request)); - // Tell the renderer that it needs to run a nested message loop. - sender->Send(new ViewMsg_SignalCookiePromptEvent()); - content_setting = request.WaitOnResponse(); - } - return (content_setting != CONTENT_SETTING_BLOCK); } diff --git a/chrome/browser/in_process_webkit/dom_storage_permission_request.cc b/chrome/browser/in_process_webkit/dom_storage_permission_request.cc deleted file mode 100644 index cd6603b..0000000 --- a/chrome/browser/in_process_webkit/dom_storage_permission_request.cc +++ /dev/null @@ -1,66 +0,0 @@ -// 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. - -#include "chrome/browser/in_process_webkit/dom_storage_permission_request.h" - -#include "chrome/browser/browser_list.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/browser/message_box_handler.h" - -DOMStoragePermissionRequest::DOMStoragePermissionRequest( - const GURL& url, - const string16& key, - const string16& value, - HostContentSettingsMap* settings) - : url_(url), - key_(key), - value_(value), - response_content_setting_(CONTENT_SETTING_DEFAULT), - event_(true, false), // manual reset, not initially signaled - host_content_settings_map_(settings) { -} - -ContentSetting DOMStoragePermissionRequest::WaitOnResponse() { - event_.Wait(); - return response_content_setting_; -} - -// static -void DOMStoragePermissionRequest::PromptUser( - DOMStoragePermissionRequest* request) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - // Cookie settings may have changed. - ContentSetting setting = - request->host_content_settings_map_->GetContentSetting( - request->url_, CONTENT_SETTINGS_TYPE_COOKIES, ""); - if (setting != CONTENT_SETTING_ASK) { - request->SendResponse(setting); - return; - } - - Browser* browser = BrowserList::GetLastActive(); - if (!browser || !browser->GetSelectedTabContents()) { - request->SendResponse(CONTENT_SETTING_BLOCK); - return; - } - - RunLocalStoragePrompt(browser->GetSelectedTabContents(), - request->host_content_settings_map_, request->url_, - request->key_, request->value_, request); -} - -void DOMStoragePermissionRequest::AllowSiteData(bool session_expire) { - SendResponse(CONTENT_SETTING_ALLOW); -} - -void DOMStoragePermissionRequest::BlockSiteData() { - SendResponse(CONTENT_SETTING_BLOCK); -} - -void DOMStoragePermissionRequest::SendResponse( - ContentSetting content_setting) { - response_content_setting_ = content_setting; - event_.Signal(); -} diff --git a/chrome/browser/in_process_webkit/dom_storage_permission_request.h b/chrome/browser/in_process_webkit/dom_storage_permission_request.h deleted file mode 100644 index da2ffc1..0000000 --- a/chrome/browser/in_process_webkit/dom_storage_permission_request.h +++ /dev/null @@ -1,64 +0,0 @@ -// 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_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_PERMISSION_REQUEST_H_ -#define CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_PERMISSION_REQUEST_H_ -#pragma once - -#include "base/ref_counted.h" -#include "base/string16.h" -#include "base/time.h" -#include "base/waitable_event.h" -#include "chrome/browser/host_content_settings_map.h" -#include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" -#include "chrome/common/content_settings.h" -#include "googleurl/src/gurl.h" - -// This class is used to request content setting related permission for local -// storage. It should only be used for one such event and then discarded. -class DOMStoragePermissionRequest : public CookiePromptModalDialogDelegate { - public: - DOMStoragePermissionRequest(const GURL& url, - const string16& key, - const string16& value, - HostContentSettingsMap* settings); - - - ContentSetting WaitOnResponse(); - - const GURL& url() const { return url_; } - const string16& key() const { return key_; } - const string16& value() const { return value_; } - - // Called on the UI thread. - static void PromptUser(DOMStoragePermissionRequest* request); - - // CookiesPromptViewDelegate methods: - virtual void AllowSiteData(bool session_expire); - virtual void BlockSiteData(); - - private: - void SendResponse(ContentSetting content_setting); - - // The URL we need to get permission for. - const GURL url_; - - // The key we're trying to set. - const string16 key_; - - // The value we're trying to set. - const string16 value_; - - // The response to the permission request. - ContentSetting response_content_setting_; - - // One time use. Never reset. - base::WaitableEvent event_; - - scoped_refptr<HostContentSettingsMap> host_content_settings_map_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStoragePermissionRequest); -}; - -#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_PERMISSION_REQUEST_H_ diff --git a/chrome/browser/message_box_handler.cc b/chrome/browser/message_box_handler.cc index be21323..a6006dc 100644 --- a/chrome/browser/message_box_handler.cc +++ b/chrome/browser/message_box_handler.cc @@ -12,9 +12,6 @@ #include "build/build_config.h" #include "chrome/browser/app_modal_dialog_queue.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/browsing_data_local_storage_helper.h" -#include "chrome/browser/cookie_modal_dialog.h" -#include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/js_modal_dialog.h" #include "chrome/browser/profile.h" @@ -93,49 +90,3 @@ void RunBeforeUnloadDialog(TabContents* tab_contents, MessageBoxFlags::kIsJavascriptConfirm, message_text, std::wstring(), false, true, reply_msg)); } - -void RunCookiePrompt(TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& origin, - const std::string& cookie_line, - CookiePromptModalDialogDelegate* delegate) { - Singleton<AppModalDialogQueue>()->AddDialog( - new CookiePromptModalDialog(tab_contents, host_content_settings_map, - origin, cookie_line, delegate)); -} - -void RunLocalStoragePrompt( - TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& origin, - const string16& key, - const string16& value, - CookiePromptModalDialogDelegate* delegate) { - Singleton<AppModalDialogQueue>()->AddDialog( - new CookiePromptModalDialog(tab_contents, host_content_settings_map, - origin, key, value, delegate)); -} - -void RunDatabasePrompt( - TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& origin, - const string16& database_name, - const string16& display_name, - unsigned long estimated_size, - CookiePromptModalDialogDelegate* delegate) { - Singleton<AppModalDialogQueue>()->AddDialog( - new CookiePromptModalDialog(tab_contents, host_content_settings_map, - origin, database_name, display_name, - estimated_size, delegate)); -} - -void RunAppCachePrompt( - TabContents* tab_contents, - HostContentSettingsMap* host_content_settings_map, - const GURL& manifest_url, - CookiePromptModalDialogDelegate* delegate) { - Singleton<AppModalDialogQueue>()->AddDialog( - new CookiePromptModalDialog(tab_contents, host_content_settings_map, - manifest_url, delegate)); -} diff --git a/chrome/browser/net/chrome_cookie_policy.cc b/chrome/browser/net/chrome_cookie_policy.cc index 52325fd..da700e3 100644 --- a/chrome/browser/net/chrome_cookie_policy.cc +++ b/chrome/browser/net/chrome_cookie_policy.cc @@ -7,9 +7,7 @@ #include "base/string_util.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/chrome_thread.h" -#include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" #include "chrome/browser/host_content_settings_map.h" -#include "chrome/browser/message_box_handler.h" #include "net/base/net_errors.h" #include "net/base/static_cookie_policy.h" @@ -20,45 +18,6 @@ static const size_t kMaxCompletionsPerHost = 10000; // ---------------------------------------------------------------------------- -// ChromeCookiePolicy cannot just subclass the delegate interface because we -// may have several prompts pending. -class ChromeCookiePolicy::PromptDelegate - : public CookiePromptModalDialogDelegate { - public: - PromptDelegate(ChromeCookiePolicy* cookie_policy, const std::string& host) - : cookie_policy_(cookie_policy), - host_(host) { - } - - // CookiesPromptViewDelegate methods: - virtual void AllowSiteData(bool session_expire); - virtual void BlockSiteData(); - - private: - void NotifyDone(int policy); - - scoped_refptr<ChromeCookiePolicy> cookie_policy_; - std::string host_; -}; - -void ChromeCookiePolicy::PromptDelegate::AllowSiteData(bool session_expire) { - int policy = net::OK; - if (session_expire) - policy = net::OK_FOR_SESSION_ONLY; - NotifyDone(policy); -} - -void ChromeCookiePolicy::PromptDelegate::BlockSiteData() { - NotifyDone(net::ERR_ACCESS_DENIED); -} - -void ChromeCookiePolicy::PromptDelegate::NotifyDone(int policy) { - cookie_policy_->DidPromptForSetCookie(host_, policy); - delete this; -} - -// ---------------------------------------------------------------------------- - ChromeCookiePolicy::ChromeCookiePolicy(HostContentSettingsMap* map) : host_content_settings_map_(map) { } @@ -121,10 +80,7 @@ int ChromeCookiePolicy::CanSetCookie(const GURL& url, DCHECK(callback); - // Else, ask the user... - Completions& completions = host_completions_map_[url.host()]; - if (completions.size() >= kMaxCompletionsPerHost) { LOG(ERROR) << "Would exceed kMaxCompletionsPerHost"; policy = net::ERR_ACCESS_DENIED; @@ -133,7 +89,6 @@ int ChromeCookiePolicy::CanSetCookie(const GURL& url, policy = net::ERR_IO_PENDING; } - PromptForSetCookie(url, cookie_line); return policy; } @@ -149,75 +104,3 @@ int ChromeCookiePolicy::CheckPolicy(const GURL& url) const { return net::ERR_IO_PENDING; // Need to prompt. } -void ChromeCookiePolicy::PromptForSetCookie(const GURL& url, - const std::string& cookie_line) { - if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { - ChromeThread::PostTask( - ChromeThread::UI, FROM_HERE, - NewRunnableMethod(this, &ChromeCookiePolicy::PromptForSetCookie, url, - cookie_line)); - return; - } - - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - const std::string& host = url.host(); - - // The policy may have changed (due to the "remember" option) - int policy = CheckPolicy(url); - if (policy != net::ERR_IO_PENDING) { - DidPromptForSetCookie(host, policy); - return; - } - - // Show the prompt on top of the current tab. - Browser* browser = BrowserList::GetLastActive(); - if (!browser || !browser->GetSelectedTabContents()) { - DidPromptForSetCookie(host, net::ERR_ACCESS_DENIED); - return; - } - - RunCookiePrompt(browser->GetSelectedTabContents(), - host_content_settings_map_, url, cookie_line, - new PromptDelegate(this, host)); -} - -void ChromeCookiePolicy::DidPromptForSetCookie(const std::string& host, - int policy) { - if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { - ChromeThread::PostTask( - ChromeThread::IO, FROM_HERE, - NewRunnableMethod(this, &ChromeCookiePolicy::DidPromptForSetCookie, - host, policy)); - return; - } - - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - - // Notify all callbacks, starting with the first until we hit another that - // is for a 'set-cookie'. - HostCompletionsMap::iterator it = host_completions_map_.find(host); - CHECK(it != host_completions_map_.end()); - - Completions& completions = it->second; - CHECK(!completions.empty() && completions[0].is_set_cookie_request()); - - // Gather the list of callbacks to notify, and remove them from the - // completions list before handing control to the callbacks (in case - // they should call back into us to modify host_completions_map_). - - std::vector<net::CompletionCallback*> callbacks; - callbacks.push_back(completions[0].callback()); - size_t i = 1; - for (; i < completions.size(); ++i) { - if (completions[i].is_set_cookie_request()) - break; - callbacks.push_back(completions[i].callback()); - } - completions.erase(completions.begin(), completions.begin() + i); - - if (completions.empty()) - host_completions_map_.erase(it); - - for (size_t j = 0; j < callbacks.size(); ++j) - callbacks[j]->Run(policy); -} diff --git a/chrome/browser/net/chrome_cookie_policy.h b/chrome/browser/net/chrome_cookie_policy.h index 8265437..ea63e6b 100644 --- a/chrome/browser/net/chrome_cookie_policy.h +++ b/chrome/browser/net/chrome_cookie_policy.h @@ -38,9 +38,6 @@ class ChromeCookiePolicy net::CompletionCallback* callback); private: - class PromptDelegate; - friend class PromptDelegate; - class Completion { public: static Completion ForSetCookie(net::CompletionCallback* callback) { @@ -67,8 +64,6 @@ class ChromeCookiePolicy typedef std::map<std::string, Completions> HostCompletionsMap; int CheckPolicy(const GURL& url) const; - void PromptForSetCookie(const GURL& url, const std::string& cookie_line); - void DidPromptForSetCookie(const std::string& host, int result); // A map from hostname to callbacks awaiting a cookie policy response. // This map is only accessed on the IO thread. diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 075cbf1..efa928e 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -10,7 +10,6 @@ #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_shutdown.h" -#include "chrome/browser/cookie_modal_dialog.h" #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/dom_ui/labs_ui.h" #include "chrome/browser/dom_ui/new_tab_ui.h" @@ -139,7 +138,6 @@ void RegisterUserPrefs(PrefService* user_prefs) { chromeos::Preferences::RegisterUserPrefs(user_prefs); #endif BackgroundContentsService::RegisterUserPrefs(user_prefs); - CookiePromptModalDialog::RegisterUserPrefs(user_prefs); SigninManager::RegisterUserPrefs(user_prefs); } diff --git a/chrome/browser/renderer_host/database_dispatcher_host.cc b/chrome/browser/renderer_host/database_dispatcher_host.cc index b592b1b..3efb836 100644 --- a/chrome/browser/renderer_host/database_dispatcher_host.cc +++ b/chrome/browser/renderer_host/database_dispatcher_host.cc @@ -15,7 +15,6 @@ #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/renderer_host/browser_render_process_host.h" -#include "chrome/browser/renderer_host/database_permission_request.h" #include "chrome/common/render_messages.h" #include "googleurl/src/gurl.h" #include "third_party/sqlite/sqlite3.h" @@ -390,26 +389,6 @@ void DatabaseDispatcherHost::OnAllowDatabase(const std::string& origin_url, ContentSetting content_setting = host_content_settings_map_->GetContentSetting( url, CONTENT_SETTINGS_TYPE_COOKIES, ""); - if (content_setting == CONTENT_SETTING_ASK) { - // Create a task for each possible outcome. - scoped_ptr<Task> on_allow(NewRunnableMethod( - this, &DatabaseDispatcherHost::AllowDatabaseResponse, - reply_msg, CONTENT_SETTING_ALLOW)); - scoped_ptr<Task> on_block(NewRunnableMethod( - this, &DatabaseDispatcherHost::AllowDatabaseResponse, - reply_msg, CONTENT_SETTING_BLOCK)); - // And then let the permission request object do the rest. - scoped_refptr<DatabasePermissionRequest> request( - new DatabasePermissionRequest(url, name, display_name, estimated_size, - on_allow.release(), on_block.release(), - host_content_settings_map_)); - request->RequestPermission(); - - // Tell the renderer that it needs to run a nested message loop. - Send(new ViewMsg_SignalCookiePromptEvent()); - return; - } - AllowDatabaseResponse(reply_msg, content_setting); } diff --git a/chrome/browser/renderer_host/database_permission_request.cc b/chrome/browser/renderer_host/database_permission_request.cc deleted file mode 100644 index 317c7f9..0000000 --- a/chrome/browser/renderer_host/database_permission_request.cc +++ /dev/null @@ -1,90 +0,0 @@ -// 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. - -#include "chrome/browser/renderer_host/database_permission_request.h" - - -#include "chrome/browser/browser_list.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/browser/host_content_settings_map.h" -#include "chrome/browser/message_box_handler.h" - -DatabasePermissionRequest::DatabasePermissionRequest( - const GURL& url, - const string16& database_name, - const string16& display_name, - unsigned long estimated_size, - Task* on_allow, - Task* on_block, - HostContentSettingsMap* settings_map) - : url_(url), - database_name_(database_name), - display_name_(display_name), - estimated_size_(estimated_size), - on_allow_(on_allow), - on_block_(on_block), - host_content_settings_map_(settings_map) { - DCHECK(on_allow_.get()); - DCHECK(on_block_.get()); -} - -DatabasePermissionRequest::~DatabasePermissionRequest() { -} - -void DatabasePermissionRequest::RequestPermission() { - if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { - ChromeThread::PostTask( - ChromeThread::UI, FROM_HERE, NewRunnableMethod( - this, &DatabasePermissionRequest::RequestPermission)); - return; - } - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - // Cookie settings may have changed. - ContentSetting setting = host_content_settings_map_->GetContentSetting( - url_, CONTENT_SETTINGS_TYPE_COOKIES, ""); - if (setting != CONTENT_SETTING_ASK) { - SendResponse(setting); - return; - } - - Browser* browser = BrowserList::GetLastActive(); - if (!browser || !browser->GetSelectedTabContents()) { - BlockSiteData(); - return; - } - - self_ref_ = this; - // Will call either AllowSiteData or BlockSiteData which will NULL out our - // self reference. - RunDatabasePrompt(browser->GetSelectedTabContents(), - host_content_settings_map_, url_, database_name_, - display_name_, estimated_size_, this); -} - -void DatabasePermissionRequest::AllowSiteData(bool session_expire) { - SendResponse(CONTENT_SETTING_ALLOW); -} - -void DatabasePermissionRequest::BlockSiteData() { - SendResponse(CONTENT_SETTING_BLOCK); -} - -void DatabasePermissionRequest::SendResponse(ContentSetting content_setting) { - if (content_setting == CONTENT_SETTING_ALLOW) { - ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, on_allow_.release()); - } else { - DCHECK(content_setting == CONTENT_SETTING_BLOCK); - ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, on_block_.release()); - } - - // Release all resources. - on_allow_.reset(); - on_block_.reset(); - - // This seems safer than possibly being deleted while in method(s) related to - // this object. Any thread will do, but UI is always around and can be - // posted without locking, so we'll ask it to do the release. - ChromeThread::ReleaseSoon(ChromeThread::UI, FROM_HERE, self_ref_.release()); -} diff --git a/chrome/browser/renderer_host/database_permission_request.h b/chrome/browser/renderer_host/database_permission_request.h deleted file mode 100644 index abe5d20..0000000 --- a/chrome/browser/renderer_host/database_permission_request.h +++ /dev/null @@ -1,66 +0,0 @@ -// 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_BROWSER_RENDERER_HOST_DATABASE_PERMISSION_REQUEST_H_ -#define CHROME_BROWSER_RENDERER_HOST_DATABASE_PERMISSION_REQUEST_H_ -#pragma once - -#include "base/ref_counted.h" -#include "base/scoped_ptr.h" -#include "base/string16.h" -#include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" -#include "chrome/common/content_settings.h" -#include "googleurl/src/gurl.h" - -class HostContentSettingsMap; -class Task; - -// This class is fully threadsafe. -class DatabasePermissionRequest - : public base::RefCountedThreadSafe<DatabasePermissionRequest>, - public CookiePromptModalDialogDelegate { - public: - DatabasePermissionRequest(const GURL& url, - const string16& database_name, - const string16& display_name, - unsigned long estimated_size, - Task* on_allow, - Task* on_block, - HostContentSettingsMap* settings_map); - ~DatabasePermissionRequest(); - - const GURL& url() const { return url_; } - const string16& database_name() const { return database_name_; } - const string16& display_name() const { return display_name_; } - unsigned long estimated_size() const { return estimated_size_; } - - // Start the permission request process. - void RequestPermission(); - - // CookiesPromptViewDelegate methods: - virtual void AllowSiteData(bool session_expire); - virtual void BlockSiteData(); - - private: - void SendResponse(ContentSetting content_setting); - - // The URL to get permission for. - const GURL url_; - const string16 database_name_; - const string16 display_name_; - unsigned long estimated_size_; - - // Set on IO, possibly release()ed on UI, destroyed on IO or UI. - scoped_ptr<Task> on_allow_; - scoped_ptr<Task> on_block_; - - scoped_refptr<HostContentSettingsMap> host_content_settings_map_; - - // Released once we have our answer. - scoped_refptr<DatabasePermissionRequest> self_ref_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(DatabasePermissionRequest); -}; - -#endif // CHROME_BROWSER_RENDERER_HOST_DATABASE_PERMISSION_REQUEST_H_ diff --git a/chrome/browser/resources/options/content_settings.html b/chrome/browser/resources/options/content_settings.html index 77184b8..3d57e9f 100644 --- a/chrome/browser/resources/options/content_settings.html +++ b/chrome/browser/resources/options/content_settings.html @@ -35,12 +35,6 @@ </label></td> </tr> <tr> - <td class="option-name" id='cookiesAskRadio'><label> - <input type="radio" name="cookies" value="ask"> - <span i18n-content="cookies_ask"></span> - </label></td> - </tr> - <tr> <td class="option-name"><label> <input type="radio" name="cookies" value="block"> <span i18n-content="cookies_block"></span> diff --git a/chrome/browser/resources/options/content_settings.js b/chrome/browser/resources/options/content_settings.js index ceaddbf..33d6a6b 100644 --- a/chrome/browser/resources/options/content_settings.js +++ b/chrome/browser/resources/options/content_settings.js @@ -84,18 +84,6 @@ cr.define('options', function() { }; /** - * Called to set whether we show certain UI related to the cookies prompt. - * @param {boolean} enabled The value --enable-cookies-prompt. - * that group. - */ - ContentSettings.setCookiesPromptEnabled = function(enabled) { - cookiesExceptionsList.enableAskOption = enabled; - - if (!enabled) - $('cookiesAskRadio').classList.add('hidden'); - } - - /** * Initializes an exceptions list. * @param {string} type The content type that we are setting exceptions for. * @param {Array} list An array of pairs, where the first element of each pair diff --git a/chrome/browser/views/cookie_prompt_view.cc b/chrome/browser/views/cookie_prompt_view.cc deleted file mode 100644 index 92b80ca..0000000 --- a/chrome/browser/views/cookie_prompt_view.cc +++ /dev/null @@ -1,297 +0,0 @@ -// 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. - -#include "chrome/browser/views/cookie_prompt_view.h" - -#include <algorithm> - -#include "app/l10n_util.h" -#include "base/message_loop.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/cookie_modal_dialog.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/views/browser_dialogs.h" -#include "chrome/browser/views/cookie_info_view.h" -#include "chrome/browser/views/database_open_info_view.h" -#include "chrome/browser/views/generic_info_view.h" -#include "chrome/browser/views/local_storage_set_item_info_view.h" -#include "chrome/browser/views/options/content_settings_window_view.h" -#include "chrome/common/pref_names.h" -#include "gfx/canvas.h" -#include "gfx/color_utils.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "net/base/cookie_monster.h" -#include "views/controls/label.h" -#include "views/controls/button/native_button.h" -#include "views/controls/button/radio_button.h" -#include "views/controls/textfield/textfield.h" -#include "views/grid_layout.h" -#include "views/standard_layout.h" -#include "views/window/non_client_view.h" - -static const int kCookiePromptViewInsetSize = 5; - -/////////////////////////////////////////////////////////////////////////////// -// CookiePromptView, public: - -CookiePromptView::CookiePromptView( - CookiePromptModalDialog* parent, - gfx::NativeWindow root_window, - Profile* profile) - : remember_radio_(NULL), - ask_radio_(NULL), - allow_button_(NULL), - block_button_(NULL), - show_cookie_link_(NULL), - info_view_(NULL), - session_expire_(false), - expanded_view_(false), - signaled_(false), - parent_(parent), - root_window_(root_window), - profile_(profile) { - InitializeViewResources(); - expanded_view_ = profile_->GetPrefs()-> - GetBoolean(prefs::kCookiePromptExpanded); -} - -CookiePromptView::~CookiePromptView() { -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiePromptView, views::View overrides: - -gfx::Size CookiePromptView::GetPreferredSize() { - gfx::Size client_size = views::View::GetPreferredSize(); - return gfx::Size(client_size.width(), - client_size.height() + GetExtendedViewHeight()); -} - - -void CookiePromptView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (is_add && child == this) - Init(); -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiePromptView, ModalDialogDelegate implementation: - -gfx::NativeWindow CookiePromptView::GetDialogRootWindow() { - return root_window_; -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiePromptView, views::DialogDelegate implementation: - -std::wstring CookiePromptView::GetWindowTitle() const { - return title_; -} - -void CookiePromptView::WindowClosing() { - if (!signaled_) - parent_->BlockSiteData(false); - parent_->CompleteDialog(); -} - -views::View* CookiePromptView::GetContentsView() { - return this; -} - -bool CookiePromptView::Accept() { - parent_->AllowSiteData(remember_radio_->checked(), session_expire_); - signaled_ = true; - return true; -} - -// CookieInfoViewDelegate overrides: -void CookiePromptView::ModifyExpireDate(bool session_expire) { - session_expire_ = session_expire; -} - - -/////////////////////////////////////////////////////////////////////////////// -// CookiePromptView, views::ButtonListener implementation: - -void CookiePromptView::ButtonPressed(views::Button* sender, - const views::Event& event) { - if (sender == allow_button_) { - Accept(); - GetWindow()->Close(); - } else if (sender == block_button_) { - parent_->BlockSiteData(remember_radio_->checked()); - signaled_ = true; - GetWindow()->Close(); - } -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiePromptView, views::LinkController implementation: -void CookiePromptView::LinkActivated(views::Link* source, int event_flags) { - DCHECK_EQ(source, show_cookie_link_); - ToggleDetailsViewExpand(); -} - -/////////////////////////////////////////////////////////////////////////////// -// CookiePromptView, private: - -void CookiePromptView::Init() { - CookiePromptModalDialog::DialogType type = parent_->dialog_type(); - std::wstring display_host = UTF8ToWide(parent_->origin().host()); - views::Label* description_label = new views::Label(l10n_util::GetStringF( - type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE ? - IDS_COOKIE_ALERT_LABEL : IDS_DATA_ALERT_LABEL, - display_host)); - int radio_group_id = 0; - remember_radio_ = new views::RadioButton( - l10n_util::GetStringF(IDS_COOKIE_ALERT_REMEMBER_RADIO, display_host), - radio_group_id); - remember_radio_->set_listener(this); - ask_radio_ = new views::RadioButton( - l10n_util::GetString(IDS_COOKIE_ALERT_ASK_RADIO), radio_group_id); - ask_radio_->set_listener(this); - allow_button_ = new views::NativeButton( - this, l10n_util::GetString(IDS_COOKIE_ALERT_ALLOW_BUTTON)); - block_button_ = new views::NativeButton( - this, l10n_util::GetString(IDS_COOKIE_ALERT_BLOCK_BUTTON)); - show_cookie_link_ = new views::Link( - l10n_util::GetString(IDS_COOKIE_SHOW_DETAILS_LABEL)); - show_cookie_link_->SetController(this); - - using views::GridLayout; - - GridLayout* layout = CreatePanelGridLayout(this); - layout->SetInsets(kCookiePromptViewInsetSize, kCookiePromptViewInsetSize, - kCookiePromptViewInsetSize, kCookiePromptViewInsetSize); - SetLayoutManager(layout); - - const int one_column_layout_id = 0; - views::ColumnSet* one_column_set = layout->AddColumnSet(one_column_layout_id); - one_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - one_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - one_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - layout->StartRow(0, one_column_layout_id); - layout->AddView(description_label); - layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); - layout->StartRow(0, one_column_layout_id); - layout->AddView(remember_radio_); - layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - layout->StartRow(0, one_column_layout_id); - layout->AddView(ask_radio_); - layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - - View* button_container = new View(); - GridLayout* button_layout = new GridLayout(button_container); - button_container->SetLayoutManager(button_layout); - const int inner_column_layout_id = 1; - views::ColumnSet* inner_column_set = button_layout->AddColumnSet( - inner_column_layout_id); - inner_column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - inner_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - inner_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - inner_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - inner_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - button_layout->StartRow(0, inner_column_layout_id); - button_layout->AddView(show_cookie_link_, 1, 1, - GridLayout::LEADING, GridLayout::TRAILING); - button_layout->AddView(allow_button_); - button_layout->AddView(block_button_); - - int button_column_layout_id = 2; - views::ColumnSet* button_column_set = - layout->AddColumnSet(button_column_layout_id); - button_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - button_column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, - GridLayout::USE_PREF, 0, 0); - button_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - layout->StartRow(0, one_column_layout_id); - layout->AddView(button_container, 1, 1, - GridLayout::FILL, GridLayout::CENTER); - layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - - layout->StartRow(0, one_column_layout_id); - - if (type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE) { - CookieInfoView* cookie_info_view = new CookieInfoView(true); - cookie_info_view->set_delegate(this); - layout->AddView(cookie_info_view, 1, 1, GridLayout::FILL, - GridLayout::CENTER); - - cookie_info_view->SetCookieString(parent_->origin(), - parent_->cookie_line()); - info_view_ = cookie_info_view; - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE) { - LocalStorageSetItemInfoView* view = new LocalStorageSetItemInfoView(); - layout->AddView(view, 1, 1, GridLayout::FILL, GridLayout::CENTER); - view->SetFields(parent_->origin().host(), - parent_->local_storage_key(), - parent_->local_storage_value()); - info_view_ = view; - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_DATABASE) { - DatabaseOpenInfoView* view = new DatabaseOpenInfoView(); - layout->AddView(view, 1, 1, GridLayout::FILL, GridLayout::CENTER); - view->SetFields(parent_->origin().host(), - parent_->database_name(), - parent_->display_name(), - parent_->estimated_size()); - info_view_ = view; - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_APPCACHE) { - static const int kAppCacheInfoLabels[] = { - IDS_COOKIES_APPLICATION_CACHE_MANIFEST_LABEL - }; - GenericInfoView* view = new GenericInfoView(ARRAYSIZE(kAppCacheInfoLabels), - kAppCacheInfoLabels); - layout->AddView(view, 1, 1, GridLayout::FILL, GridLayout::CENTER); - view->SetValue(0, UTF8ToUTF16(parent_->appcache_manifest_url().spec())); - info_view_ = view; - } else { - NOTIMPLEMENTED(); - } - - info_view_->SetVisible(expanded_view_); - - // Set default values. - remember_radio_->SetChecked(true); -} - -int CookiePromptView::GetExtendedViewHeight() { - DCHECK(info_view_); - return expanded_view_ ? - 0 : -info_view_->GetPreferredSize().height(); -} - -void CookiePromptView::ToggleDetailsViewExpand() { - int old_extended_height = GetExtendedViewHeight(); - - expanded_view_ = !expanded_view_; - profile_->GetPrefs()->SetBoolean(prefs::kCookiePromptExpanded, - expanded_view_); - - // We have to set the visbility before asking for the extended view height - // again as there is a bug in combobox that results in preferred height - // changing when visible and not visible. - info_view_->SetVisible(expanded_view_); - int extended_height_delta = GetExtendedViewHeight() - old_extended_height; - views::Window* window = GetWindow(); - gfx::Rect bounds = window->GetBounds(); - bounds.set_height(bounds.height() + extended_height_delta); - window->SetBounds(bounds, NULL); -} - -void CookiePromptView::InitializeViewResources() { - CookiePromptModalDialog::DialogType type = parent_->dialog_type(); - title_ = l10n_util::GetStringF( - type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE ? - IDS_COOKIE_ALERT_TITLE : IDS_DATA_ALERT_TITLE, - UTF8ToWide(parent_->origin().host())); -} diff --git a/chrome/browser/views/cookie_prompt_view.h b/chrome/browser/views/cookie_prompt_view.h deleted file mode 100644 index c94e700..0000000 --- a/chrome/browser/views/cookie_prompt_view.h +++ /dev/null @@ -1,123 +0,0 @@ -// 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_BROWSER_VIEWS_COOKIE_PROMPT_VIEW_H_ -#define CHROME_BROWSER_VIEWS_COOKIE_PROMPT_VIEW_H_ -#pragma once - -#include <string> - -#include "base/task.h" -#include "chrome/browser/browsing_data_local_storage_helper.h" -#include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" -#include "chrome/browser/views/cookie_info_view.h" -#include "chrome/browser/views/modal_dialog_delegate.h" -#include "googleurl/src/gurl.h" -#include "views/controls/button/button.h" -#include "views/controls/link.h" -#include "views/view.h" -#include "views/window/dialog_delegate.h" -#include "views/window/window.h" - -namespace views { -class NativeButton; -class RadioButton; -} - -class CookieInfoView; -class CookiePromptModalDialog; -class LocalStorageInfoView; -class Profile; -class Timer; - -// Cookie alert dialog UI. -class CookiePromptView : public views::View, - public ModalDialogDelegate, - public views::ButtonListener, - public views::LinkController, - public CookieInfoViewDelegate { - public: - // Creates a new CookiePromptView. We take ownership of |parent|. - CookiePromptView( - CookiePromptModalDialog* parent, - gfx::NativeWindow root_window, - Profile* profile); - - virtual ~CookiePromptView(); - - protected: - // views::View overrides. - virtual gfx::Size GetPreferredSize(); - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - // ModalDialogDelegate overrides. - virtual gfx::NativeWindow GetDialogRootWindow(); - - // views::DialogDelegate overrides. - virtual bool CanResize() const { return false; } - virtual std::wstring GetWindowTitle() const; - virtual void WindowClosing(); - virtual views::View* GetContentsView(); - virtual bool IsModal() const { return true; } - virtual bool Accept(); - - // views::ButtonListener overrides. - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // views::LinkController overrides. - virtual void LinkActivated(views::Link* source, int event_flags); - - // views::WindowDelegate overrides. - virtual int GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_NONE; - } - - // CookieInfoViewDelegate overrides: - virtual void ModifyExpireDate(bool session_expire); - - private: - // Initialize the dialog layout. - void Init(); - - // Shows or hides cooke info view and changes parent. - void ToggleDetailsViewExpand(); - - // Calculates view size offset depending on visibility of cookie details. - int GetExtendedViewHeight(); - - // Initializes text resources needed to display this view. - void InitializeViewResources(); - - views::RadioButton* remember_radio_; - views::RadioButton* ask_radio_; - views::NativeButton* allow_button_; - views::NativeButton* block_button_; - views::Link* show_cookie_link_; - views::View* info_view_; - - // True if cookie should expire with this session. - bool session_expire_; - - // True if cookie info view is currently shown and window expanded. - bool expanded_view_; - - // True if the outcome of this dialog has been signaled to the delegate. - bool signaled_; - - // Prompt window title. - std::wstring title_; - - // A pointer to the AppModalDialog that created us. We own this. - scoped_ptr<CookiePromptModalDialog> parent_; - - gfx::NativeWindow root_window_; - - Profile* profile_; - - DISALLOW_COPY_AND_ASSIGN(CookiePromptView); -}; - -#endif // CHROME_BROWSER_VIEWS_COOKIE_PROMPT_VIEW_H_ diff --git a/chrome/browser/views/options/content_filter_page_view.cc b/chrome/browser/views/options/content_filter_page_view.cc index ac2ab38..5ea47e5 100644 --- a/chrome/browser/views/options/content_filter_page_view.cc +++ b/chrome/browser/views/options/content_filter_page_view.cc @@ -103,9 +103,7 @@ void ContentFilterPageView::InitControlLayout() { Need_a_setting_for_every_content_settings_type); DCHECK_EQ(arraysize(kAskIDs), static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); - if (content_type_ != CONTENT_SETTINGS_TYPE_COOKIES || - CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableCookiePrompt)) { + if (content_type_ != CONTENT_SETTINGS_TYPE_COOKIES) { if (kAskIDs[content_type_] != 0) { ask_radio_ = new views::RadioButton( l10n_util::GetString(kAskIDs[content_type_]), radio_button_group); |