| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/bundle_installer.h" | 10 #include "chrome/browser/extensions/bundle_installer.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 ExtensionInstallDialog::ExtensionInstallDialog( | 76 ExtensionInstallDialog::ExtensionInstallDialog( |
| 77 Browser* browser, | 77 Browser* browser, |
| 78 GtkWindow* parent, | 78 GtkWindow* parent, |
| 79 ExtensionInstallPrompt::Delegate *delegate, | 79 ExtensionInstallPrompt::Delegate *delegate, |
| 80 const ExtensionInstallPrompt::Prompt& prompt) | 80 const ExtensionInstallPrompt::Prompt& prompt) |
| 81 : browser_(browser), | 81 : browser_(browser), |
| 82 delegate_(delegate), | 82 delegate_(delegate), |
| 83 dialog_(NULL) { | 83 dialog_(NULL) { |
| 84 bool show_permissions = prompt.GetPermissionCount() > 0; | 84 bool show_permissions = prompt.GetPermissionCount() > 0; |
| 85 bool show_oauth_issues = prompt.GetOAuthIssueCount() > 0; | |
| 86 bool is_inline_install = | 85 bool is_inline_install = |
| 87 prompt.type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT; | 86 prompt.type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT; |
| 88 bool is_bundle_install = | 87 bool is_bundle_install = |
| 89 prompt.type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT; | 88 prompt.type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT; |
| 90 | 89 |
| 91 if (is_inline_install) | 90 if (is_inline_install) |
| 92 extension_id_ = prompt.extension()->id(); | 91 extension_id_ = prompt.extension()->id(); |
| 93 | 92 |
| 94 // Build the dialog. | 93 // Build the dialog. |
| 95 dialog_ = gtk_dialog_new_with_buttons( | 94 dialog_ = gtk_dialog_new_with_buttons( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 123 GtkWidget* top_content_hbox = gtk_hbox_new(FALSE, ui::kContentAreaSpacing); | 122 GtkWidget* top_content_hbox = gtk_hbox_new(FALSE, ui::kContentAreaSpacing); |
| 124 gtk_box_pack_start(GTK_BOX(content_vbox), top_content_hbox, TRUE, TRUE, 0); | 123 gtk_box_pack_start(GTK_BOX(content_vbox), top_content_hbox, TRUE, TRUE, 0); |
| 125 | 124 |
| 126 // Create a new vbox for the left column. | 125 // Create a new vbox for the left column. |
| 127 GtkWidget* left_column_area = gtk_vbox_new(FALSE, ui::kControlSpacing); | 126 GtkWidget* left_column_area = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 128 gtk_box_pack_start(GTK_BOX(top_content_hbox), left_column_area, | 127 gtk_box_pack_start(GTK_BOX(top_content_hbox), left_column_area, |
| 129 TRUE, TRUE, 0); | 128 TRUE, TRUE, 0); |
| 130 | 129 |
| 131 GtkWidget* heading_vbox = gtk_vbox_new(FALSE, 0); | 130 GtkWidget* heading_vbox = gtk_vbox_new(FALSE, 0); |
| 132 // If we are not going to show anything else, vertically center the title. | 131 // If we are not going to show anything else, vertically center the title. |
| 133 bool center_heading = | 132 bool center_heading = !show_permissions && !is_inline_install; |
| 134 !show_permissions && !show_oauth_issues && !is_inline_install; | |
| 135 gtk_box_pack_start(GTK_BOX(left_column_area), heading_vbox, center_heading, | 133 gtk_box_pack_start(GTK_BOX(left_column_area), heading_vbox, center_heading, |
| 136 center_heading, 0); | 134 center_heading, 0); |
| 137 | 135 |
| 138 // Heading | 136 // Heading |
| 139 GtkWidget* heading_label = gtk_util::CreateBoldLabel( | 137 GtkWidget* heading_label = gtk_util::CreateBoldLabel( |
| 140 UTF16ToUTF8(prompt.GetHeading().c_str())); | 138 UTF16ToUTF8(prompt.GetHeading().c_str())); |
| 141 gtk_label_set_line_wrap(GTK_LABEL(heading_label), true); | 139 gtk_label_set_line_wrap(GTK_LABEL(heading_label), true); |
| 142 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); | 140 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); |
| 143 gtk_box_pack_start(GTK_BOX(heading_vbox), heading_label, center_heading, | 141 gtk_box_pack_start(GTK_BOX(heading_vbox), heading_label, center_heading, |
| 144 center_heading, 0); | 142 center_heading, 0); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 181 |
| 184 BundleInstaller::ItemList items = prompt.bundle()->GetItemsWithState( | 182 BundleInstaller::ItemList items = prompt.bundle()->GetItemsWithState( |
| 185 BundleInstaller::Item::STATE_PENDING); | 183 BundleInstaller::Item::STATE_PENDING); |
| 186 for (size_t i = 0; i < items.size(); ++i) { | 184 for (size_t i = 0; i < items.size(); ++i) { |
| 187 GtkWidget* extension_label = gtk_label_new(UTF16ToUTF8( | 185 GtkWidget* extension_label = gtk_label_new(UTF16ToUTF8( |
| 188 items[i].GetNameForDisplay()).c_str()); | 186 items[i].GetNameForDisplay()).c_str()); |
| 189 gtk_util::SetLabelWidth(extension_label, kLeftColumnMinWidth); | 187 gtk_util::SetLabelWidth(extension_label, kLeftColumnMinWidth); |
| 190 gtk_box_pack_start(GTK_BOX(extensions_vbox), extension_label, | 188 gtk_box_pack_start(GTK_BOX(extensions_vbox), extension_label, |
| 191 FALSE, FALSE, kExtensionsPadding); | 189 FALSE, FALSE, kExtensionsPadding); |
| 192 } | 190 } |
| 193 } else { | 191 } |
| 192 |
| 193 if (!is_bundle_install) { |
| 194 // Resize the icon if necessary. | 194 // Resize the icon if necessary. |
| 195 SkBitmap scaled_icon = *prompt.icon().ToSkBitmap(); | 195 SkBitmap scaled_icon = *prompt.icon().ToSkBitmap(); |
| 196 if (scaled_icon.width() > kImageSize || scaled_icon.height() > kImageSize) { | 196 if (scaled_icon.width() > kImageSize || scaled_icon.height() > kImageSize) { |
| 197 scaled_icon = skia::ImageOperations::Resize( | 197 scaled_icon = skia::ImageOperations::Resize( |
| 198 scaled_icon, skia::ImageOperations::RESIZE_LANCZOS3, | 198 scaled_icon, skia::ImageOperations::RESIZE_LANCZOS3, |
| 199 kImageSize, kImageSize); | 199 kImageSize, kImageSize); |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Put icon in the right column. | 202 // Put icon in the right column. |
| 203 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(scaled_icon); | 203 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(scaled_icon); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 229 | 229 |
| 230 for (size_t i = 0; i < prompt.GetPermissionCount(); ++i) { | 230 for (size_t i = 0; i < prompt.GetPermissionCount(); ++i) { |
| 231 GtkWidget* permission_label = gtk_label_new(UTF16ToUTF8( | 231 GtkWidget* permission_label = gtk_label_new(UTF16ToUTF8( |
| 232 prompt.GetPermission(i)).c_str()); | 232 prompt.GetPermission(i)).c_str()); |
| 233 gtk_util::SetLabelWidth(permission_label, kLeftColumnMinWidth); | 233 gtk_util::SetLabelWidth(permission_label, kLeftColumnMinWidth); |
| 234 gtk_box_pack_start(GTK_BOX(permissions_container), permission_label, | 234 gtk_box_pack_start(GTK_BOX(permissions_container), permission_label, |
| 235 FALSE, FALSE, kPermissionsPadding); | 235 FALSE, FALSE, kPermissionsPadding); |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 | 238 |
| 239 if (show_oauth_issues) { | |
| 240 GtkWidget* oauth_issues_container; | |
| 241 if (is_inline_install) { | |
| 242 oauth_issues_container = content_vbox; | |
| 243 gtk_box_pack_start(GTK_BOX(content_vbox), gtk_hseparator_new(), | |
| 244 FALSE, FALSE, ui::kControlSpacing); | |
| 245 } else { | |
| 246 oauth_issues_container = left_column_area; | |
| 247 } | |
| 248 | |
| 249 GtkWidget* oauth_issues_header = gtk_util::CreateBoldLabel( | |
| 250 "The app wants these scopes:"); | |
| 251 gtk_util::SetLabelWidth(oauth_issues_header, kLeftColumnMinWidth); | |
| 252 gtk_box_pack_start(GTK_BOX(oauth_issues_container), oauth_issues_header, | |
| 253 FALSE, FALSE, 0); | |
| 254 | |
| 255 // TODO(estade): display the issue details under zippies. | |
| 256 for (size_t i = 0; i < prompt.GetOAuthIssueCount(); ++i) { | |
| 257 GtkWidget* label = gtk_label_new( | |
| 258 prompt.GetOAuthIssue(i).description.c_str()); | |
| 259 gtk_util::SetLabelWidth(label, kLeftColumnMinWidth); | |
| 260 gtk_box_pack_start(GTK_BOX(oauth_issues_container), label, | |
| 261 FALSE, FALSE, kPermissionsPadding); | |
| 262 } | |
| 263 } | |
| 264 | |
| 265 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); | 239 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
| 266 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); | 240 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); |
| 267 | 241 |
| 268 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_CLOSE); | 242 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_CLOSE); |
| 269 gtk_widget_show_all(dialog_); | 243 gtk_widget_show_all(dialog_); |
| 270 gtk_widget_grab_focus(close_button); | 244 gtk_widget_grab_focus(close_button); |
| 271 } | 245 } |
| 272 | 246 |
| 273 ExtensionInstallDialog::~ExtensionInstallDialog() { | 247 ExtensionInstallDialog::~ExtensionInstallDialog() { |
| 274 } | 248 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 303 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( | 277 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( |
| 304 browser->window()); | 278 browser->window()); |
| 305 if (!browser_window) { | 279 if (!browser_window) { |
| 306 delegate->InstallUIAbort(false); | 280 delegate->InstallUIAbort(false); |
| 307 return; | 281 return; |
| 308 } | 282 } |
| 309 | 283 |
| 310 new browser::ExtensionInstallDialog(browser, browser_window->window(), | 284 new browser::ExtensionInstallDialog(browser, browser_window->window(), |
| 311 delegate, prompt); | 285 delegate, prompt); |
| 312 } | 286 } |
| OLD | NEW |