diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-10 19:15:08 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-10 19:15:08 +0000 |
commit | 4a8d3279cc9f2149c90d36550a55d01a264ba0a3 (patch) | |
tree | 10686a040d5bbb5af5dc4686564ceec0189fee22 | |
parent | a724b6ad91affee34adc5c3ab25b05536bb51f6d (diff) | |
download | chromium_src-4a8d3279cc9f2149c90d36550a55d01a264ba0a3.zip chromium_src-4a8d3279cc9f2149c90d36550a55d01a264ba0a3.tar.gz chromium_src-4a8d3279cc9f2149c90d36550a55d01a264ba0a3.tar.bz2 |
Unrevert 11294.
- include stub fix so that linux/mac still build.
- fix DCHECK in views code.
- fix unit test.
Review URL: http://codereview.chromium.org/41020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11360 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension.cc | 13 | ||||
-rw-r--r-- | chrome/browser/extensions/extension.h | 55 | ||||
-rwxr-xr-x | chrome/browser/extensions/extension_view.cc | 2 | ||||
-rwxr-xr-x | chrome/browser/extensions/extension_view.h | 2 | ||||
-rwxr-xr-x | chrome/browser/extensions/extension_view_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 10 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 4 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.cc | 94 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.h | 9 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.h | 1 | ||||
-rw-r--r-- | chrome/test/data/extensions/good/extension1/1/index.html | 5 | ||||
-rw-r--r-- | chrome/test/data/extensions/good/extension1/1/manifest.json | 1 | ||||
-rw-r--r-- | chrome/test/data/extensions/good/extension1/1/toolstrip.html | 21 | ||||
-rw-r--r-- | chrome/views/view.cc | 3 |
14 files changed, 161 insertions, 61 deletions
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc index 1155891..75d8930 100644 --- a/chrome/browser/extensions/extension.cc +++ b/chrome/browser/extensions/extension.cc @@ -26,6 +26,7 @@ const wchar_t* Extension::kVersionKey = L"version"; const wchar_t* Extension::kZipHashKey = L"zip_hash"; const wchar_t* Extension::kPluginsDirKey = L"plugins_dir"; const wchar_t* Extension::kThemeKey = L"theme"; +const wchar_t* Extension::kToolstripKey = L"toolstrip"; const char* Extension::kRunAtDocumentStartValue = "document_start"; const char* Extension::kRunAtDocumentEndValue = "document_end"; @@ -70,6 +71,8 @@ const char* Extension::kInvalidZipHashError = "Required key 'zip_hash' is missing or invalid."; const char* Extension::kInvalidPluginsDirError = "Invalid value for 'plugins_dir'."; +const char* Extension::kInvalidToolstripError = + "Invalid value for 'toolstrip'."; const size_t Extension::kIdSize = 20; // SHA1 (160 bits) == 20 bytes @@ -260,6 +263,16 @@ bool Extension::InitFromValue(const DictionaryValue& source, plugins_dir_ = path_.AppendASCII(plugins_dir); } + // Initialize toolstrip (optional). + if (source.HasKey(kToolstripKey)) { + std::string toolstrip_path; + if (!source.GetString(kToolstripKey, &toolstrip_path)) { + *error = kInvalidToolstripError; + return false; + } + toolstrip_url_ = GetResourceURL(extension_url_, toolstrip_path); + } + if (source.HasKey(kThemeKey)) { DictionaryValue* dict_value; if (source.GetDictionary(kThemeKey, &dict_value)) { diff --git a/chrome/browser/extensions/extension.h b/chrome/browser/extensions/extension.h index 5ca86d3..87290ca 100644 --- a/chrome/browser/extensions/extension.h +++ b/chrome/browser/extensions/extension.h @@ -42,6 +42,7 @@ class Extension { static const wchar_t* kZipHashKey; static const wchar_t* kPluginsDirKey; static const wchar_t* kThemeKey; + static const wchar_t* kToolstripKey; // Some values expected in manifests. static const char* kRunAtDocumentStartValue; @@ -65,6 +66,7 @@ class Extension { static const char* kInvalidVersionError; static const char* kInvalidZipHashError; static const char* kInvalidPluginsDirError; + static const char* kInvalidToolstripError; // The number of bytes in a legal id. static const size_t kIdSize; @@ -85,6 +87,9 @@ class Extension { static FilePath GetResourcePath(const FilePath& extension_path, const std::string& relative_path); + // Initialize the extension from a parsed manifest. + bool InitFromValue(const DictionaryValue& value, std::string* error); + // Returns an absolute path to a resource inside of an extension if the // extension has a theme defined with the given |resource_id|. Otherwise // the path will be empty. Note that this method is not static as it is @@ -92,53 +97,31 @@ class Extension { // as providing a theme. FilePath GetThemeResourcePath(const int resource_id); - // The path to the folder the extension is stored in. const FilePath& path() const { return path_; } - - // The base URL for the extension. const GURL& url() const { return extension_url_; } - - // A human-readable ID for the extension. The convention is to use something - // like 'com.example.myextension', but this is not currently enforced. An - // extension's ID is used in things like directory structures and URLs, and - // is expected to not change across versions. In the case of conflicts, - // updates will only be allowed if the extension can be validated using the - // previous version's update key. const std::string& id() const { return id_; } - - // The version number for the extension. const Version* version() const { return version_.get(); } - // String representation of the version number. const std::string VersionString() const; - - // A human-readable name of the extension. const std::string& name() const { return name_; } - - // An optional longer description of the extension. const std::string& description() const { return description_; } - - // Paths to the content scripts that the extension contains. - const UserScriptList& content_scripts() const { - return content_scripts_; - } - - // Path to the directory of NPAPI plugins that the extension contains. - const FilePath& plugins_dir() const { - return plugins_dir_; - } - - // Initialize the extension from a parsed manifest. - bool InitFromValue(const DictionaryValue& value, std::string* error); + const UserScriptList& content_scripts() const { return content_scripts_; } + const FilePath& plugins_dir() const { return plugins_dir_; } + const GURL& toolstrip_url() const { return toolstrip_url_; } private: - // The path to the directory the extension is stored in. + // The absolute path to the directory the extension is stored in. FilePath path_; // The base extension url for the extension. GURL extension_url_; - // The extension's ID. + // A human-readable ID for the extension. The convention is to use something + // like 'com.example.myextension', but this is not currently enforced. An + // extension's ID is used in things like directory structures and URLs, and + // is expected to not change across versions. In the case of conflicts, + // updates will only be allowed if the extension can be validated using the + // previous version's update key. std::string id_; // The extension's version. @@ -147,15 +130,19 @@ class Extension { // The extension's human-readable name. std::string name_; - // An optional description for the extension. + // An optional longer description of the extension. std::string description_; // Paths to the content scripts the extension contains. UserScriptList content_scripts_; - // Path to the directory of NPAPI plugins that the extension contains. + // Optional absolute path to the directory of NPAPI plugins that the extension + // contains. FilePath plugins_dir_; + // Optional URL of an HTML file to be displayed in the toolbar. + GURL toolstrip_url_; + // A SHA1 hash of the contents of the zip file. Note that this key is only // present in the manifest that's prepended to the zip. The inner manifest // will not have this key. diff --git a/chrome/browser/extensions/extension_view.cc b/chrome/browser/extensions/extension_view.cc index 883ac3a..6cd9c97b 100755 --- a/chrome/browser/extensions/extension_view.cc +++ b/chrome/browser/extensions/extension_view.cc @@ -8,6 +8,8 @@ ExtensionView::ExtensionView(const GURL& url, Profile* profile) : HWNDHtmlView(url, this, false), profile_(profile) { + // TODO(mpcomplete): query this from the renderer somehow? + set_preferred_size(gfx::Size(100, 100)); } void ExtensionView::CreatingRenderer() { diff --git a/chrome/browser/extensions/extension_view.h b/chrome/browser/extensions/extension_view.h index d95b745..6bb9e7a5 100755 --- a/chrome/browser/extensions/extension_view.h +++ b/chrome/browser/extensions/extension_view.h @@ -42,6 +42,8 @@ class ExtensionView : public HWNDHtmlView, private: Profile* profile_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionView); }; #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_ diff --git a/chrome/browser/extensions/extension_view_unittest.cc b/chrome/browser/extensions/extension_view_unittest.cc index 70ebd90..102b9bb 100755 --- a/chrome/browser/extensions/extension_view_unittest.cc +++ b/chrome/browser/extensions/extension_view_unittest.cc @@ -130,7 +130,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Index) { // Now wait for it to load, and grab a pointer to it. Extension* extension = observer.WaitForExtension(); ASSERT_TRUE(extension); - GURL url = Extension::GetResourceURL(extension->url(), "index.html"); + GURL url = Extension::GetResourceURL(extension->url(), "toolstrip.html"); // Start the extension process and wait for it to show a javascript alert. MockExtensionView view(url, profile); diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 32492cc..1b66bea 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -103,13 +103,6 @@ bool ExtensionsService::Init() { return true; } -void ExtensionsService::LaunchExtensionProcess(Extension* extension) { - // TODO(mpcomplete): Do something useful here. - GURL url = Extension::GetResourceURL(extension->url(), "index.html"); - ExtensionView* view = new ExtensionView(url, profile_); - view->InitHidden(); -} - MessageLoop* ExtensionsService::GetMessageLoop() { return message_loop_; } @@ -136,8 +129,7 @@ void ExtensionsService::LoadExtension(const FilePath& extension_path) { scoped_refptr<ExtensionsServiceFrontendInterface>(this))); } -void ExtensionsService::OnExtensionsLoaded( - ExtensionList* new_extensions) { +void ExtensionsService::OnExtensionsLoaded(ExtensionList* new_extensions) { extensions_.insert(extensions_.end(), new_extensions->begin(), new_extensions->end()); diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 56e0afa..5c08685 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -63,10 +63,6 @@ class ExtensionsService : public ExtensionsServiceFrontendInterface { // Initialize and start all installed extensions. bool Init(); - // Start the extension process for this extension. TODO(mpcomplete): not sure - // how this should actually work yet. - void LaunchExtensionProcess(Extension* extension); - // ExtensionsServiceFrontendInterface virtual MessageLoop* GetMessageLoop(); virtual void InstallExtension(const FilePath& extension_path); diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index 43c48bdf..6738791 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -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 @@ class BookmarkFolderButton : public views::MenuButton { 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 @@ BookmarkBarView::BookmarkBarView(Profile* profile, Browser* browser) 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 @@ void BookmarkBarView::SetProfile(Profile* profile) { // 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 @@ void BookmarkBarView::SetProfile(Profile* profile) { 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 @@ void BookmarkBarView::Layout() { } } + // 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 @@ MenuButton* BookmarkBarView::CreateOverflowButton() { } 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 @@ void BookmarkBarView::Loaded(BookmarkModel* model) { 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 @@ void BookmarkBarView::Observe(NotificationType type, 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 @@ void BookmarkBarView::RemoveNotificationObservers() { ns->RemoveObserver(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, NotificationService::AllSources()); + ns->RemoveObserver(this, NotificationType::EXTENSIONS_LOADED, + NotificationService::AllSources()); } void BookmarkBarView::NotifyModelChanged() { diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h index 3475a61..5982fbf 100644 --- a/chrome/browser/views/bookmark_bar_view.h +++ b/chrome/browser/views/bookmark_bar_view.h @@ -7,6 +7,7 @@ #include "chrome/browser/bookmarks/bookmark_drag_data.h" #include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/extensions/extensions_service.h" #include "chrome/common/slide_animation.h" #include "chrome/views/label.h" #include "chrome/views/menu.h" @@ -384,6 +385,11 @@ class BookmarkBarView : public views::View, // throbs. void StopThrobbing(bool immediate); + // Add any extension toolstrips which may be requested by the given + // extensions. Views for the toolstrips are inserted after the last bookmark + // button. Returns true if there were any new toolstrips added. + bool AddExtensionToolstrips(const ExtensionList* extensions); + Profile* profile_; // Used for opening urls. @@ -436,6 +442,9 @@ class BookmarkBarView : public views::View, // overflow_button_ or a button on the bar. views::BaseButton* throbbing_view_; + // How many extension toolstrips we have showing in the toolbar. + int num_extension_toolstrips_; + DISALLOW_COPY_AND_ASSIGN(BookmarkBarView); }; diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h index 8583aae..1e20c34 100644 --- a/chrome/common/temp_scaffolding_stubs.h +++ b/chrome/common/temp_scaffolding_stubs.h @@ -781,6 +781,7 @@ class HWNDHtmlView { RenderViewHost* render_view_host() { NOTIMPLEMENTED(); return NULL; } void InitHidden() { NOTIMPLEMENTED(); } + void set_preferred_size(const gfx::Size& size) { NOTIMPLEMENTED(); } }; #endif // CHROME_COMMON_TEMP_SCAFFOLDING_STUBS_H_ diff --git a/chrome/test/data/extensions/good/extension1/1/index.html b/chrome/test/data/extensions/good/extension1/1/index.html deleted file mode 100644 index 2a03e43..0000000 --- a/chrome/test/data/extensions/good/extension1/1/index.html +++ /dev/null @@ -1,5 +0,0 @@ -<body> -<script> - window.setTimeout('alert(window.extension.getTestString())', 2500); -</script> -</body> diff --git a/chrome/test/data/extensions/good/extension1/1/manifest.json b/chrome/test/data/extensions/good/extension1/1/manifest.json index 32022c4..77a4639 100644 --- a/chrome/test/data/extensions/good/extension1/1/manifest.json +++ b/chrome/test/data/extensions/good/extension1/1/manifest.json @@ -4,6 +4,7 @@ "version": "1.0.0.0", "name": "My extension 1", "description": "The first extension that I made.", + "toolstrip": "toolstrip.html", "content_scripts": [ { "matches": ["http://*.google.com/*", "https://*.google.com/*"], diff --git a/chrome/test/data/extensions/good/extension1/1/toolstrip.html b/chrome/test/data/extensions/good/extension1/1/toolstrip.html new file mode 100644 index 0000000..0171859 --- /dev/null +++ b/chrome/test/data/extensions/good/extension1/1/toolstrip.html @@ -0,0 +1,21 @@ +<style> +body { + overflow: hidden; + margin: 0 0 0 0; +} + +/* TODO: put the background style into body when + https://bugs.webkit.org/show_bug.cgi?id=18445 is fixed. */ +.content { + background: -webkit-gradient(linear, left top, left bottom, from(rgb(222, 234, 248)), to(rgb(237, 244, 252))); + padding: 1; +} +</style> +<body> +<div class="content"> +<script> + alert(window.extension.getTestString()); +</script> +<button onclick="alert('clicked')">HTML button</button> +</div> +</body> diff --git a/chrome/views/view.cc b/chrome/views/view.cc index aada086..5b5af2e 100644 --- a/chrome/views/view.cc +++ b/chrome/views/view.cc @@ -151,7 +151,8 @@ gfx::Rect View::GetLocalBounds(bool include_border) const { gfx::Insets insets; border_->GetInsets(&insets); return gfx::Rect(insets.left(), insets.top(), - width() - insets.width(), height() - insets.height()); + std::max(0, width() - insets.width()), + std::max(0, height() - insets.height())); } gfx::Point View::GetPosition() const { |