12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" 87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/notifications/sync_notifier/synced_notification.h" 97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/ui/browser.h" 107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/ui/browser_finder.h" 117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "content/public/browser/page_navigator.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace notifier { 147dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochChromeNotifierDelegate::ChromeNotifierDelegate( 157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const std::string& notification_id, 167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch ChromeNotifierService* notifier) 177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch : notification_id_(notification_id), chrome_notifier_(notifier) {} 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ChromeNotifierDelegate::~ChromeNotifierDelegate() {} 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)std::string ChromeNotifierDelegate::id() const { 227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return notification_id_; 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)content::RenderViewHost* ChromeNotifierDelegate::GetRenderViewHost() const { 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return NULL; 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// TODO(petewil) Add the ability to do URL actions also. 307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid ChromeNotifierDelegate::Click() { 317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SyncedNotification* notification = 327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chrome_notifier_->FindNotificationById(notification_id_); 337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (notification == NULL) 347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return; 357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch GURL destination = notification->GetDefaultDestinationUrl(); 377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch NavigateToUrl(destination); 387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// TODO(petewil) Add the ability to do URL actions also. 417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid ChromeNotifierDelegate::ButtonClick(int button_index) { 427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SyncedNotification* notification = 437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chrome_notifier_->FindNotificationById(notification_id_); 447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (notification) { 457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch GURL destination = notification->GetButtonUrl(button_index); 467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch NavigateToUrl(destination); 477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid ChromeNotifierDelegate::NavigateToUrl(const GURL& destination) const { 517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!destination.is_valid()) 527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return; 537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch content::OpenURLParams openParams(destination, content::Referrer(), 557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch NEW_FOREGROUND_TAB, 567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch content::PAGE_TRANSITION_LINK, false); 577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch Browser* browser = chrome::FindLastActiveWithProfile( 587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chrome_notifier_->profile(), 597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chrome::GetActiveDesktop()); 607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Navigate to the URL in a new tab. 617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (browser != NULL) 627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch browser->OpenURL(openParams); 637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ChromeNotifierDelegate::Close(bool by_user) { 67c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (by_user) 684311e82a78ceafbe0585f51d4c8a86df9f21aa0dBen Murdoch chrome_notifier_->MarkNotificationAsRead(notification_id_); 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace notifier 72