Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3279)

Unified Diff: chrome/browser/views/bookmark_bar_view.cc

Issue 39285: Support loading extensions into the bookmark toolbar. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/views/bookmark_bar_view.h ('k') | chrome/test/data/extensions/good/extension1/1/index.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/views/bookmark_bar_view.cc
===================================================================
--- chrome/browser/views/bookmark_bar_view.cc (revision 11270)
+++ chrome/browser/views/bookmark_bar_view.cc (working copy)
@@ -16,6 +16,9 @@
#include "chrome/browser/browser_window.h"
#include "chrome/browser/drag_utils.h"
#include "chrome/browser/download/download_util.h"
+#include "chrome/browser/extensions/extension.h"
+#include "chrome/browser/extensions/extension_view.h"
+#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
@@ -315,6 +318,37 @@
DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton);
};
+// ExtensionToolstrip -------------------------------------------------------
+
+// A simple container with a border for an ExtensionView.
+class ExtensionToolstrip : public views::View {
+ public:
+ static const int kPadding = 2;
+
+ ExtensionToolstrip(const GURL& url, Profile* profile)
+ : view_(new ExtensionView(url, profile)) {
+ AddChildView(view_);
+ set_border(views::Border::CreateEmptyBorder(
+ kPadding, kPadding, kPadding, kPadding));
+ }
+
+ virtual gfx::Size GetPreferredSize() {
+ gfx::Size size = view_->GetPreferredSize();
+ size.Enlarge(kPadding*2, kPadding*2);
+ return size;
+ }
+
+ virtual void DidChangeBounds(const gfx::Rect& previous,
+ const gfx::Rect& current) {
+ view_->SetBounds(GetLocalBounds(false));
+ }
+
+ private:
+ ExtensionView* view_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionToolstrip);
+};
+
// DropInfo -------------------------------------------------------------------
// Tracks drops on the BookmarkBarView.
@@ -689,7 +723,8 @@
overflow_button_(NULL),
instructions_(NULL),
bookmarks_separator_view_(NULL),
- throbbing_view_(NULL) {
+ throbbing_view_(NULL),
+ num_extension_toolstrips_(0) {
SetID(VIEW_ID_BOOKMARK_BAR);
Init();
SetProfile(profile);
@@ -720,8 +755,9 @@
// Cancels the current cancelable.
NotifyModelChanged();
- // Remove the current buttons.
- for (int i = GetBookmarkButtonCount() - 1; i >= 0; --i) {
+ // Remove the current buttons and extension toolstrips.
+ for (int i = GetBookmarkButtonCount() + num_extension_toolstrips_ - 1;
+ i >= 0; --i) {
View* child = GetChildViewAt(i);
RemoveChildView(child);
delete child;
@@ -742,6 +778,8 @@
ns->AddObserver(this, NotificationType::BOOKMARK_BUBBLE_HIDDEN, ns_source);
ns->AddObserver(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
NotificationService::AllSources());
+ ns->AddObserver(this, NotificationType::EXTENSIONS_LOADED,
+ NotificationService::AllSources());
model_ = profile_->GetBookmarkModel();
model_->AddObserver(this);
@@ -835,6 +873,17 @@
}
}
+ // Extension toolstrips.
+ for (int i = GetBookmarkButtonCount();
+ i < GetBookmarkButtonCount() + num_extension_toolstrips_; ++i) {
+ views::View* child = GetChildViewAt(i);
+ gfx::Size pref = child->GetPreferredSize();
+ int next_x = x + pref.width() + kButtonPadding;
+ child->SetVisible(next_x < max_x);
+ child->SetBounds(x, y, pref.width(), height);
+ x = next_x;
+ }
+
// Layout the right side of the bar.
const bool all_visible =
(GetBookmarkButtonCount() == 0 ||
@@ -1218,10 +1267,10 @@
}
int BookmarkBarView::GetBookmarkButtonCount() {
- // We contain four non-bookmark button views: recently bookmarked,
- // bookmarks separator, chevrons (for overflow) and the instruction
- // label.
- return GetChildViewCount() - 4;
+ // We contain at least four non-bookmark button views: recently bookmarked,
+ // bookmarks separator, chevrons (for overflow), the instruction
+ // label, as well as any ExtensionViews displaying toolstrips.
+ return GetChildViewCount() - 4 - num_extension_toolstrips_;
}
void BookmarkBarView::Loaded(BookmarkModel* model) {
@@ -1231,6 +1280,9 @@
for (int i = 0; i < node->GetChildCount(); ++i)
AddChildView(i, CreateBookmarkButton(node->GetChild(i)));
other_bookmarked_button_->SetEnabled(true);
+
+ AddExtensionToolstrips(profile_->GetExtensionsService()->extensions());
+
Layout();
SchedulePaint();
}
@@ -1582,9 +1634,35 @@
StopThrobbing(false);
bubble_url_ = GURL();
break;
+
+ case NotificationType::EXTENSIONS_LOADED: {
+ const ExtensionList* extensions = Details<ExtensionList>(details).ptr();
+ if (AddExtensionToolstrips(extensions)) {
+ Layout();
+ SchedulePaint();
+ }
+ break;
+ }
}
}
+bool BookmarkBarView::AddExtensionToolstrips(const ExtensionList* extensions) {
+ bool added_toolstrip = false;
+ for (ExtensionList::const_iterator extension = extensions->begin();
+ extension != extensions->end(); ++extension) {
+ if (!(*extension)->toolstrip_url().is_empty()) {
+ ExtensionToolstrip* view =
+ new ExtensionToolstrip((*extension)->toolstrip_url(), profile_);
+ int index = GetBookmarkButtonCount() + num_extension_toolstrips_;
+ AddChildView(index, view);
+ added_toolstrip = true;
+ ++num_extension_toolstrips_;
+ }
+ }
+
+ return added_toolstrip;
+}
+
void BookmarkBarView::RemoveNotificationObservers() {
NotificationService* ns = NotificationService::current();
Source<Profile> ns_source(profile_->GetOriginalProfile());
@@ -1593,6 +1671,8 @@
ns->RemoveObserver(this,
NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
NotificationService::AllSources());
+ ns->RemoveObserver(this, NotificationType::EXTENSIONS_LOADED,
+ NotificationService::AllSources());
}
void BookmarkBarView::NotifyModelChanged() {
« no previous file with comments | « chrome/browser/views/bookmark_bar_view.h ('k') | chrome/test/data/extensions/good/extension1/1/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698