| 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/views/extensions/extension_installed_bubble.h" | 5 #include "chrome/browser/ui/views/extensions/extension_installed_bubble.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/extensions/api/commands/command_service.h" | 14 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 15 #include "chrome/browser/extensions/api/commands/command_service_factory.h" | 15 #include "chrome/browser/extensions/api/commands/command_service_factory.h" |
| 16 #include "chrome/browser/extensions/extension_install_ui.h" | 16 #include "chrome/browser/extensions/extension_install_ui.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/browser/ui/singleton_tabs.h" |
| 20 #include "chrome/browser/ui/views/browser_action_view.h" | 21 #include "chrome/browser/ui/views/browser_action_view.h" |
| 21 #include "chrome/browser/ui/views/browser_actions_container.h" | 22 #include "chrome/browser/ui/views/browser_actions_container.h" |
| 22 #include "chrome/browser/ui/views/frame/browser_view.h" | 23 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 23 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 24 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 24 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 25 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 25 #include "chrome/browser/ui/views/toolbar_view.h" | 26 #include "chrome/browser/ui/views/toolbar_view.h" |
| 26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 27 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "chrome/common/extensions/extension.h" | 29 #include "chrome/common/extensions/extension.h" |
| 29 #include "chrome/common/extensions/extension_action.h" | 30 #include "chrome/common/extensions/extension_action.h" |
| 31 #include "chrome/common/url_constants.h" |
| 30 #include "content/public/browser/notification_details.h" | 32 #include "content/public/browser/notification_details.h" |
| 31 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
| 32 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
| 33 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
| 34 #include "grit/ui_resources.h" | 36 #include "grit/ui_resources.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
| 37 #include "ui/views/controls/button/image_button.h" | 39 #include "ui/views/controls/button/image_button.h" |
| 38 #include "ui/views/controls/image_view.h" | 40 #include "ui/views/controls/image_view.h" |
| 39 #include "ui/views/controls/label.h" | 41 #include "ui/views/controls/label.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 InstalledBubbleContent(Browser* browser, | 97 InstalledBubbleContent(Browser* browser, |
| 96 const Extension* extension, | 98 const Extension* extension, |
| 97 ExtensionInstalledBubble::BubbleType type, | 99 ExtensionInstalledBubble::BubbleType type, |
| 98 SkBitmap* icon, | 100 SkBitmap* icon, |
| 99 ExtensionInstalledBubble* bubble) | 101 ExtensionInstalledBubble* bubble) |
| 100 : browser_(browser), | 102 : browser_(browser), |
| 101 extension_id_(extension->id()), | 103 extension_id_(extension->id()), |
| 102 bubble_(bubble), | 104 bubble_(bubble), |
| 103 type_(type), | 105 type_(type), |
| 104 info_(NULL), | 106 info_(NULL), |
| 105 manage_(NULL) { | 107 manage_(NULL), |
| 108 manage_shortcut_(NULL) { |
| 106 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 109 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 107 const gfx::Font& font = rb.GetFont(ui::ResourceBundle::BaseFont); | 110 const gfx::Font& font = rb.GetFont(ui::ResourceBundle::BaseFont); |
| 108 | 111 |
| 109 // Scale down to 43x43, but allow smaller icons (don't scale up). | 112 // Scale down to 43x43, but allow smaller icons (don't scale up). |
| 110 gfx::Size size(icon->width(), icon->height()); | 113 gfx::Size size(icon->width(), icon->height()); |
| 111 if (size.width() > kIconSize || size.height() > kIconSize) | 114 if (size.width() > kIconSize || size.height() > kIconSize) |
| 112 size = gfx::Size(kIconSize, kIconSize); | 115 size = gfx::Size(kIconSize, kIconSize); |
| 113 icon_ = new views::ImageView(); | 116 icon_ = new views::ImageView(); |
| 114 icon_->SetImageSize(size); | 117 icon_->SetImageSize(size); |
| 115 icon_->SetImage(*icon); | 118 icon_->SetImage(*icon); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 has_keybinding = true; | 163 has_keybinding = true; |
| 161 info_ = new views::Label(l10n_util::GetStringFUTF16( | 164 info_ = new views::Label(l10n_util::GetStringFUTF16( |
| 162 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT, | 165 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT, |
| 163 browser_action_command.accelerator().GetShortcutText())); | 166 browser_action_command.accelerator().GetShortcutText())); |
| 164 } | 167 } |
| 165 | 168 |
| 166 info_->SetFont(font); | 169 info_->SetFont(font); |
| 167 info_->SetMultiLine(true); | 170 info_->SetMultiLine(true); |
| 168 info_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 171 info_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 169 AddChildView(info_); | 172 AddChildView(info_); |
| 173 |
| 174 manage_shortcut_ = new views::Link( |
| 175 l10n_util::GetStringUTF16( |
| 176 IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS)); |
| 170 break; | 177 break; |
| 171 } | 178 } |
| 172 case ExtensionInstalledBubble::PAGE_ACTION: { | 179 case ExtensionInstalledBubble::PAGE_ACTION: { |
| 173 extensions::CommandService* command_service = | 180 extensions::CommandService* command_service = |
| 174 extensions::CommandServiceFactory::GetForProfile( | 181 extensions::CommandServiceFactory::GetForProfile( |
| 175 browser_->profile()); | 182 browser_->profile()); |
| 176 extensions::Command page_action_command; | 183 extensions::Command page_action_command; |
| 177 if (!command_service->GetPageActionCommand( | 184 if (!command_service->GetPageActionCommand( |
| 178 extension->id(), | 185 extension->id(), |
| 179 extensions::CommandService::ACTIVE_ONLY, | 186 extensions::CommandService::ACTIVE_ONLY, |
| 180 &page_action_command, | 187 &page_action_command, |
| 181 NULL)) { | 188 NULL)) { |
| 182 info_ = new views::Label(l10n_util::GetStringUTF16( | 189 info_ = new views::Label(l10n_util::GetStringUTF16( |
| 183 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO)); | 190 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO)); |
| 184 } else { | 191 } else { |
| 185 has_keybinding = true; | 192 has_keybinding = true; |
| 186 info_ = new views::Label(l10n_util::GetStringFUTF16( | 193 info_ = new views::Label(l10n_util::GetStringFUTF16( |
| 187 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO_WITH_SHORTCUT, | 194 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO_WITH_SHORTCUT, |
| 188 page_action_command.accelerator().GetShortcutText())); | 195 page_action_command.accelerator().GetShortcutText())); |
| 196 manage_shortcut_ = new views::Link( |
| 197 l10n_util::GetStringUTF16( |
| 198 IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS)); |
| 189 } | 199 } |
| 190 | 200 |
| 191 info_->SetFont(font); | 201 info_->SetFont(font); |
| 192 info_->SetMultiLine(true); | 202 info_->SetMultiLine(true); |
| 193 info_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 203 info_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 194 AddChildView(info_); | 204 AddChildView(info_); |
| 195 break; | 205 break; |
| 196 } | 206 } |
| 197 case ExtensionInstalledBubble::OMNIBOX_KEYWORD: { | 207 case ExtensionInstalledBubble::OMNIBOX_KEYWORD: { |
| 198 info_ = new views::Label(l10n_util::GetStringFUTF16( | 208 info_ = new views::Label(l10n_util::GetStringFUTF16( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 213 manage_->SetMultiLine(true); | 223 manage_->SetMultiLine(true); |
| 214 manage_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 224 manage_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 215 AddChildView(manage_); | 225 AddChildView(manage_); |
| 216 break; | 226 break; |
| 217 } | 227 } |
| 218 default: | 228 default: |
| 219 break; | 229 break; |
| 220 } | 230 } |
| 221 | 231 |
| 222 if (has_keybinding) { | 232 if (has_keybinding) { |
| 223 // TODO(finnur): Show the shortcut link. | 233 manage_shortcut_->set_listener(this); |
| 234 AddChildView(manage_shortcut_); |
| 224 } else if (type_ != ExtensionInstalledBubble::APP) { | 235 } else if (type_ != ExtensionInstalledBubble::APP) { |
| 225 manage_ = new views::Label( | 236 manage_ = new views::Label( |
| 226 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_INFO)); | 237 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_INFO)); |
| 227 manage_->SetFont(font); | 238 manage_->SetFont(font); |
| 228 manage_->SetMultiLine(true); | 239 manage_->SetMultiLine(true); |
| 229 manage_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 240 manage_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 230 AddChildView(manage_); | 241 AddChildView(manage_); |
| 231 } | 242 } |
| 232 | 243 |
| 233 close_button_ = new views::ImageButton(this); | 244 close_button_ = new views::ImageButton(this); |
| 234 close_button_->SetImage(views::CustomButton::BS_NORMAL, | 245 close_button_->SetImage(views::CustomButton::BS_NORMAL, |
| 235 rb.GetImageSkiaNamed(IDR_CLOSE_BAR)); | 246 rb.GetImageSkiaNamed(IDR_CLOSE_BAR)); |
| 236 close_button_->SetImage(views::CustomButton::BS_HOT, | 247 close_button_->SetImage(views::CustomButton::BS_HOT, |
| 237 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_H)); | 248 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_H)); |
| 238 close_button_->SetImage(views::CustomButton::BS_PUSHED, | 249 close_button_->SetImage(views::CustomButton::BS_PUSHED, |
| 239 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_P)); | 250 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_P)); |
| 240 AddChildView(close_button_); | 251 AddChildView(close_button_); |
| 241 } | 252 } |
| 242 | 253 |
| 243 virtual void ButtonPressed(views::Button* sender, const ui::Event& event) { | 254 virtual void ButtonPressed(views::Button* sender, const ui::Event& event) { |
| 244 if (sender == close_button_) | 255 if (sender == close_button_) |
| 245 bubble_->StartFade(false); | 256 bubble_->StartFade(false); |
| 246 else | 257 else |
| 247 NOTREACHED() << "Unknown view"; | 258 NOTREACHED() << "Unknown view"; |
| 248 } | 259 } |
| 249 | 260 |
| 250 // Implements the views::LinkListener interface. | 261 // Implements the views::LinkListener interface. |
| 251 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { | 262 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { |
| 252 GetWidget()->Close(); | 263 GetWidget()->Close(); |
| 253 ExtensionInstallUI::OpenAppInstalledUI(browser_, extension_id_); | 264 if (source == manage_shortcut_) { |
| 265 std::string configure_url = chrome::kChromeUIExtensionsURL; |
| 266 configure_url += chrome::kExtensionConfigureCommandsSubPage; |
| 267 chrome::NavigateParams params( |
| 268 chrome::GetSingletonTabNavigateParams( |
| 269 browser_, GURL(configure_url.c_str()))); |
| 270 chrome::Navigate(¶ms); |
| 271 } else { |
| 272 ExtensionInstallUI::OpenAppInstalledUI(browser_, extension_id_); |
| 273 } |
| 254 } | 274 } |
| 255 | 275 |
| 256 private: | 276 private: |
| 257 virtual gfx::Size GetPreferredSize() { | 277 virtual gfx::Size GetPreferredSize() { |
| 258 int width = kHorizOuterMargin; | 278 int width = kHorizOuterMargin; |
| 259 width += kIconSize; | 279 width += kIconSize; |
| 260 width += views::kPanelHorizMargin; | 280 width += views::kPanelHorizMargin; |
| 261 width += kRightColumnWidth; | 281 width += kRightColumnWidth; |
| 262 width += 2 * views::kPanelHorizMargin; | 282 width += 2 * views::kPanelHorizMargin; |
| 263 width += kHorizOuterMargin; | 283 width += kHorizOuterMargin; |
| 264 | 284 |
| 265 int height = kVertOuterMargin; | 285 int height = kVertOuterMargin; |
| 266 height += heading_->GetHeightForWidth(kRightColumnWidth); | 286 height += heading_->GetHeightForWidth(kRightColumnWidth); |
| 267 height += kVertInnerMargin; | 287 height += kVertInnerMargin; |
| 268 if (info_) { | 288 if (info_) { |
| 269 height += info_->GetHeightForWidth(kRightColumnWidth); | 289 height += info_->GetHeightForWidth(kRightColumnWidth); |
| 270 height += kVertInnerMargin; | 290 height += kVertInnerMargin; |
| 271 } | 291 } |
| 272 | 292 |
| 273 if (manage_) { | 293 if (manage_) { |
| 274 height += manage_->GetHeightForWidth(kRightColumnWidth); | 294 height += manage_->GetHeightForWidth(kRightColumnWidth); |
| 275 height += kVertOuterMargin; | 295 height += kVertOuterMargin; |
| 276 } | 296 } |
| 277 | 297 |
| 298 if (manage_shortcut_) { |
| 299 height += manage_shortcut_->GetHeightForWidth(kRightColumnWidth); |
| 300 height += kVertOuterMargin; |
| 301 } |
| 302 |
| 278 return gfx::Size(width, std::max(height, kIconSize + 2 * kVertOuterMargin)); | 303 return gfx::Size(width, std::max(height, kIconSize + 2 * kVertOuterMargin)); |
| 279 } | 304 } |
| 280 | 305 |
| 281 virtual void Layout() { | 306 virtual void Layout() { |
| 282 int x = kHorizOuterMargin; | 307 int x = kHorizOuterMargin; |
| 283 int y = kVertOuterMargin; | 308 int y = kVertOuterMargin; |
| 284 | 309 |
| 285 icon_->SetBounds(x, y, kIconSize, kIconSize); | 310 icon_->SetBounds(x, y, kIconSize, kIconSize); |
| 286 x += kIconSize; | 311 x += kIconSize; |
| 287 x += views::kPanelHorizMargin; | 312 x += views::kPanelHorizMargin; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 302 } | 327 } |
| 303 | 328 |
| 304 if (manage_) { | 329 if (manage_) { |
| 305 manage_->SizeToFit(kRightColumnWidth); | 330 manage_->SizeToFit(kRightColumnWidth); |
| 306 manage_->SetX(x); | 331 manage_->SetX(x); |
| 307 manage_->SetY(y); | 332 manage_->SetY(y); |
| 308 y += manage_->height(); | 333 y += manage_->height(); |
| 309 y += kVertInnerMargin; | 334 y += kVertInnerMargin; |
| 310 } | 335 } |
| 311 | 336 |
| 337 if (manage_shortcut_) { |
| 338 gfx::Size sz = manage_shortcut_->GetPreferredSize(); |
| 339 manage_shortcut_->SetBounds(width() - 2 * kHorizOuterMargin - sz.width(), |
| 340 y, |
| 341 sz.width(), |
| 342 sz.height()); |
| 343 y += manage_shortcut_->height(); |
| 344 y += kVertInnerMargin; |
| 345 } |
| 346 |
| 312 gfx::Size sz; | 347 gfx::Size sz; |
| 313 x += kRightColumnWidth + 2 * views::kPanelHorizMargin + kHorizOuterMargin - | 348 x += kRightColumnWidth + 2 * views::kPanelHorizMargin + kHorizOuterMargin - |
| 314 close_button_->GetPreferredSize().width(); | 349 close_button_->GetPreferredSize().width(); |
| 315 y = kVertOuterMargin; | 350 y = kVertOuterMargin; |
| 316 sz = close_button_->GetPreferredSize(); | 351 sz = close_button_->GetPreferredSize(); |
| 317 // x-1 & y-1 is just slop to get the close button visually aligned with the | 352 // x-1 & y-1 is just slop to get the close button visually aligned with the |
| 318 // title text and bubble arrow. | 353 // title text and bubble arrow. |
| 319 close_button_->SetBounds(x - 1, y - 1, sz.width(), sz.height()); | 354 close_button_->SetBounds(x - 1, y - 1, sz.width(), sz.height()); |
| 320 } | 355 } |
| 321 | 356 |
| 322 // The browser we're associated with. | 357 // The browser we're associated with. |
| 323 Browser* browser_; | 358 Browser* browser_; |
| 324 | 359 |
| 325 // The id of the extension just installed. | 360 // The id of the extension just installed. |
| 326 const std::string extension_id_; | 361 const std::string extension_id_; |
| 327 | 362 |
| 328 // The ExtensionInstalledBubble showing us. | 363 // The ExtensionInstalledBubble showing us. |
| 329 ExtensionInstalledBubble* bubble_; | 364 ExtensionInstalledBubble* bubble_; |
| 330 | 365 |
| 331 ExtensionInstalledBubble::BubbleType type_; | 366 ExtensionInstalledBubble::BubbleType type_; |
| 332 views::ImageView* icon_; | 367 views::ImageView* icon_; |
| 333 views::Label* heading_; | 368 views::Label* heading_; |
| 334 views::Label* info_; | 369 views::Label* info_; |
| 335 views::Label* manage_; | 370 views::Label* manage_; |
| 371 views::Link* manage_shortcut_; |
| 336 views::ImageButton* close_button_; | 372 views::ImageButton* close_button_; |
| 337 | 373 |
| 338 DISALLOW_COPY_AND_ASSIGN(InstalledBubbleContent); | 374 DISALLOW_COPY_AND_ASSIGN(InstalledBubbleContent); |
| 339 }; | 375 }; |
| 340 | 376 |
| 341 void ExtensionInstalledBubble::Show(const Extension* extension, | 377 void ExtensionInstalledBubble::Show(const Extension* extension, |
| 342 Browser *browser, | 378 Browser *browser, |
| 343 const SkBitmap& icon) { | 379 const SkBitmap& icon) { |
| 344 new ExtensionInstalledBubble(extension, browser, icon); | 380 new ExtensionInstalledBubble(extension, browser, icon); |
| 345 } | 381 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 } | 515 } |
| 480 | 516 |
| 481 void ExtensionInstalledBubble::WindowClosing() { | 517 void ExtensionInstalledBubble::WindowClosing() { |
| 482 if (extension_ && type_ == PAGE_ACTION) { | 518 if (extension_ && type_ == PAGE_ACTION) { |
| 483 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 519 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
| 484 browser_view->GetLocationBarView()->SetPreviewEnabledPageAction( | 520 browser_view->GetLocationBarView()->SetPreviewEnabledPageAction( |
| 485 extension_->page_action(), | 521 extension_->page_action(), |
| 486 false); // preview_enabled | 522 false); // preview_enabled |
| 487 } | 523 } |
| 488 } | 524 } |
| OLD | NEW |