summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-04 20:04:21 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-04 20:04:21 +0000
commita0366a518fb5883c6fcd455c60257046899c44b7 (patch)
tree843dba3984b179f3478364ebd85f3094b832361a /chrome
parent6356adaa0480b3af242f7e9872cd011449d8ce09 (diff)
downloadchromium_src-a0366a518fb5883c6fcd455c60257046899c44b7.zip
chromium_src-a0366a518fb5883c6fcd455c60257046899c44b7.tar.gz
chromium_src-a0366a518fb5883c6fcd455c60257046899c44b7.tar.bz2
Move bookmark star from TabContents to TabContentsWrapper.
BUG=71097 TEST=Hammer on bookmark star on all platforms. Nothing should crash, break, or have any user-visible change. Review URL: http://codereview.chromium.org/6334066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73836 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/blocked_content_container.h5
-rw-r--r--chrome/browser/chromeos/dom_ui/menu_ui.cc1
-rw-r--r--chrome/browser/chromeos/login/eula_view.h3
-rw-r--r--chrome/browser/chromeos/login/web_page_screen.h3
-rw-r--r--chrome/browser/debugger/devtools_window.h1
-rw-r--r--chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc8
-rw-r--r--chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h3
-rw-r--r--chrome/browser/dom_ui/html_dialog_tab_contents_delegate_unittest.cc6
-rw-r--r--chrome/browser/external_tab_container_win.cc4
-rw-r--r--chrome/browser/external_tab_container_win.h1
-rw-r--r--chrome/browser/instant/instant_loader.cc1
-rw-r--r--chrome/browser/instant/instant_unload_handler.cc3
-rw-r--r--chrome/browser/sidebar/sidebar_container.h3
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc31
-rw-r--r--chrome/browser/tab_contents/tab_contents.h11
-rw-r--r--chrome/browser/tab_contents/tab_contents_delegate.h5
-rw-r--r--chrome/browser/ui/browser.cc21
-rw-r--r--chrome/browser/ui/browser.h8
-rw-r--r--chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc28
-rw-r--r--chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h1
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper.cc68
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper.h46
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.cc8
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h22
-rw-r--r--chrome/browser/ui/views/tabs/dragged_tab_controller.cc28
-rw-r--r--chrome/browser/ui/views/tabs/dragged_tab_controller.h3
-rw-r--r--chrome/chrome_browser.gypi2
27 files changed, 196 insertions, 128 deletions
diff --git a/chrome/browser/blocked_content_container.h b/chrome/browser/blocked_content_container.h
index 714af7ce0..bf13334 100644
--- a/chrome/browser/blocked_content_container.h
+++ b/chrome/browser/blocked_content_container.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -84,9 +84,6 @@ class BlockedContentContainer : public TabContentsDelegate {
// Ignored; BlockedContentContainer doesn't display a toolbar.
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {}
- // Ignored; BlockedContentContainer doesn't display a bookmarking star.
- virtual void URLStarredChanged(TabContents* source, bool starred) {}
-
// Ignored; BlockedContentContainer doesn't display a URL bar.
virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
diff --git a/chrome/browser/chromeos/dom_ui/menu_ui.cc b/chrome/browser/chromeos/dom_ui/menu_ui.cc
index e52fb58..2a5678f 100644
--- a/chrome/browser/chromeos/dom_ui/menu_ui.cc
+++ b/chrome/browser/chromeos/dom_ui/menu_ui.cc
@@ -287,7 +287,6 @@ class MenuHandler : public chromeos::MenuHandlerBase,
virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {}
virtual bool IsPopup(const TabContents* source) { return false; }
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {}
- virtual void URLStarredChanged(TabContents* source, bool starred) {}
virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
virtual bool CanDownload(int request_id) { return false; }
virtual bool infobars_enabled() { return false; }
diff --git a/chrome/browser/chromeos/login/eula_view.h b/chrome/browser/chromeos/login/eula_view.h
index 44a9257..d8d5f40 100644
--- a/chrome/browser/chromeos/login/eula_view.h
+++ b/chrome/browser/chromeos/login/eula_view.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -56,7 +56,6 @@ class EULATabContentsDelegate : public TabContentsDelegate {
virtual void LoadingStateChanged(TabContents* source) {}
virtual void CloseContents(TabContents* source) {}
virtual bool IsPopup(TabContents* source) { return false; }
- virtual void URLStarredChanged(TabContents* source, bool starred) {}
virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
virtual bool ShouldAddNavigationToHistory(
const history::HistoryAddPageArgs& add_page_args,
diff --git a/chrome/browser/chromeos/login/web_page_screen.h b/chrome/browser/chromeos/login/web_page_screen.h
index c9746bf..3d4abf0 100644
--- a/chrome/browser/chromeos/login/web_page_screen.h
+++ b/chrome/browser/chromeos/login/web_page_screen.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -41,7 +41,6 @@ class WebPageScreen : public TabContentsDelegate {
virtual void LoadingStateChanged(TabContents* source) = 0;
virtual void CloseContents(TabContents* source) {}
virtual bool IsPopup(TabContents* source) { return false; }
- virtual void URLStarredChanged(TabContents* source, bool starred) {}
virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
virtual bool ShouldAddNavigationToHistory(
const history::HistoryAddPageArgs& add_page_args,
diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h
index 66966b6..d5a81c6 100644
--- a/chrome/browser/debugger/devtools_window.h
+++ b/chrome/browser/debugger/devtools_window.h
@@ -89,7 +89,6 @@ class DevToolsWindow
virtual void CloseContents(TabContents* source) {}
virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {}
virtual bool CanReloadContents(TabContents* source) const;
- virtual void URLStarredChanged(TabContents* source, bool starred) {}
virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {}
virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
diff --git a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc
index 6f8d825..4a41b83 100644
--- a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc
+++ b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -96,12 +96,6 @@ bool HtmlDialogTabContentsDelegate::IsPopup(const TabContents* source) const {
return true;
}
-void HtmlDialogTabContentsDelegate::URLStarredChanged(TabContents* source,
- bool starred) {
- // We don't have a visible star to click in the window.
- NOTREACHED();
-}
-
void HtmlDialogTabContentsDelegate::UpdateTargetURL(TabContents* source,
const GURL& url) {
// Ignored.
diff --git a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h
index c6ec732..4642fdd 100644
--- a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h
+++ b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -52,7 +52,6 @@ class HtmlDialogTabContentsDelegate : public TabContentsDelegate {
virtual void LoadingStateChanged(TabContents* source);
virtual void CloseContents(TabContents* source);
virtual bool IsPopup(const TabContents* source) const;
- virtual void URLStarredChanged(TabContents* source, bool starred);
virtual void UpdateTargetURL(TabContents* source, const GURL& url);
virtual bool ShouldAddNavigationToHistory(
const history::HistoryAddPageArgs& add_page_args,
diff --git a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate_unittest.cc b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate_unittest.cc
index d8af35d..911a5c4 100644
--- a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate_unittest.cc
+++ b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -67,10 +67,6 @@ TEST_F(HtmlDialogTabContentsDelegateTest, DoNothingMethodsTest) {
test_tab_contents_delegate_->ActivateContents(NULL);
test_tab_contents_delegate_->LoadingStateChanged(NULL);
test_tab_contents_delegate_->CloseContents(NULL);
- // URLStarredChanged() calls NOTREACHED() which immediately crashes.
- // Death tests take too long for unit_test tests on OS X and
- // there's http://code.google.com/p/chromium/issues/detail?id=24885 on
- // death tests on Windows so we simply don't call it.
test_tab_contents_delegate_->UpdateTargetURL(NULL, GURL());
test_tab_contents_delegate_->MoveContents(NULL, gfx::Rect());
test_tab_contents_delegate_->ToolbarSizeChanged(NULL, false);
diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc
index b747945..d48aaa4 100644
--- a/chrome/browser/external_tab_container_win.cc
+++ b/chrome/browser/external_tab_container_win.cc
@@ -488,10 +488,6 @@ void ExternalTabContainer::MoveContents(TabContents* source,
const gfx::Rect& pos) {
}
-void ExternalTabContainer::URLStarredChanged(TabContents* source,
- bool starred) {
-}
-
void ExternalTabContainer::UpdateTargetURL(TabContents* source,
const GURL& url) {
if (automation_) {
diff --git a/chrome/browser/external_tab_container_win.h b/chrome/browser/external_tab_container_win.h
index 58d656d..bce994d 100644
--- a/chrome/browser/external_tab_container_win.h
+++ b/chrome/browser/external_tab_container_win.h
@@ -126,7 +126,6 @@ class ExternalTabContainer : public TabContentsDelegate,
virtual void LoadingStateChanged(TabContents* source);
virtual void CloseContents(TabContents* source);
virtual void MoveContents(TabContents* source, const gfx::Rect& pos);
- virtual void URLStarredChanged(TabContents* source, bool starred);
virtual void UpdateTargetURL(TabContents* source, const GURL& url);
virtual void ContentsZoomChange(bool zoom_in);
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating);
diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc
index 2bb01a0..95d4364 100644
--- a/chrome/browser/instant/instant_loader.cc
+++ b/chrome/browser/instant/instant_loader.cc
@@ -311,7 +311,6 @@ class InstantLoader::TabContentsDelegateImpl
}
}
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {}
- virtual void URLStarredChanged(TabContents* source, bool starred) {}
virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
virtual bool ShouldSuppressDialogs() {
// Any message shown during instant cancels instant, so we suppress them.
diff --git a/chrome/browser/instant/instant_unload_handler.cc b/chrome/browser/instant/instant_unload_handler.cc
index 811bde2..c58ee98 100644
--- a/chrome/browser/instant/instant_unload_handler.cc
+++ b/chrome/browser/instant/instant_unload_handler.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -69,7 +69,6 @@ class InstantUnloadHandler::TabContentsDelegateImpl
virtual void LoadingStateChanged(TabContents* source) {}
virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {}
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {}
- virtual void URLStarredChanged(TabContents* source, bool starred) {}
virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
private:
diff --git a/chrome/browser/sidebar/sidebar_container.h b/chrome/browser/sidebar/sidebar_container.h
index 2436c10..6b1bbed 100644
--- a/chrome/browser/sidebar/sidebar_container.h
+++ b/chrome/browser/sidebar/sidebar_container.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -112,7 +112,6 @@ class SidebarContainer
virtual void CloseContents(TabContents* source) {}
virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {}
virtual bool IsPopup(const TabContents* source) const;
- virtual void URLStarredChanged(TabContents* source, bool starred) {}
virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {}
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index d14c552..d004ea2 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -16,7 +16,6 @@
#include "chrome/browser/autocomplete_history_manager.h"
#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/blocked_content_container.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/character_encoding.h"
@@ -288,7 +287,6 @@ TabContents::TabContents(Profile* profile,
upload_size_(0),
upload_position_(0),
received_page_title_(false),
- is_starred_(false),
contents_mime_type_(),
encoding_(),
blocked_contents_(NULL),
@@ -338,11 +336,6 @@ TabContents::TabContents(Profile* profile,
pref_change_registrar_.Add(kPrefsToObserve[i], this);
}
- // Register for notifications about URL starredness changing on any profile.
- registrar_.Add(this, NotificationType::URLS_STARRED,
- NotificationService::AllSources());
- registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
- NotificationService::AllSources());
registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
NotificationService::AllSources());
#if defined(OS_LINUX)
@@ -1846,9 +1839,6 @@ void TabContents::DidNavigateMainFramePostCommit(
details.previous_url, details.entry->url()))
CloseConstrainedWindows();
- // Update the starred state.
- UpdateStarredStateForCurrentURL();
-
// Notify observers about navigation.
FOR_EACH_OBSERVER(TabContentsObserver, observers_,
DidNavigateMainFramePostCommit(details, params));
@@ -1884,15 +1874,6 @@ void TabContents::CloseConstrainedWindows() {
}
}
-void TabContents::UpdateStarredStateForCurrentURL() {
- BookmarkModel* model = profile()->GetBookmarkModel();
- const bool old_state = is_starred_;
- is_starred_ = (model && model->IsBookmarked(GetURL()));
-
- if (is_starred_ != old_state && delegate())
- delegate()->URLStarredChanged(this, is_starred_);
-}
-
void TabContents::UpdateAlternateErrorPageURL() {
GURL url = GetAlternateErrorPageURL();
render_view_host()->SetAlternateErrorPageURL(url);
@@ -2977,18 +2958,6 @@ void TabContents::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
switch (type.value) {
- case NotificationType::BOOKMARK_MODEL_LOADED:
- // BookmarkModel finished loading, fall through to update starred state.
- case NotificationType::URLS_STARRED: {
- // Somewhere, a URL has been starred.
- // Ignore notifications for profiles other than our current one.
- Profile* source_profile = Source<Profile>(source).ptr();
- if (!source_profile || !source_profile->IsSameProfile(profile()))
- return;
-
- UpdateStarredStateForCurrentURL();
- break;
- }
case NotificationType::PREF_CHANGED: {
std::string* pref_name_in = Details<std::string>(details).ptr();
DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 20cfe3c..55714db 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -202,7 +202,7 @@ class TabContents : public PageNavigator,
// If an app extension has been explicitly set for this TabContents its icon
// is returned.
//
- // NOTE: the returned icon is larger than 16x16 (it's size is
+ // NOTE: the returned icon is larger than 16x16 (its size is
// Extension::EXTENSION_ICON_SMALLISH).
SkBitmap* GetExtensionAppIcon();
@@ -267,8 +267,6 @@ class TabContents : public PageNavigator,
// "waiting" or "loading."
bool waiting_for_response() const { return waiting_for_response_; }
- bool is_starred() const { return is_starred_; }
-
const std::string& encoding() const { return encoding_; }
void set_encoding(const std::string& encoding);
void reset_encoding() {
@@ -832,10 +830,6 @@ class TabContents : public PageNavigator,
// Closes all constrained windows.
void CloseConstrainedWindows();
- // Updates the starred state from the bookmark bar model. If the state has
- // changed, the delegate is notified.
- void UpdateStarredStateForCurrentURL();
-
// Send the alternate error page URL to the renderer. This method is virtual
// so special html pages can override this (e.g., the new tab page).
virtual void UpdateAlternateErrorPageURL();
@@ -1138,9 +1132,6 @@ class TabContents : public PageNavigator,
// messages.
bool received_page_title_;
- // Whether the current URL is starred
- bool is_starred_;
-
// When a navigation occurs, we record its contents MIME type. It can be
// used to check whether we can do something for some special contents.
std::string contents_mime_type_;
diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h
index 9fb6cc5..1dace53 100644
--- a/chrome/browser/tab_contents/tab_contents_delegate.h
+++ b/chrome/browser/tab_contents/tab_contents_delegate.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -125,9 +125,6 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate {
// part of an animation.
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) = 0;
- // Notification that the starredness of the current URL changed.
- virtual void URLStarredChanged(TabContents* source, bool starred) = 0;
-
// Notification that the target URL has changed.
virtual void UpdateTargetURL(TabContents* source, const GURL& url) = 0;
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 4628f33..92ea737 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -2627,6 +2627,7 @@ bool Browser::LargeIconsPermitted() const {
void Browser::TabInsertedAt(TabContentsWrapper* contents,
int index,
bool foreground) {
+ contents->set_delegate(this);
contents->tab_contents()->set_delegate(this);
contents->controller().SetWindowID(session_id());
@@ -2651,6 +2652,7 @@ void Browser::TabClosingAt(TabStripModel* tab_strip_model,
NotificationService::NoDetails());
// Sever the TabContents' connection back to us.
+ contents->set_delegate(NULL);
contents->tab_contents()->set_delegate(NULL);
}
@@ -2939,11 +2941,6 @@ void Browser::ToolbarSizeChanged(TabContents* source, bool is_animating) {
}
}
-void Browser::URLStarredChanged(TabContents* source, bool starred) {
- if (source == GetSelectedTabContents())
- window_->SetStarredState(starred);
-}
-
void Browser::ContentsMouseEvent(
TabContents* source, const gfx::Point& location, bool motion) {
if (!GetStatusBubble())
@@ -3242,6 +3239,14 @@ void Browser::ContentRestrictionsChanged(TabContents* source) {
}
///////////////////////////////////////////////////////////////////////////////
+// Browser, TabContentsWrapperDelegate implementation:
+
+void Browser::URLStarredChanged(TabContentsWrapper* source, bool starred) {
+ if (source == GetSelectedTabContentsWrapper())
+ window_->SetStarredState(starred);
+}
+
+///////////////////////////////////////////////////////////////////////////////
// Browser, SelectFileDialog::Listener implementation:
void Browser::FileSelected(const FilePath& path, int index, void* params) {
@@ -3626,7 +3631,8 @@ void Browser::InitCommandState() {
void Browser::UpdateCommandsForTabState() {
TabContents* current_tab = GetSelectedTabContents();
- if (!current_tab) // May be NULL during tab restore.
+ TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper();
+ if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore.
return;
// Navigation commands
@@ -3648,7 +3654,7 @@ void Browser::UpdateCommandsForTabState() {
non_app_window && tab_count() > 1);
// Page-related commands
- window_->SetStarredState(current_tab->is_starred());
+ window_->SetStarredState(current_tab_wrapper->is_starred());
command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
browser_defaults::bookmarks_enabled && CanBookmarkAllTabs());
command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
@@ -4150,6 +4156,7 @@ void Browser::TabDetachedAtImpl(TabContentsWrapper* contents, int index,
SyncHistoryWithTabs(0);
}
+ contents->set_delegate(NULL);
contents->tab_contents()->set_delegate(NULL);
RemoveScheduledUpdatesFor(contents->tab_contents());
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index eaa2b57..fb5a153 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -12,6 +12,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/scoped_ptr.h"
#include "base/string16.h"
@@ -29,6 +30,7 @@
#include "chrome/browser/tabs/tab_strip_model_observer.h" // TODO(beng): remove
#include "chrome/browser/tab_contents/page_navigator.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h"
#include "chrome/browser/ui/toolbar/toolbar_model.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/notification_registrar.h"
@@ -55,6 +57,7 @@ class Point;
class Browser : public TabHandlerDelegate,
public TabContentsDelegate,
+ public TabContentsWrapperDelegate,
public PageNavigator,
public CommandUpdater::CommandUpdaterDelegate,
public NotificationObserver,
@@ -761,7 +764,6 @@ class Browser : public TabHandlerDelegate,
virtual bool IsPopup(const TabContents* source) const;
virtual bool CanReloadContents(TabContents* source) const;
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating);
- virtual void URLStarredChanged(TabContents* source, bool starred);
virtual void UpdateTargetURL(TabContents* source, const GURL& url);
virtual void ContentsMouseEvent(
TabContents* source, const gfx::Point& location, bool motion);
@@ -808,6 +810,10 @@ class Browser : public TabHandlerDelegate,
const WebApplicationInfo& app_info);
virtual void ContentRestrictionsChanged(TabContents* source);
+ // Overridden from TabContentsWrapperDelegate:
+ virtual void URLStarredChanged(TabContentsWrapper* source,
+ bool starred) OVERRIDE;
+
// Overridden from SelectFileDialog::Listener:
virtual void FileSelected(const FilePath& path, int index, void* params);
diff --git a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
index ddceec8..e855ef6 100644
--- a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
+++ b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
@@ -179,11 +179,6 @@ void DraggedTabControllerGtk::ToolbarSizeChanged(TabContents* source,
// Dragged tabs don't care about this.
}
-void DraggedTabControllerGtk::URLStarredChanged(TabContents* source,
- bool starred) {
- // Ignored.
-}
-
void DraggedTabControllerGtk::UpdateTargetURL(TabContents* source,
const GURL& url) {
// Ignored.
@@ -217,7 +212,7 @@ void DraggedTabControllerGtk::SetDraggedContents(
NotificationType::TAB_CONTENTS_DESTROYED,
Source<TabContentsWrapper>(dragged_contents_));
if (original_delegate_)
- dragged_contents_->set_delegate(original_delegate_);
+ dragged_contents_->tab_contents()->set_delegate(original_delegate_);
}
original_delegate_ = NULL;
dragged_contents_ = new_contents;
@@ -230,8 +225,8 @@ void DraggedTabControllerGtk::SetDraggedContents(
// otherwise our dragged_contents() may be replaced and subsequently
// collected/destroyed while the drag is in process, leading to
// nasty crashes.
- original_delegate_ = dragged_contents_->delegate();
- dragged_contents_->set_delegate(this);
+ original_delegate_ = dragged_contents_->tab_contents()->delegate();
+ dragged_contents_->tab_contents()->set_delegate(this);
}
}
@@ -378,7 +373,7 @@ void DraggedTabControllerGtk::Attach(TabStripGtk* attached_tabstrip,
// Remove ourselves as the delegate now that the dragged TabContents is
// being inserted back into a Browser.
- dragged_contents_->set_delegate(NULL);
+ dragged_contents_->tab_contents()->set_delegate(NULL);
original_delegate_ = NULL;
// Return the TabContents' to normalcy.
@@ -438,7 +433,7 @@ void DraggedTabControllerGtk::Detach() {
}
// Detaching resets the delegate, but we still want to be the delegate.
- dragged_contents_->set_delegate(this);
+ dragged_contents_->tab_contents()->set_delegate(this);
attached_tabstrip_ = NULL;
}
@@ -580,8 +575,9 @@ bool DraggedTabControllerGtk::EndDragImpl(EndDragType type) {
// If we get here it means the NavigationController is going down. Don't
// attempt to do any cleanup other than resetting the delegate (if we're
// still the delegate).
- if (dragged_contents_ && dragged_contents_->delegate() == this)
- dragged_contents_->set_delegate(NULL);
+ if (dragged_contents_ &&
+ dragged_contents_->tab_contents()->delegate() == this)
+ dragged_contents_->tab_contents()->set_delegate(NULL);
dragged_contents_ = NULL;
} else {
// If we never received a drag-motion event, the drag will never have
@@ -595,14 +591,16 @@ bool DraggedTabControllerGtk::EndDragImpl(EndDragType type) {
}
}
- if (dragged_contents_ && dragged_contents_->delegate() == this)
- dragged_contents_->set_delegate(original_delegate_);
+ if (dragged_contents_ &&
+ dragged_contents_->tab_contents()->delegate() == this)
+ dragged_contents_->tab_contents()->set_delegate(original_delegate_);
}
// The delegate of the dragged contents should have been reset. Unset the
// original delegate so that we don't attempt to reset the delegate when
// deleted.
- DCHECK(!dragged_contents_ || dragged_contents_->delegate() != this);
+ DCHECK(!dragged_contents_ ||
+ dragged_contents_->tab_contents()->delegate() != this);
original_delegate_ = NULL;
// If we're not destroyed now, we'll be destroyed asynchronously later.
diff --git a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h
index cf31d4c..da5212e 100644
--- a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h
+++ b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h
@@ -89,7 +89,6 @@ class DraggedTabControllerGtk : public NotificationObserver,
virtual void MoveContents(TabContents* source, const gfx::Rect& pos);
virtual bool IsPopup(TabContents* source);
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating);
- virtual void URLStarredChanged(TabContents* source, bool starred);
virtual void UpdateTargetURL(TabContents* source, const GURL& url);
// Overridden from NotificationObserver:
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
index 685be27..393f6f0 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
@@ -5,10 +5,14 @@
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "base/lazy_instance.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/password_manager_delegate_impl.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/ui/find_bar/find_manager.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h"
+#include "chrome/common/notification_service.h"
static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> >
g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED);
@@ -17,7 +21,8 @@ static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> >
// TabContentsWrapper, public:
TabContentsWrapper::TabContentsWrapper(TabContents* contents)
- : tab_contents_(contents) {
+ : is_starred_(false),
+ tab_contents_(contents) {
DCHECK(contents);
// Stash this in the property bag so it can be retrieved without having to
// go to a Browser.
@@ -25,11 +30,22 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents)
// Needed so that we initialize the password manager on first navigation.
tab_contents()->AddObserver(this);
+
+ // Register for notifications about URL starredness changing on any profile.
+ registrar_.Add(this, NotificationType::URLS_STARRED,
+ NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
+ NotificationService::AllSources());
}
TabContentsWrapper::~TabContentsWrapper() {
- // Unregister observers (TabContents outlives supporting objects).
- tab_contents()->RemoveObserver(password_manager_.get());
+ // We don't want any notifications while we're running our destructor.
+ registrar_.RemoveAll();
+
+ // Unregister observers.
+ tab_contents()->RemoveObserver(this);
+ if (password_manager_.get())
+ tab_contents()->RemoveObserver(password_manager_.get());
}
PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() {
@@ -79,6 +95,50 @@ FindManager* TabContentsWrapper::GetFindManager() {
// TabContentsWrapper, TabContentsObserver implementation:
void TabContentsWrapper::NavigateToPendingEntry() {
+ // If any page loads, ensure that the password manager is loaded so that forms
+ // get filled out.
GetPasswordManager();
- tab_contents()->RemoveObserver(this);
+}
+
+void TabContentsWrapper::DidNavigateMainFramePostCommit(
+ const NavigationController::LoadCommittedDetails& /*details*/,
+ const ViewHostMsg_FrameNavigate_Params& /*params*/) {
+ UpdateStarredStateForCurrentURL();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TabContentsWrapper, NotificationObserver implementation:
+
+void TabContentsWrapper::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type.value) {
+ case NotificationType::BOOKMARK_MODEL_LOADED:
+ // BookmarkModel finished loading, fall through to update starred state.
+ case NotificationType::URLS_STARRED: {
+ // Somewhere, a URL has been starred.
+ // Ignore notifications for profiles other than our current one.
+ Profile* source_profile = Source<Profile>(source).ptr();
+ if (!source_profile || !source_profile->IsSameProfile(profile()))
+ return;
+
+ UpdateStarredStateForCurrentURL();
+ break;
+ }
+
+ default:
+ NOTREACHED();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Internal helpers
+
+void TabContentsWrapper::UpdateStarredStateForCurrentURL() {
+ BookmarkModel* model = tab_contents()->profile()->GetBookmarkModel();
+ const bool old_state = is_starred_;
+ is_starred_ = (model && model->IsBookmarked(tab_contents()->GetURL()));
+
+ if (is_starred_ != old_state && delegate())
+ delegate()->URLStarredChanged(this, is_starred_);
}
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
index 8ff3bc7..5532730 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
@@ -10,13 +10,14 @@
#include "base/compiler_specific.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_observer.h"
+#include "chrome/common/notification_registrar.h"
class Extension;
class FindManager;
class NavigationController;
class PasswordManager;
class PasswordManagerDelegate;
-class TabContentsDelegate;
+class TabContentsWrapperDelegate;
// Wraps TabContents and all of its supporting objects in order to control
// their ownership and lifetime, while allowing TabContents to remain generic
@@ -24,7 +25,8 @@ class TabContentsDelegate;
// TODO(pinkerton): Eventually, this class will become TabContents as far as
// the browser front-end is concerned, and the current TabContents will be
// renamed to something like WebPage or WebView (ben's suggestions).
-class TabContentsWrapper : public TabContentsObserver {
+class TabContentsWrapper : public NotificationObserver,
+ public TabContentsObserver {
public:
// Takes ownership of |contents|, which must be heap-allocated (as it lives
// in a scoped_ptr) and can not be NULL.
@@ -44,6 +46,9 @@ class TabContentsWrapper : public TabContentsObserver {
static TabContentsWrapper* GetCurrentWrapperForContents(
TabContents* contents);
+ TabContentsWrapperDelegate* delegate() const { return delegate_; }
+ void set_delegate(TabContentsWrapperDelegate* d) { delegate_ = d; }
+
TabContents* tab_contents() const { return tab_contents_.get(); }
NavigationController& controller() const {
return tab_contents()->controller();
@@ -53,8 +58,6 @@ class TabContentsWrapper : public TabContentsObserver {
return tab_contents()->render_view_host();
}
Profile* profile() const { return tab_contents()->profile(); }
- TabContentsDelegate* delegate() const { return tab_contents()->delegate(); }
- void set_delegate(TabContentsDelegate* d) { tab_contents()->set_delegate(d); }
// Convenience methods until extensions are removed from TabContents.
void SetExtensionAppById(const std::string& extension_app_id) {
@@ -65,16 +68,49 @@ class TabContentsWrapper : public TabContentsObserver {
}
bool is_app() const { return tab_contents()->is_app(); }
+ bool is_starred() const { return is_starred_; }
+
// Returns the PasswordManager, creating it if necessary.
PasswordManager* GetPasswordManager();
// Returns the FindManager, creating it if necessary.
FindManager* GetFindManager();
+ // Overrides -----------------------------------------------------------------
+
// TabContentsObserver overrides:
virtual void NavigateToPendingEntry() OVERRIDE;
+ virtual void DidNavigateMainFramePostCommit(
+ const NavigationController::LoadCommittedDetails& details,
+ const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
+
+ // NotificationObserver overrides:
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) OVERRIDE;
private:
+ // Internal helpers ----------------------------------------------------------
+
+ // Updates the starred state from the bookmark bar model. If the state has
+ // changed, the delegate is notified.
+ void UpdateStarredStateForCurrentURL();
+
+ // Data for core operation ---------------------------------------------------
+
+ // Delegate for notifying our owner about stuff. Not owned by us.
+ TabContentsWrapperDelegate* delegate_;
+
+ // Registers and unregisters us for notifications.
+ NotificationRegistrar registrar_;
+
+ // Data for current page -----------------------------------------------------
+
+ // Whether the current URL is starred.
+ bool is_starred_;
+
+ // Supporting objects --------------------------------------------------------
+
// PasswordManager and its delegate, lazily created. The delegate must
// outlive the manager, per documentation in password_manager.h.
scoped_ptr<PasswordManagerDelegate> password_manager_delegate_;
@@ -83,6 +119,8 @@ class TabContentsWrapper : public TabContentsObserver {
// FindManager, lazily created.
scoped_ptr<FindManager> find_manager_;
+ // TabContents (MUST BE LAST) ------------------------------------------------
+
// The supporting objects need to outlive the TabContents dtor (as they may
// be called upon during its execution). As a result, this must come last
// in the list.
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.cc
new file mode 100644
index 0000000..61a2718
--- /dev/null
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.cc
@@ -0,0 +1,8 @@
+// Copyright (c) 2011 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/ui/tab_contents/tab_contents_wrapper_delegate.h"
+
+TabContentsWrapperDelegate::~TabContentsWrapperDelegate() {
+}
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h
new file mode 100644
index 0000000..14cdc2ff
--- /dev/null
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h
@@ -0,0 +1,22 @@
+// Copyright (c) 2011 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_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_DELEGATE_H_
+#define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_DELEGATE_H_
+#pragma once
+
+class TabContentsWrapper;
+
+// Objects implement this interface to get notified about changes in the
+// TabContentsWrapper and to provide necessary functionality.
+class TabContentsWrapperDelegate {
+ public:
+ // Notification that the starredness of the current URL changed.
+ virtual void URLStarredChanged(TabContentsWrapper* source, bool starred) = 0;
+
+ protected:
+ virtual ~TabContentsWrapperDelegate();
+};
+
+#endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_DELEGATE_H_
diff --git a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc
index 611cee3..44105de 100644
--- a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc
+++ b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc
@@ -460,11 +460,6 @@ void DraggedTabController::ToolbarSizeChanged(TabContents* source,
// Dragged tabs don't care about this.
}
-void DraggedTabController::URLStarredChanged(TabContents* source,
- bool starred) {
- // Ignored.
-}
-
void DraggedTabController::UpdateTargetURL(TabContents* source,
const GURL& url) {
// Ignored.
@@ -601,7 +596,7 @@ void DraggedTabController::SetDraggedContents(
NotificationType::TAB_CONTENTS_DESTROYED,
Source<TabContents>(dragged_contents_->tab_contents()));
if (original_delegate_)
- dragged_contents_->set_delegate(original_delegate_);
+ dragged_contents_->tab_contents()->set_delegate(original_delegate_);
}
original_delegate_ = NULL;
dragged_contents_ = new_contents;
@@ -614,8 +609,8 @@ void DraggedTabController::SetDraggedContents(
// otherwise our dragged_contents() may be replaced and subsequently
// collected/destroyed while the drag is in process, leading to
// nasty crashes.
- original_delegate_ = dragged_contents_->delegate();
- dragged_contents_->set_delegate(this);
+ original_delegate_ = dragged_contents_->tab_contents()->delegate();
+ dragged_contents_->tab_contents()->set_delegate(this);
}
}
@@ -847,7 +842,7 @@ void DraggedTabController::Attach(BaseTabStrip* attached_tabstrip,
// Remove ourselves as the delegate now that the dragged TabContents is
// being inserted back into a Browser.
- dragged_contents_->set_delegate(NULL);
+ dragged_contents_->tab_contents()->set_delegate(NULL);
original_delegate_ = NULL;
// Return the TabContents' to normalcy.
@@ -920,7 +915,7 @@ void DraggedTabController::Detach() {
view_->SetTabWidthAndUpdate(attached_tab_width, photobooth_.get());
// Detaching resets the delegate, but we still want to be the delegate.
- dragged_contents_->set_delegate(this);
+ dragged_contents_->tab_contents()->set_delegate(this);
attached_tabstrip_ = NULL;
}
@@ -1087,21 +1082,24 @@ void DraggedTabController::EndDragImpl(EndDragType type) {
else
CompleteDrag();
}
- if (dragged_contents_ && dragged_contents_->delegate() == this)
- dragged_contents_->set_delegate(original_delegate_);
+ if (dragged_contents_ &&
+ dragged_contents_->tab_contents()->delegate() == this)
+ dragged_contents_->tab_contents()->set_delegate(original_delegate_);
} else {
// If we get here it means the NavigationController is going down. Don't
// attempt to do any cleanup other than resetting the delegate (if we're
// still the delegate).
- if (dragged_contents_ && dragged_contents_->delegate() == this)
- dragged_contents_->set_delegate(NULL);
+ if (dragged_contents_ &&
+ dragged_contents_->tab_contents()->delegate() == this)
+ dragged_contents_->tab_contents()->set_delegate(NULL);
dragged_contents_ = NULL;
}
// The delegate of the dragged contents should have been reset. Unset the
// original delegate so that we don't attempt to reset the delegate when
// deleted.
- DCHECK(!dragged_contents_ || dragged_contents_->delegate() != this);
+ DCHECK(!dragged_contents_ ||
+ dragged_contents_->tab_contents()->delegate() != this);
original_delegate_ = NULL;
source_tabstrip_->DestroyDragController();
diff --git a/chrome/browser/ui/views/tabs/dragged_tab_controller.h b/chrome/browser/ui/views/tabs/dragged_tab_controller.h
index 78481ae..c4e0498 100644
--- a/chrome/browser/ui/views/tabs/dragged_tab_controller.h
+++ b/chrome/browser/ui/views/tabs/dragged_tab_controller.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -110,7 +110,6 @@ class DraggedTabController : public TabContentsDelegate,
virtual void CloseContents(TabContents* source);
virtual void MoveContents(TabContents* source, const gfx::Rect& pos);
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating);
- virtual void URLStarredChanged(TabContents* source, bool starred);
virtual void UpdateTargetURL(TabContents* source, const GURL& url);
// Overridden from NotificationObserver:
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 8d11cc6..4256e0c 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -3135,6 +3135,8 @@
'browser/ui/status_bubble.h',
'browser/ui/tab_contents/tab_contents_wrapper.cc',
'browser/ui/tab_contents/tab_contents_wrapper.h',
+ 'browser/ui/tab_contents/tab_contents_wrapper_delegate.cc',
+ 'browser/ui/tab_contents/tab_contents_wrapper_delegate.h',
'browser/ui/tabs/dock_info.cc',
'browser/ui/tabs/dock_info.h',
'browser/ui/tabs/dock_info_gtk.cc',