Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc

Issue 2803293002: Create Bookmark Footnote desktop iOS promotion (Closed)
Patch Set: no explicit remove Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/bookmarks/bookmark_bubble_view.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/metrics/user_metrics.h" 10 #include "base/metrics/user_metrics.h"
(...skipping 25 matching lines...) Expand all
36 #include "ui/views/controls/link.h" 36 #include "ui/views/controls/link.h"
37 #include "ui/views/controls/textfield/textfield.h" 37 #include "ui/views/controls/textfield/textfield.h"
38 #include "ui/views/layout/fill_layout.h" 38 #include "ui/views/layout/fill_layout.h"
39 #include "ui/views/layout/grid_layout.h" 39 #include "ui/views/layout/grid_layout.h"
40 #include "ui/views/layout/layout_constants.h" 40 #include "ui/views/layout/layout_constants.h"
41 #include "ui/views/widget/widget.h" 41 #include "ui/views/widget/widget.h"
42 42
43 #if defined(OS_WIN) 43 #if defined(OS_WIN)
44 #include "chrome/browser/sync/profile_sync_service_factory.h" 44 #include "chrome/browser/sync/profile_sync_service_factory.h"
45 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu bble_view.h" 45 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu bble_view.h"
46 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_fo otnote_view.h"
46 #include "components/browser_sync/profile_sync_service.h" 47 #include "components/browser_sync/profile_sync_service.h"
47 #endif 48 #endif
48 49
49 using base::UserMetricsAction; 50 using base::UserMetricsAction;
50 using bookmarks::BookmarkModel; 51 using bookmarks::BookmarkModel;
51 using bookmarks::BookmarkNode; 52 using bookmarks::BookmarkNode;
52 using views::ColumnSet; 53 using views::ColumnSet;
53 using views::GridLayout; 54 using views::GridLayout;
54 55
55 namespace { 56 namespace {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // |parent_combobox_| needs to be destroyed before |parent_model_| as it 129 // |parent_combobox_| needs to be destroyed before |parent_model_| as it
129 // uses |parent_model_| in its destructor. 130 // uses |parent_model_| in its destructor.
130 delete parent_combobox_; 131 delete parent_combobox_;
131 } 132 }
132 133
133 void BookmarkBubbleView::WindowClosing() { 134 void BookmarkBubbleView::WindowClosing() {
134 // We have to reset |bubble_| here, not in our destructor, because we'll be 135 // We have to reset |bubble_| here, not in our destructor, because we'll be
135 // destroyed asynchronously and the shown state will be checked before then. 136 // destroyed asynchronously and the shown state will be checked before then.
136 DCHECK_EQ(bookmark_bubble_, this); 137 DCHECK_EQ(bookmark_bubble_, this);
137 bookmark_bubble_ = NULL; 138 bookmark_bubble_ = NULL;
139 is_showing_ios_promotion_ = false;
138 140
139 if (observer_) 141 if (observer_)
140 observer_->OnBookmarkBubbleHidden(); 142 observer_->OnBookmarkBubbleHidden();
141 } 143 }
142 144
143 bool BookmarkBubbleView::AcceleratorPressed( 145 bool BookmarkBubbleView::AcceleratorPressed(
144 const ui::Accelerator& accelerator) { 146 const ui::Accelerator& accelerator) {
145 ui::KeyboardCode key_code = accelerator.key_code(); 147 ui::KeyboardCode key_code = accelerator.key_code();
146 if (key_code == ui::VKEY_RETURN) { 148 if (key_code == ui::VKEY_RETURN) {
147 HandleButtonPressed(close_button_); 149 HandleButtonPressed(close_button_);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 264
263 const char* BookmarkBubbleView::GetClassName() const { 265 const char* BookmarkBubbleView::GetClassName() const {
264 return "BookmarkBubbleView"; 266 return "BookmarkBubbleView";
265 } 267 }
266 268
267 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { 269 views::View* BookmarkBubbleView::GetInitiallyFocusedView() {
268 return title_tf_; 270 return title_tf_;
269 } 271 }
270 272
271 views::View* BookmarkBubbleView::CreateFootnoteView() { 273 views::View* BookmarkBubbleView::CreateFootnoteView() {
274 if (!is_showing_ios_promotion_ &&
275 IsIOSPromotionEligible(
276 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_FOOTNOTE)) {
277 footnote_view_ = new DesktopIOSPromotionFootnoteView(profile_, this);
278 return footnote_view_;
279 }
280
272 if (!SyncPromoUI::ShouldShowSyncPromo(profile_)) 281 if (!SyncPromoUI::ShouldShowSyncPromo(profile_))
273 return nullptr; 282 return nullptr;
274 283
275 base::RecordAction( 284 base::RecordAction(
276 base::UserMetricsAction("Signin_Impression_FromBookmarkBubble")); 285 base::UserMetricsAction("Signin_Impression_FromBookmarkBubble"));
277 286
278 return new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK, 287 footnote_view_ =
279 IDS_BOOKMARK_SYNC_PROMO_MESSAGE); 288 new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK,
289 IDS_BOOKMARK_SYNC_PROMO_MESSAGE);
290 return footnote_view_;
280 } 291 }
281 292
282 BookmarkBubbleView::BookmarkBubbleView( 293 BookmarkBubbleView::BookmarkBubbleView(
283 views::View* anchor_view, 294 views::View* anchor_view,
284 bookmarks::BookmarkBubbleObserver* observer, 295 bookmarks::BookmarkBubbleObserver* observer,
285 std::unique_ptr<BubbleSyncPromoDelegate> delegate, 296 std::unique_ptr<BubbleSyncPromoDelegate> delegate,
286 Profile* profile, 297 Profile* profile,
287 const GURL& url, 298 const GURL& url,
288 bool newly_bookmarked) 299 bool newly_bookmarked)
289 : LocationBarBubbleDelegateView(anchor_view, nullptr), 300 : LocationBarBubbleDelegateView(anchor_view, nullptr),
290 observer_(observer), 301 observer_(observer),
291 delegate_(std::move(delegate)), 302 delegate_(std::move(delegate)),
292 profile_(profile), 303 profile_(profile),
293 url_(url), 304 url_(url),
294 newly_bookmarked_(newly_bookmarked), 305 newly_bookmarked_(newly_bookmarked),
295 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), 306 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_),
296 BookmarkModelFactory::GetForBrowserContext(profile_) 307 BookmarkModelFactory::GetForBrowserContext(profile_)
297 ->GetMostRecentlyAddedUserNodeForURL(url)), 308 ->GetMostRecentlyAddedUserNodeForURL(url)),
298 remove_button_(nullptr), 309 remove_button_(nullptr),
299 edit_button_(nullptr), 310 edit_button_(nullptr),
300 close_button_(nullptr), 311 close_button_(nullptr),
301 title_tf_(nullptr), 312 title_tf_(nullptr),
302 parent_combobox_(nullptr), 313 parent_combobox_(nullptr),
303 ios_promo_view_(nullptr), 314 ios_promo_view_(nullptr),
315 footnote_view_(nullptr),
304 remove_bookmark_(false), 316 remove_bookmark_(false),
305 apply_edits_(true), 317 apply_edits_(true),
306 is_showing_ios_promotion_(false) { 318 is_showing_ios_promotion_(false) {
307 chrome::RecordDialogCreation(chrome::DialogIdentifier::BOOKMARK); 319 chrome::RecordDialogCreation(chrome::DialogIdentifier::BOOKMARK);
308 } 320 }
309 321
310 base::string16 BookmarkBubbleView::GetTitle() { 322 base::string16 BookmarkBubbleView::GetTitle() {
311 BookmarkModel* bookmark_model = 323 BookmarkModel* bookmark_model =
312 BookmarkModelFactory::GetForBrowserContext(profile_); 324 BookmarkModelFactory::GetForBrowserContext(profile_);
313 const BookmarkNode* node = 325 const BookmarkNode* node =
(...skipping 30 matching lines...) Expand all
344 // Set this so we remove the bookmark after the window closes. 356 // Set this so we remove the bookmark after the window closes.
345 remove_bookmark_ = true; 357 remove_bookmark_ = true;
346 apply_edits_ = false; 358 apply_edits_ = false;
347 GetWidget()->Close(); 359 GetWidget()->Close();
348 } else if (sender == edit_button_) { 360 } else if (sender == edit_button_) {
349 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); 361 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit"));
350 ShowEditor(); 362 ShowEditor();
351 } else { 363 } else {
352 DCHECK_EQ(close_button_, sender); 364 DCHECK_EQ(close_button_, sender);
353 #if defined(OS_WIN) 365 #if defined(OS_WIN)
354 PrefService* prefs = profile_->GetPrefs(); 366 if (IsIOSPromotionEligible(
355 const browser_sync::ProfileSyncService* sync_service =
356 ProfileSyncServiceFactory::GetForProfile(profile_);
357 if (desktop_ios_promotion::IsEligibleForIOSPromotion(
358 prefs, sync_service,
359 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE)) { 367 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE)) {
360 ShowIOSPromotion(); 368 ShowIOSPromotion(
369 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE);
361 } else { 370 } else {
362 GetWidget()->Close(); 371 GetWidget()->Close();
363 } 372 }
364 #else 373 #else
365 GetWidget()->Close(); 374 GetWidget()->Close();
366 #endif 375 #endif
367 } 376 }
368 } 377 }
369 378
370 void BookmarkBubbleView::ShowEditor() { 379 void BookmarkBubbleView::ShowEditor() {
(...skipping 25 matching lines...) Expand all
396 const base::string16 new_title = title_tf_->text(); 405 const base::string16 new_title = title_tf_->text();
397 if (new_title != node->GetTitle()) { 406 if (new_title != node->GetTitle()) {
398 model->SetTitle(node, new_title); 407 model->SetTitle(node, new_title);
399 base::RecordAction( 408 base::RecordAction(
400 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 409 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
401 } 410 }
402 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); 411 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index());
403 } 412 }
404 } 413 }
405 414
415 void BookmarkBubbleView::OnIOSPromotionFootnoteLinkClicked() {
406 #if defined(OS_WIN) 416 #if defined(OS_WIN)
407 void BookmarkBubbleView::ShowIOSPromotion() { 417 ShowIOSPromotion(
418 desktop_ios_promotion::PromotionEntryPoint::FOOTNOTE_FOLLOWUP_BUBBLE);
419 #endif
420 }
421
422 #if defined(OS_WIN)
423
424 bool BookmarkBubbleView::IsIOSPromotionEligible(
425 desktop_ios_promotion::PromotionEntryPoint entry_point) {
426 PrefService* prefs = profile_->GetPrefs();
427 const browser_sync::ProfileSyncService* sync_service =
428 ProfileSyncServiceFactory::GetForProfile(profile_);
429 return desktop_ios_promotion::IsEligibleForIOSPromotion(prefs, sync_service,
430 entry_point);
431 }
432
433 void BookmarkBubbleView::ShowIOSPromotion(
434 desktop_ios_promotion::PromotionEntryPoint entry_point) {
408 DCHECK(!is_showing_ios_promotion_); 435 DCHECK(!is_showing_ios_promotion_);
409 RemoveChildView(bookmark_details_view_.get()); 436 RemoveChildView(bookmark_details_view_.get());
437 if (footnote_view_) {
sky 2017/05/24 00:03:35 You don't actually need this conditional (delete n
mrefaat1 2017/05/24 02:27:17 Done.
438 delete footnote_view_;
439 footnote_view_ = nullptr;
440 }
441
410 is_showing_ios_promotion_ = true; 442 is_showing_ios_promotion_ = true;
411 ios_promo_view_ = new DesktopIOSPromotionBubbleView( 443 ios_promo_view_ = new DesktopIOSPromotionBubbleView(profile_, entry_point);
412 profile_, desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE);
413 AddChildView(ios_promo_view_); 444 AddChildView(ios_promo_view_);
414 GetWidget()->UpdateWindowIcon(); 445 GetWidget()->UpdateWindowIcon();
415 GetWidget()->UpdateWindowTitle(); 446 GetWidget()->UpdateWindowTitle();
416 // Resize the bubble so it has the same width as the parent bubble. 447 // Resize the bubble so it has the same width as the parent bubble.
417 ios_promo_view_->UpdateBubbleHeight(); 448 ios_promo_view_->UpdateBubbleHeight();
418 } 449 }
419 #endif 450 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698