summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 20:16:50 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 20:16:50 +0000
commit76960a40e09420ac2e302f4b307c4dd0d8a61ce8 (patch)
tree8f6a5642af430f77528fd479eba63dfae42169d8
parent45cbfb0444d2ae27d9dbc9880c547c0d42978782 (diff)
downloadchromium_src-76960a40e09420ac2e302f4b307c4dd0d8a61ce8.zip
chromium_src-76960a40e09420ac2e302f4b307c4dd0d8a61ce8.tar.gz
chromium_src-76960a40e09420ac2e302f4b307c4dd0d8a61ce8.tar.bz2
Add PropertyBag to TabContents. Convert the autocomplete state as a proof of concept. Add necessary const accessors to property bag.
BUG=5260 Review URL: http://codereview.chromium.org/13707 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6920 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc17
-rw-r--r--chrome/browser/tab_contents.cc1
-rw-r--r--chrome/browser/tab_contents.h21
-rw-r--r--chrome/common/property_bag.cc7
-rw-r--r--chrome/common/property_bag.h11
5 files changed, 40 insertions, 17 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 03267af..6fb50f1 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -645,6 +645,13 @@ static const SkColor kSchemeSelectedStrikeoutColor =
static HWND edit_hwnd = NULL;
static PAINTSTRUCT paint_struct;
+// Returns a lazily initialized property bag accessor for saving our state in a
+// TabContents.
+static PropertyAccessor<AutocompleteEditState>* GetStateAccessor() {
+ static PropertyAccessor<AutocompleteEditState> state;
+ return &state;
+}
+
AutocompleteEditView::AutocompleteEditView(
const ChromeFont& font,
AutocompleteEditController* controller,
@@ -787,8 +794,10 @@ void AutocompleteEditView::SaveStateToTab(TabContents* tab) {
CHARRANGE selection;
GetSelection(selection);
- tab->set_saved_location_bar_state(new AutocompleteEditState(model_state,
- State(selection, saved_selection_for_focus_change_)));
+ GetStateAccessor()->SetProperty(tab->property_bag(),
+ AutocompleteEditState(
+ model_state,
+ State(selection, saved_selection_for_focus_change_)));
}
void AutocompleteEditView::Update(const TabContents* tab_for_state_restoring) {
@@ -825,8 +834,8 @@ void AutocompleteEditView::Update(const TabContents* tab_for_state_restoring) {
// won't overwrite all our local state.
RevertAll();
- const AutocompleteEditState* const state =
- tab_for_state_restoring->saved_location_bar_state();
+ const AutocompleteEditState* state = GetStateAccessor()->GetProperty(
+ tab_for_state_restoring->property_bag());
if (state) {
model_->RestoreState(state->model_state);
diff --git a/chrome/browser/tab_contents.cc b/chrome/browser/tab_contents.cc
index ffd17cb..8e93672 100644
--- a/chrome/browser/tab_contents.cc
+++ b/chrome/browser/tab_contents.cc
@@ -42,7 +42,6 @@ TabContents::TabContents(TabContentsType type)
is_active_(true),
is_crashed_(false),
waiting_for_response_(false),
- saved_location_bar_state_(NULL),
shelf_visible_(false),
max_page_id_(-1),
blocked_popups_(NULL),
diff --git a/chrome/browser/tab_contents.h b/chrome/browser/tab_contents.h
index 4ff6a44..0c40e36 100644
--- a/chrome/browser/tab_contents.h
+++ b/chrome/browser/tab_contents.h
@@ -15,6 +15,7 @@
#include "chrome/browser/page_navigator.h"
#include "chrome/browser/tab_contents_type.h"
#include "chrome/common/navigation_types.h"
+#include "chrome/common/property_bag.h"
namespace gfx {
class Rect;
@@ -112,6 +113,12 @@ class TabContents : public PageNavigator,
// Returns the type of tab this is. See also the As* functions following.
TabContentsType type() const { return type_; }
+ // Returns the property bag for this tab contents, where callers can add
+ // extra data they may wish to associate with the tab. Returns a pointer
+ // rather than a reference since the PropertyAccessors expect this.
+ const PropertyBag* property_bag() const { return &property_bag_; }
+ PropertyBag* property_bag() { return &property_bag_; }
+
// Returns this object as a WebContents if it is one, and NULL otherwise.
virtual WebContents* AsWebContents() { return NULL; }
@@ -220,16 +227,6 @@ class TabContents : public PageNavigator,
// Internal state ------------------------------------------------------------
- // For use when switching tabs, these functions allow the tab contents to
- // hold the per-tab state of the location bar. The tab contents takes
- // ownership of the pointer.
- void set_saved_location_bar_state(const AutocompleteEditState* state) {
- saved_location_bar_state_.reset(state);
- }
- const AutocompleteEditState* saved_location_bar_state() const {
- return saved_location_bar_state_.get();
- }
-
// This flag indicates whether the tab contents is currently being
// screenshotted by the DraggedTabController.
bool capturing_contents() const { return capturing_contents_; }
@@ -512,6 +509,8 @@ class TabContents : public PageNavigator,
TabContentsDelegate* delegate_;
NavigationController* controller_;
+ PropertyBag property_bag_;
+
// Indicates whether we're currently loading a resource.
bool is_loading_;
@@ -523,8 +522,6 @@ class TabContents : public PageNavigator,
// See waiting_for_response() above.
bool waiting_for_response_;
- scoped_ptr<const AutocompleteEditState> saved_location_bar_state_;
-
// The download shelf view (view at the bottom of the page).
scoped_ptr<DownloadShelfView> download_shelf_view_;
diff --git a/chrome/common/property_bag.cc b/chrome/common/property_bag.cc
index f7c92a3..dc25961 100644
--- a/chrome/common/property_bag.cc
+++ b/chrome/common/property_bag.cc
@@ -35,6 +35,13 @@ PropertyBag::Prop* PropertyBag::GetProperty(PropID id) {
return found->second.get();
}
+const PropertyBag::Prop* PropertyBag::GetProperty(PropID id) const {
+ PropertyMap::const_iterator found = props_.find(id);
+ if (found == props_.end())
+ return NULL;
+ return found->second.get();
+}
+
void PropertyBag::DeleteProperty(PropID id) {
PropertyMap::iterator found = props_.find(id);
if (found == props_.end())
diff --git a/chrome/common/property_bag.h b/chrome/common/property_bag.h
index 9965382..d2f3559 100644
--- a/chrome/common/property_bag.h
+++ b/chrome/common/property_bag.h
@@ -77,6 +77,7 @@ class PropertyBag {
// The returned pointer will be NULL if there is no match. Ownership of the
// pointer will stay with the property bag.
Prop* GetProperty(PropID id);
+ const Prop* GetProperty(PropID id) const;
// Deletes the property with the given ID from the bag if it exists.
void DeleteProperty(PropID id);
@@ -107,6 +108,9 @@ class PropertyAccessorBase {
PropertyBag::Prop* GetPropertyInternal(PropertyBag* bag) {
return bag->GetProperty(prop_id_);
}
+ const PropertyBag::Prop* GetPropertyInternal(const PropertyBag* bag) const {
+ return bag->GetProperty(prop_id_);
+ }
private:
// Identifier for this property.
@@ -140,6 +144,12 @@ class PropertyAccessor : public PropertyAccessorBase {
return NULL;
return static_cast<Container*>(prop)->get();
}
+ const T* GetProperty(const PropertyBag* bag) const {
+ const PropertyBag::Prop* prop = GetPropertyInternal(bag);
+ if (!prop)
+ return NULL;
+ return static_cast<const Container*>(prop)->get();
+ }
// See also DeleteProperty on thn PropertyAccessorBase.
@@ -149,6 +159,7 @@ class PropertyAccessor : public PropertyAccessorBase {
Container(const T& data) : data_(data) {}
T* get() { return &data_; }
+ const T* get() const { return &data_; }
private:
virtual Prop* copy() {