diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 02:34:08 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 02:34:08 +0000 |
commit | f34e7963c796bda1eb7fd35f5eda0d878c2df4e6 (patch) | |
tree | 1c67e594a5d25adb0b842858f622e3038146b8b7 | |
parent | b304b6162c3a78063f1ed775e33995d8f2205ed4 (diff) | |
download | chromium_src-f34e7963c796bda1eb7fd35f5eda0d878c2df4e6.zip chromium_src-f34e7963c796bda1eb7fd35f5eda0d878c2df4e6.tar.gz chromium_src-f34e7963c796bda1eb7fd35f5eda0d878c2df4e6.tar.bz2 |
First cut at adding Extension Infobars to the experimental API.
Originally described here:
http://code.google.com/p/chromium/wiki/InfoBarExtensionAPI
The API is simple:
chrome.experimental.infoBar.show(
{"htmlPath": "infobar.html"}, function(window) {
// |window| is where the infobar was shown.
});
To close it, you can simply call window.close() from within the InfoBar (infoBar.hide is not provided).
The api is privileged (not available to content scripts directly).
The minimum height for the infobar is regular height for our infobars (32 pixels), maximum is twice that and the actual size is determined by the content (within these constraints mentioned).
See screenshot in bug. The icon on the far left is an extension icon with a dropdown menu showing the menu that shows when you right-click on the extension icon in the Omnibox/browser action container.
BUG=26463
TEST=None (for now).
Review URL: http://codereview.chromium.org/1049001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41806 0039d316-1c4b-4281-b951-d872f2087c98
28 files changed, 1238 insertions, 27 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index fcf35ba..ce10283 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_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. tet --> +without changes to the corresponding grd file. fbt1 --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/browser_resources.h" type="rc_header"> @@ -50,6 +50,7 @@ without changes to the corresponding grd file. tet --> <include name="IDR_DOM_UI_CSS" file="resources\dom_ui.css" flattenhtml="true" type="BINDATA" /> <include name="IDR_EXTENSIONS_UI_HTML" file="resources\extensions_ui.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_EXTENSION_DEFAULT_ICON" file="resources\extension_default_icon.png" type="BINDATA" /> + <include name="IDR_EXTENSIONS_INFOBAR_CSS" file="resources\extensions_infobar.css" flattenhtml="true" type="BINDATA" /> <include name="IDR_EXTENSIONS_TOOLSTRIP_THEME_CSS" file="resources\extensions_toolstrip.css" flattenhtml="true" type="BINDATA" /> <include name="IDR_PRINT_TAB_HTML" file="resources\print_tab.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_PRINT_TAB_CSS" file="resources\print_tab.css" type="BINDATA" /> diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 6d47016..1e6bee1 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -20,6 +20,7 @@ #include "chrome/browser/extensions/extension_history_api.h" #include "chrome/browser/extensions/extension_idle_api.h" #include "chrome/browser/extensions/extension_i18n_api.h" +#include "chrome/browser/extensions/extension_infobar_module.h" #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/extensions/extension_metrics_module.h" #include "chrome/browser/extensions/extension_page_actions_module.h" @@ -138,6 +139,9 @@ void FactoryRegistry::ResetFunctions() { RegisterFunction<MoveBookmarkFunction>(); RegisterFunction<UpdateBookmarkFunction>(); + // Infobars. + RegisterFunction<ShowInfoBarFunction>(); + // BookmarkManager RegisterFunction<CopyBookmarkManagerFunction>(); RegisterFunction<CutBookmarkManagerFunction>(); diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index e2d86da..2470969 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -326,6 +326,17 @@ void ExtensionHost::DidNavigate(RenderViewHost* render_view_host, new ExtensionFunctionDispatcher(render_view_host_, this, url_)); } +void ExtensionHost::InsertInfobarCSS() { + DCHECK(!is_background_page()); + + static const base::StringPiece css( + ResourceBundle::GetSharedInstance().GetRawDataResource( + IDR_EXTENSIONS_INFOBAR_CSS)); + + render_view_host()->InsertCSSInWebFrame( + L"", css.as_string(), "InfobarThemeCSS"); +} + void ExtensionHost::InsertThemeCSS() { DCHECK(!is_background_page()); @@ -367,7 +378,8 @@ void ExtensionHost::DidStopLoading() { did_stop_loading_ = true; if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP || extension_host_type_ == ViewType::EXTENSION_MOLE || - extension_host_type_ == ViewType::EXTENSION_POPUP) { + extension_host_type_ == ViewType::EXTENSION_POPUP || + extension_host_type_ == ViewType::EXTENSION_INFOBAR) { #if defined(TOOLKIT_VIEWS) if (view_.get()) view_->DidStopLoading(); @@ -388,6 +400,9 @@ void ExtensionHost::DidStopLoading() { } else if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP) { UMA_HISTOGRAM_TIMES("Extensions.ToolstripLoadTime", since_created_.Elapsed()); + } else if (extension_host_type_ == ViewType::EXTENSION_INFOBAR) { + UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime", + since_created_.Elapsed()); } } } @@ -402,7 +417,10 @@ void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) { if (is_background_page()) { extension_->SetBackgroundPageReady(); } else { - InsertThemeCSS(); + if (extension_host_type_ == ViewType::EXTENSION_INFOBAR) + InsertInfobarCSS(); + else + InsertThemeCSS(); // Listen for browser changes so we can resend the CSS. registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, @@ -464,7 +482,8 @@ void ExtensionHost::OnMessageBoxClosed(IPC::Message* reply_msg, } void ExtensionHost::Close(RenderViewHost* render_view_host) { - if (extension_host_type_ == ViewType::EXTENSION_POPUP) { + if (extension_host_type_ == ViewType::EXTENSION_POPUP || + extension_host_type_ == ViewType::EXTENSION_INFOBAR) { NotificationService::current()->Notify( NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, Source<Profile>(profile_), @@ -483,7 +502,8 @@ WebPreferences ExtensionHost::GetWebkitPrefs() { const bool kIsDomUI = true; WebPreferences webkit_prefs = RenderViewHostDelegateHelper::GetWebkitPrefs(profile, kIsDomUI); - if (extension_host_type_ == ViewType::EXTENSION_POPUP) + if (extension_host_type_ == ViewType::EXTENSION_POPUP || + extension_host_type_ == ViewType::EXTENSION_INFOBAR) webkit_prefs.allow_scripts_to_close_windows = true; return webkit_prefs; } @@ -685,7 +705,8 @@ void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP || extension_host_type_ == ViewType::EXTENSION_MOLE || - extension_host_type_ == ViewType::EXTENSION_POPUP) { + extension_host_type_ == ViewType::EXTENSION_POPUP || + extension_host_type_ == ViewType::EXTENSION_INFOBAR) { render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode( render_view_host->routing_id())); } @@ -697,7 +718,8 @@ int ExtensionHost::GetBrowserWindowID() const { int window_id = -1; if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP || extension_host_type_ == ViewType::EXTENSION_MOLE || - extension_host_type_ == ViewType::EXTENSION_POPUP) { + extension_host_type_ == ViewType::EXTENSION_POPUP || + extension_host_type_ == ViewType::EXTENSION_INFOBAR) { // If the host is bound to a browser, then extract its window id. // Extensions hosted in ExternalTabContainer objects may not have // an associated browser. diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index 4cdc8cf..6d442fa 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -97,6 +97,9 @@ class ExtensionHost : public ExtensionPopupHost::PopupDelegate, // Sets |url_| and navigates |render_view_host_|. void NavigateToURL(const GURL& url); + // Insert a default style sheet for Extension InfoBars. + void InsertInfobarCSS(); + // Insert the theme CSS for a toolstrip/mole. void InsertThemeCSS(); diff --git a/chrome/browser/extensions/extension_infobar_delegate.cc b/chrome/browser/extensions/extension_infobar_delegate.cc new file mode 100644 index 0000000..0c7323a --- /dev/null +++ b/chrome/browser/extensions/extension_infobar_delegate.cc @@ -0,0 +1,60 @@ +// Copyright (c) 2010 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_infobar_delegate.h" + +#include "chrome/browser/browser.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/extensions/extension_host.h" +#include "chrome/browser/extensions/extension_process_manager.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/notification_details.h" +#include "chrome/common/notification_source.h" +#include "chrome/common/notification_type.h" + +ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(Browser* browser, + TabContents* tab_contents, + Extension* extension, + const GURL& url) + : InfoBarDelegate(tab_contents), + extension_(extension), + tab_contents_(tab_contents) { + ExtensionProcessManager* manager = + browser->profile()->GetExtensionProcessManager(); + extension_host_.reset(manager->CreateInfobar(url, browser)); + + registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, + Source<Profile>(browser->profile())); +} + +ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { +} + +bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { + ExtensionInfoBarDelegate* extension_delegate = + delegate->AsExtensionInfoBarDelegate(); + // Only allow one InfoBar at a time per extension. + return extension_delegate->extension_host()->extension() == + extension_host_->extension(); +} + +void ExtensionInfoBarDelegate::InfoBarClosed() { + delete this; +} + +#if !defined(TOOLKIT_VIEWS) +InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() { + NOTIMPLEMENTED(); + return NULL; +} +#endif // !TOOLKIT_VIEWS + +void ExtensionInfoBarDelegate::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE); + const ExtensionHost* result = Details<ExtensionHost>(details).ptr(); + if (extension_host_.get() == result) + tab_contents_->RemoveInfoBar(this); +} diff --git a/chrome/browser/extensions/extension_infobar_delegate.h b/chrome/browser/extensions/extension_infobar_delegate.h new file mode 100644 index 0000000..485b288 --- /dev/null +++ b/chrome/browser/extensions/extension_infobar_delegate.h @@ -0,0 +1,59 @@ +// Copyright (c) 2010 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_INFOBAR_DELEGATE_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ + +#include "chrome/browser/tab_contents/infobar_delegate.h" + +class Browser; +class Extension; +class ExtensionHost; +class TabContents; + +// An interface derived from InfoBarDelegate to form the base interface for +// extension InfoBars. +class ExtensionInfoBarDelegate : public InfoBarDelegate, + public NotificationObserver { + public: + ExtensionInfoBarDelegate(Browser* browser, TabContents* contents, + Extension* extension, const GURL& url); + ~ExtensionInfoBarDelegate(); + + Extension* extension() { return extension_; } + ExtensionHost* extension_host() { return extension_host_.get(); } + + // Overridden from InfoBarDelegate: + virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; + virtual void InfoBarClosed(); + virtual InfoBar* CreateInfoBar(); + virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() { + return this; + } + virtual Type GetInfoBarType() { + return PAGE_ACTION_TYPE; + } + + // Overridden from NotificationObserver: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + private: + // The extension host we are showing the InfoBar for. The delegate needs to + // own this since the InfoBar gets deleted and recreated when you switch tabs + // and come back (and we don't want the user's interaction with the InfoBar to + // get lost at that point. + scoped_ptr<ExtensionHost> extension_host_; + + Extension* extension_; + + TabContents* tab_contents_; + + NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate); +}; + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ diff --git a/chrome/browser/extensions/extension_infobar_module.cc b/chrome/browser/extensions/extension_infobar_module.cc new file mode 100644 index 0000000..491b278 --- /dev/null +++ b/chrome/browser/extensions/extension_infobar_module.cc @@ -0,0 +1,61 @@ +// Copyright (c) 2010 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_infobar_module.h" + +#include "app/l10n_util.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/extensions/extension_infobar_module_constants.h" +#include "chrome/browser/extensions/extension_infobar_delegate.h" +#include "chrome/browser/extensions/extension_tabs_module.h" +#include "chrome/browser/extensions/extension_tabs_module_constants.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/url_constants.h" +#include "grit/generated_resources.h" + +namespace keys = extension_infobar_module_constants; + +bool ShowInfoBarFunction::RunImpl() { + EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); + const DictionaryValue* args = args_as_dictionary(); + + std::string html_path; + EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kHtmlPath, &html_path)); + + GURL url = GURL(std::string(chrome::kExtensionScheme) + + chrome::kStandardSchemeSeparator + + extension_id() + "/" + html_path); + + Browser* browser = dispatcher()->GetBrowser(true); + if (!browser) { + error_ = keys::kNoCurrentWindowError; + return false; + } + + TabContents* tab_contents = NULL; + if (args->HasKey(keys::kTabId)) { + int tab_id = -1; + EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabId, &tab_id)); + + EXTENSION_FUNCTION_VALIDATE(ExtensionTabUtil::GetTabById( + tab_id, browser->profile(), false, // No incognito. + NULL, NULL, &tab_contents, NULL)); + } else { + tab_contents = browser->GetSelectedTabContents(); + } + + if (!tab_contents) { + error_ = keys::kTabNotFoundError; + return false; + } + + tab_contents->AddInfoBar( + new ExtensionInfoBarDelegate(browser, tab_contents, GetExtension(), url)); + + // TODO(finnur): Return the actual DOMWindow object. Bug 26463. + result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); + + return true; +} diff --git a/chrome/browser/extensions/extension_infobar_module.h b/chrome/browser/extensions/extension_infobar_module.h new file mode 100644 index 0000000..3414b19 --- /dev/null +++ b/chrome/browser/extensions/extension_infobar_module.h @@ -0,0 +1,16 @@ +// Copyright (c) 2010 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_INFOBAR_MODULE_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_MODULE_H_ + +#include "chrome/browser/extensions/extension_function.h" + +class ShowInfoBarFunction : public SyncExtensionFunction { + ~ShowInfoBarFunction() {} + virtual bool RunImpl(); + DECLARE_EXTENSION_FUNCTION_NAME("experimental.infoBar.show") +}; + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_MODULE_H_ diff --git a/chrome/browser/extensions/extension_infobar_module_constants.cc b/chrome/browser/extensions/extension_infobar_module_constants.cc new file mode 100644 index 0000000..d628c48 --- /dev/null +++ b/chrome/browser/extensions/extension_infobar_module_constants.cc @@ -0,0 +1,15 @@ +// Copyright (c) 2010 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_infobar_module_constants.h" + +namespace extension_infobar_module_constants { + +const wchar_t kHtmlPath[] = L"htmlPath"; +const wchar_t kTabId[] = L"tabId"; + +const char kNoCurrentWindowError[] = "No current browser window was found"; +const char kTabNotFoundError[] = "Specified tab (or default tab) not found"; + +} // namespace extension_infobar_module_constants diff --git a/chrome/browser/extensions/extension_infobar_module_constants.h b/chrome/browser/extensions/extension_infobar_module_constants.h new file mode 100644 index 0000000..4af86b8 --- /dev/null +++ b/chrome/browser/extensions/extension_infobar_module_constants.h @@ -0,0 +1,22 @@ +// Copyright (c) 2010 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. + +// Constants used for the InfoBar API. + +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_MODULE_CONSTANTS_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_MODULE_CONSTANTS_H_ + +namespace extension_infobar_module_constants { + +// Keys. +extern const wchar_t kHtmlPath[]; +extern const wchar_t kTabId[]; + +// Errors. +extern const char kNoCurrentWindowError[]; +extern const char kTabNotFoundError[]; + +}; // namespace extension_infobar_module_constants + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_MODULE_CONSTANTS_H_ diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc index 410165f..7432102 100644 --- a/chrome/browser/extensions/extension_process_manager.cc +++ b/chrome/browser/extensions/extension_process_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -119,6 +119,17 @@ ExtensionHost* ExtensionProcessManager::CreatePopup(const GURL& url, return CreateView(url, browser, ViewType::EXTENSION_POPUP); } +ExtensionHost* ExtensionProcessManager::CreateInfobar(Extension* extension, + const GURL& url, + Browser* browser) { + return CreateView(extension, url, browser, ViewType::EXTENSION_INFOBAR); +} + +ExtensionHost* ExtensionProcessManager::CreateInfobar(const GURL& url, + Browser* browser) { + return CreateView(url, browser, ViewType::EXTENSION_INFOBAR); +} + ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( Extension* extension, const GURL& url) { ExtensionHost* host = diff --git a/chrome/browser/extensions/extension_process_manager.h b/chrome/browser/extensions/extension_process_manager.h index d002cb9..64061c0 100644 --- a/chrome/browser/extensions/extension_process_manager.h +++ b/chrome/browser/extensions/extension_process_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -50,6 +50,11 @@ class ExtensionProcessManager : public NotificationObserver { const GURL& url, Browser* browser); ExtensionHost* CreatePopup(const GURL& url, Browser* browser); + ExtensionHost* CreateInfobar(Extension* extension, + const GURL& url, + Browser* browser); + ExtensionHost* CreateInfobar(const GURL& url, + Browser* browser); // Creates a new UI-less extension instance. Like CreateView, but not // displayed anywhere. diff --git a/chrome/browser/resources/extensions_infobar.css b/chrome/browser/resources/extensions_infobar.css new file mode 100644 index 0000000..dcf4303 --- /dev/null +++ b/chrome/browser/resources/extensions_infobar.css @@ -0,0 +1,13 @@ +/**
+ * The following style rules affect Extension Infobars.
+ */
+
+body {
+ background: -webkit-gradient(linear, left top, left bottom,
+ from(#DAE7F9), to(#B5CBE8));
+ font-family: Segoe UI, Tahoma;
+ font-size: 11px;
+ height: 36px; /* Infobars are limited to 36-72px */
+ margin: 0px;
+ overflow: hidden;
+}
diff --git a/chrome/browser/tab_contents/infobar_delegate.h b/chrome/browser/tab_contents/infobar_delegate.h index fcaa621..41e09ce 100644 --- a/chrome/browser/tab_contents/infobar_delegate.h +++ b/chrome/browser/tab_contents/infobar_delegate.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -14,6 +14,7 @@ class AlertInfoBarDelegate; class ConfirmInfoBarDelegate; class CrashedExtensionInfoBarDelegate; +class ExtensionInfoBarDelegate; class TranslateInfoBarDelegate; class InfoBar; class LinkInfoBarDelegate; @@ -111,6 +112,12 @@ class InfoBarDelegate { return NULL; } + // Returns a pointer to the ExtensionInfoBarDelegate interface, if + // implemented. + virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() { + return NULL; + } + // Returns a pointer to the CrashedExtensionInfoBarDelegate interface, if // implemented. virtual CrashedExtensionInfoBarDelegate* AsCrashedExtensionInfoBarDelegate() { diff --git a/chrome/browser/views/infobars/extension_infobar.cc b/chrome/browser/views/infobars/extension_infobar.cc new file mode 100644 index 0000000..70f3f7f --- /dev/null +++ b/chrome/browser/views/infobars/extension_infobar.cc @@ -0,0 +1,143 @@ +// Copyright (c) 2010 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/views/infobars/extension_infobar.h" + +#include "app/gfx/canvas.h" +#include "app/resource_bundle.h" +#include "app/slide_animation.h" +#include "chrome/browser/extensions/extension_action_context_menu_model.h" +#include "chrome/browser/extensions/extension_infobar_delegate.h" +#include "chrome/browser/extensions/extension_host.h" +#include "chrome/common/extensions/extension.h" +#include "grit/browser_resources.h" +#include "grit/theme_resources.h" +#include "views/controls/button/menu_button.h" +#include "views/controls/menu/menu_2.h" + +// The horizontal margin between the menu and the Extension (HTML) view. +static const int kMenuHorizontalMargin = 1; + +// The amount of space to the right of the Extension (HTML) view (to avoid +// overlapping the close button for the InfoBar). +static const int kFarRightMargin = 30; + +// The margin between the extension icon and the drop-down arrow bitmap. +static const int kDropArrowLeftMargin = 3; + +ExtensionInfoBar::ExtensionInfoBar(ExtensionInfoBarDelegate* delegate) + : InfoBar(delegate), + delegate_(delegate) { + ExtensionHost* extension_host = delegate_->extension_host(); + + // We set the target height for the InfoBar to be the height of the + // ExtensionView it contains (plus 1 because the view should not overlap the + // separator line at the bottom). When the InfoBar is first created, however, + // this value is 0 but becomes positive after the InfoBar has been shown. See + // function: OnExtensionPreferredSizeChanged. + gfx::Size sz = extension_host->view()->GetPreferredSize(); + if (sz.height() > 0) + sz.set_height(sz.height() + 1); + set_target_height(sz.height()); + + // Setup the extension icon and its associated drop down menu. + SetupIconAndMenu(); + + // Get notified of resize events for the ExtensionView. + extension_host->view()->SetContainer(this); + // We show the ExtensionView, but we don't want it deleted when we get + // destroyed, which happens on tab switching (for example). + extension_host->view()->set_parent_owned(false); + AddChildView(extension_host->view()); +} + +ExtensionInfoBar::~ExtensionInfoBar() { +} + +void ExtensionInfoBar::OnExtensionPreferredSizeChanged(ExtensionView* view) { + DCHECK(view == delegate_->extension_host()->view()); + delegate_->extension_host()->view()->SetVisible(true); + + gfx::Size sz = view->GetPreferredSize(); + // Clamp height to a min and a max size of between 1 and 2 InfoBars. + int default_height = static_cast<int>(InfoBar::kDefaultTargetHeight); + sz.set_height(std::max(default_height, sz.height())); + sz.set_height(std::min(2 * default_height, sz.height())); + + if (height() == 0) + animation()->Reset(0.0); + set_target_height(sz.height()); + animation()->Show(); +} + +void ExtensionInfoBar::Layout() { + // Layout the close button and the background. + InfoBar::Layout(); + + // Layout the extension icon + drop down menu. + int x = 0; + gfx::Size sz = menu_->GetPreferredSize(); + menu_->SetBounds(x, + (height() - sz.height()) / 2, + sz.width(), sz.height()); + x += sz.width() + kMenuHorizontalMargin; + + // Layout the ExtensionView, showing the HTML InfoBar. + ExtensionView* view = delegate_->extension_host()->view(); + view->SetBounds(x, 0, width() - x - kFarRightMargin - 1, height() - 1); +} + +void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) { + if (!options_menu_contents_.get()) { + options_menu_contents_.reset(new ExtensionActionContextMenuModel( + delegate_->extension_host()->extension())); + } + options_menu_menu_.reset(new views::Menu2(options_menu_contents_.get())); + options_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPLEFT); +} + +void ExtensionInfoBar::SetupIconAndMenu() { + SkBitmap icon; + + ExtensionResource icon_resource; + Extension::Icons size = delegate_->extension_host()->extension()-> + GetIconPathAllowLargerSize(&icon_resource, + Extension::EXTENSION_ICON_BITTY); + if (!icon_resource.GetFilePath().empty()) { + scoped_ptr<SkBitmap> bitmap; + Extension::DecodeIconFromPath(icon_resource.GetFilePath(), size, &bitmap); + if (bitmap.get()) + icon = *bitmap.release(); + } + + // Failure to get the path or failure to decode it causes fall-back to the + // default extension icon. + if (icon.empty()) { + icon = *ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_EXTENSION_DEFAULT_ICON); + } + + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); + menu_ = new views::MenuButton(NULL, std::wstring(), this, false); + + int image_size = Extension::EXTENSION_ICON_BITTY; + scoped_ptr<gfx::Canvas> canvas( + new gfx::Canvas(image_size + kDropArrowLeftMargin + drop_image->width(), + image_size, false)); + canvas->DrawBitmapInt(icon, + 0, 0, icon.width(), icon.height(), + 0, 0, image_size, image_size, + false); + canvas->DrawBitmapInt(*drop_image, + image_size + kDropArrowLeftMargin, + image_size / 2); + menu_->SetIcon(canvas->ExtractBitmap()); + + AddChildView(menu_); +} + +InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() { + return new ExtensionInfoBar(this); +} diff --git a/chrome/browser/views/infobars/extension_infobar.h b/chrome/browser/views/infobars/extension_infobar.h new file mode 100644 index 0000000..0f0a64c --- /dev/null +++ b/chrome/browser/views/infobars/extension_infobar.h @@ -0,0 +1,57 @@ +// Copyright (c) 2010 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_VIEWS_INFOBARS_EXTENSION_INFOBAR_H_ +#define CHROME_BROWSER_VIEWS_INFOBARS_EXTENSION_INFOBAR_H_ + +#include "chrome/browser/views/infobars/infobars.h" + +#include "chrome/browser/views/extensions/extension_view.h" +#include "views/controls/menu/view_menu_delegate.h" + +class ExtensionActionContextMenuModel; +class ExtensionInfoBarDelegate; + +namespace views { + class MenuButton; + class Menu2; +} + +// This class implements InfoBars for Extensions. +class ExtensionInfoBar : public InfoBar, + public ExtensionView::Container, + public views::ViewMenuDelegate { + public: + explicit ExtensionInfoBar(ExtensionInfoBarDelegate* delegate); + virtual ~ExtensionInfoBar(); + + // Overridden from ExtensionView::Container: + virtual void OnExtensionMouseEvent(ExtensionView* view) {} + virtual void OnExtensionMouseLeave(ExtensionView* view) {} + virtual void OnExtensionPreferredSizeChanged(ExtensionView* view); + + // Overridden from views::View: + virtual void Layout(); + + // Overridden from views::ViewMenuDelegate: + virtual void RunMenu(View* source, const gfx::Point& pt); + + private: + // Setup the menu button showing the small extension icon and its dropdown + // menu. + void SetupIconAndMenu(); + + NotificationRegistrar notification_registrar_; + + ExtensionInfoBarDelegate* delegate_; + + // The dropdown menu for accessing the contextual extension actions. + scoped_ptr<ExtensionActionContextMenuModel> options_menu_contents_; + scoped_ptr<views::Menu2> options_menu_menu_; + views::MenuButton* menu_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBar); +}; + +#endif // CHROME_BROWSER_VIEWS_INFOBARS_EXTENSION_INFOBAR_H_ diff --git a/chrome/browser/views/infobars/infobars.cc b/chrome/browser/views/infobars/infobars.cc index f70288e..6ddffc3 100644 --- a/chrome/browser/views/infobars/infobars.cc +++ b/chrome/browser/views/infobars/infobars.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -25,7 +25,7 @@ #include "views/widget/widget.h" // static -const double InfoBar::kTargetHeight = 36.0; +const double InfoBar::kDefaultTargetHeight = 36.0; const int InfoBar::kHorizontalPadding = 6; const int InfoBar::kIconLabelSpacing = 6; const int InfoBar::kButtonButtonSpacing = 10; @@ -107,7 +107,8 @@ InfoBar::InfoBar(InfoBarDelegate* delegate) : delegate_(delegate), ALLOW_THIS_IN_INITIALIZER_LIST( close_button_(new views::ImageButton(this))), - ALLOW_THIS_IN_INITIALIZER_LIST(delete_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(delete_factory_(this)), + target_height_(kDefaultTargetHeight) { // We delete ourselves when we're removed from the view hierarchy. set_parent_owned(false); @@ -167,7 +168,7 @@ void InfoBar::Close() { // InfoBar, views::View overrides: --------------------------------------------- gfx::Size InfoBar::GetPreferredSize() { - int height = static_cast<int>(kTargetHeight * animation_->GetCurrentValue()); + int height = static_cast<int>(target_height_ * animation_->GetCurrentValue()); return gfx::Size(0, height); } @@ -200,13 +201,13 @@ void InfoBar::RemoveInfoBar() const { } int InfoBar::CenterY(const gfx::Size prefsize) { - return std::max((static_cast<int>(InfoBar::kTargetHeight) - + return std::max((static_cast<int>(target_height_) - prefsize.height()) / 2, 0); } int InfoBar::OffsetY(views::View* parent, const gfx::Size prefsize) { return CenterY(prefsize) - - (static_cast<int>(InfoBar::kTargetHeight) - parent->height()); + (static_cast<int>(target_height_) - parent->height()); } // InfoBar, views::ButtonListener implementation: ------------------ @@ -295,7 +296,6 @@ AlertInfoBar::AlertInfoBar(AlertInfoBarDelegate* delegate) } AlertInfoBar::~AlertInfoBar() { - } // AlertInfoBar, views::View overrides: ---------------------------------------- diff --git a/chrome/browser/views/infobars/infobars.h b/chrome/browser/views/infobars/infobars.h index 970b1ab..7d04904 100644 --- a/chrome/browser/views/infobars/infobars.h +++ b/chrome/browser/views/infobars/infobars.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -52,9 +52,9 @@ class InfoBar : public views::View, // is called. void Close(); - // The target height of the infobar, regardless of what its current height + // The target height of the InfoBar, regardless of what its current height // is (due to animation). - static const double kTargetHeight; + static const double kDefaultTargetHeight; static const int kHorizontalPadding; static const int kIconLabelSpacing; @@ -81,6 +81,10 @@ class InfoBar : public views::View, // (Will lead to this InfoBar being closed). void RemoveInfoBar() const; + void set_target_height(double height) { target_height_ = height; } + + SlideAnimation* animation() { return animation_.get(); } + // Returns a centered y-position of a control of height specified in // |prefsize| within the standard InfoBar height. Stable during an animation. int CenterY(const gfx::Size prefsize); @@ -132,6 +136,9 @@ class InfoBar : public views::View, // Used to delete this object after a return to the message loop. ScopedRunnableMethodFactory<InfoBar> delete_factory_; + // The target height for the InfoBar. + double target_height_; + DISALLOW_COPY_AND_ASSIGN(InfoBar); }; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index f3058c9..7b80752 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -940,6 +940,12 @@ 'browser/extensions/extension_idle_api_constants.h', 'browser/extensions/extension_i18n_api.cc', 'browser/extensions/extension_i18n_api.h', + 'browser/extensions/extension_infobar_module.cc', + 'browser/extensions/extension_infobar_module.h', + 'browser/extensions/extension_infobar_module_constants.cc', + 'browser/extensions/extension_infobar_module_constants.h', + 'browser/extensions/extension_infobar_delegate.cc', + 'browser/extensions/extension_infobar_delegate.h', 'browser/extensions/extension_install_ui.cc', 'browser/extensions/extension_install_ui.h', 'browser/extensions/extension_message_service.cc', @@ -2150,6 +2156,8 @@ 'browser/views/importing_progress_view.h', 'browser/views/info_bubble.cc', 'browser/views/info_bubble.h', + 'browser/views/infobars/extension_infobar.cc', + 'browser/views/infobars/extension_infobar.h', 'browser/views/infobars/infobar_container.cc', 'browser/views/infobars/infobar_container.h', 'browser/views/infobars/infobars.cc', diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index c53700d..afdfc24 100755 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -1392,6 +1392,44 @@ ] }, { + "namespace": "experimental.infoBar", + "types": [], + "functions": [ + { + "name": "show", + "type": "function", + "description": "Shows an infobar in the specified tab.", + "parameters": [ + { + "name": "details", + "type": "object", + "properties": { + "tabId": { + "type": "integer", + "description": "The tab id for the tab to display the infobar in. If not specified the current tab will be used.", + "optional": true + }, + "htmlPath": { + "type": "string", + "description": "The html file that contains the infobar." + } + } + }, + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "window", "$ref": "Window", "description": "Contains details about the window in which the infobar was created.", + "optional": true + } + ] + } + ] + } + ] + }, + { "namespace": "bookmarks", "types": [ { diff --git a/chrome/common/extensions/docs/experimental.html b/chrome/common/extensions/docs/experimental.html index a79f3b0..e24fd23 100644 --- a/chrome/common/extensions/docs/experimental.html +++ b/chrome/common/extensions/docs/experimental.html @@ -253,7 +253,7 @@ on the following experimental APIs: </p> <ul> - <li><a href="experimental.history.html" js="">experimental.history</a></li><li><a href="experimental.processes.html" js="">experimental.processes</a></li> + <li><a href="experimental.history.html" js="">experimental.history</a></li><li><a href="experimental.infoBar.html" js="">experimental.infoBar</a></li><li><a href="experimental.processes.html" js="">experimental.processes</a></li> </ul> <p class="caution"> diff --git a/chrome/common/extensions/docs/experimental.infoBar.html b/chrome/common/extensions/docs/experimental.infoBar.html new file mode 100644 index 0000000..02a86cb --- /dev/null +++ b/chrome/common/extensions/docs/experimental.infoBar.html @@ -0,0 +1,634 @@ +<!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. + 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. +--><html xmlns="http://www.w3.org/1999/xhtml"><head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <link href="css/ApiRefStyles.css" rel="stylesheet" type="text/css"> + <link href="css/print.css" rel="stylesheet" type="text/css" media="print"> + <script type="text/javascript" src="../../../third_party/jstemplate/jstemplate_compiled.js"> + </script> + <script type="text/javascript" src="js/api_page_generator.js"></script> + <script type="text/javascript" src="js/bootstrap.js"></script> + <title>chrome.experimental.infoBar - Google Chrome Extensions - Google Code</title></head><body> <div id="gc-container" class="labs"> + <!-- SUBTEMPLATES: DO NOT MOVE FROM THIS LOCATION --> + <!-- In particular, sub-templates that recurse, must be used by allowing + jstemplate to make a copy of the template in this section which + are not operated on by way of the jsskip="true" --> + <div style="display:none"> + + <!-- VALUE --> + <div id="valueTemplate"> + <dt> + <var>paramName</var> + <em> + + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional">optional</span> + <span id="typeTemplate"> + <span> + <a> Type</a> + </span> + <span> + <span> + array of <span><span></span></span> + </span> + <span>paramType</span> + </span> + </span> + ) + </div> + + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <dd> + Description of this parameter from the json schema. + </dd> + + <!-- OBJECT PROPERTIES --> + <dd> + <dl> + <div> + <div> + </div> + </div> + </dl> + </dd> + </div> <!-- /VALUE --> + + </div> <!-- /SUBTEMPLATES --> + + <a id="top"></a> + <div id="skipto"> + <a href="#gc-pagecontent">Skip to page content</a> + <a href="#gc-toc">Skip to main navigation</a> + </div> + <!-- API HEADER --> + <table id="header" width="100%" cellspacing="0" border="0"> + <tbody><tr> + <td valign="middle"><a href="http://code.google.com/"><img src="images/code_labs_logo.gif" height="43" width="161" alt="Google Code Labs" style="border:0; margin:0;"></a></td> + <td valign="middle" width="100%" style="padding-left:0.6em;"> + <form action="http://www.google.com/cse" id="cse" style="margin-top:0.5em"> + <div id="gsc-search-box"> + <input type="hidden" name="cx" value="002967670403910741006:61_cvzfqtno"> + <input type="hidden" name="ie" value="UTF-8"> + <input type="text" name="q" value="" size="55"> + <input class="gsc-search-button" type="submit" name="sa" value="Search"> + <br> + <span class="greytext">e.g. "page action" or "tabs"</span> + </div> + </form> + + <script type="text/javascript" src="http://www.google.com/jsapi"></script> + <script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script> + <script type="text/javascript" src="http://www.google.com/coop/cse/t13n?form=cse&t13n_langs=en"></script> + <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse&lang=en"></script> + </td> + </tr> + </tbody></table> + + <div id="codesiteContent" class=""> + + <a id="gc-topnav-anchor"></a> + <div id="gc-topnav"> + <h1>Google Chrome Extensions (<a href="http://code.google.com/labs/">Labs</a>)</h1> + <ul id="home" class="gc-topnav-tabs"> + <li id="home_link"> + <a href="index.html" title="Google Chrome Extensions home page">Home</a> + </li> + <li id="docs_link"> + <a href="docs.html" title="Official Google Chrome Extensions documentation">Docs</a> + </li> + <li id="faq_link"> + <a href="faq.html" title="Answers to frequently asked questions about Google Chrome Extensions">FAQ</a> + </li> + <li id="samples_link"> + <a href="samples.html" title="Sample extensions (with source code)">Samples</a> + </li> + <li id="group_link"> + <a href="http://groups.google.com/a/chromium.org/group/chromium-extensions" title="Google Chrome Extensions developer forum">Group</a> + </li> + </ul> + </div> <!-- end gc-topnav --> + + <div class="g-section g-tpl-170"> + <!-- SIDENAV --> + <div class="g-unit g-first" id="gc-toc"> + <ul> + <li><a href="getstarted.html">Getting Started</a></li> + <li><a href="overview.html">Overview</a></li> + <li><h2><a href="devguide.html">Developer's Guide</a></h2> + <ul> + <li>Browser UI + <ul> + <li><a href="browserAction.html">Browser Actions</a></li> + <li><a href="options.html">Options Pages</a></li> + <li><a href="override.html">Override Pages</a></li> + <li><a href="pageAction.html">Page Actions</a></li> + <li><a href="themes.html">Themes</a></li> + </ul> + </li> + <li>Browser Interaction + <ul> + <li><a href="bookmarks.html">Bookmarks</a></li> + <li><a href="events.html">Events</a></li> + <li><a href="tabs.html">Tabs</a></li> + <li><a href="windows.html">Windows</a></li> + </ul> + </li> + <li>Implementation + <ul> + <li><a href="background_pages.html">Background Pages</a></li> + <li><a href="content_scripts.html">Content Scripts</a></li> + <li><a href="xhr.html">Cross-Origin XHR</a></li> + <li><a href="i18n.html">Internationalization</a></li> + <li><a href="messaging.html">Message Passing</a></li> + <li><a href="npapi.html">NPAPI Plugins</a></li> + </ul> + </li> + <li>Finishing + <ul> + <li><a href="autoupdate.html">Autoupdating</a></li> + <li><a href="packaging.html">Packaging</a></li> + <li><a href="external_extensions.html">External Extensions</a></li> + </ul> + </li> + </ul> + </li> + <li><h2><a href="tutorials.html">Tutorials</a></h2> + <ul> + <li><a href="tut_debugging.html">Debugging</a></li> + </ul> + </li> + <li><h2>Reference</h2> + <ul> + <li>Formats + <ul> + <li><a href="manifest.html">Manifest Files</a></li> + <li><a href="match_patterns.html">Match Patterns</a></li> + <!-- <li>Packages (.crx)</li> --> + </ul> + </li> + <li><a href="api_index.html">chrome.* APIs</a></li> + <li><a href="api_other.html">Other APIs</a></li> + </ul> + </li> + <li><h2><a href="samples.html">Samples</a></h2></li> + </ul> + </div> + + <div class="g-unit" id="gc-pagecontent"> + <div id="pageTitle"> + <h1 class="page_title">chrome.experimental.infoBar</h1> + </div> + <!-- TABLE OF CONTENTS --> + <div id="toc"> + <h2>Contents</h2> + <ol> + <li style="display: none; "> + <a>h2Name</a> + <ol> + <li> + <a>h3Name</a> + </li> + </ol> + </li> + <li> + <a href="#apiReference">API reference: chrome.experimental.infoBar</a> + <ol> + <li style="display: none; "> + <a href="#properties">Properties</a> + <ol> + <li> + <a href="#property-anchor">propertyName</a> + </li> + </ol> + </li> + <li> + <a href="#methods">Methods</a> + <ol> + <li> + <a href="#method-show">show</a> + </li> + </ol> + </li> + <li style="display: none; "> + <a href="#events">Events</a> + <ol> + <li> + <a href="#event-anchor">eventName</a> + </li> + </ol> + </li> + <li style="display: none; "> + <a href="#types">Types</a> + <ol> + <li> + <a href="#id-anchor">id</a> + </li> + </ol> + </li> + </ol> + </li> + </ol> + </div> + <!-- /TABLE OF CONTENTS --> + + <!-- STATIC CONTENT PLACEHOLDER --> + <div id="static"></div> + + <!-- API PAGE --> + <div class="apiPage"> + <a name="apiReference"></a> + <h2>API reference: chrome.experimental.infoBar</h2> + + <!-- PROPERTIES --> + <div class="apiGroup" style="display: none; "> + <a name="properties"></a> + <h3 id="properties">Properties</h3> + + <div> + <a></a> + <h4>getLastError</h4> + <div class="summary"> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.extension</span><span>lastError</span> + </div> + <div> + </div> + </div> + + </div> <!-- /apiGroup --> + + <!-- METHODS --> + <div class="apiGroup" id="methods"> + <a name="methods"></a> + <h3>Methods</h3> + + <!-- iterates over all functions --> + <div class="apiItem"> + <a name="method-show"></a> <!-- method-anchor --> + <h4>show</h4> + + <div class="summary"><span style="display: none; ">void</span> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.experimental.infoBar.show</span>(<span class="null"><span style="display: none; ">, </span><span>object</span> + <var><span>details</span></var></span><span class="null"><span>, </span><span>function</span> + <var><span>callback</span></var></span>)</div> + + <div class="description"> + <p class="todo" style="display: none; ">Undocumented.</p> + <p>Shows an infobar in the specified tab.</p> + + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + <dt> + <var>details</var> + <em> + + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional" style="display: none; ">optional</span> + <span id="typeTemplate"> + <span style="display: none; "> + <a> Type</a> + </span> + <span> + <span style="display: none; "> + array of <span><span></span></span> + </span> + <span>object</span> + </span> + </span> + ) + </div> + + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <dd style="display: none; "> + Description of this parameter from the json schema. + </dd> + + <!-- OBJECT PROPERTIES --> + <dd> + <dl> + <div> + <div> + <dt> + <var>tabId</var> + <em> + + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional">optional</span> + <span id="typeTemplate"> + <span style="display: none; "> + <a> Type</a> + </span> + <span> + <span style="display: none; "> + array of <span><span></span></span> + </span> + <span>integer</span> + </span> + </span> + ) + </div> + + </em> + </dt> + <dd class="todo" style="display: none; "> + Undocumented. + </dd> + <dd>The tab id for the tab to display the infobar in. If not specified the current tab will be used.</dd> + + <!-- OBJECT PROPERTIES --> + <dd style="display: none; "> + <dl> + <div> + <div> + </div> + </div> + </dl> + </dd> + </div> + </div><div> + <div> + <dt> + <var>htmlPath</var> + <em> + + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional" style="display: none; ">optional</span> + <span id="typeTemplate"> + <span style="display: none; "> + <a> Type</a> + </span> + <span> + <span style="display: none; "> + array of <span><span></span></span> + </span> + <span>string</span> + </span> + </span> + ) + </div> + + </em> + </dt> + <dd class="todo" style="display: none; "> + Undocumented. + </dd> + <dd>The html file that contains the infobar.</dd> + + <!-- OBJECT PROPERTIES --> + <dd style="display: none; "> + <dl> + <div> + <div> + </div> + </div> + </dl> + </dd> + </div> + </div> + </dl> + </dd> + </div> + </div><div> + <div> + <dt> + <var>callback</var> + <em> + + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional" style="display: none; ">optional</span> + <span id="typeTemplate"> + <span style="display: none; "> + <a> Type</a> + </span> + <span> + <span style="display: none; "> + array of <span><span></span></span> + </span> + <span>function</span> + </span> + </span> + ) + </div> + + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <dd style="display: none; "> + Description of this parameter from the json schema. + </dd> + + <!-- OBJECT PROPERTIES --> + <dd style="display: none; "> + <dl> + <div> + <div> + </div> + </div> + </dl> + </dd> + </div> + </div> + </dl> + + <!-- RETURNS --> + <h4 style="display: none; ">Returns</h4> + <dl> + <div style="display: none; "> + <div> + </div> + </div> + </dl> + + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <p style="display: none; "> + If you specify the <em>callback</em> parameter, it should + specify a function that looks like this: + </p> + + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>Window window</span>) <span class="subdued">{...}</span>);</pre> + <dl> + <div> + <div> + <dt> + <var>window</var> + <em> + + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional">optional</span> + <span id="typeTemplate"> + <span> + <a href="windows.html#type-Window">Window</a> + </span> + <span style="display: none; "> + <span> + array of <span><span></span></span> + </span> + <span>paramType</span> + </span> + </span> + ) + </div> + + </em> + </dt> + <dd class="todo" style="display: none; "> + Undocumented. + </dd> + <dd>Contains details about the window in which the infobar was created.</dd> + + <!-- OBJECT PROPERTIES --> + <dd style="display: none; "> + <dl> + <div> + <div> + </div> + </div> + </dl> + </dd> + </div> + </div> + </dl> + </div> + </div> + + </div> <!-- /description --> + + </div> <!-- /apiItem --> + + </div> <!-- /apiGroup --> + + <!-- EVENTS --> + <div class="apiGroup" style="display: none; "> + <a name="events"></a> + <h3 id="events">Events</h3> + + <!-- iterates over all events --> + <div class="apiItem"> + <a></a> + <h4>event name</h4> + + <div class="summary"> + <!-- Note: intentionally longer 80 columns --> + <span class="subdued">chrome.bookmarks</span><span>onEvent</span><span class="subdued">.addListener</span>(function(<span>Type param1, Type param2</span>) <span class="subdued">{...}</span>); + </div> + + <div class="description"> + <p class="todo">Undocumented.</p> + <p> + A description from the json schema def of the event goes here. + </p> + + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + </div> + </div> + </dl> + + </div> <!-- /decription --> + + </div> <!-- /apiItem --> + + </div> <!-- /apiGroup --> + + <!-- TYPES --> + <div class="apiGroup" style="display: none; "> + <a name="types.sort(sortByName)"></a> + <h3 id="types">Types</h3> + + <!-- iterates over all types --> + <div class="apiItem"> + <a></a> + <h4>type name</h4> + + <div> + </div> + + </div> <!-- /apiItem --> + + </div> <!-- /apiGroup --> + + </div> <!-- /apiPage --> + </div> <!-- /gc-pagecontent --> + </div> <!-- /g-section --> + </div> <!-- /codesiteContent --> + <div id="gc-footer" --=""> + <div class="text"> + <p> + Except as otherwise <a href="http://code.google.com/policies.html#restrictions">noted</a>, + the content of this page is licensed under the <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons + Attribution 3.0 License</a>, and code samples are licensed under the + <a rel="license" href="http://code.google.com/google_bsd_license.html">BSD License</a>. + </p> + <p> + ©2009 Google + </p> + +<!-- begin analytics --> +<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script> +<script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script> + +<script type="text/javascript"> + // chrome doc tracking + try { + var engdocs = _gat._getTracker("YT-10763712-2"); + engdocs._trackPageview(); + } catch(err) {} + + // code.google.com site-wide tracking + try { + _uacct="UA-18071-1"; + _uanchor=1; + _uff=0; + urchinTracker(); + } + catch(e) {/* urchinTracker not available. */} +</script> +<!-- end analytics --> + </div> + </div> <!-- /gc-footer --> + </div> <!-- /gc-container --> +</body></html> diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index a15669d..b12c764 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -1380,6 +1380,20 @@ ExtensionResource Extension::GetIconPath(Icons icon) { return GetResource(iter->second); } +Extension::Icons Extension::GetIconPathAllowLargerSize( + ExtensionResource* resource, Icons icon) { + *resource = GetIconPath(icon); + if (!resource->GetFilePath().empty()) + return icon; + if (icon == EXTENSION_ICON_BITTY) + return GetIconPathAllowLargerSize(resource, EXTENSION_ICON_SMALL); + if (icon == EXTENSION_ICON_SMALL) + return GetIconPathAllowLargerSize(resource, EXTENSION_ICON_MEDIUM); + if (icon == EXTENSION_ICON_MEDIUM) + return GetIconPathAllowLargerSize(resource, EXTENSION_ICON_LARGE); + return EXTENSION_ICON_LARGE; +} + bool Extension::CanExecuteScriptOnHost(const GURL& url, std::string* error) const { // No extensions are allowed to execute script on the gallery because that diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 51d6931..50fe957 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -270,6 +270,13 @@ class Extension { // an empty FilePath if the extension does not have that icon. ExtensionResource GetIconPath(Icons icon); + // Looks for an extension icon of dimension |icon|. If not found, checks if + // the next larger size exists (until one is found or the end is reached). If + // an icon is found, the path is returned in |resource| and the dimension + // found is returned to the caller (as function return value). + // NOTE: |resource| is not guaranteed to be non-empty. + Icons GetIconPathAllowLargerSize(ExtensionResource* resource, Icons icon); + const DictionaryValue* manifest_value() const { return manifest_value_.get(); } diff --git a/chrome/common/extensions/extension_action.h b/chrome/common/extensions/extension_action.h index 9fbbff4..6658724 100644 --- a/chrome/common/extensions/extension_action.h +++ b/chrome/common/extensions/extension_action.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -132,7 +132,7 @@ class ExtensionAction { void SetBadgeBackgroundColor(int tab_id, const SkColor& color) { SetValue(&badge_background_color_, tab_id, color); } - // Get the badge backround color for a tab, or the default if no color + // Get the badge background color for a tab, or the default if no color // was set. SkColor GetBadgeBackgroundColor(int tab_id) { return GetValue(&badge_background_color_, tab_id); diff --git a/chrome/common/view_types.cc b/chrome/common/view_types.cc index 8d212ca..5dff5b0 100644 --- a/chrome/common/view_types.cc +++ b/chrome/common/view_types.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -9,6 +9,7 @@ const char* ViewType::kToolstrip = "TOOLSTRIP"; const char* ViewType::kMole = "MOLE"; const char* ViewType::kBackgroundPage = "BACKGROUND"; const char* ViewType::kPopup = "POPUP"; +const char* ViewType::kInfobar = "INFOBAR"; const char* ViewType::kAll = "ALL"; bool ViewType::ShouldAutoResize(ViewType::Type view_type) { diff --git a/chrome/common/view_types.h b/chrome/common/view_types.h index fd94a69..6db4161 100644 --- a/chrome/common/view_types.h +++ b/chrome/common/view_types.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -17,6 +17,7 @@ class ViewType { EXTENSION_MOLE, EXTENSION_BACKGROUND_PAGE, EXTENSION_POPUP, + EXTENSION_INFOBAR, DEV_TOOLS_UI, INTERSTITIAL_PAGE, }; @@ -28,6 +29,7 @@ class ViewType { static const char* kMole; static const char* kBackgroundPage; static const char* kPopup; + static const char* kInfobar; static const char* kAll; // Return true if a view type should automatically resize to fit its contents. diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js index ba6f314..ac487c5 100644 --- a/chrome/renderer/resources/renderer_extension_bindings.js +++ b/chrome/renderer/resources/renderer_extension_bindings.js @@ -249,6 +249,7 @@ var chrome = chrome || {}; "experimental.extension", "experimental.idle", "experimental.history", + "experimental.infoBar", "experimental.metrics", "experimental.popup", "experimental.processes", |