| 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; |
| 85 bool is_inline_install = | 86 bool is_inline_install = |
| 86 prompt.type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT; | 87 prompt.type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT; |
| 87 bool is_bundle_install = | 88 bool is_bundle_install = |
| 88 prompt.type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT; | 89 prompt.type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT; |
| 89 | 90 |
| 90 if (is_inline_install) | 91 if (is_inline_install) |
| 91 extension_id_ = prompt.extension()->id(); | 92 extension_id_ = prompt.extension()->id(); |
| 92 | 93 |
| 93 // Build the dialog. | 94 // Build the dialog. |
| 94 dialog_ = gtk_dialog_new_with_buttons( | 95 dialog_ = gtk_dialog_new_with_buttons( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 122 GtkWidget* top_content_hbox = gtk_hbox_new(FALSE, ui::kContentAreaSpacing); | 123 GtkWidget* top_content_hbox = gtk_hbox_new(FALSE, ui::kContentAreaSpacing); |
| 123 gtk_box_pack_start(GTK_BOX(content_vbox), top_content_hbox, TRUE, TRUE, 0); | 124 gtk_box_pack_start(GTK_BOX(content_vbox), top_content_hbox, TRUE, TRUE, 0); |
| 124 | 125 |
| 125 // Create a new vbox for the left column. | 126 // Create a new vbox for the left column. |
| 126 GtkWidget* left_column_area = gtk_vbox_new(FALSE, ui::kControlSpacing); | 127 GtkWidget* left_column_area = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 127 gtk_box_pack_start(GTK_BOX(top_content_hbox), left_column_area, | 128 gtk_box_pack_start(GTK_BOX(top_content_hbox), left_column_area, |
| 128 TRUE, TRUE, 0); | 129 TRUE, TRUE, 0); |
| 129 | 130 |
| 130 GtkWidget* heading_vbox = gtk_vbox_new(FALSE, 0); | 131 GtkWidget* heading_vbox = gtk_vbox_new(FALSE, 0); |
| 131 // If we are not going to show anything else, vertically center the title. | 132 // If we are not going to show anything else, vertically center the title. |
| 132 bool center_heading = !show_permissions && !is_inline_install; | 133 bool center_heading = |
| 134 !show_permissions && !show_oauth_issues && !is_inline_install; |
| 133 gtk_box_pack_start(GTK_BOX(left_column_area), heading_vbox, center_heading, | 135 gtk_box_pack_start(GTK_BOX(left_column_area), heading_vbox, center_heading, |
| 134 center_heading, 0); | 136 center_heading, 0); |
| 135 | 137 |
| 136 // Heading | 138 // Heading |
| 137 GtkWidget* heading_label = gtk_util::CreateBoldLabel( | 139 GtkWidget* heading_label = gtk_util::CreateBoldLabel( |
| 138 UTF16ToUTF8(prompt.GetHeading().c_str())); | 140 UTF16ToUTF8(prompt.GetHeading().c_str())); |
| 139 gtk_label_set_line_wrap(GTK_LABEL(heading_label), true); | 141 gtk_label_set_line_wrap(GTK_LABEL(heading_label), true); |
| 140 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); | 142 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); |
| 141 gtk_box_pack_start(GTK_BOX(heading_vbox), heading_label, center_heading, | 143 gtk_box_pack_start(GTK_BOX(heading_vbox), heading_label, center_heading, |
| 142 center_heading, 0); | 144 center_heading, 0); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 183 |
| 182 BundleInstaller::ItemList items = prompt.bundle()->GetItemsWithState( | 184 BundleInstaller::ItemList items = prompt.bundle()->GetItemsWithState( |
| 183 BundleInstaller::Item::STATE_PENDING); | 185 BundleInstaller::Item::STATE_PENDING); |
| 184 for (size_t i = 0; i < items.size(); ++i) { | 186 for (size_t i = 0; i < items.size(); ++i) { |
| 185 GtkWidget* extension_label = gtk_label_new(UTF16ToUTF8( | 187 GtkWidget* extension_label = gtk_label_new(UTF16ToUTF8( |
| 186 items[i].GetNameForDisplay()).c_str()); | 188 items[i].GetNameForDisplay()).c_str()); |
| 187 gtk_util::SetLabelWidth(extension_label, kLeftColumnMinWidth); | 189 gtk_util::SetLabelWidth(extension_label, kLeftColumnMinWidth); |
| 188 gtk_box_pack_start(GTK_BOX(extensions_vbox), extension_label, | 190 gtk_box_pack_start(GTK_BOX(extensions_vbox), extension_label, |
| 189 FALSE, FALSE, kExtensionsPadding); | 191 FALSE, FALSE, kExtensionsPadding); |
| 190 } | 192 } |
| 191 } | 193 } else { |
| 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 |
| 239 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); | 265 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
| 240 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); | 266 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); |
| 241 | 267 |
| 242 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_CLOSE); | 268 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_CLOSE); |
| 243 gtk_widget_show_all(dialog_); | 269 gtk_widget_show_all(dialog_); |
| 244 gtk_widget_grab_focus(close_button); | 270 gtk_widget_grab_focus(close_button); |
| 245 } | 271 } |
| 246 | 272 |
| 247 ExtensionInstallDialog::~ExtensionInstallDialog() { | 273 ExtensionInstallDialog::~ExtensionInstallDialog() { |
| 248 } | 274 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 277 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( | 303 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( |
| 278 browser->window()); | 304 browser->window()); |
| 279 if (!browser_window) { | 305 if (!browser_window) { |
| 280 delegate->InstallUIAbort(false); | 306 delegate->InstallUIAbort(false); |
| 281 return; | 307 return; |
| 282 } | 308 } |
| 283 | 309 |
| 284 new browser::ExtensionInstallDialog(browser, browser_window->window(), | 310 new browser::ExtensionInstallDialog(browser, browser_window->window(), |
| 285 delegate, prompt); | 311 delegate, prompt); |
| 286 } | 312 } |
| OLD | NEW |