summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-26 00:11:42 +0000
committererikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-26 00:11:42 +0000
commitbbc94554729407f821d4a60828c5758a112f042a (patch)
treefa92103aa16e6ff04e90206c6ac99710c3c2d7ca
parent4289d9b66a1453aad1115f6ede0007faab22d6d4 (diff)
downloadchromium_src-bbc94554729407f821d4a60828c5758a112f042a.zip
chromium_src-bbc94554729407f821d4a60828c5758a112f042a.tar.gz
chromium_src-bbc94554729407f821d4a60828c5758a112f042a.tar.bz2
add mole info to toolstrip definition and enable moles
Review URL: http://codereview.chromium.org/159202 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21621 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_host.cc54
-rw-r--r--chrome/browser/extensions/extension_host.h5
-rw-r--r--chrome/browser/extensions/extension_shelf_model.cc52
-rw-r--r--chrome/browser/extensions/extension_shelf_model.h16
-rw-r--r--chrome/browser/extensions/extensions_service_unittest.cc9
-rw-r--r--chrome/browser/views/browser_bubble.cc6
-rw-r--r--chrome/browser/views/browser_bubble.h7
-rw-r--r--chrome/browser/views/extensions/extension_shelf.cc100
-rw-r--r--chrome/browser/views/extensions/extension_view.cc9
-rw-r--r--chrome/browser/views/extensions/extension_view.h6
-rw-r--r--chrome/browser/views/frame/browser_view.cc9
-rw-r--r--chrome/common/extensions/extension.cc38
-rw-r--r--chrome/common/extensions/extension.h15
-rw-r--r--chrome/common/extensions/extension_constants.cc2
-rw-r--r--chrome/common/extensions/extension_constants.h2
-rw-r--r--chrome/common/notification_type.h4
-rw-r--r--chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/manifest.json6
17 files changed, 242 insertions, 98 deletions
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc
index 21acf4f..276a432 100644
--- a/chrome/browser/extensions/extension_host.cc
+++ b/chrome/browser/extensions/extension_host.cc
@@ -25,6 +25,7 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
+#include "chrome/common/render_messages.h"
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
@@ -139,6 +140,11 @@ void ExtensionHost::CreateRenderView(RenderWidgetHostView* host_view) {
Details<ExtensionHost>(this));
}
+void ExtensionHost::NavigateToURL(const GURL& url) {
+ url_ = url;
+ render_view_host_->NavigateToURL(url_);
+}
+
void ExtensionHost::RecoverCrashedExtension() {
DCHECK(!IsRenderViewLive());
#if defined(TOOLKIT_VIEWS)
@@ -177,13 +183,41 @@ void ExtensionHost::RenderViewGone(RenderViewHost* render_view_host) {
Details<ExtensionHost>(this));
}
+void ExtensionHost::DidNavigate(RenderViewHost* render_view_host,
+ const ViewHostMsg_FrameNavigate_Params& params) {
+ // We only care when the outer frame changes.
+ switch (params.transition) {
+ case PageTransition::AUTO_SUBFRAME:
+ case PageTransition::MANUAL_SUBFRAME:
+ return;
+ }
+
+ url_ = params.url;
+ extension_function_dispatcher_.reset(
+ new ExtensionFunctionDispatcher(render_view_host_, this, url_));
+}
+
void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) {
- // TODO(aa): This is toolstrip-specific and should probably not be here.
- // ExtensionToolstrip in bookmark_bar_view.cc?
- static const StringPiece toolstrip_css(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_EXTENSIONS_TOOLSTRIP_CSS));
- render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string());
+#if defined(TOOLKIT_VIEWS)
+ ExtensionView* view = view_.get();
+ if (view) {
+ // TODO(erikkay) this injection should really happen in the renderer.
+ // When the Jerry's view type change lands, investigate moving this there.
+
+ // As a toolstrip, inject our toolstrip CSS to make it easier for toolstrips
+ // to blend in with the chrome UI.
+ if (view->is_toolstrip()) {
+ static const StringPiece toolstrip_css(
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_EXTENSIONS_TOOLSTRIP_CSS));
+ render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string());
+ } else {
+ // No CSS injecting currently, but call SetDidInsertCSS to tell the view
+ // that it's OK to display.
+ view->SetDidInsertCSS(true);
+ }
+ }
+#endif
did_stop_loading_ = true;
}
@@ -222,11 +256,6 @@ void ExtensionHost::DidInsertCSS() {
}
RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() {
- // TODO(erikkay) this is unfortunate. The interface declares that this method
- // must be const (no good reason for it as far as I can tell) which means you
- // can't return self without doing this const_cast. Either we need to change
- // the interface, or we need to split out the view delegate into another
- // object (which is how TabContents works).
return this;
}
@@ -253,7 +282,6 @@ void ExtensionHost::ShowCreatedWindow(int route_id,
DCHECK(browser);
if (!browser)
return;
- // TODO(erikkay) is it safe to pass in NULL as source?
browser->AddTabContents(contents, disposition, initial_pos,
user_gesture);
}
@@ -324,6 +352,4 @@ Browser* ExtensionHost::GetBrowser() {
}
void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) {
- extension_function_dispatcher_.reset(
- new ExtensionFunctionDispatcher(render_view_host_, this, url_));
}
diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h
index e94648a..66290e3 100644
--- a/chrome/browser/extensions/extension_host.h
+++ b/chrome/browser/extensions/extension_host.h
@@ -61,6 +61,9 @@ class ExtensionHost : public RenderViewHostDelegate,
// NULL).
void CreateRenderView(RenderWidgetHostView* host_view);
+ // Sets |url_| and navigates |render_view_host_|.
+ void NavigateToURL(const GURL& url);
+
// Restarts extension's renderer process. Can be called only if the renderer
// process crashed.
void RecoverCrashedExtension();
@@ -70,6 +73,8 @@ class ExtensionHost : public RenderViewHostDelegate,
virtual const GURL& GetURL() const { return url_; }
virtual void RenderViewCreated(RenderViewHost* render_view_host);
virtual void RenderViewGone(RenderViewHost* render_view_host);
+ virtual void DidNavigate(RenderViewHost* render_view_host,
+ const ViewHostMsg_FrameNavigate_Params& params);
virtual void DidStopLoading(RenderViewHost* render_view_host);
virtual WebPreferences GetWebkitPrefs();
virtual void ProcessDOMUIMessage(const std::string& message,
diff --git a/chrome/browser/extensions/extension_shelf_model.cc b/chrome/browser/extensions/extension_shelf_model.cc
index 05f848a..1449d97 100644
--- a/chrome/browser/extensions/extension_shelf_model.cc
+++ b/chrome/browser/extensions/extension_shelf_model.cc
@@ -42,7 +42,9 @@ ExtensionShelfModel::~ExtensionShelfModel() {
while (observers_.size())
observers_.RemoveObserver(observers_.GetElementAt(0));
- STLDeleteContainerPairFirstPointers(toolstrips_.begin(), toolstrips_.end());
+ ExtensionToolstrips::iterator t;
+ for (t = toolstrips_.begin(); t != toolstrips_.end(); ++t)
+ delete t->host;
toolstrips_.clear();
}
@@ -55,27 +57,25 @@ void ExtensionShelfModel::RemoveObserver(
observers_.RemoveObserver(observer);
}
-void ExtensionShelfModel::AppendToolstrip(ExtensionHost* toolstrip) {
- InsertToolstripAt(count(), toolstrip, NULL);
+void ExtensionShelfModel::AppendToolstrip(const ToolstripItem& toolstrip) {
+ InsertToolstripAt(count(), toolstrip);
}
void ExtensionShelfModel::InsertToolstripAt(int index,
- ExtensionHost* toolstrip,
- void* data) {
- toolstrips_.insert(toolstrips_.begin() + index,
- ToolstripItem(toolstrip, data));
+ const ToolstripItem& toolstrip) {
+ toolstrips_.insert(toolstrips_.begin() + index, toolstrip);
if (ready_) {
FOR_EACH_OBSERVER(ExtensionShelfModelObserver, observers_,
- ToolstripInsertedAt(toolstrip, index));
+ ToolstripInsertedAt(toolstrip.host, index));
}
}
void ExtensionShelfModel::RemoveToolstripAt(int index) {
- ExtensionHost* toolstrip = ToolstripAt(index);
+ ExtensionHost* host = ToolstripAt(index);
FOR_EACH_OBSERVER(ExtensionShelfModelObserver, observers_,
- ToolstripRemovingAt(toolstrip, index));
+ ToolstripRemovingAt(host, index));
toolstrips_.erase(toolstrips_.begin() + index);
- delete toolstrip;
+ delete host;
}
void ExtensionShelfModel::MoveToolstripAt(int index, int to_index) {
@@ -89,7 +89,7 @@ void ExtensionShelfModel::MoveToolstripAt(int index, int to_index) {
toolstrips_.insert(toolstrips_.begin() + to_index, toolstrip);
FOR_EACH_OBSERVER(ExtensionShelfModelObserver, observers_,
- ToolstripMoved(toolstrip.first, index, to_index));
+ ToolstripMoved(toolstrip.host, index, to_index));
UpdatePrefs();
}
@@ -97,7 +97,7 @@ void ExtensionShelfModel::MoveToolstripAt(int index, int to_index) {
int ExtensionShelfModel::IndexOfToolstrip(ExtensionHost* toolstrip) {
ExtensionToolstrips::iterator i;
for (i = toolstrips_.begin(); i != toolstrips_.end(); ++i) {
- if (i->first == toolstrip)
+ if (i->host == toolstrip)
return i - toolstrips_.begin();
}
return -1;
@@ -105,17 +105,22 @@ int ExtensionShelfModel::IndexOfToolstrip(ExtensionHost* toolstrip) {
ExtensionHost* ExtensionShelfModel::ToolstripAt(int index) {
DCHECK(index >= 0);
- return toolstrips_[index].first;
+ return toolstrips_[index].host;
+}
+
+Extension::ToolstripInfo& ExtensionShelfModel::ToolstripInfoAt(int index) {
+ DCHECK(index >= 0);
+ return toolstrips_[index].info;
}
void* ExtensionShelfModel::ToolstripDataAt(int index) {
DCHECK(index >= 0);
- return toolstrips_[index].second;
+ return toolstrips_[index].data;
}
void ExtensionShelfModel::SetToolstripDataAt(int index, void* data) {
DCHECK(index >= 0);
- toolstrips_[index].second = data;
+ toolstrips_[index].data = data;
}
void ExtensionShelfModel::Observe(NotificationType type,
@@ -154,12 +159,15 @@ void ExtensionShelfModel::AddExtension(Extension* extension) {
if (!manager)
return;
- for (std::vector<std::string>::const_iterator toolstrip_path =
+ for (std::vector<Extension::ToolstripInfo>::const_iterator toolstrip =
extension->toolstrips().begin();
- toolstrip_path != extension->toolstrips().end(); ++toolstrip_path) {
- GURL url = extension->GetResourceURL(*toolstrip_path);
- ExtensionHost* host = manager->CreateView(extension, url, browser_);
- AppendToolstrip(host);
+ toolstrip != extension->toolstrips().end(); ++toolstrip) {
+ GURL url = toolstrip->toolstrip;
+ ToolstripItem item;
+ item.host = manager->CreateView(extension, url, browser_);
+ item.info = *toolstrip;
+ item.data = NULL;
+ AppendToolstrip(item);
}
}
@@ -215,7 +223,7 @@ void ExtensionShelfModel::SortToolstrips() {
GURL& url = urls[i];
for (ExtensionToolstrips::iterator toolstrip = copy.begin();
toolstrip != copy.end(); ++toolstrip) {
- if (url == (*toolstrip).first->GetURL()) {
+ if (url == toolstrip->host->GetURL()) {
// Note that it's technically possible for the same URL to appear in
// multiple toolstrips, so we don't do any testing for uniqueness.
toolstrips_.push_back(*toolstrip);
diff --git a/chrome/browser/extensions/extension_shelf_model.h b/chrome/browser/extensions/extension_shelf_model.h
index ab2af06..28fb00b 100644
--- a/chrome/browser/extensions/extension_shelf_model.h
+++ b/chrome/browser/extensions/extension_shelf_model.h
@@ -56,6 +56,12 @@ class ExtensionShelfModel : public NotificationObserver {
ExtensionShelfModel(Browser* browser);
virtual ~ExtensionShelfModel();
+ struct ToolstripItem {
+ ExtensionHost* host;
+ Extension::ToolstripInfo info;
+ void* data;
+ };
+
// Add and remove observers to changes within this ExtensionShelfModel.
void AddObserver(ExtensionShelfModelObserver* observer);
void RemoveObserver(ExtensionShelfModelObserver* observer);
@@ -65,10 +71,10 @@ class ExtensionShelfModel : public NotificationObserver {
bool empty() const { return toolstrips_.empty(); }
// Add |toolstrip| to the end of the shelf.
- void AppendToolstrip(ExtensionHost* toolstrip);
+ void AppendToolstrip(const ToolstripItem& toolstrip);
// Insert |toolstrip| and |data| at |index|.
- void InsertToolstripAt(int index, ExtensionHost* toolstrip, void* data);
+ void InsertToolstripAt(int index, const ToolstripItem& toolstrip);
// Remove the toolstrip at |index|.
void RemoveToolstripAt(int index);
@@ -79,9 +85,12 @@ class ExtensionShelfModel : public NotificationObserver {
// Lookup the index of |toolstrip|. Returns -1 if not present.
int IndexOfToolstrip(ExtensionHost* toolstrip);
- // Return the toolstrip at |index|. Returns NULL if index is out of range.
+ // Return the toolstrip at |index|.
ExtensionHost* ToolstripAt(int index);
+ // Return the ToolstripInfo at |index|.
+ Extension::ToolstripInfo& ToolstripInfoAt(int index);
+
// Get/Set some arbitrary data associated with a particular toolstrip.
void SetToolstripDataAt(int index, void* data);
void* ToolstripDataAt(int index);
@@ -117,7 +126,6 @@ class ExtensionShelfModel : public NotificationObserver {
NotificationRegistrar registrar_;
// The Toolstrips loaded in this model. The model owns these objects.
- typedef std::pair<ExtensionHost*, void*> ToolstripItem;
typedef std::vector<ToolstripItem> ExtensionToolstrips;
ExtensionToolstrips toolstrips_;
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index 57799fa..99e43ea 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -531,7 +531,8 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) {
Extension* extension = loaded_[0];
const UserScriptList& scripts = extension->content_scripts();
- const std::vector<std::string>& toolstrips = extension->toolstrips();
+ const std::vector<Extension::ToolstripInfo>& toolstrips =
+ extension->toolstrips();
ASSERT_EQ(2u, scripts.size());
EXPECT_EQ(3u, scripts[0].url_patterns().size());
EXPECT_EQ("file://*",
@@ -561,8 +562,10 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) {
EXPECT_EQ("http://*.google.com/*", permissions[0].GetAsString());
EXPECT_EQ("https://*.google.com/*", permissions[1].GetAsString());
ASSERT_EQ(2u, toolstrips.size());
- EXPECT_EQ("toolstrip1.html", toolstrips[0]);
- EXPECT_EQ("toolstrip2.html", toolstrips[1]);
+ EXPECT_EQ(extension->GetResourceURL("toolstrip1.html"),
+ toolstrips[0].toolstrip);
+ EXPECT_EQ(extension->GetResourceURL("toolstrip2.html"),
+ toolstrips[1].toolstrip);
EXPECT_EQ(std::string(good1), loaded_[1]->id());
EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name());
diff --git a/chrome/browser/views/browser_bubble.cc b/chrome/browser/views/browser_bubble.cc
index 15c45a6..de6959b 100644
--- a/chrome/browser/views/browser_bubble.cc
+++ b/chrome/browser/views/browser_bubble.cc
@@ -62,11 +62,13 @@ void BrowserBubble::BrowserWindowMoved() {
delegate_->BubbleBrowserWindowMoved(this);
else
Hide();
+ if (visible_)
+ Reposition();
}
-void BrowserBubble::BrowserWindowClosed() {
+void BrowserBubble::BrowserWindowClosing() {
if (delegate_)
- delegate_->BubbleBrowserWindowClosed(this);
+ delegate_->BubbleBrowserWindowClosing(this);
else
Hide();
}
diff --git a/chrome/browser/views/browser_bubble.h b/chrome/browser/views/browser_bubble.h
index 13317f55..03e9377 100644
--- a/chrome/browser/views/browser_bubble.h
+++ b/chrome/browser/views/browser_bubble.h
@@ -20,7 +20,10 @@ class BrowserBubble {
public:
// Called when the Browser Window that this bubble is attached to moves.
virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble) = 0;
- virtual void BubbleBrowserWindowClosed(BrowserBubble* bubble) = 0;
+
+ // Called with the Browser Window that this bubble is attached to is
+ // about to close.
+ virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble) = 0;
};
// Note that the bubble will size itself to the preferred size of |view|.
@@ -48,7 +51,7 @@ class BrowserBubble {
// Notifications from BrowserView.
// With no delegate, both of these default to Hiding the bubble.
virtual void BrowserWindowMoved();
- virtual void BrowserWindowClosed();
+ virtual void BrowserWindowClosing();
// Show or hide the bubble.
void Show();
diff --git a/chrome/browser/views/extensions/extension_shelf.cc b/chrome/browser/views/extensions/extension_shelf.cc
index 121ac79..77df55a 100644
--- a/chrome/browser/views/extensions/extension_shelf.cc
+++ b/chrome/browser/views/extensions/extension_shelf.cc
@@ -41,6 +41,9 @@ static const int kToolstripDividerWidth = 2;
// Preferred height of the ExtensionShelf.
static const int kShelfHeight = 29;
+// Height of the toolstrip within the shelf.
+static const int kToolstripHeight = kShelfHeight - (kTopMargin + kBottomMargin);
+
// Colors for the ExtensionShelf.
static const SkColor kBackgroundColor = SkColorSetRGB(230, 237, 244);
static const SkColor kBorderColor = SkColorSetRGB(201, 212, 225);
@@ -69,14 +72,19 @@ static const int kHideDelayMs = 500;
// is being dragged or moved.
// TODO(erikkay) this should draw a dimmed out version of the toolstrip.
class ExtensionShelf::PlaceholderView : public views::View {
-public:
+ public:
PlaceholderView() {}
+ void SetWidth(int width) {
+ SetBounds(x(), y(), width, height());
+ PreferredSizeChanged();
+ }
+
// ExtensionShelf resizes its views to their preferred size at layout,
// so just always prefer the current size.
gfx::Size GetPreferredSize() { return size(); }
-private:
+ private:
DISALLOW_COPY_AND_ASSIGN(PlaceholderView);
};
@@ -86,7 +94,8 @@ private:
class ExtensionShelf::Toolstrip : public views::View,
public BrowserBubble::Delegate {
public:
- Toolstrip(ExtensionShelf* shelf, ExtensionHost* host);
+ Toolstrip(ExtensionShelf* shelf, ExtensionHost* host,
+ const Extension::ToolstripInfo& info);
virtual ~Toolstrip();
// View
@@ -146,12 +155,15 @@ class ExtensionShelf::Toolstrip : public views::View,
// BrowserBubble::Delegate
virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble);
- virtual void BubbleBrowserWindowClosed(BrowserBubble* bubble);
+ virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble);
private:
// The actual renderer that this toolstrip contains.
ExtensionHost* host_;
+ // Manifest definition of this toolstrip.
+ Extension::ToolstripInfo info_;
+
// The handle is a BrowserBubble so that it can exist as an independent,
// floating window. It also acts as the container for the ExtensionView when
// it's being dragged.
@@ -184,8 +196,10 @@ class ExtensionShelf::Toolstrip : public views::View,
};
ExtensionShelf::Toolstrip::Toolstrip(ExtensionShelf* shelf,
- ExtensionHost* host)
+ ExtensionHost* host,
+ const Extension::ToolstripInfo& info)
: host_(host),
+ info_(info),
shelf_(shelf),
placeholder_view_(NULL),
dragging_(false),
@@ -239,21 +253,13 @@ void ExtensionShelf::Toolstrip::Paint(gfx::Canvas* canvas) {
gfx::Size ExtensionShelf::Toolstrip::GetPreferredSize() {
gfx::Size sz = title_->GetPreferredSize();
- int width = std::max(view()->width() + 2, sz.width());
- sz.set_width(width);
- sz.Enlarge(kHandlePadding * 2, kHandlePadding * 2);
- if (dragging_) {
+ sz.set_width(std::max(view()->width(), sz.width()));
+ if (!expanded_) {
+ sz.Enlarge(2 + kHandlePadding * 2, kHandlePadding * 2);
+ }
+ if (dragging_ || expanded_) {
gfx::Size extension_size = view()->GetPreferredSize();
sz.Enlarge(0, extension_size.height() + 2);
- } else if (expanded_) {
- // TODO(erikkay) these sizes are a temporary hack until we can get the
- // size from the extension itself.
- const int tempHeight = 200;
- const int tempWidth = 400;
- int width = std::max(sz.width(), tempWidth);
- sz.set_width(width);
- gfx::Size extension_size = view()->GetPreferredSize();
- sz.Enlarge(0, extension_size.height() + 2 + tempHeight);
}
return sz;
}
@@ -315,7 +321,9 @@ bool ExtensionShelf::Toolstrip::OnMouseDragged(const views::MouseEvent& event) {
void ExtensionShelf::Toolstrip::OnMouseReleased(const views::MouseEvent& event,
bool canceled) {
+ StopHandleTimer();
if (dragging_) {
+ // Drop the toolstrip roughly where it is now.
views::View::OnMouseReleased(event, canceled);
dragging_ = false;
// |this| and |shelf_| are in different view hierarchies, so we need to
@@ -325,18 +333,33 @@ void ExtensionShelf::Toolstrip::OnMouseReleased(const views::MouseEvent& event,
View::ConvertPointToView(NULL, shelf_, &loc);
shelf_->DropExtension(this, loc, canceled);
AttachToShelf(true);
- } else {
-#if 0
- // TODO(erikkay) implementation currently in progress
+ } else if (!canceled &&
+ info_.mole.is_valid() && info_.toolstrip.is_valid()) {
+ // Toggle mole to either expanded or collapsed.
expanded_ = !expanded_;
+ view()->set_is_toolstrip(!expanded_);
if (expanded_) {
+ host_->NavigateToURL(info_.mole);
StopHandleTimer();
DetachFromShelf(false);
+
+ gfx::Size extension_size = view()->GetPreferredSize();
+ extension_size.set_height(info_.mole_height);
+ view()->SetPreferredSize(extension_size);
LayoutHandle();
} else {
+ gfx::Size extension_size = view()->GetPreferredSize();
+ extension_size.set_height(kToolstripHeight);
+ view()->SetPreferredSize(extension_size);
+
+ host_->NavigateToURL(info_.toolstrip);
AttachToShelf(false);
}
-#endif
+
+ // This is to prevent flickering as the page loads and lays out.
+ // Once the navigation is finished, ExtensionView will wind up setting
+ // visibility to true.
+ view()->SetVisible(false);
}
}
@@ -357,7 +380,7 @@ void ExtensionShelf::Toolstrip::LayoutHandle() {
int handle_width = std::max(view()->width(), width());
gfx::Point origin(-kToolstripPadding, -(height() + kToolstripPadding - 1));
if (expanded_) {
- origin.set_y(-(height() + kToolstripPadding - 1));
+ origin.set_y(GetShelfView()->height() - height());
views::View::ConvertPointToView(GetShelfView(), shelf_->GetRootView(),
&origin);
} else {
@@ -369,18 +392,25 @@ void ExtensionShelf::Toolstrip::LayoutHandle() {
}
void ExtensionShelf::Toolstrip::ChildPreferredSizeChanged(View* child) {
- if (child == view())
+ if (child == view()) {
child->SizeToPreferredSize();
+ Layout();
+ if (expanded_) {
+ LayoutHandle();
+ placeholder_view_->SetWidth(child->width());
+ shelf_->Layout();
+ }
+ }
}
-void ExtensionShelf::Toolstrip::BubbleBrowserWindowMoved(BrowserBubble* bubble)
-{
+void ExtensionShelf::Toolstrip::BubbleBrowserWindowMoved(
+ BrowserBubble* bubble) {
HideShelfHandle(0);
}
-void ExtensionShelf::Toolstrip::BubbleBrowserWindowClosed(BrowserBubble* bubble)
-{
- HideShelfHandle(0);
+void ExtensionShelf::Toolstrip::BubbleBrowserWindowClosing(
+ BrowserBubble* bubble) {
+ DoHideShelfHandle();
}
void ExtensionShelf::Toolstrip::DetachFromShelf(bool browserDetach) {
@@ -429,12 +459,13 @@ void ExtensionShelf::Toolstrip::DoShowShelfHandle() {
}
void ExtensionShelf::Toolstrip::DoHideShelfHandle() {
- if (!handle_visible() || dragging_ || expanded_)
+ if (!handle_visible())
return;
handle_->Hide();
if (handle_->attached())
handle_->DetachFromBrowser();
handle_.reset(NULL);
+ shelf_->Layout();
}
void ExtensionShelf::Toolstrip::StopHandleTimer() {
@@ -526,8 +557,7 @@ void ExtensionShelf::ChildPreferredSizeChanged(View* child) {
Toolstrip *toolstrip = ToolstripForView(static_cast<ExtensionView*>(child));
if (!toolstrip)
return;
- if (!toolstrip->handle_visible())
- Layout();
+ Layout();
}
void ExtensionShelf::Layout() {
@@ -586,8 +616,10 @@ void ExtensionShelf::SetAccessibleName(const std::wstring& name) {
accessible_name_.assign(name);
}
-void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host, int index) {
- model_->SetToolstripDataAt(index, new Toolstrip(this, host));
+void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host,
+ int index) {
+ model_->SetToolstripDataAt(index,
+ new Toolstrip(this, host, model_->ToolstripInfoAt(index)));
bool had_views = GetChildViewCount() > 0;
ExtensionView* view = host->view();
diff --git a/chrome/browser/views/extensions/extension_view.cc b/chrome/browser/views/extensions/extension_view.cc
index 120fb3c..1518567 100644
--- a/chrome/browser/views/extensions/extension_view.cc
+++ b/chrome/browser/views/extensions/extension_view.cc
@@ -15,7 +15,7 @@
ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser)
: host_(host), browser_(browser),
initialized_(false), pending_preferred_width_(0), container_(NULL),
- did_insert_css_(false), is_clipped_(false) {
+ did_insert_css_(false), is_clipped_(false), is_toolstrip_(true) {
host_->set_view(this);
}
@@ -127,10 +127,13 @@ void ExtensionView::SetBackground(const SkBitmap& background) {
void ExtensionView::DidContentsPreferredWidthChange(const int pref_width) {
// Don't actually do anything with this information until we have been shown.
// Size changes will not be honored by lower layers while we are hidden.
+ gfx::Size preferred_size = GetPreferredSize();
if (!IsVisible()) {
pending_preferred_width_ = pref_width;
- } else if (pref_width > 0 && pref_width != GetPreferredSize().width()) {
- SetPreferredSize(gfx::Size(pref_width, height()));
+ } else if (pref_width > 0 && pref_width != preferred_size.width()) {
+ if (preferred_size.height() == 0)
+ preferred_size.set_height(height());
+ SetPreferredSize(gfx::Size(pref_width, preferred_size.height()));
}
}
diff --git a/chrome/browser/views/extensions/extension_view.h b/chrome/browser/views/extensions/extension_view.h
index de34aa5..df3ca2d 100644
--- a/chrome/browser/views/extensions/extension_view.h
+++ b/chrome/browser/views/extensions/extension_view.h
@@ -8,7 +8,6 @@
#include "build/build_config.h"
#include "base/scoped_ptr.h"
-#include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "views/controls/native/native_view_host.h"
@@ -39,6 +38,8 @@ class ExtensionView : public views::NativeViewHost {
RenderViewHost* render_view_host() const;
void SetDidInsertCSS(bool did_insert);
void set_is_clipped(bool is_clipped) { is_clipped_ = is_clipped; }
+ bool is_toolstrip() const { return is_toolstrip_; }
+ void set_is_toolstrip(bool is) { is_toolstrip_ = is; }
// Notification from ExtensionHost.
void DidContentsPreferredWidthChange(const int pref_width);
@@ -103,6 +104,9 @@ class ExtensionView : public views::NativeViewHost {
// Whether this extension view is clipped.
bool is_clipped_;
+ // Whether this view is currently displaying in toolstrip mode.
+ bool is_toolstrip_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionView);
};
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index 24e29da..6d59587 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -602,12 +602,11 @@ void BrowserView::SetBounds(const gfx::Rect& bounds) {
}
void BrowserView::Close() {
- frame_->GetWindow()->Close();
-
BubbleSet::iterator bubble = browser_bubbles_.begin();
- for (; bubble != browser_bubbles_.end(); ++bubble) {
- (*bubble)->BrowserWindowClosed();
- }
+ for (; bubble != browser_bubbles_.end(); ++bubble)
+ (*bubble)->BrowserWindowClosing();
+
+ frame_->GetWindow()->Close();
}
void BrowserView::Activate() {
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index b5e0684..ac1607a 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -751,8 +751,42 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id,
}
for (size_t i = 0; i < list_value->GetSize(); ++i) {
- std::string toolstrip;
- if (!list_value->GetString(i, &toolstrip)) {
+ ToolstripInfo toolstrip;
+ DictionaryValue* toolstrip_value;
+ std::string toolstrip_path;
+ if (list_value->GetString(i, &toolstrip_path)) {
+ // Support a simple URL value for backwards compatibility.
+ // TODO(erikkay) Perhaps deprecate this in the future.
+ toolstrip.toolstrip = GetResourceURL(toolstrip_path);
+ } else if (list_value->GetDictionary(i, &toolstrip_value)) {
+ if (!toolstrip_value->GetString(keys::kToolstripPath,
+ &toolstrip_path)) {
+ *error = ExtensionErrorUtils::FormatErrorMessage(
+ errors::kInvalidToolstrip, IntToString(i));
+ return false;
+ }
+ toolstrip.toolstrip = GetResourceURL(toolstrip_path);
+ if (toolstrip_value->HasKey(keys::kToolstripMolePath)) {
+ std::string mole_path;
+ if (!toolstrip_value->GetString(keys::kToolstripMolePath,
+ &mole_path)) {
+ *error = ExtensionErrorUtils::FormatErrorMessage(
+ errors::kInvalidToolstrip, IntToString(i));
+ return false;
+ }
+ // TODO(erikkay) is there a better way to get this dynamically
+ // from the content itself?
+ int height;
+ if (!toolstrip_value->GetInteger(keys::kToolstripMoleHeight,
+ &height) || (height < 0)) {
+ *error = ExtensionErrorUtils::FormatErrorMessage(
+ errors::kInvalidToolstrip, IntToString(i));
+ return false;
+ }
+ toolstrip.mole = GetResourceURL(mole_path);
+ toolstrip.mole_height = height;
+ }
+ } else {
*error = ExtensionErrorUtils::FormatErrorMessage(
errors::kInvalidToolstrip, IntToString(i));
return false;
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index 6600da0..debdab9 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -54,6 +54,15 @@ class Extension {
bool is_public; // False if only this extension can load this plugin.
};
+ // A toolstrip and its associated mole.
+ struct ToolstripInfo {
+ ToolstripInfo() : mole_height(0) {}
+
+ GURL toolstrip;
+ GURL mole;
+ int mole_height;
+ };
+
// The name of the manifest inside an extension.
static const char kManifestFilename[];
@@ -150,7 +159,7 @@ class Extension {
const PageActionMap& page_actions() const { return page_actions_; }
const std::vector<PluginInfo>& plugins() const { return plugins_; }
const GURL& background_url() const { return background_url_; }
- const std::vector<std::string>& toolstrips() const { return toolstrips_; }
+ const std::vector<ToolstripInfo>& toolstrips() const { return toolstrips_; }
const std::vector<URLPattern>& permissions() const { return permissions_; }
const GURL& update_url() const { return update_url_; }
const std::map<int, std::string>& icons() { return icons_; }
@@ -240,8 +249,8 @@ class Extension {
// loaded in the background.
GURL background_url_;
- // Paths to HTML files to be displayed in the toolbar.
- std::vector<std::string> toolstrips_;
+ // Optional list of toolstrips_ and associated properties.
+ std::vector<ToolstripInfo> toolstrips_;
// The public key ('key' in the manifest) used to sign the contents of the
// crx package ('signature' in the manifest)
diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc
index 373e913..7965746 100644
--- a/chrome/common/extensions/extension_constants.cc
+++ b/chrome/common/extensions/extension_constants.cc
@@ -29,6 +29,8 @@ const wchar_t* kThemeImages = L"images";
const wchar_t* kThemeColors = L"colors";
const wchar_t* kThemeTints = L"tints";
const wchar_t* kThemeDisplayProperties = L"properties";
+const wchar_t* kToolstripMoleHeight = L"mole_height";
+const wchar_t* kToolstripMolePath = L"mole";
const wchar_t* kToolstripPath = L"path";
const wchar_t* kToolstrips = L"toolstrips";
const wchar_t* kType = L"type";
diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h
index 28aeecb..0bac6dd 100644
--- a/chrome/common/extensions/extension_constants.h
+++ b/chrome/common/extensions/extension_constants.h
@@ -30,6 +30,8 @@ namespace extension_manifest_keys {
extern const wchar_t* kThemeColors;
extern const wchar_t* kThemeTints;
extern const wchar_t* kThemeDisplayProperties;
+ extern const wchar_t* kToolstripMoleHeight;
+ extern const wchar_t* kToolstripMolePath;
extern const wchar_t* kToolstripPath;
extern const wchar_t* kToolstrips;
extern const wchar_t* kType;
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index d691f66..221bf32 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -593,11 +593,11 @@ class NotificationType {
EXTENSION_UNLOADED,
// Sent after a new ExtensionHost is created. The details are
- // an ExtensionHost*.
+ // an ExtensionHost* and the source is an ExtensionProcessManager*.
EXTENSION_HOST_CREATED,
// Sent before an ExtensionHost is destroyed. The details are
- // an ExtensionHost*.
+ // an ExtensionHost* and the source is a Profile*.
EXTENSION_HOST_DESTROYED,
// Sent after an extension render process is created and fully functional.
diff --git a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/manifest.json b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/manifest.json
index 61afce1..c1cf5b3 100644
--- a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/manifest.json
+++ b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/manifest.json
@@ -7,7 +7,11 @@
"128": "icon_128.png"
},
"toolstrips": [
- "toolstrip1.html",
+ {
+ "path": "toolstrip1.html",
+ "mole": "lorem_ipsum.html",
+ "mole_height": 200
+ },
"toolstrip2.html"
],
"permissions": ["http://*.google.com/*", "https://*.google.com/*"],