diff options
25 files changed, 128 insertions, 715 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 749b46f..35a57d6 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -272,10 +272,6 @@ Browser* Browser::CreateForApp(const std::wstring& app_name, void Browser::CreateBrowserWindow() { DCHECK(!window_); - - if (SupportsWindowFeature(FEATURE_EXTENSIONSHELF)) - extension_shelf_model_.reset(new ExtensionShelfModel(this)); - window_ = BrowserWindow::CreateBrowserWindow(this); // Show the First Run information bubble if we've been told to. diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 5044810..6afac8a 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -13,7 +13,6 @@ #include "base/scoped_ptr.h" #include "base/task.h" #include "chrome/browser/command_updater.h" -#include "chrome/browser/extensions/extension_shelf_model.h" #include "chrome/browser/sessions/session_id.h" #include "chrome/browser/shell_dialogs.h" #include "chrome/browser/tabs/tab_strip_model.h" @@ -134,9 +133,6 @@ class Browser : public TabStripModelDelegate, const SessionID& session_id() const { return session_id_; } CommandUpdater* command_updater() { return &command_updater_; } FindBarController* find_bar() { return find_bar_controller_.get(); } - ExtensionShelfModel* extension_shelf_model() { - return extension_shelf_model_.get(); - } // Setters ///////////////////////////////////////////////////////////////// @@ -707,9 +703,6 @@ class Browser : public TabStripModelDelegate, // The model for the toolbar view. BrowserToolbarModel toolbar_model_; - // The model for the extension shelf. - scoped_ptr<ExtensionShelfModel> extension_shelf_model_; - // UI update coalescing and handling //////////////////////////////////////// // Tracks invalidates to the UI, see the declaration in the .cc file. diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 5d03e1f..40c5996 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -16,12 +16,10 @@ #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/extensions/extension_tabs_module_constants.h" -#include "chrome/browser/extensions/extension_toolstrip_api.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/common/result_codes.h" -#include "chrome/common/url_constants.h" // FactoryRegistry ------------------------------------------------------------- @@ -69,7 +67,6 @@ void FactoryRegistry::ResetFunctions() { namespace tabs = extension_tabs_module_constants; namespace page_actions = extension_page_actions_module_constants; namespace bookmarks = extension_bookmarks_module_constants; - namespace toolstrip = extension_toolstrip_api_functions; // Windows factories_[tabs::kGetWindowFunction] = @@ -130,12 +127,6 @@ void FactoryRegistry::ResetFunctions() { &NewExtensionFunction<MoveBookmarkFunction>; factories_[bookmarks::kSetBookmarkTitleFunction] = &NewExtensionFunction<SetBookmarkTitleFunction>; - - // Toolstrips. - factories_[toolstrip::kExpandFunction] = - &NewExtensionFunction<ToolstripExpandFunction>; - factories_[toolstrip::kCollapseFunction] = - &NewExtensionFunction<ToolstripCollapseFunction>; } void FactoryRegistry::GetAllNames(std::vector<std::string>* names) { @@ -196,10 +187,6 @@ ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( delegate_(delegate), url_(url), ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) { - // TODO(erikkay) should we do something for these errors in Release? - DCHECK(url.SchemeIs(chrome::kExtensionScheme)); - DCHECK(profile()->GetExtensionsService()->GetExtensionByURL(url)); - all_instances()->insert(this); // Notify the ExtensionProcessManager that the view was created. @@ -220,11 +207,6 @@ Browser* ExtensionFunctionDispatcher::GetBrowser() { return retval; } -ExtensionHost* ExtensionFunctionDispatcher::GetExtensionHost() { - DCHECK(delegate_); - return delegate_->GetExtensionHost(); -} - void ExtensionFunctionDispatcher::HandleRequest(const std::string& name, const std::string& args, int request_id, diff --git a/chrome/browser/extensions/extension_function_dispatcher.h b/chrome/browser/extensions/extension_function_dispatcher.h index 7a47b3f..0e79882 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.h +++ b/chrome/browser/extensions/extension_function_dispatcher.h @@ -14,7 +14,6 @@ class Browser; class ExtensionFunction; -class ExtensionHost; class Profile; class RenderViewHost; class RenderViewHostDelegate; @@ -30,7 +29,6 @@ class ExtensionFunctionDispatcher { class Delegate { public: virtual Browser* GetBrowser() = 0; - virtual ExtensionHost* GetExtensionHost() { return NULL; } }; // The peer object allows us to notify ExtensionFunctions when we are @@ -70,10 +68,6 @@ class ExtensionFunctionDispatcher { // example, for positioning windows, or alert boxes, or creating tabs. Browser* GetBrowser(); - // Gets the ExtensionHost associated with this object. In the case of - // tab hosted extension pages, this will return NULL. - ExtensionHost* GetExtensionHost(); - // Handle a malformed message. Possibly the result of an attack, so kill // the renderer. void HandleBadMessage(ExtensionFunction* api); diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index b4fbd00..78ec493 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -26,7 +26,6 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/render_messages.h" -#include "chrome/common/url_constants.h" #include "grit/browser_resources.h" #include "grit/generated_resources.h" @@ -194,10 +193,6 @@ void ExtensionHost::DidNavigate(RenderViewHost* render_view_host, } url_ = params.url; - if (!url_.SchemeIs(chrome::kExtensionScheme)) { - extension_function_dispatcher_.reset(NULL); - return; - } extension_function_dispatcher_.reset( new ExtensionFunctionDispatcher(render_view_host_, this, url_)); } @@ -249,10 +244,8 @@ void ExtensionHost::ProcessDOMUIMessage(const std::string& message, const std::string& content, int request_id, bool has_callback) { - if (extension_function_dispatcher_.get()) { - extension_function_dispatcher_->HandleRequest(message, content, request_id, - has_callback); - } + extension_function_dispatcher_->HandleRequest(message, content, request_id, + has_callback); } void ExtensionHost::DidInsertCSS() { diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index 18fedd3..8961dfe 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -124,7 +124,6 @@ class ExtensionHost : public RenderViewHostDelegate, // part of. If this is a global background page, we use the active Browser // instead. virtual Browser* GetBrowser(); - virtual ExtensionHost* GetExtensionHost() { return this; } // The extension that we're hosting in this view. Extension* extension_; diff --git a/chrome/browser/extensions/extension_shelf_model.cc b/chrome/browser/extensions/extension_shelf_model.cc index 6b7bd0c..1449d97 100644 --- a/chrome/browser/extensions/extension_shelf_model.cc +++ b/chrome/browser/extensions/extension_shelf_model.cc @@ -39,13 +39,11 @@ ExtensionShelfModel::ExtensionShelfModel(Browser* browser) } ExtensionShelfModel::~ExtensionShelfModel() { - FOR_EACH_OBSERVER(ExtensionShelfModelObserver, observers_, - ShelfModelDeleting()); - while (observers_.size()) observers_.RemoveObserver(observers_.GetElementAt(0)); - for (iterator t = toolstrips_.begin(); t != toolstrips_.end(); ++t) + ExtensionToolstrips::iterator t; + for (t = toolstrips_.begin(); t != toolstrips_.end(); ++t) delete t->host; toolstrips_.clear(); } @@ -73,7 +71,7 @@ void ExtensionShelfModel::InsertToolstripAt(int index, } void ExtensionShelfModel::RemoveToolstripAt(int index) { - ExtensionHost* host = ToolstripAt(index).host; + ExtensionHost* host = ToolstripAt(index); FOR_EACH_OBSERVER(ExtensionShelfModelObserver, observers_, ToolstripRemovingAt(host, index)); toolstrips_.erase(toolstrips_.begin() + index); @@ -96,52 +94,33 @@ void ExtensionShelfModel::MoveToolstripAt(int index, int to_index) { UpdatePrefs(); } -int ExtensionShelfModel::IndexOfHost(ExtensionHost* host) { - for (iterator i = toolstrips_.begin(); i != toolstrips_.end(); ++i) { - if (i->host == host) +int ExtensionShelfModel::IndexOfToolstrip(ExtensionHost* toolstrip) { + ExtensionToolstrips::iterator i; + for (i = toolstrips_.begin(); i != toolstrips_.end(); ++i) { + if (i->host == toolstrip) return i - toolstrips_.begin(); } return -1; } -ExtensionShelfModel::iterator ExtensionShelfModel::ToolstripForHost( - ExtensionHost* host) { - for (iterator i = toolstrips_.begin(); i != toolstrips_.end(); ++i) { - if (i->host == host) - return i; - } - return toolstrips_.end(); -} - -const ExtensionShelfModel::ToolstripItem& ExtensionShelfModel::ToolstripAt( - int index) { +ExtensionHost* ExtensionShelfModel::ToolstripAt(int index) { DCHECK(index >= 0); - return toolstrips_[index]; + return toolstrips_[index].host; } -void ExtensionShelfModel::SetToolstripDataAt(int index, void* data) { +Extension::ToolstripInfo& ExtensionShelfModel::ToolstripInfoAt(int index) { DCHECK(index >= 0); - toolstrips_[index].data = data; + return toolstrips_[index].info; } -void ExtensionShelfModel::ExpandToolstrip(iterator toolstrip, - const GURL& url, int height) { - if (toolstrip == end()) - return; - toolstrip->height = height; - toolstrip->url = url; - FOR_EACH_OBSERVER(ExtensionShelfModelObserver, observers_, - ToolstripChanged(toolstrip)); +void* ExtensionShelfModel::ToolstripDataAt(int index) { + DCHECK(index >= 0); + return toolstrips_[index].data; } -void ExtensionShelfModel::CollapseToolstrip(iterator toolstrip, - const GURL& url) { - if (toolstrip == end()) - return; - toolstrip->height = 0; - toolstrip->url = url; - FOR_EACH_OBSERVER(ExtensionShelfModelObserver, observers_, - ToolstripChanged(toolstrip)); +void ExtensionShelfModel::SetToolstripDataAt(int index, void* data) { + DCHECK(index >= 0); + toolstrips_[index].data = data; } void ExtensionShelfModel::Observe(NotificationType type, @@ -157,8 +136,7 @@ void ExtensionShelfModel::Observe(NotificationType type, break; case NotificationType::EXTENSIONS_READY: if (browser_->profile()->GetExtensionsService()) { - AddExtensions( - browser_->profile()->GetExtensionsService()->extensions()); + AddExtensions(browser_->profile()->GetExtensionsService()->extensions()); SortToolstrips(); } ready_ = true; @@ -189,7 +167,6 @@ void ExtensionShelfModel::AddExtension(Extension* extension) { item.host = manager->CreateView(extension, url, browser_); item.info = *toolstrip; item.data = NULL; - item.height = 0; AppendToolstrip(item); } } @@ -205,7 +182,7 @@ void ExtensionShelfModel::AddExtensions(const ExtensionList* extensions) { void ExtensionShelfModel::RemoveExtension(Extension* extension) { bool changed = false; for (int i = count() - 1; i >= 0; --i) { - ExtensionHost* t = ToolstripAt(i).host; + ExtensionHost* t = ToolstripAt(i); if (t->extension()->id() == extension->id()) { changed = true; RemoveToolstripAt(i); @@ -225,7 +202,7 @@ void ExtensionShelfModel::UpdatePrefs() { // It's easiest to just rebuild the list each time. ExtensionPrefs::URLList urls; for (int i = 0; i < count(); ++i) - urls.push_back(ToolstripAt(i).host->GetURL()); + urls.push_back(ToolstripAt(i)->GetURL()); prefs_->SetShelfToolstripOrder(urls); NotificationService::current()->Notify( @@ -236,15 +213,15 @@ void ExtensionShelfModel::UpdatePrefs() { void ExtensionShelfModel::SortToolstrips() { ExtensionPrefs::URLList urls = prefs_->GetShelfToolstripOrder(); - ToolstripList copy = - ToolstripList(toolstrips_.begin(), toolstrips_.end()); + ExtensionToolstrips copy = + ExtensionToolstrips(toolstrips_.begin(), toolstrips_.end()); toolstrips_.clear(); // Go through the urls and find the matching toolstrip, re-adding it to the // new list in the proper order. for (size_t i = 0; i < urls.size(); ++i) { GURL& url = urls[i]; - for (iterator toolstrip = copy.begin(); + for (ExtensionToolstrips::iterator toolstrip = copy.begin(); toolstrip != copy.end(); ++toolstrip) { if (url == toolstrip->host->GetURL()) { // Note that it's technically possible for the same URL to appear in @@ -261,7 +238,7 @@ void ExtensionShelfModel::SortToolstrips() { // Any toolstrips remaining in |copy| were somehow missing from the prefs, // so just append them to the end. - for (iterator toolstrip = copy.begin(); + for (ExtensionToolstrips::iterator toolstrip = copy.begin(); toolstrip != copy.end(); ++toolstrip) { toolstrips_.push_back(*toolstrip); } diff --git a/chrome/browser/extensions/extension_shelf_model.h b/chrome/browser/extensions/extension_shelf_model.h index 29f6592..28fb00b 100644 --- a/chrome/browser/extensions/extension_shelf_model.h +++ b/chrome/browser/extensions/extension_shelf_model.h @@ -16,7 +16,36 @@ class Browser; class ExtensionPrefs; -class ExtensionShelfModelObserver; + +// Objects implement this interface when they wish to be notified of changes to +// the ExtensionShelfModel. +// +// Register your ExtensionShelfModelObserver with the ExtensionShelfModel using +// Add/RemoveObserver methods. +class ExtensionShelfModelObserver { + public: + // A new toolstrip was inserted into ExtensionShelfModel at |index|. + virtual void ToolstripInsertedAt(ExtensionHost* toolstrip, int index) {} + + // The specified toolstrip is being removed and destroyed. + virtual void ToolstripRemovingAt(ExtensionHost* toolstrip, int index) {} + + // |toolstrip| moved from |from_index| to |to_index|. + virtual void ToolstripMoved(ExtensionHost* toolstrip, + int from_index, + int to_index) {} + + // The specified toolstrip changed in some way (currently only size changes) + virtual void ToolstripChangedAt(ExtensionHost* toolstrip, int index) {} + + // There are no more toolstrips in the model. + virtual void ExtensionShelfEmpty() {} + + // The entire model may have changed. + virtual void ShelfModelReloaded() {} + + // TODO(erikkay) - any more? +}; // The model representing the toolstrips on an ExtensionShelf. The order of // the toolstrips is common across all of the models for a given Profile, @@ -31,13 +60,8 @@ class ExtensionShelfModel : public NotificationObserver { ExtensionHost* host; Extension::ToolstripInfo info; void* data; - int height; - GURL url; }; - typedef std::vector<ToolstripItem> ToolstripList; - typedef ToolstripList::iterator iterator; - // Add and remove observers to changes within this ExtensionShelfModel. void AddObserver(ExtensionShelfModelObserver* observer); void RemoveObserver(ExtensionShelfModelObserver* observer); @@ -46,10 +70,6 @@ class ExtensionShelfModel : public NotificationObserver { int count() const { return static_cast<int>(toolstrips_.size()); } bool empty() const { return toolstrips_.empty(); } - // Iterators for the toolstrips in the model. - iterator begin() { return toolstrips_.begin(); } - ExtensionShelfModel::iterator end() { return toolstrips_.end(); } - // Add |toolstrip| to the end of the shelf. void AppendToolstrip(const ToolstripItem& toolstrip); @@ -62,28 +82,18 @@ class ExtensionShelfModel : public NotificationObserver { // Move the toolstrip at |index| to |to_index|. void MoveToolstripAt(int index, int to_index); - // Lookup the index of |host|. Returns -1 if not present. - int IndexOfHost(ExtensionHost* host); + // Lookup the index of |toolstrip|. Returns -1 if not present. + int IndexOfToolstrip(ExtensionHost* toolstrip); // Return the toolstrip at |index|. - const ToolstripItem& ToolstripAt(int index); + ExtensionHost* ToolstripAt(int index); - // Return the ToolstripItem associated with |host| or NULL if it's not - // present. - ToolstripList::iterator ToolstripForHost(ExtensionHost* host); + // Return the ToolstripInfo at |index|. + Extension::ToolstripInfo& ToolstripInfoAt(int index); - // Set some arbitrary data associated with a particular toolstrip. + // Get/Set some arbitrary data associated with a particular toolstrip. void SetToolstripDataAt(int index, void* data); - - // Update the ToolstripItem for |toolstrip| to set its |url| and |height| - // and then call ToolstripChanged for all observers. - // If |url| is empty, no navigation is requested. - void ExpandToolstrip(iterator toolstrip, const GURL& url, int height); - - // Update the ToolstripItem for |toolstrip| to set its |url| and its height - // to 0, and then call ToolstripChanged for all observers. - // If |url| is empty, no navigation is requested. - void CollapseToolstrip(iterator toolstrip, const GURL& url); + void* ToolstripDataAt(int index); // NotificationObserver virtual void Observe(NotificationType type, @@ -116,7 +126,8 @@ class ExtensionShelfModel : public NotificationObserver { NotificationRegistrar registrar_; // The Toolstrips loaded in this model. The model owns these objects. - ToolstripList toolstrips_; + typedef std::vector<ToolstripItem> ExtensionToolstrips; + ExtensionToolstrips toolstrips_; // Our observers. typedef ObserverList<ExtensionShelfModelObserver> @@ -129,36 +140,4 @@ class ExtensionShelfModel : public NotificationObserver { DISALLOW_COPY_AND_ASSIGN(ExtensionShelfModel); }; -// Objects implement this interface when they wish to be notified of changes to -// the ExtensionShelfModel. -// -// Register your ExtensionShelfModelObserver with the ExtensionShelfModel using -// Add/RemoveObserver methods. -class ExtensionShelfModelObserver { - public: - // A new toolstrip was inserted into ExtensionShelfModel at |index|. - virtual void ToolstripInsertedAt(ExtensionHost* toolstrip, int index) {} - - // The specified toolstrip is being removed and destroyed. - virtual void ToolstripRemovingAt(ExtensionHost* toolstrip, int index) {} - - // |toolstrip| moved from |from_index| to |to_index|. - virtual void ToolstripMoved(ExtensionHost* toolstrip, - int from_index, - int to_index) {} - - // The specified toolstrip changed in some way (currently only size changes) - virtual void ToolstripChanged(ExtensionShelfModel::iterator toolstrip) {} - - // There are no more toolstrips in the model. - virtual void ExtensionShelfEmpty() {} - - // The entire model may have changed. - virtual void ShelfModelReloaded() {} - - // The model is being destroyed. - virtual void ShelfModelDeleting() {} -}; - - #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SHELF_MODEL_H_ diff --git a/chrome/browser/extensions/extension_shelf_model_unittest.cc b/chrome/browser/extensions/extension_shelf_model_unittest.cc index 59cf318..d1e2217 100644 --- a/chrome/browser/extensions/extension_shelf_model_unittest.cc +++ b/chrome/browser/extensions/extension_shelf_model_unittest.cc @@ -80,18 +80,18 @@ IN_PROC_BROWSER_TEST_F(ExtensionShelfModelTest, Basic) { // extension1 has two toolstrips EXPECT_EQ(inserted_count_, 2); - ExtensionHost* one = model_->ToolstripAt(0).host; - ExtensionHost* two = model_->ToolstripAt(1).host; + ExtensionHost* one = model_->ToolstripAt(0); + ExtensionHost* two = model_->ToolstripAt(1); EXPECT_EQ(one->GetURL().path(), "/toolstrip1.html"); EXPECT_EQ(two->GetURL().path(), "/toolstrip2.html"); model_->MoveToolstripAt(0, 1); - EXPECT_EQ(two, model_->ToolstripAt(0).host); - EXPECT_EQ(one, model_->ToolstripAt(1).host); + EXPECT_EQ(two, model_->ToolstripAt(0)); + EXPECT_EQ(one, model_->ToolstripAt(1)); EXPECT_EQ(moved_count_, 1); model_->RemoveToolstripAt(0); - EXPECT_EQ(one, model_->ToolstripAt(0).host); + EXPECT_EQ(one, model_->ToolstripAt(0)); EXPECT_EQ(1, model_->count()); EXPECT_EQ(removed_count_, 1); } diff --git a/chrome/browser/extensions/extension_toolstrip_api.cc b/chrome/browser/extensions/extension_toolstrip_api.cc deleted file mode 100644 index 248eedb..0000000 --- a/chrome/browser/extensions/extension_toolstrip_api.cc +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) 2009 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/extensions/extension_toolstrip_api.h" - -#include "chrome/browser/browser.h" -#include "chrome/browser/extensions/extension_host.h" -#include "chrome/browser/extensions/extension_shelf_model.h" - -namespace extension_toolstrip_api_functions { -const char kExpandFunction[] = "toolstrip.expand"; -const char kCollapseFunction[] = "toolstrip.collapse"; -}; // namespace extension_toolstrip_api_functions - -namespace { -// Errors. -const char kNotAToolstripError[] = "This page is not a toolstrip."; -const char kAlreadyExpandedError[] = "This toolstrip is already expanded."; -const char kAlreadyCollapsedError[] = "This toolstrip is already collapsed."; -const char kInvalidURLError[] = "Invalid URL"; -const char kBadHeightError[] = "Bad height."; - -// TODO(erikkay) what are good values here? -const int kMinHeight = 50; -const int kMaxHeight = 1000; -}; // namespace - -bool ToolstripFunction::RunImpl() { - ExtensionHost* host = dispatcher()->GetExtensionHost(); - if (!host) { - error_ = kNotAToolstripError; - return false; - } - Browser* browser = dispatcher()->GetBrowser(); - if (!browser) { - error_ = kNotAToolstripError; - return false; - } - model_ = browser->extension_shelf_model(); - if (!model_) { - error_ = kNotAToolstripError; - return false; - } - toolstrip_ = model_->ToolstripForHost(host); - if (toolstrip_ == model_->end()) { - error_ = kNotAToolstripError; - return false; - } - return true; -} - -bool ToolstripExpandFunction::RunImpl() { - if (!ToolstripFunction::RunImpl()) - return false; - if (toolstrip_->height != 0) { - error_ = kAlreadyExpandedError; - return false; - } - - EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); - const ListValue* args = static_cast<const ListValue*>(args_); - EXTENSION_FUNCTION_VALIDATE(args->GetSize() <= 2); - - int height; - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &height)); - EXTENSION_FUNCTION_VALIDATE(height >= 0); - if (height < kMinHeight || height > kMaxHeight) { - error_ = kBadHeightError; - return false; - } - - GURL url; - if (args->GetSize() == 2) { - Value* url_val; - EXTENSION_FUNCTION_VALIDATE(args->Get(1, &url_val)); - if (url_val->GetType() != Value::TYPE_NULL) { - std::string url_str; - EXTENSION_FUNCTION_VALIDATE(url_val->GetAsString(&url_str)); - url = GURL(url_str); - if (!url.is_valid() && !url.is_empty()) { - error_ = kInvalidURLError; - return false; - } - } - } - - model_->ExpandToolstrip(toolstrip_, url, height); - return true; -} - -bool ToolstripCollapseFunction::RunImpl() { - if (!ToolstripFunction::RunImpl()) - return false; - - if (toolstrip_->height == 0) { - error_ = kAlreadyCollapsedError; - return false; - } - - GURL url; - if (args_->GetType() != Value::TYPE_NULL) { - std::string url_str; - EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&url_str)); - url = GURL(url_str); - if (!url.is_valid() && !url.is_empty()) { - error_ = kInvalidURLError; - return false; - } - } - - model_->CollapseToolstrip(toolstrip_, url); - return true; -} diff --git a/chrome/browser/extensions/extension_toolstrip_api.h b/chrome/browser/extensions/extension_toolstrip_api.h deleted file mode 100644 index 127c952..0000000 --- a/chrome/browser/extensions/extension_toolstrip_api.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2009 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_EXTENSIONS_EXTENSION_TOOLSTRIP_API_H_ -#define CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLSTRIP_API_H_ - -#include "chrome/browser/extensions/extension_function.h" -#include "chrome/browser/extensions/extension_shelf_model.h" - -// Function names. -namespace extension_toolstrip_api_functions { - extern const char kExpandFunction[]; - extern const char kCollapseFunction[]; -}; // namespace extension_toolstrip_api_functions - -class ToolstripFunction : public SyncExtensionFunction { - protected: - virtual bool RunImpl(); - - ExtensionShelfModel* model_; - ExtensionShelfModel::iterator toolstrip_; -}; - -class ToolstripExpandFunction : public ToolstripFunction { - virtual bool RunImpl(); -}; - -class ToolstripCollapseFunction : public ToolstripFunction { - virtual bool RunImpl(); -}; - -#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLSTRIP_API_H_ diff --git a/chrome/browser/gtk/extension_shelf_gtk.cc b/chrome/browser/gtk/extension_shelf_gtk.cc index c83d182..5f3a4b9 100644 --- a/chrome/browser/gtk/extension_shelf_gtk.cc +++ b/chrome/browser/gtk/extension_shelf_gtk.cc @@ -67,7 +67,7 @@ void ExtensionShelfGtk::Toolstrip::Init() { ExtensionShelfGtk::ExtensionShelfGtk(Profile* profile, Browser* browser) : browser_(browser), theme_provider_(GtkThemeProvider::GetFrom(profile)), - model_(browser->extension_shelf_model()) { + model_(new ExtensionShelfModel(browser)) { Init(profile); registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, @@ -75,8 +75,7 @@ ExtensionShelfGtk::ExtensionShelfGtk(Profile* profile, Browser* browser) } ExtensionShelfGtk::~ExtensionShelfGtk() { - if (model_) - model_->RemoveObserver(this); + model_->RemoveObserver(this); event_box_.Destroy(); } @@ -120,8 +119,8 @@ void ExtensionShelfGtk::ToolstripMoved(ExtensionHost* host, AdjustHeight(); } -void ExtensionShelfGtk::ToolstripChanged( - ExtensionShelfModel::iterator toolstrip) { +void ExtensionShelfGtk::ToolstripChangedAt(ExtensionHost* host, + int index) { // TODO(phajdan.jr): Implement changing toolstrips. AdjustHeight(); } @@ -140,18 +139,6 @@ void ExtensionShelfGtk::ShelfModelReloaded() { LoadFromModel(); } -void ExtensionShelfGtk::ShelfModelDeleting() { - for (std::set<Toolstrip*>::iterator iter = toolstrips_.begin(); - iter != toolstrips_.end(); ++iter) { - (*iter)->RemoveToolstripFromBox(shelf_hbox_); - delete *iter; - } - toolstrips_.clear(); - - model_->RemoveObserver(this); - model_ = NULL; -} - void ExtensionShelfGtk::Init(Profile* profile) { event_box_.Own(gtk_event_box_new()); @@ -200,12 +187,12 @@ void ExtensionShelfGtk::LoadFromModel() { DCHECK(toolstrips_.empty()); int count = model_->count(); for (int i = 0; i < count; ++i) - ToolstripInsertedAt(model_->ToolstripAt(i).host, i); + ToolstripInsertedAt(model_->ToolstripAt(i), i); AdjustHeight(); } ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) { - return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); + return static_cast<Toolstrip*>(model_->ToolstripDataAt(index)); } // static diff --git a/chrome/browser/gtk/extension_shelf_gtk.h b/chrome/browser/gtk/extension_shelf_gtk.h index 81b055a89..da2948d 100644 --- a/chrome/browser/gtk/extension_shelf_gtk.h +++ b/chrome/browser/gtk/extension_shelf_gtk.h @@ -42,10 +42,9 @@ class ExtensionShelfGtk : public ExtensionShelfModelObserver, virtual void ToolstripMoved(ExtensionHost* host, int from_index, int to_index); - virtual void ToolstripChanged(ExtensionShelfModel::iterator toolstrip); + virtual void ToolstripChangedAt(ExtensionHost* host, int index); virtual void ExtensionShelfEmpty(); virtual void ShelfModelReloaded(); - virtual void ShelfModelDeleting(); private: class Toolstrip; @@ -89,7 +88,7 @@ class ExtensionShelfGtk : public ExtensionShelfModelObserver, NotificationRegistrar registrar_; // The model representing the toolstrips on the shelf. - ExtensionShelfModel* model_; + scoped_ptr<ExtensionShelfModel> model_; // Set of toolstrip views which are really on the shelf. std::set<Toolstrip*> toolstrips_; diff --git a/chrome/browser/views/extensions/extension_shelf.cc b/chrome/browser/views/extensions/extension_shelf.cc index 3ba801c..77df55a 100644 --- a/chrome/browser/views/extensions/extension_shelf.cc +++ b/chrome/browser/views/extensions/extension_shelf.cc @@ -153,10 +153,6 @@ class ExtensionShelf::Toolstrip : public views::View, void DoHideShelfHandle(); void StopHandleTimer(); - // Expand / Collapse - void Expand(int height, const GURL& url); - void Collapse(const GURL& url); - // BrowserBubble::Delegate virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); @@ -258,8 +254,9 @@ void ExtensionShelf::Toolstrip::Paint(gfx::Canvas* canvas) { gfx::Size ExtensionShelf::Toolstrip::GetPreferredSize() { gfx::Size sz = title_->GetPreferredSize(); sz.set_width(std::max(view()->width(), sz.width())); - if (!expanded_) + 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); @@ -336,17 +333,33 @@ void ExtensionShelf::Toolstrip::OnMouseReleased(const views::MouseEvent& event, View::ConvertPointToView(NULL, shelf_, &loc); shelf_->DropExtension(this, loc, canceled); AttachToShelf(true); - } else if (!canceled) { + } else if (!canceled && + info_.mole.is_valid() && info_.toolstrip.is_valid()) { // Toggle mole to either expanded or collapsed. - // TODO(erikkay) If there's no valid URL in the manifest, should we - // post an event to the toolstrip in this case? + expanded_ = !expanded_; + view()->set_is_toolstrip(!expanded_); if (expanded_) { - if (info_.toolstrip.is_valid()) - shelf_->CollapseToolstrip(host_, info_.toolstrip); + 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 { - if (info_.mole.is_valid()) - shelf_->ExpandToolstrip(host_, info_.mole, info_.mole_height); + gfx::Size extension_size = view()->GetPreferredSize(); + extension_size.set_height(kToolstripHeight); + view()->SetPreferredSize(extension_size); + + host_->NavigateToURL(info_.toolstrip); + AttachToShelf(false); } + + // 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); } } @@ -401,7 +414,6 @@ void ExtensionShelf::Toolstrip::BubbleBrowserWindowClosing( } void ExtensionShelf::Toolstrip::DetachFromShelf(bool browserDetach) { - DCHECK(handle_.get()); DCHECK(!placeholder_view_); if (browserDetach && handle_->attached()) handle_->DetachFromBrowser(); @@ -418,8 +430,6 @@ void ExtensionShelf::Toolstrip::DetachFromShelf(bool browserDetach) { } void ExtensionShelf::Toolstrip::AttachToShelf(bool browserAttach) { - DCHECK(handle_.get()); - DCHECK(placeholder_view_); if (browserAttach && !handle_->attached()) handle_->AttachToBrowser(); @@ -463,56 +473,6 @@ void ExtensionShelf::Toolstrip::StopHandleTimer() { timer_factory_.RevokeAll(); } -void ExtensionShelf::Toolstrip::Expand(int height, const GURL& url) { - DCHECK(!expanded_); - - DoShowShelfHandle(); - - expanded_ = true; - view()->set_is_toolstrip(!expanded_); - - bool navigate = (!url.is_empty() && url != host_->GetURL()); - if (navigate) - host_->NavigateToURL(url); - - StopHandleTimer(); - DetachFromShelf(false); - - gfx::Size extension_size = view()->GetPreferredSize(); - extension_size.set_height(height); - view()->SetPreferredSize(extension_size); - LayoutHandle(); - - // 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. - if (navigate) - view()->SetVisible(false); -} - -void ExtensionShelf::Toolstrip::Collapse(const GURL& url) { - DCHECK(expanded_); - expanded_ = false; - view()->set_is_toolstrip(!expanded_); - - gfx::Size extension_size = view()->GetPreferredSize(); - extension_size.set_height(kToolstripHeight); - view()->SetPreferredSize(extension_size); - AttachToShelf(false); - - if (!url.is_empty() && url != host_->GetURL()) { - host_->NavigateToURL(url); - - // 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); - } - - // Must use the delay due to bug 18248. - HideShelfHandle(kHideDelayMs); -} - void ExtensionShelf::Toolstrip::ShowShelfHandle() { StopHandleTimer(); if (handle_visible()) @@ -540,21 +500,19 @@ void ExtensionShelf::Toolstrip::HideShelfHandle(int delay_ms) { //////////////////////////////////////////////////////////////////////////////// ExtensionShelf::ExtensionShelf(Browser* browser) - : model_(browser->extension_shelf_model()) { + : model_(new ExtensionShelfModel(browser)) { model_->AddObserver(this); LoadFromModel(); EnableCanvasFlippingForRTLUI(true); } ExtensionShelf::~ExtensionShelf() { - if (model_) { - int count = model_->count(); - for (int i = 0; i < count; ++i) { - delete ToolstripAtIndex(i); - model_->SetToolstripDataAt(i, NULL); - } - model_->RemoveObserver(this); + int count = model_->count(); + for (int i = 0; i < count; ++i) { + delete ToolstripAtIndex(i); + model_->SetToolstripDataAt(i, NULL); } + model_->RemoveObserver(this); } void ExtensionShelf::Paint(gfx::Canvas* canvas) { @@ -605,8 +563,6 @@ void ExtensionShelf::ChildPreferredSizeChanged(View* child) { void ExtensionShelf::Layout() { if (!GetParent()) return; - if (!model_) - return; int x = kLeftMargin; int y = kTopMargin; @@ -663,7 +619,7 @@ void ExtensionShelf::SetAccessibleName(const std::wstring& name) { void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host, int index) { model_->SetToolstripDataAt(index, - new Toolstrip(this, host, model_->ToolstripAt(index).info)); + new Toolstrip(this, host, model_->ToolstripInfoAt(index))); bool had_views = GetChildViewCount() > 0; ExtensionView* view = host->view(); @@ -697,15 +653,7 @@ void ExtensionShelf::ToolstripMoved(ExtensionHost* host, int from_index, Layout(); } -void ExtensionShelf::ToolstripChanged(ExtensionShelfModel::iterator toolstrip) { - Toolstrip* t = static_cast<Toolstrip*>(toolstrip->data); - if (toolstrip->height > 0) { - if (!t->expanded()) { - t->Expand(toolstrip->height, toolstrip->url); - } - } else if (t->expanded()) { - t->Collapse(toolstrip->url); - } +void ExtensionShelf::ToolstripChangedAt(ExtensionHost* toolstrip, int index) { } void ExtensionShelf::ExtensionShelfEmpty() { @@ -718,16 +666,6 @@ void ExtensionShelf::ShelfModelReloaded() { LoadFromModel(); } -void ExtensionShelf::ShelfModelDeleting() { - int count = model_->count(); - for (int i = 0; i < count; ++i) { - delete ToolstripAtIndex(i); - model_->SetToolstripDataAt(i, NULL); - } - model_->RemoveObserver(this); - model_ = NULL; -} - void ExtensionShelf::OnExtensionMouseEvent(ExtensionView* view) { Toolstrip *toolstrip = ToolstripForView(view); if (toolstrip) @@ -751,23 +689,12 @@ void ExtensionShelf::DropExtension(Toolstrip* toolstrip, const gfx::Point& pt, } if (toolstrip == dest_toolstrip) return; - int from = model_->IndexOfHost(toolstrip->host()); - int to = model_->IndexOfHost(dest_toolstrip->host()); + int from = model_->IndexOfToolstrip(toolstrip->host()); + int to = model_->IndexOfToolstrip(dest_toolstrip->host()); DCHECK(from != to); model_->MoveToolstripAt(from, to); } -void ExtensionShelf::ExpandToolstrip(ExtensionHost* host, const GURL& url, - int height) { - ExtensionShelfModel::iterator toolstrip = model_->ToolstripForHost(host); - model_->ExpandToolstrip(toolstrip, url, height); -} - -void ExtensionShelf::CollapseToolstrip(ExtensionHost* host, const GURL& url) { - ExtensionShelfModel::iterator toolstrip = model_->ToolstripForHost(host); - model_->CollapseToolstrip(toolstrip, url); -} - void ExtensionShelf::InitBackground(gfx::Canvas* canvas, const SkRect& subset) { if (!background_.empty()) return; @@ -822,7 +749,7 @@ ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripAtX(int x) { } ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripAtIndex(int index) { - return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); + return static_cast<Toolstrip*>(model_->ToolstripDataAt(index)); } ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripForView( @@ -833,11 +760,12 @@ ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripForView( if (view == toolstrip->view()) return toolstrip; } + NOTREACHED(); return NULL; } void ExtensionShelf::LoadFromModel() { int count = model_->count(); for (int i = 0; i < count; ++i) - ToolstripInsertedAt(model_->ToolstripAt(i).host, i); + ToolstripInsertedAt(model_->ToolstripAt(i), i); } diff --git a/chrome/browser/views/extensions/extension_shelf.h b/chrome/browser/views/extensions/extension_shelf.h index e0dbe5d..57a0954 100644 --- a/chrome/browser/views/extensions/extension_shelf.h +++ b/chrome/browser/views/extensions/extension_shelf.h @@ -27,7 +27,7 @@ class ExtensionShelf : public views::View, virtual ~ExtensionShelf(); // Get the current model. - ExtensionShelfModel* model() { return model_; } + ExtensionShelfModel* model() { return model_.get(); } // View virtual void Paint(gfx::Canvas* canvas); @@ -50,10 +50,9 @@ class ExtensionShelf : public views::View, virtual void ToolstripMoved(ExtensionHost* toolstrip, int from_index, int to_index); - virtual void ToolstripChanged(ExtensionShelfModel::iterator toolstrip); + virtual void ToolstripChangedAt(ExtensionHost* toolstrip, int index); virtual void ExtensionShelfEmpty(); virtual void ShelfModelReloaded(); - virtual void ShelfModelDeleting(); protected: // View @@ -67,13 +66,6 @@ class ExtensionShelf : public views::View, // Dragging toolstrips void DropExtension(Toolstrip* handle, const gfx::Point& pt, bool cancel); - // Expand the specified toolstrip, navigating to |url| if non-empty, - // and setting the |height|. - void ExpandToolstrip(ExtensionHost* host, const GURL& url, int height); - - // Collapse the specified toolstrip, navigating to |url| if non-empty. - void CollapseToolstrip(ExtensionHost* host, const GURL& url); - // Inits the background bitmap. void InitBackground(gfx::Canvas* canvas, const SkRect& subset); @@ -94,7 +86,7 @@ class ExtensionShelf : public views::View, SkBitmap background_; // The model representing the toolstrips on the shelf. - ExtensionShelfModel* model_; + scoped_ptr<ExtensionShelfModel> model_; // Storage of strings needed for accessibility. std::wstring accessible_name_; diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 580ee77..c9a3155 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -599,13 +599,9 @@ void BrowserView::SetBounds(const gfx::Rect& bounds) { } void BrowserView::Close() { - // BrowserWindowClosing will usually cause the bubble to remove itself from - // the set, so we need to iterate in a way that's safe against deletion. - for (BubbleSet::iterator i = browser_bubbles_.begin(); - i != browser_bubbles_.end();) { - BubbleSet::iterator bubble = i++; + BubbleSet::iterator bubble = browser_bubbles_.begin(); + for (; bubble != browser_bubbles_.end(); ++bubble) (*bubble)->BrowserWindowClosing(); - } frame_->GetWindow()->Close(); } @@ -1494,12 +1490,10 @@ void BrowserView::Init() { status_bubble_.reset(new StatusBubbleViews(GetWidget())); - if (browser_->SupportsWindowFeature(Browser::FEATURE_EXTENSIONSHELF)) { - extension_shelf_ = new ExtensionShelf(browser_.get()); - extension_shelf_-> - SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_EXTENSIONS)); - AddChildView(extension_shelf_); - } + extension_shelf_ = new ExtensionShelf(browser_.get()); + extension_shelf_-> + SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_EXTENSIONS)); + AddChildView(extension_shelf_); #if defined(OS_WIN) InitSystemMenu(); diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 5f9929c..4c6cd567 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -977,8 +977,6 @@ 'browser/extensions/extension_tabs_module.h', 'browser/extensions/extension_tabs_module_constants.cc', 'browser/extensions/extension_tabs_module_constants.h', - 'browser/extensions/extension_toolstrip_api.cc', - 'browser/extensions/extension_toolstrip_api.h', 'browser/extensions/extension_updater.cc', 'browser/extensions/extension_updater.h', 'browser/extensions/extensions_service.cc', diff --git a/chrome/common/common_resources.grd b/chrome/common/common_resources.grd index e13c7c1..5ea8f3c 100644 --- a/chrome/common/common_resources.grd +++ b/chrome/common/common_resources.grd @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- This comment is only here because changes to resources are not picked up -without changes to the corresponding grd file. --> +without changes to the corresponding grd file. rw --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/common_resources.h" type="rc_header"> diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index 2740069..1561a41 100755 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -65,6 +65,7 @@ * TODO(rafaelw): Validate event arguments in debug and unittests * TODO(rafaelw): Support $ref for json_schema validation. */ + [ /** * chrome.self @@ -705,36 +706,5 @@ ] } ] - }, - - /** - * chrome.toolstrip - */ - { - namespace: "toolstrip", - types: [], - functions: [ - { - name: "expand", - type: "function", - description: "", - parameters: [ - {type: "integer", name: "height", minimum: 0}, - {type: "string", name: "url", optional: true}, - {type: "function", name: "callback", optional: true} - ] - }, - { - name: "collapse", - type: "function", - description: "", - parameters: [ - {type: "string", name: "url", optional: true}, - {type: "function", name: "callback", optional: true} - ] - } - ], - events: [ - ] } ] diff --git a/chrome/common/extensions/docs/toolstrip.html b/chrome/common/extensions/docs/toolstrip.html deleted file mode 100644 index 5e96cb7..0000000 --- a/chrome/common/extensions/docs/toolstrip.html +++ /dev/null @@ -1,46 +0,0 @@ -<!DOCTYPE html>
-<!-- This page is a placeholder for generated extensions api doc. Note:
- 1) The <head> information in this page is significant, should be uniform
- across api docs and should be edited only with knowledge of the
- templating mechanism.
- 2) The <body> tag *must* retain id="body"
- 3) All <body>.innerHTML is genereated as an rendering step. If viewed in a
- browser, it will be re-generated from the template, json schema and
- authored overview content.
- 4) The <body>.innerHTML is also generated by an offline step so that this
- page may easily be indexed by search engines.
-
- TODO(rafaelw): Abstract this into a "pageshell" that becomes the single
- version of page template shell and the "instance" pages (bookmarks.html,
- etc...) can be generated with a build step.
--->
-<!-- <html> must retain id="template -->
-<html xmlns="http://www.w3.org/1999/xhtml">
- <!-- <head> data is significant and loads the needed libraries and styles -->
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title jscontent="pageTitle">pageTitle</title>
- <link href="css/ApiRefStyles.css" rel="stylesheet" type="text/css">
- <script type="text/javascript"
- src="../../../third_party/jstemplate/jstemplate_compiled.js">
- </script>
- <script type="text/javascript" src="js/api_page_generator.js"></script>
- <script>
-// Re-render the page if the user-agent is chrome and it is being served as
-// a file:/// scheme. This allows both the initial render to static as well
-// as dynamic re-rendering for developers/doc-writers working on local changes.
-window.onload = function() {
- var chrome = navigator.userAgent.indexOf("Chrome") > -1;
- var fileScheme = location.protocol == "file:";
- var regenerate = chrome && fileScheme;
- //if (regenerate) {
- window.renderPage();
- //}
-}
- </script>
- </head>
- <!-- <body> content is completely generated. Do not edit, as it will be
- and rewritten. -->
- <body class="hidden">
- </body>
-</html>
diff --git a/chrome/renderer/extensions/extension_api_client_unittest.cc b/chrome/renderer/extensions/extension_api_client_unittest.cc index 5465a5c..bd0ce09 100644 --- a/chrome/renderer/extensions/extension_api_client_unittest.cc +++ b/chrome/renderer/extensions/extension_api_client_unittest.cc @@ -518,44 +518,3 @@ TEST_F(ExtensionAPIClientTest, EnablePageAction) { "pageActions.disableForTab", "[\"dummy\",{\"tabId\":0,\"url\":\"http://foo/\"}]"); } - -TEST_F(ExtensionAPIClientTest, ExpandToolstrip) { - ExpectJsPass("chrome.toolstrip.expand(100, 'http://foo/')", - "toolstrip.expand", - "[100,\"http://foo/\"]"); - ExpectJsPass("chrome.toolstrip.expand(100, null)", - "toolstrip.expand", - "[100,null]"); - ExpectJsPass("chrome.toolstrip.expand(100, 'http://foo/', function(){})", - "toolstrip.expand", - "[100,\"http://foo/\"]"); - - ExpectJsFail("chrome.toolstrip.expand('100', 'http://foo/')", - "Uncaught Error: Invalid value for argument 0. " - "Expected 'integer' but got 'string'."); - ExpectJsFail("chrome.toolstrip.expand(100, 100)", - "Uncaught Error: Invalid value for argument 1. " - "Expected 'string' but got 'integer'."); - ExpectJsFail("chrome.toolstrip.expand(100, 'http://foo/', 32)", - "Uncaught Error: Invalid value for argument 2. " - "Expected 'function' but got 'integer'."); -} - -TEST_F(ExtensionAPIClientTest, CollapseToolstrip) { - ExpectJsPass("chrome.toolstrip.collapse('http://foo/')", - "toolstrip.collapse", - "\"http://foo/\""); - ExpectJsPass("chrome.toolstrip.collapse(null)", - "toolstrip.collapse", - "null"); - ExpectJsPass("chrome.toolstrip.collapse('http://foo/', function(){})", - "toolstrip.collapse", - "\"http://foo/\""); - - ExpectJsFail("chrome.toolstrip.collapse(100)", - "Uncaught Error: Invalid value for argument 0. " - "Expected 'string' but got 'integer'."); - ExpectJsFail("chrome.toolstrip.collapse('http://foo/', 32)", - "Uncaught Error: Invalid value for argument 1. " - "Expected 'function' but got 'integer'."); -} diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd index ec1d32c..5e05578 100644 --- a/chrome/renderer/renderer_resources.grd +++ b/chrome/renderer/renderer_resources.grd @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- This comment is only here because changes to resources are not picked up -without changes to the corresponding grd file. ek2 --> +without changes to the corresponding grd file. rw3 --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/renderer_resources.h" type="rc_header"> diff --git a/chrome/test/data/extensions/samples/mappy/manifest.json b/chrome/test/data/extensions/samples/mappy/manifest.json deleted file mode 100755 index 1473ce8..0000000 --- a/chrome/test/data/extensions/samples/mappy/manifest.json +++ /dev/null @@ -1,11 +0,0 @@ -{
- "name": "Mappy",
- "version": "0.2",
- "description": "Map stuff",
- "toolstrips": [
- "mappy_toolstrip.html"
- ],
- "content_scripts": [
- { "matches": ["http://*/*"], "js": ["mappy_content_script.js"] }
- ]
-}
diff --git a/chrome/test/data/extensions/samples/mappy/mappy_content_script.js b/chrome/test/data/extensions/samples/mappy/mappy_content_script.js deleted file mode 100755 index 1b9f49c..0000000 --- a/chrome/test/data/extensions/samples/mappy/mappy_content_script.js +++ /dev/null @@ -1,55 +0,0 @@ -// find map on demand
-
-console.log("mappy_content_script.js loaded");
-
-var maps_key = "ABQIAAAATfHumDbW3OmRByfquHd3SRTRERdeAiwZ9EeJWta3L_JZVS0bOBRQeZgr4K0xyVKzUdnnuFl8X9PX0w";
-
-chrome.extension.onConnect.addListener(function(port) {
- //console.log("extension connected");
- port.onMessage.addListener(function(data) {
- //console.log("extension sent message");
- findAddress(port);
- });
-});
-
-var findAddress = function(port) {
- var found;
- var re = /(\d+ [':.,\s\w]*,\s*[A-Za-z]+\s*\d{5}(-\d{4})?)/m;
- var node = document.body;
- var done = false;
- while (!done) {
- done = true;
- for (var i = 0; i < node.childNodes.length; ++i) {
- var child = node.childNodes[i];
- if (child.textContent.match(re)) {
- node = child;
- found = node;
- done = false;
- break;
- }
- }
- }
- if (found) {
- var text = "";
- if (found.childNodes.length) {
- for (var i = 0; i < found.childNodes.length; ++i) {
- text += found.childNodes[i].textContent + " ";
- }
- } else {
- text = found.textContent;
- }
- var match = re.exec(text);
- if (match && match.length) {
- console.log("found: " + match[0]);
- var trim = /\s{2,}/g;
- var map = match[0].replace(trim, " ");
- port.postMessage({message:"map", values:[map]});
- } else {
- console.log("found bad " + found.textContent);
- console.log("no match in: " + text);
- }
- } else {
- console.log("no match in " + node.textContent);
- }
-}
-
diff --git a/chrome/test/data/extensions/samples/mappy/mappy_toolstrip.html b/chrome/test/data/extensions/samples/mappy/mappy_toolstrip.html deleted file mode 100755 index d279a15..0000000 --- a/chrome/test/data/extensions/samples/mappy/mappy_toolstrip.html +++ /dev/null @@ -1,68 +0,0 @@ -<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAATfHumDbW3OmRByfquHd3SRTRERdeAiwZ9EeJWta3L_JZVS0bOBRQeZgr4K0xyVKzUdnnuFl8X9PX0w&sensor=false"
- type="text/javascript"></script>
-<script>
-var maps_key = "ABQIAAAATfHumDbW3OmRByfquHd3SRTRERdeAiwZ9EeJWta3L_JZVS0bOBRQeZgr4K0xyVKzUdnnuFl8X9PX0w";
-
-function xhr_geocode(address) {
- var xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4 && xhr.status == 200) {
- console.log(xhr.responseText);
- var parsed = JSON.parse(xhr.responseText);
- console.dir(parsed);
- var point = parsed.Placemark[0].Point.coordinates;
- var latlng = point[1] + "," + point[0];
- window.open("http://maps.google.com/staticmap?center=" + latlng +
- "&markers=" + latlng + "&zoom=14" +
- "&size=512x512&sensor=false&key=" + maps_key,
- "mappy_popup",
- "width=512,height=512");
- } else {
- console.log("xhr: " + xhr.readyState);
- }
- };
- var url =
- "http://maps.google.com/maps/geo?output=json&oe=utf8&sensor=false&key=" +
- maps_key + "&q=" + address;
- console.log(url);
- xhr.open("GET", url);
- xhr.send(null);
-}
-
-function gclient_geocode(address) {
- var geocoder = new GClientGeocoder();
- geocoder.getLatLng(address, function(point) {
- if (!point) {
- console.log(address + " not found");
- } else {
- var latlng = point.toUrlValue();
- var url = "http://maps.google.com/staticmap?center=" + latlng +
- "&markers=" + latlng + "&zoom=14" +
- "&size=512x512&sensor=false&key=" + maps_key;
- //window.open(url, "mappy_popup", "width=512,height=512");
- document.body.style.width = "512px";
- setTimeout(chrome.toolstrip.expand, 100, 512, url);
- }
- });
-}
-
-function map() {
- chrome.tabs.getSelected(null, function(tab) {
- var port = chrome.tabs.connect(tab.id);
- if (!port) {
- console.log("no port");
- } else {
- port.onMessage.addListener(function(data) {
- var address = data.values[0];
- //xhr_geocode(address);
- gclient_geocode(address);
- });
- port.postMessage({message: "hello tab: " + tab.id});
- console.log("sent message");
- }
- });
-};
-</script>
-<div class="toolstrip-button" onclick="map()">
-<span>Mappy</span>
-</div>
|