15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/views/extensions/bookmark_app_bubble_view.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/strings/string16.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/extensions/app_icon_loader_impl.h" 10e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "chrome/browser/extensions/bookmark_app_helper.h" 11e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "chrome/browser/extensions/extension_service.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/extensions/launch_util.h" 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/common/extensions/extension_constants.h" 151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/grit/generated_resources.h" 16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "extensions/browser/extension_prefs.h" 17116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "extensions/browser/extension_registry.h" 18116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "extensions/browser/extension_system.h" 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/pref_names.h" 205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/browser/uninstall_reason.h" 21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "extensions/common/constants.h" 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h" 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/events/keycodes/keyboard_codes.h" 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/controls/button/checkbox.h" 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/controls/button/label_button.h" 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/views/controls/image_view.h" 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/controls/label.h" 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/controls/textfield/textfield.h" 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/layout/grid_layout.h" 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/layout/layout_constants.h" 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/widget/widget.h" 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using views::ColumnSet; 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using views::GridLayout; 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace { 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Minimum width of the the bubble. 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const int kMinBubbleWidth = 300; 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Minimum width of the the textfield. 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const int kMinTextfieldWidth = 200; 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Size of the icon. 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)const int kIconSize = extension_misc::EXTENSION_ICON_MEDIUM; 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 46116680a4aac90f2aa7413d9095a592090648e557Ben MurdochExtensionService* GetExtensionService(Profile* profile) { 47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return extensions::ExtensionSystem::Get(profile)->extension_service(); 48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)BookmarkAppBubbleView* BookmarkAppBubbleView::bookmark_app_bubble_ = NULL; 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)BookmarkAppBubbleView::~BookmarkAppBubbleView() { 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// static 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void BookmarkAppBubbleView::ShowBubble(views::View* anchor_view, 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Profile* profile, 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const WebApplicationInfo& web_app_info, 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& extension_id) { 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (bookmark_app_bubble_ != NULL) 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bookmark_app_bubble_ = new BookmarkAppBubbleView( 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) anchor_view, profile, web_app_info, extension_id); 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) views::BubbleDelegateView::CreateBubble(bookmark_app_bubble_)->Show(); 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Select the entire title textfield contents when the bubble is first shown. 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bookmark_app_bubble_->title_tf_->SelectAll(true); 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bookmark_app_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)BookmarkAppBubbleView::BookmarkAppBubbleView( 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) views::View* anchor_view, 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Profile* profile, 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const WebApplicationInfo& web_app_info, 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& extension_id) 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile_(profile), 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) web_app_info_(web_app_info), 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) extension_id_(extension_id), 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) add_button_(NULL), 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cancel_button_(NULL), 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) open_as_tab_checkbox_(NULL), 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) title_tf_(NULL), 86a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) remove_app_(true), 87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) app_icon_loader_(new extensions::AppIconLoaderImpl(profile, 88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kIconSize, 89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) this)) { 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const SkColor background_color = GetNativeTheme()->GetSystemColor( 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::NativeTheme::kColorId_DialogBackground); 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) set_arrow(views::BubbleBorder::TOP_CENTER); 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) set_color(background_color); 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) set_background(views::Background::CreateSolidBackground(background_color)); 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) set_margins(gfx::Insets(views::kPanelVertMargin, 0, 0, 0)); 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void BookmarkAppBubbleView::Init() { 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) views::Label* title_label = new views::Label( 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_TITLE)); 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) title_label->SetFontList(rb->GetFontList(ui::ResourceBundle::MediumFont)); 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) add_button_ = 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_ADD)); 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) add_button_->SetStyle(views::Button::STYLE_BUTTON); 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) add_button_->SetIsDefault(true); 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cancel_button_ = 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_CANCEL)); 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cancel_button_->SetStyle(views::Button::STYLE_BUTTON); 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GridLayout* layout = new GridLayout(this); 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetLayoutManager(layout); 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Column sets used in the layout of the bubble. 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) enum ColumnSetID { 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TITLE_COLUMN_SET_ID, 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TITLE_TEXT_COLUMN_SET_ID, 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CONTENT_COLUMN_SET_ID 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The column layout used for the title and checkbox. 1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ColumnSet* cs = layout->AddColumnSet(TITLE_COLUMN_SET_ID); 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs->AddColumn( 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0); 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The column layout used for the icon and text box. 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs = layout->AddColumnSet(TITLE_TEXT_COLUMN_SET_ID); 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) cs->AddColumn(GridLayout::LEADING, 135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GridLayout::CENTER, 136a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 0, 137a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GridLayout::USE_PREF, 138a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 0, 139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 0); 140a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs->AddColumn(GridLayout::FILL, 142a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GridLayout::CENTER, 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1, 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GridLayout::USE_PREF, 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 0, 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) kMinTextfieldWidth); 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The column layout used for the row with buttons. 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs = layout->AddColumnSet(CONTENT_COLUMN_SET_ID); 151a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs->AddColumn( 153a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0); 154a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); 155a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) cs->AddColumn( 156a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0); 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs->AddColumn( 159a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0); 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->StartRow(0, TITLE_COLUMN_SET_ID); 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddView(title_label); 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const extensions::Extension* extension = 167116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( 168116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch extension_id_, extensions::ExtensionRegistry::EVERYTHING); 169a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 170a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) layout->StartRow(0, TITLE_TEXT_COLUMN_SET_ID); 171a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) icon_image_view_ = new views::ImageView(); 172a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) icon_image_view_->SetImageSize(gfx::Size(kIconSize, kIconSize)); 173a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) layout->AddView(icon_image_view_); 174a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) app_icon_loader_->FetchImage(extension_id_); 175a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 176a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) title_tf_ = new views::Textfield(); 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) title_tf_->SetText(extension ? base::UTF8ToUTF16(extension->name()) 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : web_app_info_.title); 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddView(title_tf_); 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 182a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) layout->StartRow(0, CONTENT_COLUMN_SET_ID); 1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) open_as_tab_checkbox_ = new views::Checkbox( 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_TAB)); 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) open_as_tab_checkbox_->SetChecked( 1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile_->GetPrefs()->GetInteger( 1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) extensions::pref_names::kBookmarkAppCreationLaunchType) == 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) extensions::LAUNCH_TYPE_REGULAR); 1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddView(open_as_tab_checkbox_); 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddView(add_button_); 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddView(cancel_button_); 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)views::View* BookmarkAppBubbleView::GetInitiallyFocusedView() { 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return title_tf_; 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void BookmarkAppBubbleView::WindowClosing() { 2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We have to reset |bookmark_app_bubble_| here, not in our destructor, 2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // because we'll be destroyed asynchronously and the shown state will be 2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // checked before then. 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK_EQ(bookmark_app_bubble_, this); 2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bookmark_app_bubble_ = NULL; 2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (remove_app_) { 2095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) GetExtensionService(profile_) 2105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ->UninstallExtension(extension_id_, 2115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) extensions::UNINSTALL_REASON_INSTALL_CANCELED, 2125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::Bind(&base::DoNothing), 2135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NULL); 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ApplyEdits(); 2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool BookmarkAppBubbleView::AcceleratorPressed( 2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const ui::Accelerator& accelerator) { 2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (accelerator.key_code() == ui::VKEY_RETURN) { 2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) HandleButtonPressed(add_button_); 2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return BubbleDelegateView::AcceleratorPressed(accelerator); 2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 228cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)gfx::Size BookmarkAppBubbleView::GetMinimumSize() const { 2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Size size(views::BubbleDelegateView::GetPreferredSize()); 2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) size.SetToMax(gfx::Size(kMinBubbleWidth, 0)); 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return size; 2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void BookmarkAppBubbleView::ButtonPressed(views::Button* sender, 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const ui::Event& event) { 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) HandleButtonPressed(sender); 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 239a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void BookmarkAppBubbleView::SetAppImage(const std::string& id, 240a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::ImageSkia& image) { 241a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DCHECK_EQ(extension_id_, id); 242a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) icon_image_view_->SetImage(image); 243a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 244a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void BookmarkAppBubbleView::HandleButtonPressed(views::Button* sender) { 2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Unset |remove_app_| so we don't delete the bookmark after the window 2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // closes. 2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (sender == add_button_) 2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) remove_app_ = false; 2505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 251a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetWidget()->Close(); 2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void BookmarkAppBubbleView::ApplyEdits() { 2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set the launch type based on the checkbox. 2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) extensions::LaunchType launch_type = open_as_tab_checkbox_->checked() 2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ? extensions::LAUNCH_TYPE_REGULAR 2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : extensions::LAUNCH_TYPE_WINDOW; 2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile_->GetPrefs()->SetInteger( 2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type); 261116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch extensions::SetLaunchType(GetExtensionService(profile_), 2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) extension_id_, 2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launch_type); 2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const extensions::Extension* extension = 266116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( 267116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch extension_id_, extensions::ExtensionRegistry::EVERYTHING); 2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (extension && base::UTF8ToUTF16(extension->name()) == title_tf_->text()) 2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Reinstall the app with an updated name. 2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WebApplicationInfo install_info(web_app_info_); 2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) install_info.title = title_tf_->text(); 2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 275116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch extensions::CreateOrUpdateBookmarkApp(GetExtensionService(profile_), 276e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch install_info); 2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 278