2010-10-23 19:00:47 +02:00
|
|
|
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "browser_webview_delegate.h"
|
2011-08-02 18:50:06 +02:00
|
|
|
#import "browser_webview_mac.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
#include "browser_impl.h"
|
2011-08-02 18:50:06 +02:00
|
|
|
#import "include/cef_application_mac.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2011-08-02 18:50:06 +02:00
|
|
|
#include "base/mac/mac_util.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
#include "base/sys_string_conversions.h"
|
2011-08-02 18:50:06 +02:00
|
|
|
#include "skia/ext/skia_utils_mac.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
|
2011-08-02 18:50:06 +02:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
#include "webkit/glue/webcursor.h"
|
2011-08-02 18:50:06 +02:00
|
|
|
#include "webkit/glue/webdropdata.h"
|
2011-01-07 22:34:20 +01:00
|
|
|
#include "webkit/plugins/npapi/plugin_list.h"
|
|
|
|
#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
#include "webkit/glue/webmenurunner_mac.h"
|
|
|
|
|
|
|
|
using WebKit::WebCursorInfo;
|
2011-08-02 18:50:06 +02:00
|
|
|
using WebKit::WebDragData;
|
|
|
|
using WebKit::WebDragOperationsMask;
|
2011-04-09 18:54:59 +02:00
|
|
|
using WebKit::WebExternalPopupMenu;
|
|
|
|
using WebKit::WebExternalPopupMenuClient;
|
2011-08-02 18:50:06 +02:00
|
|
|
using WebKit::WebImage;
|
2010-10-23 19:00:47 +02:00
|
|
|
using WebKit::WebNavigationPolicy;
|
2011-08-02 18:50:06 +02:00
|
|
|
using WebKit::WebPoint;
|
2010-10-23 19:00:47 +02:00
|
|
|
using WebKit::WebPopupMenuInfo;
|
|
|
|
using WebKit::WebRect;
|
|
|
|
using WebKit::WebWidget;
|
|
|
|
|
|
|
|
// WebViewClient --------------------------------------------------------------
|
|
|
|
|
2011-04-09 18:54:59 +02:00
|
|
|
WebExternalPopupMenu* BrowserWebViewDelegate::createExternalPopupMenu(
|
|
|
|
const WebPopupMenuInfo& info,
|
|
|
|
WebExternalPopupMenuClient* client) {
|
|
|
|
DCHECK(!external_popup_menu_.get());
|
|
|
|
external_popup_menu_.reset(new ExternalPopupMenu(this, info, client));
|
|
|
|
return external_popup_menu_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::ClosePopupMenu() {
|
|
|
|
if (external_popup_menu_ == NULL) {
|
|
|
|
NOTREACHED();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
external_popup_menu_.reset();
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::showContextMenu(
|
|
|
|
WebKit::WebFrame* frame, const WebKit::WebContextMenuData& data) {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
// WebWidgetClient ------------------------------------------------------------
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) {
|
|
|
|
NSCursor* ns_cursor = WebCursor(cursor_info).GetCursor();
|
|
|
|
[ns_cursor set];
|
|
|
|
}
|
|
|
|
|
|
|
|
WebRect BrowserWebViewDelegate::windowRect() {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost()) {
|
|
|
|
NSView *view = host->view_handle();
|
|
|
|
NSRect rect = [view frame];
|
|
|
|
return gfx::Rect(NSRectToCGRect(rect));
|
|
|
|
}
|
|
|
|
return WebRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::setWindowRect(const WebRect& rect) {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (this == browser_->UIT_GetWebViewDelegate()) {
|
2010-10-23 19:00:47 +02:00
|
|
|
// TODO(port): Set the window rectangle.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WebRect BrowserWebViewDelegate::rootWindowRect() {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost()) {
|
|
|
|
NSView *view = host->view_handle();
|
|
|
|
NSRect rect = [[[view window] contentView] frame];
|
|
|
|
return gfx::Rect(NSRectToCGRect(rect));
|
|
|
|
}
|
|
|
|
return WebRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
@interface NSWindow(OSInternals)
|
|
|
|
- (NSRect)_growBoxRect;
|
|
|
|
@end
|
|
|
|
|
|
|
|
WebRect BrowserWebViewDelegate::windowResizerRect() {
|
|
|
|
NSRect resize_rect = NSMakeRect(0, 0, 0, 0);
|
|
|
|
WebWidgetHost* host = GetWidgetHost();
|
|
|
|
if (host) {
|
|
|
|
NSView *view = host->view_handle();
|
|
|
|
NSWindow* window = [view window];
|
2011-07-03 04:00:01 +02:00
|
|
|
if (window == nil)
|
|
|
|
return gfx::Rect();
|
|
|
|
|
2010-10-23 19:00:47 +02:00
|
|
|
resize_rect = [window _growBoxRect];
|
|
|
|
// The scrollbar assumes that the resizer goes all the way down to the
|
|
|
|
// bottom corner, so we ignore any y offset to the rect itself and use the
|
|
|
|
// entire bottom corner.
|
|
|
|
resize_rect.origin.y = 0;
|
|
|
|
// Convert to view coordinates from window coordinates.
|
|
|
|
resize_rect = [view convertRect:resize_rect fromView:nil];
|
|
|
|
// Flip the rect in view coordinates
|
|
|
|
resize_rect.origin.y =
|
|
|
|
[view frame].size.height - resize_rect.origin.y -
|
|
|
|
resize_rect.size.height;
|
|
|
|
}
|
|
|
|
return gfx::Rect(NSRectToCGRect(resize_rect));
|
|
|
|
}
|
|
|
|
|
2011-08-02 18:50:06 +02:00
|
|
|
void BrowserWebViewDelegate::startDragging(const WebDragData& data,
|
|
|
|
WebDragOperationsMask mask,
|
|
|
|
const WebImage& image,
|
|
|
|
const WebPoint& image_offset) {
|
2011-08-02 19:30:11 +02:00
|
|
|
if (browser_->settings().drag_drop_disabled) {
|
|
|
|
browser_->UIT_GetWebView()->dragSourceSystemDragEnded();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-02 18:50:06 +02:00
|
|
|
WebWidgetHost* host = GetWidgetHost();
|
|
|
|
if (!host)
|
|
|
|
return;
|
|
|
|
|
|
|
|
BrowserWebView *view = static_cast<BrowserWebView*>(host->view_handle());
|
|
|
|
if (!view)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// By allowing nested tasks, the code below also allows Close(),
|
|
|
|
// which would deallocate |this|. The same problem can occur while
|
|
|
|
// processing -sendEvent:, so Close() is deferred in that case.
|
|
|
|
// Drags from web content do not come via -sendEvent:, this sets the
|
|
|
|
// same flag -sendEvent: would.
|
|
|
|
CefScopedSendingEvent sendingEventScoper;
|
|
|
|
|
|
|
|
// The drag invokes a nested event loop, arrange to continue
|
|
|
|
// processing events.
|
|
|
|
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
|
|
|
|
NSDragOperation op_mask = static_cast<NSDragOperation>(mask);
|
|
|
|
const SkBitmap& bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
|
|
|
|
CGColorSpaceRef color_space = base::mac::GetSystemColorSpace();
|
|
|
|
NSImage* ns_image = gfx::SkBitmapToNSImageWithColorSpace(bitmap, color_space);
|
|
|
|
NSPoint offset = NSPointFromCGPoint(gfx::Point(image_offset).ToCGPoint());
|
|
|
|
[view startDragWithDropData:WebDropData(data)
|
|
|
|
dragOperationMask:op_mask
|
|
|
|
image:ns_image
|
|
|
|
offset:offset];
|
|
|
|
}
|
|
|
|
|
2010-10-23 19:00:47 +02:00
|
|
|
void BrowserWebViewDelegate::runModal() {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
// WebPluginPageDelegate ------------------------------------------------------
|
|
|
|
|
2011-01-07 22:34:20 +01:00
|
|
|
webkit::npapi::WebPluginDelegate* BrowserWebViewDelegate::CreatePluginDelegate(
|
2010-10-23 19:00:47 +02:00
|
|
|
const FilePath& path,
|
|
|
|
const std::string& mime_type) {
|
|
|
|
WebWidgetHost *host = GetWidgetHost();
|
|
|
|
if (!host)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gfx::PluginWindowHandle containing_view = NULL;
|
2011-01-07 22:34:20 +01:00
|
|
|
return webkit::npapi::WebPluginDelegateImpl::Create(
|
|
|
|
path, mime_type, containing_view);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::CreatedPluginWindow(
|
|
|
|
gfx::PluginWindowHandle handle) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::WillDestroyPluginWindow(
|
|
|
|
gfx::PluginWindowHandle handle) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::DidMovePlugin(
|
2011-01-07 22:34:20 +01:00
|
|
|
const webkit::npapi::WebPluginGeometry& move) {
|
2010-10-23 19:00:47 +02:00
|
|
|
// TODO(port): add me once plugins work.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Protected methods ----------------------------------------------------------
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::ShowJavaScriptAlert(
|
2010-11-23 15:46:01 +01:00
|
|
|
WebKit::WebFrame* webframe, const CefString& message) {
|
|
|
|
std::string messageStr(message);
|
|
|
|
NSString *text = [NSString stringWithUTF8String:messageStr.c_str()];
|
2010-10-23 19:00:47 +02:00
|
|
|
NSAlert *alert = [NSAlert alertWithMessageText:@"JavaScript Alert"
|
|
|
|
defaultButton:@"OK"
|
|
|
|
alternateButton:nil
|
|
|
|
otherButton:nil
|
|
|
|
informativeTextWithFormat:text];
|
|
|
|
[alert runModal];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::ShowJavaScriptConfirm(
|
2010-11-23 15:46:01 +01:00
|
|
|
WebKit::WebFrame* webframe, const CefString& message) {
|
2010-10-23 19:00:47 +02:00
|
|
|
NOTIMPLEMENTED();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::ShowJavaScriptPrompt(
|
2010-11-23 15:46:01 +01:00
|
|
|
WebKit::WebFrame* webframe, const CefString& message,
|
|
|
|
const CefString& default_value, CefString* result) {
|
2010-10-23 19:00:47 +02:00
|
|
|
NOTIMPLEMENTED();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called to show the file chooser dialog.
|
|
|
|
bool BrowserWebViewDelegate::ShowFileChooser(std::vector<FilePath>& file_names,
|
|
|
|
const bool multi_select,
|
|
|
|
const WebKit::WebString& title,
|
|
|
|
const FilePath& default_file) {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
return false;
|
|
|
|
}
|