2009-07-24 21:11:01 +02:00
|
|
|
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2006-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.
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
#ifndef _BROWSER_IMPL_H
|
|
|
|
#define _BROWSER_IMPL_H
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
#include "include/cef.h"
|
2008-12-02 16:48:14 +01:00
|
|
|
#include "context.h"
|
|
|
|
|
|
|
|
#include "webview_host.h"
|
|
|
|
#include "browser_webview_delegate.h"
|
|
|
|
#include "browser_navigation_controller.h"
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "printing/win_printing_context.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "webkit/glue/webview.h"
|
|
|
|
|
2009-03-08 03:26:16 +01:00
|
|
|
#define BUFFER_SIZE 32768
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
// Implementation of CefBrowser.
|
|
|
|
class CefBrowserImpl : public CefThreadSafeBase<CefBrowser>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefBrowserImpl(CefWindowInfo& windowInfo, bool popup,
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefHandler> handler);
|
|
|
|
virtual ~CefBrowserImpl() {}
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
static LPCTSTR GetWndClass();
|
|
|
|
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam,
|
|
|
|
LPARAM lParam);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// CefBrowser methods
|
|
|
|
virtual bool CanGoBack();
|
|
|
|
virtual void GoBack();
|
|
|
|
virtual bool CanGoForward();
|
|
|
|
virtual void GoForward();
|
|
|
|
virtual void Reload();
|
|
|
|
virtual void StopLoad();
|
2009-03-08 03:26:16 +01:00
|
|
|
virtual void SetFocus(bool enable);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual CefWindowHandle GetWindowHandle();
|
|
|
|
virtual bool IsPopup();
|
|
|
|
virtual CefRefPtr<CefHandler> GetHandler();
|
2009-05-28 02:31:21 +02:00
|
|
|
virtual CefRefPtr<CefFrame> GetMainFrame();
|
|
|
|
virtual CefRefPtr<CefFrame> GetFocusedFrame();
|
|
|
|
virtual CefRefPtr<CefFrame> GetFrame(const std::wstring& name);
|
|
|
|
virtual void GetFrameNames(std::vector<std::wstring>& names);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
// CefFrames are light-weight objects managed by the browser and loosely
|
|
|
|
// coupled to a WebFrame object by name. If a CefFrame object does not
|
|
|
|
// already exist for the specified WebFrame one will be created. There is no
|
|
|
|
// guarantee that the same CefFrame object will be returned across different
|
|
|
|
// calls to this function.
|
2009-08-13 19:23:08 +02:00
|
|
|
CefRefPtr<CefFrame> GetCefFrame(WebKit::WebFrame* frame);
|
2009-05-28 02:31:21 +02:00
|
|
|
void RemoveCefFrame(const std::wstring& name);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
// Return the WebFrame object associated with the specified CefFrame. This
|
|
|
|
// may return NULL if no WebFrame with the CefFrame's name exists.
|
2009-08-13 19:23:08 +02:00
|
|
|
WebKit::WebFrame* GetWebFrame(CefRefPtr<CefFrame> frame);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
// Frame-related methods
|
|
|
|
void Undo(CefRefPtr<CefFrame> frame);
|
|
|
|
void Redo(CefRefPtr<CefFrame> frame);
|
|
|
|
void Cut(CefRefPtr<CefFrame> frame);
|
|
|
|
void Copy(CefRefPtr<CefFrame> frame);
|
|
|
|
void Paste(CefRefPtr<CefFrame> frame);
|
|
|
|
void Delete(CefRefPtr<CefFrame> frame);
|
|
|
|
void SelectAll(CefRefPtr<CefFrame> frame);
|
|
|
|
void Print(CefRefPtr<CefFrame> frame);
|
|
|
|
void ViewSource(CefRefPtr<CefFrame> frame);
|
|
|
|
std::wstring GetSource(CefRefPtr<CefFrame> frame);
|
|
|
|
std::wstring GetText(CefRefPtr<CefFrame> frame);
|
|
|
|
void LoadRequest(CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request);
|
|
|
|
void LoadURL(CefRefPtr<CefFrame> frame,
|
|
|
|
const std::wstring& url);
|
|
|
|
void LoadString(CefRefPtr<CefFrame> frame,
|
|
|
|
const std::wstring& string,
|
|
|
|
const std::wstring& url);
|
|
|
|
void LoadStream(CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefStreamReader> stream,
|
|
|
|
const std::wstring& url);
|
|
|
|
void ExecuteJavaScript(CefRefPtr<CefFrame> frame,
|
|
|
|
const std::wstring& jsCode,
|
|
|
|
const std::wstring& scriptUrl,
|
2009-07-24 21:11:01 +02:00
|
|
|
int startLine);
|
2009-05-28 02:31:21 +02:00
|
|
|
virtual std::wstring GetURL(CefRefPtr<CefFrame> frame);
|
|
|
|
|
|
|
|
WebView* GetWebView() const {
|
2008-12-02 16:48:14 +01:00
|
|
|
return webviewhost_.get() ? webviewhost_->webview() : NULL;
|
|
|
|
}
|
2009-05-28 02:31:21 +02:00
|
|
|
WebViewHost* GetWebViewHost() const {
|
2008-12-02 16:48:14 +01:00
|
|
|
return webviewhost_.get();
|
|
|
|
}
|
2009-07-24 21:11:01 +02:00
|
|
|
BrowserWebViewDelegate* GetWebViewDelegate() const {
|
|
|
|
return delegate_.get();
|
|
|
|
}
|
2009-05-28 02:31:21 +02:00
|
|
|
HWND GetWebViewWndHandle() const {
|
2009-07-24 20:37:00 +02:00
|
|
|
return webviewhost_->view_handle();
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
2009-07-24 21:11:01 +02:00
|
|
|
WebKit::WebWidget* GetPopup() const {
|
|
|
|
return popuphost_ ? popuphost_->webwidget() : NULL;
|
|
|
|
}
|
2009-05-28 02:31:21 +02:00
|
|
|
WebWidgetHost* GetPopupHost() const {
|
2008-12-02 16:48:14 +01:00
|
|
|
return popuphost_;
|
|
|
|
}
|
2009-07-24 20:37:00 +02:00
|
|
|
BrowserWebViewDelegate* GetPopupDelegate() const {
|
|
|
|
return popup_delegate_.get();
|
|
|
|
}
|
2009-05-28 02:31:21 +02:00
|
|
|
HWND GetPopupWndHandle() const {
|
2009-07-24 20:37:00 +02:00
|
|
|
return popuphost_->view_handle();
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
2009-05-28 02:31:21 +02:00
|
|
|
HWND GetMainWndHandle() const {
|
2008-12-02 16:48:14 +01:00
|
|
|
return window_info_.m_hWnd;
|
|
|
|
}
|
2009-07-24 20:37:00 +02:00
|
|
|
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// ALL UIT_* METHODS MUST ONLY BE CALLED ON THE UI THREAD //
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
BrowserNavigationController* UIT_GetNavigationController() {
|
|
|
|
REQUIRE_UIT();
|
|
|
|
return nav_controller_.get();
|
|
|
|
}
|
2009-07-24 20:37:00 +02:00
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
// Return true to allow user editing such as entering text in form elements
|
|
|
|
bool UIT_AllowEditing() { return true; }
|
|
|
|
|
|
|
|
bool UIT_IsModal() {
|
|
|
|
REQUIRE_UIT();
|
|
|
|
return is_modal_;
|
|
|
|
}
|
|
|
|
void UIT_SetIsModal(bool val) {
|
|
|
|
REQUIRE_UIT();
|
|
|
|
is_modal_ = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIT_SetTitle(const std::wstring& title) {
|
|
|
|
REQUIRE_UIT();
|
|
|
|
title_ = title;
|
|
|
|
}
|
|
|
|
std::wstring UIT_GetTitle() {
|
|
|
|
REQUIRE_UIT();
|
|
|
|
return title_;
|
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void UIT_CreateBrowser(const std::wstring& url);
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
void UIT_LoadURL(CefFrame* frame,
|
|
|
|
const std::wstring& url);
|
|
|
|
void UIT_LoadURLForRequest(CefFrame* frame,
|
|
|
|
const std::wstring& url,
|
|
|
|
const std::wstring& method,
|
|
|
|
const WebKit::WebHTTPBody& upload_data,
|
|
|
|
const CefRequest::HeaderMap& headers);
|
|
|
|
void UIT_LoadURLForRequestRef(CefFrame* frame,
|
|
|
|
CefRequest* request);
|
|
|
|
void UIT_LoadHTML(CefFrame* frame,
|
|
|
|
const std::wstring& html,
|
|
|
|
const std::wstring& url);
|
|
|
|
void UIT_LoadHTMLForStreamRef(CefFrame* frame,
|
|
|
|
CefStreamReader* stream,
|
|
|
|
const std::wstring& url);
|
|
|
|
void UIT_ExecuteJavaScript(CefFrame* frame,
|
2009-05-28 02:31:21 +02:00
|
|
|
const std::wstring& js_code,
|
2009-01-29 18:48:16 +01:00
|
|
|
const std::wstring& script_url,
|
2009-07-24 21:11:01 +02:00
|
|
|
int start_line);
|
|
|
|
void UIT_GoBackOrForward(int offset);
|
|
|
|
void UIT_Reload();
|
2008-12-02 16:48:14 +01:00
|
|
|
bool UIT_Navigate(const BrowserNavigationEntry& entry, bool reload);
|
|
|
|
void UIT_SetFocus(WebWidgetHost* host, bool enable);
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
CefRefPtr<CefBrowserImpl> UIT_CreatePopupWindow(const std::wstring& url);
|
|
|
|
WebKit::WebWidget* UIT_CreatePopupWidget(WebView* webview);
|
|
|
|
void UIT_ClosePopupWidget();
|
|
|
|
|
2009-07-24 20:37:00 +02:00
|
|
|
void UIT_Show(WebKit::WebNavigationPolicy policy);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
// Handles most simple browser actions
|
2009-05-28 02:31:21 +02:00
|
|
|
void UIT_HandleActionView(CefHandler::MenuId menuId);
|
|
|
|
void UIT_HandleAction(CefHandler::MenuId menuId, CefFrame* frame);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
// Save the document HTML to a temporary file and open in the default viewing
|
|
|
|
// application
|
2009-08-13 19:23:08 +02:00
|
|
|
bool UIT_ViewDocumentString(WebKit::WebFrame *frame);
|
2008-12-02 16:48:14 +01:00
|
|
|
#if defined(OS_WIN)
|
2009-05-28 02:31:21 +02:00
|
|
|
void UIT_GetDocumentStringNotify(CefFrame* frame,
|
|
|
|
CefStreamWriter* writer, HANDLE hEvent);
|
|
|
|
void UIT_GetDocumentTextNotify(CefFrame* frame,
|
|
|
|
CefStreamWriter* writer, HANDLE hEvent);
|
2008-12-02 16:48:14 +01:00
|
|
|
void UIT_CanGoBackNotify(bool *retVal, HANDLE hEvent);
|
|
|
|
void UIT_CanGoForwardNotify(bool *retVal, HANDLE hEvent);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool UIT_CanGoBack() { return !nav_controller_->IsAtStart(); }
|
|
|
|
bool UIT_CanGoForward() { return !nav_controller_->IsAtEnd(); }
|
|
|
|
|
|
|
|
// Printing support
|
2009-08-13 19:23:08 +02:00
|
|
|
void UIT_PrintPages(WebKit::WebFrame* frame);
|
2009-04-28 02:29:14 +02:00
|
|
|
void UIT_PrintPage(int page_number, int total_pages,
|
2009-08-13 19:23:08 +02:00
|
|
|
const gfx::Size& canvas_size, WebKit::WebFrame* frame);
|
|
|
|
int UIT_GetPagesCount(WebKit::WebFrame* frame);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-03-24 16:06:38 +01:00
|
|
|
void UIT_SetUniqueID(int id) { unique_id_ = id; }
|
|
|
|
int UIT_GetUniqueID() { return unique_id_; }
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
protected:
|
|
|
|
CefWindowInfo window_info_;
|
|
|
|
bool is_popup_;
|
|
|
|
bool is_modal_;
|
|
|
|
CefRefPtr<CefHandler> handler_;
|
|
|
|
scoped_ptr<WebViewHost> webviewhost_;
|
|
|
|
WebWidgetHost* popuphost_;
|
2009-08-13 19:23:08 +02:00
|
|
|
scoped_ptr<BrowserWebViewDelegate> delegate_;
|
|
|
|
scoped_ptr<BrowserWebViewDelegate> popup_delegate_;
|
2008-12-02 16:48:14 +01:00
|
|
|
scoped_ptr<BrowserNavigationController> nav_controller_;
|
|
|
|
|
|
|
|
std::wstring title_;
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
// Context object used to manage printing.
|
2009-04-28 02:29:14 +02:00
|
|
|
printing::PrintingContext print_context_;
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
typedef std::map<std::wstring, CefFrame*> FrameMap;
|
|
|
|
FrameMap frames_;
|
|
|
|
CefFrame* frame_main_;
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-03-24 16:06:38 +01:00
|
|
|
// Unique browser ID assigned by the context.
|
|
|
|
int unique_id_;
|
2008-12-02 16:48:14 +01:00
|
|
|
};
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
|
|
|
|
// Implementation of CefFrame.
|
|
|
|
class CefFrameImpl : public CefThreadSafeBase<CefFrame>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefFrameImpl(CefBrowserImpl* browser, const std::wstring& name)
|
|
|
|
: browser_(browser), name_(name) {}
|
|
|
|
virtual ~CefFrameImpl() { browser_->RemoveCefFrame(name_); }
|
|
|
|
|
|
|
|
// CefFrame methods
|
|
|
|
virtual void Undo() { browser_->Undo(this); }
|
|
|
|
virtual void Redo() { browser_->Redo(this); }
|
|
|
|
virtual void Cut() { browser_->Cut(this); }
|
|
|
|
virtual void Copy() { browser_->Copy(this); }
|
|
|
|
virtual void Paste() { browser_->Paste(this); }
|
|
|
|
virtual void Delete() { browser_->Delete(this); }
|
|
|
|
virtual void SelectAll() { browser_->SelectAll(this); }
|
|
|
|
virtual void Print() { browser_->Print(this); }
|
|
|
|
virtual void ViewSource() { browser_->ViewSource(this); }
|
|
|
|
virtual std::wstring GetSource() { return browser_->GetSource(this); }
|
|
|
|
virtual std::wstring GetText() { return browser_->GetText(this); }
|
|
|
|
virtual void LoadRequest(CefRefPtr<CefRequest> request)
|
|
|
|
{ return browser_->LoadRequest(this, request); }
|
|
|
|
virtual void LoadURL(const std::wstring& url)
|
|
|
|
{ return browser_->LoadURL(this, url); }
|
|
|
|
virtual void LoadString(const std::wstring& string,
|
|
|
|
const std::wstring& url)
|
|
|
|
{ return browser_->LoadString(this, string, url); }
|
|
|
|
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
|
|
|
|
const std::wstring& url)
|
|
|
|
{ return browser_->LoadStream(this, stream, url); }
|
|
|
|
virtual void ExecuteJavaScript(const std::wstring& jsCode,
|
|
|
|
const std::wstring& scriptUrl,
|
|
|
|
int startLine)
|
|
|
|
{ return browser_->ExecuteJavaScript(this, jsCode, scriptUrl, startLine); }
|
|
|
|
virtual bool IsMain() { return name_.empty(); }
|
|
|
|
virtual bool IsFocused()
|
|
|
|
{ return (browser_->GetWebFrame(this) ==
|
|
|
|
browser_->GetWebView()->GetFocusedFrame()); }
|
|
|
|
virtual std::wstring GetName() { return name_; }
|
|
|
|
virtual std::wstring GetURL() { return browser_->GetURL(this); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefRefPtr<CefBrowserImpl> browser_;
|
|
|
|
std::wstring name_;
|
|
|
|
};
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
#endif // _BROWSER_IMPL_H
|