chrome_web_contents_view_delegate_android.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/android/tab_contents/chrome_web_contents_view_delegate_android.h" 6 7#include "base/logging.h" 8#include "chrome/browser/android/tab_android.h" 9#include "content/public/browser/android/content_view_core.h" 10#include "content/public/browser/web_contents.h" 11#include "content/public/browser/web_contents_view_delegate.h" 12#include "content/public/common/context_menu_params.h" 13 14ChromeWebContentsViewDelegateAndroid::ChromeWebContentsViewDelegateAndroid( 15 content::WebContents* web_contents) 16 : web_contents_(web_contents) { 17} 18 19ChromeWebContentsViewDelegateAndroid::~ChromeWebContentsViewDelegateAndroid() { 20} 21 22content::WebDragDestDelegate* 23ChromeWebContentsViewDelegateAndroid::GetDragDestDelegate() { 24 // GetDragDestDelegate is a pure virtual method from WebContentsViewDelegate 25 // and must have an implementation although android doesn't use it. 26 NOTREACHED(); 27 return NULL; 28} 29 30void ChromeWebContentsViewDelegateAndroid::ShowContextMenu( 31 const content::ContextMenuParams& params, 32 content::ContextMenuSourceType type) { 33 // Display paste pop-up only when selection is empty and editable. 34 if (params.is_editable && params.selection_text.empty()) { 35 content::ContentViewCore* content_view_core = 36 web_contents_->GetContentNativeView(); 37 if (content_view_core) { 38 content_view_core->ShowPastePopup(params.selection_start.x(), 39 params.selection_start.y()); 40 return; 41 } 42 } 43 44 TabAndroid* tab = TabAndroid::FromWebContents(web_contents_); 45 // We may not have a Tab if we're running in Android WebView mode. 46 // TODO: The long term plan is to factor out the context menu code into 47 // a shared class and have WebView use a separate delegate. 48 if (tab) 49 tab->ShowContextMenu(params); 50} 51 52namespace chrome { 53 54content::WebContentsViewDelegate* CreateWebContentsViewDelegate( 55 content::WebContents* web_contents) { 56 return new ChromeWebContentsViewDelegateAndroid(web_contents); 57} 58 59} // namespace chrome 60