| 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 "chrome/browser/ui/gtk/extensions/extension_installed_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/extensions/extension_installed_bubble_gtk.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | |
| 10 #include "base/bind_helpers.h" | |
| 11 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 12 #include "base/message_loop/message_loop.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/extensions/api/commands/command_service.h" | 12 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 16 #include "chrome/browser/extensions/extension_action.h" | 13 #include "chrome/browser/extensions/extension_action.h" |
| 17 #include "chrome/browser/extensions/extension_action_manager.h" | 14 #include "chrome/browser/extensions/extension_action_manager.h" |
| 18 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_dialogs.h" | 16 #include "chrome/browser/ui/browser_dialogs.h" |
| 20 #include "chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h" | 17 #include "chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h" |
| 21 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" | 18 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" |
| 22 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 19 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 23 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 20 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 24 #include "chrome/browser/ui/gtk/gtk_util.h" | 21 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 25 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" | 22 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
| 26 #include "chrome/browser/ui/singleton_tabs.h" | 23 #include "chrome/browser/ui/singleton_tabs.h" |
| 27 #include "chrome/common/extensions/api/extension_action/action_info.h" | |
| 28 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h" | 24 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h" |
| 29 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
| 30 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 31 #include "content/public/browser/notification_details.h" | 27 #include "content/public/browser/notification_details.h" |
| 32 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
| 33 #include "grit/chromium_strings.h" | 29 #include "grit/chromium_strings.h" |
| 34 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 35 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
| 36 #include "ui/base/gtk/gtk_hig_constants.h" | 32 #include "ui/base/gtk/gtk_hig_constants.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 38 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/gfx/gtk_util.h" | 35 #include "ui/gfx/gtk_util.h" |
| 40 | 36 |
| 41 using extensions::Extension; | 37 using extensions::Extension; |
| 42 using extensions::ExtensionActionManager; | 38 using extensions::ExtensionActionManager; |
| 43 | 39 |
| 44 namespace { | 40 namespace { |
| 45 | 41 |
| 46 const int kHorizontalColumnSpacing = 10; | 42 const int kHorizontalColumnSpacing = 10; |
| 47 const int kIconPadding = 3; | 43 const int kIconPadding = 3; |
| 48 const int kIconSize = 43; | 44 const int kIconSize = 43; |
| 49 const int kTextColumnVerticalSpacing = 7; | 45 const int kTextColumnVerticalSpacing = 7; |
| 50 const int kTextColumnWidth = 350; | 46 const int kTextColumnWidth = 350; |
| 51 | 47 |
| 52 // When showing the bubble for a new browser action, we may have to wait for | |
| 53 // the toolbar to finish animating to know where the item's final position | |
| 54 // will be. | |
| 55 const int kAnimationWaitRetries = 10; | |
| 56 const int kAnimationWaitMS = 50; | |
| 57 | |
| 58 } // namespace | 48 } // namespace |
| 59 | 49 |
| 60 namespace chrome { | 50 namespace chrome { |
| 61 | 51 |
| 62 void ShowExtensionInstalledBubble(const Extension* extension, | 52 void ShowExtensionInstalledBubble(const Extension* extension, |
| 63 Browser* browser, | 53 Browser* browser, |
| 64 const SkBitmap& icon) { | 54 const SkBitmap& icon) { |
| 65 ExtensionInstalledBubbleGtk::Show(extension, browser, icon); | 55 ExtensionInstalledBubbleGtk::Show(extension, browser, icon); |
| 66 } | 56 } |
| 67 | 57 |
| 68 } // namespace chrome | 58 } // namespace chrome |
| 69 | 59 |
| 70 void ExtensionInstalledBubbleGtk::Show(const Extension* extension, | 60 void ExtensionInstalledBubbleGtk::Show(const Extension* extension, |
| 71 Browser* browser, | 61 Browser* browser, |
| 72 const SkBitmap& icon) { | 62 const SkBitmap& icon) { |
| 73 new ExtensionInstalledBubbleGtk(extension, browser, icon); | 63 new ExtensionInstalledBubbleGtk(extension, browser, icon); |
| 74 } | 64 } |
| 75 | 65 |
| 76 ExtensionInstalledBubbleGtk::ExtensionInstalledBubbleGtk( | 66 ExtensionInstalledBubbleGtk::ExtensionInstalledBubbleGtk( |
| 77 const Extension* extension, Browser *browser, const SkBitmap& icon) | 67 const Extension* extension, Browser *browser, const SkBitmap& icon) |
| 78 : extension_(extension), | 68 : bubble_(this, extension, browser, icon) { |
| 79 browser_(browser), | |
| 80 icon_(icon), | |
| 81 animation_wait_retries_(kAnimationWaitRetries), | |
| 82 bubble_(NULL), | |
| 83 weak_factory_(this) { | |
| 84 if (!extensions::OmniboxInfo::GetKeyword(extension_).empty()) | |
| 85 type_ = OMNIBOX_KEYWORD; | |
| 86 else if (extensions::ActionInfo::GetBrowserActionInfo(extension_)) | |
| 87 type_ = BROWSER_ACTION; | |
| 88 else if (extensions::ActionInfo::GetPageActionInfo(extension) && | |
| 89 extensions::ActionInfo::IsVerboseInstallMessage(extension)) | |
| 90 type_ = PAGE_ACTION; | |
| 91 else | |
| 92 type_ = GENERIC; | |
| 93 | |
| 94 // |extension| has been initialized but not loaded at this point. We need | |
| 95 // to wait on showing the Bubble until not only the EXTENSION_LOADED gets | |
| 96 // fired, but all of the EXTENSION_LOADED Observers have run. Only then can we | |
| 97 // be sure that a browser action or page action has had views created which we | |
| 98 // can inspect for the purpose of pointing to them. | |
| 99 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | |
| 100 content::Source<Profile>(browser->profile())); | |
| 101 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | |
| 102 content::Source<Profile>(browser->profile())); | |
| 103 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, | |
| 104 content::Source<Browser>(browser)); | |
| 105 } | 69 } |
| 106 | 70 |
| 107 ExtensionInstalledBubbleGtk::~ExtensionInstalledBubbleGtk() {} | 71 ExtensionInstalledBubbleGtk::~ExtensionInstalledBubbleGtk() {} |
| 108 | 72 |
| 109 void ExtensionInstalledBubbleGtk::Observe( | |
| 110 int type, | |
| 111 const content::NotificationSource& source, | |
| 112 const content::NotificationDetails& details) { | |
| 113 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { | |
| 114 const Extension* extension = | |
| 115 content::Details<const Extension>(details).ptr(); | |
| 116 if (extension == extension_) { | |
| 117 // PostTask to ourself to allow all EXTENSION_LOADED Observers to run. | |
| 118 base::MessageLoopForUI::current()->PostTask( | |
| 119 FROM_HERE, | |
| 120 base::Bind(&ExtensionInstalledBubbleGtk::ShowInternal, | |
| 121 weak_factory_.GetWeakPtr())); | |
| 122 } | |
| 123 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | |
| 124 const Extension* extension = | |
| 125 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; | |
| 126 if (extension == extension_) { | |
| 127 // Extension is going away, make sure ShowInternal won't be called. | |
| 128 weak_factory_.InvalidateWeakPtrs(); | |
| 129 extension_ = NULL; | |
| 130 } | |
| 131 } else if (type == chrome::NOTIFICATION_BROWSER_CLOSING) { | |
| 132 // The browser closed before the bubble could be created. | |
| 133 if (!bubble_) | |
| 134 delete this; | |
| 135 } else { | |
| 136 NOTREACHED() << L"Received unexpected notification"; | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 void ExtensionInstalledBubbleGtk::OnDestroy(GtkWidget* widget) { | 73 void ExtensionInstalledBubbleGtk::OnDestroy(GtkWidget* widget) { |
| 141 bubble_ = NULL; | 74 gtk_bubble_ = NULL; |
| 142 delete this; | 75 delete this; |
| 143 } | 76 } |
| 144 | 77 |
| 145 void ExtensionInstalledBubbleGtk::ShowInternal() { | 78 void ExtensionInstalledBubbleGtk::ShowInternal() { |
| 146 BrowserWindowGtk* browser_window = | 79 BrowserWindowGtk* browser_window = |
| 147 BrowserWindowGtk::GetBrowserWindowForNativeWindow( | 80 BrowserWindowGtk::GetBrowserWindowForNativeWindow( |
| 148 browser_->window()->GetNativeWindow()); | 81 bubble_.browser()->window()->GetNativeWindow()); |
| 149 | 82 |
| 150 GtkWidget* reference_widget = NULL; | 83 GtkWidget* reference_widget = NULL; |
| 151 | 84 |
| 152 if (type_ == BROWSER_ACTION) { | 85 if (bubble_.type() == bubble_.BROWSER_ACTION) { |
| 153 BrowserActionsToolbarGtk* toolbar = | 86 BrowserActionsToolbarGtk* toolbar = |
| 154 browser_window->GetToolbar()->GetBrowserActionsToolbar(); | 87 browser_window->GetToolbar()->GetBrowserActionsToolbar(); |
| 155 | 88 if (toolbar->animating()) { |
| 156 if (toolbar->animating() && animation_wait_retries_-- > 0) { | 89 bubble_.MaybeShowLater(); |
| 157 base::MessageLoopForUI::current()->PostDelayedTask( | |
| 158 FROM_HERE, | |
| 159 base::Bind(&ExtensionInstalledBubbleGtk::ShowInternal, | |
| 160 weak_factory_.GetWeakPtr()), | |
| 161 base::TimeDelta::FromMilliseconds(kAnimationWaitMS)); | |
| 162 return; | 90 return; |
| 163 } | 91 } |
| 164 | 92 |
| 165 reference_widget = toolbar->GetBrowserActionWidget(extension_); | 93 reference_widget = toolbar->GetBrowserActionWidget(bubble_.extension()); |
| 166 // glib delays recalculating layout, but we need reference_widget to know | 94 // glib delays recalculating layout, but we need reference_widget to know |
| 167 // its coordinates, so we force a check_resize here. | 95 // its coordinates, so we force a check_resize here. |
| 168 gtk_container_check_resize(GTK_CONTAINER( | 96 gtk_container_check_resize(GTK_CONTAINER( |
| 169 browser_window->GetToolbar()->widget())); | 97 browser_window->GetToolbar()->widget())); |
| 170 // If the widget is not visible then browser_window could be incognito | 98 // If the widget is not visible then browser_window could be incognito |
| 171 // with this extension disabled. Try showing it on the chevron. | 99 // with this extension disabled. Try showing it on the chevron. |
| 172 // If that fails, fall back to default position. | 100 // If that fails, fall back to default position. |
| 173 if (reference_widget && !gtk_widget_get_visible(reference_widget)) { | 101 if (reference_widget && !gtk_widget_get_visible(reference_widget)) { |
| 174 reference_widget = gtk_widget_get_visible(toolbar->chevron()) ? | 102 reference_widget = gtk_widget_get_visible(toolbar->chevron()) ? |
| 175 toolbar->chevron() : NULL; | 103 toolbar->chevron() : NULL; |
| 176 } | 104 } |
| 177 } else if (type_ == PAGE_ACTION) { | 105 } else if (bubble_.type() == bubble_.PAGE_ACTION) { |
| 178 LocationBarViewGtk* location_bar_view = | 106 LocationBarViewGtk* location_bar_view = |
| 179 browser_window->GetToolbar()->GetLocationBarView(); | 107 browser_window->GetToolbar()->GetLocationBarView(); |
| 180 ExtensionAction* page_action = | 108 ExtensionAction* page_action = |
| 181 ExtensionActionManager::Get(browser_->profile())-> | 109 ExtensionActionManager::Get(bubble_.browser()->profile())-> |
| 182 GetPageAction(*extension_); | 110 GetPageAction(*bubble_.extension()); |
| 183 location_bar_view->SetPreviewEnabledPageAction(page_action, | 111 location_bar_view->SetPreviewEnabledPageAction(page_action, |
| 184 true); // preview_enabled | 112 true); // preview_enabled |
| 185 reference_widget = location_bar_view->GetPageActionWidget(page_action); | 113 reference_widget = location_bar_view->GetPageActionWidget(page_action); |
| 186 // glib delays recalculating layout, but we need reference_widget to know | 114 // glib delays recalculating layout, but we need reference_widget to know |
| 187 // its coordinates, so we force a check_resize here. | 115 // its coordinates, so we force a check_resize here. |
| 188 gtk_container_check_resize(GTK_CONTAINER( | 116 gtk_container_check_resize(GTK_CONTAINER( |
| 189 browser_window->GetToolbar()->widget())); | 117 browser_window->GetToolbar()->widget())); |
| 190 DCHECK(reference_widget); | 118 DCHECK(reference_widget); |
| 191 } else if (type_ == OMNIBOX_KEYWORD) { | 119 } else if (bubble_.type() == bubble_.OMNIBOX_KEYWORD) { |
| 192 LocationBarViewGtk* location_bar_view = | 120 LocationBarViewGtk* location_bar_view = |
| 193 browser_window->GetToolbar()->GetLocationBarView(); | 121 browser_window->GetToolbar()->GetLocationBarView(); |
| 194 reference_widget = location_bar_view->location_entry_widget(); | 122 reference_widget = location_bar_view->location_entry_widget(); |
| 195 DCHECK(reference_widget); | 123 DCHECK(reference_widget); |
| 196 } | 124 } |
| 197 | 125 |
| 198 // Default case. | 126 // Default case. |
| 199 if (reference_widget == NULL) | 127 if (reference_widget == NULL) |
| 200 reference_widget = browser_window->GetToolbar()->GetAppMenuButton(); | 128 reference_widget = browser_window->GetToolbar()->GetAppMenuButton(); |
| 201 | 129 |
| 202 GtkThemeService* theme_provider = GtkThemeService::GetFrom( | 130 GtkThemeService* theme_provider = GtkThemeService::GetFrom( |
| 203 browser_->profile()); | 131 bubble_.browser()->profile()); |
| 204 | 132 |
| 205 // Setup the BubbleGtk content. | 133 // Setup the BubbleGtk content. |
| 206 GtkWidget* bubble_content = gtk_hbox_new(FALSE, kHorizontalColumnSpacing); | 134 GtkWidget* bubble_content = gtk_hbox_new(FALSE, kHorizontalColumnSpacing); |
| 207 gtk_container_set_border_width(GTK_CONTAINER(bubble_content), | 135 gtk_container_set_border_width(GTK_CONTAINER(bubble_content), |
| 208 ui::kContentAreaBorder); | 136 ui::kContentAreaBorder); |
| 209 | 137 |
| 210 if (!icon_.isNull()) { | 138 if (!bubble_.icon().isNull()) { |
| 211 // Scale icon down to 43x43, but allow smaller icons (don't scale up). | 139 // Scale icon down to 43x43, but allow smaller icons (don't scale up). |
| 212 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(icon_); | 140 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bubble_.icon()); |
| 213 gfx::Size size(icon_.width(), icon_.height()); | 141 gfx::Size size(bubble_.icon().width(), bubble_.icon().height()); |
| 214 if (size.width() > kIconSize || size.height() > kIconSize) { | 142 if (size.width() > kIconSize || size.height() > kIconSize) { |
| 215 if (size.width() > size.height()) { | 143 if (size.width() > size.height()) { |
| 216 size.set_height(size.height() * kIconSize / size.width()); | 144 size.set_height(size.height() * kIconSize / size.width()); |
| 217 size.set_width(kIconSize); | 145 size.set_width(kIconSize); |
| 218 } else { | 146 } else { |
| 219 size.set_width(size.width() * kIconSize / size.height()); | 147 size.set_width(size.width() * kIconSize / size.height()); |
| 220 size.set_height(kIconSize); | 148 size.set_height(kIconSize); |
| 221 } | 149 } |
| 222 | 150 |
| 223 GdkPixbuf* old = pixbuf; | 151 GdkPixbuf* old = pixbuf; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 236 g_object_unref(pixbuf); | 164 g_object_unref(pixbuf); |
| 237 gtk_box_pack_start(GTK_BOX(icon_column), image, FALSE, FALSE, 0); | 165 gtk_box_pack_start(GTK_BOX(icon_column), image, FALSE, FALSE, 0); |
| 238 } | 166 } |
| 239 | 167 |
| 240 // Center text column. | 168 // Center text column. |
| 241 GtkWidget* text_column = gtk_vbox_new(FALSE, kTextColumnVerticalSpacing); | 169 GtkWidget* text_column = gtk_vbox_new(FALSE, kTextColumnVerticalSpacing); |
| 242 gtk_box_pack_start(GTK_BOX(bubble_content), text_column, FALSE, FALSE, 0); | 170 gtk_box_pack_start(GTK_BOX(bubble_content), text_column, FALSE, FALSE, 0); |
| 243 | 171 |
| 244 // Heading label. | 172 // Heading label. |
| 245 GtkWidget* heading_label = gtk_label_new(NULL); | 173 GtkWidget* heading_label = gtk_label_new(NULL); |
| 246 string16 extension_name = UTF8ToUTF16(extension_->name()); | 174 string16 extension_name = UTF8ToUTF16(bubble_.extension()->name()); |
| 247 base::i18n::AdjustStringForLocaleDirection(&extension_name); | 175 base::i18n::AdjustStringForLocaleDirection(&extension_name); |
| 248 std::string heading_text = l10n_util::GetStringFUTF8( | 176 std::string heading_text = l10n_util::GetStringFUTF8( |
| 249 IDS_EXTENSION_INSTALLED_HEADING, extension_name); | 177 IDS_EXTENSION_INSTALLED_HEADING, extension_name); |
| 250 char* markup = g_markup_printf_escaped("<span size=\"larger\">%s</span>", | 178 char* markup = g_markup_printf_escaped("<span size=\"larger\">%s</span>", |
| 251 heading_text.c_str()); | 179 heading_text.c_str()); |
| 252 gtk_label_set_markup(GTK_LABEL(heading_label), markup); | 180 gtk_label_set_markup(GTK_LABEL(heading_label), markup); |
| 253 g_free(markup); | 181 g_free(markup); |
| 254 | 182 |
| 255 gtk_util::SetLabelWidth(heading_label, kTextColumnWidth); | 183 gtk_util::SetLabelWidth(heading_label, kTextColumnWidth); |
| 256 gtk_box_pack_start(GTK_BOX(text_column), heading_label, FALSE, FALSE, 0); | 184 gtk_box_pack_start(GTK_BOX(text_column), heading_label, FALSE, FALSE, 0); |
| 257 | 185 |
| 258 bool has_keybinding = false; | 186 bool has_keybinding = false; |
| 259 | 187 |
| 260 // Browser action label. | 188 // Browser action label. |
| 261 if (type_ == BROWSER_ACTION) { | 189 if (bubble_.type() == bubble_.BROWSER_ACTION) { |
| 262 extensions::CommandService* command_service = | 190 extensions::CommandService* command_service = |
| 263 extensions::CommandService::Get(browser_->profile()); | 191 extensions::CommandService::Get(bubble_.browser()->profile()); |
| 264 extensions::Command browser_action_command; | 192 extensions::Command browser_action_command; |
| 265 GtkWidget* info_label; | 193 GtkWidget* info_label; |
| 266 if (!command_service->GetBrowserActionCommand( | 194 if (!command_service->GetBrowserActionCommand( |
| 267 extension_->id(), | 195 bubble_.extension()->id(), |
| 268 extensions::CommandService::ACTIVE_ONLY, | 196 extensions::CommandService::ACTIVE_ONLY, |
| 269 &browser_action_command, | 197 &browser_action_command, |
| 270 NULL)) { | 198 NULL)) { |
| 271 info_label = gtk_label_new(l10n_util::GetStringUTF8( | 199 info_label = gtk_label_new(l10n_util::GetStringUTF8( |
| 272 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO).c_str()); | 200 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO).c_str()); |
| 273 } else { | 201 } else { |
| 274 info_label = gtk_label_new(l10n_util::GetStringFUTF8( | 202 info_label = gtk_label_new(l10n_util::GetStringFUTF8( |
| 275 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT, | 203 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT, |
| 276 browser_action_command.accelerator().GetShortcutText()).c_str()); | 204 browser_action_command.accelerator().GetShortcutText()).c_str()); |
| 277 has_keybinding = true; | 205 has_keybinding = true; |
| 278 } | 206 } |
| 279 gtk_util::SetLabelWidth(info_label, kTextColumnWidth); | 207 gtk_util::SetLabelWidth(info_label, kTextColumnWidth); |
| 280 gtk_box_pack_start(GTK_BOX(text_column), info_label, FALSE, FALSE, 0); | 208 gtk_box_pack_start(GTK_BOX(text_column), info_label, FALSE, FALSE, 0); |
| 281 } | 209 } |
| 282 | 210 |
| 283 // Page action label. | 211 // Page action label. |
| 284 if (type_ == PAGE_ACTION) { | 212 if (bubble_.type() == bubble_.PAGE_ACTION) { |
| 285 extensions::CommandService* command_service = | 213 extensions::CommandService* command_service = |
| 286 extensions::CommandService::Get(browser_->profile()); | 214 extensions::CommandService::Get(bubble_.browser()->profile()); |
| 287 extensions::Command page_action_command; | 215 extensions::Command page_action_command; |
| 288 GtkWidget* info_label; | 216 GtkWidget* info_label; |
| 289 if (!command_service->GetPageActionCommand( | 217 if (!command_service->GetPageActionCommand( |
| 290 extension_->id(), | 218 bubble_.extension()->id(), |
| 291 extensions::CommandService::ACTIVE_ONLY, | 219 extensions::CommandService::ACTIVE_ONLY, |
| 292 &page_action_command, | 220 &page_action_command, |
| 293 NULL)) { | 221 NULL)) { |
| 294 info_label = gtk_label_new(l10n_util::GetStringUTF8( | 222 info_label = gtk_label_new(l10n_util::GetStringUTF8( |
| 295 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO).c_str()); | 223 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO).c_str()); |
| 296 } else { | 224 } else { |
| 297 info_label = gtk_label_new(l10n_util::GetStringFUTF8( | 225 info_label = gtk_label_new(l10n_util::GetStringFUTF8( |
| 298 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO_WITH_SHORTCUT, | 226 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO_WITH_SHORTCUT, |
| 299 page_action_command.accelerator().GetShortcutText()).c_str()); | 227 page_action_command.accelerator().GetShortcutText()).c_str()); |
| 300 has_keybinding = true; | 228 has_keybinding = true; |
| 301 } | 229 } |
| 302 gtk_util::SetLabelWidth(info_label, kTextColumnWidth); | 230 gtk_util::SetLabelWidth(info_label, kTextColumnWidth); |
| 303 gtk_box_pack_start(GTK_BOX(text_column), info_label, FALSE, FALSE, 0); | 231 gtk_box_pack_start(GTK_BOX(text_column), info_label, FALSE, FALSE, 0); |
| 304 } | 232 } |
| 305 | 233 |
| 306 // Omnibox keyword label. | 234 // Omnibox keyword label. |
| 307 if (type_ == OMNIBOX_KEYWORD) { | 235 if (bubble_.type() == bubble_.OMNIBOX_KEYWORD) { |
| 308 GtkWidget* info_label = gtk_label_new(l10n_util::GetStringFUTF8( | 236 GtkWidget* info_label = gtk_label_new(l10n_util::GetStringFUTF8( |
| 309 IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO, | 237 IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO, |
| 310 UTF8ToUTF16(extensions::OmniboxInfo::GetKeyword(extension_))).c_str()); | 238 UTF8ToUTF16(extensions::OmniboxInfo::GetKeyword( |
| 239 bubble_.extension()))).c_str()); |
| 311 gtk_util::SetLabelWidth(info_label, kTextColumnWidth); | 240 gtk_util::SetLabelWidth(info_label, kTextColumnWidth); |
| 312 gtk_box_pack_start(GTK_BOX(text_column), info_label, FALSE, FALSE, 0); | 241 gtk_box_pack_start(GTK_BOX(text_column), info_label, FALSE, FALSE, 0); |
| 313 } | 242 } |
| 314 | 243 |
| 315 if (has_keybinding) { | 244 if (has_keybinding) { |
| 316 GtkWidget* manage_link = theme_provider->BuildChromeLinkButton( | 245 GtkWidget* manage_link = theme_provider->BuildChromeLinkButton( |
| 317 l10n_util::GetStringUTF8(IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS)); | 246 l10n_util::GetStringUTF8(IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS)); |
| 318 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0); | 247 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0); |
| 319 // Stick it in an hbox so it doesn't expand to the whole width. | 248 // Stick it in an hbox so it doesn't expand to the whole width. |
| 320 gtk_box_pack_end(GTK_BOX(link_hbox), manage_link, FALSE, FALSE, 0); | 249 gtk_box_pack_end(GTK_BOX(link_hbox), manage_link, FALSE, FALSE, 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 334 gtk_box_pack_start(GTK_BOX(bubble_content), close_column, FALSE, FALSE, 0); | 263 gtk_box_pack_start(GTK_BOX(bubble_content), close_column, FALSE, FALSE, 0); |
| 335 close_button_.reset(CustomDrawButton::CloseButtonBubble(theme_provider)); | 264 close_button_.reset(CustomDrawButton::CloseButtonBubble(theme_provider)); |
| 336 g_signal_connect(close_button_->widget(), "clicked", | 265 g_signal_connect(close_button_->widget(), "clicked", |
| 337 G_CALLBACK(OnButtonClick), this); | 266 G_CALLBACK(OnButtonClick), this); |
| 338 gtk_box_pack_start(GTK_BOX(close_column), close_button_->widget(), | 267 gtk_box_pack_start(GTK_BOX(close_column), close_button_->widget(), |
| 339 FALSE, FALSE, 0); | 268 FALSE, FALSE, 0); |
| 340 | 269 |
| 341 BubbleGtk::FrameStyle frame_style = BubbleGtk::ANCHOR_TOP_RIGHT; | 270 BubbleGtk::FrameStyle frame_style = BubbleGtk::ANCHOR_TOP_RIGHT; |
| 342 | 271 |
| 343 gfx::Rect bounds = gtk_util::WidgetBounds(reference_widget); | 272 gfx::Rect bounds = gtk_util::WidgetBounds(reference_widget); |
| 344 if (type_ == OMNIBOX_KEYWORD) { | 273 if (bubble_.type() == bubble_.OMNIBOX_KEYWORD) { |
| 345 // Reverse the arrow for omnibox keywords, since the bubble will be on the | 274 // Reverse the arrow for omnibox keywords, since the bubble will be on the |
| 346 // other side of the window. We also clear the width to avoid centering | 275 // other side of the window. We also clear the width to avoid centering |
| 347 // the popup on the URL bar. | 276 // the popup on the URL bar. |
| 348 frame_style = BubbleGtk::ANCHOR_TOP_LEFT; | 277 frame_style = BubbleGtk::ANCHOR_TOP_LEFT; |
| 349 if (base::i18n::IsRTL()) | 278 if (base::i18n::IsRTL()) |
| 350 bounds.Offset(bounds.width(), 0); | 279 bounds.Offset(bounds.width(), 0); |
| 351 bounds.set_width(0); | 280 bounds.set_width(0); |
| 352 } | 281 } |
| 353 | 282 |
| 354 bubble_ = BubbleGtk::Show(reference_widget, | 283 gtk_bubble_ = BubbleGtk::Show(reference_widget, |
| 355 &bounds, | 284 &bounds, |
| 356 bubble_content, | 285 bubble_content, |
| 357 frame_style, | 286 frame_style, |
| 358 BubbleGtk::MATCH_SYSTEM_THEME | | 287 BubbleGtk::MATCH_SYSTEM_THEME | |
| 359 BubbleGtk::POPUP_WINDOW | | 288 BubbleGtk::POPUP_WINDOW | |
| 360 BubbleGtk::GRAB_INPUT, | 289 BubbleGtk::GRAB_INPUT, |
| 361 theme_provider, | 290 theme_provider, |
| 362 this); | 291 this); |
| 363 g_signal_connect(bubble_content, "destroy", | 292 g_signal_connect(bubble_content, "destroy", |
| 364 G_CALLBACK(&OnDestroyThunk), this); | 293 G_CALLBACK(&OnDestroyThunk), this); |
| 365 } | 294 } |
| 366 | 295 |
| 296 void ExtensionInstalledBubbleGtk::OnBrowserClosing() { |
| 297 delete this; |
| 298 } |
| 299 |
| 367 // static | 300 // static |
| 368 void ExtensionInstalledBubbleGtk::OnButtonClick(GtkWidget* button, | 301 void ExtensionInstalledBubbleGtk::OnButtonClick(GtkWidget* button, |
| 369 ExtensionInstalledBubbleGtk* bubble) { | 302 ExtensionInstalledBubbleGtk* bubble) { |
| 370 if (button == bubble->close_button_->widget()) { | 303 if (button == bubble->close_button_->widget()) { |
| 371 bubble->bubble_->Close(); | 304 bubble->gtk_bubble_->Close(); |
| 372 } else { | 305 } else { |
| 373 NOTREACHED(); | 306 NOTREACHED(); |
| 374 } | 307 } |
| 375 } | 308 } |
| 376 | 309 |
| 377 void ExtensionInstalledBubbleGtk::OnLinkClicked(GtkWidget* widget) { | 310 void ExtensionInstalledBubbleGtk::OnLinkClicked(GtkWidget* widget) { |
| 378 bubble_->Close(); | 311 gtk_bubble_->Close(); |
| 379 | 312 |
| 380 std::string configure_url = chrome::kChromeUIExtensionsURL; | 313 std::string configure_url = chrome::kChromeUIExtensionsURL; |
| 381 configure_url += chrome::kExtensionConfigureCommandsSubPage; | 314 configure_url += chrome::kExtensionConfigureCommandsSubPage; |
| 382 chrome::NavigateParams params( | 315 chrome::NavigateParams params( |
| 383 chrome::GetSingletonTabNavigateParams( | 316 chrome::GetSingletonTabNavigateParams( |
| 384 browser_, GURL(configure_url.c_str()))); | 317 bubble_.browser(), GURL(configure_url.c_str()))); |
| 385 chrome::Navigate(¶ms); | 318 chrome::Navigate(¶ms); |
| 386 } | 319 } |
| 387 | 320 |
| 388 void ExtensionInstalledBubbleGtk::BubbleClosing(BubbleGtk* bubble, | 321 void ExtensionInstalledBubbleGtk::BubbleClosing(BubbleGtk* bubble, |
| 389 bool closed_by_escape) { | 322 bool closed_by_escape) { |
| 390 if (extension_ && type_ == PAGE_ACTION) { | 323 if (bubble_.extension() && bubble_.type() == bubble_.PAGE_ACTION) { |
| 391 // Turn the page action preview off. | 324 // Turn the page action preview off. |
| 392 BrowserWindowGtk* browser_window = | 325 BrowserWindowGtk* browser_window = |
| 393 BrowserWindowGtk::GetBrowserWindowForNativeWindow( | 326 BrowserWindowGtk::GetBrowserWindowForNativeWindow( |
| 394 browser_->window()->GetNativeWindow()); | 327 bubble_.browser()->window()->GetNativeWindow()); |
| 395 LocationBarViewGtk* location_bar_view = | 328 LocationBarViewGtk* location_bar_view = |
| 396 browser_window->GetToolbar()->GetLocationBarView(); | 329 browser_window->GetToolbar()->GetLocationBarView(); |
| 397 location_bar_view->SetPreviewEnabledPageAction( | 330 location_bar_view->SetPreviewEnabledPageAction( |
| 398 ExtensionActionManager::Get(browser_->profile())-> | 331 ExtensionActionManager::Get(bubble_.browser()->profile())-> |
| 399 GetPageAction(*extension_), | 332 GetPageAction(*bubble_.extension()), |
| 400 false); // preview_enabled | 333 false); // preview_enabled |
| 401 } | 334 } |
| 402 } | 335 } |
| OLD | NEW |