diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 23:48:43 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 23:48:43 +0000 |
commit | e2a284e6c009801faef4dae663649cc14335539e (patch) | |
tree | 102f7d2c52fc99ca7b526ed016b6fd2d5204c97b /chrome | |
parent | e444c95bb327f0addaa066df4356268cf84bfb46 (diff) | |
download | chromium_src-e2a284e6c009801faef4dae663649cc14335539e.zip chromium_src-e2a284e6c009801faef4dae663649cc14335539e.tar.gz chromium_src-e2a284e6c009801faef4dae663649cc14335539e.tar.bz2 |
GTK: New extension install prompt ui.
BUG=29633
TEST=manual
Review URL: http://codereview.chromium.org/1513002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43144 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/extensions/extension_install_ui.cc | 46 | ||||
-rwxr-xr-x | chrome/browser/extensions/extension_install_ui.h | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/extension_install_prompt2_gtk.cc | 169 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 1 |
4 files changed, 199 insertions, 23 deletions
diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc index 3accc44..257f667d 100644 --- a/chrome/browser/extensions/extension_install_ui.cc +++ b/chrome/browser/extensions/extension_install_ui.cc @@ -82,6 +82,9 @@ static bool ExtensionHasFileAccess(Extension* extension) { return false; } +// TODO(estade): remove this function when the old install UI is removed. It +// is commented out on linux/gtk due to compiler warnings. +#if !defined(TOOLKIT_GTK) static std::wstring GetInstallWarning(Extension* extension) { // If the extension has a plugin, it's easy: the plugin has the most severe // warning. @@ -126,51 +129,54 @@ static std::wstring GetInstallWarning(Extension* extension) { else return l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_BROWSER); } +#endif -#if defined(OS_WIN) +#if defined(OS_WIN) || defined(TOOLKIT_GTK) static void GetV2Warnings(Extension* extension, - std::vector<std::wstring>* warnings) { + std::vector<string16>* warnings) { if (!extension->plugins().empty() || ExtensionHasFileAccess(extension)) { // TODO(aa): This one is a bit awkward. Should we have a separate // presentation for this case? warnings->push_back( - l10n_util::GetString(IDS_EXTENSION_PROMPT2_WARNING_FULL_ACCESS)); + l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT2_WARNING_FULL_ACCESS)); return; } if (extension->HasAccessToAllHosts()) { warnings->push_back( - l10n_util::GetString(IDS_EXTENSION_PROMPT2_WARNING_ALL_HOSTS)); + l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT2_WARNING_ALL_HOSTS)); } else { std::set<std::string> hosts = extension->GetEffectiveHostPermissions(); if (hosts.size() == 1) { warnings->push_back( - l10n_util::GetStringF(IDS_EXTENSION_PROMPT2_WARNING_1_HOST, - UTF8ToWide(*hosts.begin()))); + l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT2_WARNING_1_HOST, + UTF8ToUTF16(*hosts.begin()))); } else if (hosts.size() == 2) { warnings->push_back( - l10n_util::GetStringF(IDS_EXTENSION_PROMPT2_WARNING_2_HOSTS, - UTF8ToWide(*hosts.begin()), - UTF8ToWide(*(++hosts.begin())))); + l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT2_WARNING_2_HOSTS, + UTF8ToUTF16(*hosts.begin()), + UTF8ToUTF16(*(++hosts.begin())))); } else if (hosts.size() == 3) { warnings->push_back( - l10n_util::GetStringF(IDS_EXTENSION_PROMPT2_WARNING_3_HOSTS, - UTF8ToWide(*hosts.begin()), - UTF8ToWide(*(++hosts.begin())), - UTF8ToWide(*(++++hosts.begin())))); + l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT2_WARNING_3_HOSTS, + UTF8ToUTF16(*hosts.begin()), + UTF8ToUTF16(*(++hosts.begin())), + UTF8ToUTF16(*(++++hosts.begin())))); } else if (hosts.size() >= 4) { warnings->push_back( - l10n_util::GetStringF(IDS_EXTENSION_PROMPT2_WARNING_4_OR_MORE_HOSTS, - UTF8ToWide(*hosts.begin()), - UTF8ToWide(*(++hosts.begin())), - IntToWString(hosts.size() - 2))); + l10n_util::GetStringFUTF16( + IDS_EXTENSION_PROMPT2_WARNING_4_OR_MORE_HOSTS, + UTF8ToUTF16(*hosts.begin()), + UTF8ToUTF16(*(++hosts.begin())), + IntToString16(hosts.size() - 2))); } } if (extension->HasApiPermission(Extension::kTabPermission) || extension->HasApiPermission(Extension::kBookmarkPermission)) { warnings->push_back( - l10n_util::GetString(IDS_EXTENSION_PROMPT2_WARNING_BROWSING_HISTORY)); + l10n_util::GetStringUTF16( + IDS_EXTENSION_PROMPT2_WARNING_BROWSING_HISTORY)); } // TODO(aa): Geolocation, camera/mic, what else? @@ -307,8 +313,8 @@ void ExtensionInstallUI::OnImageLoaded( Source<ExtensionInstallUI>(this), NotificationService::NoDetails()); -#if defined(OS_WIN) - std::vector<std::wstring> warnings; +#if defined(OS_WIN) || defined(TOOLKIT_GTK) + std::vector<string16> warnings; GetV2Warnings(extension_, &warnings); ShowExtensionInstallUIPrompt2Impl( profile_, delegate_, extension_, &icon_, warnings); diff --git a/chrome/browser/extensions/extension_install_ui.h b/chrome/browser/extensions/extension_install_ui.h index 83c165e..822060d 100755 --- a/chrome/browser/extensions/extension_install_ui.h +++ b/chrome/browser/extensions/extension_install_ui.h @@ -6,10 +6,12 @@ #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ #include <string> +#include <vector> #include "base/file_path.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "chrome/browser/extensions/image_loading_tracker.h" #include "gfx/native_widget_types.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -114,13 +116,11 @@ class ExtensionInstallUI : public ImageLoadingTracker::Observer { Profile* profile, Delegate* delegate, Extension* extension, SkBitmap* icon, const string16& warning, PromptType type); -#if defined(OS_WIN) // Implements the showing of the new install dialog. The implementations of // this function are platform-specific. static void ShowExtensionInstallUIPrompt2Impl( Profile* profile, Delegate* delegate, Extension* extension, - SkBitmap* icon, const std::vector<std::wstring>& permissions); -#endif + SkBitmap* icon, const std::vector<string16>& permissions); Profile* profile_; MessageLoop* ui_loop_; diff --git a/chrome/browser/gtk/extension_install_prompt2_gtk.cc b/chrome/browser/gtk/extension_install_prompt2_gtk.cc new file mode 100644 index 0000000..5714414 --- /dev/null +++ b/chrome/browser/gtk/extension_install_prompt2_gtk.cc @@ -0,0 +1,169 @@ +// 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 <gtk/gtk.h> + +#include "app/l10n_util.h" +#include "base/rand_util.h" +#include "base/string_util.h" +#include "chrome/browser/browser_list.h" +#include "chrome/browser/browser_window.h" +#include "chrome/browser/extensions/extension_install_ui.h" +#include "chrome/browser/gtk/browser_window_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" +#include "chrome/common/extensions/extension.h" +#include "gfx/gtk_util.h" +#include "grit/generated_resources.h" +#include "skia/ext/image_operations.h" + +class Profile; + +namespace { + +const int kRightColumnWidth = 290; + +const int kImageSize = 69; + +// Padding on all sides of each permission in the permissions list. +const int kPermissionsPadding = 8; + +// Make a GtkLabel with |str| as its text, using the formatting in |format|. +GtkWidget* MakeMarkupLabel(const char* format, const std::string& str) { + GtkWidget* label = gtk_label_new(NULL); + char* markup = g_markup_printf_escaped(format, str.c_str()); + gtk_label_set_markup(GTK_LABEL(label), markup); + g_free(markup); + + // Left align it. + gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); + + return label; +} + +void OnDialogResponse(GtkDialog* dialog, int response_id, + ExtensionInstallUI::Delegate* delegate) { + if (response_id == GTK_RESPONSE_ACCEPT) { + delegate->InstallUIProceed(false); + } else { + delegate->InstallUIAbort(); + } + + gtk_widget_destroy(GTK_WIDGET(dialog)); +} + +void ShowInstallPromptDialog2(GtkWindow* parent, SkBitmap* skia_icon, + Extension* extension, + ExtensionInstallUI::Delegate *delegate, + const std::vector<string16>& permissions) { + // Build the dialog. + GtkWidget* dialog = gtk_dialog_new_with_buttons( + l10n_util::GetStringUTF8(IDS_EXTENSION_INSTALL_PROMPT_TITLE).c_str(), + parent, + GTK_DIALOG_MODAL, + NULL); + GtkWidget* close_button = gtk_dialog_add_button(GTK_DIALOG(dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CLOSE); + gtk_dialog_add_button(GTK_DIALOG(dialog), + l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_INSTALL_BUTTON).c_str(), + GTK_RESPONSE_ACCEPT); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); + + // Create a two column layout. + GtkWidget* content_area = GTK_DIALOG(dialog)->vbox; + gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); + + GtkWidget* icon_hbox = gtk_hbox_new(FALSE, gtk_util::kContentAreaSpacing); + gtk_box_pack_start(GTK_BOX(content_area), icon_hbox, TRUE, TRUE, 0); + + // Resize the icon if necessary. + SkBitmap scaled_icon = *skia_icon; + if (scaled_icon.width() > kImageSize || scaled_icon.height() > kImageSize) { + scaled_icon = skia::ImageOperations::Resize(scaled_icon, + skia::ImageOperations::RESIZE_LANCZOS3, + kImageSize, kImageSize); + } + + // Put Icon in the left column. + GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&scaled_icon); + GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf); + g_object_unref(pixbuf); + gtk_box_pack_start(GTK_BOX(icon_hbox), icon, FALSE, FALSE, 0); + // Top justify the image. + gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0.0); + + // Create a new vbox for the right column. + GtkWidget* right_column_area = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); + gtk_box_pack_start(GTK_BOX(icon_hbox), right_column_area, TRUE, TRUE, 0); + + std::string heading_text = l10n_util::GetStringFUTF8( + IDS_EXTENSION_INSTALL_PROMPT_HEADING, UTF8ToUTF16(extension->name())); + GtkWidget* heading_label = MakeMarkupLabel("<span weight=\"bold\">%s</span>", + heading_text); + gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); + bool show_permissions = !permissions.empty(); + // If we are not going to show the permissions, vertically center the title. + gtk_box_pack_start(GTK_BOX(right_column_area), heading_label, + !show_permissions, !show_permissions, 0); + + if (show_permissions) { + GtkWidget* warning_label = gtk_label_new(l10n_util::GetStringUTF8( + IDS_EXTENSION_PROMPT2_WILL_HAVE_ACCESS_TO).c_str()); + gtk_label_set_line_wrap(GTK_LABEL(warning_label), TRUE); + gtk_widget_set_size_request(warning_label, kRightColumnWidth, -1); + gtk_misc_set_alignment(GTK_MISC(warning_label), 0.0, 0.5); + gtk_box_pack_start(GTK_BOX(right_column_area), warning_label, + FALSE, FALSE, 0); + + GtkWidget* frame = gtk_frame_new(NULL); + gtk_box_pack_start(GTK_BOX(right_column_area), frame, FALSE, FALSE, 0); + + GtkWidget* table = gtk_table_new(permissions.size(), 1, false); + gtk_container_add(GTK_CONTAINER(frame), table); + int row = 0; + for (std::vector<string16>::const_iterator iter = permissions.begin(); + iter != permissions.end(); ++iter) { + GtkWidget* entry = gtk_entry_new(); + GtkBorder border = { kPermissionsPadding, kPermissionsPadding, + row == 0 ? kPermissionsPadding : 0, + kPermissionsPadding }; + gtk_entry_set_inner_border(GTK_ENTRY(entry), &border); + gtk_entry_set_text(GTK_ENTRY(entry), UTF16ToUTF8(*iter).c_str()); + gtk_entry_set_editable(GTK_ENTRY(entry), FALSE); + gtk_entry_set_has_frame(GTK_ENTRY(entry), FALSE); + + gtk_table_attach_defaults(GTK_TABLE(table), entry, + 0, 1, row, row + 1); + ++row; + } + } + + g_signal_connect(dialog, "response", G_CALLBACK(OnDialogResponse), delegate); + gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); + + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); + gtk_widget_show_all(dialog); + gtk_widget_grab_focus(close_button); +} + +} // namespace + +void ExtensionInstallUI::ShowExtensionInstallUIPrompt2Impl( + Profile* profile, Delegate* delegate, Extension* extension, SkBitmap* icon, + const std::vector<string16>& permissions) { + Browser* browser = BrowserList::GetLastActiveWithProfile(profile); + if (!browser) { + delegate->InstallUIAbort(); + return; + } + + BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( + browser->window()); + if (!browser_window) { + delegate->InstallUIAbort(); + return; + } + + ShowInstallPromptDialog2(browser_window->window(), icon, extension, + delegate, permissions); +} diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 0c1941c..36e8a31 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1194,6 +1194,7 @@ 'browser/gtk/edit_search_engine_dialog.cc', 'browser/gtk/edit_search_engine_dialog.h', 'browser/gtk/extension_install_prompt_gtk.cc', + 'browser/gtk/extension_install_prompt2_gtk.cc', 'browser/gtk/extension_installed_bubble_gtk.cc', 'browser/gtk/extension_installed_bubble_gtk.h', 'browser/gtk/extension_view_gtk.cc', |