diff options
-rw-r--r-- | chrome/browser/cookie_modal_dialog.cc | 16 | ||||
-rw-r--r-- | chrome/browser/cookie_modal_dialog.h | 36 | ||||
-rw-r--r-- | chrome/browser/cookie_modal_dialog_views.cc | 5 | ||||
-rw-r--r-- | chrome/browser/in_process_webkit/dom_storage_area.cc | 40 | ||||
-rw-r--r-- | chrome/browser/in_process_webkit/dom_storage_area.h | 4 | ||||
-rw-r--r-- | chrome/browser/in_process_webkit/dom_storage_permission_request.cc | 22 | ||||
-rw-r--r-- | chrome/browser/in_process_webkit/dom_storage_permission_request.h | 21 | ||||
-rw-r--r-- | chrome/browser/message_box_handler.cc | 10 | ||||
-rw-r--r-- | chrome/browser/message_box_handler.h | 7 | ||||
-rw-r--r-- | chrome/browser/net/chrome_cookie_policy.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/cookie_prompt_view.cc | 62 | ||||
-rw-r--r-- | chrome/browser/views/cookie_prompt_view.h | 30 | ||||
-rwxr-xr-x | chrome/browser/views/local_storage_set_item_info_view.cc | 130 | ||||
-rwxr-xr-x | chrome/browser/views/local_storage_set_item_info_view.h | 60 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 2 |
15 files changed, 298 insertions, 149 deletions
diff --git a/chrome/browser/cookie_modal_dialog.cc b/chrome/browser/cookie_modal_dialog.cc index 5bd46fa..496843c 100644 --- a/chrome/browser/cookie_modal_dialog.cc +++ b/chrome/browser/cookie_modal_dialog.cc @@ -10,24 +10,28 @@ CookiePromptModalDialog::CookiePromptModalDialog( TabContents* tab_contents, - const std::string& host, + const GURL& origin, const std::string& cookie_line, CookiePromptModalDialogDelegate* delegate) : AppModalDialog(tab_contents, std::wstring()), - host_(host), + dialog_type_(DIALOG_TYPE_COOKIE), + origin_(origin), cookie_line_(cookie_line), - cookie_ui_(true), delegate_(delegate) { } CookiePromptModalDialog::CookiePromptModalDialog( TabContents* tab_contents, - const BrowsingDataLocalStorageHelper::LocalStorageInfo& storage_info, + const GURL& origin, + const string16& key, + const string16& value, CookiePromptModalDialogDelegate* delegate) : AppModalDialog(tab_contents, std::wstring()), - storage_info_(storage_info), - cookie_ui_(false), + dialog_type_(DIALOG_TYPE_LOCAL_STORAGE), + origin_(origin), + local_storage_key_(key), + local_storage_value_(value), delegate_(delegate) { } diff --git a/chrome/browser/cookie_modal_dialog.h b/chrome/browser/cookie_modal_dialog.h index d36bb93..f704bad 100644 --- a/chrome/browser/cookie_modal_dialog.h +++ b/chrome/browser/cookie_modal_dialog.h @@ -18,15 +18,24 @@ class PrefService; // |NativeDialog| is a platform specific view. class CookiePromptModalDialog : public AppModalDialog { public: + enum DialogType { + DIALOG_TYPE_COOKIE = 0, + DIALOG_TYPE_LOCAL_STORAGE + // TODO(jorlow): Database + // TODO(michaeln): AppCache + }; + // A union of data necessary to determine the type of message box to // show. CookiePromptModalDialog(TabContents* tab_contents, - const std::string& host, + const GURL& origin, const std::string& cookie_line, CookiePromptModalDialogDelegate* delegate); CookiePromptModalDialog( TabContents* tab_contents, - const BrowsingDataLocalStorageHelper::LocalStorageInfo& storage_info, + const GURL& origin, + const string16& key, + const string16& value, CookiePromptModalDialogDelegate* delegate); virtual ~CookiePromptModalDialog() {} @@ -37,6 +46,13 @@ class CookiePromptModalDialog : public AppModalDialog { virtual void AcceptWindow(); virtual void CancelWindow(); + 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_; } + CookiePromptModalDialogDelegate* GetDelegate() { return delegate_; } + protected: // AppModalDialog overrides. virtual NativeDialog CreateNativeDialog(); @@ -45,17 +61,17 @@ class CookiePromptModalDialog : public AppModalDialog { #endif private: - // Cookie host. - std::string host_; + const DialogType dialog_type_; - // Cookie to display. - std::string cookie_line_; + // The origin connected to this request. + GURL origin_; - // Local storage info to display. - BrowsingDataLocalStorageHelper::LocalStorageInfo storage_info_; + // Cookie to display. + const std::string cookie_line_; - // Whether we're showing cookie UI as opposed to other site data. - bool cookie_ui_; + // LocalStorage key/value. + const string16 local_storage_key_; + const string16 local_storage_value_; // Delegate. The caller should provide one in order to receive results // from this delegate. diff --git a/chrome/browser/cookie_modal_dialog_views.cc b/chrome/browser/cookie_modal_dialog_views.cc index 6e9027a..c8930c1 100644 --- a/chrome/browser/cookie_modal_dialog_views.cc +++ b/chrome/browser/cookie_modal_dialog_views.cc @@ -41,10 +41,7 @@ NativeDialog CookiePromptModalDialog::CreateNativeDialog() { #if defined(OS_WIN) return new CookiePromptView(this, tab_contents_->GetMessageBoxRootWindow(), - tab_contents_->profile(), - storage_info_, - host_, cookie_line_, delegate_, - cookie_ui_); + tab_contents_->profile()); #else return NULL; #endif diff --git a/chrome/browser/in_process_webkit/dom_storage_area.cc b/chrome/browser/in_process_webkit/dom_storage_area.cc index fc9bf80..99f24c6 100644 --- a/chrome/browser/in_process_webkit/dom_storage_area.cc +++ b/chrome/browser/in_process_webkit/dom_storage_area.cc @@ -42,32 +42,23 @@ DOMStorageArea::~DOMStorageArea() { } unsigned DOMStorageArea::Length() { - if (!CheckContentSetting()) - return 0; // Pretend we're an empty store. - CreateWebStorageAreaIfNecessary(); return storage_area_->length(); } NullableString16 DOMStorageArea::Key(unsigned index) { - if (!CheckContentSetting()) - return NullableString16(true); // Null string. - CreateWebStorageAreaIfNecessary(); return storage_area_->key(index); } NullableString16 DOMStorageArea::GetItem(const string16& key) { - if (!CheckContentSetting()) - return NullableString16(true); // Null string. - CreateWebStorageAreaIfNecessary(); return storage_area_->getItem(key); } NullableString16 DOMStorageArea::SetItem( const string16& key, const string16& value, bool* quota_exception) { - if (!CheckContentSetting()) { + if (!CheckContentSetting(key, value)) { *quota_exception = true; return NullableString16(true); // Ignored if exception is true. } @@ -79,9 +70,6 @@ NullableString16 DOMStorageArea::SetItem( } NullableString16 DOMStorageArea::RemoveItem(const string16& key) { - if (!CheckContentSetting()) - return NullableString16(true); // Indicates nothing removed. - CreateWebStorageAreaIfNecessary(); WebString old_value; storage_area_->removeItem(key, WebURL(), old_value); @@ -89,9 +77,6 @@ NullableString16 DOMStorageArea::RemoveItem(const string16& key) { } bool DOMStorageArea::Clear() { - if (!CheckContentSetting()) - return false; // Nothing cleared. - CreateWebStorageAreaIfNecessary(); bool somethingCleared; storage_area_->clear(WebURL(), somethingCleared); @@ -107,31 +92,14 @@ void DOMStorageArea::CreateWebStorageAreaIfNecessary() { storage_area_.reset(owner_->CreateWebStorageArea(origin_)); } -bool DOMStorageArea::CheckContentSetting() { +bool DOMStorageArea::CheckContentSetting(const string16& key, + const string16& value) { ContentSetting content_setting = host_content_settings_map_->GetContentSetting( origin_url_, CONTENT_SETTINGS_TYPE_COOKIES); if (content_setting == CONTENT_SETTING_ASK) { - WebSecurityOrigin security_origin( - WebSecurityOrigin::createFromString(origin_)); - FilePath::StringType file_name = webkit_glue::WebStringToFilePath( - security_origin.databaseIdentifier()).value(); - file_name.append(DOMStorageContext::kLocalStorageExtension); - FilePath file_path = webkit_glue::WebStringToFilePath( - owner_->data_dir_path()).Append(file_name); - - bool file_exists = false; - int64 size = 0; - base::Time last_modified; - file_util::FileInfo file_info; - if (file_util::GetFileInfo(file_path, &file_info)) { - file_exists = true; - size = file_info.size; - last_modified = file_info.last_modified; - } - DOMStoragePermissionRequest request(origin_url_, file_exists, size, - last_modified, + DOMStoragePermissionRequest request(origin_url_, key, value, host_content_settings_map_); ChromeThread::PostTask( ChromeThread::UI, FROM_HERE, diff --git a/chrome/browser/in_process_webkit/dom_storage_area.h b/chrome/browser/in_process_webkit/dom_storage_area.h index 4afc731..01c068c 100644 --- a/chrome/browser/in_process_webkit/dom_storage_area.h +++ b/chrome/browser/in_process_webkit/dom_storage_area.h @@ -38,7 +38,6 @@ class DOMStorageArea { NullableString16 RemoveItem(const string16& key); bool Clear(); void PurgeMemory(); - bool CheckContentSetting(); int64 id() const { return id_; } @@ -46,6 +45,9 @@ class DOMStorageArea { // Creates the underlying WebStorageArea on demand. void CreateWebStorageAreaIfNecessary(); + // Used to see if setItem has permission to do its thing. + bool CheckContentSetting(const string16& key, const string16& value); + // The origin this storage area represents. string16 origin_; GURL origin_url_; diff --git a/chrome/browser/in_process_webkit/dom_storage_permission_request.cc b/chrome/browser/in_process_webkit/dom_storage_permission_request.cc index 4fb3293..6970cc9b 100644 --- a/chrome/browser/in_process_webkit/dom_storage_permission_request.cc +++ b/chrome/browser/in_process_webkit/dom_storage_permission_request.cc @@ -9,14 +9,12 @@ DOMStoragePermissionRequest::DOMStoragePermissionRequest( const GURL& url, - bool file_exists, - int64 size, - base::Time last_modified, + const string16& key, + const string16& value, HostContentSettingsMap* settings) : url_(url), - file_exists_(file_exists), - size_(size), - last_modified_(last_modified), + key_(key), + value_(value), event_(true, false), // manual reset, not initially signaled host_content_settings_map_(settings) { } @@ -62,15 +60,9 @@ void DOMStoragePermissionRequest::PromptUser( // showed the name and value being stored (as is done for cookies). const std::string& host = dom_storage_permission_request->url().host(); RunLocalStoragePrompt(browser->GetSelectedTabContents(), - BrowsingDataLocalStorageHelper::LocalStorageInfo( - std::string(), - host, - -1, - std::string(), - host, - FilePath(), - dom_storage_permission_request->size(), - dom_storage_permission_request->last_modified()), + dom_storage_permission_request->url(), + dom_storage_permission_request->key(), + dom_storage_permission_request->value(), dom_storage_permission_request); #else // TODO(darin): Enable prompting for other ports. diff --git a/chrome/browser/in_process_webkit/dom_storage_permission_request.h b/chrome/browser/in_process_webkit/dom_storage_permission_request.h index 3b94177..3d0d81f 100644 --- a/chrome/browser/in_process_webkit/dom_storage_permission_request.h +++ b/chrome/browser/in_process_webkit/dom_storage_permission_request.h @@ -20,9 +20,8 @@ class DOMStoragePermissionRequest : public CookiePromptModalDialogDelegate { public: DOMStoragePermissionRequest(const GURL& url, - bool file_exists, - int64 size, - base::Time last_modified, + const string16& key, + const string16& value, HostContentSettingsMap* settings); @@ -30,9 +29,8 @@ class DOMStoragePermissionRequest : public CookiePromptModalDialogDelegate { void SendResponse(ContentSetting content_setting, bool remember); const GURL& url() const { return url_; } - bool file_exists() const { return file_exists_; } - int64 size() const { return size_; } - const base::Time last_modified() const { return last_modified_; } + const string16& key() const { return key_; } + const string16& value() const { return value_; } // Called on the UI thread. static void PromptUser(DOMStoragePermissionRequest* request); @@ -45,14 +43,11 @@ class DOMStoragePermissionRequest : public CookiePromptModalDialogDelegate { // The URL we need to get permission for. const GURL url_; - // Is there any information on disk currently? - bool file_exists_; + // The key we're trying to set. + const string16 key_; - // If file_exists_, what's the size? - int64 size_; - - // If file_exists_, what's the size? - const base::Time last_modified_; + // The value we're trying to set. + const string16 value_; // The response to the permission request. ContentSetting response_content_setting_; diff --git a/chrome/browser/message_box_handler.cc b/chrome/browser/message_box_handler.cc index b1c33a7..4a2d19f 100644 --- a/chrome/browser/message_box_handler.cc +++ b/chrome/browser/message_box_handler.cc @@ -60,20 +60,22 @@ void RunBeforeUnloadDialog(TabContents* tab_contents, #if defined(OS_WIN) void RunCookiePrompt(TabContents* tab_contents, - const std::string& host, + const GURL& origin, const std::string& cookie_line, CookiePromptModalDialogDelegate* delegate) { Singleton<AppModalDialogQueue>()->AddDialog( - new CookiePromptModalDialog(tab_contents, host, cookie_line, delegate)); + new CookiePromptModalDialog(tab_contents, origin, cookie_line, delegate)); } void RunLocalStoragePrompt( TabContents* tab_contents, - const BrowsingDataLocalStorageHelper::LocalStorageInfo& local_storage_info, + const GURL& origin, + const string16& key, + const string16& value, CookiePromptModalDialogDelegate* delegate) { Singleton<AppModalDialogQueue>()->AddDialog( - new CookiePromptModalDialog(tab_contents, local_storage_info, delegate)); + new CookiePromptModalDialog(tab_contents, origin, key, value, delegate)); } #endif diff --git a/chrome/browser/message_box_handler.h b/chrome/browser/message_box_handler.h index 04df1f8..7b16c35 100644 --- a/chrome/browser/message_box_handler.h +++ b/chrome/browser/message_box_handler.h @@ -7,6 +7,7 @@ #include <string> +#include "base/string16.h" #include "chrome/browser/browsing_data_local_storage_helper.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_message.h" @@ -45,7 +46,7 @@ void RunBeforeUnloadDialog(TabContents* tab_contents, // user to accept or reject the cookie. The caller should pass |delegate| // that will handle the reply from the dialog. void RunCookiePrompt(TabContents* tab_contents, - const std::string& host, + const GURL& origin, const std::string& cookie_line, CookiePromptModalDialogDelegate* delegate); @@ -54,7 +55,9 @@ void RunCookiePrompt(TabContents* tab_contents, // that will handle the reply from the dialog. void RunLocalStoragePrompt( TabContents* tab_contents, - const BrowsingDataLocalStorageHelper::LocalStorageInfo& local_storage_info, + const GURL& origin, + const string16& key, + const string16& value, CookiePromptModalDialogDelegate* delegate); #endif diff --git a/chrome/browser/net/chrome_cookie_policy.cc b/chrome/browser/net/chrome_cookie_policy.cc index 848ce28..6646af3 100644 --- a/chrome/browser/net/chrome_cookie_policy.cc +++ b/chrome/browser/net/chrome_cookie_policy.cc @@ -163,7 +163,7 @@ void ChromeCookiePolicy::ShowNextPrompt() { } #if defined(OS_WIN) - RunCookiePrompt(browser->GetSelectedTabContents(), host, data.cookie_line, + RunCookiePrompt(browser->GetSelectedTabContents(), data.url, data.cookie_line, new PromptDelegate(this, host)); #else // TODO(darin): Enable prompting for other ports. diff --git a/chrome/browser/views/cookie_prompt_view.cc b/chrome/browser/views/cookie_prompt_view.cc index cc0430f..dd2425e 100644 --- a/chrome/browser/views/cookie_prompt_view.cc +++ b/chrome/browser/views/cookie_prompt_view.cc @@ -17,7 +17,7 @@ #include "chrome/browser/profile.h" #include "chrome/browser/views/browser_dialogs.h" #include "chrome/browser/views/cookie_info_view.h" -#include "chrome/browser/views/local_storage_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 "chrome/common/pref_service.h" @@ -40,12 +40,7 @@ static const int kCookiePromptViewInsetSize = 5; CookiePromptView::CookiePromptView( CookiePromptModalDialog* parent, gfx::NativeWindow root_window, - Profile* profile, - const BrowsingDataLocalStorageHelper::LocalStorageInfo& storage_info, - const std::string& host, - const std::string& cookie_line, - CookiePromptModalDialogDelegate* delegate, - bool cookie_ui) + Profile* profile) : remember_radio_(NULL), ask_radio_(NULL), allow_button_(NULL), @@ -55,14 +50,9 @@ CookiePromptView::CookiePromptView( session_expire_(false), expanded_view_(false), signaled_(false), - cookie_ui_(cookie_ui), parent_(parent), - root_window_(root_window), - host_(host), - cookie_line_(cookie_line), - local_storage_info_(storage_info), - delegate_(delegate) { - InitializeViewResources(host); + root_window_(root_window) { + InitializeViewResources(parent_->origin().host()); expanded_view_ = g_browser_process->local_state()-> GetBoolean(prefs::kCookiePromptExpanded); } @@ -102,8 +92,8 @@ std::wstring CookiePromptView::GetWindowTitle() const { } void CookiePromptView::WindowClosing() { - if (!signaled_ && delegate_) - delegate_->BlockSiteData(false); + if (!signaled_ && parent_->GetDelegate()) + parent_->GetDelegate()->BlockSiteData(false); parent_->CompleteDialog(); } @@ -123,14 +113,15 @@ void CookiePromptView::ModifyExpireDate(bool session_expire) { void CookiePromptView::ButtonPressed(views::Button* sender, const views::Event& event) { if (sender == allow_button_) { - if (delegate_) { - delegate_->AllowSiteData(remember_radio_->checked(), session_expire_); + if (parent_->GetDelegate()) { + parent_->GetDelegate()->AllowSiteData(remember_radio_->checked(), + session_expire_); signaled_ = true; } GetWindow()->Close(); } else if (sender == block_button_) { - if (delegate_) { - delegate_->BlockSiteData(remember_radio_->checked()); + if (parent_->GetDelegate()) { + parent_->GetDelegate()->BlockSiteData(remember_radio_->checked()); signaled_ = true; } GetWindow()->Close(); @@ -148,9 +139,11 @@ void CookiePromptView::LinkActivated(views::Link* source, int event_flags) { // CookiePromptView, private: void CookiePromptView::Init() { - std::wstring display_host = UTF8ToWide(host_); + CookiePromptModalDialog::DialogType type = parent_->dialog_type(); + std::wstring display_host = UTF8ToWide(parent_->origin().host()); views::Label* description_label = new views::Label(l10n_util::GetStringF( - cookie_ui_ ? IDS_COOKIE_ALERT_LABEL : IDS_DATA_ALERT_LABEL, + 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( @@ -236,20 +229,23 @@ void CookiePromptView::Init() { layout->StartRow(0, one_column_layout_id); - if (cookie_ui_) { + 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(host_, cookie_line_); + cookie_info_view->SetCookieString(parent_->origin().host(), 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 { - LocalStorageInfoView* local_storage_info_view = new LocalStorageInfoView(); - layout->AddView(local_storage_info_view, 1, 1, GridLayout::FILL, - GridLayout::CENTER); - local_storage_info_view->SetLocalStorageInfo(local_storage_info_); - info_view_ = local_storage_info_view; + NOTIMPLEMENTED(); } info_view_->SetVisible(expanded_view_); @@ -284,9 +280,11 @@ void CookiePromptView::ToggleDetailsViewExpand() { void CookiePromptView::InitializeViewResources(const std::string& host) { DCHECK(host.empty() || host[0] != '.'); - host_ = host; + DCHECK(host == parent_->origin().host()); + CookiePromptModalDialog::DialogType type = parent_->dialog_type(); title_ = l10n_util::GetStringF( - cookie_ui_ ? IDS_COOKIE_ALERT_TITLE : IDS_DATA_ALERT_TITLE, - UTF8ToWide(host_)); + 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 index 5f1e400..daeb2b4 100644 --- a/chrome/browser/views/cookie_prompt_view.h +++ b/chrome/browser/views/cookie_prompt_view.h @@ -32,21 +32,15 @@ class Timer; // Cookie alert dialog UI. class CookiePromptView : public views::View, - public ModalDialogDelegate, - public views::ButtonListener, - public views::LinkController, - public CookieInfoViewDelegate { + public ModalDialogDelegate, + public views::ButtonListener, + public views::LinkController, + public CookieInfoViewDelegate { public: CookiePromptView( CookiePromptModalDialog* parent, gfx::NativeWindow root_window, - Profile* profile, - const BrowsingDataLocalStorageHelper::LocalStorageInfo& - local_storage_info, - const std::string& host, - const std::string& cookie_line, - CookiePromptModalDialogDelegate* delegate, - bool cookie_ui); + Profile* profile); virtual ~CookiePromptView(); @@ -113,25 +107,11 @@ class CookiePromptView : public views::View, // Prompt window title. std::wstring title_; - // Whether we're showing cookie UI as opposed to other site data. - bool cookie_ui_; - // A pointer to the AppModalDialog that owns us. CookiePromptModalDialog* parent_; gfx::NativeWindow root_window_; - // Cookie / local storage host. - std::string host_; - - // Displayed cookie. Only used when |cookie_ui_| is true. - std::string cookie_line_; - - // Displayed local storage info. Only used when |cookie_ui_| is false. - BrowsingDataLocalStorageHelper::LocalStorageInfo local_storage_info_; - - CookiePromptModalDialogDelegate* delegate_; - DISALLOW_COPY_AND_ASSIGN(CookiePromptView); }; diff --git a/chrome/browser/views/local_storage_set_item_info_view.cc b/chrome/browser/views/local_storage_set_item_info_view.cc new file mode 100755 index 0000000..b55934e --- /dev/null +++ b/chrome/browser/views/local_storage_set_item_info_view.cc @@ -0,0 +1,130 @@ +// 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/local_storage_set_item_info_view.h" + +#include <algorithm> + +#include "app/gfx/color_utils.h" +#include "app/l10n_util.h" +#include "base/i18n/time_formatting.h" +#include "base/string_util.h" +#include "grit/generated_resources.h" +#include "views/grid_layout.h" +#include "views/controls/label.h" +#include "views/controls/textfield/textfield.h" +#include "views/standard_layout.h" + +static const int kLocalStorageSetItemInfoViewBorderSize = 1; +static const int kLocalStorageSetItemInfoViewInsetSize = 3; + +/////////////////////////////////////////////////////////////////////////////// +// LocalStorageSetItemInfoView, public: + +LocalStorageSetItemInfoView::LocalStorageSetItemInfoView() + : host_value_field_(NULL), + key_value_field_(NULL), + value_value_field_(NULL) { +} + +LocalStorageSetItemInfoView::~LocalStorageSetItemInfoView() { +} + +void LocalStorageSetItemInfoView::SetFields(const std::string& host, + const string16& key, + const string16& value) { + host_value_field_->SetText(UTF8ToWide(host)); + key_value_field_->SetText(key); + value_value_field_->SetText(value); + EnableLocalStorageDisplay(true); +} + +void LocalStorageSetItemInfoView::EnableLocalStorageDisplay(bool enabled) { + host_value_field_->SetEnabled(enabled); + key_value_field_->SetEnabled(enabled); + value_value_field_->SetEnabled(enabled); +} + +void LocalStorageSetItemInfoView::ClearLocalStorageDisplay() { + std::wstring no_cookie_string = + l10n_util::GetString(IDS_COOKIES_COOKIE_NONESELECTED); + host_value_field_->SetText(no_cookie_string); + key_value_field_->SetText(no_cookie_string); + value_value_field_->SetText(no_cookie_string); + EnableLocalStorageDisplay(false); +} + +/////////////////////////////////////////////////////////////////////////////// +// LocalStorageSetItemInfoView, views::View overrides: + +void LocalStorageSetItemInfoView::ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child) { + if (is_add && child == this) + Init(); +} + +/////////////////////////////////////////////////////////////////////////////// +// LocalStorageSetItemInfoView, private: + +void LocalStorageSetItemInfoView::Init() { + SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); + views::Border* border = views::Border::CreateSolidBorder( + kLocalStorageSetItemInfoViewBorderSize, border_color); + set_border(border); + + // TODO(jorlow): These strings are not quite right, but we're post-freeze. + views::Label* host_label = new views::Label( + l10n_util::GetString(IDS_COOKIES_COOKIE_DOMAIN_LABEL)); + host_value_field_ = new views::Textfield; + views::Label* key_label = new views::Label( + l10n_util::GetString(IDS_COOKIES_COOKIE_NAME_LABEL)); + key_value_field_ = new views::Textfield; + views::Label* value_label = new views::Label( + l10n_util::GetString(IDS_COOKIES_COOKIE_CONTENT_LABEL)); + value_value_field_ = new views::Textfield; + + using views::GridLayout; + + GridLayout* layout = new GridLayout(this); + layout->SetInsets(kLocalStorageSetItemInfoViewInsetSize, + kLocalStorageSetItemInfoViewInsetSize, + kLocalStorageSetItemInfoViewInsetSize, + kLocalStorageSetItemInfoViewInsetSize); + SetLayoutManager(layout); + + int three_column_layout_id = 0; + views::ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); + column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, + GridLayout::USE_PREF, 0, 0); + + layout->StartRow(0, three_column_layout_id); + layout->AddView(host_label); + layout->AddView(host_value_field_); + layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); + layout->StartRow(0, three_column_layout_id); + layout->AddView(key_label); + layout->AddView(key_value_field_); + layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); + layout->StartRow(0, three_column_layout_id); + layout->AddView(value_label); + layout->AddView(value_value_field_); + + // Color these borderless text areas the same as the containing dialog. + SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); + // Now that the Textfields are in the view hierarchy, we can initialize them. + host_value_field_->SetReadOnly(true); + host_value_field_->RemoveBorder(); + host_value_field_->SetBackgroundColor(text_area_background); + key_value_field_->SetReadOnly(true); + key_value_field_->RemoveBorder(); + key_value_field_->SetBackgroundColor(text_area_background); + value_value_field_->SetReadOnly(true); + value_value_field_->RemoveBorder(); + value_value_field_->SetBackgroundColor(text_area_background); +} + diff --git a/chrome/browser/views/local_storage_set_item_info_view.h b/chrome/browser/views/local_storage_set_item_info_view.h new file mode 100755 index 0000000..7ab2118 --- /dev/null +++ b/chrome/browser/views/local_storage_set_item_info_view.h @@ -0,0 +1,60 @@ +// 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_LOCAL_STORAGE_SET_ITEM_INFO_VIEW_H_ +#define CHROME_BROWSER_VIEWS_LOCAL_STORAGE_SET_ITEM_INFO_VIEW_H_ + +#include <string> +#include <vector> + +#include "base/string16.h" +#include "views/view.h" + +namespace views { +class Label; +class Textfield; +} + +/////////////////////////////////////////////////////////////////////////////// +// LocalStorageSetItemInfoView +// +// Responsible for displaying a tabular grid of Local Storage information when +// prompting for permission to set an item. +class LocalStorageSetItemInfoView : public views::View { + public: + LocalStorageSetItemInfoView(); + virtual ~LocalStorageSetItemInfoView(); + + // Update the display from the specified Local Storage info. + void SetFields(const std::string& host, + const string16& key, + const string16& value); + + // Clears the display to indicate that no or multiple local storages + // are selected. + void ClearLocalStorageDisplay(); + + // Enables or disables the local storate property text fields. + void EnableLocalStorageDisplay(bool enabled); + + protected: + // views::View overrides: + virtual void ViewHierarchyChanged( + bool is_add, views::View* parent, views::View* child); + + private: + // Set up the view layout + void Init(); + + // Individual property labels + views::Textfield* host_value_field_; + views::Textfield* key_value_field_; + views::Textfield* value_value_field_; + + DISALLOW_COPY_AND_ASSIGN(LocalStorageSetItemInfoView); +}; + + +#endif // CHROME_BROWSER_VIEWS_LOCAL_STORAGE_SET_ITEM_INFO_VIEW_H_ + diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index a927299..501e2ae 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1966,6 +1966,8 @@ 'browser/views/keyword_editor_view.h', 'browser/views/local_storage_info_view.cc', 'browser/views/local_storage_info_view.h', + 'browser/views/local_storage_set_item_info_view.cc', + 'browser/views/local_storage_set_item_info_view.h', 'browser/views/location_bar_view.cc', 'browser/views/location_bar_view.h', 'browser/views/login_view.cc', |